From 4116c90c9cb0ee0e0a37affc3903e2965548b252 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Wed, 7 Oct 2020 13:23:34 +0200 Subject: [PATCH] Move the activity action behavior on the C++ side We better do this before this business logic grows in the QML side and gets out of control. We'll need finer grained information due to the conflict handling anyway. Signed-off-by: Kevin Ottens --- src/gui/tray/ActivityListModel.cpp | 18 ++++++++++++++++++ src/gui/tray/ActivityListModel.h | 2 ++ src/gui/tray/Window.qml | 8 +------- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/gui/tray/ActivityListModel.cpp b/src/gui/tray/ActivityListModel.cpp index 89c9e2804..3887093b7 100644 --- a/src/gui/tray/ActivityListModel.cpp +++ b/src/gui/tray/ActivityListModel.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -416,6 +417,23 @@ void ActivityListModel::removeActivityFromActivityList(Activity activity) } } +void ActivityListModel::triggerActionAtIndex(int id) const +{ + if (id < 0 || id >= _finalList.size()) { + qCWarning(lcActivity) << "Couldn't trigger action at index" << id << "/ final list size:" << _finalList.size(); + return; + } + + const auto modelIndex = index(id); + const auto path = data(modelIndex, PathRole).toUrl(); + if (path.isValid()) { + QDesktopServices::openUrl(path); + } else { + const auto link = data(modelIndex, LinkRole).toUrl(); + QDesktopServices::openUrl(link); + } +} + void ActivityListModel::combineActivityLists() { ActivityList resultList; diff --git a/src/gui/tray/ActivityListModel.h b/src/gui/tray/ActivityListModel.h index fd7da9aa4..f09d39d66 100644 --- a/src/gui/tray/ActivityListModel.h +++ b/src/gui/tray/ActivityListModel.h @@ -74,6 +74,8 @@ public: void removeActivityFromActivityList(int row); void removeActivityFromActivityList(Activity activity); + Q_INVOKABLE void triggerActionAtIndex(int id) const; + public slots: void slotRefreshActivity(); void slotRemoveAccount(); diff --git a/src/gui/tray/Window.qml b/src/gui/tray/Window.qml index 4299b7707..d06260a46 100644 --- a/src/gui/tray/Window.qml +++ b/src/gui/tray/Window.qml @@ -542,13 +542,7 @@ Window { height: parent.height anchors.margins: 2 hoverEnabled: true - onClicked: { - if (path !== "") { - Qt.openUrlExternally(path) - } else { - Qt.openUrlExternally(link) - } - } + onClicked: activityModel.triggerActionAtIndex(model.index) Rectangle { anchors.fill: parent -- 2.30.2