From: Kevin Ottens Date: Wed, 7 Oct 2020 11:23:34 +0000 (+0200) Subject: Move the activity action behavior on the C++ side X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~22^2~95^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=4116c90c9cb0ee0e0a37affc3903e2965548b252;p=nextcloud-desktop.git 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 --- 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