File 0027-Signal-which-menu-has-updated-in-libdbusmenu-qt.patch of Package plasma5-workspace
From 339b18154b9b0dd829ff9306f1961e55332caf4d Mon Sep 17 00:00:00 2001
From: David Edmundson <kde@davidedmundson.co.uk>
Date: Mon, 16 Jan 2017 15:18:55 +0000
Subject: [PATCH 27/44] Signal which menu has updated in libdbusmenu-qt
Summary:
Then update appet, SNI, and appmenu appropriately which are only care
about the root menu.
This fixes some premature showing and re-evaluation.
Test Plan:
Ran statusnotifiertest and checked submenu worked
Ran applet and checked everything was still fine
Restarted kded and checked window decoration menu
Reviewers: #plasma
Subscribers: plasma-devel
Tags: #plasma
Differential Revision: https://phabricator.kde.org/D4161
---
applets/appmenu/plugin/appmenumodel.cpp | 6 +++---
appmenu/appmenu.cpp | 4 ++--
.../statusnotifieritemsource.cpp | 6 +++++-
libdbusmenuqt/dbusmenuimporter.cpp | 22 +++++++++++++---------
libdbusmenuqt/dbusmenuimporter.h | 2 +-
5 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/applets/appmenu/plugin/appmenumodel.cpp b/applets/appmenu/plugin/appmenumodel.cpp
index 4130d97f..02259a30 100644
--- a/applets/appmenu/plugin/appmenumodel.cpp
+++ b/applets/appmenu/plugin/appmenumodel.cpp
@@ -225,12 +225,12 @@ void AppMenuModel::updateApplicationMenu(const QString &serviceName, const QStri
m_importer->deleteLater();
}
- m_importer = new KDBusMenuImporter(serviceName, menuObjectPath, this);
+ m_importer = new KDBusMenuImporter(serviceName, menuObjectPath, this);
QMetaObject::invokeMethod(m_importer, "updateMenu", Qt::QueuedConnection);
- connect(m_importer.data(), &DBusMenuImporter::menuUpdated, this, [=] {
+ connect(m_importer.data(), &DBusMenuImporter::menuUpdated, this, [=](QMenu *menu) {
m_menu = m_importer->menu();
- if (m_menu.isNull()) {
+ if (m_menu.isNull() || menu != m_menu) {
return;
}
setMenuAvailable(true);
diff --git a/appmenu/appmenu.cpp b/appmenu/appmenu.cpp
index ce3ef01d..366f8c7a 100644
--- a/appmenu/appmenu.cpp
+++ b/appmenu/appmenu.cpp
@@ -136,9 +136,9 @@ void AppMenuModule::slotShowMenu(int x, int y, const QString &serviceName, const
QMetaObject::invokeMethod(importer, "updateMenu", Qt::QueuedConnection);
disconnect(importer, 0, this, 0); // ensure we don't popup multiple times in case the menu updates again later
- connect(importer, &KDBusMenuImporter::menuUpdated, this, [=] {
+ connect(importer, &KDBusMenuImporter::menuUpdated, this, [=](QMenu *m) {
QMenu *menu = importer->menu();
- if (!menu) {
+ if (!menu || menu != m) {
return;
}
m_menu = qobject_cast<VerticalMenu*>(menu);
diff --git a/dataengines/statusnotifieritem/statusnotifieritemsource.cpp b/dataengines/statusnotifieritem/statusnotifieritemsource.cpp
index d835d50c..bd5f2069 100644
--- a/dataengines/statusnotifieritem/statusnotifieritemsource.cpp
+++ b/dataengines/statusnotifieritem/statusnotifieritemsource.cpp
@@ -368,7 +368,11 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call)
qWarning() << "DBusMenu disabled for this application";
} else {
m_menuImporter = new PlasmaDBusMenuImporter(m_statusNotifierItemInterface->service(), menuObjectPath, iconLoader(), this);
- connect(m_menuImporter, SIGNAL(menuUpdated()), this, SLOT(contextMenuReady()));
+ connect(m_menuImporter, &PlasmaDBusMenuImporter::menuUpdated, this, [this](QMenu *menu) {
+ if (menu == m_menuImporter->menu()) {
+ contextMenuReady();
+ }
+ });
}
}
}
diff --git a/libdbusmenuqt/dbusmenuimporter.cpp b/libdbusmenuqt/dbusmenuimporter.cpp
index 9265212d..8737fb25 100644
--- a/libdbusmenuqt/dbusmenuimporter.cpp
+++ b/libdbusmenuqt/dbusmenuimporter.cpp
@@ -375,11 +375,14 @@ void DBusMenuImporter::slotGetLayoutFinished(QDBusPendingCallWatcher *watcher)
int parentId = watcher->property(DBUSMENU_PROPERTY_ID).toInt();
watcher->deleteLater();
+ QMenu *menu = d->menuForId(parentId);
+
QDBusPendingReply<uint, DBusMenuLayoutItem> reply = *watcher;
if (!reply.isValid()) {
qWarning() << reply.error().message();
-
- emit menuUpdated();
+ if (menu) {
+ emit menuUpdated(menu);
+ }
return;
}
@@ -388,7 +391,6 @@ void DBusMenuImporter::slotGetLayoutFinished(QDBusPendingCallWatcher *watcher)
#endif
DBusMenuLayoutItem rootItem = reply.argumentAt<1>();
- QMenu *menu = d->menuForId(parentId);
if (!menu) {
qWarning() << "No menu for id" << parentId;
return;
@@ -443,7 +445,7 @@ void DBusMenuImporter::slotGetLayoutFinished(QDBusPendingCallWatcher *watcher)
}
}
- emit menuUpdated();
+ emit menuUpdated(menu);
}
void DBusMenuImporter::sendClickedEvent(int id)
@@ -477,24 +479,26 @@ void DBusMenuImporter::slotAboutToShowDBusCallFinished(QDBusPendingCallWatcher *
int id = watcher->property(DBUSMENU_PROPERTY_ID).toInt();
watcher->deleteLater();
+ QMenu *menu = d->menuForId(id);
+
QDBusPendingReply<bool> reply = *watcher;
if (reply.isError()) {
- menuUpdated();
qWarning() << "Call to AboutToShow() failed:" << reply.error().message();
+ if (menu) {
+ menuUpdated(menu);
+ }
return;
}
//Note, this isn't used by Qt's QPT - but we get a LayoutChanged emitted before
//this returns, which equates to the same thing
bool needRefresh = reply.argumentAt<0>();
- QMenu *menu = d->menuForId(id);
- DMRETURN_IF_FAIL(menu);
if (needRefresh || menu->actions().isEmpty()) {
d->m_idsRefreshedByAboutToShow << id;
d->refresh(id);
- } else {
- menuUpdated();
+ } else if (menu) {
+ menuUpdated(menu);
}
}
diff --git a/libdbusmenuqt/dbusmenuimporter.h b/libdbusmenuqt/dbusmenuimporter.h
index 9ab87c6e..5c4d7c46 100644
--- a/libdbusmenuqt/dbusmenuimporter.h
+++ b/libdbusmenuqt/dbusmenuimporter.h
@@ -69,7 +69,7 @@ Q_SIGNALS:
* Emitted after a call to updateMenu().
* @see updateMenu()
*/
- void menuUpdated();
+ void menuUpdated(QMenu *);
/**
* Emitted when the exporter was asked to activate an action
--
2.12.0