Changeset View
Changeset View
Standalone View
Standalone View
libdbusmenuqt/dbusmenuimporter.cpp
Show All 14 Lines | 1 | /* This file is part of the dbusmenu-qt library | |||
---|---|---|---|---|---|
15 | 15 | | |||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License | ||
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
19 | Boston, MA 02110-1301, USA. | 19 | Boston, MA 02110-1301, USA. | ||
20 | */ | 20 | */ | ||
21 | #include "dbusmenuimporter.h" | 21 | #include "dbusmenuimporter.h" | ||
22 | 22 | | |||
23 | #include "debug.h" | ||||
24 | | ||||
23 | // Qt | 25 | // Qt | ||
24 | #include <QCoreApplication> | 26 | #include <QCoreApplication> | ||
25 | #include <QDBusConnection> | 27 | #include <QDBusConnection> | ||
26 | #include <QDBusInterface> | 28 | #include <QDBusInterface> | ||
27 | #include <QDBusReply> | 29 | #include <QDBusReply> | ||
28 | #include <QDBusVariant> | 30 | #include <QDBusVariant> | ||
29 | #include <QFont> | 31 | #include <QFont> | ||
30 | #include <QMenu> | 32 | #include <QMenu> | ||
Show All 14 Lines | |||||
45 | #include "dbusmenu_interface.h" | 47 | #include "dbusmenu_interface.h" | ||
46 | 48 | | |||
47 | //#define BENCHMARK | 49 | //#define BENCHMARK | ||
48 | #ifdef BENCHMARK | 50 | #ifdef BENCHMARK | ||
49 | static QTime sChrono; | 51 | static QTime sChrono; | ||
50 | #endif | 52 | #endif | ||
51 | 53 | | |||
52 | #define DMRETURN_IF_FAIL(cond) if (!(cond)) { \ | 54 | #define DMRETURN_IF_FAIL(cond) if (!(cond)) { \ | ||
53 | qWarning() << "Condition failed: " #cond; \ | 55 | qCWarning(DBUSMENUQT) << "Condition failed: " #cond; \ | ||
54 | return; \ | 56 | return; \ | ||
55 | } | 57 | } | ||
56 | 58 | | |||
57 | static const char *DBUSMENU_PROPERTY_ID = "_dbusmenu_id"; | 59 | static const char *DBUSMENU_PROPERTY_ID = "_dbusmenu_id"; | ||
58 | static const char *DBUSMENU_PROPERTY_ICON_NAME = "_dbusmenu_icon_name"; | 60 | static const char *DBUSMENU_PROPERTY_ICON_NAME = "_dbusmenu_icon_name"; | ||
59 | static const char *DBUSMENU_PROPERTY_ICON_DATA_HASH = "_dbusmenu_icon_data_hash"; | 61 | static const char *DBUSMENU_PROPERTY_ICON_DATA_HASH = "_dbusmenu_icon_data_hash"; | ||
60 | 62 | | |||
61 | static QAction *createKdeTitle(QAction *action, QWidget *parent) | 63 | static QAction *createKdeTitle(QAction *action, QWidget *parent) | ||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Line(s) | 177 | } else if (key == QLatin1String("icon-name")) { | |||
176 | updateActionIconByName(action, value); | 178 | updateActionIconByName(action, value); | ||
177 | } else if (key == QLatin1String("icon-data")) { | 179 | } else if (key == QLatin1String("icon-data")) { | ||
178 | updateActionIconByData(action, value); | 180 | updateActionIconByData(action, value); | ||
179 | } else if (key == QLatin1String("visible")) { | 181 | } else if (key == QLatin1String("visible")) { | ||
180 | updateActionVisible(action, value); | 182 | updateActionVisible(action, value); | ||
181 | } else if (key == QLatin1String("shortcut")) { | 183 | } else if (key == QLatin1String("shortcut")) { | ||
182 | updateActionShortcut(action, value); | 184 | updateActionShortcut(action, value); | ||
183 | } else { | 185 | } else { | ||
184 | qWarning() << "Unhandled property update" << key; | 186 | qDebug(DBUSMENUQT) << "Unhandled property update" << key; | ||
185 | } | 187 | } | ||
186 | } | 188 | } | ||
187 | 189 | | |||
188 | void updateActionLabel(QAction *action, const QVariant &value) | 190 | void updateActionLabel(QAction *action, const QVariant &value) | ||
189 | { | 191 | { | ||
190 | QString text = swapMnemonicChar(value.toString(), '_', '&'); | 192 | QString text = swapMnemonicChar(value.toString(), '_', '&'); | ||
191 | action->setText(text); | 193 | action->setText(text); | ||
192 | } | 194 | } | ||
Show All 31 Lines | 224 | { | |||
224 | uint dataHash = qHash(data); | 226 | uint dataHash = qHash(data); | ||
225 | uint previousDataHash = action->property(DBUSMENU_PROPERTY_ICON_DATA_HASH).toUInt(); | 227 | uint previousDataHash = action->property(DBUSMENU_PROPERTY_ICON_DATA_HASH).toUInt(); | ||
226 | if (previousDataHash == dataHash) { | 228 | if (previousDataHash == dataHash) { | ||
227 | return; | 229 | return; | ||
228 | } | 230 | } | ||
229 | action->setProperty(DBUSMENU_PROPERTY_ICON_DATA_HASH, dataHash); | 231 | action->setProperty(DBUSMENU_PROPERTY_ICON_DATA_HASH, dataHash); | ||
230 | QPixmap pix; | 232 | QPixmap pix; | ||
231 | if (!pix.loadFromData(data)) { | 233 | if (!pix.loadFromData(data)) { | ||
232 | qWarning() << "Failed to decode icon-data property for action" << action->text(); | 234 | qDebug(DBUSMENUQT) << "Failed to decode icon-data property for action" << action->text(); | ||
233 | action->setIcon(QIcon()); | 235 | action->setIcon(QIcon()); | ||
234 | return; | 236 | return; | ||
235 | } | 237 | } | ||
236 | action->setIcon(QIcon(pix)); | 238 | action->setIcon(QIcon(pix)); | ||
237 | } | 239 | } | ||
238 | 240 | | |||
239 | void updateActionVisible(QAction *action, const QVariant &value) | 241 | void updateActionVisible(QAction *action, const QVariant &value) | ||
240 | { | 242 | { | ||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Line(s) | |||||
377 | { | 379 | { | ||
378 | int parentId = watcher->property(DBUSMENU_PROPERTY_ID).toInt(); | 380 | int parentId = watcher->property(DBUSMENU_PROPERTY_ID).toInt(); | ||
379 | watcher->deleteLater(); | 381 | watcher->deleteLater(); | ||
380 | 382 | | |||
381 | QMenu *menu = d->menuForId(parentId); | 383 | QMenu *menu = d->menuForId(parentId); | ||
382 | 384 | | |||
383 | QDBusPendingReply<uint, DBusMenuLayoutItem> reply = *watcher; | 385 | QDBusPendingReply<uint, DBusMenuLayoutItem> reply = *watcher; | ||
384 | if (!reply.isValid()) { | 386 | if (!reply.isValid()) { | ||
385 | qWarning() << reply.error().message(); | 387 | qDebug(DBUSMENUQT) << reply.error().message(); | ||
386 | if (menu) { | 388 | if (menu) { | ||
387 | emit menuUpdated(menu); | 389 | emit menuUpdated(menu); | ||
388 | } | 390 | } | ||
389 | return; | 391 | return; | ||
390 | } | 392 | } | ||
391 | 393 | | |||
392 | #ifdef BENCHMARK | 394 | #ifdef BENCHMARK | ||
393 | DMDEBUG << "- items received:" << sChrono.elapsed() << "ms"; | 395 | DMDEBUG << "- items received:" << sChrono.elapsed() << "ms"; | ||
394 | #endif | 396 | #endif | ||
395 | DBusMenuLayoutItem rootItem = reply.argumentAt<1>(); | 397 | DBusMenuLayoutItem rootItem = reply.argumentAt<1>(); | ||
396 | 398 | | |||
397 | if (!menu) { | 399 | if (!menu) { | ||
398 | qWarning() << "No menu for id" << parentId; | 400 | qDebug(DBUSMENUQT) << "No menu for id" << parentId; | ||
399 | return; | 401 | return; | ||
400 | } | 402 | } | ||
401 | 403 | | |||
402 | //remove outdated actions | 404 | //remove outdated actions | ||
403 | QSet<int> newDBusMenuItemIds; | 405 | QSet<int> newDBusMenuItemIds; | ||
404 | newDBusMenuItemIds.reserve(rootItem.children.count()); | 406 | newDBusMenuItemIds.reserve(rootItem.children.count()); | ||
405 | for (const DBusMenuLayoutItem &item: rootItem.children) { | 407 | for (const DBusMenuLayoutItem &item: rootItem.children) { | ||
406 | newDBusMenuItemIds << item.id; | 408 | newDBusMenuItemIds << item.id; | ||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Line(s) | 488 | { | |||
489 | 491 | | |||
490 | QMenu *menu = d->menuForId(id); | 492 | QMenu *menu = d->menuForId(id); | ||
491 | if (!menu) { | 493 | if (!menu) { | ||
492 | return; | 494 | return; | ||
493 | } | 495 | } | ||
494 | 496 | | |||
495 | QDBusPendingReply<bool> reply = *watcher; | 497 | QDBusPendingReply<bool> reply = *watcher; | ||
496 | if (reply.isError()) { | 498 | if (reply.isError()) { | ||
497 | qWarning() << "Call to AboutToShow() failed:" << reply.error().message(); | 499 | qDebug(DBUSMENUQT) << "Call to AboutToShow() failed:" << reply.error().message(); | ||
498 | menuUpdated(menu); | 500 | menuUpdated(menu); | ||
499 | return; | 501 | return; | ||
500 | } | 502 | } | ||
501 | //Note, this isn't used by Qt's QPT - but we get a LayoutChanged emitted before | 503 | //Note, this isn't used by Qt's QPT - but we get a LayoutChanged emitted before | ||
502 | //this returns, which equates to the same thing | 504 | //this returns, which equates to the same thing | ||
503 | bool needRefresh = reply.argumentAt<0>(); | 505 | bool needRefresh = reply.argumentAt<0>(); | ||
504 | 506 | | |||
505 | if (needRefresh || menu->actions().isEmpty()) { | 507 | if (needRefresh || menu->actions().isEmpty()) { | ||
Show All 38 Lines |