Skip to content

Commit

Permalink
Merge pull request #4748 from nextcloud/feature/open-local-files
Browse files Browse the repository at this point in the history
Clicking on an activity list item for a file opens the local file if available
  • Loading branch information
claucambra authored Aug 2, 2022
2 parents 84f6d62 + 7891792 commit be2ed7a
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/gui/tray/ActivityList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ScrollView {

property bool isFileActivityList: false

signal showFileActivity(string objectName, int objectId)
signal openFile(string filePath)
signal activityItemClicked(int index)

contentWidth: availableWidth
Expand Down Expand Up @@ -38,8 +38,8 @@ ScrollView {
width: activityList.contentWidth
flickable: activityList
onClicked: {
if (model.isCurrentUserFileActivity) {
showFileActivity(model.objectName, model.objectId)
if (model.isCurrentUserFileActivity && model.openablePath) {
openFile("file://" + model.openablePath);
} else {
activityItemClicked(model.index)
}
Expand Down
4 changes: 1 addition & 3 deletions src/gui/tray/Window.qml
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,7 @@ Window {

activeFocusOnTab: true
model: activityModel
onShowFileActivity: {
openFileActivityDialog(objectName, objectId)
}
onOpenFile: Qt.openUrlExternally(filePath);
onActivityItemClicked: {
model.slotTriggerDefaultAction(index)
}
Expand Down
1 change: 1 addition & 0 deletions src/gui/tray/activitydata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ OCC::Activity Activity::fromActivityJson(const QJsonObject &json, const AccountP
activity._dateTime = QDateTime::fromString(json.value(QStringLiteral("datetime")).toString(), Qt::ISODate);
activity._icon = json.value(QStringLiteral("icon")).toString();
activity._isCurrentUserFileActivity = activity._objectType == QStringLiteral("files") && activityUser == account->davUser();
activity._isMultiObjectActivity = json.value("objects").toObject().count() > 1;

auto richSubjectData = json.value(QStringLiteral("subject_rich")).toArray();

Expand Down
2 changes: 2 additions & 0 deletions src/gui/tray/activitydata.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Activity
static Activity fromActivityJson(const QJsonObject &json, const AccountPtr account);

static QString relativeServerFileTypeIconPath(const QMimeType &mimeType);
static QString localFilePathForActivity(const Activity &activity, const AccountPtr account);

struct RichSubjectParameter {
QString type; // Required
Expand Down Expand Up @@ -133,6 +134,7 @@ class Activity
QString _folder;
QString _file;
QString _renamedFile;
bool _isMultiObjectActivity;
QUrl _link;
QDateTime _dateTime;
qint64 _expireAtMsecs = -1;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/tray/activitylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ QHash<int, QByteArray> ActivityListModel::roleNames() const
auto roles = QAbstractListModel::roleNames();
roles[DisplayPathRole] = "displayPath";
roles[PathRole] = "path";
roles[OpenablePathRole] = "openablePath";
roles[DisplayLocationRole] = "displayLocation";
roles[LinkRole] = "link";
roles[MessageRole] = "message";
Expand All @@ -77,6 +78,7 @@ QHash<int, QByteArray> ActivityListModel::roleNames() const
roles[DisplayActions] = "displayActions";
roles[ShareableRole] = "isShareable";
roles[IsCurrentUserFileActivityRole] = "isCurrentUserFileActivity";
roles[IsCurrentUserFileActivityRole] = "isCurrentUserFileActivity";
roles[ThumbnailRole] = "thumbnail";
roles[TalkNotificationConversationTokenRole] = "conversationToken";
roles[TalkNotificationMessageIdRole] = "messageId";
Expand Down Expand Up @@ -263,6 +265,8 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
return getDisplayPath();
case PathRole:
return QFileInfo(getFilePath()).path();
case OpenablePathRole:
return a._isMultiObjectActivity ? QFileInfo(getFilePath()).canonicalPath() : QFileInfo(getFilePath()).canonicalFilePath();
case DisplayLocationRole:
return displayLocation();
case ActionsLinksRole: {
Expand Down
1 change: 1 addition & 0 deletions src/gui/tray/activitylistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class ActivityListModel : public QAbstractListModel
MessageRole,
DisplayPathRole,
PathRole,
OpenablePathRole,
DisplayLocationRole, // Provides the display path to a file's parent folder, relative to Nextcloud root
LinkRole,
PointInTimeRole,
Expand Down

0 comments on commit be2ed7a

Please sign in to comment.