From 2fbd1c79ad1e88ca9fff15550a7808d6ac19d0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Wed, 2 Jan 2013 13:22:26 +0000 Subject: [PATCH] e/music-control: Add keybinds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by: José Roberto de Souza SVN revision: 81996 --- src/modules/music-control/e_mod_main.c | 62 ++++++++++++++++++++++++++ src/modules/music-control/private.h | 1 + 2 files changed, 63 insertions(+) diff --git a/src/modules/music-control/e_mod_main.c b/src/modules/music-control/e_mod_main.c index ab910311f..9f78628ed 100644 --- a/src/modules/music-control/e_mod_main.c +++ b/src/modules/music-control/e_mod_main.c @@ -36,6 +36,65 @@ music_control_edj_path_get(void) #undef TF } +static void +_music_control(E_Object *obj, const char *params) +{ + E_Music_Control_Module_Context *ctxt; + EINA_SAFETY_ON_NULL_RETURN(music_control_mod->data); + ctxt = music_control_mod->data; + if (!strcmp(params, "play")) + media_player2_player_pause_call(ctxt->mpris2_player); + else if (!strcmp(params, "next")) + media_player2_player_next_call(ctxt->mpris2_player); + else if (!strcmp(params, "previous")) + media_player2_player_previous_call(ctxt->mpris2_player); +} + +#define ACTION_NEXT "next_music" +#define ACTION_NEXT_NAME "Next Music" +#define ACTION_PLAY_PAUSE "playpause_music" +#define ACTION_PLAY_PAUSE_NAME "Play/Pause Music" +#define ACTION_PREVIOUS "previous_music" +#define ACTION_PREVIOUS_NAME "Previous Music" + +static void +_actions_register(E_Music_Control_Module_Context *ctxt) +{ + E_Action *action; + if (ctxt->actions_set) return; + + action = e_action_add(ACTION_NEXT); + action->func.go = _music_control; + e_action_predef_name_set(_e_music_control_Name, ACTION_NEXT_NAME, + ACTION_NEXT, "next", NULL, 0); + + action = e_action_add(ACTION_PLAY_PAUSE); + action->func.go = _music_control; + e_action_predef_name_set(_e_music_control_Name, ACTION_PLAY_PAUSE_NAME, + ACTION_PLAY_PAUSE, "play", NULL, 0); + + action = e_action_add(ACTION_PREVIOUS); + action->func.go = _music_control; + e_action_predef_name_set(_e_music_control_Name, ACTION_PREVIOUS_NAME, + ACTION_PREVIOUS, "previous", NULL, 0); + + ctxt->actions_set = EINA_TRUE; +} + +static void +_actions_unregister(E_Music_Control_Module_Context *ctxt) +{ + if (!ctxt->actions_set) return; + e_action_predef_name_del(ACTION_NEXT_NAME, ACTION_NEXT); + e_action_del(ACTION_NEXT); + e_action_predef_name_del(ACTION_PLAY_PAUSE_NAME, ACTION_PLAY_PAUSE); + e_action_del(ACTION_PLAY_PAUSE); + e_action_predef_name_del(ACTION_PREVIOUS_NAME, ACTION_PREVIOUS); + e_action_del(ACTION_PREVIOUS); + + ctxt->actions_set = EINA_FALSE; +} + /* Gadcon Api Functions */ static E_Gadcon_Client * _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style) @@ -61,6 +120,7 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style) evas_object_event_callback_add(inst->gadget, EVAS_CALLBACK_MOUSE_DOWN, music_control_mouse_down_cb, inst); ctxt->instances = eina_list_append(ctxt->instances, inst); + _actions_register(ctxt); return inst->gcc; } @@ -79,6 +139,8 @@ _gc_shutdown(E_Gadcon_Client *gcc) evas_object_del(inst->gadget); if (inst->popup) music_control_popup_del(inst); ctxt->instances = eina_list_remove(ctxt->instances, inst); + if (!ctxt->instances) + _actions_unregister(ctxt); free(inst); } diff --git a/src/modules/music-control/private.h b/src/modules/music-control/private.h index f36c37119..ec18bf460 100644 --- a/src/modules/music-control/private.h +++ b/src/modules/music-control/private.h @@ -19,6 +19,7 @@ typedef struct _E_Music_Control_Module_Context EDBus_Proxy *mpris2_player; E_Config_DD *conf_edd; Music_Control_Config *config; + Eina_Bool actions_set:1; } E_Music_Control_Module_Context; typedef struct _E_Music_Control_Instance