Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions panels/notification/bubble/bubbleitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

#include "bubbleitem.h"

#include <QUrl>

Check warning on line 7 in panels/notification/bubble/bubbleitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QUrl> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTimer>

Check warning on line 8 in panels/notification/bubble/bubbleitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QImage>

Check warning on line 9 in panels/notification/bubble/bubbleitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QImage> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDir>

Check warning on line 10 in panels/notification/bubble/bubbleitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDir> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFile>

Check warning on line 11 in panels/notification/bubble/bubbleitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFile> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusArgument>

Check warning on line 12 in panels/notification/bubble/bubbleitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusArgument> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTemporaryFile>

Check warning on line 13 in panels/notification/bubble/bubbleitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTemporaryFile> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLoggingCategory>

Check warning on line 14 in panels/notification/bubble/bubbleitem.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <DIconTheme>

Expand Down Expand Up @@ -140,15 +142,24 @@
if (img.isNull()) {
img = decodeImageFromBase64(imageData);
}

if (!img.isNull()) {
QTemporaryFile file("notification_icon");
img.save(file.fileName());
return file.fileName();
QTemporaryFile file(QDir::temp().filePath("notification_icon_XXXXXX.png"));
if (file.open()) {
QString filePath = file.fileName();
if (img.save(filePath)) {
file.setAutoRemove(false);
file.close();
qDebug(notifyLog) << "Created temporary icon file:" << filePath;
return filePath;
}

file.close();
return {};
}
}

DGUI_USE_NAMESPACE;
auto icon = DIconTheme::findQIcon(appName, DIconTheme::findQIcon("application-x-desktop"));
return icon.name();
return {};
}


Expand All @@ -166,6 +177,14 @@
setEntity(entity);
}

BubbleItem::~BubbleItem()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Destructor cleanup may not handle all edge cases for temporary file removal.

Currently, only the most recent temp file is removed. If multiple temp files can be created, consider tracking all of them or restricting creation to a single file.

{
// clean up temporary icon file.
if (!m_tempIconPath.isEmpty() && QFile::exists(m_tempIconPath)) {
QFile::remove(m_tempIconPath);
}
}

void BubbleItem::setEntity(const NotifyEntity &entity)
{
m_entity = entity;
Expand All @@ -192,13 +211,19 @@
return m_entity.appName();
}

QString BubbleItem::appIcon() const
QString BubbleItem::appIcon()
{
if (!m_entity.appIcon().isEmpty()) {
return m_entity.appIcon();
}

return imagePathOfNotification(m_entity.hints(), m_entity.appIcon(), m_entity.appName());
if (!m_tempIconPath.isEmpty() && QFile::exists(m_tempIconPath)) {
return m_tempIconPath;
}

m_tempIconPath = imagePathOfNotification(m_entity.hints(), m_entity.appIcon(), m_entity.appName());
// if this is empty path, UI can fallback to application-x-desktop icon.
return m_tempIconPath;
}

QString BubbleItem::summary() const
Expand Down
4 changes: 3 additions & 1 deletion panels/notification/bubble/bubbleitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@

explicit BubbleItem(QObject *parent = nullptr);
explicit BubbleItem(const NotifyEntity &entity, QObject *parent = nullptr);
~BubbleItem();

public:
void setEntity(const NotifyEntity &entity);

public:
qint64 id() const;

Check warning on line 27 in panels/notification/bubble/bubbleitem.h

View workflow job for this annotation

GitHub Actions / cppcheck

Local variable 'id' shadows outer function
uint bubbleId() const;
QString appName() const;
QString appIcon() const;
QString appIcon();
QString summary() const;
QString body() const;
uint replacesId() const;
Expand Down Expand Up @@ -65,6 +66,7 @@
bool m_enablePreview = true;
QVariantList m_actions;
QString m_defaultAction;
QString m_tempIconPath;
};

}
Expand Down