diff options
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r-- | libqmenumodel/src/unitymenumodel.cpp | 43 | ||||
-rw-r--r-- | libqmenumodel/src/unitymenumodel.h | 3 |
2 files changed, 44 insertions, 2 deletions
diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp index 658fdca..d9dc542 100644 --- a/libqmenumodel/src/unitymenumodel.cpp +++ b/libqmenumodel/src/unitymenumodel.cpp @@ -289,7 +289,7 @@ UnityMenuModel::UnityMenuModel(QObject *parent): priv = new UnityMenuModelPrivate(this); } -UnityMenuModel::UnityMenuModel(const UnityMenuModelPrivate& other, QObject *parent): +UnityMenuModel::UnityMenuModel(const UnityMenuModelPrivate& other, UnityMenuModel *parent): QAbstractListModel(parent) { priv = new UnityMenuModelPrivate(other, this); @@ -729,6 +729,47 @@ void UnityMenuModel::activate(int index, const QVariant& parameter) } } +void UnityMenuModel::aboutToShow(int index) +{ + GSequenceIter *it = g_sequence_get_iter_at_pos (priv->items, index); + if (g_sequence_iter_is_end (it)) { + return; + } + + auto item = static_cast<GtkMenuTrackerItem*>(g_sequence_get(it)); + if (!item) { + return; + } + + quint64 actionTag; + if (gtk_menu_tracker_item_get_attribute (item, "qtubuntu-tag", "t", &actionTag)) { + // Child UnityMenuModel have priv->connection null, so climb to the parent until we find a non null one + UnityMenuModelPrivate *privToUse = priv; + while (privToUse && !privToUse->connection) { + auto pModel = dynamic_cast<UnityMenuModel*>(privToUse->model->QObject::parent()); + if (pModel) { + privToUse = pModel->priv; + } else { + privToUse = nullptr; + } + } + if (privToUse) { + g_dbus_connection_call (privToUse->connection, + privToUse->busName, + privToUse->menuObjectPath, + "qtubuntu.actions.extra", + "aboutToShow", + g_variant_new("(t)", actionTag), + nullptr, + G_DBUS_CALL_FLAGS_NO_AUTO_START, + G_MAXINT, + nullptr, + nullptr, + nullptr); + } + } +} + void UnityMenuModel::activateByVariantString(int index, const QString& parameter) { activate(index, Converter::toQVariantFromVariantString(parameter)); diff --git a/libqmenumodel/src/unitymenumodel.h b/libqmenumodel/src/unitymenumodel.h index ed3bcd7..1a2a190 100644 --- a/libqmenumodel/src/unitymenumodel.h +++ b/libqmenumodel/src/unitymenumodel.h @@ -63,6 +63,7 @@ public: Q_INVOKABLE QVariant get(int row, const QByteArray &role); Q_INVOKABLE void activate(int index, const QVariant& parameter = QVariant()); + Q_INVOKABLE void aboutToShow(int index); Q_INVOKABLE void activateByVariantString(int index, const QString& parameter = QString()); Q_INVOKABLE void changeState(int index, const QVariant& parameter); Q_INVOKABLE void changeStateByVariantString(int index, const QString& parameter); @@ -90,7 +91,7 @@ private: class UnityMenuModelPrivate *priv; friend class UnityMenuModelPrivate; - UnityMenuModel(const UnityMenuModelPrivate& other, QObject *parent); + UnityMenuModel(const UnityMenuModelPrivate& other, UnityMenuModel *parent); }; #endif |