on master help sign in
unity8/plugins/Unity/Indicators/sharedunitymenumodel.cpp
96 lines 2.6 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"
21#include <unitymenumodel.h>
23SharedUnityMenuModel::SharedUnityMenuModel(QObject* parent)
24 : QObject(parent)
28QByteArray SharedUnityMenuModel::busName() const
30 return m_busName;
33void SharedUnityMenuModel::setBusName(const QByteArray& busName)
35 if (m_busName != busName) {
36 m_busName = busName;
37 Q_EMIT busNameChanged();
38 initialize();
39 }
42QByteArray SharedUnityMenuModel::menuObjectPath() const
44 return m_menuObjectPath;
47void SharedUnityMenuModel::setMenuObjectPath(const QByteArray& menuObjectPath)
49 if (m_menuObjectPath != menuObjectPath) {
50 m_menuObjectPath = menuObjectPath;
51 Q_EMIT menuObjectPathChanged();
52 initialize();
53 }
56QVariantMap SharedUnityMenuModel::actions() const
58 return m_actions;
61void SharedUnityMenuModel::setActions(const QVariantMap& actions)
63 if (m_actions != actions) {
64 m_actions = actions;
65 Q_EMIT actionsChanged();
66 initialize();
67 }
70UnityMenuModel* SharedUnityMenuModel::model() const
72 return m_model ? m_model.data() : nullptr;
75void SharedUnityMenuModel::initialize()
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);
85 if (model != m_model) {
86 if (model->busName() != m_busName) model->setBusName(m_busName);
87 if (model->actions() != m_actions) model->setActions(m_actions);
89 m_model = model;
90 Q_EMIT modelChanged();
91 } else if (m_model) {
92 if (m_model->busName() != m_busName) m_model->setBusName(m_busName);
93 if (m_model->actions() != m_actions) m_model->setActions(m_actions);
94 }
95 }