fix: 修复任务栏概率性获取不到图标的问题

采用qtxdg-iconfinder命令查找图标的文件,然后直接读取文件

Log: 修复任务栏安装应用后图标小概率显示为齿轮的问题
Bug: https://pms.uniontech.com/zentao/bug-view-80456.html
Change-Id: Ibd534c42d8991a8f8918fe31c73ed00c871cc285
This commit is contained in:
FanPengCheng 2021-05-26 10:50:43 +08:00
parent 331cf7c749
commit 07b6a455eb
3 changed files with 31 additions and 9 deletions

3
debian/control vendored
View File

@ -38,7 +38,8 @@ Depends: ${shlibs:Depends}, ${misc:Depends},
dde-qt5xcb-plugin (>=5.0.19),
dde-daemon (>=5.12.0.31),
startdde (>=5.6.0.34),
lastore-daemon (>=5.1.0.21)
lastore-daemon (>=5.1.0.21),
qtxdg-dev-tools
Recommends: dde-disk-mount-plugin, dde-dock-onboard-plugin
Conflicts:
dde-workspace (<< 2.90.5),

View File

@ -60,7 +60,7 @@ AppItem::AppItem(const QGSettings *appSettings, const QGSettings *activeAppSetti
, m_drag(nullptr)
, m_dragging(false)
, m_retryTimes(0)
, m_iconValid(false)
, m_iconValid(true)
, m_lastclickTimes(0)
, m_appIcon(QPixmap())
, m_updateIconGeometryTimer(new QTimer(this))

View File

@ -32,6 +32,7 @@
#include <QDate>
#include <QPainter>
#include <QStandardPaths>
#include <QProcess>
#include <private/qguiapplication_p.h>
#include <private/qiconloader_p.h>
@ -182,18 +183,38 @@ ThemeAppIcon::~ThemeAppIcon()
* @brief ThemeAppIcon::getIcon \a name
* @param name
* @return
* @note 使QIcon::fromTheme是因为这个函数中有缓存机制
* @note 使QIcon::fromTheme可以获取到图标
*/
QIcon ThemeAppIcon::getIcon(const QString &name)
{
QPlatformTheme * const platformTheme = QGuiApplicationPrivate::platformTheme();
bool hasUserTheme = QIconLoader::instance()->hasUserTheme();
//TODO 这里找图标会耗时界面轻微卡顿后面有时间可以放到AppItem里面单独开启线程去查找
auto getIconList = [ = ] (const QString &iconName) {
QProcess process;
process.start("qtxdg-iconfinder", QStringList() << iconName);
process.closeWriteChannel();
process.waitForFinished();
if (!platformTheme || hasUserTheme)
return QIcon::fromTheme(name);
int exitCode = process.exitCode();
QString outputTxt = process.readAllStandardOutput();
QIconEngine * const engine = platformTheme->createIconEngine(name);
return QIcon(engine);
auto list = outputTxt.split("\n");
if (exitCode != 0 || list.size() <= 3)
return QStringList() << "";
// 去掉无用数据
list.removeFirst();
list.removeLast();
list.removeLast();
for (auto &s : list) {
s = s.simplified();
}
return list;
};
return QIcon::fromTheme(getIconList(name).first());
}
bool ThemeAppIcon::getIcon(QPixmap &pix, const QString iconName, const int size, bool reObtain)