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,24 @@ 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+ if (file.open ()) {
149+ QString filePath = file.fileName ();
150+ if (img.save (filePath)) {
151+ file.setAutoRemove (false );
152+ file.close ();
153+ qDebug (notifyLog) << " Created temporary icon file:" << filePath;
154+ return filePath;
155+ }
156+
157+ file.close ();
158+ return {};
159+ }
147160 }
148161
149- DGUI_USE_NAMESPACE ;
150- auto icon = DIconTheme::findQIcon (appName, DIconTheme::findQIcon (" application-x-desktop" ));
151- return icon.name ();
162+ return {};
152163}
153164
154165
@@ -166,6 +177,14 @@ BubbleItem::BubbleItem(const NotifyEntity &entity, QObject *parent)
166177 setEntity (entity);
167178}
168179
180+ BubbleItem::~BubbleItem ()
181+ {
182+ // clean up temporary icon file.
183+ if (!m_tempIconPath.isEmpty () && QFile::exists (m_tempIconPath)) {
184+ QFile::remove (m_tempIconPath);
185+ }
186+ }
187+
169188void BubbleItem::setEntity (const NotifyEntity &entity)
170189{
171190 m_entity = entity;
@@ -192,13 +211,19 @@ QString BubbleItem::appName() const
192211 return m_entity.appName ();
193212}
194213
195- QString BubbleItem::appIcon () const
214+ QString BubbleItem::appIcon ()
196215{
197216 if (!m_entity.appIcon ().isEmpty ()) {
198217 return m_entity.appIcon ();
199218 }
200219
201- return imagePathOfNotification (m_entity.hints (), m_entity.appIcon (), m_entity.appName ());
220+ if (!m_tempIconPath.isEmpty () && QFile::exists (m_tempIconPath)) {
221+ return m_tempIconPath;
222+ }
223+
224+ m_tempIconPath = imagePathOfNotification (m_entity.hints (), m_entity.appIcon (), m_entity.appName ());
225+ // if this is empty path, UI can fallback to application-x-desktop icon.
226+ return m_tempIconPath;
202227}
203228
204229QString BubbleItem::summary () const
0 commit comments