Use C++11 enum class
This commit is contained in:
@@ -47,10 +47,10 @@ OSDBase::OSDBase(std::shared_ptr<SystemTrayIcon> tray_icon, Application *app, QO
|
||||
: QObject(parent),
|
||||
app_(app),
|
||||
tray_icon_(tray_icon),
|
||||
pretty_popup_(new OSDPretty(OSDPretty::Mode_Popup)),
|
||||
pretty_popup_(new OSDPretty(OSDPretty::Mode::Popup)),
|
||||
app_name_(QCoreApplication::applicationName()),
|
||||
timeout_msec_(5000),
|
||||
behaviour_(Native),
|
||||
behaviour_(Behaviour::Native),
|
||||
show_on_volume_change_(false),
|
||||
show_art_(true),
|
||||
show_on_play_mode_change_(true),
|
||||
@@ -75,7 +75,7 @@ void OSDBase::ReloadSettings() {
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(kSettingsGroup);
|
||||
behaviour_ = OSDBase::Behaviour(s.value("Behaviour", Native).toInt());
|
||||
behaviour_ = static_cast<OSDBase::Behaviour>(s.value("Behaviour", static_cast<int>(Behaviour::Native)).toInt());
|
||||
timeout_msec_ = s.value("Timeout", 5000).toInt();
|
||||
show_on_volume_change_ = s.value("ShowOnVolumeChange", false).toBool();
|
||||
show_art_ = s.value("ShowArt", true).toBool();
|
||||
@@ -88,15 +88,15 @@ void OSDBase::ReloadSettings() {
|
||||
s.endGroup();
|
||||
|
||||
#ifdef Q_OS_WIN32
|
||||
if (!SupportsNativeNotifications() && !SupportsTrayPopups() && behaviour_ == Native) {
|
||||
if (!SupportsNativeNotifications() && !SupportsTrayPopups() && behaviour_ == Behaviour::Native) {
|
||||
#else
|
||||
if (!SupportsNativeNotifications() && behaviour_ == Native) {
|
||||
if (!SupportsNativeNotifications() && behaviour_ == Behaviour::Native) {
|
||||
#endif
|
||||
behaviour_ = Pretty;
|
||||
behaviour_ = Behaviour::Pretty;
|
||||
}
|
||||
|
||||
if (!SupportsTrayPopups() && behaviour_ == TrayPopup) {
|
||||
behaviour_ = Disabled;
|
||||
if (!SupportsTrayPopups() && behaviour_ == Behaviour::TrayPopup) {
|
||||
behaviour_ = Behaviour::Disabled;
|
||||
}
|
||||
|
||||
ReloadPrettyOSDSettings();
|
||||
@@ -139,8 +139,8 @@ void OSDBase::ShowPlaying(const Song &song, const QUrl &cover_url, const QImage
|
||||
QString summary;
|
||||
bool html_escaped = false;
|
||||
if (use_custom_text_) {
|
||||
summary = ReplaceMessage(Type_Summary, custom_text1_, song);
|
||||
message_parts << ReplaceMessage(Type_Message, custom_text2_, song);
|
||||
summary = ReplaceMessage(MessageType::Summary, custom_text1_, song);
|
||||
message_parts << ReplaceMessage(MessageType::Message, custom_text2_, song);
|
||||
}
|
||||
else {
|
||||
summary = song.PrettyTitle();
|
||||
@@ -156,12 +156,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_ == Pretty) {
|
||||
if (behaviour_ == Behaviour::Pretty) {
|
||||
summary = summary.toHtmlEscaped();
|
||||
html_escaped = true;
|
||||
}
|
||||
#if defined(HAVE_DBUS) && !defined(Q_OS_MACOS)
|
||||
else if (behaviour_ == Native) {
|
||||
else if (behaviour_ == Behaviour::Native) {
|
||||
html_escaped = true;
|
||||
}
|
||||
#endif
|
||||
@@ -194,7 +194,7 @@ void OSDBase::Paused() {
|
||||
if (show_on_pause_) {
|
||||
QString summary;
|
||||
if (use_custom_text_) {
|
||||
summary = ReplaceMessage(Type_Summary, custom_text1_, last_song_);
|
||||
summary = ReplaceMessage(MessageType::Summary, custom_text1_, last_song_);
|
||||
}
|
||||
else {
|
||||
summary = last_song_.PrettyTitle();
|
||||
@@ -202,7 +202,7 @@ void OSDBase::Paused() {
|
||||
summary.prepend(" - ");
|
||||
summary.prepend(last_song_.artist());
|
||||
}
|
||||
if (behaviour_ == Pretty) {
|
||||
if (behaviour_ == Behaviour::Pretty) {
|
||||
summary = summary.toHtmlEscaped();
|
||||
}
|
||||
}
|
||||
@@ -239,7 +239,7 @@ void OSDBase::Stopped() {
|
||||
|
||||
QString summary;
|
||||
if (use_custom_text_) {
|
||||
summary = ReplaceMessage(Type_Summary, custom_text1_, last_song_);
|
||||
summary = ReplaceMessage(MessageType::Summary, custom_text1_, last_song_);
|
||||
}
|
||||
else {
|
||||
summary = last_song_.PrettyTitle();
|
||||
@@ -247,7 +247,7 @@ void OSDBase::Stopped() {
|
||||
summary.prepend(" - ");
|
||||
summary.prepend(last_song_.artist());
|
||||
}
|
||||
if (behaviour_ == Pretty) {
|
||||
if (behaviour_ == Behaviour::Pretty) {
|
||||
summary = summary.toHtmlEscaped();
|
||||
}
|
||||
}
|
||||
@@ -283,11 +283,11 @@ void OSDBase::VolumeChanged(const uint value) {
|
||||
if (!show_on_volume_change_) return;
|
||||
|
||||
QString message = tr("Volume %1%").arg(value);
|
||||
if (behaviour_ == Pretty) {
|
||||
if (behaviour_ == Behaviour::Pretty) {
|
||||
message = message.toHtmlEscaped();
|
||||
}
|
||||
#if defined(HAVE_DBUS) && !defined(Q_OS_MACOS)
|
||||
else if (behaviour_ == Native) {
|
||||
else if (behaviour_ == Behaviour::Native) {
|
||||
message = message.toHtmlEscaped();
|
||||
}
|
||||
#endif
|
||||
@@ -303,7 +303,7 @@ void OSDBase::ShowMessage(const QString &summary, const QString &message, const
|
||||
}
|
||||
else {
|
||||
switch (behaviour_) {
|
||||
case Native:
|
||||
case Behaviour::Native:
|
||||
#ifdef Q_OS_WIN32
|
||||
Q_UNUSED(icon)
|
||||
[[fallthrough]];
|
||||
@@ -316,18 +316,18 @@ void OSDBase::ShowMessage(const QString &summary, const QString &message, const
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case TrayPopup:
|
||||
case Behaviour::TrayPopup:
|
||||
#ifdef Q_OS_MACOS
|
||||
[[fallthrough]];
|
||||
#else
|
||||
if (tray_icon_) tray_icon_->ShowPopup(summary, message, timeout_msec_);
|
||||
break;
|
||||
#endif
|
||||
case Disabled:
|
||||
case Behaviour::Disabled:
|
||||
if (!force_show_next_) break;
|
||||
force_show_next_ = false;
|
||||
[[fallthrough]];
|
||||
case Pretty:
|
||||
case Behaviour::Pretty:
|
||||
pretty_popup_->ShowMessage(summary, message, image);
|
||||
break;
|
||||
|
||||
@@ -343,10 +343,10 @@ void OSDBase::ShuffleModeChanged(const PlaylistSequence::ShuffleMode mode) {
|
||||
if (show_on_play_mode_change_) {
|
||||
QString current_mode = QString();
|
||||
switch (mode) {
|
||||
case PlaylistSequence::Shuffle_Off: current_mode = tr("Don't shuffle"); break;
|
||||
case PlaylistSequence::Shuffle_All: current_mode = tr("Shuffle all"); break;
|
||||
case PlaylistSequence::Shuffle_InsideAlbum: current_mode = tr("Shuffle tracks in this album"); break;
|
||||
case PlaylistSequence::Shuffle_Albums: current_mode = tr("Shuffle albums"); break;
|
||||
case PlaylistSequence::ShuffleMode::Off: current_mode = tr("Don't shuffle"); break;
|
||||
case PlaylistSequence::ShuffleMode::All: current_mode = tr("Shuffle all"); break;
|
||||
case PlaylistSequence::ShuffleMode::InsideAlbum: current_mode = tr("Shuffle tracks in this album"); break;
|
||||
case PlaylistSequence::ShuffleMode::Albums: current_mode = tr("Shuffle albums"); break;
|
||||
}
|
||||
ShowMessage(app_name_, current_mode);
|
||||
}
|
||||
@@ -358,12 +358,12 @@ void OSDBase::RepeatModeChanged(const PlaylistSequence::RepeatMode mode) {
|
||||
if (show_on_play_mode_change_) {
|
||||
QString current_mode = QString();
|
||||
switch (mode) {
|
||||
case PlaylistSequence::Repeat_Off: current_mode = tr("Don't repeat"); break;
|
||||
case PlaylistSequence::Repeat_Track: current_mode = tr("Repeat track"); break;
|
||||
case PlaylistSequence::Repeat_Album: current_mode = tr("Repeat album"); break;
|
||||
case PlaylistSequence::Repeat_Playlist: current_mode = tr("Repeat playlist"); break;
|
||||
case PlaylistSequence::Repeat_OneByOne: current_mode = tr("Stop after every track"); break;
|
||||
case PlaylistSequence::Repeat_Intro: current_mode = tr("Intro tracks"); break;
|
||||
case PlaylistSequence::RepeatMode::Off: current_mode = tr("Don't repeat"); break;
|
||||
case PlaylistSequence::RepeatMode::Track: current_mode = tr("Repeat track"); break;
|
||||
case PlaylistSequence::RepeatMode::Album: current_mode = tr("Repeat album"); break;
|
||||
case PlaylistSequence::RepeatMode::Playlist: current_mode = tr("Repeat playlist"); break;
|
||||
case PlaylistSequence::RepeatMode::OneByOne: current_mode = tr("Stop after every track"); break;
|
||||
case PlaylistSequence::RepeatMode::Intro: current_mode = tr("Intro tracks"); break;
|
||||
}
|
||||
ShowMessage(app_name_, current_mode);
|
||||
}
|
||||
@@ -381,19 +381,19 @@ QString OSDBase::ReplaceMessage(const MessageType type, const QString &message,
|
||||
|
||||
// We need different strings depending on notification type
|
||||
switch (behaviour_) {
|
||||
case Native:
|
||||
case Behaviour::Native:
|
||||
#if defined(Q_OS_MACOS)
|
||||
html_escaped = false;
|
||||
newline = "\n";
|
||||
break;
|
||||
#elif defined(HAVE_DBUS)
|
||||
switch (type) {
|
||||
case Type_Summary:{
|
||||
case MessageType::Summary:{
|
||||
html_escaped = false;
|
||||
newline = "";
|
||||
break;
|
||||
}
|
||||
case Type_Message: {
|
||||
case MessageType::Message: {
|
||||
html_escaped = true;
|
||||
newline = "<br />";
|
||||
break;
|
||||
@@ -407,13 +407,13 @@ QString OSDBase::ReplaceMessage(const MessageType type, const QString &message,
|
||||
qLog(Debug) << "Native notifications are not supported on this OS.";
|
||||
break;
|
||||
#endif
|
||||
case TrayPopup:
|
||||
case Behaviour::TrayPopup:
|
||||
qLog(Debug) << "New line not supported by this notification type.";
|
||||
html_escaped = false;
|
||||
newline = "";
|
||||
break;
|
||||
case Disabled: // When notifications are disabled, we force the PrettyOSD
|
||||
case Pretty:
|
||||
case Behaviour::Disabled: // When notifications are disabled, we force the PrettyOSD
|
||||
case Behaviour::Pretty:
|
||||
html_escaped = true;
|
||||
newline = "<br />";
|
||||
break;
|
||||
|
||||
@@ -49,11 +49,11 @@ class OSDBase : public QObject {
|
||||
|
||||
static const char *kSettingsGroup;
|
||||
|
||||
enum Behaviour {
|
||||
enum class Behaviour {
|
||||
Disabled = 0,
|
||||
Native,
|
||||
TrayPopup,
|
||||
Pretty,
|
||||
Pretty
|
||||
};
|
||||
|
||||
int timeout_msec() const { return timeout_msec_; }
|
||||
@@ -83,9 +83,9 @@ class OSDBase : public QObject {
|
||||
void ShowPreview(const OSDBase::Behaviour type, const QString &line1, const QString &line2, const Song &song);
|
||||
|
||||
private:
|
||||
enum MessageType {
|
||||
Type_Summary,
|
||||
Type_Message,
|
||||
enum class MessageType {
|
||||
Summary,
|
||||
Message
|
||||
};
|
||||
void ShowPlaying(const Song &song, const QUrl &cover_url, const QImage &image, const bool preview = false);
|
||||
void ShowMessage(const QString &summary, const QString &message = QString(), const QString &icon = "strawberry", const QImage &image = QImage());
|
||||
|
||||
@@ -112,11 +112,11 @@ OSDPretty::OSDPretty(Mode mode, QWidget *parent)
|
||||
|
||||
// Mode settings
|
||||
switch (mode_) {
|
||||
case Mode_Popup:
|
||||
case Mode::Popup:
|
||||
setCursor(QCursor(Qt::ArrowCursor));
|
||||
break;
|
||||
|
||||
case Mode_Draggable:
|
||||
case Mode::Draggable:
|
||||
setCursor(QCursor(Qt::OpenHandCursor));
|
||||
break;
|
||||
}
|
||||
@@ -189,7 +189,7 @@ void OSDPretty::showEvent(QShowEvent *e) {
|
||||
fader_->setDirection(QTimeLine::Forward);
|
||||
fader_->start(); // Timeout will be started in FaderFinished
|
||||
}
|
||||
else if (mode_ == Mode_Popup) {
|
||||
else if (mode_ == Mode::Popup) {
|
||||
if (!disable_duration()) {
|
||||
timeout_->start();
|
||||
}
|
||||
@@ -363,7 +363,7 @@ void OSDPretty::ShowMessage(const QString &summary, const QString &message, cons
|
||||
|
||||
SetMessage(summary, message, image);
|
||||
|
||||
if (isVisible() && mode_ == Mode_Popup) {
|
||||
if (isVisible() && mode_ == Mode::Popup) {
|
||||
// The OSD is already visible, toggle or restart the timer
|
||||
if (toggle_mode()) {
|
||||
set_toggle_mode(false);
|
||||
@@ -406,7 +406,7 @@ void OSDPretty::FaderFinished() {
|
||||
if (fader_->direction() == QTimeLine::Backward) {
|
||||
hide();
|
||||
}
|
||||
else if (mode_ == Mode_Popup && !disable_duration()) {
|
||||
else if (mode_ == Mode::Popup && !disable_duration()) {
|
||||
timeout_->start();
|
||||
}
|
||||
|
||||
@@ -465,7 +465,7 @@ void OSDPretty::enterEvent(QEnterEvent*) {
|
||||
#else
|
||||
void OSDPretty::enterEvent(QEvent*) {
|
||||
#endif
|
||||
if (mode_ == Mode_Popup) {
|
||||
if (mode_ == Mode::Popup) {
|
||||
setWindowOpacity(0.25);
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ void OSDPretty::leaveEvent(QEvent*) {
|
||||
|
||||
void OSDPretty::mousePressEvent(QMouseEvent *e) {
|
||||
|
||||
if (mode_ == Mode_Popup) {
|
||||
if (mode_ == Mode::Popup) {
|
||||
hide();
|
||||
}
|
||||
else {
|
||||
@@ -493,7 +493,7 @@ void OSDPretty::mousePressEvent(QMouseEvent *e) {
|
||||
|
||||
void OSDPretty::mouseMoveEvent(QMouseEvent *e) {
|
||||
|
||||
if (mode_ == Mode_Draggable) {
|
||||
if (mode_ == Mode::Draggable) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QPoint delta = e->globalPosition().toPoint() - drag_start_pos_;
|
||||
#else
|
||||
@@ -530,7 +530,7 @@ void OSDPretty::mouseMoveEvent(QMouseEvent *e) {
|
||||
|
||||
void OSDPretty::mouseReleaseEvent(QMouseEvent *) {
|
||||
|
||||
if (current_screen() && mode_ == Mode_Draggable) {
|
||||
if (current_screen() && mode_ == Mode::Draggable) {
|
||||
popup_screen_ = current_screen();
|
||||
popup_screen_name_ = current_screen()->name();
|
||||
popup_pos_ = current_pos();
|
||||
|
||||
@@ -52,9 +52,9 @@ class OSDPretty : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Mode {
|
||||
Mode_Popup,
|
||||
Mode_Draggable,
|
||||
enum class Mode {
|
||||
Popup,
|
||||
Draggable
|
||||
};
|
||||
|
||||
explicit OSDPretty(Mode mode, QWidget *parent = nullptr);
|
||||
|
||||
Reference in New Issue
Block a user