Skip to content
Merged
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
38 changes: 19 additions & 19 deletions panels/notification/bubble/bubbleitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

#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 <QBuffer>

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 11 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 12 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 13 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 <QRegularExpression>

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <DIconTheme>

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

namespace notification {
Q_DECLARE_LOGGING_CATEGORY(notifyLog)
Expand Down Expand Up @@ -91,20 +93,17 @@
return image;
}

static QImage decodeImageFromBase64(const QString &arg)
static QString decodeImageToBase64(const QImage &image, const char *format = "PNG")
Copy link

Choose a reason for hiding this comment

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

suggestion: Function name may be misleading regarding its purpose.

Consider renaming the function to encodeImageToBase64 or imageToBase64Uri to better reflect that it encodes a QImage to a base64 data URI.

Suggested implementation:

static QString encodeImageToBase64(const QImage &image, const char *format = "PNG")

If this function is called elsewhere in the file or project, those call sites should also be updated to use the new name encodeImageToBase64.

{
if (arg.startsWith("data:image/")) {
// iconPath is a string representing an inline image.
QStringList strs = arg.split("base64,");
if (strs.length() == 2) {
QByteArray data = QByteArray::fromBase64(strs.at(1).toLatin1());
return QImage::fromData(data);
}
}
return QImage();
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, format);

return QString("data:image/%1;base64,%2").arg(QString::fromLatin1(format).toLower()).arg(QString::fromLatin1(ba.toBase64()));
}

static QIcon decodeIconFromPath(const QString &arg, const QString &fallback)

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

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'decodeIconFromPath' is never used.
{
DGUI_USE_NAMESPACE;
const QUrl url(arg);
Expand Down Expand Up @@ -138,17 +137,18 @@
imageData = source.toString();
}
if (img.isNull()) {
img = decodeImageFromBase64(imageData);
}
if (!img.isNull()) {
QTemporaryFile file("notification_icon");
img.save(file.fileName());
return file.fileName();
// check if imageData is a base64 image data.
QRegularExpression dataUriPattern("^data:image/[a-zA-Z0-9+\\-]+;base64,");
QRegularExpressionMatch match = dataUriPattern.match(imageData);
if (match.hasMatch()) {
return imageData;
}
} else {
return decodeImageToBase64(img);
}

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


Expand Down