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
wilder-5.14
David Edmundson 9 years ago
parent 68abbe6693
commit 77e57190ed
  1. 4
      applets/appmenu/plugin/appmenumodel.cpp
  2. 4
      appmenu/appmenu.cpp
  3. 6
      dataengines/statusnotifieritem/statusnotifieritemsource.cpp
  4. 22
      libdbusmenuqt/dbusmenuimporter.cpp
  5. 2
      libdbusmenuqt/dbusmenuimporter.h

@ -228,9 +228,9 @@ void AppMenuModel::updateApplicationMenu(const QString &serviceName, const QStri
m_importer = new KDBusMenuImporter(serviceName, menuObjectPath, this); m_importer = new KDBusMenuImporter(serviceName, menuObjectPath, this);
QMetaObject::invokeMethod(m_importer, "updateMenu", Qt::QueuedConnection); 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(); m_menu = m_importer->menu();
if (m_menu.isNull()) { if (m_menu.isNull() || menu != m_menu) {
return; return;
} }
setMenuAvailable(true); setMenuAvailable(true);

@ -136,9 +136,9 @@ void AppMenuModule::slotShowMenu(int x, int y, const QString &serviceName, const
QMetaObject::invokeMethod(importer, "updateMenu", Qt::QueuedConnection); 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 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(); QMenu *menu = importer->menu();
if (!menu) { if (!menu || menu != m) {
return; return;
} }
m_menu = qobject_cast<VerticalMenu*>(menu); m_menu = qobject_cast<VerticalMenu*>(menu);

@ -368,7 +368,11 @@ void StatusNotifierItemSource::refreshCallback(QDBusPendingCallWatcher *call)
qWarning() << "DBusMenu disabled for this application"; qWarning() << "DBusMenu disabled for this application";
} else { } else {
m_menuImporter = new PlasmaDBusMenuImporter(m_statusNotifierItemInterface->service(), menuObjectPath, iconLoader(), this); 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();
}
});
} }
} }
} }

@ -375,11 +375,14 @@ void DBusMenuImporter::slotGetLayoutFinished(QDBusPendingCallWatcher *watcher)
int parentId = watcher->property(DBUSMENU_PROPERTY_ID).toInt(); int parentId = watcher->property(DBUSMENU_PROPERTY_ID).toInt();
watcher->deleteLater(); watcher->deleteLater();
QMenu *menu = d->menuForId(parentId);
QDBusPendingReply<uint, DBusMenuLayoutItem> reply = *watcher; QDBusPendingReply<uint, DBusMenuLayoutItem> reply = *watcher;
if (!reply.isValid()) { if (!reply.isValid()) {
qWarning() << reply.error().message(); qWarning() << reply.error().message();
if (menu) {
emit menuUpdated(); emit menuUpdated(menu);
}
return; return;
} }
@ -388,7 +391,6 @@ void DBusMenuImporter::slotGetLayoutFinished(QDBusPendingCallWatcher *watcher)
#endif #endif
DBusMenuLayoutItem rootItem = reply.argumentAt<1>(); DBusMenuLayoutItem rootItem = reply.argumentAt<1>();
QMenu *menu = d->menuForId(parentId);
if (!menu) { if (!menu) {
qWarning() << "No menu for id" << parentId; qWarning() << "No menu for id" << parentId;
return; return;
@ -443,7 +445,7 @@ void DBusMenuImporter::slotGetLayoutFinished(QDBusPendingCallWatcher *watcher)
} }
} }
emit menuUpdated(); emit menuUpdated(menu);
} }
void DBusMenuImporter::sendClickedEvent(int id) void DBusMenuImporter::sendClickedEvent(int id)
@ -477,24 +479,26 @@ void DBusMenuImporter::slotAboutToShowDBusCallFinished(QDBusPendingCallWatcher *
int id = watcher->property(DBUSMENU_PROPERTY_ID).toInt(); int id = watcher->property(DBUSMENU_PROPERTY_ID).toInt();
watcher->deleteLater(); watcher->deleteLater();
QMenu *menu = d->menuForId(id);
QDBusPendingReply<bool> reply = *watcher; QDBusPendingReply<bool> reply = *watcher;
if (reply.isError()) { if (reply.isError()) {
menuUpdated();
qWarning() << "Call to AboutToShow() failed:" << reply.error().message(); qWarning() << "Call to AboutToShow() failed:" << reply.error().message();
if (menu) {
menuUpdated(menu);
}
return; return;
} }
//Note, this isn't used by Qt's QPT - but we get a LayoutChanged emitted before //Note, this isn't used by Qt's QPT - but we get a LayoutChanged emitted before
//this returns, which equates to the same thing //this returns, which equates to the same thing
bool needRefresh = reply.argumentAt<0>(); bool needRefresh = reply.argumentAt<0>();
QMenu *menu = d->menuForId(id);
DMRETURN_IF_FAIL(menu);
if (needRefresh || menu->actions().isEmpty()) { if (needRefresh || menu->actions().isEmpty()) {
d->m_idsRefreshedByAboutToShow << id; d->m_idsRefreshedByAboutToShow << id;
d->refresh(id); d->refresh(id);
} else { } else if (menu) {
menuUpdated(); menuUpdated(menu);
} }
} }

@ -69,7 +69,7 @@ Q_SIGNALS:
* Emitted after a call to updateMenu(). * Emitted after a call to updateMenu().
* @see updateMenu() * @see updateMenu()
*/ */
void menuUpdated(); void menuUpdated(QMenu *);
/** /**
* Emitted when the exporter was asked to activate an action * Emitted when the exporter was asked to activate an action

Loading…
Cancel
Save