2
* Copyright (C) 2016 Canonical, Ltd.
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.
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.
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/>.
19
#include "menuregistrar_interface.h"
21
#include <QDBusObjectPath>
22
#include <QDBusServiceWatcher>
24
Q_LOGGING_CATEGORY(ubuntuappmenuRegistrar, "ubuntuappmenu.registrar", QtWarningMsg)
26
#define REGISTRAR_SERVICE "com.ubuntu.MenuRegistrar"
27
#define REGISTRY_OBJECT_PATH "/com/ubuntu/MenuRegistrar"
29
UbuntuMenuRegistry *UbuntuMenuRegistry::instance()
31
static UbuntuMenuRegistry* registry(new UbuntuMenuRegistry());
35
UbuntuMenuRegistry::UbuntuMenuRegistry(QObject* parent)
37
, m_serviceWatcher(new QDBusServiceWatcher(REGISTRAR_SERVICE, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this))
38
, m_interface(new ComUbuntuMenuRegistrarInterface(REGISTRAR_SERVICE, REGISTRY_OBJECT_PATH, QDBusConnection::sessionBus(), this))
39
, m_connected(m_interface->isValid())
41
connect(m_serviceWatcher.data(), &QDBusServiceWatcher::serviceOwnerChanged, this, &UbuntuMenuRegistry::serviceOwnerChanged);
44
UbuntuMenuRegistry::~UbuntuMenuRegistry()
48
void UbuntuMenuRegistry::registerApplicationMenu(pid_t pid, QDBusObjectPath menuObjectPath, const QString &service)
50
qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::registerMenu(pid=%d, menuObjectPath=%s, service=%s)",
52
qPrintable(menuObjectPath.path()),
55
m_interface->RegisterAppMenu(pid, menuObjectPath, menuObjectPath, service);
58
void UbuntuMenuRegistry::unregisterApplicationMenu(pid_t pid, QDBusObjectPath menuObjectPath)
60
qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::unregisterSurfaceMenu(pid=%d, menuObjectPath=%s)",
62
qPrintable(menuObjectPath.path()));
64
m_interface->UnregisterAppMenu(pid, menuObjectPath);
67
void UbuntuMenuRegistry::registerSurfaceMenu(const QString &surfaceId, QDBusObjectPath menuObjectPath, const QString &service)
69
qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::registerMenu(surfaceId=%s, menuObjectPath=%s, service=%s)",
70
qPrintable(surfaceId),
71
qPrintable(menuObjectPath.path()),
74
m_interface->RegisterSurfaceMenu(surfaceId, menuObjectPath, menuObjectPath, service);
77
void UbuntuMenuRegistry::unregisterSurfaceMenu(const QString &surfaceId, QDBusObjectPath menuObjectPath)
79
qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::unregisterSurfaceMenu(surfaceId=%s, menuObjectPath=%s)",
80
qPrintable(surfaceId),
81
qPrintable(menuObjectPath.path()));
83
m_interface->UnregisterSurfaceMenu(surfaceId, menuObjectPath);
87
void UbuntuMenuRegistry::serviceOwnerChanged(const QString &serviceName, const QString& oldOwner, const QString &newOwner)
89
qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::serviceOwnerChanged(newOwner=%s)", qPrintable(newOwner));
91
if (serviceName != REGISTRAR_SERVICE) return;
93
if (oldOwner != newOwner) {
94
m_connected = !newOwner.isEmpty();
95
Q_EMIT serviceChanged();