enjoy: Move track list/player events to Ecore_Event.

This is to prepare to move MPRIS stuff to a plugin later.

SVN revision: 62876
This commit is contained in:
Leandro Pereira 2011-08-26 19:24:05 +00:00
parent 549e8f1cdb
commit 14a6b10ede
6 changed files with 145 additions and 39 deletions

View File

@ -85,6 +85,34 @@ enjoy_cache_dir_get(void)
return cache;
}
void
no_free()
{
}
int
enjoy_event_id_get(Event_ID event_id)
{
switch (event_id)
{
case ENJOY_EVENT_PLAYER_CAPS_CHANGE: return app.event_id.player.caps_change;
case ENJOY_EVENT_PLAYER_STATUS_CHANGE: return app.event_id.player.status_change;
case ENJOY_EVENT_PLAYER_TRACK_CHANGE: return app.event_id.player.track_change;
case ENJOY_EVENT_TRACKLIST_TRACKLIST_CHANGE: return app.event_id.tracklist.tracklist_change;
}
return -1;
}
static void
enjoy_event_id_init()
{
ecore_init();
app.event_id.player.caps_change = ecore_event_type_new();
app.event_id.player.status_change = ecore_event_type_new();
app.event_id.player.track_change = ecore_event_type_new();
app.event_id.tracklist.tracklist_change = ecore_event_type_new();
}
EAPI int
elm_main(int argc, char **argv)
{
@ -156,7 +184,8 @@ elm_main(int argc, char **argv)
fso_init();
fso_request_resource("CPU");
#endif
enjoy_event_id_init();
mpris_init();
cover_init();
elm_run();

View File

@ -12,6 +12,12 @@ typedef struct _MPRIS_Signal MPRIS_Signal;
#define PLAYER_NAME "/Player"
static void _mpris_signal_player_caps_change(int caps);
static void _mpris_signal_player_status_change(int playback, int shuffle, int repeat, int endless);
static void _mpris_signal_player_track_change(Song *song);
static void _mpris_signal_tracklist_tracklist_change(int size);
static void _mpris_signal_emit(const char *root, const char *signal_name, int arg_type, void *arg_value);
static void _mpris_signals_add(const char *root, const MPRIS_Signal *signals);
static void _mpris_methods_add(const char *root, const MPRIS_Method *methods);
static void _mpris_append_dict_entry(DBusMessageIter *dict_iter, const char *key,
@ -133,6 +139,39 @@ static const MPRIS_Method mpris_tracklist_methods[] = {
};
static Ecore_Event_Handler *_event_handler_caps_change,
*_event_handler_status_change,
*_event_handler_track_change,
*_event_handler_tracklist_change;
static Eina_Bool
_cb_player_caps_change(void *data __UNUSED__, int type __UNUSED__, void *event)
{
_mpris_signal_player_caps_change(*(int *)event);
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_cb_player_status_change(void *data __UNUSED__, int type __UNUSED__, void *event)
{
int *new_status = event;
_mpris_signal_player_status_change(new_status[0], new_status[1], new_status[2], new_status[3]);
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_cb_player_track_change(void *data __UNUSED__, int type __UNUSED__, void *event)
{
_mpris_signal_player_track_change((Song *)event);
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_cb_player_tracklist_change(void *data __UNUSED__, int type __UNUSED__, void *event)
{
_mpris_signal_tracklist_tracklist_change(*(int *)event);
return ECORE_CALLBACK_PASS_ON;
}
void
mpris_init(void)
@ -142,12 +181,20 @@ mpris_init(void)
conn = e_dbus_bus_get(DBUS_BUS_SESSION);
if (conn)
e_dbus_request_name(conn, APPLICATION_NAME, 0, _cb_dbus_request_name, NULL);
_event_handler_caps_change = ecore_event_handler_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_CAPS_CHANGE), _cb_player_caps_change, NULL);
_event_handler_status_change = ecore_event_handler_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_STATUS_CHANGE), _cb_player_status_change, NULL);
_event_handler_track_change = ecore_event_handler_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_TRACK_CHANGE), _cb_player_track_change, NULL);
_event_handler_tracklist_change = ecore_event_handler_add(enjoy_event_id_get(ENJOY_EVENT_TRACKLIST_TRACKLIST_CHANGE), _cb_player_tracklist_change, NULL);
}
void
mpris_shutdown(void)
{
if (!conn) return;
ecore_event_handler_del(_event_handler_caps_change);
ecore_event_handler_del(_event_handler_status_change);
ecore_event_handler_del(_event_handler_track_change);
ecore_event_handler_del(_event_handler_tracklist_change);
eina_hash_free(interface_list);
e_dbus_shutdown();
conn = NULL;
@ -323,7 +370,7 @@ _mpris_message_fill_song_metadata(DBusMessage *msg, Song *song)
}
void
mpris_signal_player_caps_change(int caps)
_mpris_signal_player_caps_change(int caps)
{
static int old_caps = 0;
if (caps != old_caps)
@ -333,8 +380,8 @@ mpris_signal_player_caps_change(int caps)
}
}
void
mpris_signal_player_status_change(int playback, int shuffle, int repeat, int endless)
static void
_mpris_signal_player_status_change(int playback, int shuffle, int repeat, int endless)
{
DBusMessage *sig;
DBusMessageIter iter, siter;
@ -360,8 +407,8 @@ mpris_signal_player_status_change(int playback, int shuffle, int repeat, int end
dbus_message_unref(sig);
}
void
mpris_signal_player_track_change(Song *song)
static void
_mpris_signal_player_track_change(Song *song)
{
static Song *old_song = NULL;
if (old_song != song)
@ -375,8 +422,8 @@ mpris_signal_player_track_change(Song *song)
}
}
void
mpris_signal_tracklist_tracklist_change(int size)
static void
_mpris_signal_tracklist_tracklist_change(int size)
{
_mpris_signal_emit(TRACKLIST_NAME, "TrackListChange", DBUS_TYPE_INT32, &size);
}

View File

@ -4,23 +4,7 @@
#include <E_DBus.h>
#include "private.h"
typedef enum {
CAN_GO_NEXT = 1 << 0,
CAN_GO_PREV = 1 << 1,
CAN_PAUSE = 1 << 2,
CAN_PLAY = 1 << 3,
CAN_SEEK = 1 << 4,
CAN_PROVIDE_METADATA = 1 << 5,
CAN_HAS_TRACKLIST = 1 << 6
} MPRIS_Capabilities;
void mpris_init(void);
void mpris_shutdown(void);
void mpris_signal_player_caps_change(int caps);
void mpris_signal_player_status_change(int playback, int shuffle, int repeat, int endless);
void mpris_signal_player_track_change(Song *song);
void mpris_signal_tracklist_tracklist_change(int size);
void mpris_signal_emit(const char *root, const char *signal_name, int arg_type, void *arg_value);
#endif /* ENJOY_MPRIS_H */

View File

@ -1,5 +1,4 @@
#include "private.h"
#include "mpris.h"
#include <ctype.h>
#include <stdlib.h>
@ -581,7 +580,7 @@ _song_item_selected(void *data, Evas_Object *list __UNUSED__, void *event_info)
static void
_page_songs_after_populate(Page *page)
{
mpris_signal_tracklist_tracklist_change(page->num_elements);
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_TRACKLIST_TRACKLIST_CHANGE), &page->num_elements, no_free, NULL);
}
static Evas_Object *
@ -745,7 +744,7 @@ page_songs_next_go(Evas_Object *obj)
page->selected = it;
elm_genlist_item_selected_set(it, EINA_TRUE);
elm_genlist_item_bring_in(it);
mpris_signal_player_track_change(song);
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_TRACK_CHANGE), song, no_free, NULL);
return song;
}
@ -842,7 +841,7 @@ page_songs_shuffle_prev_go(Evas_Object *obj)
page->selected = it;
elm_genlist_item_selected_set(it, EINA_TRUE);
elm_genlist_item_bring_in(it);
mpris_signal_player_track_change(song);
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_TRACK_CHANGE), song, no_free, NULL);
return song;
}
@ -870,7 +869,7 @@ page_songs_shuffle_next_go(Evas_Object *obj)
page->selected = it;
elm_genlist_item_selected_set(it, EINA_TRUE);
elm_genlist_item_bring_in(it);
mpris_signal_player_track_change(song);
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_TRACK_CHANGE), song, no_free, NULL);
return song;
}
@ -897,7 +896,7 @@ page_songs_prev_go(Evas_Object *obj)
page->selected = it;
elm_genlist_item_selected_set(it, EINA_TRUE);
elm_genlist_item_bring_in(it);
mpris_signal_player_track_change(song);
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_TRACK_CHANGE), song, no_free, NULL);
return song;
}

View File

@ -35,12 +35,39 @@ extern int _log_domain;
#define MSG_LOOP 5
#define MSG_SHUFFLE 6
typedef enum {
ENJOY_EVENT_PLAYER_CAPS_CHANGE,
ENJOY_EVENT_PLAYER_STATUS_CHANGE,
ENJOY_EVENT_PLAYER_TRACK_CHANGE,
ENJOY_EVENT_TRACKLIST_TRACKLIST_CHANGE
} Event_ID;
typedef enum {
CAN_GO_NEXT = 1 << 0,
CAN_GO_PREV = 1 << 1,
CAN_PAUSE = 1 << 2,
CAN_PLAY = 1 << 3,
CAN_SEEK = 1 << 4,
CAN_PROVIDE_METADATA = 1 << 5,
CAN_HAS_TRACKLIST = 1 << 6
} Capabilities;
struct _App
{
Eina_List *add_dirs;
Eina_List *del_dirs;
char configdir[PATH_MAX];
Evas_Object *win;
struct {
struct {
int caps_change;
int status_change;
int track_change;
} player;
struct {
int tracklist_change;
} tracklist;
} event_id;
};
@ -69,6 +96,10 @@ void enjoy_repeat_set(Eina_Bool repeat);
void enjoy_status_get(int *playback, int *shuffle, int *repeat, int *endless);
void enjoy_volume_set(int32_t volume);
int enjoy_event_id_get(Event_ID eid);
void no_free();
Libmgr *libmgr_new(const char *dbpath);
Eina_Bool libmgr_scanpath_add(Libmgr *mgr, const char *path);
Eina_Bool libmgr_scan_start(Libmgr *mgr, void (*func_end)(void *, Eina_Bool), void *data);

View File

@ -1,5 +1,4 @@
#include "private.h"
#include "mpris.h"
#include <Emotion.h>
typedef struct Win
@ -142,7 +141,9 @@ _win_toolbar_eval(Win *w)
elm_toolbar_item_disabled_set(w->action.nowplaying, EINA_TRUE);
}
mpris_signal_player_caps_change(enjoy_caps_get());
int *caps = malloc(sizeof(*caps));
*caps = enjoy_caps_get();
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_CAPS_CHANGE), caps, NULL, NULL);
}
static void
@ -150,8 +151,15 @@ _win_play_pause_toggle(Win *w)
{
int playback, shuffle, repeat, endless;
enjoy_status_get(&playback, &shuffle, &repeat, &endless);
mpris_signal_player_status_change(playback, shuffle, repeat, endless);
mpris_signal_player_caps_change(enjoy_caps_get());
int *status = malloc(sizeof(*status) * 4);
status[0] = playback;
status[1] = shuffle;
status[2] = repeat;
status[3] = endless;
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_STATUS_CHANGE), status, NULL, NULL);
int *caps = malloc(sizeof(*caps));
*caps = enjoy_caps_get();
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_CAPS_CHANGE), caps, NULL, NULL);
if (w->play.playing)
elm_toolbar_item_state_set(w->action.play, w->action.pause);
@ -183,7 +191,9 @@ _win_play_eval(Win *w)
w->play.playing_last = !w->play.playing;
_win_play_pause_toggle(w);
mpris_signal_player_caps_change(enjoy_caps_get());
int *caps = malloc(sizeof(*caps));
*caps = enjoy_caps_get();
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_CAPS_CHANGE), caps, NULL, NULL);
}
static Eina_Bool
@ -270,8 +280,10 @@ end:
_win_play_eval(w);
_win_toolbar_eval(w);
mpris_signal_player_caps_change(enjoy_caps_get());
mpris_signal_player_track_change(s);
int *caps = malloc(sizeof(*caps));
*caps = enjoy_caps_get();
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_CAPS_CHANGE), caps, NULL, NULL);
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_TRACK_CHANGE), s, no_free, NULL);
}
static void
@ -359,7 +371,9 @@ _win_action_play(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNU
_win_play_pause_toggle(w);
_win_play_eval(w);
mpris_signal_player_caps_change(enjoy_caps_get());
int *caps = malloc(sizeof(*caps));
*caps = enjoy_caps_get();
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_CAPS_CHANGE), caps, NULL, NULL);
}
static void
@ -372,7 +386,9 @@ _win_action_pause(void *data, Evas_Object *obj __UNUSED__, void *event_info __UN
_win_play_pause_toggle(w);
_win_play_eval(w);
mpris_signal_player_caps_change(enjoy_caps_get());
int *caps = malloc(sizeof(*caps));
*caps = enjoy_caps_get();
ecore_event_add(enjoy_event_id_get(ENJOY_EVENT_PLAYER_CAPS_CHANGE), caps, NULL, NULL);
}
static void