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,26 @@ 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+ if (img.save (filePath)) {
152+ file.close ();
153+ qDebug (notifyLog) << " Created temporary icon file:" << filePath;
154+ return filePath;
155+ }
156+
157+ file.close ();
158+ QFile::remove (filePath);
159+
160+ return {};
161+ }
147162 }
148163
149- DGUI_USE_NAMESPACE ;
150- auto icon = DIconTheme::findQIcon (appName, DIconTheme::findQIcon (" application-x-desktop" ));
151- return icon.name ();
164+ return {};
152165}
153166
154167
@@ -166,6 +179,14 @@ BubbleItem::BubbleItem(const NotifyEntity &entity, QObject *parent)
166179 setEntity (entity);
167180}
168181
182+ BubbleItem::~BubbleItem ()
183+ {
184+ // clean up temporary icon file.
185+ if (!m_tempIconPath.isEmpty () && QFile::exists (m_tempIconPath)) {
186+ QFile::remove (m_tempIconPath);
187+ }
188+ }
189+
169190void BubbleItem::setEntity (const NotifyEntity &entity)
170191{
171192 m_entity = entity;
@@ -192,13 +213,19 @@ QString BubbleItem::appName() const
192213 return m_entity.appName ();
193214}
194215
195- QString BubbleItem::appIcon () const
216+ QString BubbleItem::appIcon ()
196217{
197218 if (!m_entity.appIcon ().isEmpty ()) {
198219 return m_entity.appIcon ();
199220 }
200221
201- return imagePathOfNotification (m_entity.hints (), m_entity.appIcon (), m_entity.appName ());
222+ if (!m_tempIconPath.isEmpty () && QFile::exists (m_tempIconPath)) {
223+ return m_tempIconPath;
224+ }
225+
226+ m_tempIconPath = imagePathOfNotification (m_entity.hints (), m_entity.appIcon (), m_entity.appName ());
227+ // if this is empty path, UI can fallback to application-x-desktop icon.
228+ return m_tempIconPath;
202229}
203230
204231QString BubbleItem::summary () const
0 commit comments