55
56
gboolean keyboard_activated; /* TRUE if the current button was activated with a key */
57
58
GActionGroup *action_group;
59
gchar *button_actions[N_BUTTONS];
63
62
G_DEFINE_TYPE (IdoPlaybackMenuItem, ido_playback_menu_item, GTK_TYPE_MENU_ITEM);
82
81
ido_playback_menu_item_finalize (GObject *object)
84
83
IdoPlaybackMenuItem *item = IDO_PLAYBACK_MENU_ITEM (object);
86
g_free (item->play_action);
87
g_free (item->next_action);
88
g_free (item->prev_action);
86
for (i = 0; i < N_BUTTONS; i++)
87
g_free (item->button_actions[i]);
90
89
G_OBJECT_CLASS (ido_playback_menu_item_parent_class)->finalize (object);
130
129
case GDK_KEY_Left:
131
130
self->cur_pushed_button = BUTTON_PREVIOUS;
132
if (self->action_group && self->prev_action)
133
g_action_group_activate_action (self->action_group, self->prev_action, NULL);
136
133
case GDK_KEY_Right:
137
134
self->cur_pushed_button = BUTTON_NEXT;
138
if (self->action_group && self->next_action)
139
g_action_group_activate_action (self->action_group, self->next_action, NULL);
142
137
case GDK_KEY_space:
143
self->cur_pushed_button = BUTTON_PLAYPAUSE;
144
if (self->action_group && self->play_action)
145
g_action_group_activate_action (self->action_group, self->play_action, NULL);
138
if (self->cur_hover_button != BUTTON_NONE)
139
self->cur_pushed_button = self->cur_hover_button;
141
self->cur_pushed_button = BUTTON_PLAYPAUSE;
152
148
if (self->cur_pushed_button != BUTTON_NONE)
150
const gchar *action = self->button_actions[self->cur_pushed_button];
152
if (self->action_group && action)
153
g_action_group_activate_action (self->action_group, action, NULL);
154
155
self->keyboard_activated = TRUE;
155
156
gtk_widget_queue_draw (widget);
244
245
IdoPlaybackMenuItem *item = IDO_PLAYBACK_MENU_ITEM (menuitem);
247
const gchar *action = action;
247
249
button = ido_playback_menu_item_get_button_at_pos (event->x, event->y);
248
250
if (button != item->cur_pushed_button)
249
251
button = BUTTON_NONE;
256
case BUTTON_PREVIOUS:
257
if (item->action_group && item->prev_action)
258
g_action_group_activate_action (item->action_group, item->prev_action, NULL);
262
if (item->action_group && item->next_action)
263
g_action_group_activate_action (item->action_group, item->next_action, NULL);
266
case BUTTON_PLAYPAUSE:
267
if (item->action_group && item->play_action)
268
g_action_group_activate_action (item->action_group, item->play_action, NULL);
253
action = item->button_actions[item->cur_pushed_button];
254
if (item->action_group && action)
255
g_action_group_activate_action (item->action_group, action, NULL);
272
257
item->cur_pushed_button = BUTTON_NONE;
273
258
gtk_widget_queue_draw (menuitem);
363
348
gpointer user_data)
365
350
IdoPlaybackMenuItem *self = user_data;
367
if (self->play_action && g_str_equal (action_name, self->play_action))
353
action = self->button_actions[BUTTON_PLAYPAUSE];
354
if (action && g_str_equal (action_name, action))
371
state = g_action_group_get_action_state (action_group, self->play_action);
358
state = g_action_group_get_action_state (action_group, action);
372
359
if (g_variant_is_of_type (state, G_VARIANT_TYPE_STRING))
373
360
ido_playback_menu_item_set_state_from_string (self, g_variant_get_string (state, NULL));
382
369
gpointer user_data)
384
371
IdoPlaybackMenuItem *self = user_data;
386
if (self->play_action && g_str_equal (action_name, self->play_action))
374
action = self->button_actions[BUTTON_PLAYPAUSE];
375
if (action && g_str_equal (action_name, action))
387
376
ido_playback_menu_item_set_state (self, STATE_PAUSED);
394
383
gpointer user_data)
396
385
IdoPlaybackMenuItem *self = user_data;
398
388
g_return_if_fail (action_name != NULL);
400
if (self->play_action && g_str_equal (action_name, self->play_action))
390
action = self->button_actions[BUTTON_PLAYPAUSE];
392
if (action && g_str_equal (action_name, action))
402
394
if (g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
403
395
ido_playback_menu_item_set_state_from_string (self, g_variant_get_string (value, NULL));
417
410
g_signal_connect (actions, "action-added", G_CALLBACK (ido_playback_menu_item_action_added), widget);
418
411
g_signal_connect (actions, "action-removed", G_CALLBACK (ido_playback_menu_item_action_removed), widget);
420
g_menu_item_get_attribute (item, "x-canonical-play-action", "s", &widget->play_action);
421
g_menu_item_get_attribute (item, "x-canonical-next-action", "s", &widget->next_action);
422
g_menu_item_get_attribute (item, "x-canonical-previous-action", "s", &widget->prev_action);
413
g_menu_item_get_attribute (item, "x-canonical-play-action", "s", &widget->button_actions[BUTTON_PLAYPAUSE]);
414
g_menu_item_get_attribute (item, "x-canonical-next-action", "s", &widget->button_actions[BUTTON_NEXT]);
415
g_menu_item_get_attribute (item, "x-canonical-previous-action", "s", &widget->button_actions[BUTTON_PREVIOUS]);
424
if (widget->play_action && g_action_group_has_action (actions, widget->play_action))
425
ido_playback_menu_item_action_added (actions, widget->play_action, widget);
417
play_action = widget->button_actions[BUTTON_PLAYPAUSE];
418
if (play_action && g_action_group_has_action (actions, play_action))
419
ido_playback_menu_item_action_added (actions, play_action, widget);
427
421
return GTK_MENU_ITEM (widget);
1436
1430
// draw previous-button drop-shadow
1437
if (item->cur_pushed_button == BUTTON_PREVIOUS && item->keyboard_activated )
1431
if ((item->cur_pushed_button == BUTTON_PREVIOUS && item->keyboard_activated) ||
1432
item->cur_hover_button == BUTTON_PREVIOUS)
1439
1434
_setup (&cr_surf, &surf, PREV_WIDTH+6, PREV_HEIGHT+6);
1440
1435
_mask_prev (cr_surf,
1494
1489
_finalize (cr, &cr_surf, &surf, PREV_X, PREV_Y);
1496
1491
// draw next-button drop-shadow
1497
if (item->cur_pushed_button == BUTTON_NEXT && item->keyboard_activated)
1492
if ((item->cur_pushed_button == BUTTON_NEXT && item->keyboard_activated) ||
1493
item->cur_hover_button == BUTTON_NEXT)
1499
1495
_setup (&cr_surf, &surf, NEXT_WIDTH+6, NEXT_HEIGHT+6);
1500
1496
_mask_next (cr_surf,
1557
1553
if (item->current_state == STATE_PLAYING)
1559
1555
if (item->has_focus &&
1556
(item->cur_hover_button == BUTTON_NONE || item->cur_hover_button == BUTTON_PLAYPAUSE) &&
1560
1557
(item->cur_pushed_button == BUTTON_NONE || item->cur_pushed_button == BUTTON_PLAYPAUSE))
1562
1559
_setup (&cr_surf, &surf, PAUSE_WIDTH+6, PAUSE_HEIGHT+6);
1619
1616
else if (item->current_state == STATE_PAUSED)
1621
1618
if (item->has_focus &&
1619
(item->cur_hover_button == BUTTON_NONE || item->cur_hover_button == BUTTON_PLAYPAUSE) &&
1622
1620
(item->cur_pushed_button == BUTTON_NONE || item->cur_pushed_button == BUTTON_PLAYPAUSE))
1624
1622
_setup (&cr_surf, &surf, PLAY_WIDTH+6, PLAY_HEIGHT+6);