aboutsummaryrefslogtreecommitdiff
path: root/src/music-player-bridge.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/music-player-bridge.c')
-rw-r--r--src/music-player-bridge.c208
1 files changed, 153 insertions, 55 deletions
diff --git a/src/music-player-bridge.c b/src/music-player-bridge.c
index 250f761..9fd386a 100644
--- a/src/music-player-bridge.c
+++ b/src/music-player-bridge.c
@@ -70,6 +70,8 @@ typedef struct _FamiliarPlayersDB FamiliarPlayersDB;
typedef struct _FamiliarPlayersDBClass FamiliarPlayersDBClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
+
+#define PLAYER_CONTROLLER_TYPE_STATE (player_controller_state_get_type ())
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
struct _MusicPlayerBridge {
@@ -88,6 +90,14 @@ struct _MusicPlayerBridgePrivate {
FamiliarPlayersDB* playersDB;
};
+typedef enum {
+ PLAYER_CONTROLLER_STATE_OFFLINE,
+ PLAYER_CONTROLLER_STATE_INSTANTIATING,
+ PLAYER_CONTROLLER_STATE_READY,
+ PLAYER_CONTROLLER_STATE_CONNECTED,
+ PLAYER_CONTROLLER_STATE_DISCONNECTED
+} PlayerControllerstate;
+
static gpointer music_player_bridge_parent_class = NULL;
@@ -115,13 +125,19 @@ static void _music_player_bridge_on_server_count_changed_indicate_listener_serve
MusicPlayerBridge* music_player_bridge_new (void);
MusicPlayerBridge* music_player_bridge_construct (GType object_type);
GeeSet* familiar_players_db_records (FamiliarPlayersDB* self);
-PlayerController* player_controller_new (DbusmenuMenuitem* root, const char* client_name, gboolean active);
-PlayerController* player_controller_construct (GType object_type, DbusmenuMenuitem* root, const char* client_name, gboolean active);
+GType player_controller_state_get_type (void);
+PlayerController* player_controller_new (DbusmenuMenuitem* root, const char* client_name, PlayerControllerstate initial_state);
+PlayerController* player_controller_construct (GType object_type, DbusmenuMenuitem* root, const char* client_name, PlayerControllerstate initial_state);
static void music_player_bridge_try_to_add_inactive_familiar_clients (MusicPlayerBridge* self);
static gboolean music_player_bridge_server_is_not_of_interest (MusicPlayerBridge* self, const char* type);
+void player_controller_update_state (PlayerController* self, PlayerControllerstate new_state);
+void player_controller_activate (PlayerController* self);
+GAppInfo* player_controller_get_app_info (PlayerController* self);
static void music_player_bridge_desktop_info_callback (MusicPlayerBridge* self, IndicateListenerServer* server, char* path, void* data);
void player_controller_vanish (PlayerController* self);
+gboolean familiar_players_db_already_familiar (FamiliarPlayersDB* self, const char* desktop);
void familiar_players_db_insert (FamiliarPlayersDB* self, const char* desktop);
+GAppInfo* music_player_bridge_create_app_info (const char* path);
void music_player_bridge_set_root_menu_item (MusicPlayerBridge* self, DbusmenuMenuitem* menu);
static void music_player_bridge_finalize (GObject* obj);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
@@ -184,6 +200,22 @@ MusicPlayerBridge* music_player_bridge_new (void) {
}
+static gpointer _g_object_ref0 (gpointer self) {
+ return self ? g_object_ref (self) : NULL;
+}
+
+
+static char* string_strip (const char* self) {
+ char* result = NULL;
+ char* _result_;
+ g_return_val_if_fail (self != NULL, NULL);
+ _result_ = g_strdup (self);
+ g_strstrip (_result_);
+ result = _result_;
+ return result;
+}
+
+
static void music_player_bridge_try_to_add_inactive_familiar_clients (MusicPlayerBridge* self) {
GError * _inner_error_;
gint count;
@@ -202,34 +234,43 @@ static void music_player_bridge_try_to_add_inactive_familiar_clients (MusicPlaye
}
app = (char*) gee_iterator_get (_app_it);
if (count == 0) {
- char** _tmp3_;
- gint _bits_size_;
- gint bits_length1;
- char** _tmp2_;
- char** bits;
- g_debug ("music-player-bridge.vala:51: we have found %s", app);
- bits = (_tmp3_ = _tmp2_ = g_strsplit (app, "/", 0), bits_length1 = _vala_array_length (_tmp2_), _bits_size_ = bits_length1, _tmp3_);
+ if (app == NULL) {
+ g_warning ("music-player-bridge.vala:52: App string in keyfile is null therefore m" \
+"oving on to next player");
+ _g_free0 (app);
+ continue;
+ }
{
- gint _tmp5__length1;
- char** _tmp5_;
- char** _tmp4_;
- char* _tmp6_;
- char* app_name;
- PlayerController* ctrl;
GDesktopAppInfo* info;
- char* desc;
- app_name = (_tmp6_ = g_strdup ((_tmp5_ = _tmp4_ = g_strsplit (bits[bits_length1 - 1], ".", 0), _tmp5__length1 = _vala_array_length (_tmp4_), _tmp5_)[0]), _tmp5_ = (_vala_array_free (_tmp5_, _tmp5__length1, (GDestroyNotify) g_free), NULL), _tmp6_);
- g_debug ("music-player-bridge.vala:56: we have found %s", app_name);
- ctrl = player_controller_new (self->priv->root_menu, app_name, FALSE);
- gee_abstract_map_set ((GeeAbstractMap*) self->priv->registered_clients, app_name, ctrl);
- info = g_desktop_app_info_new_from_filename (app_name);
- desc = g_strdup (g_app_info_get_display_name ((GAppInfo*) info));
- g_debug ("music-player-bridge.vala:63: description from app %s", desc);
+ GDesktopAppInfo* _tmp2_;
+ GAppInfo* app_info;
+ PlayerController* ctrl;
+ char* _tmp4_;
+ char* _tmp3_;
+ char* _tmp6_;
+ char* _tmp5_;
+ info = g_desktop_app_info_new_from_filename (app);
+ if (info == NULL) {
+ g_warning ("music-player-bridge.vala:58: Could not create a desktopappinfo instanc" \
+"e from app: %s", app);
+ _g_object_unref0 (info);
+ _g_free0 (app);
+ continue;
+ }
+ app_info = _g_object_ref0 ((_tmp2_ = info, G_IS_APP_INFO (_tmp2_) ? ((GAppInfo*) _tmp2_) : NULL));
+ ctrl = player_controller_new (self->priv->root_menu, g_app_info_get_name (app_info), PLAYER_CONTROLLER_STATE_OFFLINE);
+ g_object_set ((GObject*) ctrl, "app_info", app_info, NULL);
+ gee_abstract_map_set ((GeeAbstractMap*) self->priv->registered_clients, _tmp4_ = string_strip (_tmp3_ = g_utf8_strdown (g_app_info_get_name (app_info), -1)), ctrl);
+ _g_free0 (_tmp4_);
+ _g_free0 (_tmp3_);
+ g_debug ("music-player-bridge.vala:67: Created a player controller for %s which " \
+"was found in the cache file", _tmp6_ = string_strip (_tmp5_ = g_utf8_strdown (g_app_info_get_name (app_info), -1)));
+ _g_free0 (_tmp6_);
+ _g_free0 (_tmp5_);
count = count + 1;
- _g_free0 (app_name);
- _g_object_unref0 (ctrl);
_g_object_unref0 (info);
- _g_free0 (desc);
+ _g_object_unref0 (app_info);
+ _g_object_unref0 (ctrl);
}
goto __finally0;
__catch0_g_error:
@@ -238,21 +279,19 @@ static void music_player_bridge_try_to_add_inactive_familiar_clients (MusicPlaye
er = _inner_error_;
_inner_error_ = NULL;
{
- g_warning ("music-player-bridge.vala:67: desktop path in cache is not formatted as" \
+ g_warning ("music-player-bridge.vala:71: desktop path in cache is not formatted as" \
" we have anticipated");
_g_error_free0 (er);
}
}
__finally0:
if (_inner_error_ != NULL) {
- bits = (_vala_array_free (bits, bits_length1, (GDestroyNotify) g_free), NULL);
_g_free0 (app);
_g_object_unref0 (_app_it);
g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
g_clear_error (&_inner_error_);
return;
}
- bits = (_vala_array_free (bits, bits_length1, (GDestroyNotify) g_free), NULL);
}
_g_free0 (app);
break;
@@ -271,7 +310,7 @@ void music_player_bridge_on_server_added (MusicPlayerBridge* self, IndicateListe
gboolean _tmp3_ = FALSE;
g_return_if_fail (self != NULL);
g_return_if_fail (type != NULL);
- g_debug ("music-player-bridge.vala:76: MusicPlayerBridge -> on_server_added with" \
+ g_debug ("music-player-bridge.vala:80: MusicPlayerBridge -> on_server_added with" \
" value %s", type);
if (music_player_bridge_server_is_not_of_interest (self, type)) {
return;
@@ -283,15 +322,32 @@ void music_player_bridge_on_server_added (MusicPlayerBridge* self, IndicateListe
_tmp3_ = FALSE;
}
if (_tmp3_) {
- indicate_listener_get_server_property_cb cb;
- PlayerController* ctrl;
- cb = (indicate_listener_get_server_property_cb) music_player_bridge_desktop_info_callback;
- indicate_listener_server_get_desktop (self->priv->listener, object, cb, self);
- ctrl = player_controller_new (self->priv->root_menu, client_name, TRUE);
- gee_abstract_map_set ((GeeAbstractMap*) self->priv->registered_clients, client_name, ctrl);
- g_debug ("music-player-bridge.vala:84: client of name %s has successfully regist" \
-"ered with us", client_name);
- _g_object_unref0 (ctrl);
+ GeeSet* _tmp4_;
+ gboolean _tmp5_;
+ PlayerController* _tmp8_;
+ gboolean _tmp9_;
+ if ((_tmp5_ = gee_collection_contains ((GeeCollection*) (_tmp4_ = gee_map_get_keys ((GeeMap*) self->priv->registered_clients)), client_name), _g_object_unref0 (_tmp4_), _tmp5_)) {
+ PlayerController* _tmp6_;
+ PlayerController* _tmp7_;
+ g_debug ("music-player-bridge.vala:86: It figured out that it already has an ins" \
+"tance for this player already");
+ player_controller_update_state (_tmp6_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) self->priv->registered_clients, client_name), PLAYER_CONTROLLER_STATE_READY);
+ _g_object_unref0 (_tmp6_);
+ player_controller_activate (_tmp7_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) self->priv->registered_clients, client_name));
+ _g_object_unref0 (_tmp7_);
+ } else {
+ PlayerController* ctrl;
+ ctrl = player_controller_new (self->priv->root_menu, client_name, PLAYER_CONTROLLER_STATE_READY);
+ gee_abstract_map_set ((GeeAbstractMap*) self->priv->registered_clients, client_name, ctrl);
+ g_debug ("music-player-bridge.vala:94: New Client of name %s has successfully re" \
+"gistered with us", client_name);
+ _g_object_unref0 (ctrl);
+ }
+ if ((_tmp9_ = player_controller_get_app_info (_tmp8_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) self->priv->registered_clients, client_name)) == NULL, _g_object_unref0 (_tmp8_), _tmp9_)) {
+ indicate_listener_get_server_property_cb cb;
+ cb = (indicate_listener_get_server_property_cb) music_player_bridge_desktop_info_callback;
+ indicate_listener_server_get_desktop (self->priv->listener, object, cb, self);
+ }
}
_g_free0 (client_name);
}
@@ -306,8 +362,8 @@ void music_player_bridge_on_server_removed (MusicPlayerBridge* self, IndicateLis
gboolean _tmp3_ = FALSE;
g_return_if_fail (self != NULL);
g_return_if_fail (type != NULL);
- g_debug ("music-player-bridge.vala:90: MusicPlayerBridge -> on_server_removed wi" \
-"th value %s", type);
+ g_debug ("music-player-bridge.vala:106: MusicPlayerBridge -> on_server_removed w" \
+"ith value %s", type);
if (music_player_bridge_server_is_not_of_interest (self, type)) {
return;
}
@@ -322,8 +378,8 @@ void music_player_bridge_on_server_removed (MusicPlayerBridge* self, IndicateLis
player_controller_vanish (_tmp4_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) self->priv->registered_clients, client_name));
_g_object_unref0 (_tmp4_);
gee_map_remove ((GeeMap*) self->priv->registered_clients, client_name, NULL);
- g_debug ("music-player-bridge.vala:96: Successively removed menu_item for client" \
-" %s from registered_clients", client_name);
+ g_debug ("music-player-bridge.vala:112: Successively removed menu_item for clien" \
+"t %s from registered_clients", client_name);
}
_g_free0 (client_name);
}
@@ -347,7 +403,7 @@ static gboolean music_player_bridge_server_is_not_of_interest (MusicPlayerBridge
return result;
}
if (string_contains (type, "music") == FALSE) {
- g_debug ("music-player-bridge.vala:103: server is of no interest, it is not an " \
+ g_debug ("music-player-bridge.vala:120: server is of no interest, it is not an " \
"music server");
result = TRUE;
return result;
@@ -357,19 +413,39 @@ static gboolean music_player_bridge_server_is_not_of_interest (MusicPlayerBridge
}
-static gpointer _g_object_ref0 (gpointer self) {
- return self ? g_object_ref (self) : NULL;
-}
-
-
static void music_player_bridge_desktop_info_callback (MusicPlayerBridge* self, IndicateListenerServer* server, char* path, void* data) {
void* _tmp0_;
MusicPlayerBridge* bridge;
+ gboolean _tmp1_ = FALSE;
g_return_if_fail (self != NULL);
g_return_if_fail (path != NULL);
- g_debug ("music-player-bridge.vala:112: we got a desktop file path hopefully: %s", path);
bridge = _g_object_ref0 ((_tmp0_ = data, IS_MUSIC_PLAYER_BRIDGE (_tmp0_) ? ((MusicPlayerBridge*) _tmp0_) : NULL));
- familiar_players_db_insert (bridge->priv->playersDB, path);
+ if (string_contains (path, "/")) {
+ _tmp1_ = familiar_players_db_already_familiar (bridge->priv->playersDB, path) == FALSE;
+ } else {
+ _tmp1_ = FALSE;
+ }
+ if (_tmp1_) {
+ GAppInfo* app_info;
+ g_debug ("music-player-bridge.vala:131: About to store desktop file path: %s", path);
+ familiar_players_db_insert (bridge->priv->playersDB, path);
+ app_info = music_player_bridge_create_app_info (path);
+ if (app_info != NULL) {
+ char* _tmp3_;
+ char* _tmp2_;
+ PlayerController* _tmp4_;
+ PlayerController* ctrl;
+ ctrl = (_tmp4_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) bridge->priv->registered_clients, _tmp3_ = string_strip (_tmp2_ = g_utf8_strdown (g_app_info_get_name (app_info), -1))), _g_free0 (_tmp3_), _g_free0 (_tmp2_), _tmp4_);
+ g_object_set ((GObject*) ctrl, "app_info", app_info, NULL);
+ g_debug ("music-player-bridge.vala:137: successfully created appinfo from path a" \
+"nd set it on the respective instance");
+ _g_object_unref0 (ctrl);
+ }
+ _g_object_unref0 (app_info);
+ } else {
+ g_debug ("music-player-bridge.vala:141: Ignoring desktop file path because its e" \
+"ither invalid of the db cache file has it already: %s", path);
+ }
_g_object_unref0 (bridge);
_g_free0 (path);
}
@@ -380,25 +456,26 @@ void music_player_bridge_set_root_menu_item (MusicPlayerBridge* self, DbusmenuMe
g_return_if_fail (self != NULL);
g_return_if_fail (menu != NULL);
self->priv->root_menu = (_tmp0_ = _g_object_ref0 (menu), _g_object_unref0 (self->priv->root_menu), _tmp0_);
+ music_player_bridge_try_to_add_inactive_familiar_clients (self);
}
void music_player_bridge_on_server_count_changed (MusicPlayerBridge* self, IndicateListenerServer* object, guint i) {
g_return_if_fail (self != NULL);
- g_debug ("music-player-bridge.vala:125: MusicPlayerBridge-> on_server_count_chan" \
+ g_debug ("music-player-bridge.vala:153: MusicPlayerBridge-> on_server_count_chan" \
"ged with value %u", i);
}
void music_player_bridge_on_indicator_added (MusicPlayerBridge* self, IndicateListenerServer* object, IndicateListenerIndicator* p0) {
g_return_if_fail (self != NULL);
- g_debug ("music-player-bridge.vala:129: MusicPlayerBridge-> on_indicator_added");
+ g_debug ("music-player-bridge.vala:157: MusicPlayerBridge-> on_indicator_added");
}
void music_player_bridge_on_indicator_removed (MusicPlayerBridge* self, IndicateListenerServer* object, IndicateListenerIndicator* p0) {
g_return_if_fail (self != NULL);
- g_debug ("music-player-bridge.vala:134: MusicPlayerBridge -> on_indicator_remove" \
+ g_debug ("music-player-bridge.vala:162: MusicPlayerBridge -> on_indicator_remove" \
"d");
}
@@ -406,11 +483,32 @@ void music_player_bridge_on_indicator_removed (MusicPlayerBridge* self, Indicate
void music_player_bridge_on_indicator_modified (MusicPlayerBridge* self, IndicateListenerServer* object, IndicateListenerIndicator* p0, const char* s) {
g_return_if_fail (self != NULL);
g_return_if_fail (s != NULL);
- g_debug ("music-player-bridge.vala:139: MusicPlayerBridge -> indicator_modified " \
+ g_debug ("music-player-bridge.vala:167: MusicPlayerBridge -> indicator_modified " \
"with vale %s", s);
}
+GAppInfo* music_player_bridge_create_app_info (const char* path) {
+ GAppInfo* result = NULL;
+ GDesktopAppInfo* info;
+ GDesktopAppInfo* _tmp0_;
+ GAppInfo* app_info;
+ g_return_val_if_fail (path != NULL, NULL);
+ info = g_desktop_app_info_new_from_filename (path);
+ if (path == NULL) {
+ g_warning ("music-player-bridge.vala:174: Could not create a desktopappinfo instan" \
+"ce from app: %s", path);
+ result = NULL;
+ _g_object_unref0 (info);
+ return result;
+ }
+ app_info = _g_object_ref0 ((_tmp0_ = info, G_IS_APP_INFO (_tmp0_) ? ((GAppInfo*) _tmp0_) : NULL));
+ result = app_info;
+ _g_object_unref0 (info);
+ return result;
+}
+
+
static void music_player_bridge_class_init (MusicPlayerBridgeClass * klass) {
music_player_bridge_parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (MusicPlayerBridgePrivate));