aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src
diff options
context:
space:
mode:
authorBileto Bot <ci-train-bot@canonical.com>2017-03-16 16:55:30 +0000
committerBileto Bot <ci-train-bot@canonical.com>2017-03-16 16:55:30 +0000
commitf0aa8c3ebfa80e7a44afe630053fe818e240b9f1 (patch)
treeec2a1af8af851972dc41e3707d70109104a5ea83 /libqmenumodel/src
parente2b335b0ccb0b156283a320c2e1b7a2f4063b70b (diff)
parent5c4aae110e361f292b534d3a31a6b4c275e8963d (diff)
downloadqmenumodel-f0aa8c3ebfa80e7a44afe630053fe818e240b9f1.tar.gz
qmenumodel-f0aa8c3ebfa80e7a44afe630053fe818e240b9f1.tar.bz2
qmenumodel-f0aa8c3ebfa80e7a44afe630053fe818e240b9f1.zip
Add UnityMenuModel::aboutToShow ((LP: 1664578)
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r--libqmenumodel/src/unitymenumodel.cpp43
-rw-r--r--libqmenumodel/src/unitymenumodel.h3
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