diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2020-11-04 14:34:35 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2020-11-04 19:21:52 +0300 |
commit | 09875801016842b9325274acf91d88946a8720d2 (patch) | |
tree | 964bbfd39c0594352c8dc60e53f1fe5a16b5c74a | |
parent | 0d1fa8177acc5b61ebd3bdc2555769226282891d (diff) |
Generate theme qrc automatically, fall back to core icons
-rw-r--r-- | cmake/modules/OCGenerateTheme.cmake | 46 | ||||
-rw-r--r-- | core_theme.qrc (renamed from theme.qrc) | 9 | ||||
-rw-r--r-- | src/gui/CMakeLists.txt | 26 | ||||
-rw-r--r-- | src/gui/aboutdialog.ui | 4 | ||||
-rw-r--r-- | src/gui/wizard/owncloudadvancedsetuppage.ui | 3 | ||||
-rw-r--r-- | src/libsync/owncloudtheme.cpp | 4 | ||||
-rw-r--r-- | src/libsync/theme.cpp | 57 | ||||
-rw-r--r-- | src/libsync/theme.h | 5 | ||||
-rw-r--r-- | src/libsync/vfs/CMakeLists.txt | 5 | ||||
-rw-r--r-- | theme/colored/128-owncloud-icon.png | bin | 2755 -> 0 bytes |
10 files changed, 111 insertions, 48 deletions
diff --git a/cmake/modules/OCGenerateTheme.cmake b/cmake/modules/OCGenerateTheme.cmake new file mode 100644 index 000000000..158454edb --- /dev/null +++ b/cmake/modules/OCGenerateTheme.cmake @@ -0,0 +1,46 @@ +function(__addIcon THEME ICON_NAME) + set(icon "theme/${THEME}/${ICON_NAME}.svg") + if (EXISTS ${OEM_THEME_DIR}/${icon}) + file(APPEND "${QRC}" "<file alias=\"${icon}\">${OEM_THEME_DIR}/${icon}</file>\n") + else() + set(SIZES "16;22,32;48;64;128;256;512;1024") + foreach(size ${SIZES}) + set(icon "theme/${THEME}/${ICON_NAME}-${size}.png") + if (EXISTS ${OEM_THEME_DIR}/${icon}) + file(APPEND "${QRC}" "<file alias=\"${icon}\">${OEM_THEME_DIR}/${icon}</file>\n") + endif() + endforeach() + endif() +endfunction() + +function(generate_theme TARGET) + if(NOT "${OEM_THEME_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}") + set(QRC ${CMAKE_BINARY_DIR}/theme.qrc) + file(WRITE "${QRC}" "<RCC>\n<qresource prefix=\"/client\">\n") + __addIcon("colored" "${APPLICATION_SHORTNAME}-icon") + + set(STATES "ok;error;information;offline;pause;sync") + set(THEMES "colored;dark;black;white") + foreach(theme ${THEMES}) + foreach(state ${STATES}) + __addIcon(${theme} "state-${state}") + endforeach() + endforeach() + file(APPEND "${QRC}" "</qresource>\n</RCC>\n") + target_sources(${TARGET} PRIVATE ${QRC}) + endif() +endfunction() + + +function(generate_legacy_icons theme_dir OUT) + # allow legacy file names + file(GLOB_RECURSE OWNCLOUD_ICONS_OLD "${theme_dir}/colored/${APPLICATION_ICON_NAME}-icon-*.png") + foreach(icon ${OWNCLOUD_ICONS_OLD}) + get_filename_component(icon_name ${icon} NAME) + string(REGEX MATCH "([0-9]+)" size ${icon_name}) + set(out_name "${CMAKE_BINARY_DIR}/${size}-app-icon.png") + configure_file(${icon} ${out_name} COPYONLY) + list(APPEND OWNCLOUD_ICONS ${out_name}) + endforeach() + set(${OUT} ${OWNCLOUD_ICONS} PARENT_SCOPE) +endfunction() diff --git a/theme.qrc b/core_theme.qrc index 85a5e88cf..a62eebb20 100644 --- a/theme.qrc +++ b/core_theme.qrc @@ -1,18 +1,13 @@ <RCC> - <qresource prefix="/client"> + <qresource prefix="/client/core"> <file alias="theme/black/state-ok.svg">theme/black/ui-light-plain-monochrom-state-checkmark.svg</file> <file alias="theme/black/state-error.svg">theme/black/ui-light-plain-monochrom-state-error.svg</file> <file alias="theme/black/state-information.svg">theme/black/ui-light-plain-monochrom-state-info.svg</file> <file alias="theme/black/state-offline.svg">theme/black/ui-light-plain-monochrom-state-offline.svg</file> <file alias="theme/black/state-pause.svg">theme/black/ui-light-plain-monochrom-state-pause.svg</file> <file alias="theme/black/state-sync.svg">theme/black/ui-light-plain-monochrom-state-sync.svg</file> - <file alias="theme/colored/owncloud-icon-128.png">theme/colored/128-owncloud-icon.png</file> - <file alias="theme/colored/owncloud-icon-256.png">theme/colored/256-owncloud-icon.png</file> - <file alias="theme/colored/owncloud-icon-32.png">theme/colored/32-owncloud-icon.png</file> - <file alias="theme/colored/owncloud-icon-48.png">theme/colored/48-owncloud-icon.png</file> - <file alias="theme/colored/owncloud-icon-512.png">theme/colored/512-owncloud-icon-sidebar.png</file> - <file alias="theme/colored/owncloud-icon-64.png">theme/colored/64-owncloud-icon.png</file> <file>theme/colored/oc-image-about.svg</file> + <file>theme/colored/owncloud-icon.svg</file> <file alias="theme/colored/state-ok.svg">theme/colored/ui-light-plain-color-state-checkmark.svg</file> <file alias="theme/colored/state-error.svg">theme/colored/ui-light-plain-color-state-error.svg</file> <file alias="theme/colored/state-information.svg">theme/colored/ui-light-plain-color-state-info.svg</file> diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 1568d1dc5..329218831 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -209,28 +209,18 @@ if(Qt5LinguistTools_FOUND) endif() #TODO Move resources files -target_sources(${APPLICATION_EXECUTABLE} PRIVATE ../../client.qrc) -if (EXISTS "${OEM_THEME_DIR}/theme.qrc") - target_sources(${APPLICATION_EXECUTABLE} PRIVATE ${OEM_THEME_DIR}/theme.qrc) - set(theme_dir ${OEM_THEME_DIR}/theme) -else() - target_sources(${APPLICATION_EXECUTABLE} PRIVATE ../../theme.qrc) - set(theme_dir ${CMAKE_SOURCE_DIR}/theme) -endif() +target_sources(${APPLICATION_EXECUTABLE} PRIVATE + ${PROJECT_SOURCE_DIR}/client.qrc + ${PROJECT_SOURCE_DIR}/core_theme.qrc) + +include(OCGenerateTheme) +generate_theme(${APPLICATION_EXECUTABLE}) +set(theme_dir ${OEM_THEME_DIR}/theme) # add executable icon on windows and osx file(GLOB_RECURSE OWNCLOUD_ICONS "${theme_dir}/colored/*-${APPLICATION_ICON_NAME}-icon.png") if (NOT OWNCLOUD_ICONS) - # allow legacy file names - file(GLOB_RECURSE OWNCLOUD_ICONS_OLD "${theme_dir}/colored/${APPLICATION_ICON_NAME}-icon-*.png") - MESSAGE(STATUS "OWNCLOUD_ICONS_OLD: ${APPLICATION_ICON_NAME}: ${OWNCLOUD_ICONS_OLD}") - foreach(icon ${OWNCLOUD_ICONS_OLD}) - get_filename_component(icon_name ${icon} NAME) - string(REGEX MATCH "([0-9]+)" size ${icon_name}) - set(out_name "${CMAKE_BINARY_DIR}/${size}-app-icon.png") - configure_file(${icon} ${out_name} COPYONLY) - list(APPEND OWNCLOUD_ICONS ${out_name}) - endforeach() + generate_legacy_icons(${theme_dir} OWNCLOUD_ICONS) endif() MESSAGE(STATUS "OWNCLOUD_ICONS: ${APPLICATION_ICON_NAME}: ${OWNCLOUD_ICONS}") diff --git a/src/gui/aboutdialog.ui b/src/gui/aboutdialog.ui index 1c404165c..e2cc10e17 100644 --- a/src/gui/aboutdialog.ui +++ b/src/gui/aboutdialog.ui @@ -57,7 +57,7 @@ <string notr="true"/> </property> <property name="pixmap"> - <pixmap resource="../../theme.qrc">:/client/theme/colored/owncloud-icon-256.png</pixmap> + <pixmap resource="../../core_theme.qrc">:/client/core/theme/colored/owncloud-icon.svg</pixmap> </property> </widget> </item> @@ -123,7 +123,7 @@ </layout> </widget> <resources> - <include location="../../theme.qrc"/> + <include location="../../core_theme.qrc"/> </resources> <connections> <connection> diff --git a/src/gui/wizard/owncloudadvancedsetuppage.ui b/src/gui/wizard/owncloudadvancedsetuppage.ui index 06f53b5ac..09dbb80b9 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.ui +++ b/src/gui/wizard/owncloudadvancedsetuppage.ui @@ -70,7 +70,7 @@ <string/> </property> <property name="pixmap"> - <pixmap resource="../../../theme.qrc">:/client/theme/colored/owncloud-icon-48.png</pixmap> + <pixmap>:/client/core/theme/colored/owncloud-icon.svg</pixmap> </property> <property name="scaledContents"> <bool>true</bool> @@ -580,7 +580,6 @@ </tabstops> <resources> <include location="../../../client.qrc"/> - <include location="../../../theme.qrc"/> </resources> <connections/> </ui> diff --git a/src/libsync/owncloudtheme.cpp b/src/libsync/owncloudtheme.cpp index 3e8eb6893..9e3061944 100644 --- a/src/libsync/owncloudtheme.cpp +++ b/src/libsync/owncloudtheme.cpp @@ -58,12 +58,12 @@ QColor ownCloudTheme::wizardHeaderSubTitleColor() const QIcon ownCloudTheme::wizardHeaderLogo() const { - return QIcon(QStringLiteral(":/client/theme/colored/wizard_logo.svg")); + return QIcon(QStringLiteral(":/client/core/theme/colored/wizard_logo.svg")); } QIcon ownCloudTheme::aboutIcon() const { - return QIcon(QStringLiteral(":/client/theme/colored/oc-image-about.svg")); + return QIcon(QStringLiteral(":/client/core/theme/colored/oc-image-about.svg")); } #endif diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index fa56a070e..be7993cb5 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -37,6 +37,17 @@ #undef Mirall #endif +namespace { +constexpr bool strings_equal(char const *a, char const *b) +{ + return *a == *b && (*a == '\0' || strings_equal(a + 1, b + 1)); +} +constexpr bool isVanilla() +{ + // TODO: c++17 stringview + return strings_equal(APPLICATION_SHORTNAME, "ownCloud"); +} +} namespace OCC { Theme *Theme::_instance = nullptr; @@ -137,8 +148,9 @@ bool Theme::isUsingDarkTheme() const * helper to load a icon from either the icon theme the desktop provides or from * the apps Qt resources. */ -QIcon Theme::themeIcon(const QString &name, bool sysTray, bool sysTrayMenuVisible) const +QIcon Theme::themeIcon(const QString &name, bool sysTray, bool sysTrayMenuVisible, bool useCoreIcon) const { + useCoreIcon = useCoreIcon || isVanilla(); QString flavor; if (sysTray) { flavor = systrayIconFlavor(_mono, sysTrayMenuVisible); @@ -149,27 +161,40 @@ QIcon Theme::themeIcon(const QString &name, bool sysTray, bool sysTrayMenuVisibl flavor = QStringLiteral("colored"); } } - + const QString path = useCoreIcon ? QStringLiteral(":/client/core/theme") : QStringLiteral(":/client/theme"); const QString key = name + QLatin1Char(',') + flavor; QIcon &cached = _iconCache[key]; // Take reference, this will also "set" the cache entry if (cached.isNull()) { - if (appName() == QLatin1String("ownCloud") && QIcon::hasThemeIcon(name)) { + if (isVanilla() && QIcon::hasThemeIcon(name)) { // use from theme return cached = QIcon::fromTheme(name); } - const auto svg = QIcon(QStringLiteral(":/client/theme/%1/%2.svg").arg(flavor, name)); - if (!svg.isNull()) { - return cached = svg; + const QString svg = QStringLiteral("%1/%2/%3.svg").arg(path, flavor, name); + if (QFile::exists(svg)) { + return cached = QIcon(svg); } const QList<int> sizes {16, 22, 32, 48, 64, 128, 256, 512, 1024}; + QString previousIcon; for (int size : sizes) { - QString pixmapName = QStringLiteral(":/client/theme/%1/%2-%3.png").arg(flavor).arg(name).arg(size); + QString pixmapName = QStringLiteral("%1/%2/%3-%4.png").arg(path, flavor, name, QString::number(size)); if (QFile::exists(pixmapName)) { - cached.addPixmap(QPixmap(pixmapName)); + previousIcon = pixmapName; + cached.addFile(pixmapName, { size, size }); + } else if (size >= 128) { + if (!previousIcon.isEmpty()) { + qWarning() << "Upsacling:" << previousIcon << "to" << size; + cached.addPixmap(QPixmap(previousIcon).scaled({ size, size }, Qt::KeepAspectRatio)); + } } } } + if (cached.isNull()) { + if (!useCoreIcon) { + return themeIcon(name, sysTray, sysTrayMenuVisible, true); + } + qWarning() << "Failed to locate the icon" << name; + } #ifdef Q_OS_MAC // This defines the icon as a template and enables automatic macOS color handling @@ -180,6 +205,14 @@ QIcon Theme::themeIcon(const QString &name, bool sysTray, bool sysTrayMenuVisibl return cached; } +bool Theme::hasTheme(const QString &theme) +{ + if (isVanilla()) { + return QFileInfo(QStringLiteral(":/client/core/theme/%1/").arg(theme)).isDir(); + } + return QFileInfo(QStringLiteral(":/client/theme/%1/").arg(theme)).isDir(); +} + QString Theme::systrayIconFlavor(bool mono, bool sysTrayMenuVisible) const { Q_UNUSED(sysTrayMenuVisible) @@ -268,8 +301,7 @@ bool Theme::systrayUseMonoIcons() const bool Theme::monoIconsAvailable() const { - const QString themeDir = QStringLiteral(":/client/theme/%1/").arg(Theme::instance()->systrayIconFlavor(true)); - return QFileInfo(themeDir).isDir(); + return hasTheme(systrayIconFlavor(true)); } QString Theme::updateCheckUrl() const @@ -347,12 +379,9 @@ QString Theme::aboutVersions(Theme::VersionFormat format) const QString Theme::about() const { - QString vendor = QStringLiteral(APPLICATION_VENDOR); // Ideally, the vendor should be "ownCloud GmbH", but it cannot be changed without // changing the location of the settings and other registery keys. - if (vendor == QLatin1String("ownCloud")) { - vendor = QStringLiteral("ownCloud GmbH"); - } + const QString vendor = isVanilla() ? QStringLiteral("ownCloud GmbH") : QStringLiteral(APPLICATION_VENDOR); return tr("<p>Version %1. For more information visit <a href=\"%2\">https://%3</a></p>" "<p>For known issues and help, please visit: <a href=\"https://central.owncloud.org/c/desktop-client\">https://central.owncloud.org</a></p>" "<p><small>By Klaas Freitag, Daniel Molkentin, Olivier Goffart, Markus Götz, " diff --git a/src/libsync/theme.h b/src/libsync/theme.h index 6184b484b..84c7b3ea3 100644 --- a/src/libsync/theme.h +++ b/src/libsync/theme.h @@ -399,7 +399,8 @@ public: protected: #ifndef TOKEN_AUTH_ONLY - QIcon themeIcon(const QString &name, bool sysTray = false, bool sysTrayMenuVisible = false) const; + QIcon themeIcon(const QString &name, bool sysTray = false, bool sysTrayMenuVisible = false, bool useCoreIcon = false) const; + static bool hasTheme(const QString &theme); #endif Theme(); @@ -413,7 +414,7 @@ private: static Theme *_instance; bool _mono; #ifndef TOKEN_AUTH_ONLY - bool _hasDarkColoredTheme = QFileInfo(QStringLiteral(":/client/theme/dark/")).isDir(); + bool _hasDarkColoredTheme = hasTheme(QStringLiteral("dark")); mutable QHash<QString, QIcon> _iconCache; #endif }; diff --git a/src/libsync/vfs/CMakeLists.txt b/src/libsync/vfs/CMakeLists.txt index 4918d6bd7..dadf1eed9 100644 --- a/src/libsync/vfs/CMakeLists.txt +++ b/src/libsync/vfs/CMakeLists.txt @@ -3,15 +3,18 @@ foreach(vfsPlugin ${VIRTUAL_FILE_SYSTEM_PLUGINS}) set(vfsPluginPath ${vfsPlugin}) + set(vfsPluginPathOut ${vfsPlugin}) get_filename_component(vfsPluginName ${vfsPlugin} NAME) if (NOT IS_ABSOLUTE ${vfsPlugin}) set(vfsPluginPath "${CMAKE_CURRENT_LIST_DIR}/${vfsPlugin}") + else() + get_filename_component(vfsPluginPathOut ${vfsPluginPath} DIRECTORY) endif() if(NOT IS_DIRECTORY ${vfsPluginPath}) continue() endif() - add_subdirectory(${vfsPluginPath} ${vfsPluginName}) + add_subdirectory(${vfsPluginPath} ${vfsPluginPathOut}) if(BUILD_TESTING AND IS_DIRECTORY "${vfsPluginPath}/test") add_subdirectory("${vfsPluginPath}/test" "${vfsPluginName}_test") diff --git a/theme/colored/128-owncloud-icon.png b/theme/colored/128-owncloud-icon.png Binary files differdeleted file mode 100644 index f708f41c7..000000000 --- a/theme/colored/128-owncloud-icon.png +++ /dev/null |