Changeset View
Changeset View
Standalone View
Standalone View
applets/appmenu/plugin/appmenumodel.cpp
Show All 29 Lines | |||||
30 | #include <xcb/xcb.h> | 30 | #include <xcb/xcb.h> | ||
31 | #endif | 31 | #endif | ||
32 | 32 | | |||
33 | #include <QAction> | 33 | #include <QAction> | ||
34 | #include <QMenu> | 34 | #include <QMenu> | ||
35 | #include <QDebug> | 35 | #include <QDebug> | ||
36 | #include <QDBusConnection> | 36 | #include <QDBusConnection> | ||
37 | #include <QDBusConnectionInterface> | 37 | #include <QDBusConnectionInterface> | ||
38 | #include <QDBusServiceWatcher> | ||||
38 | 39 | | |||
39 | #include <dbusmenuimporter.h> | 40 | #include <dbusmenuimporter.h> | ||
40 | 41 | | |||
41 | static const QByteArray s_x11AppMenuServiceNamePropertyName = QByteArrayLiteral("_KDE_NET_WM_APPMENU_SERVICE_NAME"); | 42 | static const QByteArray s_x11AppMenuServiceNamePropertyName = QByteArrayLiteral("_KDE_NET_WM_APPMENU_SERVICE_NAME"); | ||
42 | static const QByteArray s_x11AppMenuObjectPathPropertyName = QByteArrayLiteral("_KDE_NET_WM_APPMENU_OBJECT_PATH"); | 43 | static const QByteArray s_x11AppMenuObjectPathPropertyName = QByteArrayLiteral("_KDE_NET_WM_APPMENU_OBJECT_PATH"); | ||
43 | 44 | | |||
44 | class KDBusMenuImporter : public DBusMenuImporter | 45 | class KDBusMenuImporter : public DBusMenuImporter | ||
45 | { | 46 | { | ||
Show All 9 Lines | 55 | protected: | |||
55 | QIcon iconForName(const QString &name) override | 56 | QIcon iconForName(const QString &name) override | ||
56 | { | 57 | { | ||
57 | return QIcon::fromTheme(name); | 58 | return QIcon::fromTheme(name); | ||
58 | } | 59 | } | ||
59 | 60 | | |||
60 | }; | 61 | }; | ||
61 | 62 | | |||
62 | AppMenuModel::AppMenuModel(QObject *parent) | 63 | AppMenuModel::AppMenuModel(QObject *parent) | ||
63 | : QAbstractListModel(parent) | 64 | : QAbstractListModel(parent), | ||
65 | m_serviceWatcher(new QDBusServiceWatcher(this)) | ||||
64 | { | 66 | { | ||
65 | connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &AppMenuModel::onActiveWindowChanged); | 67 | connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &AppMenuModel::onActiveWindowChanged); | ||
66 | connect(this, &AppMenuModel::modelNeedsUpdate, this, &AppMenuModel::update, Qt::UniqueConnection); | 68 | connect(this, &AppMenuModel::modelNeedsUpdate, this, &AppMenuModel::update, Qt::UniqueConnection); | ||
67 | onActiveWindowChanged(KWindowSystem::activeWindow()); | 69 | onActiveWindowChanged(KWindowSystem::activeWindow()); | ||
68 | 70 | | |||
71 | m_serviceWatcher->setConnection(QDBusConnection::sessionBus()); | ||||
69 | //if our current DBus connection gets lost, close the menu | 72 | //if our current DBus connection gets lost, close the menu | ||
70 | //we'll select the new menu when the focus changes | 73 | //we'll select the new menu when the focus changes | ||
71 | connect(QDBusConnection::sessionBus().interface(), &QDBusConnectionInterface::serviceOwnerChanged, this, [this](const QString &serviceName, const QString &oldOwner, const QString &newOwner) | 74 | connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, [this](const QString &serviceName) | ||
72 | { | 75 | { | ||
73 | if (serviceName == m_serviceName && newOwner.isEmpty()) { | 76 | if (serviceName == m_serviceName) { | ||
74 | setMenuAvailable(false); | 77 | setMenuAvailable(false); | ||
75 | emit modelNeedsUpdate(); | 78 | emit modelNeedsUpdate(); | ||
76 | } | 79 | } | ||
77 | }); | 80 | }); | ||
78 | } | 81 | } | ||
79 | 82 | | |||
80 | AppMenuModel::~AppMenuModel() = default; | 83 | AppMenuModel::~AppMenuModel() = default; | ||
81 | 84 | | |||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Line(s) | 231 | { | |||
229 | if (m_serviceName == serviceName && m_menuObjectPath == menuObjectPath) { | 232 | if (m_serviceName == serviceName && m_menuObjectPath == menuObjectPath) { | ||
230 | if (m_importer) { | 233 | if (m_importer) { | ||
231 | QMetaObject::invokeMethod(m_importer, "updateMenu", Qt::QueuedConnection); | 234 | QMetaObject::invokeMethod(m_importer, "updateMenu", Qt::QueuedConnection); | ||
232 | } | 235 | } | ||
233 | return; | 236 | return; | ||
234 | } | 237 | } | ||
235 | 238 | | |||
236 | m_serviceName = serviceName; | 239 | m_serviceName = serviceName; | ||
240 | m_serviceWatcher->setWatchedServices(QStringList({m_serviceName})); | ||||
241 | | ||||
237 | m_menuObjectPath = menuObjectPath; | 242 | m_menuObjectPath = menuObjectPath; | ||
238 | 243 | | |||
239 | if (m_importer) { | 244 | if (m_importer) { | ||
240 | m_importer->deleteLater(); | 245 | m_importer->deleteLater(); | ||
241 | } | 246 | } | ||
242 | 247 | | |||
243 | m_importer = new KDBusMenuImporter(serviceName, menuObjectPath, this); | 248 | m_importer = new KDBusMenuImporter(serviceName, menuObjectPath, this); | ||
244 | QMetaObject::invokeMethod(m_importer, "updateMenu", Qt::QueuedConnection); | 249 | QMetaObject::invokeMethod(m_importer, "updateMenu", Qt::QueuedConnection); | ||
Show All 27 Lines |