Debian Codegraph @

src/lomiriappmenu/registry.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * 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 #include "registry.h"
18 #include "logging.h"
19 #include "menuregistrar_interface.h"
20
21 #include <QDBusObjectPath>
22 #include <QDBusServiceWatcher>
23
24 Q_LOGGING_CATEGORY(lomiriappmenuRegistrar, "lomiriappmenu.registrar", QtWarningMsg)
25
26 #define REGISTRAR_SERVICE "com.lomiri.MenuRegistrar"
27 #define REGISTRY_OBJECT_PATH "/com/lomiri/MenuRegistrar"
28
29 LomiriMenuRegistry *LomiriMenuRegistry::instance()
30 {
31 static LomiriMenuRegistry* registry(new LomiriMenuRegistry());
32 return registry;
33 }
34
35 LomiriMenuRegistry::LomiriMenuRegistry(QObject* parent)
36 : QObject(parent)
37 , m_serviceWatcher(new QDBusServiceWatcher(REGISTRAR_SERVICE, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this))
38 , m_interface(new ComLomiriMenuRegistrarInterface(REGISTRAR_SERVICE, REGISTRY_OBJECT_PATH, QDBusConnection::sessionBus(), this))
39 , m_connected(m_interface->isValid())
40 {
41 connect(m_serviceWatcher.data(), &QDBusServiceWatcher::serviceOwnerChanged, this, &LomiriMenuRegistry::serviceOwnerChanged);
42 }
43
44 LomiriMenuRegistry::~LomiriMenuRegistry()
45 {
46 }
47
48 void LomiriMenuRegistry::registerApplicationMenu(pid_t pid, QDBusObjectPath menuObjectPath, const QString &service)
49 {
50 qCDebug(lomiriappmenuRegistrar, "LomiriMenuRegistry::registerMenu(pid=%d, menuObjectPath=%s, service=%s)",
51 pid,
52 qPrintable(menuObjectPath.path()),
53 qPrintable(service));
54
55 m_interface->RegisterAppMenu(pid, menuObjectPath, menuObjectPath, service);
56 }
57
58 void LomiriMenuRegistry::unregisterApplicationMenu(pid_t pid, QDBusObjectPath menuObjectPath)
59 {
60 qCDebug(lomiriappmenuRegistrar, "LomiriMenuRegistry::unregisterSurfaceMenu(pid=%d, menuObjectPath=%s)",
61 pid,
62 qPrintable(menuObjectPath.path()));
63
64 m_interface->UnregisterAppMenu(pid, menuObjectPath);
65 }
66
67 void LomiriMenuRegistry::registerSurfaceMenu(const QString &surfaceId, QDBusObjectPath menuObjectPath, const QString &service)
68 {
69 qCDebug(lomiriappmenuRegistrar, "LomiriMenuRegistry::registerMenu(surfaceId=%s, menuObjectPath=%s, service=%s)",
70 qPrintable(surfaceId),
71 qPrintable(menuObjectPath.path()),
72 qPrintable(service));
73
74 m_interface->RegisterSurfaceMenu(surfaceId, menuObjectPath, menuObjectPath, service);
75 }
76
77 void LomiriMenuRegistry::unregisterSurfaceMenu(const QString &surfaceId, QDBusObjectPath menuObjectPath)
78 {
79 qCDebug(lomiriappmenuRegistrar, "LomiriMenuRegistry::unregisterSurfaceMenu(surfaceId=%s, menuObjectPath=%s)",
80 qPrintable(surfaceId),
81 qPrintable(menuObjectPath.path()));
82
83 m_interface->UnregisterSurfaceMenu(surfaceId, menuObjectPath);
84 }
85
86
87 void LomiriMenuRegistry::serviceOwnerChanged(const QString &serviceName, const QString& oldOwner, const QString &newOwner)
88 {
89 qCDebug(lomiriappmenuRegistrar, "LomiriMenuRegistry::serviceOwnerChanged(newOwner=%s)", qPrintable(newOwner));
90
91 if (serviceName != REGISTRAR_SERVICE) return;
92
93 if (oldOwner != newOwner) {
94 m_connected = !newOwner.isEmpty();
95 Q_EMIT serviceChanged();
96 }
97 }