Merge g152 via gui_notify_setup_bg

This commit is contained in:
Luke Dashjr 2025-03-05 03:27:08 +00:00
commit f81eeca008
2 changed files with 42 additions and 9 deletions

View File

@ -28,6 +28,18 @@
#ifdef USE_DBUS
// https://wiki.ubuntu.com/NotificationDevelopmentGuidelines recommends at least 128
const int FREEDESKTOP_NOTIFICATION_ICON_SIZE = 128;
void DBusInitThread::run() {
auto interface = new QDBusInterface("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications");
if (!interface->isValid()) {
delete interface;
return;
}
interface->moveToThread(m_notificator.thread());
m_notificator.interface = interface;
m_notificator.mode = Notificator::Freedesktop;
}
#endif
Notificator::Notificator(const QString &_programName, QSystemTrayIcon *_trayIcon, QWidget *_parent) :
@ -41,12 +53,8 @@ Notificator::Notificator(const QString &_programName, QSystemTrayIcon *_trayIcon
mode = QSystemTray;
}
#ifdef USE_DBUS
interface = new QDBusInterface("org.freedesktop.Notifications",
"/org/freedesktop/Notifications", "org.freedesktop.Notifications");
if(interface->isValid())
{
mode = Freedesktop;
}
m_dbus_init_thread = new DBusInitThread(*this);
m_dbus_init_thread->start();
#endif
#ifdef Q_OS_MACOS
// check if users OS has support for NSUserNotification
@ -59,6 +67,8 @@ Notificator::Notificator(const QString &_programName, QSystemTrayIcon *_trayIcon
Notificator::~Notificator()
{
#ifdef USE_DBUS
m_dbus_init_thread->wait();
delete m_dbus_init_thread;
delete interface;
#endif
}
@ -218,8 +228,7 @@ void Notificator::notifyMacUserNotificationCenter(const QString &title, const QS
void Notificator::notify(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout)
{
switch(mode)
{
switch (Mode(mode)) {
#ifdef USE_DBUS
case Freedesktop:
notifyDBus(cls, title, text, icon, millisTimeout);

View File

@ -9,6 +9,9 @@
#include <QIcon>
#include <QObject>
#include <QThread>
#include <atomic>
QT_BEGIN_NAMESPACE
class QSystemTrayIcon;
@ -18,6 +21,23 @@ class QDBusInterface;
#endif
QT_END_NAMESPACE
class Notificator;
#ifdef USE_DBUS
class DBusInitThread : public QThread
{
Q_OBJECT
Notificator& m_notificator;
public:
DBusInitThread(Notificator& notificator) : m_notificator(notificator) {};
protected:
void run() override;
};
#endif
/** Cross-platform desktop notification client. */
class Notificator: public QObject
{
@ -59,11 +79,15 @@ private:
UserNotificationCenter /**< Use the 10.8+ User Notification Center (Mac only) */
};
QString programName;
Mode mode{None};
std::atomic<Mode> mode{None};
QSystemTrayIcon *trayIcon;
#ifdef USE_DBUS
QThread *m_dbus_init_thread{nullptr};
protected:
QDBusInterface* interface{nullptr};
friend class DBusInitThread;
private:
void notifyDBus(Class cls, const QString &title, const QString &text, const QIcon &icon, int millisTimeout);
#endif
void notifySystray(Class cls, const QString &title, const QString &text, int millisTimeout);