Refactoring

This commit is contained in:
Jonas Kvinge
2024-10-22 18:12:33 +02:00
parent dfcf715291
commit 8da2b9cd94
623 changed files with 9071 additions and 5126 deletions

View File

@@ -31,30 +31,26 @@
#include "osdbase.h"
#include "osdpretty.h"
#include "core/shared_ptr.h"
#include "core/application.h"
#include "includes/shared_ptr.h"
#include "core/logging.h"
#include "core/settings.h"
#ifdef Q_OS_MACOS
# include "core/macsystemtrayicon.h"
# include "systemtrayicon/macsystemtrayicon.h"
#else
# include "core/qtsystemtrayicon.h"
# include "systemtrayicon/qtsystemtrayicon.h"
#endif
#include "utilities/strutils.h"
#include "covermanager/currentalbumcoverloader.h"
#include "constants/notificationssettings.h"
using namespace Qt::Literals::StringLiterals;
const char *OSDBase::kSettingsGroup = "OSD";
OSDBase::OSDBase(SharedPtr<SystemTrayIcon> tray_icon, Application *app, QObject *parent)
OSDBase::OSDBase(const SharedPtr<SystemTrayIcon> tray_icon, QObject *parent)
: QObject(parent),
app_(app),
tray_icon_(tray_icon),
pretty_popup_(new OSDPretty(OSDPretty::Mode::Popup)),
app_name_(QCoreApplication::applicationName()),
timeout_msec_(5000),
behaviour_(Behaviour::Native),
type_(OSDSettings::Type::Native),
show_on_volume_change_(false),
show_art_(true),
show_on_play_mode_change_(true),
@@ -65,8 +61,6 @@ OSDBase::OSDBase(SharedPtr<SystemTrayIcon> tray_icon, Application *app, QObject
ignore_next_stopped_(false),
playing_(false) {
QObject::connect(&*app_->current_albumcover_loader(), &CurrentAlbumCoverLoader::ThumbnailLoaded, this, &OSDBase::AlbumCoverLoaded);
app_name_[0] = app_name_[0].toUpper();
}
@@ -78,9 +72,9 @@ OSDBase::~OSDBase() {
void OSDBase::ReloadSettings() {
Settings s;
s.beginGroup(kSettingsGroup);
behaviour_ = static_cast<OSDBase::Behaviour>(s.value("Behaviour", static_cast<int>(Behaviour::Native)).toInt());
timeout_msec_ = s.value("Timeout", 5000).toInt();
s.beginGroup(OSDSettings::kSettingsGroup);
type_ = static_cast<OSDSettings::Type>(s.value(OSDSettings::kType, static_cast<int>(OSDSettings::Type::Native)).toInt());
timeout_msec_ = s.value(OSDSettings::kTimeout, 5000).toInt();
show_on_volume_change_ = s.value("ShowOnVolumeChange", false).toBool();
show_art_ = s.value("ShowArt", true).toBool();
show_on_play_mode_change_ = s.value("ShowOnPlayModeChange", true).toBool();
@@ -92,15 +86,15 @@ void OSDBase::ReloadSettings() {
s.endGroup();
#ifdef Q_OS_WIN32
if (!SupportsNativeNotifications() && !SupportsTrayPopups() && behaviour_ == Behaviour::Native) {
if (!SupportsNativeNotifications() && !SupportsTrayPopups() && type_ == OSDSettings::Type::Native) {
#else
if (!SupportsNativeNotifications() && behaviour_ == Behaviour::Native) {
if (!SupportsNativeNotifications() && type_ == OSDSettings::Type::Native) {
#endif
behaviour_ = Behaviour::Pretty;
type_ = OSDSettings::Type::Pretty;
}
if (!SupportsTrayPopups() && behaviour_ == Behaviour::TrayPopup) {
behaviour_ = Behaviour::Disabled;
if (!SupportsTrayPopups() && type_ == OSDSettings::Type::TrayPopup) {
type_ = OSDSettings::Type::Disabled;
}
ReloadPrettyOSDSettings();
@@ -160,12 +154,12 @@ void OSDBase::ShowPlaying(const Song &song, const QUrl &cover_url, const QImage
if (song.track() > 0) {
message_parts << tr("track %1").arg(song.track());
}
if (behaviour_ == Behaviour::Pretty) {
if (type_ == OSDSettings::Type::Pretty) {
summary = summary.toHtmlEscaped();
html_escaped = true;
}
#if defined(HAVE_DBUS) && !defined(Q_OS_MACOS)
else if (behaviour_ == Behaviour::Native) {
else if (type_ == OSDSettings::Type::Native) {
html_escaped = true;
}
#endif
@@ -206,7 +200,7 @@ void OSDBase::Paused() {
summary.prepend(" - "_L1);
summary.prepend(last_song_.artist());
}
if (behaviour_ == Behaviour::Pretty) {
if (type_ == OSDSettings::Type::Pretty) {
summary = summary.toHtmlEscaped();
}
}
@@ -251,7 +245,7 @@ void OSDBase::Stopped() {
summary.prepend(" - "_L1);
summary.prepend(last_song_.artist());
}
if (behaviour_ == Behaviour::Pretty) {
if (type_ == OSDSettings::Type::Pretty) {
summary = summary.toHtmlEscaped();
}
}
@@ -287,11 +281,11 @@ void OSDBase::VolumeChanged(const uint value) {
if (!show_on_volume_change_) return;
QString message = tr("Volume %1%").arg(value);
if (behaviour_ == Behaviour::Pretty) {
if (type_ == OSDSettings::Type::Pretty) {
message = message.toHtmlEscaped();
}
#if defined(HAVE_DBUS) && !defined(Q_OS_MACOS)
else if (behaviour_ == Behaviour::Native) {
else if (type_ == OSDSettings::Type::Native) {
message = message.toHtmlEscaped();
}
#endif
@@ -306,8 +300,8 @@ void OSDBase::ShowMessage(const QString &summary, const QString &message, const
pretty_popup_->ShowMessage(summary, message, image);
}
else {
switch (behaviour_) {
case Behaviour::Native:
switch (type_) {
case OSDSettings::Type::Native:
#ifdef Q_OS_WIN32
Q_UNUSED(icon)
[[fallthrough]];
@@ -320,18 +314,18 @@ void OSDBase::ShowMessage(const QString &summary, const QString &message, const
}
break;
#endif
case Behaviour::TrayPopup:
case OSDSettings::Type::TrayPopup:
#ifdef Q_OS_MACOS
[[fallthrough]];
#else
if (tray_icon_) tray_icon_->ShowPopup(summary, message, timeout_msec_);
break;
#endif
case Behaviour::Disabled:
case OSDSettings::Type::Disabled:
if (!force_show_next_) break;
force_show_next_ = false;
[[fallthrough]];
case Behaviour::Pretty:
case OSDSettings::Type::Pretty:
pretty_popup_->ShowMessage(summary, message, image);
break;
@@ -384,8 +378,8 @@ QString OSDBase::ReplaceMessage(const MessageType type, const QString &message,
QString newline = ""_L1;
// We need different strings depending on notification type
switch (behaviour_) {
case Behaviour::Native:
switch (type_) {
case OSDSettings::Type::Native:
#if defined(Q_OS_MACOS)
html_escaped = false;
newline = QLatin1String("\n");
@@ -411,13 +405,13 @@ QString OSDBase::ReplaceMessage(const MessageType type, const QString &message,
qLog(Debug) << "Native notifications are not supported on this OS.";
break;
#endif
case Behaviour::TrayPopup:
case OSDSettings::Type::TrayPopup:
qLog(Debug) << "New line not supported by this notification type.";
html_escaped = false;
newline = ""_L1;
break;
case Behaviour::Disabled: // When notifications are disabled, we force the PrettyOSD
case Behaviour::Pretty:
case OSDSettings::Type::Disabled: // When notifications are disabled, we force the PrettyOSD
case OSDSettings::Type::Pretty:
html_escaped = true;
newline = "<br />"_L1;
break;
@@ -427,9 +421,9 @@ QString OSDBase::ReplaceMessage(const MessageType type, const QString &message,
}
void OSDBase::ShowPreview(const Behaviour type, const QString &line1, const QString &line2, const Song &song) {
void OSDBase::ShowPreview(const OSDSettings::Type type, const QString &line1, const QString &line2, const Song &song) {
behaviour_ = type;
type_ = type;
custom_text1_ = line1;
custom_text2_ = line2;
if (!use_custom_text_) use_custom_text_ = true;