Move the activity action behavior on the C++ side
authorKevin Ottens <kevin.ottens@nextcloud.com>
Wed, 7 Oct 2020 11:23:34 +0000 (13:23 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Thu, 22 Oct 2020 14:40:46 +0000 (16:40 +0200)
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 <kevin.ottens@nextcloud.com>
src/gui/tray/ActivityListModel.cpp
src/gui/tray/ActivityListModel.h
src/gui/tray/Window.qml

index 89c9e2804b207d1f073e42b7b0dca54dbec3d2c1..3887093b705bc704e9e947d821ef55597f53334f 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <QtCore>
 #include <QAbstractListModel>
+#include <QDesktopServices>
 #include <QWidget>
 #include <QJsonObject>
 #include <QJsonDocument>
@@ -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;
index fd7da9aa43cf57949c0a69b8f9a1b01b5f75cd39..f09d39d66e0d30ef3b7c6ce01b13642ff8d90f93 100644 (file)
@@ -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();
index 4299b7707799384f6ce0bb705af2bb7d0696beaf..d06260a46831e686c007cf26ea1533c54310c014 100644 (file)
@@ -542,13 +542,7 @@ Window {
                     height: parent.height\r
                     anchors.margins: 2\r
                     hoverEnabled: true\r
-                    onClicked: {\r
-                        if (path !== "") {\r
-                            Qt.openUrlExternally(path)\r
-                        } else {\r
-                            Qt.openUrlExternally(link)\r
-                        }\r
-                    }\r
+                    onClicked: activityModel.triggerActionAtIndex(model.index)\r
 \r
                     Rectangle {\r
                         anchors.fill: parent\r