Lomiri
Loading...
Searching...
No Matches
sharedlomirimenumodel.cpp
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 "sharedlomirimenumodel.h"
19#include "lomirimenumodelcache.h"
20
21#include <ayatanamenumodel.h>
22
23SharedLomiriMenuModel::SharedLomiriMenuModel(QObject* parent)
24 : QObject(parent)
25{
26}
27
28QByteArray SharedLomiriMenuModel::busName() const
29{
30 return m_busName;
31}
32
33void SharedLomiriMenuModel::setBusName(const QByteArray& busName)
34{
35 if (m_busName != busName) {
36 m_busName = busName;
37 Q_EMIT busNameChanged();
38 initialize();
39 }
40}
41
42QByteArray SharedLomiriMenuModel::menuObjectPath() const
43{
44 return m_menuObjectPath;
45}
46
47void SharedLomiriMenuModel::setMenuObjectPath(const QByteArray& menuObjectPath)
48{
49 if (m_menuObjectPath != menuObjectPath) {
50 m_menuObjectPath = menuObjectPath;
51 Q_EMIT menuObjectPathChanged();
52 initialize();
53 }
54}
55
56QVariantMap SharedLomiriMenuModel::actions() const
57{
58 return m_actions;
59}
60
61void SharedLomiriMenuModel::setActions(const QVariantMap& actions)
62{
63 if (m_actions != actions) {
64 m_actions = actions;
65 Q_EMIT actionsChanged();
66 initialize();
67 }
68}
69
70AyatanaMenuModel* SharedLomiriMenuModel::model() const
71{
72 return m_model ? m_model.data() : nullptr;
73}
74
75void SharedLomiriMenuModel::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<AyatanaMenuModel> model = LomiriMenuModelCache::singleton()->model(m_menuObjectPath);
84
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);
88
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 }
96}