Commit c453e9b5 authored by David Edmundson's avatar David Edmundson

Port Appmenu model to QDBusServiceWatcher

Summary:
QDBusConnection::serviceOwnerChanged is deprecated, with the intended
replacement being QDBusServiceWatcher. QDBusServiceWatcher only creates
a match rule for the relevant services, resulting in less noise and
wakeups.

(practically this has no impact as the the system tray also connects to
watch every service change, and that runs in the same process)

Test Plan:
Ran appmenu
Had dolphin open showing the menu
Closed dolphin
menu immediately closed

Reviewers: #plasma, broulik

Reviewed By: #plasma, broulik

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D7611
parent a47d1f19
......@@ -35,6 +35,7 @@
#include <QDebug>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusServiceWatcher>
#include <dbusmenuimporter.h>
......@@ -60,17 +61,19 @@ protected:
};
AppMenuModel::AppMenuModel(QObject *parent)
: QAbstractListModel(parent)
: QAbstractListModel(parent),
m_serviceWatcher(new QDBusServiceWatcher(this))
{
connect(KWindowSystem::self(), &KWindowSystem::activeWindowChanged, this, &AppMenuModel::onActiveWindowChanged);
connect(this, &AppMenuModel::modelNeedsUpdate, this, &AppMenuModel::update, Qt::UniqueConnection);
onActiveWindowChanged(KWindowSystem::activeWindow());
m_serviceWatcher->setConnection(QDBusConnection::sessionBus());
//if our current DBus connection gets lost, close the menu
//we'll select the new menu when the focus changes
connect(QDBusConnection::sessionBus().interface(), &QDBusConnectionInterface::serviceOwnerChanged, this, [this](const QString &serviceName, const QString &oldOwner, const QString &newOwner)
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, [this](const QString &serviceName)
{
if (serviceName == m_serviceName && newOwner.isEmpty()) {
if (serviceName == m_serviceName) {
setMenuAvailable(false);
emit modelNeedsUpdate();
}
......@@ -234,6 +237,8 @@ void AppMenuModel::updateApplicationMenu(const QString &serviceName, const QStri
}
m_serviceName = serviceName;
m_serviceWatcher->setWatchedServices(QStringList({m_serviceName}));
m_menuObjectPath = menuObjectPath;
if (m_importer) {
......
......@@ -27,6 +27,7 @@
class QMenu;
class QAction;
class QModelIndex;
class QDBusServiceWatcher;
class KDBusMenuImporter;
class AppMenuModel : public QAbstractListModel
......@@ -71,6 +72,7 @@ private:
QStringList m_activeMenu;
QList<QAction *> m_activeActions;
QDBusServiceWatcher *m_serviceWatcher;
QString m_serviceName;
QString m_menuObjectPath;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment