Skip to content

Commit

Permalink
statusicon-qt: Somewhat improved context menu.
Browse files Browse the repository at this point in the history
* Added an explicit action to show/hide main window (non-toggle).
* Kind of fixed the absence of the Quit action.
  • Loading branch information
Crazy-Hopper committed Aug 25, 2015
1 parent 790cc4f commit 61ed658
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/statusicon-qt/statusicon.cc
Expand Up @@ -55,6 +55,8 @@ class StatusIcon : public GeneralPlugin {
static void window_closed (void * data, void * user_data);
static void activate (QSystemTrayIcon::ActivationReason);
static void open_files ();
static void toggle_aud_ui ();
static void update_menu ();
};

EXPORT StatusIcon aud_plugin_instance;
Expand All @@ -80,15 +82,18 @@ const PluginPreferences StatusIcon::prefs = {{widgets}};

const audqt::MenuItem StatusIcon::items[] =
{
audqt::MenuCommand ({N_("_Hide"), "window-close"}, StatusIcon::toggle_aud_ui),
audqt::MenuCommand ({N_("_Restore"), "window-new"}, StatusIcon::toggle_aud_ui),
audqt::MenuSep (),
audqt::MenuCommand ({N_("_Open Files ..."), "document-open"}, StatusIcon::open_files),
audqt::MenuCommand ({N_("Pre_vious"), "media-skip-backward"}, aud_drct_pl_prev),
audqt::MenuCommand ({N_("_Play"), "media-playback-start"}, aud_drct_play),
audqt::MenuCommand ({N_("Paus_e"), "media-playback-pause"}, aud_drct_pause),
audqt::MenuCommand ({N_("_Stop"), "media-playback-stop"}, aud_drct_stop),
audqt::MenuCommand ({N_("_Next"), "media-skip-forward"}, aud_drct_pl_next),
audqt::MenuSep (),
audqt::MenuCommand ({N_("Se_ttings ..."), "preferences-system"}, audqt::prefswin_show)
// Quit command is added automatically
audqt::MenuCommand ({N_("Se_ttings ..."), "preferences-system"}, audqt::prefswin_show),
audqt::MenuCommand ({N_("_Quit"), "application-exit"}, aud_quit),
};

static QSystemTrayIcon * tray = nullptr;
Expand All @@ -103,7 +108,12 @@ bool StatusIcon::init ()
tray = new QSystemTrayIcon (qApp->windowIcon ());
QObject::connect (tray, & QSystemTrayIcon::activated, activate);
menu = audqt::menu_build (items);
// Very dirty hack to get along with KDE5 SNI implementation
// which adds Quit action without any permission.
// See below in activate().
menu->actions ().last ()->setVisible (false);
tray->setContextMenu (menu);
QObject::connect (menu, & QMenu::aboutToShow, update_menu);
tray->show ();

hook_associate ("window close", window_closed, nullptr);
Expand Down Expand Up @@ -145,7 +155,13 @@ void StatusIcon::activate(QSystemTrayIcon::ActivationReason reason)
switch (reason)
{
case QSystemTrayIcon::Trigger:
aud_ui_show (! aud_ui_is_shown ());
toggle_aud_ui ();
break;

case QSystemTrayIcon::Context:
// It is expected that only KDE5 SNI implementation blocks this activation signal.
// So getting it means we aren't in KDE and should show the Quit action.
menu->actions ().last ()->setVisible (true);

This comment has been minimized.

Copy link
@Crazy-Hopper

Crazy-Hopper Dec 25, 2016

Author Member

KDE5 became even nastier since this was written. Now "Quit" action isn't added by the SNI implementation but the signal is still blocked. This results in absence of "Quit" in context menu in current KDE5. The simplest way to go is to always add the "Quit" action and forget about older KDE5 which would show double "Quit" then. Is this the right way to go? Any other suggestions are very welcome.

This comment has been minimized.

Copy link
@jlindgren90

jlindgren90 Dec 25, 2016

Member

I'm fine with always adding the "quit" item.

break;

default:
Expand All @@ -157,3 +173,16 @@ void StatusIcon::open_files ()
{
audqt::fileopener_show (audqt::FileMode::Open);
}

void StatusIcon::toggle_aud_ui ()
{
aud_ui_show (! aud_ui_is_shown ());
}

void StatusIcon::update_menu ()
{
QList< QAction *> acts = menu->actions ();

acts.at (0)->setVisible (aud_ui_is_shown ());
acts.at (1)->setVisible (! aud_ui_is_shown ());
}

0 comments on commit 61ed658

Please sign in to comment.