Refactor systemtrayicon code

This commit is contained in:
Jonas Kvinge
2021-05-20 21:40:08 +02:00
parent 264d47caf4
commit 67f831beba
18 changed files with 335 additions and 442 deletions

View File

@@ -33,13 +33,17 @@
#include "core/application.h"
#include "core/logging.h"
#include "core/systemtrayicon.h"
#include "core/utilities.h"
#ifdef Q_OS_MACOS
# include "core/macsystemtrayicon.h"
#else
# include "core/qtsystemtrayicon.h"
#endif
#include "covermanager/currentalbumcoverloader.h"
const char *OSDBase::kSettingsGroup = "OSD";
OSDBase::OSDBase(SystemTrayIcon *tray_icon, Application *app, QObject *parent)
OSDBase::OSDBase(std::shared_ptr<SystemTrayIcon> tray_icon, Application *app, QObject *parent)
: QObject(parent),
app_(app),
tray_icon_(tray_icon),
@@ -85,11 +89,13 @@ void OSDBase::ReloadSettings() {
custom_text2_ = s.value("CustomText2").toString();
s.endGroup();
if (!SupportsNativeNotifications() && behaviour_ == Native)
if (!SupportsNativeNotifications() && behaviour_ == Native) {
behaviour_ = Pretty;
}
if (!SupportsTrayPopups() && behaviour_ == TrayPopup)
if (!SupportsTrayPopups() && behaviour_ == TrayPopup) {
behaviour_ = Disabled;
}
ReloadPrettyOSDSettings();
@@ -429,7 +435,7 @@ bool OSDBase::SupportsNativeNotifications() {
}
bool OSDBase::SupportsTrayPopups() {
return tray_icon_;
return tray_icon_->isSystemTrayAvailable();
}
void OSDBase::ShowMessageNative(const QString&, const QString&, const QString&, const QImage&) {

View File

@@ -44,7 +44,7 @@ class OSDBase : public QObject {
Q_OBJECT
public:
explicit OSDBase(SystemTrayIcon *tray_icon, Application *app, QObject *parent = nullptr);
explicit OSDBase(std::shared_ptr<SystemTrayIcon> tray_icon, Application *app, QObject *parent = nullptr);
~OSDBase() override;
static const char *kSettingsGroup;
@@ -97,7 +97,7 @@ class OSDBase : public QObject {
private:
Application *app_;
SystemTrayIcon *tray_icon_;
std::shared_ptr<SystemTrayIcon> tray_icon_;
OSDPretty *pretty_popup_;
QString app_name_;

View File

@@ -109,7 +109,7 @@ const QDBusArgument &operator>>(const QDBusArgument &arg, QImage &image) {
}
OSDDBus::OSDDBus(SystemTrayIcon *tray_icon, Application *app, QObject *parent) : OSDBase(tray_icon, app, parent), version_(1, 1), notification_id_(0) {
OSDDBus::OSDDBus(std::shared_ptr<SystemTrayIcon> tray_icon, Application *app, QObject *parent) : OSDBase(tray_icon, app, parent), version_(1, 1), notification_id_(0) {
Init();
}

View File

@@ -47,7 +47,7 @@ class OSDDBus : public OSDBase {
Q_OBJECT
public:
explicit OSDDBus(SystemTrayIcon *tray_icon, Application *app, QObject *parent = nullptr);
explicit OSDDBus(std::shared_ptr<SystemTrayIcon> tray_icon, Application *app, QObject *parent = nullptr);
~OSDDBus() override;
static const char *kSettingsGroup;

View File

@@ -24,8 +24,12 @@
#include "config.h"
#include <memory>
#include <QtGlobal>
#include <QObject>
#include <QString>
#include <QImage>
#include "osdbase.h"
@@ -33,7 +37,7 @@ class OSDMac : public OSDBase {
Q_OBJECT
public:
explicit OSDMac(SystemTrayIcon *tray_icon, Application *app, QObject *parent = nullptr);
explicit OSDMac(std::shared_ptr<SystemTrayIcon> tray_icon, Application *app, QObject *parent = nullptr);
~OSDMac() override;
bool SupportsNativeNotifications() override;

View File

@@ -21,7 +21,7 @@
#include "config.h"
#include "osdmac.h"
#include <memory>
#include <QBuffer>
#include <QByteArray>
@@ -30,6 +30,8 @@
#include "core/scoped_nsobject.h"
#include "osdmac.h"
namespace {
bool NotificationCenterSupported() {
@@ -52,7 +54,7 @@ void SendNotificationCenterMessage(NSString *title, NSString *subtitle) {
} // namespace
OSDMac::OSDMac(SystemTrayIcon *tray_icon, Application *app, QObject *parent) : OSDBase(tray_icon, app, parent) {}
OSDMac::OSDMac(std::shared_ptr<SystemTrayIcon> tray_icon, Application *app, QObject *parent) : OSDBase(tray_icon, app, parent) {}
OSDMac::~OSDMac() = default;