Skip to content

Commit

Permalink
statusicon-qt: Implement remaining features. Closes: #803.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlindgren90 committed Jun 30, 2018
1 parent b5bc905 commit b461d8e
Showing 1 changed file with 66 additions and 7 deletions.
73 changes: 66 additions & 7 deletions src/statusicon-qt/statusicon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QApplication>
#include <QMenu>
#include <QSystemTrayIcon>
#include <QWheelEvent>

class StatusIcon : public GeneralPlugin {
public:
Expand Down Expand Up @@ -69,13 +70,35 @@ const char StatusIcon::about[] =
"This plugin provides a status icon, placed in\n"
"the system tray area of the window manager.");

enum {
SI_CFG_SCROLL_ACTION_VOLUME,
SI_CFG_SCROLL_ACTION_SKIP
};

const char * const StatusIcon::defaults[] = {
"scroll_action", aud::numeric_string<SI_CFG_SCROLL_ACTION_VOLUME>::str,
"volume_delta", "5",
"disable_popup", "FALSE",
"close_to_tray", "FALSE",
"reverse_scroll", "FALSE",
nullptr
};

const PreferencesWidget StatusIcon::widgets[] = {
WidgetCheck (N_("Close to the system tray"), WidgetBool ("statusicon-qt", "close_to_tray"))
WidgetLabel (N_("<b>Mouse Scroll Action</b>")),
WidgetRadio (N_("Change volume"),
WidgetInt ("statusicon", "scroll_action"),
{SI_CFG_SCROLL_ACTION_VOLUME}),
WidgetRadio (N_("Change playing song"),
WidgetInt ("statusicon", "scroll_action"),
{SI_CFG_SCROLL_ACTION_SKIP}),
WidgetLabel (N_("<b>Other Settings</b>")),
WidgetCheck (N_("Disable the popup window"),
WidgetBool ("statusicon", "disable_popup")),
WidgetCheck (N_("Close to the system tray"),
WidgetBool ("statusicon", "close_to_tray")),
WidgetCheck (N_("Advance in playlist when scrolling upward"),
WidgetBool ("statusicon", "reverse_scroll"))
};

const PluginPreferences StatusIcon::prefs = {{widgets}};
Expand Down Expand Up @@ -105,22 +128,58 @@ class SystemTrayIcon : public QSystemTrayIcon
void hide_popup ();

protected:
void scroll (int steps);
bool event (QEvent * e) override;

private:
int scroll_delta = 0;
bool popup_shown = false;
QueuedFunc popup_timer;
};

void SystemTrayIcon::scroll (int delta)
{
scroll_delta += delta;

/* we want discrete steps here */
int steps = scroll_delta / 120;
if (steps == 0)
return;

scroll_delta -= 120 * steps;

switch (aud_get_int ("statusicon", "scroll_action"))
{
case SI_CFG_SCROLL_ACTION_VOLUME:
aud_drct_set_volume_main (aud_drct_get_volume_main () +
aud_get_int ("statusicon", "volume_delta") * steps);
break;

case SI_CFG_SCROLL_ACTION_SKIP:
if ((steps > 0) ^ aud_get_bool ("statusicon", "reverse_scroll"))
aud_drct_pl_prev ();
else
aud_drct_pl_next ();
break;
}
}

bool SystemTrayIcon::event (QEvent * e)
{
if (e->type () == QEvent::ToolTip)
switch (e->type ())
{
show_popup ();
case QEvent::ToolTip:
if (! aud_get_bool ("statusicon", "disable_popup"))
show_popup ();
return true;
}

return QSystemTrayIcon::event (e);
case QEvent::Wheel:
scroll (((QWheelEvent *) e)->angleDelta ().y ());
return true;

default:
return QSystemTrayIcon::event (e);
}
}

void SystemTrayIcon::show_popup ()
Expand All @@ -144,7 +203,7 @@ static QMenu * menu = nullptr;

bool StatusIcon::init ()
{
aud_config_set_defaults ("statusicon-qt", defaults);
aud_config_set_defaults ("statusicon", defaults);

audqt::init ();

Expand Down Expand Up @@ -182,7 +241,7 @@ void StatusIcon::window_closed (void * data, void * user_data)
{
bool * handled = (bool *) data;

if (aud_get_bool ("statusicon-qt", "close_to_tray") && tray->isVisible ())
if (aud_get_bool ("statusicon", "close_to_tray") && tray->isVisible ())
{
* handled = true;
aud_ui_show (false);
Expand Down

0 comments on commit b461d8e

Please sign in to comment.