Skip to content

Commit

Permalink
fix: can't find icon in qt6
Browse files Browse the repository at this point in the history
  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: linuxdeepin/developer-center#6860
  • Loading branch information
18202781743 committed Jan 16, 2024
1 parent ab6ff5d commit 3b6e242
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/models/appsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "appsmodel.h"
#include "categoryutils.h"
#include "iconutils.h"

#include <QDebug>
#include <DConfig>
Expand Down Expand Up @@ -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<AppItem *> items(allAppInfosShouldBeShown());
cleanUpInvalidApps(items);
QList<AppItem *> duplicatedItems = updateItems(items);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 10 additions & 0 deletions src/utils/iconutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "iconutils.h"

#include <private/qiconloader_p.h>

#include <QDate>
#include <QDebug>
#include <QIcon>
Expand Down Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions src/utils/iconutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3b6e242

Please sign in to comment.