Skip to content

Commit efcf359

Browse files
[qt]hotkey: Add options for previous/next album. Closes: #1737
1 parent c0e4d83 commit efcf359

File tree

6 files changed

+51
-5
lines changed

6 files changed

+51
-5
lines changed

src/hotkey/gui.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ static const char * event_desc[] = {N_("Previous track"),
8484
N_("Toggle repeat"),
8585
N_("Toggle shuffle"),
8686
N_("Toggle stop after current"),
87-
N_("Raise player window(s)")};
87+
N_("Raise player window(s)"),
88+
N_("Previous album"),
89+
N_("Next album")};
8890

8991
static_assert(aud::n_elems(event_desc) == EVENT_MAX,
9092
"event_desc table is not up to date");
@@ -141,8 +143,7 @@ static void set_keytext(GtkWidget * entry, int key, int mask, int type)
141143

142144
gtk_entry_set_text(GTK_ENTRY(entry), text);
143145
gtk_editable_set_position(GTK_EDITABLE(entry), -1);
144-
if (text)
145-
g_free(text);
146+
g_free(text);
146147
}
147148

148149
static gboolean on_entry_key_press_event(GtkWidget * widget,

src/hotkey/plugin.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,27 @@ bool handle_keyevent(EVENT event)
195195
return true;
196196
}
197197

198+
/* prev album */
199+
if (event == EVENT_PREV_ALBUM)
200+
{
201+
aud_drct_pl_prev_album();
202+
return true;
203+
}
204+
198205
/* next track */
199206
if (event == EVENT_NEXT_TRACK)
200207
{
201208
aud_drct_pl_next();
202209
return true;
203210
}
204211

212+
/* next album */
213+
if (event == EVENT_NEXT_ALBUM)
214+
{
215+
aud_drct_pl_next_album();
216+
return true;
217+
}
218+
205219
/* forward */
206220
if (event == EVENT_FORWARD)
207221
{
@@ -334,6 +348,7 @@ void load_config()
334348
if (max == 0)
335349
load_defaults();
336350
else
351+
{
337352
for (i = 0; i < max; i++)
338353
{
339354
char * text = nullptr;
@@ -364,6 +379,7 @@ void load_config()
364379
hotkey->event = (EVENT)aud_get_int("globalHotkey", text);
365380
g_free(text);
366381
}
382+
}
367383
}
368384

369385
/* save plugin configuration */

src/hotkey/plugin.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#define TYPE_KEY 0
55
#define TYPE_MOUSE 1
66

7+
/*
8+
* Add new events always at the end of the enum (but before EVENT_MAX).
9+
* The int values are used in the configuration and hence should not change.
10+
*/
711
typedef enum
812
{
913
EVENT_PREV_TRACK = 0,
@@ -27,6 +31,9 @@ typedef enum
2731

2832
EVENT_RAISE,
2933

34+
EVENT_PREV_ALBUM,
35+
EVENT_NEXT_ALBUM,
36+
3037
EVENT_MAX
3138
} EVENT;
3239

src/qthotkey/gui.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ static const QMap<Event, const char *> event_desc = {
8080
{Event::ToggleShuffle, N_("Toggle shuffle")},
8181
{Event::ToggleStop, N_("Toggle stop after current")},
8282
{Event::Raise, N_("Raise player window(s)")},
83+
{Event::PrevAlbum, N_("Previous album")},
84+
{Event::NextAlbum, N_("Next album")},
8385
};
8486

8587
class LineKeyEdit : public QLineEdit

src/qthotkey/plugin.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ bool handle_keyevent(Event event)
211211
}
212212
break;
213213

214+
/* prev album */
215+
case Event::PrevAlbum:
216+
{
217+
aud_drct_pl_prev_album();
218+
return true;
219+
}
220+
break;
221+
214222
/* next track */
215223
case Event::NextTrack:
216224
{
@@ -219,6 +227,14 @@ bool handle_keyevent(Event event)
219227
}
220228
break;
221229

230+
/* next album */
231+
case Event::NextAlbum:
232+
{
233+
aud_drct_pl_next_album();
234+
return true;
235+
}
236+
break;
237+
222238
/* forward */
223239
case Event::Forward:
224240
{

src/qthotkey/plugin.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ namespace GlobalHotkeys
77
{
88

99
/*
10-
* Values in this enum must not be skipped and must start with 0,
11-
* otherwise event_desc in gui.cc and it's use must be updated.
10+
* Values in this enum must not be changed and must start with 0.
11+
* New events must always be added at the end (but before Event::Max).
12+
* The int values are used in the configuration and shared with the GTK plugin.
1213
* All values except for Event::Max must be present in event_desc map.
1314
*/
1415
enum class Event
@@ -34,6 +35,9 @@ enum class Event
3435

3536
Raise,
3637

38+
PrevAlbum,
39+
NextAlbum,
40+
3741
Max
3842
};
3943

0 commit comments

Comments
 (0)