on 4af4e83 help sign in
unity8/plugins/Unity/Indicators/sharedunitymenumodel.cpp
87 lines 2.3 kB history raw
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 */
18#include "sharedunitymenumodel.h"
19#include "unitymenumodelcache.h"
21SharedUnityMenuModel::SharedUnityMenuModel(QObject* parent)
22 : QObject(parent)
26QByteArray SharedUnityMenuModel::busName() const
28 return m_busName;
31void SharedUnityMenuModel::setBusName(const QByteArray& busName)
33 if (m_busName != busName) {
34 m_busName = busName;
35 Q_EMIT busNameChanged();
36 initialize();
37 }
40QByteArray SharedUnityMenuModel::menuObjectPath() const
42 return m_menuObjectPath;
45void SharedUnityMenuModel::setMenuObjectPath(const QByteArray& menuObjectPath)
47 if (m_menuObjectPath != menuObjectPath) {
48 m_menuObjectPath = menuObjectPath;
49 Q_EMIT menuObjectPathChanged();
50 initialize();
51 }
54QVariantMap SharedUnityMenuModel::actions() const
56 return m_actions;
59void SharedUnityMenuModel::setActions(const QVariantMap& actions)
61 if (m_actions != actions) {
62 m_actions = actions;
63 Q_EMIT actionsChanged();
64 initialize();
65 }
68UnityMenuModel* SharedUnityMenuModel::model() const
70 return m_model ? m_model.data() : nullptr;
73void SharedUnityMenuModel::initialize()
75 if (m_busName.isEmpty() || m_menuObjectPath.isEmpty() || m_actions.isEmpty()) {
76 if (!m_model.isNull()) {
77 m_model.clear();
78 Q_EMIT modelChanged();
79 }
80 } else {
81 QSharedPointer<UnityMenuModel> model = UnityMenuModelCache::singleton()->model(m_busName, m_menuObjectPath, m_actions);
82 if (model != m_model) {
83 m_model = model;
84 Q_EMIT modelChanged();
85 }
86 }