From 1074e941a6474942609b2282406b1c0eb4fc26aa Mon Sep 17 00:00:00 2001 From: zty199 <46324746+zty199@users.noreply.github.com> Date: Wed, 1 Feb 2023 11:59:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ISSUE=20#I6B4CS=20=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E5=BA=94=E7=94=A8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 应用安装过程中,重新进入应用详情页,仅通过 `dpkg-query -s $pkgName` 判断本地是否已安装,未判断当前安装任务执行状态 Log: 判断本地安装状态后,执行 isDownloading 函数判断安装任务状态,更新按钮显示状态;整理应用详情页代码 --- src/mainwindow-dtk.cpp | 1 + src/pages/appintopage.cpp | 412 +++++++++++++++++++++----------------- src/pages/appintopage.h | 61 +++--- src/utils/utils.cpp | 31 ++- src/utils/utils.h | 4 +- 5 files changed, 279 insertions(+), 230 deletions(-) diff --git a/src/mainwindow-dtk.cpp b/src/mainwindow-dtk.cpp index eaa7842..1bafa38 100644 --- a/src/mainwindow-dtk.cpp +++ b/src/mainwindow-dtk.cpp @@ -11,6 +11,7 @@ #include #include +#include #define AppPageApplist 0 #define AppPageSearchlist 1 diff --git a/src/pages/appintopage.cpp b/src/pages/appintopage.cpp index 344bfaa..179e035 100644 --- a/src/pages/appintopage.cpp +++ b/src/pages/appintopage.cpp @@ -1,82 +1,40 @@ #include "appintopage.h" #include "ui_appintopage.h" -AppIntoPage::AppIntoPage(QWidget *parent) : QWidget(parent), - ui(new Ui::AppIntoPage) +#include "backend/sparkapi.h" +#include "widgets/downloadlistwidget.h" +#include "backend/image_show.h" +#include "application.h" + +#include +#include + +AppIntoPage::AppIntoPage(QWidget *parent) + : QWidget(parent) + , ui(new Ui::AppIntoPage) + , api(new SparkAPI(this)) { - ui->setupUi(this); - ui->listWidget->setViewMode(QListView::IconMode); - ui->listWidget->setMovement(QListView::Static); - ui->listWidget->setMaximumHeight(200); - ui->listWidget->setFlow(QListView::TopToBottom); - api1 = new SparkAPI(this); - connect(api1, &SparkAPI::finishedRAW, [=](QString download_times) - { - download_times.remove(QRegExp("\\n")); - ui->download_times->setText(download_times); - qDebug()<<"Download Times:"+download_times; }); - clear(); + initUI(); + initConnections(); } -void AppIntoPage::clear() +AppIntoPage::~AppIntoPage() { - ui->tag_a2d->hide(); - ui->tag_uos->hide(); - ui->tag_dtk5->hide(); - ui->tag_deepin->hide(); - ui->tag_dwine2->hide(); - ui->tag_dwine5->hide(); - ui->tag_ubuntu->hide(); - ui->tag_community->hide(); - ui->icon->clear(); - ui->title->clear(); - ui->author->clear(); - ui->label_2->clear(); - ui->downloadButton->hide(); - ui->downloadButton->setEnabled(false); - ui->pushButton_3->hide(); - int n = ui->listWidget->count(); - for (int i = 0; i < n; i++) - { - QListWidgetItem *item = ui->listWidget->takeItem(0); - QWidget *card = ui->listWidget->itemWidget(item); - delete card; - card = NULL; - delete item; - item = NULL; - } - ui->listWidget->clear(); + delete ui; } -void AppIntoPage::setDownloadWidget(DownloadListWidget *w) -{ - dw = w; - connect(w, &DownloadListWidget::downloadFinished, [=]() - { isDownloading(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString()); }); -} -void AppIntoPage::openUrl(QUrl url) + +void AppIntoPage::openUrl(const QUrl &url) { + clear(); + + // qDebug() << url; spk = url; - SparkAPI *api = new SparkAPI(this); - clear(); - connect(api, &SparkAPI::finishedObject, [=](QJsonObject appinfo) - { + SparkAPI *api1 = new SparkAPI(this); + connect(api1, &SparkAPI::finishedObject, [=](const QJsonObject &appinfo) + { info = appinfo; -// qDebug()<getImgServerUrl()+"store"+url.path().replace("+","%2B") + "/icon.png"; - request.setUrl(QUrl(api->getImgServerUrl()+"store"+url.path().replace("+","%2B") + "/icon.png")); - request.setRawHeader("User-Agent", "Mozilla/5.0"); - request.setRawHeader("Content-Type", "charset='utf-8'"); - naManager->get(request); - QObject::connect(naManager,&QNetworkAccessManager::finished,[=](QNetworkReply *reply){ - QByteArray jpegData = reply->readAll(); - iconpixmap.loadFromData(jpegData); - iconpixmap.scaled(210, 200, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - ui->icon->setPixmap(iconpixmap); - ui->icon->setScaledContents(true); - }); + + // 显示基本信息 ui->title->setText(info["Name"].toString()); ui->version->setText(info["Version"].toString()); ui->author->setText(info["Author"].toString()); @@ -84,10 +42,66 @@ void AppIntoPage::openUrl(QUrl url) ui->d_size->setText(info["Size"].toString()); ui->d_update->setText(info["Update"].toString()); ui->d_pkgname->setText(info["Pkgname"].toString()); - ui->d_website->setText(""+tr("Click Open")); + ui->d_website->setText("" + tr("Click Open")); ui->d_contributor->setText(info["Contributor"].toString()); ui->label_2->setText(info["More"].toString()); + // 显示 tags + QStringList taglist = info["Tags"].toString().split(";", QString::SkipEmptyParts); + setAppinfoTags(taglist); + + // 获取图标 + QNetworkRequest request; + QNetworkAccessManager *manager = new QNetworkAccessManager(this); + qDebug() << api->getImgServerUrl() + "store" + url.path() + "/icon.png"; + request.setUrl(QUrl(api->getImgServerUrl() + "store" + url.path() + "/icon.png")); + request.setRawHeader("User-Agent", "Mozilla/5.0"); + request.setRawHeader("Content-Type", "charset='utf-8'"); + manager->get(request); + QObject::connect(manager, &QNetworkAccessManager::finished, [=](QNetworkReply *reply) + { + QByteArray jpegData = reply->readAll(); + iconpixmap.loadFromData(jpegData); + iconpixmap.scaled(210, 200, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + ui->icon->setPixmap(iconpixmap); + ui->icon->setScaledContents(true); + + manager->deleteLater(); }); + + // 获取截图 + QJsonParseError error; + QJsonArray array = QJsonDocument::fromJson(info.value("img_urls").toString().toUtf8(), &error).array(); + QStringList imglist; + foreach (const QJsonValue &value, array) { + QString imgUrl = value.toString(); + imglist.append(imgUrl); + } + qDebug() << imglist; + + for (int i = 0; i < imglist.size(); i++) + { + QNetworkRequest request; + QNetworkAccessManager *manager = new QNetworkAccessManager(this); + request.setUrl(QUrl(imglist.value(i))); + request.setRawHeader("User-Agent", "Mozilla/5.0"); + request.setRawHeader("Content-Type", "charset='utf-8'"); + manager->get(request); + QObject::connect(manager, &QNetworkAccessManager::finished, [=](QNetworkReply *reply) + { + QByteArray jpegData = reply->readAll(); + QPixmap pixmap; + pixmap.loadFromData(jpegData); + pixmap.scaled(100, 100, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + image_show *img=new image_show(this); + img->setImage(pixmap); + //img->setScaledContents(true); + QListWidgetItem* pItem = new QListWidgetItem(); + pItem->setSizeHint(QSize(280, 200)); + ui->listWidget->addItem(pItem); + ui->listWidget->setItemWidget(pItem, img); + + manager->deleteLater(); }); + } // Check UOS QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat); @@ -135,79 +149,147 @@ void AppIntoPage::openUrl(QUrl url) isUpdated = false; } - QObject::connect(naManager, &QNetworkAccessManager::finished, [=]() - { - - if (isInstalled) + if (isInstalled) + { + if (isUpdated) { - if (isUpdated) - { - ui->downloadButton->setText(tr("Reinstall")); - ui->downloadButton->setEnabled(true); - ui->downloadButton->show(); - ui->pushButton_3->show(); - } - else - { - ui->downloadButton->setText(tr("Upgrade")); - ui->downloadButton->setEnabled(true); - ui->downloadButton->show(); - ui->pushButton_3->show(); - } + ui->downloadButton->setText(tr("Reinstall")); + ui->downloadButton->setEnabled(true); + ui->downloadButton->show(); + ui->pushButton_3->show(); } else { - ui->downloadButton->setText(tr("Download")); + ui->downloadButton->setText(tr("Upgrade")); ui->downloadButton->setEnabled(true); - isDownloading(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString()); ui->downloadButton->show(); - } }); + ui->pushButton_3->show(); + } + } + else + { + ui->downloadButton->setText(tr("Download")); + ui->downloadButton->setEnabled(true); + ui->downloadButton->show(); + } + + isDownloading(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString()); } - QStringList taglist = info["Tags"].toString().split(";"); - QString tmp=info["img_urls"].toString(); - qDebug() << tmp; - if (tmp.left(2) == "[\"") - { - tmp.remove(0, 2); - } - if (tmp.right(2) == "\"]") - { - tmp.remove(tmp.size() - 2, tmp.size()); - } - QStringList imglist = tmp.split("\",\""); - qDebug() << imglist; - for (int i = 0; i < imglist.size(); i++) - { - QNetworkRequest request; - QNetworkAccessManager *iconNaManager = new QNetworkAccessManager(this); - request.setUrl(QUrl(imglist[i].replace("+", "%2B"))); - request.setRawHeader("User-Agent", "Mozilla/5.0"); - request.setRawHeader("Content-Type", "charset='utf-8'"); - iconNaManager->get(request); - QObject::connect(iconNaManager, &QNetworkAccessManager::finished, [=](QNetworkReply *reply) - { - QByteArray jpegData = reply->readAll(); - QPixmap pixmap; - pixmap.loadFromData(jpegData); - pixmap.scaled(100, 100, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - image_show *img=new image_show(this); - img->setImage(pixmap); - //img->setScaledContents(true); - QListWidgetItem* pItem = new QListWidgetItem(); - pItem->setSizeHint(QSize(280, 200)); - ui->listWidget->addItem(pItem); - ui->listWidget->setItemWidget(pItem, img); - }); - } - this->sltAppinfoTags(&taglist); - disconnect(api,&SparkAPI::finished,nullptr,nullptr); - api->deleteLater(); }); - api->getAppInfo(url); - api1->getAppDownloadTimes(url); + api1->disconnect(); + api1->deleteLater(); }); + + api1->getAppInfo(url); + + api->getAppDownloadTimes(url); } -void AppIntoPage::isDownloading(QUrl url) +void AppIntoPage::clear() +{ + ui->tag_a2d->hide(); + ui->tag_uos->hide(); + ui->tag_dtk5->hide(); + ui->tag_deepin->hide(); + ui->tag_dwine2->hide(); + ui->tag_dwine5->hide(); + ui->tag_ubuntu->hide(); + ui->tag_community->hide(); + ui->icon->clear(); + ui->title->clear(); + ui->author->clear(); + ui->label_2->clear(); + ui->downloadButton->hide(); + ui->downloadButton->setEnabled(false); + ui->pushButton_3->hide(); + + // QListWidgetItem *item = nullptr; + // while ((item = ui->listWidget->takeItem(0)) != nullptr) + // { + // QWidget *card = ui->listWidget->itemWidget(item); + // if (card) + // { + // card->deleteLater(); + // card = nullptr; + // } + // delete item; + // item = nullptr; + // } + + ui->listWidget->clear(); // NOTE: QListWidget::clear() 会析构所有 items +} + +void AppIntoPage::setTheme(bool dark) +{ + if (dark) + { + QString frameStyleSheet ="#frame,#frame_2,#frame_3,#frame_4 {background-color: #252525; border-radius: 14px; border: 1px solid rgb(64, 64, 64);}\ + QLabel#cardtitle,QLabel#title,QLabel#title_1,QLabel#title_2,QLabel#title_3 {color: #FFFFFF}"; + ui->frame->setStyleSheet(frameStyleSheet); + ui->frame_2->setStyleSheet(frameStyleSheet); + ui->frame_3->setStyleSheet(frameStyleSheet); + ui->frame_4->setStyleSheet(frameStyleSheet); + + ui->icon_1->setPixmap(QPixmap(":/icon/dark/box.svg")); + ui->icon_2->setPixmap(QPixmap(":/icon/dark/box.svg")); + ui->icon_3->setPixmap(QPixmap(":/icon/dark/calendar.svg")); + ui->icon_4->setPixmap(QPixmap(":/icon/dark/text.svg")); + ui->icon_5->setPixmap(QPixmap(":/icon/dark/folder.svg")); + ui->icon_6->setPixmap(QPixmap(":/icon/dark/globe.svg")); + } + else + { + //亮色模式 + QString frameStyleSheet ="#frame,#frame_2,#frame_3,#frame_4 {background-color: #fbfbfb; border-radius: 14px; border: 1px solid rgb(229,229,229);}\ + QLabel#cardtitle,QLabel#title,QLabel#title_1,QLabel#title_2,QLabel#title_3 {color: #000000}"; + ui->frame->setStyleSheet(frameStyleSheet); + ui->frame_2->setStyleSheet(frameStyleSheet); + ui->frame_3->setStyleSheet(frameStyleSheet); + ui->frame_4->setStyleSheet(frameStyleSheet); + + ui->icon_1->setPixmap(QPixmap(":/icon/light/box.svg")); + ui->icon_2->setPixmap(QPixmap(":/icon/light/box.svg")); + ui->icon_3->setPixmap(QPixmap(":/icon/light/calendar.svg")); + ui->icon_4->setPixmap(QPixmap(":/icon/light/text.svg")); + ui->icon_5->setPixmap(QPixmap(":/icon/light/folder.svg")); + ui->icon_6->setPixmap(QPixmap(":/icon/light/globe.svg")); + } +} + +void AppIntoPage::setDownloadWidget(DownloadListWidget *w) +{ + if (dw) + { + dw->deleteLater(); + dw = nullptr; + } + + dw = w; + connect(w, &DownloadListWidget::downloadFinished, [=]() + { isDownloading(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString()); }); +} + +void AppIntoPage::initUI() +{ + ui->setupUi(this); + + ui->listWidget->setViewMode(QListView::IconMode); + ui->listWidget->setFlow(QListView::TopToBottom); + ui->listWidget->setMovement(QListView::Static); + ui->listWidget->setMaximumHeight(200); + + clear(); +} + +void AppIntoPage::initConnections() +{ + connect(api, &SparkAPI::finishedRAW, [=](QString download_times) + { + download_times = download_times.trimmed(); + qDebug() << "Download Times:" + download_times; + ui->download_times->setText(download_times); }); +} + +void AppIntoPage::isDownloading(const QUrl &url) { if (dw->getUrlList().lastIndexOf(url) == -1) { @@ -245,9 +327,9 @@ void AppIntoPage::isDownloading(QUrl url) } } -void AppIntoPage::sltAppinfoTags(QStringList *tagList) +void AppIntoPage::setAppinfoTags(const QStringList &tagList) { - foreach (const QString &tag, *tagList) + foreach (const QString &tag, tagList) { if (tag == "community") { @@ -283,44 +365,6 @@ void AppIntoPage::sltAppinfoTags(QStringList *tagList) } } } -void AppIntoPage::setTheme(bool dark) -{ - if (dark) - { - QString frameStyleSheet ="#frame,#frame_2,#frame_3,#frame_4 {background-color: #252525; border-radius: 14px; border: 1px solid rgb(64, 64, 64);}\ - QLabel#cardtitle,QLabel#title,QLabel#title_1,QLabel#title_2,QLabel#title_3 {color: #FFFFFF}"; - ui->frame->setStyleSheet(frameStyleSheet); - ui->frame_2->setStyleSheet(frameStyleSheet); - ui->frame_3->setStyleSheet(frameStyleSheet); - ui->frame_4->setStyleSheet(frameStyleSheet); - - ui->icon_1->setPixmap(QPixmap(":/icon/dark/box.svg")); - ui->icon_2->setPixmap(QPixmap(":/icon/dark/box.svg")); - ui->icon_3->setPixmap(QPixmap(":/icon/dark/calendar.svg")); - ui->icon_4->setPixmap(QPixmap(":/icon/dark/text.svg")); - ui->icon_5->setPixmap(QPixmap(":/icon/dark/folder.svg")); - ui->icon_6->setPixmap(QPixmap(":/icon/dark/globe.svg")); - }else { - //亮色模式 - QString frameStyleSheet ="#frame,#frame_2,#frame_3,#frame_4 {background-color: #fbfbfb; border-radius: 14px; border: 1px solid rgb(229,229,229);}\ - QLabel#cardtitle,QLabel#title,QLabel#title_1,QLabel#title_2,QLabel#title_3 {color: #000000}"; - ui->frame->setStyleSheet(frameStyleSheet); - ui->frame_2->setStyleSheet(frameStyleSheet); - ui->frame_3->setStyleSheet(frameStyleSheet); - ui->frame_4->setStyleSheet(frameStyleSheet); - - ui->icon_1->setPixmap(QPixmap(":/icon/light/box.svg")); - ui->icon_2->setPixmap(QPixmap(":/icon/light/box.svg")); - ui->icon_3->setPixmap(QPixmap(":/icon/light/calendar.svg")); - ui->icon_4->setPixmap(QPixmap(":/icon/light/text.svg")); - ui->icon_5->setPixmap(QPixmap(":/icon/light/folder.svg")); - ui->icon_6->setPixmap(QPixmap(":/icon/light/globe.svg")); - } -} -AppIntoPage::~AppIntoPage() -{ - delete ui; -} void AppIntoPage::on_downloadButton_clicked() { @@ -328,23 +372,27 @@ void AppIntoPage::on_downloadButton_clicked() { dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString())]->install(0); isDownloading(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString()); - QObject::connect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString())], &DownloadItem::finished, [=]() - { - isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString()); - disconnect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString())],&DownloadItem::finished,nullptr,nullptr); }); + connect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString())], &DownloadItem::finished, [=]() + { + isDownloading(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString()); + disconnect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString())], &DownloadItem::finished, nullptr, nullptr); }); + return; } + emit clickedDownloadBtn(); + dw->addItem(info["Name"].toString(), info["Filename"].toString(), info["Pkgname"].toString(), iconpixmap, SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString()); if (ui->downloadButton->text() == tr("Reinstall")) { dw->getDIList()[dw->allDownload - 1]->reinstall = true; } ui->downloadButton->setEnabled(false); - QObject::connect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString())], &DownloadItem::finished, [=]() - { - isDownloading(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString()); - disconnect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl()+"store"+spk.path()+"/"+info["Filename"].toString())],&DownloadItem::finished,nullptr,nullptr); }); + connect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString())], &DownloadItem::finished, [=]() + { + isDownloading(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString()); + disconnect(dw->getDIList()[dw->getUrlList().lastIndexOf(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString())], &DownloadItem::finished, nullptr, nullptr); }); + isDownloading(SparkAPI::getServerUrl() + "store" + spk.path() + "/" + info["Filename"].toString()); } @@ -380,9 +428,9 @@ void AppIntoPage::on_pushButton_3_clicked() void AppIntoPage::on_shareButton_clicked() { qDebug() << "Share" << spk; + Application::clipboard()->setText(spk.toString()); + Utils::sendNotification("spark-store", tr("Spark Store"), tr("The URL has been copied to the clipboard")); - QClipboard *clipboard = QApplication::clipboard(); - clipboard->setText(spk.toString()); } void AppIntoPage::on_updateButton_clicked() diff --git a/src/pages/appintopage.h b/src/pages/appintopage.h index d966f3c..f696e7a 100644 --- a/src/pages/appintopage.h +++ b/src/pages/appintopage.h @@ -1,52 +1,55 @@ #ifndef APPINTOPAGE_H #define APPINTOPAGE_H -#include -#include -#include -#include -#include -#include "backend/sparkapi.h" -#include "backend/image_show.h" -#include "widgets/downloadlistwidget.h" #include "utils/utils.h" + +#include +#include +#include + namespace Ui { class AppIntoPage; } +class SparkAPI; +class DownloadListWidget; class AppIntoPage : public QWidget { Q_OBJECT public: - void clear(); - void setDownloadWidget(DownloadListWidget *w); - void setTheme(bool dark); - void openUrl(QUrl url); explicit AppIntoPage(QWidget *parent = nullptr); - ~AppIntoPage(); + ~AppIntoPage() override; -private slots: - void on_downloadButton_clicked(); - - void on_pushButton_3_clicked(); - - void on_shareButton_clicked(); - - void on_updateButton_clicked(); + void openUrl(const QUrl &url); + void clear(); + void setTheme(bool dark); + void setDownloadWidget(DownloadListWidget *w); private: - SparkAPI *api1; - QJsonObject info; - QPixmap iconpixmap; - QUrl spk; - void isDownloading(QUrl url); - void sltAppinfoTags(QStringList *tagList); - DownloadListWidget *dw; - Ui::AppIntoPage *ui; + void initUI(); + void initConnections(); + void isDownloading(const QUrl &url); + void setAppinfoTags(const QStringList &tagList); signals: void clickedDownloadBtn(); + +private slots: + void on_downloadButton_clicked(); + void on_pushButton_3_clicked(); + void on_shareButton_clicked(); + void on_updateButton_clicked(); + +private: + Ui::AppIntoPage *ui; + + SparkAPI *api; + DownloadListWidget *dw = nullptr; + + QJsonObject info; + QPixmap iconpixmap; + QUrl spk; }; #endif // APPINTOPAGE_H diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index d57b403..77da24c 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -1,25 +1,24 @@ #include "utils.h" +#include "application.h" -Utils::Utils() -{ -} +#include // Author: chatGPT -void Utils::sendNotification(QString icon, QString title, QString body) +void Utils::sendNotification(const QString &icon, const QString &title, const QString &body) { - QDBusInterface iface("org.freedesktop.Notifications", - "/org/freedesktop/Notifications", - "org.freedesktop.Notifications"); + QDBusInterface interface("org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + "org.freedesktop.Notifications"); QVariantList args; - args << QCoreApplication::applicationName() // the name of the application - << (uint)0 // replaces the previous notification with the same ID - << icon // the application icon of the notification - << title // the title of the notification - << body // the body of the notification - << QStringList() // no actions - << QVariantMap() // no hints - << -1; // no timeout + args << Application::applicationName() // the name of the application + << static_cast(0) // replaces the previous notification with the same ID + << icon // the application icon of the notification + << title // the title of the notification + << body // the body of the notification + << QStringList() // no actions + << QVariantMap() // no hints + << -1; // no timeout - iface.callWithArgumentList(QDBus::AutoDetect, "Notify", args); + interface.callWithArgumentList(QDBus::AutoDetect, "Notify", args); } diff --git a/src/utils/utils.h b/src/utils/utils.h index 336bbf1..920bd5b 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -2,13 +2,11 @@ #define UTILS_H #include -#include class Utils { public: - Utils(); - static void sendNotification(QString icon,QString title,QString body); + static void sendNotification(const QString &icon, const QString &title, const QString &body); }; #endif // UTILS_H