enjoy: simplify events and isolate mpris bit more.
Keep mpris stuff into mpris itself. Things like status and capabilities will go into a structure that is easier to use. Events were simplified, couple of them do not carry arguments anymore, removing the need of "no_free" and hacks like alocating an integer to later free it. The point of event data is when you must use that value, in that exact sequence. When you have things that just the latest version matters, like the capabilities or the current song you'll inform MPRIS, then it's simpler to just query before using. Remember that events are asynchronous and may run after timers, fd-handlers (mouse, kbd) and even other events. I've also fixed the behavior of setting repeat (loop), reflect the UI. Shuffle also were not updating toolbar, etc. As a bonus I've added a missing MPRIS TrackList.GetLength :-) Last but not least... watch out things like giving Edje a MSG_INT where the given pointer is Eina_Bool (1 byte), it may cause problems depending on the sibling values :-/ SVN revision: 63145
This commit is contained in:
parent
5d2e467aa0
commit
88289dd448
|
@ -258,15 +258,23 @@ list_next_go(Evas_Object *obj)
|
|||
}
|
||||
|
||||
int32_t
|
||||
list_song_selected_n_get(Evas_Object *obj)
|
||||
list_song_selected_n_get(const Evas_Object *obj)
|
||||
{
|
||||
LIST_GET_OR_RETURN(list, obj, 0);
|
||||
if (list->page.songs) return page_songs_selected_n_get(list->page.songs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t
|
||||
list_song_count(const Evas_Object *obj)
|
||||
{
|
||||
LIST_GET_OR_RETURN(list, obj, 0);
|
||||
if (list->page.songs) return page_songs_count(list->page.songs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Song *
|
||||
list_song_nth_get(Evas_Object *obj, int32_t n)
|
||||
list_song_nth_get(const Evas_Object *obj, int32_t n)
|
||||
{
|
||||
LIST_GET_OR_RETURN(list, obj, NULL);
|
||||
if (list->page.songs) return page_songs_nth_get(list->page.songs, n);
|
||||
|
|
|
@ -82,11 +82,6 @@ enjoy_cache_dir_get(void)
|
|||
return cache;
|
||||
}
|
||||
|
||||
void
|
||||
no_free()
|
||||
{
|
||||
}
|
||||
|
||||
EAPI int ENJOY_EVENT_PLAYER_CAPS_CHANGE = -1;
|
||||
EAPI int ENJOY_EVENT_PLAYER_STATUS_CHANGE = -1;
|
||||
EAPI int ENJOY_EVENT_PLAYER_TRACK_CHANGE = -1;
|
||||
|
|
|
@ -580,9 +580,7 @@ _song_item_selected(void *data, Evas_Object *list __UNUSED__, void *event_info)
|
|||
static void
|
||||
_page_songs_after_populate(Page *page)
|
||||
{
|
||||
ecore_event_add
|
||||
(ENJOY_EVENT_TRACKLIST_TRACKLIST_CHANGE,
|
||||
&page->num_elements, no_free, NULL);
|
||||
ecore_event_add(ENJOY_EVENT_TRACKLIST_TRACKLIST_CHANGE, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static Evas_Object *
|
||||
|
@ -746,12 +744,11 @@ page_songs_next_go(Evas_Object *obj)
|
|||
page->selected = it;
|
||||
elm_genlist_item_selected_set(it, EINA_TRUE);
|
||||
elm_genlist_item_bring_in(it);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_TRACK_CHANGE, song, no_free, NULL);
|
||||
return song;
|
||||
}
|
||||
|
||||
int32_t
|
||||
page_songs_selected_n_get(Evas_Object *obj)
|
||||
page_songs_selected_n_get(const Evas_Object *obj)
|
||||
{
|
||||
PAGE_SONGS_GET_OR_RETURN(page, obj, 0);
|
||||
Elm_Genlist_Item *it;
|
||||
|
@ -762,8 +759,15 @@ page_songs_selected_n_get(Evas_Object *obj)
|
|||
return (it) ? n : 0;
|
||||
}
|
||||
|
||||
int32_t
|
||||
page_songs_count(const Evas_Object *obj)
|
||||
{
|
||||
PAGE_SONGS_GET_OR_RETURN(page, obj, 0);
|
||||
return page->num_elements;
|
||||
}
|
||||
|
||||
Song *
|
||||
page_songs_nth_get(Evas_Object *obj, int32_t n)
|
||||
page_songs_nth_get(const Evas_Object *obj, int32_t n)
|
||||
{
|
||||
PAGE_SONGS_GET_OR_RETURN(page, obj, NULL);
|
||||
Elm_Genlist_Item *it = page->first;
|
||||
|
@ -843,7 +847,6 @@ 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);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_TRACK_CHANGE, song, no_free, NULL);
|
||||
return song;
|
||||
}
|
||||
|
||||
|
@ -871,7 +874,6 @@ 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);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_TRACK_CHANGE, song, no_free, NULL);
|
||||
return song;
|
||||
}
|
||||
|
||||
|
@ -898,7 +900,6 @@ page_songs_prev_go(Evas_Object *obj)
|
|||
page->selected = it;
|
||||
elm_genlist_item_selected_set(it, EINA_TRUE);
|
||||
elm_genlist_item_bring_in(it);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_TRACK_CHANGE, song, no_free, NULL);
|
||||
return song;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,31 +9,40 @@
|
|||
|
||||
typedef struct _Song Song;
|
||||
typedef struct _Enjoy_Player_Status Enjoy_Player_Status;
|
||||
typedef struct _Enjoy_Player_Caps Enjoy_Player_Caps;
|
||||
|
||||
/**
|
||||
* Capabilities changed. Use enjoy_player_caps_get() for value.
|
||||
*/
|
||||
EAPI extern int ENJOY_EVENT_PLAYER_CAPS_CHANGE;
|
||||
/**
|
||||
* Status changed. Use enjoy_player_status_get() for value.
|
||||
*/
|
||||
EAPI extern int ENJOY_EVENT_PLAYER_STATUS_CHANGE;
|
||||
EAPI extern int ENJOY_EVENT_PLAYER_TRACK_CHANGE;
|
||||
EAPI extern int ENJOY_EVENT_TRACKLIST_TRACKLIST_CHANGE;
|
||||
|
||||
/*
|
||||
* Capabilities and player status values conform to the MPRIS 1.0 standard:
|
||||
* http://www.mpris.org/1.0/spec.html
|
||||
*/
|
||||
struct _Enjoy_Player_Caps {
|
||||
Eina_Bool can_go_next:1;
|
||||
Eina_Bool can_go_prev:1;
|
||||
Eina_Bool can_pause:1;
|
||||
Eina_Bool can_play:1;
|
||||
Eina_Bool can_seek:1;
|
||||
Eina_Bool can_provide_metadata:1;
|
||||
Eina_Bool has_tracklist:1;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
ENJOY_CAPABILITY_CAN_GO_NEXT = 1 << 0,
|
||||
ENJOY_CAPABILITY_CAN_GO_PREV = 1 << 1,
|
||||
ENJOY_CAPABILITY_CAN_PAUSE = 1 << 2,
|
||||
ENJOY_CAPABILITY_CAN_PLAY = 1 << 3,
|
||||
ENJOY_CAPABILITY_CAN_SEEK = 1 << 4,
|
||||
ENJOY_CAPABILITY_CAN_PROVIDE_METADATA = 1 << 5,
|
||||
ENJOY_CAPABILITY_CAN_HAS_TRACKLIST = 1 << 6
|
||||
} Enjoy_Capabilities;
|
||||
ENJOY_PLAYBACK_PLAYING = 0,
|
||||
ENJOY_PLAYBACK_PAUSED,
|
||||
ENJOY_PLAYBACK_STOPPED
|
||||
} Enjoy_Playback_Status;
|
||||
|
||||
struct _Enjoy_Player_Status {
|
||||
Eina_Bool playback;
|
||||
Eina_Bool shuffle;
|
||||
Eina_Bool repeat;
|
||||
Eina_Bool endless;
|
||||
Enjoy_Playback_Status playback;
|
||||
Eina_Bool shuffle:1;
|
||||
Eina_Bool repeat:1;
|
||||
Eina_Bool endless:1;
|
||||
};
|
||||
|
||||
EAPI char *enjoy_cache_dir_get(void);
|
||||
|
@ -41,10 +50,10 @@ EAPI Eina_Bool enjoy_repeat_get(void);
|
|||
EAPI int32_t enjoy_playlist_current_position_get(void);
|
||||
EAPI int32_t enjoy_position_get(void);
|
||||
EAPI int32_t enjoy_volume_get(void);
|
||||
EAPI int enjoy_caps_get(void);
|
||||
EAPI Song *enjoy_playlist_song_position_get(int32_t position);
|
||||
EAPI Song *enjoy_song_current_get(void);
|
||||
EAPI Song *enjoy_song_position_get(int32_t position);
|
||||
EAPI int32_t enjoy_playlist_count(void);
|
||||
EAPI const Song*enjoy_playlist_song_position_get(int32_t position);
|
||||
EAPI const Song*enjoy_song_current_get(void);
|
||||
EAPI const Song*enjoy_song_position_get(int32_t position);
|
||||
EAPI void enjoy_control_loop_set(Eina_Bool param);
|
||||
EAPI void enjoy_control_next(void);
|
||||
EAPI void enjoy_control_pause(void);
|
||||
|
@ -56,8 +65,9 @@ EAPI void enjoy_control_stop(void);
|
|||
EAPI void enjoy_position_set(int32_t position);
|
||||
EAPI void enjoy_quit(void);
|
||||
EAPI void enjoy_repeat_set(Eina_Bool repeat);
|
||||
EAPI Enjoy_Player_Status *enjoy_status_get(void);
|
||||
EAPI void enjoy_volume_set(int32_t volume);
|
||||
EAPI void no_free();
|
||||
|
||||
EAPI Enjoy_Player_Caps enjoy_player_caps_get(void);
|
||||
EAPI Enjoy_Player_Status enjoy_player_status_get(void);
|
||||
|
||||
#endif /* __PLUGIN_H__ */
|
||||
|
|
|
@ -71,8 +71,9 @@ Song *list_prev_go(Evas_Object *list);
|
|||
DB *list_db_get(const Evas_Object *obj);
|
||||
void list_freeze(Evas_Object *obj);
|
||||
void list_thaw(Evas_Object *obj);
|
||||
Song *list_song_nth_get(Evas_Object *obj, int32_t n);
|
||||
int32_t list_song_selected_n_get(Evas_Object *obj);
|
||||
Song *list_song_nth_get(const Evas_Object *obj, int32_t n);
|
||||
int32_t list_song_selected_n_get(const Evas_Object *obj);
|
||||
int32_t list_song_count(const Evas_Object *obj);
|
||||
|
||||
const char *page_title_get(const Evas_Object *obj);
|
||||
void page_songs_exists_changed(Evas_Object *obj, Eina_Bool exists);
|
||||
|
@ -92,8 +93,9 @@ Song *page_songs_shuffle_prev_go(Evas_Object *obj);
|
|||
void page_songs_shuffle_reset(Evas_Object *obj);
|
||||
Eina_Bool page_songs_prev_exists(const Evas_Object *obj);
|
||||
Song *page_songs_prev_go(Evas_Object *obj);
|
||||
Song *page_songs_nth_get(Evas_Object *obj, int32_t n);
|
||||
int32_t page_songs_selected_n_get(Evas_Object *obj);
|
||||
Song *page_songs_nth_get(const Evas_Object *obj, int32_t n);
|
||||
int32_t page_songs_selected_n_get(const Evas_Object *obj);
|
||||
int32_t page_songs_count(const Evas_Object *obj);
|
||||
|
||||
Evas_Object *cover_allsongs_fetch(Evas_Object *parent, unsigned short size);
|
||||
Evas_Object *cover_album_fetch(Evas_Object *parent, DB *db, Album *album, unsigned short size, void (*cb)(void *data), void *data);
|
||||
|
|
100
src/bin/win.c
100
src/bin/win.c
|
@ -141,19 +141,14 @@ _win_toolbar_eval(Win *w)
|
|||
elm_toolbar_item_disabled_set(w->action.nowplaying, EINA_TRUE);
|
||||
}
|
||||
|
||||
int *caps = malloc(sizeof(*caps));
|
||||
*caps = enjoy_caps_get();
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, caps, NULL, NULL);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
_win_play_pause_toggle(Win *w)
|
||||
{
|
||||
int *caps = malloc(sizeof(*caps));
|
||||
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_STATUS_CHANGE, enjoy_status_get(), NULL, NULL);
|
||||
*caps = enjoy_caps_get();
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, caps, NULL, NULL);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_STATUS_CHANGE, NULL, NULL, NULL);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, NULL, NULL, NULL);
|
||||
|
||||
if (w->play.playing)
|
||||
elm_toolbar_item_state_set(w->action.play, w->action.pause);
|
||||
|
@ -181,9 +176,7 @@ _win_play_eval(Win *w)
|
|||
w->play.playing_last = !w->play.playing;
|
||||
_win_play_pause_toggle(w);
|
||||
|
||||
int *caps = malloc(sizeof(*caps));
|
||||
*caps = enjoy_caps_get();
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, caps, NULL, NULL);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
|
@ -270,10 +263,8 @@ end:
|
|||
_win_play_eval(w);
|
||||
_win_toolbar_eval(w);
|
||||
|
||||
int *caps = malloc(sizeof(*caps));
|
||||
*caps = enjoy_caps_get();
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, caps, NULL, NULL);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_TRACK_CHANGE, s, no_free, NULL);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, NULL, NULL, NULL);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_TRACK_CHANGE, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -361,9 +352,7 @@ _win_action_play(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNU
|
|||
_win_play_pause_toggle(w);
|
||||
_win_play_eval(w);
|
||||
|
||||
int *caps = malloc(sizeof(*caps));
|
||||
*caps = enjoy_caps_get();
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, caps, NULL, NULL);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -376,9 +365,7 @@ _win_action_pause(void *data, Evas_Object *obj __UNUSED__, void *event_info __UN
|
|||
_win_play_pause_toggle(w);
|
||||
_win_play_eval(w);
|
||||
|
||||
int *caps = malloc(sizeof(*caps));
|
||||
*caps = enjoy_caps_get();
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, caps, NULL, NULL);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -566,44 +553,46 @@ enjoy_quit(void)
|
|||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
EAPI int
|
||||
enjoy_caps_get(void)
|
||||
EAPI Enjoy_Player_Caps
|
||||
enjoy_player_caps_get(void)
|
||||
{
|
||||
Win *w = &_win;
|
||||
int caps = 0;
|
||||
Enjoy_Player_Caps caps;
|
||||
|
||||
if (list_prev_exists(w->list)) caps |= ENJOY_CAPABILITY_CAN_GO_PREV;
|
||||
if ((w->play.shuffle) || (list_next_exists(w->list))) caps |= ENJOY_CAPABILITY_CAN_GO_NEXT;
|
||||
memset(&caps, 0, sizeof(caps));
|
||||
|
||||
caps.can_go_prev = !!list_prev_exists(w->list);
|
||||
caps.can_go_next = !!((w->play.shuffle) || (list_next_exists(w->list)));
|
||||
if (w->song)
|
||||
{
|
||||
caps |= ENJOY_CAPABILITY_CAN_PAUSE;
|
||||
caps |= ENJOY_CAPABILITY_CAN_PLAY;
|
||||
if (emotion_object_seekable_get(w->emotion))
|
||||
caps |= ENJOY_CAPABILITY_CAN_SEEK;
|
||||
caps |= ENJOY_CAPABILITY_CAN_PROVIDE_METADATA;
|
||||
caps |= ENJOY_CAPABILITY_CAN_HAS_TRACKLIST;
|
||||
caps.can_pause = EINA_TRUE;
|
||||
caps.can_play = EINA_TRUE;
|
||||
caps.can_seek = emotion_object_seekable_get(w->emotion);
|
||||
caps.can_provide_metadata = EINA_TRUE;
|
||||
caps.has_tracklist = EINA_TRUE;
|
||||
}
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
EAPI Enjoy_Player_Status*
|
||||
enjoy_status_get()
|
||||
EAPI Enjoy_Player_Status
|
||||
enjoy_player_status_get(void)
|
||||
{
|
||||
Win *w = &_win;
|
||||
Enjoy_Player_Status *status = calloc(1, sizeof(*status));
|
||||
if (!status) return NULL;
|
||||
Enjoy_Player_Status status;
|
||||
|
||||
memset(&status, 0, sizeof(status));
|
||||
|
||||
if (w->play.playing)
|
||||
status->playback = 0;
|
||||
status.playback = ENJOY_PLAYBACK_PLAYING;
|
||||
else if (w->play.position == 0.0)
|
||||
status->playback = 2;
|
||||
status.playback = ENJOY_PLAYBACK_STOPPED;
|
||||
else
|
||||
status->playback = 1;
|
||||
status.playback = ENJOY_PLAYBACK_PAUSED;
|
||||
|
||||
status->shuffle = !!w->play.shuffle;
|
||||
status->repeat = !!w->play.repeat;
|
||||
status->endless = 0;
|
||||
status.shuffle = !!w->play.shuffle;
|
||||
status.repeat = !!w->play.repeat;
|
||||
status.endless = EINA_FALSE;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -658,14 +647,14 @@ enjoy_volume_set(int32_t volume)
|
|||
emotion_object_audio_volume_set(w->emotion, w->play.volume);
|
||||
}
|
||||
|
||||
EAPI Song *
|
||||
EAPI const Song *
|
||||
enjoy_song_current_get(void)
|
||||
{
|
||||
Win *w = &_win;
|
||||
return w->song;
|
||||
}
|
||||
|
||||
EAPI Song *
|
||||
EAPI const Song *
|
||||
enjoy_song_position_get(int32_t position)
|
||||
{
|
||||
Win *w = &_win;
|
||||
|
@ -676,18 +665,23 @@ EAPI void
|
|||
enjoy_control_loop_set(Eina_Bool param)
|
||||
{
|
||||
Win *w = &_win;
|
||||
param = !!param;
|
||||
int val = !!param;
|
||||
w->play.repeat = !!param;
|
||||
edje_object_message_send(elm_layout_edje_get(w->nowplaying),
|
||||
EDJE_MESSAGE_INT, MSG_LOOP, ¶m);
|
||||
EDJE_MESSAGE_INT, MSG_LOOP, &val);
|
||||
ecore_event_add(ENJOY_EVENT_PLAYER_CAPS_CHANGE, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
EAPI void
|
||||
enjoy_control_shuffle_set(Eina_Bool param)
|
||||
{
|
||||
Win *w = &_win;
|
||||
param = !!param;
|
||||
int val = !!param;
|
||||
w->play.shuffle = !!param;
|
||||
edje_object_message_send(elm_layout_edje_get(w->nowplaying),
|
||||
EDJE_MESSAGE_INT, MSG_SHUFFLE, ¶m);
|
||||
EDJE_MESSAGE_INT, MSG_SHUFFLE, &val);
|
||||
if (val) list_shuffle_reset(w->list);
|
||||
_win_toolbar_eval(w);
|
||||
}
|
||||
|
||||
EAPI int32_t
|
||||
|
@ -698,7 +692,15 @@ enjoy_playlist_current_position_get(void)
|
|||
return list_song_selected_n_get(w->list);
|
||||
}
|
||||
|
||||
EAPI Song *
|
||||
EAPI int32_t
|
||||
enjoy_playlist_count(void)
|
||||
{
|
||||
Win *w = &_win;
|
||||
if (!w->list) return 0;
|
||||
return list_song_count(w->list);
|
||||
}
|
||||
|
||||
EAPI const Song *
|
||||
enjoy_playlist_song_position_get(int32_t position)
|
||||
{
|
||||
Win *w = &_win;
|
||||
|
|
|
@ -33,6 +33,21 @@ static int _mpris_log_domain = -1;
|
|||
#define DBG(...) EINA_LOG_DOM_DBG(_mpris_log_domain, __VA_ARGS__)
|
||||
|
||||
|
||||
/*
|
||||
* Capabilities and player status values conform to the MPRIS 1.0 standard:
|
||||
* http://www.mpris.org/1.0/spec.html
|
||||
*/
|
||||
typedef enum {
|
||||
MPRIS_CAPABILITY_CAN_GO_NEXT = 1 << 0,
|
||||
MPRIS_CAPABILITY_CAN_GO_PREV = 1 << 1,
|
||||
MPRIS_CAPABILITY_CAN_PAUSE = 1 << 2,
|
||||
MPRIS_CAPABILITY_CAN_PLAY = 1 << 3,
|
||||
MPRIS_CAPABILITY_CAN_SEEK = 1 << 4,
|
||||
MPRIS_CAPABILITY_CAN_PROVIDE_METADATA = 1 << 5,
|
||||
MPRIS_CAPABILITY_HAS_TRACKLIST = 1 << 6
|
||||
} Mpris_Capabilities;
|
||||
|
||||
|
||||
#define APPLICATION_NAME "org.mpris.enjoy"
|
||||
#define PLAYER_INTERFACE_NAME "org.freedesktop.MediaPlayer"
|
||||
#define ROOT_NAME "/Root" /* should really be "/", but this doesn't work correctly :( */
|
||||
|
@ -42,14 +57,14 @@ static int _mpris_log_domain = -1;
|
|||
|
||||
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_player_track_change(const 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,
|
||||
int value_type, void *value);
|
||||
int value_type, const void *value);
|
||||
static void _mpris_signal_emit(const char *root, const char *signal_name, int arg_type,
|
||||
void *arg_value);
|
||||
static DBusMessage *_mpris_player_next(E_DBus_Object *obj __UNUSED__, DBusMessage *msg);
|
||||
|
@ -68,9 +83,10 @@ static DBusMessage *_mpris_player_repeat_set(E_DBus_Object *obj __UNUSED__, DBus
|
|||
static DBusMessage *_mpris_player_status_get(E_DBus_Object *obj __UNUSED__, DBusMessage *msg);
|
||||
static DBusMessage *_mpris_player_position_set(E_DBus_Object *obj __UNUSED__, DBusMessage *msg);
|
||||
static DBusMessage *_mpris_player_position_get(E_DBus_Object *obj __UNUSED__, DBusMessage *msg);
|
||||
static DBusMessage *_mpris_song_metadata_reply(DBusMessage *msg, Song *song);
|
||||
static DBusMessage *_mpris_song_metadata_reply(DBusMessage *msg, const Song *song);
|
||||
static DBusMessage *_mpris_player_metadata_get(E_DBus_Object *obj __UNUSED__, DBusMessage *msg);
|
||||
static DBusMessage *_mpris_tracklist_current_track_get(E_DBus_Object *obj __UNUSED__, DBusMessage *msg);
|
||||
static DBusMessage *_mpris_tracklist_count(E_DBus_Object *obj __UNUSED__, DBusMessage *msg);
|
||||
static DBusMessage *_mpris_tracklist_metadata_get(E_DBus_Object *obj __UNUSED__, DBusMessage *msg);
|
||||
static DBusMessage *_mpris_tracklist_shuffle_set(E_DBus_Object *obj __UNUSED__, DBusMessage *msg);
|
||||
|
||||
|
@ -158,7 +174,7 @@ static const MPRIS_Method mpris_tracklist_methods[] = {
|
|||
/* Returns the position of the current URI in the track list */
|
||||
{ "GetCurrentTrack", "", "i", _mpris_tracklist_current_track_get },
|
||||
/* Returns the number of elements in the track list */
|
||||
{ "GetLength", "", "i", NULL },
|
||||
{ "GetLength", "", "i", _mpris_tracklist_count },
|
||||
/* Appends an URI to the track list */
|
||||
{ "AddTrack", "sb", "i", NULL },
|
||||
/* Removes an URL from the track list */
|
||||
|
@ -170,34 +186,49 @@ static const MPRIS_Method mpris_tracklist_methods[] = {
|
|||
{ NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
static int
|
||||
_caps_to_mpris_bits(const Enjoy_Player_Caps caps)
|
||||
{
|
||||
int bits = 0;
|
||||
if (caps.can_go_next) bits |= MPRIS_CAPABILITY_CAN_GO_NEXT;
|
||||
if (caps.can_go_prev) bits |= MPRIS_CAPABILITY_CAN_GO_PREV;
|
||||
if (caps.can_pause) bits |= MPRIS_CAPABILITY_CAN_PAUSE;
|
||||
if (caps.can_play) bits |= MPRIS_CAPABILITY_CAN_PLAY;
|
||||
if (caps.can_seek) bits |= MPRIS_CAPABILITY_CAN_SEEK;
|
||||
if (caps.can_provide_metadata) bits |= MPRIS_CAPABILITY_CAN_PROVIDE_METADATA;
|
||||
if (caps.has_tracklist) bits |= MPRIS_CAPABILITY_HAS_TRACKLIST;
|
||||
return bits;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_cb_player_caps_change(void *data __UNUSED__, int type __UNUSED__, void *event)
|
||||
_cb_player_caps_change(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
|
||||
{
|
||||
_mpris_signal_player_caps_change(*(int *)event);
|
||||
Enjoy_Player_Caps caps = enjoy_player_caps_get();
|
||||
int bits = _caps_to_mpris_bits(caps);
|
||||
_mpris_signal_player_caps_change(bits);
|
||||
return ECORE_CALLBACK_PASS_ON;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_cb_player_status_change(void *data __UNUSED__, int type __UNUSED__, void *event)
|
||||
_cb_player_status_change(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
|
||||
{
|
||||
const Enjoy_Player_Status *status = event;
|
||||
_mpris_signal_player_status_change(status->playback, status->shuffle, status->repeat, status->endless);
|
||||
Enjoy_Player_Status status = enjoy_player_status_get();
|
||||
_mpris_signal_player_status_change
|
||||
(status.playback, status.shuffle, status.repeat, status.endless);
|
||||
return ECORE_CALLBACK_PASS_ON;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_cb_player_track_change(void *data __UNUSED__, int type __UNUSED__, void *event)
|
||||
_cb_player_track_change(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
|
||||
{
|
||||
_mpris_signal_player_track_change((Song *)event);
|
||||
_mpris_signal_player_track_change(enjoy_song_current_get());
|
||||
return ECORE_CALLBACK_PASS_ON;
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
_cb_player_tracklist_change(void *data __UNUSED__, int type __UNUSED__, void *event)
|
||||
_cb_player_tracklist_change(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
|
||||
{
|
||||
_mpris_signal_tracklist_tracklist_change(*(int *)event);
|
||||
_mpris_signal_tracklist_tracklist_change(enjoy_playlist_count());
|
||||
return ECORE_CALLBACK_PASS_ON;
|
||||
}
|
||||
|
||||
|
@ -320,7 +351,7 @@ _mpris_methods_add(const char *root, const MPRIS_Method *methods)
|
|||
|
||||
static void
|
||||
_mpris_append_dict_entry(DBusMessageIter *dict_iter, const char *key,
|
||||
int value_type, void *value)
|
||||
int value_type, const void *value)
|
||||
{
|
||||
DBusMessageIter entry_iter, value_iter;
|
||||
const char *signature;
|
||||
|
@ -376,7 +407,7 @@ _mpris_signal_emit(const char *root, const char *signal_name, int arg_type, void
|
|||
}
|
||||
|
||||
static void
|
||||
_mpris_message_fill_song_metadata(DBusMessage *msg, Song *song)
|
||||
_mpris_message_fill_song_metadata(DBusMessage *msg, const Song *song)
|
||||
{
|
||||
DBusMessageIter iter, dict;
|
||||
|
||||
|
@ -444,19 +475,19 @@ _mpris_signal_player_status_change(int playback, int shuffle, int repeat, int en
|
|||
if (!sig) return;
|
||||
dbus_message_iter_init_append(sig, &iter);
|
||||
dbus_message_iter_open_container(&iter, DBUS_TYPE_STRUCT, NULL, &siter);
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_UINT32, &playback);
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_UINT32, &shuffle);
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_UINT32, &repeat);
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_UINT32, &endless);
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_INT32, &playback);
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_INT32, &shuffle);
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_INT32, &repeat);
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_INT32, &endless);
|
||||
dbus_message_iter_close_container(&iter, &siter);
|
||||
e_dbus_message_send(conn, sig, NULL, -1, NULL);
|
||||
dbus_message_unref(sig);
|
||||
}
|
||||
|
||||
static void
|
||||
_mpris_signal_player_track_change(Song *song)
|
||||
_mpris_signal_player_track_change(const Song *song)
|
||||
{
|
||||
static Song *old_song = NULL;
|
||||
static const void *old_song = NULL;
|
||||
if (old_song != song)
|
||||
{
|
||||
DBusMessage *sig = dbus_message_new_signal(PLAYER_NAME, PLAYER_INTERFACE_NAME, "TrackChange");
|
||||
|
@ -505,11 +536,10 @@ _mpris_player_stop(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
|
|||
static DBusMessage *
|
||||
_mpris_player_play(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
|
||||
{
|
||||
Enjoy_Player_Status *status = enjoy_status_get();
|
||||
if (!status->playback)
|
||||
Enjoy_Player_Status status = enjoy_player_status_get();
|
||||
if (!status.playback)
|
||||
enjoy_position_set(0);
|
||||
enjoy_control_play();
|
||||
free(status);
|
||||
return dbus_message_new_method_return(msg);
|
||||
}
|
||||
|
||||
|
@ -547,8 +577,16 @@ _mpris_root_version(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
|
|||
DBusMessageIter iter, siter;
|
||||
dbus_message_iter_init_append(reply, &iter);
|
||||
dbus_message_iter_open_container(&iter, DBUS_TYPE_STRUCT, NULL, &siter);
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_UINT16, (int[]) { 1 });
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_UINT16, (int[]) { 0 });
|
||||
|
||||
#define APPEND_UINT16(val) \
|
||||
do { \
|
||||
unsigned short _tmp_val = val; \
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_UINT16, &_tmp_val); \
|
||||
} while (0)
|
||||
APPEND_UINT16(1);
|
||||
APPEND_UINT16(0);
|
||||
#undef APPEND_UINT16
|
||||
|
||||
dbus_message_iter_close_container(&iter, &siter);
|
||||
return reply;
|
||||
}
|
||||
|
@ -558,8 +596,9 @@ _mpris_player_caps_get(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
|
|||
{
|
||||
DBusMessage *reply = dbus_message_new_method_return(msg);
|
||||
DBusMessageIter iter;
|
||||
int bits = _caps_to_mpris_bits(enjoy_player_caps_get());
|
||||
dbus_message_iter_init_append(reply, &iter);
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, (int[]) { enjoy_caps_get() });
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &bits);
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
@ -583,8 +622,9 @@ _mpris_player_volume_get(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
|
|||
{
|
||||
DBusMessage *reply = dbus_message_new_method_return(msg);
|
||||
DBusMessageIter iter;
|
||||
int vol = enjoy_volume_get();
|
||||
dbus_message_iter_init_append(reply, &iter);
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, (int[]) { enjoy_volume_get() });
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &vol);
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
@ -592,8 +632,8 @@ static DBusMessage *
|
|||
_mpris_player_repeat_set(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
|
||||
{
|
||||
dbus_bool_t repeat;
|
||||
dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &repeat, DBUS_TYPE_INVALID);
|
||||
enjoy_repeat_set(repeat);
|
||||
dbus_message_get_args(msg, NULL, DBUS_TYPE_BOOLEAN, &repeat, DBUS_TYPE_INVALID);
|
||||
enjoy_control_loop_set(repeat);
|
||||
return dbus_message_new_method_return(msg);
|
||||
}
|
||||
|
||||
|
@ -602,17 +642,23 @@ _mpris_player_status_get(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
|
|||
{
|
||||
DBusMessage *reply = dbus_message_new_method_return(msg);
|
||||
DBusMessageIter iter, siter;
|
||||
Enjoy_Player_Status *status = enjoy_status_get();
|
||||
Enjoy_Player_Status status = enjoy_player_status_get();
|
||||
|
||||
dbus_message_iter_init_append(reply, &iter);
|
||||
dbus_message_iter_open_container(&iter, DBUS_TYPE_STRUCT, NULL, &siter);
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_UINT32, &(status->playback));
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_UINT32, &(status->shuffle));
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_UINT32, &(status->repeat));
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_UINT32, &(status->endless));
|
||||
dbus_message_iter_close_container(&iter, &siter);
|
||||
|
||||
free(status);
|
||||
#define APPEND_INT(member) \
|
||||
do { \
|
||||
int _tmp_val = status.member; \
|
||||
dbus_message_iter_append_basic(&siter, DBUS_TYPE_INT32, &(_tmp_val)); \
|
||||
} while (0)
|
||||
APPEND_INT(playback);
|
||||
APPEND_INT(shuffle);
|
||||
APPEND_INT(repeat);
|
||||
APPEND_INT(endless);
|
||||
#undef APPEND_INT
|
||||
|
||||
dbus_message_iter_close_container(&iter, &siter);
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
@ -630,13 +676,14 @@ _mpris_player_position_get(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
|
|||
{
|
||||
DBusMessage *reply = dbus_message_new_method_return(msg);
|
||||
DBusMessageIter iter;
|
||||
int pos = enjoy_position_get();
|
||||
dbus_message_iter_init_append(reply, &iter);
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, (int[]) { enjoy_position_get() });
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &pos);
|
||||
return reply;
|
||||
}
|
||||
|
||||
static DBusMessage *
|
||||
_mpris_song_metadata_reply(DBusMessage *msg, Song *song)
|
||||
_mpris_song_metadata_reply(DBusMessage *msg, const Song *song)
|
||||
{
|
||||
DBusMessage *reply = dbus_message_new_method_return(msg);
|
||||
_mpris_message_fill_song_metadata(reply, song);
|
||||
|
@ -646,8 +693,7 @@ _mpris_song_metadata_reply(DBusMessage *msg, Song *song)
|
|||
static DBusMessage *
|
||||
_mpris_player_metadata_get(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
|
||||
{
|
||||
Song *song = enjoy_song_current_get();
|
||||
return _mpris_song_metadata_reply(msg, song);
|
||||
return _mpris_song_metadata_reply(msg, enjoy_song_current_get());
|
||||
}
|
||||
|
||||
static DBusMessage *
|
||||
|
@ -655,8 +701,20 @@ _mpris_tracklist_current_track_get(E_DBus_Object *obj __UNUSED__, DBusMessage *m
|
|||
{
|
||||
DBusMessage *reply = dbus_message_new_method_return(msg);
|
||||
DBusMessageIter iter;
|
||||
int pos = enjoy_playlist_current_position_get();
|
||||
dbus_message_iter_init_append(reply, &iter);
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, (int[]) { enjoy_playlist_current_position_get() });
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &pos);
|
||||
return reply;
|
||||
}
|
||||
|
||||
static DBusMessage *
|
||||
_mpris_tracklist_count(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
|
||||
{
|
||||
DBusMessage *reply = dbus_message_new_method_return(msg);
|
||||
DBusMessageIter iter;
|
||||
int count = enjoy_playlist_count();
|
||||
dbus_message_iter_init_append(reply, &iter);
|
||||
dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &count);
|
||||
return reply;
|
||||
}
|
||||
|
||||
|
@ -664,7 +722,7 @@ static DBusMessage *
|
|||
_mpris_tracklist_metadata_get(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
|
||||
{
|
||||
DBusMessage *reply;
|
||||
Song *song;
|
||||
const Song *song;
|
||||
dbus_int32_t position;
|
||||
dbus_message_get_args(msg, NULL, DBUS_TYPE_INT32, &position, DBUS_TYPE_INVALID);
|
||||
song = enjoy_playlist_song_position_get(position);
|
||||
|
|
Loading…
Reference in New Issue