Changeset View
Changeset View
Standalone View
Standalone View
libdbusmenuqt/dbusmenuimporter.cpp
Show First 20 Lines • Show All 369 Lines • ▼ Show 20 Line(s) | 367 | { | |||
---|---|---|---|---|---|
370 | actionActivationRequested(action); | 370 | actionActivationRequested(action); | ||
371 | } | 371 | } | ||
372 | 372 | | |||
373 | void DBusMenuImporter::slotGetLayoutFinished(QDBusPendingCallWatcher *watcher) | 373 | void DBusMenuImporter::slotGetLayoutFinished(QDBusPendingCallWatcher *watcher) | ||
374 | { | 374 | { | ||
375 | int parentId = watcher->property(DBUSMENU_PROPERTY_ID).toInt(); | 375 | int parentId = watcher->property(DBUSMENU_PROPERTY_ID).toInt(); | ||
376 | watcher->deleteLater(); | 376 | watcher->deleteLater(); | ||
377 | 377 | | |||
378 | QMenu *menu = d->menuForId(parentId); | ||||
379 | | ||||
378 | QDBusPendingReply<uint, DBusMenuLayoutItem> reply = *watcher; | 380 | QDBusPendingReply<uint, DBusMenuLayoutItem> reply = *watcher; | ||
379 | if (!reply.isValid()) { | 381 | if (!reply.isValid()) { | ||
380 | qWarning() << reply.error().message(); | 382 | qWarning() << reply.error().message(); | ||
381 | 383 | if (menu) { | |||
382 | emit menuUpdated(); | 384 | emit menuUpdated(menu); | ||
385 | } | ||||
383 | return; | 386 | return; | ||
384 | } | 387 | } | ||
385 | 388 | | |||
386 | #ifdef BENCHMARK | 389 | #ifdef BENCHMARK | ||
387 | DMDEBUG << "- items received:" << sChrono.elapsed() << "ms"; | 390 | DMDEBUG << "- items received:" << sChrono.elapsed() << "ms"; | ||
388 | #endif | 391 | #endif | ||
389 | DBusMenuLayoutItem rootItem = reply.argumentAt<1>(); | 392 | DBusMenuLayoutItem rootItem = reply.argumentAt<1>(); | ||
390 | 393 | | |||
391 | QMenu *menu = d->menuForId(parentId); | | |||
392 | if (!menu) { | 394 | if (!menu) { | ||
393 | qWarning() << "No menu for id" << parentId; | 395 | qWarning() << "No menu for id" << parentId; | ||
394 | return; | 396 | return; | ||
395 | } | 397 | } | ||
396 | 398 | | |||
397 | //remove outdated actions | 399 | //remove outdated actions | ||
398 | QSet<int> newDBusMenuItemIds; | 400 | QSet<int> newDBusMenuItemIds; | ||
399 | newDBusMenuItemIds.reserve(rootItem.children.count()); | 401 | newDBusMenuItemIds.reserve(rootItem.children.count()); | ||
Show All 38 Lines | 438 | } else { | |||
438 | QStringList filteredKeys = dbusMenuItem.properties.keys(); | 440 | QStringList filteredKeys = dbusMenuItem.properties.keys(); | ||
439 | filteredKeys.removeOne("type"); | 441 | filteredKeys.removeOne("type"); | ||
440 | filteredKeys.removeOne("toggle-type"); | 442 | filteredKeys.removeOne("toggle-type"); | ||
441 | filteredKeys.removeOne("children-display"); | 443 | filteredKeys.removeOne("children-display"); | ||
442 | d->updateAction(*it, dbusMenuItem.properties, filteredKeys); | 444 | d->updateAction(*it, dbusMenuItem.properties, filteredKeys); | ||
443 | } | 445 | } | ||
444 | } | 446 | } | ||
445 | 447 | | |||
446 | emit menuUpdated(); | 448 | emit menuUpdated(menu); | ||
447 | } | 449 | } | ||
448 | 450 | | |||
449 | void DBusMenuImporter::sendClickedEvent(int id) | 451 | void DBusMenuImporter::sendClickedEvent(int id) | ||
450 | { | 452 | { | ||
451 | d->sendEvent(id, QStringLiteral("clicked")); | 453 | d->sendEvent(id, QStringLiteral("clicked")); | ||
452 | } | 454 | } | ||
453 | 455 | | |||
454 | void DBusMenuImporter::updateMenu() | 456 | void DBusMenuImporter::updateMenu() | ||
Show All 17 Lines | 473 | connect(watcher, &QDBusPendingCallWatcher::finished, this, | |||
472 | &DBusMenuImporter::slotAboutToShowDBusCallFinished); | 474 | &DBusMenuImporter::slotAboutToShowDBusCallFinished); | ||
473 | } | 475 | } | ||
474 | 476 | | |||
475 | void DBusMenuImporter::slotAboutToShowDBusCallFinished(QDBusPendingCallWatcher *watcher) | 477 | void DBusMenuImporter::slotAboutToShowDBusCallFinished(QDBusPendingCallWatcher *watcher) | ||
476 | { | 478 | { | ||
477 | int id = watcher->property(DBUSMENU_PROPERTY_ID).toInt(); | 479 | int id = watcher->property(DBUSMENU_PROPERTY_ID).toInt(); | ||
478 | watcher->deleteLater(); | 480 | watcher->deleteLater(); | ||
479 | 481 | | |||
482 | QMenu *menu = d->menuForId(id); | ||||
483 | | ||||
480 | QDBusPendingReply<bool> reply = *watcher; | 484 | QDBusPendingReply<bool> reply = *watcher; | ||
481 | if (reply.isError()) { | 485 | if (reply.isError()) { | ||
482 | menuUpdated(); | | |||
483 | qWarning() << "Call to AboutToShow() failed:" << reply.error().message(); | 486 | qWarning() << "Call to AboutToShow() failed:" << reply.error().message(); | ||
487 | if (menu) { | ||||
488 | menuUpdated(menu); | ||||
489 | } | ||||
484 | return; | 490 | return; | ||
485 | } | 491 | } | ||
486 | //Note, this isn't used by Qt's QPT - but we get a LayoutChanged emitted before | 492 | //Note, this isn't used by Qt's QPT - but we get a LayoutChanged emitted before | ||
487 | //this returns, which equates to the same thing | 493 | //this returns, which equates to the same thing | ||
488 | bool needRefresh = reply.argumentAt<0>(); | 494 | bool needRefresh = reply.argumentAt<0>(); | ||
489 | 495 | | |||
490 | QMenu *menu = d->menuForId(id); | | |||
491 | DMRETURN_IF_FAIL(menu); | | |||
492 | 496 | | |||
493 | if (needRefresh || menu->actions().isEmpty()) { | 497 | if (needRefresh || menu->actions().isEmpty()) { | ||
494 | d->m_idsRefreshedByAboutToShow << id; | 498 | d->m_idsRefreshedByAboutToShow << id; | ||
495 | d->refresh(id); | 499 | d->refresh(id); | ||
496 | } else { | 500 | } else if (menu) { | ||
497 | menuUpdated(); | 501 | menuUpdated(menu); | ||
498 | } | 502 | } | ||
499 | } | 503 | } | ||
500 | 504 | | |||
501 | void DBusMenuImporter::slotMenuAboutToHide() | 505 | void DBusMenuImporter::slotMenuAboutToHide() | ||
502 | { | 506 | { | ||
503 | QMenu *menu = qobject_cast<QMenu*>(sender()); | 507 | QMenu *menu = qobject_cast<QMenu*>(sender()); | ||
504 | Q_ASSERT(menu); | 508 | Q_ASSERT(menu); | ||
505 | 509 | | |||
Show All 30 Lines |