From e18b2ab437d1fff9b303c01a7f00557e88e28bfc Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 10 Apr 2021 15:42:23 +0800 Subject: [PATCH 1/3] Regenerate D-Bus notifications related code --- src/gui/mainwindow.cpp | 2 +- src/gui/qtnotify/notifications.cpp | 4 ++-- src/gui/qtnotify/notifications.h | 18 +++++++++--------- src/gui/qtnotify/notifications.xml | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index b0dc2d842..170856b6e 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1666,7 +1666,7 @@ void MainWindow::showNotificationBaloon(const QString &title, const QString &msg { if (!isNotificationsEnabled()) return; #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) - org::freedesktop::Notifications notifications("org.freedesktop.Notifications", + OrgFreedesktopNotificationsInterface notifications("org.freedesktop.Notifications", "/org/freedesktop/Notifications", QDBusConnection::sessionBus()); // Testing for 'notifications.isValid()' isn't helpful here. diff --git a/src/gui/qtnotify/notifications.cpp b/src/gui/qtnotify/notifications.cpp index 59b4d9d8b..a91578b49 100644 --- a/src/gui/qtnotify/notifications.cpp +++ b/src/gui/qtnotify/notifications.cpp @@ -1,8 +1,8 @@ /* - * This file was generated by qdbusxml2cpp version 0.7 + * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -p notifications.h:notifications.cpp notifications.xml * - * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. * * This is an auto-generated file. * This file may have been hand-edited. Look for HAND-EDIT comments diff --git a/src/gui/qtnotify/notifications.h b/src/gui/qtnotify/notifications.h index b042599d6..7317b443b 100644 --- a/src/gui/qtnotify/notifications.h +++ b/src/gui/qtnotify/notifications.h @@ -1,15 +1,15 @@ /* - * This file was generated by qdbusxml2cpp version 0.7 + * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -p notifications.h:notifications.cpp notifications.xml * - * qdbusxml2cpp is Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. * * This is an auto-generated file. * Do not edit! All changes made to it will be lost. */ -#ifndef NOTIFICATIONS_H_1301681398 -#define NOTIFICATIONS_H_1301681398 +#ifndef NOTIFICATIONS_H +#define NOTIFICATIONS_H #include #include @@ -40,24 +40,24 @@ public Q_SLOTS: // METHODS { QList argumentList; argumentList << QVariant::fromValue(id); - return asyncCallWithArgumentList(QLatin1String("CloseNotification"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("CloseNotification"), argumentList); } inline QDBusPendingReply GetCapabilities() { QList argumentList; - return asyncCallWithArgumentList(QLatin1String("GetCapabilities"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("GetCapabilities"), argumentList); } inline QDBusPendingReply GetServerInformation() { QList argumentList; - return asyncCallWithArgumentList(QLatin1String("GetServerInformation"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("GetServerInformation"), argumentList); } inline QDBusReply GetServerInformation(QString &return_vendor, QString &return_version, QString &return_spec_version) { QList argumentList; - QDBusMessage reply = callWithArgumentList(QDBus::Block, QLatin1String("GetServerInformation"), argumentList); + QDBusMessage reply = callWithArgumentList(QDBus::Block, QStringLiteral("GetServerInformation"), argumentList); if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() == 4) { return_vendor = qdbus_cast(reply.arguments().at(1)); return_version = qdbus_cast(reply.arguments().at(2)); @@ -70,7 +70,7 @@ public Q_SLOTS: // METHODS { QList argumentList; argumentList << QVariant::fromValue(app_name) << QVariant::fromValue(id) << QVariant::fromValue(icon) << QVariant::fromValue(summary) << QVariant::fromValue(body) << QVariant::fromValue(actions) << QVariant::fromValue(hints) << QVariant::fromValue(timeout); - return asyncCallWithArgumentList(QLatin1String("Notify"), argumentList); + return asyncCallWithArgumentList(QStringLiteral("Notify"), argumentList); } Q_SIGNALS: // SIGNALS diff --git a/src/gui/qtnotify/notifications.xml b/src/gui/qtnotify/notifications.xml index 41f733009..00e85ea53 100644 --- a/src/gui/qtnotify/notifications.xml +++ b/src/gui/qtnotify/notifications.xml @@ -22,7 +22,7 @@ - + From d13be829c33bcb99c29cc28a9729625544a3db49 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 10 Apr 2021 15:47:03 +0800 Subject: [PATCH 2/3] Fix D-Bus Notification `desktop-entry` field --- src/gui/mainwindow.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 170856b6e..47f848ea0 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1678,8 +1678,7 @@ void MainWindow::showNotificationBaloon(const QString &title, const QString &msg // some inactivity shuts it down. Other DEs, like GNOME, choose // to start their daemons at the session startup and have it sit // idling for the whole session. - QVariantMap hints; - hints["desktop-entry"] = "qBittorrent"; + const QVariantMap hints {{QLatin1String("desktop-entry"), QLatin1String("org.qbittorrent.qBittorrent")}}; QDBusPendingReply reply = notifications.Notify("qBittorrent", 0, "qbittorrent", title, msg, QStringList(), hints, getNotificationTimeout()); reply.waitForFinished(); From 53b795696888ee9e82af138545995bf3a02f9ba8 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 10 Apr 2021 15:58:14 +0800 Subject: [PATCH 3/3] Clean up code and remove unused parameters/variables. --- src/base/bittorrent/session.cpp | 7 +++---- src/base/bittorrent/torrentimpl.cpp | 2 +- src/gui/mainwindow.cpp | 16 ++++++++++------ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 0041092c5..9aefb3a30 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -3766,14 +3766,13 @@ void Session::updateSeedingLimitTimer() } } -void Session::handleTorrentShareLimitChanged(TorrentImpl *const torrent) +void Session::handleTorrentShareLimitChanged(TorrentImpl *const) { updateSeedingLimitTimer(); } -void Session::handleTorrentNameChanged(TorrentImpl *const torrent) +void Session::handleTorrentNameChanged(TorrentImpl *const) { - Q_UNUSED(torrent); } void Session::handleTorrentSavePathChanged(TorrentImpl *const torrent) @@ -4653,11 +4652,11 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) m_status.diskWriteQueue = stats[m_metricIndices.peer.numPeersDownDisk]; m_status.peersCount = stats[m_metricIndices.peer.numPeersConnected]; - const int64_t numBlocksRead = stats[m_metricIndices.disk.numBlocksRead]; m_cacheStatus.totalUsedBuffers = stats[m_metricIndices.disk.diskBlocksInUse]; m_cacheStatus.jobQueueLength = stats[m_metricIndices.disk.queuedDiskJobs]; #if (LIBTORRENT_VERSION_NUM < 20000) + const int64_t numBlocksRead = stats[m_metricIndices.disk.numBlocksRead]; const int64_t numBlocksCacheHits = stats[m_metricIndices.disk.numBlocksCacheHits]; m_cacheStatus.readRatio = static_cast(numBlocksCacheHits) / std::max((numBlocksCacheHits + numBlocksRead), 1); #endif diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 3b0b0f9b1..f653b7f71 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1887,7 +1887,7 @@ void TorrentImpl::handleFileCompletedAlert(const lt::file_completed_alert *p) } #if (LIBTORRENT_VERSION_NUM >= 20003) -void TorrentImpl::handleFilePrioAlert(const lt::file_prio_alert *p) +void TorrentImpl::handleFilePrioAlert(const lt::file_prio_alert *) { if (m_nativeHandle.need_save_resume_data()) m_session->handleTorrentNeedSaveResumeData(this); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 47f848ea0..ae9b913c3 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1664,11 +1664,14 @@ void MainWindow::reloadTorrentStats(const QVector &torren void MainWindow::showNotificationBaloon(const QString &title, const QString &msg) const { - if (!isNotificationsEnabled()) return; + if (!isNotificationsEnabled()) + return; + #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) - OrgFreedesktopNotificationsInterface notifications("org.freedesktop.Notifications", - "/org/freedesktop/Notifications", - QDBusConnection::sessionBus()); + OrgFreedesktopNotificationsInterface notifications(QLatin1String("org.freedesktop.Notifications") + , QLatin1String("/org/freedesktop/Notifications") + , QDBusConnection::sessionBus()); + // Testing for 'notifications.isValid()' isn't helpful here. // If the notification daemon is configured to run 'as needed' // the above check can be false if the daemon wasn't started @@ -1679,8 +1682,9 @@ void MainWindow::showNotificationBaloon(const QString &title, const QString &msg // to start their daemons at the session startup and have it sit // idling for the whole session. const QVariantMap hints {{QLatin1String("desktop-entry"), QLatin1String("org.qbittorrent.qBittorrent")}}; - QDBusPendingReply reply = notifications.Notify("qBittorrent", 0, "qbittorrent", title, - msg, QStringList(), hints, getNotificationTimeout()); + QDBusPendingReply reply = notifications.Notify(QLatin1String("qBittorrent"), 0 + , QLatin1String("qbittorrent"), title, msg, {}, hints, getNotificationTimeout()); + reply.waitForFinished(); if (!reply.isError()) return;