From f64c8e28da0c58fc3e5139f303cd970e31be7781 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Wed, 5 Apr 2023 09:40:38 +0200 Subject: [PATCH] Use newly introduced setBadgeNumber api on Qt >= 6.6 --- src/models/roomlistmodel.cpp | 53 ++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/src/models/roomlistmodel.cpp b/src/models/roomlistmodel.cpp index c07f92ace..dfbed4a7a 100644 --- a/src/models/roomlistmodel.cpp +++ b/src/models/roomlistmodel.cpp @@ -10,11 +10,13 @@ #include "user.h" #include +#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0) #ifndef Q_OS_ANDROID #include #include #include #endif +#endif #include #include @@ -29,15 +31,6 @@ using namespace Quotient; Q_DECLARE_METATYPE(Quotient::JoinState) -#ifndef Q_OS_ANDROID -bool useUnityCounter() -{ - static const auto Result = QDBusInterface("com.canonical.Unity", "/").isValid(); - - return Result; -} -#endif - RoomListModel::RoomListModel(QObject *parent) : QAbstractListModel(parent) { @@ -46,30 +39,32 @@ RoomListModel::RoomListModel(QObject *parent) m_categoryVisibility[collapsedSection] = false; } -#ifndef Q_OS_ANDROID connect(this, &RoomListModel::notificationCountChanged, this, [this]() { - if (useUnityCounter()) { - // copied from Telegram desktop - const auto launcherUrl = "application://org.kde.neochat.desktop"; - // Gnome requires that count is a 64bit integer - const qint64 counterSlice = std::min(m_notificationCount, 9999); - QVariantMap dbusUnityProperties; +#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0) +#ifndef Q_OS_ANDROID + // copied from Telegram desktop + const auto launcherUrl = "application://org.kde.neochat.desktop"; + // Gnome requires that count is a 64bit integer + const qint64 counterSlice = std::min(m_notificationCount, 9999); + QVariantMap dbusUnityProperties; - if (counterSlice > 0) { - dbusUnityProperties["count"] = counterSlice; - dbusUnityProperties["count-visible"] = true; - } else { - dbusUnityProperties["count-visible"] = false; - } - - auto signal = QDBusMessage::createSignal("/com/canonical/unity/launcherentry/neochat", "com.canonical.Unity.LauncherEntry", "Update"); - - signal.setArguments({launcherUrl, dbusUnityProperties}); - - QDBusConnection::sessionBus().send(signal); + if (counterSlice > 0) { + dbusUnityProperties["count"] = counterSlice; + dbusUnityProperties["count-visible"] = true; + } else { + dbusUnityProperties["count-visible"] = false; } + + auto signal = QDBusMessage::createSignal("/com/canonical/unity/launcherentry/neochat", "com.canonical.Unity.LauncherEntry", "Update"); + + signal.setArguments({launcherUrl, dbusUnityProperties}); + + QDBusConnection::sessionBus().send(signal); +#endif // Q_OS_ANDROID +#else + qGuiApp->setBadgeNumber(m_notificationCount); +#endif // QT_VERSION_CHECK(6, 6, 0) }); -#endif } RoomListModel::~RoomListModel() = default;