~mterry/unity8/power-button-on-lock

« back to all changes in this revision

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

  • Committer: Michael Terry
  • Date: 2014-11-24 15:25:42 UTC
  • mfrom: (1368.1.82 unity8)
  • Revision ID: michael.terry@canonical.com-20141124152542-5cysva8ds3qfula6
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2014 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 */
 
17
 
 
18
#include "sharedunitymenumodel.h"
 
19
#include "unitymenumodelcache.h"
 
20
 
 
21
#include <unitymenumodel.h>
 
22
 
 
23
SharedUnityMenuModel::SharedUnityMenuModel(QObject* parent)
 
24
    : QObject(parent)
 
25
{
 
26
}
 
27
 
 
28
QByteArray SharedUnityMenuModel::busName() const
 
29
{
 
30
    return m_busName;
 
31
}
 
32
 
 
33
void SharedUnityMenuModel::setBusName(const QByteArray& busName)
 
34
{
 
35
    if (m_busName != busName) {
 
36
        m_busName = busName;
 
37
        Q_EMIT busNameChanged();
 
38
        initialize();
 
39
    }
 
40
}
 
41
 
 
42
QByteArray SharedUnityMenuModel::menuObjectPath() const
 
43
{
 
44
    return m_menuObjectPath;
 
45
}
 
46
 
 
47
void SharedUnityMenuModel::setMenuObjectPath(const QByteArray& menuObjectPath)
 
48
{
 
49
    if (m_menuObjectPath != menuObjectPath) {
 
50
        m_menuObjectPath = menuObjectPath;
 
51
        Q_EMIT menuObjectPathChanged();
 
52
        initialize();
 
53
    }
 
54
}
 
55
 
 
56
QVariantMap SharedUnityMenuModel::actions() const
 
57
{
 
58
    return m_actions;
 
59
}
 
60
 
 
61
void SharedUnityMenuModel::setActions(const QVariantMap& actions)
 
62
{
 
63
    if (m_actions != actions) {
 
64
        m_actions = actions;
 
65
        Q_EMIT actionsChanged();
 
66
        initialize();
 
67
    }
 
68
}
 
69
 
 
70
UnityMenuModel* SharedUnityMenuModel::model() const
 
71
{
 
72
    return m_model ? m_model.data() : nullptr;
 
73
}
 
74
 
 
75
void SharedUnityMenuModel::initialize()
 
76
{
 
77
    if (m_busName.isEmpty() || m_menuObjectPath.isEmpty() || m_actions.isEmpty()) {
 
78
        if (!m_model.isNull()) {
 
79
            m_model.clear();
 
80
            Q_EMIT modelChanged();
 
81
        }
 
82
    } else {
 
83
        QSharedPointer<UnityMenuModel> model = UnityMenuModelCache::singleton()->model(m_menuObjectPath);
 
84
        if (model != m_model) {
 
85
            if (model->busName() != m_busName) model->setBusName(m_busName);
 
86
            if (model->actions() != m_actions) model->setActions(m_actions);
 
87
 
 
88
            m_model = model;
 
89
            Q_EMIT modelChanged();
 
90
        }
 
91
    }
 
92
}