Skip to content

Commit

Permalink
Merge pull request #7567 from nextcloud/bugfix/activity-icon-colours
Browse files Browse the repository at this point in the history
gui/tray: Fix activity icon colours
  • Loading branch information
mgallien authored Dec 9, 2024
2 parents 0fb2e93 + d921411 commit d8f1df9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/gui/tray/ActivityItemContent.qml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ RowLayout {

cache: true
fillMode: Image.PreserveAspectFit
source: Style.darkMode ? model.darkIcon : model.lightIcon
source: model.icon + "/" + palette.text
sourceSize.height: 64
sourceSize.width: 64
mipmap: true // Addresses grainy downscale
Expand Down
25 changes: 7 additions & 18 deletions src/gui/tray/activitylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ QHash<int, QByteArray> ActivityListModel::roleNames() const
roles[LinkRole] = "link";
roles[MessageRole] = "message";
roles[ActionRole] = "type";
roles[DarkIconRole] = "darkIcon";
roles[LightIconRole] = "lightIcon";
roles[IconRole] = "icon";
roles[ActionTextRole] = "subject";
roles[ActionsLinksRole] = "links";
roles[ActionsLinksContextMenuRole] = "linksContextMenu";
Expand Down Expand Up @@ -226,7 +225,7 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
};

const auto generateIconPath = [&]() {
auto colorIconPath = role == DarkIconRole ? QStringLiteral("image://svgimage-custom-color/%1/white") : QStringLiteral("image://svgimage-custom-color/%1/black");
auto colorIconPath = QStringLiteral("image://svgimage-custom-color/%1");
if (a._type == Activity::NotificationType && !a._talkNotificationData.userAvatar.isEmpty()) {
return QStringLiteral("image://svgimage-custom-color/talk-bordered.svg");
} else if (a._type == Activity::SyncResultType) {
Expand All @@ -250,24 +249,16 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
} else {
// File sync successful
if (a._fileAction == "file_created") {
return a._previews.empty() ? QStringLiteral("image://svgimage-custom-color/add.svg/")
: QStringLiteral("image://svgimage-custom-color/add-bordered.svg/");
return a._previews.empty() ? colorIconPath.arg("add.svg") : colorIconPath.arg("add-bordered.svg");
} else if (a._fileAction == "file_deleted") {
return a._previews.empty() ? QStringLiteral("image://svgimage-custom-color/delete.svg/")
: QStringLiteral("image://svgimage-custom-color/delete-bordered.svg/");
return a._previews.empty() ? colorIconPath.arg("delete.svg") : colorIconPath.arg("delete-bordered.svg");
} else {
return a._previews.empty() ? colorIconPath.arg(QStringLiteral("change.svg"))
: QStringLiteral("image://svgimage-custom-color/change-bordered.svg/");
return a._previews.empty() ? colorIconPath.arg("change.svg") : colorIconPath.arg("change-bordered.svg");
}
}
} else {
// We have an activity
if (a._icon.isEmpty()) {
return colorIconPath.arg("activity.svg");
}

const QString basePath = QStringLiteral("image://tray-image-provider/") % a._icon % QStringLiteral("/");
return role == DarkIconRole ? QString(basePath + QStringLiteral("white")) : QString(basePath + QStringLiteral("black"));
return a._icon.isEmpty() ? colorIconPath.arg("activity.svg") : colorIconPath.arg(a._icon);
}
};

Expand Down Expand Up @@ -296,10 +287,8 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
return ActivityListModel::convertLinksToActionButtons(a);
}

case DarkIconRole:
case LightIconRole: {
case IconRole:
return generateIconPath();
}
case ObjectTypeRole:
return a._objectType;
case ObjectIdRole:
Expand Down
3 changes: 1 addition & 2 deletions src/gui/tray/activitylistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class ActivityListModel : public QAbstractListModel

public:
enum DataRole {
DarkIconRole = Qt::UserRole + 1,
LightIconRole,
IconRole = Qt::UserRole + 1,
AccountRole,
ObjectTypeRole,
ObjectIdRole,
Expand Down
3 changes: 1 addition & 2 deletions test/testactivitylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ private slots:

QVERIFY(!index.data(OCC::ActivityListModel::AccountRole).toString().isEmpty());
QVERIFY(!index.data(OCC::ActivityListModel::ActionTextColorRole).toString().isEmpty());
QVERIFY(!index.data(OCC::ActivityListModel::DarkIconRole).toString().isEmpty());
QVERIFY(!index.data(OCC::ActivityListModel::LightIconRole).toString().isEmpty());
QVERIFY(!index.data(OCC::ActivityListModel::IconRole).toString().isEmpty());
QVERIFY(!index.data(OCC::ActivityListModel::PointInTimeRole).toString().isEmpty());

QVERIFY(index.data(OCC::ActivityListModel::ObjectTypeRole).canConvert<int>());
Expand Down

0 comments on commit d8f1df9

Please sign in to comment.