From 7579572643413c5d399ec2bee6339ab20232c8cf Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Mon, 6 Mar 2017 15:55:12 +0100 Subject: Call about to show for those items that have a qtubuntu-tag property --- libqmenumodel/src/unitymenumodel.cpp | 43 +++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'libqmenumodel/src/unitymenumodel.cpp') diff --git a/libqmenumodel/src/unitymenumodel.cpp b/libqmenumodel/src/unitymenumodel.cpp index 192ee46..ebadaf7 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; + } + + GtkMenuTrackerItem *item = (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) { + UnityMenuModel *pModel = dynamic_cast(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, + 0, + nullptr, + nullptr, + nullptr); + } + } +} + void UnityMenuModel::activateByVariantString(int index, const QString& parameter) { activate(index, Converter::toQVariantFromVariantString(parameter)); -- cgit v1.2.3