~aacid/qtubuntu/remove_unused_signal

« back to all changes in this revision

Viewing changes to src/ubuntuappmenu/registry.cpp

  • Committer: Bileto Bot
  • Date: 2017-01-16 06:39:32 UTC
  • mfrom: (360.2.4 qtubuntu)
  • Revision ID: ci-train-bot@canonical.com-20170116063932-70jenqyqw3jplt3q
Resync trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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(ubuntuappmenuRegistrar, "ubuntuappmenu.registrar", QtWarningMsg)
 
25
 
 
26
#define REGISTRAR_SERVICE "com.ubuntu.MenuRegistrar"
 
27
#define REGISTRY_OBJECT_PATH "/com/ubuntu/MenuRegistrar"
 
28
 
 
29
UbuntuMenuRegistry *UbuntuMenuRegistry::instance()
 
30
{
 
31
    static UbuntuMenuRegistry* registry(new UbuntuMenuRegistry());
 
32
    return registry;
 
33
}
 
34
 
 
35
UbuntuMenuRegistry::UbuntuMenuRegistry(QObject* parent)
 
36
    : 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())
 
40
{
 
41
    connect(m_serviceWatcher.data(), &QDBusServiceWatcher::serviceOwnerChanged, this, &UbuntuMenuRegistry::serviceOwnerChanged);
 
42
}
 
43
 
 
44
UbuntuMenuRegistry::~UbuntuMenuRegistry()
 
45
{
 
46
}
 
47
 
 
48
void UbuntuMenuRegistry::registerApplicationMenu(pid_t pid, QDBusObjectPath menuObjectPath, const QString &service)
 
49
{
 
50
    qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::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 UbuntuMenuRegistry::unregisterApplicationMenu(pid_t pid, QDBusObjectPath menuObjectPath)
 
59
{
 
60
    qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::unregisterSurfaceMenu(pid=%d, menuObjectPath=%s)",
 
61
            pid,
 
62
            qPrintable(menuObjectPath.path()));
 
63
 
 
64
    m_interface->UnregisterAppMenu(pid, menuObjectPath);
 
65
}
 
66
 
 
67
void UbuntuMenuRegistry::registerSurfaceMenu(const QString &surfaceId, QDBusObjectPath menuObjectPath, const QString &service)
 
68
{
 
69
    qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::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 UbuntuMenuRegistry::unregisterSurfaceMenu(const QString &surfaceId, QDBusObjectPath menuObjectPath)
 
78
{
 
79
    qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::unregisterSurfaceMenu(surfaceId=%s, menuObjectPath=%s)",
 
80
            qPrintable(surfaceId),
 
81
            qPrintable(menuObjectPath.path()));
 
82
 
 
83
    m_interface->UnregisterSurfaceMenu(surfaceId, menuObjectPath);
 
84
}
 
85
 
 
86
 
 
87
void UbuntuMenuRegistry::serviceOwnerChanged(const QString &serviceName, const QString& oldOwner, const QString &newOwner)
 
88
{
 
89
    qCDebug(ubuntuappmenuRegistrar, "UbuntuMenuRegistry::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
}