77#include < QUrl>
88#include < QTimer>
99#include < QImage>
10+ #include < QDir>
11+ #include < QFile>
1012#include < QDBusArgument>
1113#include < QTemporaryFile>
1214#include < QLoggingCategory>
@@ -140,15 +142,21 @@ static QString imagePathOfNotification(const QVariantMap &hints, const QString &
140142 if (img.isNull ()) {
141143 img = decodeImageFromBase64 (imageData);
142144 }
145+
143146 if (!img.isNull ()) {
144- QTemporaryFile file (" notification_icon" );
145- img.save (file.fileName ());
146- return file.fileName ();
147+ QTemporaryFile file (QDir::temp ().filePath (" notification_icon_XXXXXX.png" ));
148+ file.setAutoRemove (false );
149+ if (file.open ()) {
150+ QString filePath = file.fileName ();
151+ file.close ();
152+ if (img.save (filePath)) {
153+ qDebug (notifyLog) << " Created temporary icon file:" << filePath;
154+ return filePath;
155+ }
156+ }
147157 }
148158
149- DGUI_USE_NAMESPACE ;
150- auto icon = DIconTheme::findQIcon (appName, DIconTheme::findQIcon (" application-x-desktop" ));
151- return icon.name ();
159+ return {};
152160}
153161
154162
@@ -166,6 +174,14 @@ BubbleItem::BubbleItem(const NotifyEntity &entity, QObject *parent)
166174 setEntity (entity);
167175}
168176
177+ BubbleItem::~BubbleItem ()
178+ {
179+ // clean up temporary icon file.
180+ if (!m_tempIconPath.isEmpty () && QFile::exists (m_tempIconPath)) {
181+ QFile::remove (m_tempIconPath);
182+ }
183+ }
184+
169185void BubbleItem::setEntity (const NotifyEntity &entity)
170186{
171187 m_entity = entity;
@@ -192,13 +208,19 @@ QString BubbleItem::appName() const
192208 return m_entity.appName ();
193209}
194210
195- QString BubbleItem::appIcon () const
211+ QString BubbleItem::appIcon ()
196212{
197213 if (!m_entity.appIcon ().isEmpty ()) {
198214 return m_entity.appIcon ();
199215 }
200216
201- return imagePathOfNotification (m_entity.hints (), m_entity.appIcon (), m_entity.appName ());
217+ if (!m_tempIconPath.isEmpty () && QFile::exists (m_tempIconPath)) {
218+ return m_tempIconPath;
219+ }
220+
221+ m_tempIconPath = imagePathOfNotification (m_entity.hints (), m_entity.appIcon (), m_entity.appName ());
222+ // if this is empty path, UI can fallback to application-x-desktop icon.
223+ return m_tempIconPath;
202224}
203225
204226QString BubbleItem::summary () const
0 commit comments