Using new actions (that doesn't display unusuable shorcuts) for the tray icon menu. Fixes issue 679
This commit is contained in:
parent
7a60b52704
commit
7fbd09954b
@ -810,25 +810,28 @@ void MainWindow::MediaPlaying() {
|
||||
ui_->action_play_pause->setIcon(IconLoader::Load("media-playback-pause"));
|
||||
ui_->action_play_pause->setText(tr("Pause"));
|
||||
|
||||
ui_->action_play_pause->setEnabled(
|
||||
! (player_->GetCurrentItem()->options() & PlaylistItem::PauseDisabled));
|
||||
bool enable_play_pause = !(player_->GetCurrentItem()->options() & PlaylistItem::PauseDisabled);
|
||||
ui_->action_play_pause->setEnabled(enable_play_pause);
|
||||
|
||||
#ifdef HAVE_LIBLASTFM
|
||||
bool is_lastfm = (player_->GetCurrentItem()->options() & PlaylistItem::LastFMControls);
|
||||
LastFMService* lastfm = RadioModel::Service<LastFMService>();
|
||||
bool enable_ban = lastfm->IsScrobblingEnabled() && is_lastfm;
|
||||
bool enable_love = lastfm->IsScrobblingEnabled();
|
||||
|
||||
ui_->action_ban->setEnabled(lastfm->IsScrobblingEnabled() && is_lastfm);
|
||||
ui_->action_love->setEnabled(lastfm->IsScrobblingEnabled());
|
||||
ui_->action_ban->setEnabled(enable_ban);
|
||||
ui_->action_love->setEnabled(enable_love);
|
||||
|
||||
tray_icon_->SetPlaying(enable_play_pause, enable_ban, enable_love);
|
||||
|
||||
ui_->track_slider->SetCanSeek(!is_lastfm);
|
||||
#else
|
||||
ui_->track_slider->SetCanSeek(true);
|
||||
tray_icon_->SetPlaying(enable_play_pause);
|
||||
#endif
|
||||
|
||||
track_position_timer_->start();
|
||||
UpdateTrackPosition();
|
||||
|
||||
tray_icon_->SetPlaying();
|
||||
}
|
||||
|
||||
void MainWindow::VolumeChanged(int volume) {
|
||||
|
@ -31,7 +31,12 @@
|
||||
QtSystemTrayIcon::QtSystemTrayIcon(QObject* parent)
|
||||
: SystemTrayIcon(parent),
|
||||
tray_(new QSystemTrayIcon(this)),
|
||||
menu_(new QMenu)
|
||||
menu_(new QMenu),
|
||||
action_play_pause_(NULL),
|
||||
action_stop_(NULL),
|
||||
action_stop_after_this_track_(NULL),
|
||||
action_love_(NULL),
|
||||
action_ban_(NULL)
|
||||
{
|
||||
QIcon theme_icon = IconLoader::Load("clementine-panel");
|
||||
QIcon theme_icon_grey = IconLoader::Load("clementine-panel-grey");
|
||||
@ -82,18 +87,28 @@ bool QtSystemTrayIcon::eventFilter(QObject* object, QEvent* event) {
|
||||
void QtSystemTrayIcon::SetupMenu(
|
||||
QAction* previous, QAction* play, QAction* stop, QAction* stop_after,
|
||||
QAction* next, QAction* mute, QAction* love, QAction* ban, QAction* quit) {
|
||||
menu_->addAction(previous);
|
||||
menu_->addAction(play);
|
||||
menu_->addAction(stop);
|
||||
menu_->addAction(stop_after);
|
||||
menu_->addAction(next);
|
||||
// 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
|
||||
// Clementine's window is hidden
|
||||
menu_->addAction(previous->icon(), previous->text(), previous, SLOT(trigger()));
|
||||
action_play_pause_ = menu_->addAction(play->icon(), play->text(), play, SLOT(trigger()));
|
||||
action_stop_ = menu_->addAction(stop->icon(), stop->text(), stop, SLOT(trigger()));
|
||||
action_stop_after_this_track_ = menu_->addAction(stop_after->icon(), stop_after->text(), stop_after, SLOT(trigger()));
|
||||
menu_->addAction(next->icon(), next->text(), next, SLOT(trigger()));
|
||||
|
||||
menu_->addSeparator();
|
||||
menu_->addAction(mute);
|
||||
menu_->addAction(mute->icon(), mute->text(), mute, SLOT(trigger()));
|
||||
|
||||
menu_->addSeparator();
|
||||
menu_->addAction(love);
|
||||
menu_->addAction(ban);
|
||||
#ifdef HAVE_LIBLASTFM
|
||||
action_love_ = menu_->addAction(love->icon(), love->text(), love, SLOT(trigger()));
|
||||
action_love_->setVisible(love->isVisible());
|
||||
action_ban_ = menu_->addAction(ban->icon(), ban->text(), ban, SLOT(trigger()));
|
||||
action_ban_->setVisible(ban->isVisible());
|
||||
#endif
|
||||
|
||||
menu_->addSeparator();
|
||||
menu_->addAction(quit);
|
||||
menu_->addAction(quit->icon(), quit->text(), quit, SLOT(trigger()));
|
||||
|
||||
tray_->setContextMenu(menu_);
|
||||
}
|
||||
@ -123,6 +138,48 @@ void QtSystemTrayIcon::UpdateIcon() {
|
||||
tray_->setIcon(CreateIcon(orange_icon_, grey_icon_));
|
||||
}
|
||||
|
||||
void QtSystemTrayIcon::SetPaused() {
|
||||
SystemTrayIcon::SetPaused();
|
||||
|
||||
action_stop_->setEnabled(true);
|
||||
action_stop_after_this_track_->setEnabled(true);
|
||||
action_play_pause_->setIcon(IconLoader::Load("media-playback-start"));
|
||||
action_play_pause_->setText(tr("Play"));
|
||||
|
||||
action_play_pause_->setEnabled(true);
|
||||
}
|
||||
|
||||
void QtSystemTrayIcon::SetPlaying(bool enable_play_pause, bool enable_ban,
|
||||
bool enable_love) {
|
||||
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);
|
||||
#ifdef HAVE_LIBLASTFM
|
||||
action_ban_->setEnabled(enable_ban);
|
||||
action_love_->setEnabled(enable_love);
|
||||
#endif
|
||||
}
|
||||
|
||||
void QtSystemTrayIcon::SetStopped() {
|
||||
SystemTrayIcon::SetStopped();
|
||||
|
||||
action_stop_->setEnabled(false);
|
||||
action_stop_after_this_track_->setEnabled(false);
|
||||
action_play_pause_->setIcon(IconLoader::Load("media-playback-start"));
|
||||
action_play_pause_->setText(tr("Play"));
|
||||
|
||||
action_play_pause_->setEnabled(true);
|
||||
|
||||
#ifdef HAVE_LIBLASTFM
|
||||
action_ban_->setEnabled(false);
|
||||
action_love_->setEnabled(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool QtSystemTrayIcon::IsVisible() const {
|
||||
return tray_->isVisible();
|
||||
}
|
||||
|
@ -43,6 +43,10 @@ public:
|
||||
protected:
|
||||
// SystemTrayIcon
|
||||
void UpdateIcon();
|
||||
void SetPaused();
|
||||
void SetPlaying(bool enable_play_pause = false, bool enable_ban = false,
|
||||
bool enable_love = false);
|
||||
void SetStopped();
|
||||
|
||||
// QObject
|
||||
bool eventFilter(QObject *, QEvent *);
|
||||
@ -53,6 +57,11 @@ private slots:
|
||||
private:
|
||||
QSystemTrayIcon* tray_;
|
||||
QMenu* menu_;
|
||||
QAction* action_play_pause_;
|
||||
QAction* action_stop_;
|
||||
QAction* action_stop_after_this_track_;
|
||||
QAction* action_love_;
|
||||
QAction* action_ban_;
|
||||
|
||||
QString pattern_;
|
||||
|
||||
|
@ -88,7 +88,8 @@ void SystemTrayIcon::SetPaused() {
|
||||
UpdateIcon();
|
||||
}
|
||||
|
||||
void SystemTrayIcon::SetPlaying() {
|
||||
void SystemTrayIcon::SetPlaying(bool enable_play_pause, bool enable_ban,
|
||||
bool enable_love) {
|
||||
current_state_icon_ = playing_icon_;
|
||||
UpdateIcon();
|
||||
}
|
||||
|
@ -52,9 +52,10 @@ class SystemTrayIcon : public QObject {
|
||||
|
||||
public slots:
|
||||
void SetProgress(int percentage);
|
||||
void SetPaused();
|
||||
void SetPlaying();
|
||||
void SetStopped();
|
||||
virtual void SetPaused();
|
||||
virtual void SetPlaying(bool enable_play_pause = false,
|
||||
bool enable_ban = false, bool enable_love = false);
|
||||
virtual void SetStopped();
|
||||
|
||||
signals:
|
||||
void ChangeVolume(int delta);
|
||||
|
Loading…
x
Reference in New Issue
Block a user