~aacid/unity8/moreAsyncAudioCard

« back to all changes in this revision

Viewing changes to plugins/Unity/Indicators/modelactionrootstate.cpp

  • Committer: Albert Astals Cid
  • Date: 2016-03-10 08:32:16 UTC
  • mfrom: (2136.2.83 unity8)
  • Revision ID: albert.astals@canonical.com-20160310083216-8nnplxl85qx13xd0
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2013 Canonical Ltd.
 
2
 * Copyright 2013-2016 Canonical Ltd.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
5
5
 * it under the terms of the GNU Lesser General Public License as published by
32
32
ModelActionRootState::ModelActionRootState(QObject *parent)
33
33
    : RootStateObject(parent),
34
34
      m_menu(nullptr)
 
35
    , m_reentryGuard(false)
35
36
{
36
37
}
37
38
 
62
63
            connect(m_menu, &UnityMenuModel::destroyed, this, &ModelActionRootState::reset);
63
64
        }
64
65
        updateActionState();
 
66
        updateOtherActions();
65
67
        Q_EMIT menuChanged();
66
68
 
67
69
        if (wasValid != valid())
69
71
    }
70
72
}
71
73
 
 
74
QString ModelActionRootState::secondaryAction() const
 
75
{
 
76
    return m_secondaryAction;
 
77
}
 
78
 
 
79
QString ModelActionRootState::scrollAction() const
 
80
{
 
81
    return m_scrollAction;
 
82
}
 
83
 
 
84
QString ModelActionRootState::submenuAction() const
 
85
{
 
86
    return m_submenuAction;
 
87
}
 
88
 
72
89
bool ModelActionRootState::valid() const
73
90
{
74
91
    return !currentState().empty();
79
96
    Q_UNUSED(parent);
80
97
    if (start == 0 && end >= 0) {
81
98
        updateActionState();
 
99
        updateOtherActions();
82
100
    }
83
101
}
84
102
 
87
105
    Q_UNUSED(parent);
88
106
    if (start == 0 && end >= 0) {
89
107
        updateActionState();
 
108
        updateOtherActions();
90
109
    }
91
110
}
92
111
 
99
118
 
100
119
    if (topLeft.row() <= 0 && bottomRight.row() >= 0) {
101
120
        updateActionState();
 
121
        updateOtherActions();
102
122
    }
103
123
}
104
124
 
108
128
 
109
129
    Q_EMIT menuChanged();
110
130
    setCurrentState(QVariantMap());
 
131
 
 
132
    updateOtherActions();
111
133
}
112
134
 
113
135
void ModelActionRootState::updateActionState()
114
136
{
 
137
    if (m_reentryGuard) return;
 
138
    m_reentryGuard = true;
 
139
 
115
140
    if (m_menu && m_menu->rowCount() > 0) {
116
141
        ActionStateParser* oldParser = m_menu->actionStateParser();
117
142
        m_menu->setActionStateParser(&m_parser);
126
151
    }
127
152
    // else if m_menu->rowCount() == 0, let's leave existing cache in place
128
153
    // until the new menu comes in, to avoid flashing the UI empty for a moment
 
154
 
 
155
    m_reentryGuard = false;
 
156
}
 
157
 
 
158
void ModelActionRootState::updateOtherActions()
 
159
{
 
160
    if (m_reentryGuard) return;
 
161
    m_reentryGuard = true;
 
162
 
 
163
    if (m_menu && m_menu->rowCount() > 0) {
 
164
        QVariantMap map;
 
165
        map[QStringLiteral("submenu-action")] = QStringLiteral("string");
 
166
        map[QStringLiteral("x-canonical-scroll-action")] = QStringLiteral("string");
 
167
        map[QStringLiteral("x-canonical-secondary-action")] = QStringLiteral("string");
 
168
        m_menu->loadExtendedAttributes(0, map);
 
169
        QVariantMap extMap = m_menu->get(0, "ext").toMap();
 
170
 
 
171
        QString secondaryAction = extMap.value(QStringLiteral("xCanonicalSecondaryAction")).toString();
 
172
        if (m_secondaryAction != secondaryAction) {
 
173
            m_secondaryAction = secondaryAction;
 
174
            Q_EMIT secondaryActionChanged();
 
175
        }
 
176
 
 
177
        QString scrollAction = extMap.value(QStringLiteral("xCanonicalScrollAction")).toString();
 
178
        if (m_scrollAction != scrollAction) {
 
179
            m_scrollAction = scrollAction;
 
180
            Q_EMIT scrollActionChanged();
 
181
        }
 
182
 
 
183
        QString submenuAction = extMap.value(QStringLiteral("submenuAction")).toString();
 
184
        if (m_submenuAction != submenuAction) {
 
185
            m_submenuAction = submenuAction;
 
186
            Q_EMIT submenuActionChanged();
 
187
        }
 
188
    } else {
 
189
        if (!m_secondaryAction.isEmpty()) {
 
190
            m_secondaryAction.clear();
 
191
            Q_EMIT secondaryActionChanged();
 
192
        }
 
193
        if (!m_scrollAction.isEmpty()) {
 
194
            m_scrollAction.clear();
 
195
            Q_EMIT scrollActionChanged();
 
196
        }
 
197
        if (!m_submenuAction.isEmpty()) {
 
198
            m_submenuAction.clear();
 
199
            Q_EMIT submenuActionChanged();
 
200
        }
 
201
    }
 
202
 
 
203
    m_reentryGuard = false;
129
204
}