From da407f77dbf34b232ea3b50c51b094095206deef Mon Sep 17 00:00:00 2001 From: listenerri Date: Thu, 30 Aug 2018 12:03:25 +0800 Subject: [PATCH] fix(app): icon is null Change-Id: I1fb4415d97bf35572bf4f5e7ea8fd4291e62a83f --- frame/item/appitem.cpp | 19 +++++++++++++++++++ frame/item/appitem.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index c68fc2fb0..ff9fc0e39 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -60,6 +60,8 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) m_dragging(false), + m_retryTimes(0), + m_appIcon(QPixmap()), m_horizontalIndicator(QPixmap(":/indicator/resources/indicator.png")), @@ -67,6 +69,7 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) m_activeHorizontalIndicator(QPixmap(":/indicator/resources/indicator_active.png")), m_activeVerticalIndicator(QPixmap(":/indicator/resources/indicator_active_ver.png")), m_updateIconGeometryTimer(new QTimer(this)), + m_retryObtainIconTimer(new QTimer(this)), m_smallWatcher(new QFutureWatcher(this)), m_largeWatcher(new QFutureWatcher(this)) @@ -90,12 +93,16 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent) m_updateIconGeometryTimer->setInterval(500); m_updateIconGeometryTimer->setSingleShot(true); + m_retryObtainIconTimer->setInterval(500); + m_retryObtainIconTimer->setSingleShot(true); + connect(m_itemEntryInter, &DockEntryInter::IsActiveChanged, this, &AppItem::activeChanged); connect(m_itemEntryInter, &DockEntryInter::IsActiveChanged, this, static_cast(&AppItem::update)); connect(m_itemEntryInter, &DockEntryInter::WindowInfosChanged, this, &AppItem::updateWindowInfos, Qt::QueuedConnection); connect(m_itemEntryInter, &DockEntryInter::IconChanged, this, &AppItem::refershIcon); connect(m_updateIconGeometryTimer, &QTimer::timeout, this, &AppItem::updateWindowIconGeometries, Qt::QueuedConnection); + connect(m_retryObtainIconTimer, &QTimer::timeout, this, &AppItem::refershIcon, Qt::QueuedConnection); updateWindowInfos(m_itemEntryInter->windowInfos()); refershIcon(); @@ -511,6 +518,18 @@ void AppItem::refershIcon() else m_appIcon = ThemeAppIcon::getIcon(icon, iconSize * 0.8); + if (m_appIcon.isNull()) { + if (m_retryTimes < 5) { + m_retryTimes++; + qDebug() << m_itemEntryInter->name() << "obtain app icon failed, retry times" << m_retryTimes; + m_retryObtainIconTimer->start(); + } + return; + } else if (m_retryTimes > 0) { + // reset times + m_retryTimes = 0; + } + update(); m_updateIconGeometryTimer->start(); diff --git a/frame/item/appitem.h b/frame/item/appitem.h index a4e127890..e4f58b2e1 100644 --- a/frame/item/appitem.h +++ b/frame/item/appitem.h @@ -109,6 +109,8 @@ private: bool m_dragging; bool m_active; + int m_retryTimes; + WindowInfoMap m_windowInfos; QString m_id; QPixmap m_appIcon; @@ -118,6 +120,7 @@ private: QPixmap m_activeVerticalIndicator; QTimer *m_updateIconGeometryTimer; + QTimer *m_retryObtainIconTimer; QFutureWatcher *m_smallWatcher; QFutureWatcher *m_largeWatcher;