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

@@ -36,11 +36,10 @@ set(SOURCES
core/utilities.cpp
core/imageutils.cpp
core/iconloader.cpp
core/qtsystemtrayicon.cpp
core/standarditemiconloader.cpp
core/systemtrayicon.cpp
core/scopedtransaction.cpp
core/translations.cpp
core/systemtrayicon.cpp
engine/enginetype.cpp
engine/enginebase.cpp
@@ -266,9 +265,7 @@ set(HEADERS
core/tagreaderclient.h
core/taskmanager.h
core/urlhandler.h
core/qtsystemtrayicon.h
core/standarditemiconloader.h
core/systemtrayicon.h
core/mimedata.h
core/stylesheetloader.h
@@ -542,7 +539,10 @@ option(USE_INSTALL_PREFIX "Look for data in CMAKE_INSTALL_PREFIX" ON)
if(NOT APPLE)
set(NOT_APPLE ON)
optional_source(NOT_APPLE SOURCES widgets/qsearchfield_nonmac.cpp)
optional_source(NOT_APPLE
SOURCES widgets/qsearchfield_nonmac.cpp core/qtsystemtrayicon.cpp
HEADERS core/qtsystemtrayicon.h
)
endif()
if(HAVE_GLOBALSHORTCUTS)

View File

@@ -31,37 +31,69 @@
#include <QPixmap>
#include <QAction>
#include "systemtrayicon.h"
#include "song.h"
class MacSystemTrayIconPrivate;
class MacSystemTrayIcon : public SystemTrayIcon {
class SystemTrayIcon : public QObject {
Q_OBJECT
public:
explicit MacSystemTrayIcon(QObject *parent = nullptr);
~MacSystemTrayIcon();
explicit SystemTrayIcon(QObject *parent = nullptr);
~SystemTrayIcon();
bool isSystemTrayAvailable() { return true; }
void setVisible(const bool) {}
void SetTrayiconProgress(const bool enabled);
void SetupMenu(QAction *previous, QAction *play, QAction *stop, QAction *stop_after, QAction *next, QAction *mute, QAction *love, QAction *quit);
void ShowPopup(const QString&, const QString&, const int) {}
void SetNowPlaying(const Song& song, const QUrl &cover_url);
bool MuteEnabled() const { return false; }
void SetMuteEnabled(const bool) {}
void MuteButtonStateChanged(const bool) {}
void SetPlaying(bool enable_play_pause = false);
void SetPaused();
void SetStopped();
void SetNowPlaying(const Song &song, const QUrl&);
void ClearNowPlaying();
void SetProgress(const int percentage);
void LoveVisibilityChanged(const bool) {}
void LoveStateChanged(const bool) {}
private:
void SetupMenuItem(QAction *action);
QPixmap CreateIcon(const QPixmap &icon, const QPixmap &grey_icon);
void UpdateIcon();
private slots:
void ActionChanged();
protected:
// SystemTrayIcon
void UpdateIcon();
signals:
void ChangeVolume(int delta);
void SeekForward();
void SeekBackward();
void NextTrack();
void PreviousTrack();
void ShowHide();
void PlayPause();
private:
std::unique_ptr<MacSystemTrayIconPrivate> p_;
QPixmap normal_icon_;
QPixmap grey_icon_;
std::unique_ptr<MacSystemTrayIconPrivate> p_;
Q_DISABLE_COPY(MacSystemTrayIcon);
QPixmap playing_icon_;
QPixmap paused_icon_;
QPixmap current_state_icon_;
bool trayicon_progress_;
int song_progress_;
Q_DISABLE_COPY(SystemTrayIcon);
};
#endif // MACSYSTEMTRAYICON_H

View File

@@ -21,19 +21,21 @@
#include "config.h"
#include <QApplication>
#include <QMap>
#include <QString>
#include <QUrl>
#include <QIcon>
#include <QAction>
#include <AppKit/NSMenu.h>
#include <AppKit/NSMenuItem.h>
#include "macsystemtrayicon.h"
#include "mac_delegate.h"
#include "song.h"
#include <QApplication>
#include <QAction>
#include <QIcon>
#include <QUrl>
#include <QtDebug>
#include <AppKit/NSMenu.h>
#include <AppKit/NSMenuItem.h>
#include "iconloader.h"
@interface Target :NSObject {
QAction* action_;
@@ -69,21 +71,10 @@ class MacSystemTrayIconPrivate {
dock_menu_ = [[NSMenu alloc] initWithTitle:@"DockMenu"];
QString title = QT_TR_NOOP("Now Playing");
NSString* t = [[NSString alloc] initWithUTF8String:title.toUtf8().constData()];
now_playing_ = [[NSMenuItem alloc]
initWithTitle:t
action:nullptr
keyEquivalent:@""];
now_playing_artist_ = [[NSMenuItem alloc]
initWithTitle:@"Nothing to see here"
action:nullptr
keyEquivalent:@""];
now_playing_title_ = [[NSMenuItem alloc]
initWithTitle:@"Nothing to see here"
action:nullptr
keyEquivalent:@""];
NSString *t = [[NSString alloc] initWithUTF8String:title.toUtf8().constData()];
now_playing_ = [[NSMenuItem alloc] initWithTitle:t action:nullptr keyEquivalent:@""];
now_playing_artist_ = [[NSMenuItem alloc] initWithTitle:@"Nothing to see here" action:nullptr keyEquivalent:@""];
now_playing_title_ = [[NSMenuItem alloc] initWithTitle:@"Nothing to see here" action:nullptr keyEquivalent:@""];
[dock_menu_ insertItem:now_playing_title_ atIndex:0];
[dock_menu_ insertItem:now_playing_artist_ atIndex:0];
@@ -96,39 +87,34 @@ class MacSystemTrayIconPrivate {
ClearNowPlaying();
}
void AddMenuItem(QAction* action) {
void AddMenuItem(QAction *action) {
// Strip accelarators from name.
QString text = action->text().remove("&");
NSString* title = [[NSString alloc] initWithUTF8String: text.toUtf8().constData()];
NSString *title = [[NSString alloc] initWithUTF8String: text.toUtf8().constData()];
// Create an object that can receive user clicks and pass them on to the QAction.
Target* target = [[Target alloc] initWithQAction:action];
NSMenuItem* item = [[[NSMenuItem alloc]
initWithTitle:title
action:@selector(clicked)
keyEquivalent:@""] autorelease];
Target *target = [[Target alloc] initWithQAction:action];
NSMenuItem *item = [[[NSMenuItem alloc] initWithTitle:title action:@selector(clicked) keyEquivalent:@""] autorelease];
[item setEnabled:action->isEnabled()];
[item setTarget:target];
[dock_menu_ addItem:item];
actions_[action] = item;
}
void ActionChanged(QAction* action) {
NSMenuItem* item = actions_[action];
NSString* title = [[NSString alloc] initWithUTF8String: action->text().toUtf8().constData()];
void ActionChanged(QAction *action) {
NSMenuItem *item = actions_[action];
NSString *title = [[NSString alloc] initWithUTF8String: action->text().toUtf8().constData()];
[item setTitle:title];
}
void AddSeparator() {
NSMenuItem* separator = [NSMenuItem separatorItem];
NSMenuItem *separator = [NSMenuItem separatorItem];
[dock_menu_ addItem:separator];
}
void ShowNowPlaying(const QString& artist, const QString& title) {
ClearNowPlaying(); // Makes sure the order is consistent.
[now_playing_artist_ setTitle:
[[NSString alloc] initWithUTF8String: artist.toUtf8().constData()]];
[now_playing_title_ setTitle:
[[NSString alloc] initWithUTF8String: title.toUtf8().constData()]];
[now_playing_artist_ setTitle: [[NSString alloc] initWithUTF8String: artist.toUtf8().constData()]];
[now_playing_title_ setTitle: [[NSString alloc] initWithUTF8String: title.toUtf8().constData()]];
title.isEmpty() ? HideItem(now_playing_title_) : ShowItem(now_playing_title_);
artist.isEmpty() ? HideItem(now_playing_artist_) : ShowItem(now_playing_artist_);
artist.isEmpty() && title.isEmpty() ? HideItem(now_playing_) : ShowItem(now_playing_);
@@ -142,13 +128,13 @@ class MacSystemTrayIconPrivate {
}
private:
void HideItem(NSMenuItem* item) {
void HideItem(NSMenuItem *item) {
if ([dock_menu_ indexOfItem:item] != -1) {
[dock_menu_ removeItem:item];
}
}
void ShowItem(NSMenuItem* item, int index = 0) {
void ShowItem(NSMenuItem *item, int index = 0) {
if ([dock_menu_ indexOfItem:item] == -1) {
[dock_menu_ insertItem:item atIndex:index];
}
@@ -156,25 +142,37 @@ class MacSystemTrayIconPrivate {
QMap<QAction*, NSMenuItem*> actions_;
NSMenu* dock_menu_;
NSMenuItem* now_playing_;
NSMenuItem* now_playing_artist_;
NSMenuItem* now_playing_title_;
NSMenu *dock_menu_;
NSMenuItem *now_playing_;
NSMenuItem *now_playing_artist_;
NSMenuItem *now_playing_title_;
Q_DISABLE_COPY(MacSystemTrayIconPrivate);
};
MacSystemTrayIcon::MacSystemTrayIcon(QObject* parent)
: SystemTrayIcon(parent),
SystemTrayIcon::SystemTrayIcon(QObject *parent)
: QObject(parent),
normal_icon_(QPixmap(":/pictures/strawberry.png").scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)),
grey_icon_(QPixmap(":/pictures/strawberry-grey.png").scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)) {
grey_icon_(QPixmap(":/pictures/strawberry-grey.png").scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)),
playing_icon_(":/pictures/tiny-play.png"),
paused_icon_(":/pictures/tiny-pause.png"),
trayicon_progress_(false),
song_progress_(0) {
QApplication::setWindowIcon(normal_icon_);
}
MacSystemTrayIcon::~MacSystemTrayIcon() {
SystemTrayIcon::~SystemTrayIcon() {}
void SystemTrayIcon::SetTrayiconProgress(const bool enabled) {
trayicon_progress_ = enabled;
UpdateIcon();
}
void MacSystemTrayIcon::SetupMenu(QAction* previous, QAction* play, QAction* stop, QAction* stop_after, QAction* next, QAction* mute, QAction* love, QAction* quit) {
void SystemTrayIcon::SetupMenu(QAction *previous, QAction *play, QAction *stop, QAction *stop_after, QAction *next, QAction *mute, QAction *love, QAction *quit) {
p_.reset(new MacSystemTrayIconPrivate());
SetupMenuItem(previous);
@@ -190,25 +188,58 @@ void MacSystemTrayIcon::SetupMenu(QAction* previous, QAction* play, QAction* sto
}
void MacSystemTrayIcon::SetupMenuItem(QAction* action) {
void SystemTrayIcon::SetupMenuItem(QAction *action) {
p_->AddMenuItem(action);
QObject::connect(action, &QAction::changed, this, &MacSystemTrayIcon::ActionChanged);
QObject::connect(action, &QAction::changed, this, &SystemTrayIcon::ActionChanged);
}
void MacSystemTrayIcon::UpdateIcon() {
QApplication::setWindowIcon(CreateIcon(normal_icon_, normal_icon_));
void SystemTrayIcon::UpdateIcon() {
QApplication::setWindowIcon(CreateIcon(normal_icon_, grey_icon_));
}
void MacSystemTrayIcon::ActionChanged() {
QAction* action = qobject_cast<QAction*>(sender());
void SystemTrayIcon::ActionChanged() {
QAction *action = qobject_cast<QAction*>(sender());
p_->ActionChanged(action);
}
void MacSystemTrayIcon::ClearNowPlaying() {
void SystemTrayIcon::SetPlaying(const bool enable_play_pause) {
Q_UNUSED(enable_play_pause);
current_state_icon_ = playing_icon_;
UpdateIcon();
}
void SystemTrayIcon::SetPaused() {
current_state_icon_ = paused_icon_;
UpdateIcon();
}
void SystemTrayIcon::SetStopped() {
current_state_icon_ = QPixmap();
UpdateIcon();
}
void SystemTrayIcon::SetProgress(const int percentage) {
song_progress_ = percentage;
if (trayicon_progress_) UpdateIcon();
}
void SystemTrayIcon::ClearNowPlaying() {
p_->ClearNowPlaying();
}
void MacSystemTrayIcon::SetNowPlaying(const Song& song, const QUrl& cover_url) {
Q_UNUSED(cover_url);
void SystemTrayIcon::SetNowPlaying(const Song &song, const QUrl&) {
p_->ShowNowPlaying(song.artist(), song.PrettyTitle());
}

View File

@@ -35,7 +35,6 @@
#include <QWindow>
#include <QMetaObject>
#include <QThread>
#include <QSystemTrayIcon>
#include <QSortFilterProxyModel>
#include <QByteArray>
#include <QDir>
@@ -88,13 +87,17 @@
#include "song.h"
#include "stylehelper.h"
#include "stylesheetloader.h"
#include "systemtrayicon.h"
#include "application.h"
#include "database.h"
#include "player.h"
#include "appearance.h"
#include "filesystemmusicstorage.h"
#include "deletefiles.h"
#ifdef Q_OS_MACOS
# include "macsystemtrayicon.h"
#else
# include "qtsystemtrayicon.h"
#endif
#include "engine/enginetype.h"
#include "engine/enginebase.h"
#include "engine/engine_fwd.h"
@@ -184,10 +187,6 @@
# include "musicbrainz/tagfetcher.h"
#endif
#ifdef Q_OS_MACOS
# include "core/macsystemtrayicon.h"
#endif
#ifdef HAVE_MOODBAR
# include "moodbar/moodbarcontroller.h"
# include "moodbar/moodbarproxystyle.h"
@@ -216,7 +215,7 @@ const int kTrackSliderUpdateTimeMs = 200;
const int kTrackPositionUpdateTimeMs = 1000;
}
MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSDBase *osd, const CommandlineOptions &options, QWidget *parent) :
MainWindow::MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_icon, OSDBase *osd, const CommandlineOptions &options, QWidget *parent) :
QMainWindow(parent),
ui_(new Ui_MainWindow),
#ifdef Q_OS_WIN
@@ -745,15 +744,15 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSDBase *osd
mac::SetApplicationHandler(this);
#endif
// Tray icon
if (tray_icon_) {
if (tray_icon_->isSystemTrayAvailable()) {
tray_icon_->SetupMenu(ui_->action_previous_track, ui_->action_play_pause, ui_->action_stop, ui_->action_stop_after_this_track, ui_->action_next_track, ui_->action_mute, ui_->action_love, ui_->action_quit);
QObject::connect(tray_icon_, &SystemTrayIcon::PlayPause, app_->player(), &Player::PlayPauseHelper);
QObject::connect(tray_icon_, &SystemTrayIcon::SeekForward, app_->player(), &Player::SeekForward);
QObject::connect(tray_icon_, &SystemTrayIcon::SeekBackward, app_->player(), &Player::SeekBackward);
QObject::connect(tray_icon_, &SystemTrayIcon::NextTrack, app_->player(), &Player::Next);
QObject::connect(tray_icon_, &SystemTrayIcon::PreviousTrack, app_->player(), &Player::Previous);
QObject::connect(tray_icon_, &SystemTrayIcon::ShowHide, this, &MainWindow::ToggleShowHide);
QObject::connect(tray_icon_, &SystemTrayIcon::ChangeVolume, this, &MainWindow::VolumeWheelEvent);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::PlayPause, app_->player(), &Player::PlayPauseHelper);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::SeekForward, app_->player(), &Player::SeekForward);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::SeekBackward, app_->player(), &Player::SeekBackward);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::NextTrack, app_->player(), &Player::Next);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::PreviousTrack, app_->player(), &Player::Previous);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::ShowHide, this, &MainWindow::ToggleShowHide);
QObject::connect(tray_icon_.get(), &SystemTrayIcon::ChangeVolume, this, &MainWindow::VolumeWheelEvent);
}
// Windows 7 thumbbar buttons
@@ -930,7 +929,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSDBase *osd
show();
break;
case BehaviourSettingsPage::Startup_Hide:
if (QSystemTrayIcon::isSystemTrayAvailable() && tray_icon_ && tray_icon_->IsVisible()) {
if (tray_icon_->isSystemTrayAvailable() && tray_icon_->isVisible()) {
hide();
break;
}
@@ -944,7 +943,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSDBase *osd
was_minimized_ = settings_.value("minimized", false).toBool();
if (was_minimized_) setWindowState(windowState() | Qt::WindowMinimized);
if (!QSystemTrayIcon::isSystemTrayAvailable() || !tray_icon_ || !tray_icon_->IsVisible()) {
if (!tray_icon_->isSystemTrayAvailable() || !tray_icon_->isVisible()) {
hidden_ = false;
settings_.setValue("hidden", false);
show();
@@ -1020,10 +1019,14 @@ void MainWindow::ReloadSettings() {
#ifndef Q_OS_MACOS
s.beginGroup(BehaviourSettingsPage::kSettingsGroup);
bool showtrayicon = s.value("showtrayicon", QSystemTrayIcon::isSystemTrayAvailable()).toBool();
bool showtrayicon = s.value("showtrayicon", tray_icon_->isSystemTrayAvailable()).toBool();
s.endGroup();
if (tray_icon_) tray_icon_->SetVisible(showtrayicon);
if ((!showtrayicon || !QSystemTrayIcon::isSystemTrayAvailable()) && !isVisible()) show();
if (tray_icon_->isSystemTrayAvailable()) {
tray_icon_->setVisible(showtrayicon);
}
if ((!showtrayicon || !tray_icon_->isSystemTrayAvailable()) && !isVisible()) {
show();
}
#endif
s.beginGroup(BehaviourSettingsPage::kSettingsGroup);
@@ -1041,7 +1044,7 @@ void MainWindow::ReloadSettings() {
int iconsize = s.value(AppearanceSettingsPage::kIconSizePlayControlButtons, 32).toInt();
s.endGroup();
if (tray_icon_) tray_icon_->SetTrayiconProgress(trayicon_progress);
tray_icon_->SetTrayiconProgress(trayicon_progress);
ui_->back_button->setIconSize(QSize(iconsize, iconsize));
ui_->pause_play_button->setIconSize(QSize(iconsize, iconsize));
@@ -1056,11 +1059,11 @@ void MainWindow::ReloadSettings() {
ui_->volume->SetEnabled(volume_control);
if (volume_control) {
if (!ui_->action_mute->isVisible()) ui_->action_mute->setVisible(true);
if (tray_icon_ && !tray_icon_->MuteEnabled()) tray_icon_->SetMuteEnabled(true);
if (!tray_icon_->MuteEnabled()) tray_icon_->SetMuteEnabled(true);
}
else {
if (ui_->action_mute->isVisible()) ui_->action_mute->setVisible(false);
if (tray_icon_ && tray_icon_->MuteEnabled()) tray_icon_->SetMuteEnabled(false);
if (tray_icon_->MuteEnabled()) tray_icon_->SetMuteEnabled(false);
}
}
@@ -1181,7 +1184,9 @@ void MainWindow::Exit() {
if (app_->player()->GetState() == Engine::Playing) {
app_->player()->Stop();
hide();
if (tray_icon_) tray_icon_->SetVisible(false);
if (tray_icon_->isSystemTrayAvailable()) {
tray_icon_->setVisible(false);
}
return; // Don't quit the application now: wait for the fadeout finished signal
}
}
@@ -1229,15 +1234,13 @@ void MainWindow::MediaStopped() {
ui_->action_love->setEnabled(false);
ui_->button_love->setEnabled(false);
if (tray_icon_) tray_icon_->LoveStateChanged(false);
tray_icon_->LoveStateChanged(false);
track_position_timer_->stop();
track_slider_timer_->stop();
ui_->track_slider->SetStopped();
if (tray_icon_) {
tray_icon_->SetProgress(0);
tray_icon_->SetStopped();
}
tray_icon_->SetProgress(0);
tray_icon_->SetStopped();
song_playing_ = Song();
song_ = Song();
@@ -1259,9 +1262,7 @@ void MainWindow::MediaPaused() {
track_position_timer_->stop();
track_slider_timer_->stop();
if (tray_icon_) {
tray_icon_->SetPaused();
}
tray_icon_->SetPaused();
}
@@ -1282,7 +1283,7 @@ void MainWindow::MediaPlaying() {
}
ui_->action_play_pause->setEnabled(enable_play_pause);
ui_->track_slider->SetCanSeek(can_seek);
if (tray_icon_) tray_icon_->SetPlaying(enable_play_pause);
tray_icon_->SetPlaying(enable_play_pause);
track_position_timer_->start();
track_slider_timer_->start();
@@ -1298,14 +1299,14 @@ void MainWindow::SendNowPlaying() {
app_->scrobbler()->UpdateNowPlaying(playlist->current_item()->Metadata());
ui_->action_love->setEnabled(true);
ui_->button_love->setEnabled(true);
if (tray_icon_) tray_icon_->LoveStateChanged(true);
tray_icon_->LoveStateChanged(true);
}
}
void MainWindow::VolumeChanged(const int volume) {
ui_->action_mute->setChecked(!volume);
if (tray_icon_) tray_icon_->MuteButtonStateChanged(!volume);
tray_icon_->MuteButtonStateChanged(!volume);
}
void MainWindow::SongChanged(const Song &song) {
@@ -1315,7 +1316,7 @@ void MainWindow::SongChanged(const Song &song) {
song_playing_ = song;
song_ = song;
setWindowTitle(song.PrettyTitleWithArtist());
if (tray_icon_) tray_icon_->SetProgress(0);
tray_icon_->SetProgress(0);
SendNowPlaying();
@@ -1567,7 +1568,7 @@ void MainWindow::showEvent(QShowEvent *e) {
void MainWindow::closeEvent(QCloseEvent *e) {
if (!exit_) {
if (!hidden_ && keep_running_ && e->spontaneous() && QSystemTrayIcon::isSystemTrayAvailable()) {
if (!hidden_ && keep_running_ && e->spontaneous() && tray_icon_->isSystemTrayAvailable()) {
SetHiddenInTray(true);
}
else {
@@ -1606,7 +1607,7 @@ void MainWindow::Seeked(const qint64 microseconds) {
const qint64 position = microseconds / kUsecPerSec;
const qint64 length = app_->player()->GetCurrentItem()->Metadata().length_nanosec() / kNsecPerSec;
if (tray_icon_) tray_icon_->SetProgress(static_cast<int>(double(position) / length * 100));
tray_icon_->SetProgress(static_cast<int>(double(position) / length * 100));
}
@@ -1620,7 +1621,7 @@ void MainWindow::UpdateTrackPosition() {
const int position = std::floor(float(app_->player()->engine()->position_nanosec()) / kNsecPerSec + 0.5);
// Update the tray icon every 10 seconds
if (tray_icon_ && position % 10 == 0) tray_icon_->SetProgress(static_cast<int>(double(position) / length * 100));
if (position % 10 == 0) tray_icon_->SetProgress(static_cast<int>(double(position) / length * 100));
// Send Scrobble
if (app_->scrobbler()->IsEnabled() && item->Metadata().is_metadata_good()) {
@@ -3067,7 +3068,7 @@ void MainWindow::LoveButtonVisibilityChanged(const bool value) {
else
ui_->widget_love->hide();
if (tray_icon_) tray_icon_->LoveVisibilityChanged(value);
tray_icon_->LoveVisibilityChanged(value);
}
@@ -3090,7 +3091,7 @@ void MainWindow::Love() {
app_->scrobbler()->Love();
ui_->button_love->setEnabled(false);
ui_->action_love->setEnabled(false);
if (tray_icon_) tray_icon_->LoveStateChanged(false);
tray_icon_->LoveStateChanged(false);
}

View File

@@ -105,7 +105,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
Q_OBJECT
public:
explicit MainWindow(Application *app, SystemTrayIcon *tray_icon, OSDBase *osd, const CommandlineOptions &options, QWidget *parent = nullptr);
explicit MainWindow(Application *app, std::shared_ptr<SystemTrayIcon> tray_icon, OSDBase *osd, const CommandlineOptions &options, QWidget *parent = nullptr);
~MainWindow() override;
static const char *kSettingsGroup;
@@ -299,7 +299,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
#endif
Application *app_;
SystemTrayIcon *tray_icon_;
std::shared_ptr<SystemTrayIcon> tray_icon_;
OSDBase *osd_;
Lazy<About> about_dialog_;
Lazy<Console> console_;

View File

@@ -29,97 +29,56 @@
#include <QIcon>
#include <QString>
#include <QUrl>
#include <QtEvents>
#include <QSettings>
#include "song.h"
#include "iconloader.h"
#include "utilities.h"
#include "systemtrayicon.h"
#include "qtsystemtrayicon.h"
#include "settings/behavioursettingspage.h"
QtSystemTrayIcon::QtSystemTrayIcon(QObject *parent)
: SystemTrayIcon(parent),
tray_(new QSystemTrayIcon(this)),
SystemTrayIcon::SystemTrayIcon(QObject *parent)
: QSystemTrayIcon(parent),
menu_(new QMenu),
app_name_(QCoreApplication::applicationName()),
icon_(IconLoader::Load("strawberry")),
normal_icon_(icon_.pixmap(48, QIcon::Normal)),
grey_icon_(icon_.pixmap(48, QIcon::Disabled)),
playing_icon_(":/pictures/tiny-play.png"),
paused_icon_(":/pictures/tiny-pause.png"),
action_play_pause_(nullptr),
action_stop_(nullptr),
action_stop_after_this_track_(nullptr),
action_mute_(nullptr) {
action_mute_(nullptr),
trayicon_progress_(false),
song_progress_(0) {
app_name_[0] = app_name_[0].toUpper();
QIcon theme_icon_grey = IconLoader::Load("strawberry-grey");
if (!theme_icon_grey.isNull()) {
grey_icon_ = theme_icon_grey.pixmap(48, QIcon::Disabled);
}
tray_->setIcon(normal_icon_);
tray_->installEventFilter(this);
QtSystemTrayIcon::ClearNowPlaying();
QObject::connect(tray_, &QSystemTrayIcon::activated, this, &QtSystemTrayIcon::Clicked);
if (isSystemTrayAvailable()) {
setIcon(normal_icon_);
setToolTip(app_name_);
}
QObject::connect(this, &QSystemTrayIcon::activated, this, &SystemTrayIcon::Clicked);
}
QtSystemTrayIcon::~QtSystemTrayIcon() {
SystemTrayIcon::~SystemTrayIcon() {
delete menu_;
}
bool QtSystemTrayIcon::eventFilter(QObject *object, QEvent *event) {
void SystemTrayIcon::SetTrayiconProgress(const bool enabled) {
if (QObject::eventFilter(object, event)) return true;
if (object != tray_) return false;
if (event->type() == QEvent::Wheel) {
QWheelEvent *e = static_cast<QWheelEvent*>(event);
if (e->modifiers() == Qt::ShiftModifier) {
if (e->angleDelta().y() > 0) {
emit SeekForward();
}
else {
emit SeekBackward();
}
}
else if (e->modifiers() == Qt::ControlModifier) {
if (e->angleDelta().y() < 0) {
emit NextTrack();
}
else {
emit PreviousTrack();
}
}
else {
QSettings s;
s.beginGroup(BehaviourSettingsPage::kSettingsGroup);
bool prev_next_track = s.value("scrolltrayicon").toBool();
s.endGroup();
if (prev_next_track) {
if (e->angleDelta().y() < 0) {
emit NextTrack();
}
else {
emit PreviousTrack();
}
}
else {
emit ChangeVolume(e->angleDelta().y());
}
}
return true;
}
return false;
trayicon_progress_ = enabled;
UpdateIcon();
}
void QtSystemTrayIcon::SetupMenu(QAction *previous, QAction *play, QAction *stop, QAction *stop_after, QAction *next, QAction *mute, QAction *love, QAction *quit) {
void SystemTrayIcon::SetupMenu(QAction *previous, QAction *play, QAction *stop, QAction *stop_after, QAction *next, QAction *mute, QAction *love, QAction *quit) {
// Creating new actions and connecting them to old ones.
// This allows us to use old actions without displaying shortcuts that can not be used when Strawberry's window is hidden
@@ -141,11 +100,11 @@ void QtSystemTrayIcon::SetupMenu(QAction *previous, QAction *play, QAction *stop
menu_->addSeparator();
menu_->addAction(quit->icon(), quit->text(), quit, &QAction::trigger);
tray_->setContextMenu(menu_);
if (isSystemTrayAvailable()) setContextMenu(menu_);
}
void QtSystemTrayIcon::Clicked(QSystemTrayIcon::ActivationReason reason) {
void SystemTrayIcon::Clicked(const QSystemTrayIcon::ActivationReason reason) {
switch (reason) {
case QSystemTrayIcon::DoubleClick:
@@ -163,17 +122,33 @@ void QtSystemTrayIcon::Clicked(QSystemTrayIcon::ActivationReason reason) {
}
void QtSystemTrayIcon::ShowPopup(const QString &summary, const QString &message, int timeout) {
tray_->showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout);
void SystemTrayIcon::ShowPopup(const QString &summary, const QString &message, const int timeout) {
if (isSystemTrayAvailable()) showMessage(summary, message, QSystemTrayIcon::NoIcon, timeout);
}
void QtSystemTrayIcon::UpdateIcon() {
tray_->setIcon(CreateIcon(normal_icon_, grey_icon_));
void SystemTrayIcon::UpdateIcon() {
if (isSystemTrayAvailable()) setIcon(CreateIcon(normal_icon_, grey_icon_));
}
void QtSystemTrayIcon::SetPaused() {
void SystemTrayIcon::SetPlaying(bool enable_play_pause) {
SystemTrayIcon::SetPaused();
current_state_icon_ = playing_icon_;
UpdateIcon();
action_stop_->setEnabled(true);
action_stop_after_this_track_->setEnabled(true);
action_play_pause_->setIcon(IconLoader::Load("media-playback-pause"));
action_play_pause_->setText(tr("Pause"));
action_play_pause_->setEnabled(enable_play_pause);
}
void SystemTrayIcon::SetPaused() {
current_state_icon_ = paused_icon_;
UpdateIcon();
action_stop_->setEnabled(true);
action_stop_after_this_track_->setEnabled(true);
@@ -184,21 +159,10 @@ void QtSystemTrayIcon::SetPaused() {
}
void QtSystemTrayIcon::SetPlaying(bool enable_play_pause) {
void SystemTrayIcon::SetStopped() {
SystemTrayIcon::SetPlaying();
action_stop_->setEnabled(true);
action_stop_after_this_track_->setEnabled(true);
action_play_pause_->setIcon(IconLoader::Load("media-playback-pause"));
action_play_pause_->setText(tr("Pause"));
action_play_pause_->setEnabled(enable_play_pause);
}
void QtSystemTrayIcon::SetStopped() {
SystemTrayIcon::SetStopped();
current_state_icon_ = QPixmap();
UpdateIcon();
action_stop_->setEnabled(false);
action_stop_after_this_track_->setEnabled(false);
@@ -211,32 +175,29 @@ void QtSystemTrayIcon::SetStopped() {
}
void QtSystemTrayIcon::MuteButtonStateChanged(bool value) {
void SystemTrayIcon::SetProgress(const int percentage) {
song_progress_ = percentage;
UpdateIcon();
}
void SystemTrayIcon::MuteButtonStateChanged(const bool value) {
if (action_mute_) action_mute_->setChecked(value);
}
bool QtSystemTrayIcon::IsVisible() const {
return tray_->isVisible();
void SystemTrayIcon::SetNowPlaying(const Song &song, const QUrl&) {
if (isSystemTrayAvailable()) setToolTip(song.PrettyTitleWithArtist());
}
void QtSystemTrayIcon::SetVisible(bool visible) {
tray_->setVisible(visible);
void SystemTrayIcon::ClearNowPlaying() {
if (isSystemTrayAvailable()) setToolTip(app_name_);
}
void QtSystemTrayIcon::SetNowPlaying(const Song &song, const QUrl&) {
tray_->setToolTip(song.PrettyTitleWithArtist());
}
void QtSystemTrayIcon::ClearNowPlaying() {
tray_->setToolTip(app_name_);
}
void QtSystemTrayIcon::LoveVisibilityChanged(bool value) {
void SystemTrayIcon::LoveVisibilityChanged(const bool value) {
action_love_->setVisible(value);
}
void QtSystemTrayIcon::LoveStateChanged(bool value) {
void SystemTrayIcon::LoveStateChanged(const bool value) {
action_love_->setEnabled(value);
}

View File

@@ -33,55 +33,59 @@
#include <QAction>
#include <QtEvents>
#include "systemtrayicon.h"
#include "song.h"
class QMenu;
class QEvent;
class Song;
class QtSystemTrayIcon : public SystemTrayIcon {
class SystemTrayIcon : public QSystemTrayIcon {
Q_OBJECT
public:
explicit QtSystemTrayIcon(QObject *parent = nullptr);
~QtSystemTrayIcon() override;
explicit SystemTrayIcon(QObject *parent = nullptr);
~SystemTrayIcon() override;
void SetupMenu(QAction *previous, QAction *play, QAction *stop, QAction *stop_after, QAction *next, QAction *mute, QAction *love, QAction *quit) override;
bool IsVisible() const override;
void SetVisible(bool visible) override;
void SetTrayiconProgress(const bool enabled);
void ShowPopup(const QString &summary, const QString &message, int timeout) override;
void SetupMenu(QAction *previous, QAction *play, QAction *stop, QAction *stop_after, QAction *next, QAction *mute, QAction *love, QAction *quit);
void ShowPopup(const QString &summary, const QString &message, const int timeout);
void SetNowPlaying(const Song &song, const QUrl&) override;
void ClearNowPlaying() override;
void SetPlaying(const bool enable_play_pause = false);
void SetPaused();
void SetStopped();
void SetProgress(const int percentage);
void MuteButtonStateChanged(const bool value);
void SetNowPlaying(const Song &song, const QUrl&);
void ClearNowPlaying();
void LoveVisibilityChanged(const bool value);
void LoveStateChanged(const bool value);
bool MuteEnabled() const override { return action_mute_->isVisible(); }
void SetMuteEnabled(bool enabled) override { action_mute_->setVisible(enabled); }
protected:
// SystemTrayIcon
void UpdateIcon() override;
void SetPaused() override;
void SetPlaying(bool enable_play_pause = false) override;
void SetStopped() override;
void MuteButtonStateChanged(bool value) override;
void LoveVisibilityChanged(bool value) override;
void LoveStateChanged(bool value) override;
// QObject
bool eventFilter(QObject*, QEvent*) override;
private slots:
void Clicked(QSystemTrayIcon::ActivationReason);
bool MuteEnabled() const { return action_mute_->isVisible(); }
void SetMuteEnabled(const bool enabled) { action_mute_->setVisible(enabled); }
private:
QPixmap CreateIcon(const QPixmap &icon, const QPixmap &grey_icon);
void UpdateIcon();
signals:
void ChangeVolume(int delta);
void SeekForward();
void SeekBackward();
void NextTrack();
void PreviousTrack();
void ShowHide();
void PlayPause();
private slots:
void Clicked(const QSystemTrayIcon::ActivationReason);
private:
QSystemTrayIcon *tray_;
QMenu *menu_;
QString app_name_;
QIcon icon_;
QPixmap normal_icon_;
QPixmap grey_icon_;
QPixmap playing_icon_;
QPixmap paused_icon_;
QAction *action_play_pause_;
QAction *action_stop_;
@@ -89,6 +93,11 @@ class QtSystemTrayIcon : public SystemTrayIcon {
QAction *action_mute_;
QAction *action_love_;
bool trayicon_progress_;
int song_progress_;
QPixmap current_state_icon_;
};
#endif // QTSYSTEMTRAYICON_H

View File

@@ -23,29 +23,18 @@
#include <cmath>
#include <QObject>
#include <QSystemTrayIcon>
#include <QPixmap>
#include <QPainter>
#include <QPoint>
#include <QPolygon>
#include <QRect>
#include <QVector>
#include "systemtrayicon.h"
#include "qtsystemtrayicon.h"
#ifdef Q_OS_MACOS
# include "macsystemtrayicon.h"
#else
# include "qtsystemtrayicon.h"
#endif
SystemTrayIcon::SystemTrayIcon(QObject *parent)
: QObject(parent),
percentage_(0),
playing_icon_(":/pictures/tiny-play.png"),
paused_icon_(":/pictures/tiny-pause.png")
{
}
QPixmap SystemTrayIcon::CreateIcon(const QPixmap &icon, const QPixmap &grey_icon) {
QRect rect(icon.rect());
@@ -56,14 +45,14 @@ QPixmap SystemTrayIcon::CreateIcon(const QPixmap &icon, const QPixmap &grey_icon
if (trayicon_progress_) {
// The angle of the line that's used to cover the icon.
// Centered on rect.topLeft()
double angle = double(100 - song_progress()) / 100.0 * M_PI_2;
double angle = double(100 - song_progress_) / 100.0 * M_PI_2;
double length = sqrt(pow(rect.width(), 2.0) + pow(rect.height(), 2.0));
QPolygon mask;
mask << rect.topLeft();
mask << rect.topLeft() + QPoint(static_cast<int>(length * sin(angle)), static_cast<int>(length * cos(angle)));
if (song_progress() > 50) mask << rect.bottomRight();
if (song_progress_ > 50) mask << rect.bottomRight();
mask << rect.topRight();
mask << rect.topLeft();
@@ -75,9 +64,9 @@ QPixmap SystemTrayIcon::CreateIcon(const QPixmap &icon, const QPixmap &grey_icon
}
// Draw the playing or paused icon in the top-right
if (!current_state_icon().isNull()) {
if (!current_state_icon_.isNull()) {
int height = rect.height() / 2;
QPixmap scaled(current_state_icon().scaledToHeight(height, Qt::SmoothTransformation));
QPixmap scaled(current_state_icon_.scaledToHeight(height, Qt::SmoothTransformation));
QRect state_rect(rect.width() - scaled.width(), 0, scaled.width(), scaled.height());
p.drawPixmap(state_rect, scaled);
@@ -88,36 +77,3 @@ QPixmap SystemTrayIcon::CreateIcon(const QPixmap &icon, const QPixmap &grey_icon
return ret;
}
void SystemTrayIcon::SetProgress(int percentage) {
percentage_ = percentage;
UpdateIcon();
}
void SystemTrayIcon::SetPaused() {
current_state_icon_ = paused_icon_;
UpdateIcon();
}
void SystemTrayIcon::SetPlaying(bool enable_play_pause) {
Q_UNUSED(enable_play_pause);
current_state_icon_ = playing_icon_;
UpdateIcon();
}
void SystemTrayIcon::SetStopped() {
current_state_icon_ = QPixmap();
UpdateIcon();
}
SystemTrayIcon *SystemTrayIcon::CreateSystemTrayIcon(QObject *parent) {
#ifdef Q_OS_MACOS
return new MacSystemTrayIcon(parent);
#else
if (QSystemTrayIcon::isSystemTrayAvailable()) return new QtSystemTrayIcon(parent);
else return nullptr;
#endif
}

View File

@@ -1,93 +0,0 @@
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef SYSTEMTRAYICON_H
#define SYSTEMTRAYICON_H
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QString>
#include <QPixmap>
class QAction;
class Song;
class SystemTrayIcon : public QObject {
Q_OBJECT
public:
explicit SystemTrayIcon(QObject *parent = nullptr);
// Called once to create the icon's context menu
virtual void SetupMenu(QAction *previous, QAction *play, QAction *stop, QAction *stop_after, QAction *next, QAction *mute, QAction *love, QAction *quit) = 0;
virtual bool IsVisible() const { return true; }
virtual void SetVisible(bool visible) { Q_UNUSED(visible); }
// Called by the OSD
virtual void ShowPopup(const QString &summary, const QString &message, int timeout) { Q_UNUSED(summary); Q_UNUSED(message); Q_UNUSED(timeout); }
// If this gets invoked with image_path equal to nullptr, the tooltip should still be shown - just without the cover art.
virtual void SetNowPlaying(const Song &song, const QUrl &cover_url) { Q_UNUSED(song); Q_UNUSED(cover_url); }
virtual void ClearNowPlaying() {}
virtual bool MuteEnabled() const { return false; }
virtual void SetMuteEnabled(bool enabled) { Q_UNUSED(enabled); }
static SystemTrayIcon *CreateSystemTrayIcon(QObject *parent = nullptr);
public slots:
void SetProgress(int percentage);
void SetTrayiconProgress(bool enabled) { trayicon_progress_ = enabled; }
virtual void SetPaused();
virtual void SetPlaying(bool enable_play_pause = false);
virtual void SetStopped();
virtual void LoveVisibilityChanged(bool value) { Q_UNUSED(value); }
virtual void LoveStateChanged(bool value) { Q_UNUSED(value); }
virtual void MuteButtonStateChanged(bool value) { Q_UNUSED(value); }
signals:
void ChangeVolume(int delta);
void SeekForward();
void SeekBackward();
void NextTrack();
void PreviousTrack();
void ShowHide();
void PlayPause();
protected:
virtual void UpdateIcon() = 0;
QPixmap CreateIcon(const QPixmap &icon, const QPixmap &grey_icon);
int song_progress() const { return percentage_; }
QPixmap current_state_icon() const { return current_state_icon_; }
private:
int percentage_;
QPixmap playing_icon_;
QPixmap paused_icon_;
QPixmap current_state_icon_;
bool trayicon_progress_;
};
#endif // SYSTEMTRAYICON_H

View File

@@ -90,9 +90,13 @@
#include "core/iconloader.h"
#include "core/mainwindow.h"
#include "core/commandlineoptions.h"
#include "core/systemtrayicon.h"
#include "core/application.h"
#include "core/networkproxyfactory.h"
#ifdef Q_OS_MACOS
# include "core/macsystemtrayicon.h"
#else
# include "core/qtsystemtrayicon.h"
#endif
#ifdef HAVE_TRANSLATIONS
# include "core/translations.h"
#endif
@@ -278,13 +282,18 @@ int main(int argc, char* argv[]) {
QNetworkProxyFactory::setApplicationProxyFactory(NetworkProxyFactory::Instance());
// Create the tray icon and OSD
std::unique_ptr<SystemTrayIcon> tray_icon(SystemTrayIcon::CreateSystemTrayIcon());
#if defined(Q_OS_MACOS)
OSDMac osd(tray_icon.get(), &app);
#elif defined(HAVE_DBUS)
OSDDBus osd(tray_icon.get(), &app);
#ifdef Q_OS_MACOS
std::shared_ptr<SystemTrayIcon> tray_icon(new SystemTrayIcon);
#else
OSDBase osd(tray_icon.get(), &app);
std::shared_ptr<SystemTrayIcon> tray_icon(new SystemTrayIcon);
#endif
#if defined(Q_OS_MACOS)
OSDMac osd(tray_icon, &app);
#elif defined(HAVE_DBUS)
OSDDBus osd(tray_icon, &app);
#else
OSDBase osd(tray_icon, &app);
#endif
#ifdef HAVE_DBUS
@@ -292,7 +301,8 @@ int main(int argc, char* argv[]) {
#endif
// Window
MainWindow w(&app, tray_icon.get(), &osd, options);
MainWindow w(&app, tray_icon, &osd, options);
#ifdef Q_OS_MACOS
mac::EnableFullScreen(w);
#endif // Q_OS_MACOS

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;

View File

@@ -42,7 +42,6 @@
#include "core/iconloader.h"
#include "core/mainwindow.h"
#include "core/utilities.h"
#include "settings/settingspage.h"
#include "behavioursettingspage.h"
#include "ui_behavioursettingspage.h"
@@ -68,8 +67,6 @@ BehaviourSettingsPage::BehaviourSettingsPage(SettingsDialog *dialog) : SettingsP
#ifdef Q_OS_MACOS
ui_->checkbox_showtrayicon->hide();
ui_->checkbox_trayicon_progress->hide();
ui_->checkbox_scrolltrayicon->hide();
ui_->groupbox_startup->hide();
#endif
@@ -135,12 +132,6 @@ BehaviourSettingsPage::BehaviourSettingsPage(SettingsDialog *dialog) : SettingsP
ui_->combobox_doubleclickplaylistaddmode->setItemData(0, PlaylistAddBehaviour_Play);
ui_->combobox_doubleclickplaylistaddmode->setItemData(1, PlaylistAddBehaviour_Enqueue);
#ifdef HAVE_X11
QString de = Utilities::DesktopEnvironment();
if (de.toLower() == "kde")
#endif
ui_->checkbox_scrolltrayicon->hide();
}
BehaviourSettingsPage::~BehaviourSettingsPage() {
@@ -155,21 +146,13 @@ void BehaviourSettingsPage::Load() {
#ifndef Q_OS_MACOS
if (QSystemTrayIcon::isSystemTrayAvailable()) {
ui_->checkbox_showtrayicon->setEnabled(true);
ui_->checkbox_trayicon_progress->setEnabled(true);
ui_->checkbox_scrolltrayicon->setEnabled(true);
ui_->radiobutton_hide->setEnabled(true);
ui_->checkbox_showtrayicon->setChecked(s.value("showtrayicon", true).toBool());
ui_->checkbox_trayicon_progress->setChecked(s.value("trayicon_progress", false).toBool());
ui_->checkbox_scrolltrayicon->setChecked(s.value("scrolltrayicon", ui_->checkbox_showtrayicon->isChecked()).toBool());
ui_->radiobutton_hide->setEnabled(true);
}
else {
ui_->checkbox_showtrayicon->setEnabled(false);
ui_->checkbox_trayicon_progress->setEnabled(false);
ui_->checkbox_scrolltrayicon->setEnabled(false);
ui_->radiobutton_hide->setEnabled(false);
ui_->checkbox_showtrayicon->setChecked(false);
ui_->checkbox_trayicon_progress->setChecked(false);
ui_->checkbox_scrolltrayicon->setChecked(false);
ui_->radiobutton_hide->setEnabled(false);
ui_->radiobutton_hide->setChecked(false);
}
#endif
@@ -177,10 +160,14 @@ void BehaviourSettingsPage::Load() {
if (QSystemTrayIcon::isSystemTrayAvailable()) {
ui_->checkbox_keeprunning->setEnabled(true);
ui_->checkbox_keeprunning->setChecked(s.value("keeprunning", false).toBool());
ui_->checkbox_trayicon_progress->setEnabled(true);
ui_->checkbox_trayicon_progress->setChecked(s.value("trayicon_progress", false).toBool());
}
else {
ui_->checkbox_keeprunning->setEnabled(false);
ui_->checkbox_keeprunning->setChecked(false);
ui_->checkbox_trayicon_progress->setEnabled(false);
ui_->checkbox_trayicon_progress->setChecked(false);
}
ui_->checkbox_resumeplayback->setChecked(s.value("resumeplayback", false).toBool());
@@ -248,7 +235,6 @@ void BehaviourSettingsPage::Save() {
s.setValue("trayicon_progress", ui_->checkbox_trayicon_progress->isChecked());
s.setValue("resumeplayback", ui_->checkbox_resumeplayback->isChecked());
s.setValue("playing_widget", ui_->checkbox_playingwidget->isChecked());
s.setValue("scrolltrayicon", ui_->checkbox_scrolltrayicon->isChecked());
StartupBehaviour behaviour = Startup_Remember;
if (ui_->radiobutton_remember->isChecked()) behaviour = Startup_Remember;
@@ -287,6 +273,5 @@ void BehaviourSettingsPage::ShowTrayIconToggled(bool on) {
if (!on && ui_->radiobutton_hide->isChecked()) ui_->radiobutton_remember->setChecked(true);
ui_->checkbox_keeprunning->setEnabled(on);
ui_->checkbox_trayicon_progress->setEnabled(on);
ui_->checkbox_scrolltrayicon->setEnabled(on);
}

View File

@@ -58,16 +58,6 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkbox_scrolltrayicon">
<property name="text">
<string>Scroll over icon to change track</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupbox_startup">
<property name="title">
@@ -350,7 +340,6 @@
<tabstop>checkbox_trayicon_progress</tabstop>
<tabstop>checkbox_resumeplayback</tabstop>
<tabstop>checkbox_playingwidget</tabstop>
<tabstop>checkbox_scrolltrayicon</tabstop>
<tabstop>radiobutton_remember</tabstop>
<tabstop>radiobutton_show</tabstop>
<tabstop>radiobutton_hide</tabstop>