From c94f70e042e0bcd660f5b207239641a12dd097a3 Mon Sep 17 00:00:00 2001 From: iaom <18504285112@163.com> Date: Mon, 13 Sep 2021 21:05:49 +0800 Subject: [PATCH] Fix: Wrong display of some files' icons. --- libsearch/file-utils.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/libsearch/file-utils.cpp b/libsearch/file-utils.cpp index da2b5e8..8e5d2fa 100644 --- a/libsearch/file-utils.cpp +++ b/libsearch/file-utils.cpp @@ -55,31 +55,24 @@ QIcon FileUtils::getFileIcon(const QString &uri, bool checkValid) { if(!G_IS_FILE_INFO(info.get()->get())) return QIcon::fromTheme("unknown"); GIcon *g_icon = g_file_info_get_icon(info.get()->get()); - QString icon_name; + //do not unref the GIcon from info. if(G_IS_ICON(g_icon)) { const gchar* const* icon_names = g_themed_icon_get_names(G_THEMED_ICON(g_icon)); if(icon_names) { auto p = icon_names; - if(*p) - icon_name = QString(*p); - if(checkValid) { - while(*p) { - QIcon icon = QIcon::fromTheme(*p); - if(!icon.isNull()) { - icon_name = QString(*p); - break; - } else { - p++; - } + while(*p) { + QIcon icon = QIcon::fromTheme(*p); + if(!icon.isNull()) { + return icon; + } else { + p++; } } } } - if(!QIcon::hasThemeIcon(icon_name)) { - return QIcon::fromTheme("unknown"); - } - return QIcon::fromTheme(icon_name); + return QIcon::fromTheme("unknown"); + } /**