Use newly introduced setBadgeNumber api on Qt >= 6.6

This commit is contained in:
Carl Schwan
2023-04-05 09:40:38 +02:00
parent 4570d6350b
commit f64c8e28da

View File

@@ -10,11 +10,13 @@
#include "user.h" #include "user.h"
#include <QDebug> #include <QDebug>
#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
#include <QDBusConnection> #include <QDBusConnection>
#include <QDBusInterface> #include <QDBusInterface>
#include <QDBusMessage> #include <QDBusMessage>
#endif #endif
#endif
#include <KLocalizedString> #include <KLocalizedString>
#include <QGuiApplication> #include <QGuiApplication>
@@ -29,15 +31,6 @@ using namespace Quotient;
Q_DECLARE_METATYPE(Quotient::JoinState) 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) RoomListModel::RoomListModel(QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent)
{ {
@@ -46,30 +39,32 @@ RoomListModel::RoomListModel(QObject *parent)
m_categoryVisibility[collapsedSection] = false; m_categoryVisibility[collapsedSection] = false;
} }
#ifndef Q_OS_ANDROID
connect(this, &RoomListModel::notificationCountChanged, this, [this]() { connect(this, &RoomListModel::notificationCountChanged, this, [this]() {
if (useUnityCounter()) { #if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
// copied from Telegram desktop #ifndef Q_OS_ANDROID
const auto launcherUrl = "application://org.kde.neochat.desktop"; // copied from Telegram desktop
// Gnome requires that count is a 64bit integer const auto launcherUrl = "application://org.kde.neochat.desktop";
const qint64 counterSlice = std::min(m_notificationCount, 9999); // Gnome requires that count is a 64bit integer
QVariantMap dbusUnityProperties; const qint64 counterSlice = std::min(m_notificationCount, 9999);
QVariantMap dbusUnityProperties;
if (counterSlice > 0) { if (counterSlice > 0) {
dbusUnityProperties["count"] = counterSlice; dbusUnityProperties["count"] = counterSlice;
dbusUnityProperties["count-visible"] = true; dbusUnityProperties["count-visible"] = true;
} else { } else {
dbusUnityProperties["count-visible"] = false; 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);
} }
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; RoomListModel::~RoomListModel() = default;