Use APPLICATION_ICON_SET for themed icons
authorKevin Ottens <kevin.ottens@nextcloud.com>
Wed, 20 Jan 2021 14:11:57 +0000 (15:11 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Wed, 20 Jan 2021 14:11:57 +0000 (15:11 +0100)
We now favor APPLICATION_ICON_SET to isBranded() regarding the decision
to use PNG or SVG for icons.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/libsync/theme.cpp

index 93487134f3acd1713aae9491e4cc9a6badc9f010..be3bde5e6a5d026444321b65b1d9e418da011bca 100644 (file)
@@ -192,10 +192,11 @@ QIcon Theme::themeIcon(const QString &name, bool sysTray) const
             return QPixmap(pixmapName);
         };
 
-        const auto sizes = isBranded() ? QVector<int>{ 16, 22, 32, 48, 64, 128, 256, 512, 1024 }
-                                       : QVector<int>{ 16, 32, 64, 128, 256 };
+        const auto useSvg = shouldPreferSvg();
+        const auto sizes = useSvg ? QVector<int>{ 16, 32, 64, 128, 256 }
+                                  : QVector<int>{ 16, 22, 32, 48, 64, 128, 256, 512, 1024 };
         for (int size : sizes) {
-            auto px = isBranded() ? loadPixmap(size) : createPixmapFromSvg(size);
+            auto px = useSvg ? createPixmapFromSvg(size) : loadPixmap(size);
             if (px.isNull()) {
                 continue;
             }
@@ -224,20 +225,25 @@ QIcon Theme::themeIcon(const QString &name, bool sysTray) const
 QString Theme::themeImagePath(const QString &name, int size, bool sysTray) const
 {
     const auto flavor = (!isBranded() && sysTray) ? systrayIconFlavor(_mono) : QLatin1String("colored");
+    const auto useSvg = shouldPreferSvg();
 
     // branded client may have several sizes of the same icon
-    const QString filePath = (isBranded() && size > 0)
-            ? QString::fromLatin1(":/client/theme/%1/%2-%3").arg(flavor).arg(name).arg(size)
-            : QString::fromLatin1(":/client/theme/%1/%2").arg(flavor).arg(name);
-
-    const QString brandedImagePath = filePath + ".png";
+    const QString filePath = (useSvg || size <= 0)
+            ? QString::fromLatin1(":/client/theme/%1/%2").arg(flavor).arg(name)
+            : QString::fromLatin1(":/client/theme/%1/%2-%3").arg(flavor).arg(name).arg(size);
 
-    // only return branded .png image path if it exists, or fall-back to non-branded .svg otherwise
-    if (isBranded() && QFile::exists(brandedImagePath)) {
-        return brandedImagePath;
+    const QString svgPath = filePath + ".svg";
+    if (useSvg) {
+        return svgPath;
     }
 
-    return filePath + ".svg";
+    const QString pngPath = filePath + ".png";
+    // Use the SVG as fallback if a PNG is missing so that we get a chance to display something
+    if (QFile::exists(pngPath)) {
+        return pngPath;
+    } else {
+        return svgPath;
+    }
 }
 
 QIcon Theme::uiThemeIcon(const QString &iconName, bool uiHasDarkBg) const