From 3b6e242b88af187198d939311a139d439bb85ab8 Mon Sep 17 00:00:00 2001 From: YeShanShan Date: Mon, 15 Jan 2024 17:03:20 +0800 Subject: [PATCH] fix: can't find icon in qt6 It maybe a bug for qt. xdgicon has not adapt to qt6, so we use Qt's QIconLoaderEngine to find icon for xdg icon in dtkgui, but `icon-theme.cache` is read once in QIconCacheGtkReader, so it's not updated even if `gtk-update-cache-icon` is executed in deepin-app-store-tool before reading icon. we release cache when `changed` signal received. Issue: https://github.com/linuxdeepin/developer-center/issues/6860 --- src/models/appsmodel.cpp | 3 +++ src/utils/CMakeLists.txt | 2 +- src/utils/iconutils.cpp | 10 ++++++++++ src/utils/iconutils.h | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/models/appsmodel.cpp b/src/models/appsmodel.cpp index dbdaecf3..9016cc59 100644 --- a/src/models/appsmodel.cpp +++ b/src/models/appsmodel.cpp @@ -4,6 +4,7 @@ #include "appsmodel.h" #include "categoryutils.h" +#include "iconutils.h" #include #include @@ -37,6 +38,8 @@ AppsModel::AppsModel(QObject *parent) connect(m_appInfoMonitor, &AppInfoMonitor::changed, this, [this](){ qDebug() << "changed"; + // TODO release icon's cache when gtk's icon-theme.cache is updated. + IconUtils::tryUpdateIconCache(); QList items(allAppInfosShouldBeShown()); cleanUpInvalidApps(items); QList duplicatedItems = updateItems(items); diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index f0eb7a1b..fc771206 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -18,4 +18,4 @@ PRIVATE ) target_include_directories(launcher-utils PUBLIC ${CMAKE_CURRENT_LIST_DIR}) -target_link_libraries(launcher-utils PRIVATE Qt::Core Qt::Gui Qt::Svg ${DTK_NS}::Gui) +target_link_libraries(launcher-utils PRIVATE Qt::Core Qt::Gui Qt::GuiPrivate Qt::Svg ${DTK_NS}::Gui) diff --git a/src/utils/iconutils.cpp b/src/utils/iconutils.cpp index d4c0e7f7..0f1de398 100644 --- a/src/utils/iconutils.cpp +++ b/src/utils/iconutils.cpp @@ -4,6 +4,8 @@ #include "iconutils.h" +#include + #include #include #include @@ -241,3 +243,11 @@ const QPixmap IconUtils::loadSvg(const QString &fileName, const QSize &size) return pixmap; } + +void IconUtils::tryUpdateIconCache() +{ + qInfo() << "Update theme cache manually."; + // TODO release icon's cache. + const auto paths = QIconLoader::instance()->themeSearchPaths(); + QIconLoader::instance()->setThemeSearchPath(paths); +} diff --git a/src/utils/iconutils.h b/src/utils/iconutils.h index ff2d3ebf..70e90399 100644 --- a/src/utils/iconutils.h +++ b/src/utils/iconutils.h @@ -8,6 +8,7 @@ namespace IconUtils { bool getThemeIcon(QPixmap &pixmap, const QString & iconName, const int size); +void tryUpdateIconCache(); int perfectIconSize(const int size); bool createCalendarIcon(const QString &fileName); const QPixmap loadSvg(const QString &fileName, int size);