From 31b5a5a6508535ed1af86919c79d75571f1a65ef Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Fri, 30 Mar 2012 14:08:19 -0400 Subject: Import upstream version 0.8.5.0 --- src/Makefile.in | 5 +- src/metadata-widget.c | 166 +++++++++++++---------------- src/mpris2-controller.c | 188 +++++++++++++++++++++++++-------- src/mpris2-controller.vala | 25 ++++- src/mpris2-interfaces.c | 42 ++++---- src/mpris2-interfaces.vala | 2 +- src/music-player-bridge.c | 213 +++++++++++++++++++------------------ src/music-player-bridge.h | 4 +- src/music-player-bridge.vala | 26 +++-- src/settings-manager.c | 243 +++++++++++++++++++++---------------------- src/settings-manager.vala | 32 +++--- src/sound-service-dbus.c | 16 +-- 12 files changed, 526 insertions(+), 436 deletions(-) (limited to 'src') diff --git a/src/Makefile.in b/src/Makefile.in index 308bbfc..ca34bba 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -56,10 +56,7 @@ DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(top_srcdir)/Makefile.am.marshal subdir = src ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/intltool.m4 \ - $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ - $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ - $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/gcov.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/m4/gcov.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) diff --git a/src/metadata-widget.c b/src/metadata-widget.c index ceae79a..4d7763f 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -44,7 +44,7 @@ struct _MetadataWidgetPrivate GtkWidget* piece_label; GtkWidget* container_label; GtkWidget* player_label; - GdkPixbuf* icon_buf; + GtkWidget* player_icon; DbusmenuMenuitem* twin_item; gint current_height; }; @@ -126,7 +126,6 @@ metadata_widget_init (MetadataWidget *self) MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); GtkWidget *hbox; GtkWidget *outer_v_box; - priv->icon_buf = NULL; #if GTK_CHECK_VERSION(3, 0, 0) outer_v_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); @@ -178,7 +177,6 @@ metadata_widget_init (MetadataWidget *self) GtkWidget* vbox = gtk_vbox_new(FALSE, 0); #endif - // artist GtkWidget* artist; artist = gtk_label_new(""); @@ -224,16 +222,35 @@ metadata_widget_init (MetadataWidget *self) G_CALLBACK(metadata_widget_selection_received_event_callback), GTK_WIDGET(self)); + gint padding = 4; + gtk_widget_style_get(GTK_WIDGET(self), "toggle-spacing", &padding, NULL); + +#if GTK_CHECK_VERSION(3, 0, 0) + GtkWidget * tophbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, padding); +#else + GtkWidget * tophbox = gtk_hbox_new(FALSE, padding); +#endif + + GtkWidget *player_icon; + player_icon = gtk_image_new(); + priv->player_icon = player_icon; + + gtk_misc_set_alignment (GTK_MISC(priv->player_icon), 1.0 /* right aligned */, 0.5); + gtk_box_pack_start (GTK_BOX (tophbox), priv->player_icon, FALSE, FALSE, 0); + GtkWidget* spacer; + spacer = gtk_alignment_new (0,0,0,0); + gtk_container_add (GTK_CONTAINER (spacer), priv->meta_data_h_box); + gtk_alignment_set_padding (GTK_ALIGNMENT (spacer),5,0,0,0); + // player label GtkWidget* player_label; player_label = gtk_label_new (""); - gtk_misc_set_alignment(GTK_MISC(player_label), (gfloat)0, (gfloat)0); - gtk_misc_set_padding (GTK_MISC(player_label), (gfloat)1, (gfloat)4); - gtk_widget_set_size_request (player_label, 150, 24); + gtk_misc_set_alignment(GTK_MISC(player_label), (gfloat)0, 0.5); priv->player_label = player_label; + gtk_box_pack_start (GTK_BOX (tophbox), priv->player_label, TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX(outer_v_box), priv->player_label, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(outer_v_box), priv->meta_data_h_box, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(outer_v_box), tophbox, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(outer_v_box), spacer, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (self), outer_v_box); @@ -246,16 +263,6 @@ metadata_widget_init (MetadataWidget *self) static void metadata_widget_dispose (GObject *object) { - MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(METADATA_WIDGET(object)); - - if (priv->icon_buf != NULL){ - #if GTK_CHECK_VERSION(3, 0, 0) - g_object_unref(priv->icon_buf); - #else - gdk_pixbuf_unref(priv->icon_buf); - #endif - priv->icon_buf = NULL; - } G_OBJECT_CLASS (metadata_widget_parent_class)->dispose (object); } @@ -349,13 +356,19 @@ metadata_image_expose_gtk_3 (GtkWidget *metadata, // Draw the triangle if the player is running ... static gboolean metadata_widget_icon_triangle_draw_cb_gtk_3 (GtkWidget *widget, - cairo_t* cr, - gpointer user_data) + cairo_t* cr, + gpointer user_data) { - g_return_val_if_fail(IS_METADATA_WIDGET(user_data), FALSE); - MetadataWidget* meta = METADATA_WIDGET(user_data); + g_return_val_if_fail (IS_METADATA_WIDGET (user_data), FALSE); + MetadataWidget* meta = METADATA_WIDGET (user_data); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(meta); + gboolean running = dbusmenu_menuitem_property_get_bool (priv->twin_item, + DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING); + + if (!running) + return FALSE; + GtkStyle *style; int x, y, arrow_width, arrow_height; @@ -369,32 +382,18 @@ metadata_widget_icon_triangle_draw_cb_gtk_3 (GtkWidget *widget, x = allocation.x; y = 0; - gint offset = gdk_pixbuf_get_height (priv->icon_buf) / 3; - - // Draw player icon - if (priv->icon_buf != NULL){ - gdk_cairo_set_source_pixbuf (cr, - priv->icon_buf, - x + arrow_width + 1, - y + offset); - cairo_paint (cr); - } - // Draw triangle but only if the player is running. - if (dbusmenu_menuitem_property_get_bool (priv->twin_item, - DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING)){ - y += gdk_pixbuf_get_height (priv->icon_buf) / 3 + 3; - cairo_set_line_width (cr, 1.0); - - cairo_move_to (cr, x, y); - cairo_line_to (cr, x, y + arrow_height); - cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0); - cairo_close_path (cr); - cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0, - style->fg[gtk_widget_get_state(widget)].green/65535.0, - style->fg[gtk_widget_get_state(widget)].blue/65535.0); - cairo_fill (cr); - } + y += gtk_image_get_pixel_size (GTK_IMAGE (priv->player_icon)) / 3 + 5; + cairo_set_line_width (cr, 1.0); + + cairo_move_to (cr, x, y); + cairo_line_to (cr, x, y + arrow_height); + cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0); + cairo_close_path (cr); + cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0, + style->fg[gtk_widget_get_state(widget)].green/65535.0, + style->fg[gtk_widget_get_state(widget)].blue/65535.0); + cairo_fill (cr); return FALSE; } @@ -445,7 +444,7 @@ metadata_image_expose (GtkWidget *metadata, return FALSE; } clear_album_art (GTK_IMAGE(priv->album_art)); - g_string_erase (priv->old_image_path, 0, -1); + g_string_erase (priv->old_image_path, 0, -1); gtk_widget_set_size_request(GTK_WIDGET(priv->album_art), 60, 60); draw_album_art_placeholder(metadata); return FALSE; @@ -459,9 +458,16 @@ metadata_widget_icon_triangle_draw_cb (GtkWidget *widget, gpointer user_data) { g_return_val_if_fail(IS_METADATA_WIDGET(user_data), FALSE); + MetadataWidget* meta = METADATA_WIDGET(user_data); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(meta); + gboolean running = dbusmenu_menuitem_property_get_bool (priv->twin_item, + DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING); + + if (!running) + return FALSE; + GtkStyle *style; cairo_t *cr; int x, y, arrow_width, arrow_height; @@ -478,32 +484,18 @@ metadata_widget_icon_triangle_draw_cb (GtkWidget *widget, x = allocation.x; y = allocation.y; - gint offset = (allocation.height - gdk_pixbuf_get_height (priv->icon_buf)) / 2; - - // Draw player icon - if (priv->icon_buf != NULL){ - gdk_cairo_set_source_pixbuf (cr, - priv->icon_buf, - x + arrow_width + 1, - y + offset); - cairo_paint (cr); - } - // Draw triangle but only if the player is running. - if (dbusmenu_menuitem_property_get_bool (priv->twin_item, - DBUSMENU_METADATA_MENUITEM_PLAYER_RUNNING)){ - y += allocation.height/2.0 - (double)arrow_height/2.0; - cairo_set_line_width (cr, 1.0); - - cairo_move_to (cr, x, y); - cairo_line_to (cr, x, y + arrow_height); - cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0); - cairo_close_path (cr); - cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0, - style->fg[gtk_widget_get_state(widget)].green/65535.0, - style->fg[gtk_widget_get_state(widget)].blue/65535.0); - cairo_fill (cr); - } + y += allocation.height/2.0 - (double)arrow_height/2.0; + cairo_set_line_width (cr, 1.0); + + cairo_move_to (cr, x, y); + cairo_line_to (cr, x, y + arrow_height); + cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0); + cairo_close_path (cr); + cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0, + style->fg[gtk_widget_get_state(widget)].green/65535.0, + style->fg[gtk_widget_get_state(widget)].blue/65535.0); + cairo_fill (cr); cairo_destroy (cr); return FALSE; @@ -790,27 +782,12 @@ metadata_widget_set_style(GtkWidget* metadata, GtkStyle* style) static void metadata_widget_set_icon (MetadataWidget *self) { - MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); - - if (priv->icon_buf != NULL){ - #if GTK_CHECK_VERSION(3, 0, 0) - g_object_unref(priv->icon_buf); - #else - gdk_pixbuf_unref(priv->icon_buf); - #endif - priv->icon_buf = NULL; - } - - gint padding = 0; - gtk_widget_style_get(GTK_WIDGET(self), "horizontal-padding", &padding, NULL); - gint width, height; - gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height); - + MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); + GString* banshee_string = g_string_new ( "banshee" ); gchar * tmp = g_utf8_strdown (dbusmenu_menuitem_property_get(priv->twin_item, DBUSMENU_METADATA_MENUITEM_PLAYER_NAME), -1); GString* app_panel = g_string_new (tmp); g_free (tmp); - GdkPixbuf* icon_buf; // Banshee Special case! // Not ideal but apparently we want the banshee icon to be the greyscale one @@ -827,12 +804,9 @@ metadata_widget_set_icon (MetadataWidget *self) dbusmenu_menuitem_property_get ( priv->twin_item, DBUSMENU_METADATA_MENUITEM_PLAYER_ICON )); } - icon_buf = gtk_icon_theme_load_icon ( gtk_icon_theme_get_default(), - app_panel->str, - (width > height) ? width : height, - GTK_ICON_LOOKUP_GENERIC_FALLBACK, - NULL ); - priv->icon_buf = icon_buf; + + gtk_image_set_from_icon_name(GTK_IMAGE (priv->player_icon), app_panel->str, GTK_ICON_SIZE_MENU); + g_string_free ( app_panel, TRUE); g_string_free ( banshee_string, TRUE); } diff --git a/src/mpris2-controller.c b/src/mpris2-controller.c index 57250b6..a471d07 100644 --- a/src/mpris2-controller.c +++ b/src/mpris2-controller.c @@ -151,6 +151,7 @@ typedef struct _PlaylistsMenuitem PlaylistsMenuitem; typedef struct _PlaylistsMenuitemClass PlaylistsMenuitemClass; #define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL))) typedef struct _Mpris2ControllerFetchPlaylistsData Mpris2ControllerFetchPlaylistsData; +#define _active_playlist_container_free0(var) ((var == NULL) ? NULL : (var = (active_playlist_container_free (var), NULL))) struct _Mpris2Controller { GObject parent_instance; @@ -218,7 +219,7 @@ struct _MprisPlaylistsIface { void (*set_Orderings) (MprisPlaylists* self, gchar** value, int value_length1); guint32 (*get_PlaylistCount) (MprisPlaylists* self); void (*set_PlaylistCount) (MprisPlaylists* self, guint32 value); - void (*get_ActivePlaylist) (MprisPlaylists* self, ActivePlaylistContainer* value); + ActivePlaylistContainer* (*get_ActivePlaylist) (MprisPlaylists* self); void (*set_ActivePlaylist) (MprisPlaylists* self, ActivePlaylistContainer* value); }; @@ -281,8 +282,12 @@ struct _Mpris2ControllerFetchPlaylistsData { PlaylistDetails* _tmp9_; gint _tmp9__length1; PlayerController* _tmp10_; - gboolean _tmp11_; - gboolean* _tmp12_; + GAppInfo* _tmp11_; + GAppInfo* _tmp12_; + const gchar* _tmp13_; + PlayerController* _tmp14_; + gboolean _tmp15_; + gboolean* _tmp16_; GError * _inner_error_; }; @@ -382,8 +387,10 @@ PlaylistDetails* mpris_playlists_GetPlaylists_finish (MprisPlaylists* self, GAsy static void mpris2_controller_fetch_playlists_ready (GObject* source_object, GAsyncResult* _res_, gpointer _user_data_); static void _vala_PlaylistDetails_array_free (PlaylistDetails* array, gint array_length); void playlists_menuitem_update (PlaylistsMenuitem* self, PlaylistDetails* playlists, int playlists_length1); +GAppInfo* player_controller_get_app_info (PlayerController* self); static gboolean* _bool_dup (gboolean* self); -void mpris_playlists_get_ActivePlaylist (MprisPlaylists* self, ActivePlaylistContainer* result); +static gboolean mpris2_controller_validate_playlists_details (Mpris2Controller* self); +ActivePlaylistContainer* mpris_playlists_get_ActivePlaylist (MprisPlaylists* self); void playlists_menuitem_active_playlist_update (PlaylistsMenuitem* self, PlaylistDetails* detail); void mpris2_controller_activate_playlist (Mpris2Controller* self, const char* path); void mpris_playlists_ActivatePlaylist (MprisPlaylists* self, const char* playlist_id, GAsyncReadyCallback _callback_, gpointer _user_data_); @@ -580,7 +587,7 @@ void mpris2_controller_property_changed_cb (Mpris2Controller* self, const gchar* } _tmp31_ = _tmp26_; if (_tmp31_) { - g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 300, _mpris2_controller_fetch_active_playlist_gsource_func, g_object_ref (self), g_object_unref); + g_timeout_add_full (G_PRIORITY_DEFAULT, (guint) 500, _mpris2_controller_fetch_active_playlist_gsource_func, g_object_ref (self), g_object_unref); } _tmp32_ = changed_properties; _tmp33_ = g_hash_table_lookup (_tmp32_, "PlaylistCount"); @@ -1206,13 +1213,18 @@ static gboolean mpris2_controller_fetch_playlists_co (Mpris2ControllerFetchPlayl playlists_menuitem_update (_data_->_tmp8_, _data_->_tmp9_, _data_->_tmp9__length1); _g_object_unref0 (_data_->playlists_item); } else { - g_warning ("mpris2-controller.vala:243: Playlists are on but its returning no cur" \ -"rent_playlists"); _data_->_tmp10_ = _data_->self->priv->_owner; - _data_->_tmp11_ = FALSE; - _data_->_tmp12_ = __bool_dup0 (&_data_->_tmp11_); - _g_free0 (_data_->_tmp10_->use_playlists); - _data_->_tmp10_->use_playlists = _data_->_tmp12_; + _data_->_tmp11_ = player_controller_get_app_info (_data_->_tmp10_); + _data_->_tmp12_ = _data_->_tmp11_; + _data_->_tmp13_ = NULL; + _data_->_tmp13_ = g_app_info_get_name (_data_->_tmp12_); + g_warning ("mpris2-controller.vala:243: Playlists are on but %s is returning no c" \ +"urrent_playlists ?", _data_->_tmp13_); + _data_->_tmp14_ = _data_->self->priv->_owner; + _data_->_tmp15_ = FALSE; + _data_->_tmp16_ = __bool_dup0 (&_data_->_tmp15_); + _g_free0 (_data_->_tmp14_->use_playlists); + _data_->_tmp14_->use_playlists = _data_->_tmp16_; } _data_->current_playlists = (_vala_PlaylistDetails_array_free (_data_->current_playlists, _data_->current_playlists_length1), NULL); if (_data_->_state_ == 0) { @@ -1225,50 +1237,136 @@ static gboolean mpris2_controller_fetch_playlists_co (Mpris2ControllerFetchPlayl } -static gboolean mpris2_controller_fetch_active_playlist (Mpris2Controller* self) { +static gboolean mpris2_controller_validate_playlists_details (Mpris2Controller* self) { gboolean result = FALSE; MprisPlaylists* _tmp0_; - ActivePlaylistContainer _tmp1_; - ActivePlaylistContainer _tmp2_; - ActivePlaylistContainer _tmp3_; + ActivePlaylistContainer* _tmp1_; + ActivePlaylistContainer* _tmp2_; + ActivePlaylistContainer* _tmp3_; gboolean _tmp4_; - gboolean _tmp5_; - PlayerController* _tmp6_; - GeeArrayList* _tmp7_; - gpointer _tmp8_ = NULL; - PlaylistsMenuitem* playlists_item; - PlaylistsMenuitem* _tmp9_; - MprisPlaylists* _tmp10_; - ActivePlaylistContainer _tmp11_; - ActivePlaylistContainer _tmp12_; - ActivePlaylistContainer _tmp13_; - PlaylistDetails* _tmp14_; - PlaylistDetails _tmp15_; + MprisPlaylists* _tmp5_; + ActivePlaylistContainer* _tmp6_; + ActivePlaylistContainer* _tmp7_; + ActivePlaylistContainer* _tmp8_; + gboolean _tmp9_; + gboolean _tmp10_; + MprisPlaylists* _tmp11_; + ActivePlaylistContainer* _tmp12_; + ActivePlaylistContainer* _tmp13_; + ActivePlaylistContainer* _tmp14_; + PlaylistDetails* _tmp15_; + gboolean _tmp16_; + gboolean _tmp17_ = FALSE; + MprisPlaylists* _tmp18_; + ActivePlaylistContainer* _tmp19_; + ActivePlaylistContainer* _tmp20_; + ActivePlaylistContainer* _tmp21_; + PlaylistDetails* _tmp22_; + const char* _tmp23_; + gboolean _tmp24_; + gboolean _tmp31_; g_return_val_if_fail (self != NULL, FALSE); _tmp0_ = self->priv->_playlists; - mpris_playlists_get_ActivePlaylist (_tmp0_, &_tmp1_); + _tmp1_ = mpris_playlists_get_ActivePlaylist (_tmp0_); _tmp2_ = _tmp1_; _tmp3_ = _tmp2_; - _tmp4_ = _tmp3_.valid; - _tmp5_ = _tmp4_ == FALSE; - active_playlist_container_destroy (&_tmp3_); - if (_tmp5_) { + _tmp4_ = _tmp3_ == NULL; + _active_playlist_container_free0 (_tmp3_); + if (_tmp4_) { result = FALSE; return result; } - _tmp6_ = self->priv->_owner; - _tmp7_ = _tmp6_->custom_items; - _tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_PLAYLISTS); - playlists_item = IS_PLAYLISTS_MENUITEM ((PlayerItem*) _tmp8_) ? ((PlaylistsMenuitem*) ((PlayerItem*) _tmp8_)) : NULL; - _tmp9_ = playlists_item; - _tmp10_ = self->priv->_playlists; - mpris_playlists_get_ActivePlaylist (_tmp10_, &_tmp11_); - _tmp12_ = _tmp11_; + _tmp5_ = self->priv->_playlists; + _tmp6_ = mpris_playlists_get_ActivePlaylist (_tmp5_); + _tmp7_ = _tmp6_; + _tmp8_ = _tmp7_; + _tmp9_ = (*_tmp8_).valid; + _tmp10_ = _tmp9_ == FALSE; + _active_playlist_container_free0 (_tmp8_); + if (_tmp10_) { + result = FALSE; + return result; + } + _tmp11_ = self->priv->_playlists; + _tmp12_ = mpris_playlists_get_ActivePlaylist (_tmp11_); _tmp13_ = _tmp12_; - _tmp14_ = _tmp13_.details; - _tmp15_ = *_tmp14_; - playlists_menuitem_active_playlist_update (_tmp9_, &_tmp15_); - active_playlist_container_destroy (&_tmp13_); + _tmp14_ = _tmp13_; + _tmp15_ = (*_tmp14_).details; + _tmp16_ = _tmp15_ == NULL; + _active_playlist_container_free0 (_tmp14_); + if (_tmp16_) { + result = FALSE; + return result; + } + _tmp18_ = self->priv->_playlists; + _tmp19_ = mpris_playlists_get_ActivePlaylist (_tmp18_); + _tmp20_ = _tmp19_; + _tmp21_ = _tmp20_; + _tmp22_ = (*_tmp21_).details; + _tmp23_ = (*_tmp22_).path; + _tmp24_ = _tmp23_ == NULL; + _active_playlist_container_free0 (_tmp21_); + if (_tmp24_) { + _tmp17_ = TRUE; + } else { + MprisPlaylists* _tmp25_; + ActivePlaylistContainer* _tmp26_; + ActivePlaylistContainer* _tmp27_; + ActivePlaylistContainer* _tmp28_; + PlaylistDetails* _tmp29_; + const gchar* _tmp30_; + _tmp25_ = self->priv->_playlists; + _tmp26_ = mpris_playlists_get_ActivePlaylist (_tmp25_); + _tmp27_ = _tmp26_; + _tmp28_ = _tmp27_; + _tmp29_ = (*_tmp28_).details; + _tmp30_ = (*_tmp29_).name; + _tmp17_ = _tmp30_ == NULL; + _active_playlist_container_free0 (_tmp28_); + } + _tmp31_ = _tmp17_; + if (_tmp31_) { + result = FALSE; + return result; + } + result = TRUE; + return result; +} + + +static gboolean mpris2_controller_fetch_active_playlist (Mpris2Controller* self) { + gboolean result = FALSE; + gboolean _tmp0_ = FALSE; + PlayerController* _tmp1_; + GeeArrayList* _tmp2_; + gpointer _tmp3_ = NULL; + PlaylistsMenuitem* playlists_item; + PlaylistsMenuitem* _tmp4_; + MprisPlaylists* _tmp5_; + ActivePlaylistContainer* _tmp6_; + ActivePlaylistContainer* _tmp7_; + ActivePlaylistContainer* _tmp8_; + PlaylistDetails* _tmp9_; + PlaylistDetails _tmp10_; + g_return_val_if_fail (self != NULL, FALSE); + _tmp0_ = mpris2_controller_validate_playlists_details (self); + if (_tmp0_ == FALSE) { + result = FALSE; + return result; + } + _tmp1_ = self->priv->_owner; + _tmp2_ = _tmp1_->custom_items; + _tmp3_ = gee_abstract_list_get ((GeeAbstractList*) _tmp2_, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_PLAYLISTS); + playlists_item = IS_PLAYLISTS_MENUITEM ((PlayerItem*) _tmp3_) ? ((PlaylistsMenuitem*) ((PlayerItem*) _tmp3_)) : NULL; + _tmp4_ = playlists_item; + _tmp5_ = self->priv->_playlists; + _tmp6_ = mpris_playlists_get_ActivePlaylist (_tmp5_); + _tmp7_ = _tmp6_; + _tmp8_ = _tmp7_; + _tmp9_ = (*_tmp8_).details; + _tmp10_ = *_tmp9_; + playlists_menuitem_active_playlist_update (_tmp4_, &_tmp10_); + _active_playlist_container_free0 (_tmp8_); result = FALSE; _g_object_unref0 (playlists_item); return result; @@ -1298,7 +1396,7 @@ void mpris2_controller_activate_playlist (Mpris2Controller* self, const char* pa _tmp2_ = path; _tmp3_ = e; _tmp4_ = _tmp3_->message; - g_warning ("mpris2-controller.vala:264: Could not activate playlist %s because %s", (const gchar*) _tmp2_, _tmp4_); + g_warning ("mpris2-controller.vala:283: Could not activate playlist %s because %s", (const gchar*) _tmp2_, _tmp4_); _g_error_free0 (e); } __finally13: diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 0fa7b6c..2cc8d12 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -92,7 +92,7 @@ public class Mpris2Controller : GLib.Object } Variant? playlist_v = changed_properties.lookup("ActivePlaylist"); if ( playlist_v != null && this.owner.use_playlists == true ){ - Timeout.add (300, this.fetch_active_playlist); + Timeout.add (500, this.fetch_active_playlist); } Variant? playlist_count_v = changed_properties.lookup("PlaylistCount"); if ( playlist_count_v != null && this.owner.use_playlists == true ){ @@ -240,14 +240,33 @@ public class Mpris2Controller : GLib.Object playlists_item.update(current_playlists); } else{ - warning(" Playlists are on but its returning no current_playlists" ); + warning(" Playlists are on but %s is returning no current_playlists ?", + this.owner.app_info.get_name()); this.owner.use_playlists = false; } } + private bool validate_playlists_details() + { + if (this.playlists.ActivePlaylist == null){ + return false; + } + if (this.playlists.ActivePlaylist.valid == false){ + return false; + } + if (this.playlists.ActivePlaylist.details == null){ + return false; + } + if (this.playlists.ActivePlaylist.details.path == null || + this.playlists.ActivePlaylist.details.name == null){ + return false; + } + return true; + } + private bool fetch_active_playlist() { - if (this.playlists.ActivePlaylist.valid == false){ + if (this.validate_playlists_details() == false){ return false; } PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem; diff --git a/src/mpris2-interfaces.c b/src/mpris2-interfaces.c index 9058f95..d625955 100644 --- a/src/mpris2-interfaces.c +++ b/src/mpris2-interfaces.c @@ -70,6 +70,7 @@ typedef struct _MprisPlaylistsIface MprisPlaylistsIface; #define TYPE_MPRIS_PLAYLISTS_PROXY (mpris_playlists_proxy_get_type ()) typedef GDBusProxy MprisPlaylistsProxy; typedef GDBusProxyClass MprisPlaylistsProxyClass; +#define _active_playlist_container_free0(var) ((var == NULL) ? NULL : (var = (active_playlist_container_free (var), NULL))) struct _MprisRootIface { GTypeInterface parent_iface; @@ -128,7 +129,7 @@ struct _MprisPlaylistsIface { void (*set_Orderings) (MprisPlaylists* self, gchar** value, int value_length1); guint32 (*get_PlaylistCount) (MprisPlaylists* self); void (*set_PlaylistCount) (MprisPlaylists* self, guint32 value); - void (*get_ActivePlaylist) (MprisPlaylists* self, ActivePlaylistContainer* value); + ActivePlaylistContainer* (*get_ActivePlaylist) (MprisPlaylists* self); void (*set_ActivePlaylist) (MprisPlaylists* self, ActivePlaylistContainer* value); }; @@ -263,7 +264,7 @@ gchar** mpris_playlists_get_Orderings (MprisPlaylists* self, int* result_length1 void mpris_playlists_set_Orderings (MprisPlaylists* self, gchar** value, int value_length1); guint32 mpris_playlists_get_PlaylistCount (MprisPlaylists* self); void mpris_playlists_set_PlaylistCount (MprisPlaylists* self, guint32 value); -void mpris_playlists_get_ActivePlaylist (MprisPlaylists* self, ActivePlaylistContainer* result); +ActivePlaylistContainer* mpris_playlists_get_ActivePlaylist (MprisPlaylists* self); void mpris_playlists_set_ActivePlaylist (MprisPlaylists* self, ActivePlaylistContainer* value); static void g_cclosure_user_marshal_VOID__BOXED (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data); static void mpris_playlists_proxy_g_signal (GDBusProxy* proxy, const gchar* sender_name, const gchar* signal_name, GVariant* parameters); @@ -276,7 +277,7 @@ static gchar** mpris_playlists_dbus_proxy_get_Orderings (MprisPlaylists* self, i static void mpris_playlists_dbus_proxy_set_Orderings (MprisPlaylists* self, gchar** value, int value_length1); static guint32 mpris_playlists_dbus_proxy_get_PlaylistCount (MprisPlaylists* self); static void mpris_playlists_dbus_proxy_set_PlaylistCount (MprisPlaylists* self, guint32 value); -static void mpris_playlists_dbus_proxy_get_ActivePlaylist (MprisPlaylists* self, ActivePlaylistContainer* result); +static ActivePlaylistContainer* mpris_playlists_dbus_proxy_get_ActivePlaylist (MprisPlaylists* self); static void mpris_playlists_dbus_proxy_set_ActivePlaylist (MprisPlaylists* self, ActivePlaylistContainer* value); static void mpris_playlists_proxy_mpris_playlists_interface_init (MprisPlaylistsIface* iface); static void _dbus_mpris_playlists_ActivatePlaylist (MprisPlaylists* self, GVariant* parameters, GDBusMethodInvocation* invocation); @@ -1879,9 +1880,9 @@ void mpris_playlists_set_PlaylistCount (MprisPlaylists* self, guint32 value) { } -void mpris_playlists_get_ActivePlaylist (MprisPlaylists* self, ActivePlaylistContainer* result) { - g_return_if_fail (self != NULL); - MPRIS_PLAYLISTS_GET_INTERFACE (self)->get_ActivePlaylist (self, result); +ActivePlaylistContainer* mpris_playlists_get_ActivePlaylist (MprisPlaylists* self) { + g_return_val_if_fail (self != NULL, NULL); + return MPRIS_PLAYLISTS_GET_INTERFACE (self)->get_ActivePlaylist (self); } @@ -2211,8 +2212,9 @@ static void mpris_playlists_dbus_proxy_set_PlaylistCount (MprisPlaylists* self, } -static void mpris_playlists_dbus_proxy_get_ActivePlaylist (MprisPlaylists* self, ActivePlaylistContainer* result) { +static ActivePlaylistContainer* mpris_playlists_dbus_proxy_get_ActivePlaylist (MprisPlaylists* self) { GVariant *_inner_reply; + ActivePlaylistContainer* _result; ActivePlaylistContainer _tmp39_; GVariantIter _tmp40_; GVariant* _tmp41_; @@ -2233,7 +2235,7 @@ static void mpris_playlists_dbus_proxy_get_ActivePlaylist (MprisPlaylists* self, _arguments = g_variant_builder_end (&_arguments_builder); _reply = g_dbus_proxy_call_sync ((GDBusProxy *) self, "org.freedesktop.DBus.Properties.Get", _arguments, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); if (!_reply) { - return; + return NULL; } g_variant_get (_reply, "(v)", &_inner_reply); g_variant_unref (_reply); @@ -2255,9 +2257,9 @@ static void mpris_playlists_dbus_proxy_get_ActivePlaylist (MprisPlaylists* self, g_variant_unref (_tmp47_); _tmp39_.details = g_memdup (&_tmp43_, sizeof (PlaylistDetails)); g_variant_unref (_tmp42_); - *result = _tmp39_; + _result = g_memdup (&_tmp39_, sizeof (ActivePlaylistContainer)); g_variant_unref (_inner_reply); - return; + return _result; } @@ -2462,20 +2464,20 @@ static GVariant* _dbus_mpris_playlists_get_PlaylistCount (MprisPlaylists* self) static GVariant* _dbus_mpris_playlists_get_ActivePlaylist (MprisPlaylists* self) { - ActivePlaylistContainer result = {0}; + ActivePlaylistContainer* result; GVariantBuilder _tmp62_; GVariantBuilder _tmp63_; GVariant* _reply; - mpris_playlists_get_ActivePlaylist (self, &result); + result = mpris_playlists_get_ActivePlaylist (self); g_variant_builder_init (&_tmp62_, G_VARIANT_TYPE_TUPLE); - g_variant_builder_add_value (&_tmp62_, g_variant_new_boolean (result.valid)); + g_variant_builder_add_value (&_tmp62_, g_variant_new_boolean ((*result).valid)); g_variant_builder_init (&_tmp63_, G_VARIANT_TYPE_TUPLE); - g_variant_builder_add_value (&_tmp63_, g_variant_new_object_path ((*result.details).path)); - g_variant_builder_add_value (&_tmp63_, g_variant_new_string ((*result.details).name)); - g_variant_builder_add_value (&_tmp63_, g_variant_new_string ((*result.details).icon_path)); + g_variant_builder_add_value (&_tmp63_, g_variant_new_object_path ((*(*result).details).path)); + g_variant_builder_add_value (&_tmp63_, g_variant_new_string ((*(*result).details).name)); + g_variant_builder_add_value (&_tmp63_, g_variant_new_string ((*(*result).details).icon_path)); g_variant_builder_add_value (&_tmp62_, g_variant_builder_end (&_tmp63_)); _reply = g_variant_builder_end (&_tmp62_); - active_playlist_container_destroy (&result); + _active_playlist_container_free0 (result); return _reply; } @@ -2534,7 +2536,7 @@ static void _dbus_mpris_playlists_set_PlaylistCount (MprisPlaylists* self, GVari static void _dbus_mpris_playlists_set_ActivePlaylist (MprisPlaylists* self, GVariant* _value) { - ActivePlaylistContainer value = {0}; + ActivePlaylistContainer* value = NULL; ActivePlaylistContainer _tmp67_; GVariantIter _tmp68_; GVariant* _tmp69_; @@ -2561,9 +2563,9 @@ static void _dbus_mpris_playlists_set_ActivePlaylist (MprisPlaylists* self, GVar g_variant_unref (_tmp75_); _tmp67_.details = g_memdup (&_tmp71_, sizeof (PlaylistDetails)); g_variant_unref (_tmp70_); - value = _tmp67_; + value = g_memdup (&_tmp67_, sizeof (ActivePlaylistContainer)); mpris_playlists_set_ActivePlaylist (self, &value); - active_playlist_container_destroy (&value); + _active_playlist_container_free0 (value); } diff --git a/src/mpris2-interfaces.vala b/src/mpris2-interfaces.vala index db6888d..cb68e84 100644 --- a/src/mpris2-interfaces.vala +++ b/src/mpris2-interfaces.vala @@ -65,7 +65,7 @@ public interface MprisPlaylists : Object { //properties public abstract string[] Orderings{owned get; set;} public abstract uint32 PlaylistCount{owned get; set;} - public abstract ActivePlaylistContainer ActivePlaylist {owned get; set;} + public abstract ActivePlaylistContainer? ActivePlaylist {owned get; set;} //methods public abstract async void ActivatePlaylist(ObjectPath playlist_id) throws IOError; diff --git a/src/music-player-bridge.c b/src/music-player-bridge.c index d3d865d..f04450b 100644 --- a/src/music-player-bridge.c +++ b/src/music-player-bridge.c @@ -133,7 +133,7 @@ typedef enum { struct _Block1Data { int _ref_count_; MusicPlayerBridge * self; - GFileMonitor* monitor; + GFileMonitor* weak_monitor; }; struct _PlayerController { @@ -180,9 +180,9 @@ PlayerController* player_controller_construct (GType object_type, DbusmenuMenuit static void music_player_bridge_establish_file_monitoring (MusicPlayerBridge* self, GAppInfo* info, const gchar* mpris_key); static Block1Data* block1_data_ref (Block1Data* _data1_); static void block1_data_unref (Block1Data* _data1_); -static void __lambda2_ (Block1Data* _data1_, GFile* desktop_file, GFile* other_file, GFileMonitorEvent event_type); +static void ___lambda2_ (Block1Data* _data1_, GFile* desktop_file, GFile* other_file, GFileMonitorEvent event_type); static void music_player_bridge_relevant_desktop_file_changed (MusicPlayerBridge* self, GFile* desktop_file, GFile* other_file, GFileMonitorEvent event_type, GFileMonitor* monitor); -static void ___lambda2__g_file_monitor_changed (GFileMonitor* _sender, GFile* file, GFile* other_file, GFileMonitorEvent event_type, gpointer self); +static void ____lambda2__g_file_monitor_changed (GFileMonitor* _sender, GFile* file, GFile* other_file, GFileMonitorEvent event_type, gpointer self); void settings_manager_remove_interested (SettingsManager* self, const gchar* app_desktop_name); #define PLAYER_CONTROLLER_WIDGET_QUANTITY 4 void music_player_bridge_client_has_become_available (MusicPlayerBridge* self, const gchar* desktop, const gchar* dbus_name, gboolean use_playlists); @@ -407,6 +407,11 @@ static void music_player_bridge_try_to_add_inactive_familiar_clients (MusicPlaye } +static gpointer _g_object_ref0 (gpointer self) { + return self ? g_object_ref (self) : NULL; +} + + static Block1Data* block1_data_ref (Block1Data* _data1_) { g_atomic_int_inc (&_data1_->_ref_count_); return _data1_; @@ -416,18 +421,12 @@ static Block1Data* block1_data_ref (Block1Data* _data1_) { static void block1_data_unref (Block1Data* _data1_) { if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) { _g_object_unref0 (_data1_->self); - _g_object_unref0 (_data1_->monitor); g_slice_free (Block1Data, _data1_); } } -static gpointer _g_object_ref0 (gpointer self) { - return self ? g_object_ref (self) : NULL; -} - - -static void __lambda2_ (Block1Data* _data1_, GFile* desktop_file, GFile* other_file, GFileMonitorEvent event_type) { +static void ___lambda2_ (Block1Data* _data1_, GFile* desktop_file, GFile* other_file, GFileMonitorEvent event_type) { MusicPlayerBridge * self; GFile* _tmp0_; GFile* _tmp1_; @@ -438,18 +437,17 @@ static void __lambda2_ (Block1Data* _data1_, GFile* desktop_file, GFile* other_f _tmp0_ = desktop_file; _tmp1_ = other_file; _tmp2_ = event_type; - _tmp3_ = _data1_->monitor; + _tmp3_ = _data1_->weak_monitor; music_player_bridge_relevant_desktop_file_changed (self, _tmp0_, _tmp1_, _tmp2_, _tmp3_); } -static void ___lambda2__g_file_monitor_changed (GFileMonitor* _sender, GFile* file, GFile* other_file, GFileMonitorEvent event_type, gpointer self) { - __lambda2_ (self, file, other_file, event_type); +static void ____lambda2__g_file_monitor_changed (GFileMonitor* _sender, GFile* file, GFile* other_file, GFileMonitorEvent event_type, gpointer self) { + ___lambda2_ (self, file, other_file, event_type); } static void music_player_bridge_establish_file_monitoring (MusicPlayerBridge* self, GAppInfo* info, const gchar* mpris_key) { - Block1Data* _data1_; GAppInfo* _tmp0_; GDesktopAppInfo* _tmp1_; GDesktopAppInfo* desktop_info; @@ -460,17 +458,10 @@ static void music_player_bridge_establish_file_monitoring (MusicPlayerBridge* se const gchar* _tmp5_; GFile* _tmp6_ = NULL; GFile* f; - GeeHashMap* _tmp13_; - const gchar* _tmp14_; - const gchar* _tmp15_; - GFileMonitor* _tmp16_; GError * _inner_error_ = NULL; g_return_if_fail (self != NULL); g_return_if_fail (info != NULL); g_return_if_fail (mpris_key != NULL); - _data1_ = g_slice_new0 (Block1Data); - _data1_->_ref_count_ = 1; - _data1_->self = g_object_ref (self); _tmp0_ = info; _tmp1_ = _g_object_ref0 (G_IS_DESKTOP_APP_INFO (_tmp0_) ? ((GDesktopAppInfo*) _tmp0_) : NULL); desktop_info = _tmp1_; @@ -482,37 +473,61 @@ static void music_player_bridge_establish_file_monitoring (MusicPlayerBridge* se _tmp6_ = g_file_new_for_path (_tmp5_); f = _tmp6_; { + Block1Data* _data1_; GFile* _tmp7_; GFileMonitor* _tmp8_ = NULL; GFileMonitor* _tmp9_; + GFileMonitor* monitor; GFileMonitor* _tmp10_; + GFileMonitor* _tmp11_; + GFileMonitor* _tmp12_; + const gchar* _tmp13_; + GeeHashMap* _tmp14_; + const gchar* _tmp15_; + const gchar* _tmp16_; + _data1_ = g_slice_new0 (Block1Data); + _data1_->_ref_count_ = 1; + _data1_->self = g_object_ref (self); _tmp7_ = f; _tmp8_ = g_file_monitor (_tmp7_, G_FILE_MONITOR_SEND_MOVED, NULL, &_inner_error_); - _tmp9_ = _tmp8_; + _tmp9_ = _g_object_ref0 (_tmp8_); + monitor = _tmp9_; if (_inner_error_ != NULL) { + block1_data_unref (_data1_); + _data1_ = NULL; goto __catch0_g_error; } - _tmp10_ = _g_object_ref0 (_tmp9_); - _g_object_unref0 (_data1_->monitor); - _data1_->monitor = _tmp10_; + _tmp10_ = monitor; + _data1_->weak_monitor = _tmp10_; + _tmp11_ = monitor; + g_signal_connect_data (_tmp11_, "changed", (GCallback) ____lambda2__g_file_monitor_changed, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0); + _tmp12_ = monitor; + g_object_ref ((GObject*) _tmp12_); + _tmp13_ = file_path; + g_debug ("music-player-bridge.vala:95: monitoring file '%s'", _tmp13_); + _tmp14_ = self->priv->file_monitors; + _tmp15_ = file_path; + _tmp16_ = mpris_key; + gee_abstract_map_set ((GeeAbstractMap*) _tmp14_, _tmp15_, _tmp16_); + _g_object_unref0 (monitor); + block1_data_unref (_data1_); + _data1_ = NULL; } goto __finally0; __catch0_g_error: { GError* e = NULL; - GAppInfo* _tmp11_; - const gchar* _tmp12_ = NULL; + GAppInfo* _tmp17_; + const gchar* _tmp18_ = NULL; e = _inner_error_; _inner_error_ = NULL; - _tmp11_ = info; - _tmp12_ = g_app_info_get_name (_tmp11_); - g_warning ("music-player-bridge.vala:93: Unable to create a file monitor for %s", _tmp12_); + _tmp17_ = info; + _tmp18_ = g_app_info_get_name (_tmp17_); + g_warning ("music-player-bridge.vala:99: Unable to create a file monitor for %s", _tmp18_); _g_error_free0 (e); _g_object_unref0 (f); _g_free0 (file_path); _g_object_unref0 (desktop_info); - block1_data_unref (_data1_); - _data1_ = NULL; return; } __finally0: @@ -520,23 +535,13 @@ static void music_player_bridge_establish_file_monitoring (MusicPlayerBridge* se _g_object_unref0 (f); _g_free0 (file_path); _g_object_unref0 (desktop_info); - block1_data_unref (_data1_); - _data1_ = NULL; 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; } - _tmp13_ = self->priv->file_monitors; - _tmp14_ = file_path; - _tmp15_ = mpris_key; - gee_abstract_map_set ((GeeAbstractMap*) _tmp13_, _tmp14_, _tmp15_); - _tmp16_ = _data1_->monitor; - g_signal_connect_data (_tmp16_, "changed", (GCallback) ___lambda2__g_file_monitor_changed, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0); _g_object_unref0 (f); _g_free0 (file_path); _g_object_unref0 (desktop_info); - block1_data_unref (_data1_); - _data1_ = NULL; } @@ -550,24 +555,21 @@ static void music_player_bridge_relevant_desktop_file_changed (MusicPlayerBridge const gchar* _tmp5_; gboolean _tmp6_ = FALSE; GeeHashMap* _tmp8_; - GeeHashMap* _tmp9_; - const gchar* _tmp10_; - gpointer _tmp11_ = NULL; - gchar* _tmp12_; - gpointer _tmp13_ = NULL; - PlayerController* _tmp14_; - SettingsManager* _tmp15_; - GeeHashMap* _tmp16_; - const gchar* _tmp17_; - gpointer _tmp18_ = NULL; - gchar* _tmp19_; - GeeHashMap* _tmp20_; - GeeHashMap* _tmp21_; - const gchar* _tmp22_; - gpointer _tmp23_ = NULL; - gchar* _tmp24_; - GFileMonitor* _tmp25_; - GFileMonitor* _tmp26_; + const gchar* _tmp9_; + gpointer _tmp10_ = NULL; + gchar* mpris_key; + const gchar* _tmp11_; + const gchar* _tmp12_; + GeeHashMap* _tmp13_; + const gchar* _tmp14_; + gpointer _tmp15_ = NULL; + PlayerController* _tmp16_; + SettingsManager* _tmp17_; + const gchar* _tmp18_; + GeeHashMap* _tmp19_; + const gchar* _tmp20_; + GFileMonitor* _tmp21_; + GFileMonitor* _tmp22_; g_return_if_fail (self != NULL); g_return_if_fail (desktop_file != NULL); g_return_if_fail (monitor != NULL); @@ -580,7 +582,7 @@ static void music_player_bridge_relevant_desktop_file_changed (MusicPlayerBridge path = _tmp2_; _tmp3_ = path; if (_tmp3_ == NULL) { - g_warning ("music-player-bridge.vala:113: relevant_desktop_file_changed is returni" \ + g_warning ("music-player-bridge.vala:114: relevant_desktop_file_changed is returni" \ "ng a file with no path !"); _g_free0 (path); return; @@ -591,39 +593,36 @@ static void music_player_bridge_relevant_desktop_file_changed (MusicPlayerBridge if (!_tmp6_) { const gchar* _tmp7_; _tmp7_ = path; - g_warning ("music-player-bridge.vala:117: relevant_desktop_file_changed is returni" \ + g_warning ("music-player-bridge.vala:118: relevant_desktop_file_changed is returni" \ "ng a file which we know nothing about - %s", _tmp7_); _g_free0 (path); return; } - _tmp8_ = self->priv->registered_clients; - _tmp9_ = self->priv->file_monitors; - _tmp10_ = path; - _tmp11_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp9_, _tmp10_); - _tmp12_ = (gchar*) _tmp11_; - _tmp13_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp8_, _tmp12_); - _tmp14_ = (PlayerController*) _tmp13_; - player_controller_remove_from_menu (_tmp14_); - _g_object_unref0 (_tmp14_); - _g_free0 (_tmp12_); - _tmp15_ = self->priv->settings_manager; - _tmp16_ = self->priv->file_monitors; - _tmp17_ = path; - _tmp18_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp16_, _tmp17_); - _tmp19_ = (gchar*) _tmp18_; - settings_manager_remove_interested (_tmp15_, _tmp19_); - _g_free0 (_tmp19_); - _tmp20_ = self->priv->registered_clients; - _tmp21_ = self->priv->file_monitors; - _tmp22_ = path; - _tmp23_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp21_, _tmp22_); - _tmp24_ = (gchar*) _tmp23_; - gee_abstract_map_unset ((GeeAbstractMap*) _tmp20_, _tmp24_, NULL); - _g_free0 (_tmp24_); - _tmp25_ = monitor; - g_file_monitor_cancel (_tmp25_); - _tmp26_ = monitor; - g_object_unref ((GObject*) _tmp26_); + _tmp8_ = self->priv->file_monitors; + _tmp9_ = path; + _tmp10_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp8_, _tmp9_); + mpris_key = (gchar*) _tmp10_; + _tmp11_ = path; + _tmp12_ = mpris_key; + g_debug ("music-player-bridge.vala:124: file \"%s\" was removed; stopping monito" \ +"ring \"%s\"", _tmp11_, _tmp12_); + _tmp13_ = self->priv->registered_clients; + _tmp14_ = mpris_key; + _tmp15_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp13_, _tmp14_); + _tmp16_ = (PlayerController*) _tmp15_; + player_controller_remove_from_menu (_tmp16_); + _g_object_unref0 (_tmp16_); + _tmp17_ = self->priv->settings_manager; + _tmp18_ = mpris_key; + settings_manager_remove_interested (_tmp17_, _tmp18_); + _tmp19_ = self->priv->registered_clients; + _tmp20_ = mpris_key; + gee_abstract_map_unset ((GeeAbstractMap*) _tmp19_, _tmp20_, NULL); + _tmp21_ = monitor; + g_file_monitor_cancel (_tmp21_); + _tmp22_ = monitor; + g_object_unref ((GObject*) _tmp22_); + _g_free0 (mpris_key); _g_free0 (path); } @@ -734,7 +733,7 @@ void music_player_bridge_client_has_become_available (MusicPlayerBridge* self, c if (_tmp3_) { const gchar* _tmp4_; _tmp4_ = dbus_name; - g_warning ("music-player-bridge.vala:143: Client %s attempting to register without" \ + g_warning ("music-player-bridge.vala:147: Client %s attempting to register without" \ " desktop entry being set on the mpris root", _tmp4_); return; } @@ -748,12 +747,12 @@ void music_player_bridge_client_has_become_available (MusicPlayerBridge* self, c if (_tmp10_) { const gchar* _tmp11_; _tmp11_ = desktop; - g_debug ("music-player-bridge.vala:148: Client %s attempting to register but I'm" \ + g_debug ("music-player-bridge.vala:152: Client %s attempting to register but I'm" \ " afraid it is blacklisted", _tmp11_); return; } _tmp12_ = desktop; - g_debug ("music-player-bridge.vala:153: client_has_become_available %s", _tmp12_); + g_debug ("music-player-bridge.vala:157: client_has_become_available %s", _tmp12_); _tmp13_ = desktop; _tmp14_ = g_strconcat (_tmp13_, ".desktop", NULL); _tmp15_ = _tmp14_; @@ -765,7 +764,7 @@ void music_player_bridge_client_has_become_available (MusicPlayerBridge* self, c if (_tmp18_ == NULL) { const gchar* _tmp19_; _tmp19_ = desktop; - g_warning ("music-player-bridge.vala:156: Could not create app_info for path %s \n" \ + g_warning ("music-player-bridge.vala:160: Could not create app_info for path %s \n" \ " Getting out of here ", _tmp19_); _g_object_unref0 (app_info); return; @@ -799,7 +798,7 @@ void music_player_bridge_client_has_become_available (MusicPlayerBridge* self, c GAppInfo* _tmp43_; const gchar* _tmp44_; _tmp26_ = dbus_name; - g_debug ("music-player-bridge.vala:164: New client has registered that we have n" \ + g_debug ("music-player-bridge.vala:168: New client has registered that we have n" \ "ot seen before: %s", _tmp26_); _tmp27_ = self->priv->root_menu; _tmp28_ = app_info; @@ -818,7 +817,7 @@ void music_player_bridge_client_has_become_available (MusicPlayerBridge* self, c _tmp39_ = ctrl; gee_abstract_map_set ((GeeAbstractMap*) _tmp37_, _tmp38_, _tmp39_); _tmp40_ = desktop; - g_debug ("music-player-bridge.vala:173: Have not seen this %s before, new contro" \ + g_debug ("music-player-bridge.vala:177: Have not seen this %s before, new contro" \ "ller created.", _tmp40_); _tmp41_ = self->priv->settings_manager; _tmp42_ = desktop; @@ -826,7 +825,7 @@ void music_player_bridge_client_has_become_available (MusicPlayerBridge* self, c _tmp43_ = app_info; _tmp44_ = mpris_key; music_player_bridge_establish_file_monitoring (self, _tmp43_, _tmp44_); - g_debug ("music-player-bridge.vala:176: application added to the interested list"); + g_debug ("music-player-bridge.vala:180: application added to the interested list"); _g_object_unref0 (ctrl); } else { GeeHashMap* _tmp45_; @@ -874,7 +873,7 @@ void music_player_bridge_client_has_become_available (MusicPlayerBridge* self, c _tmp61_ = use_playlists; _tmp62_ = bool_to_string (_tmp61_); _tmp63_ = _tmp62_; - g_debug ("music-player-bridge.vala:182: Application has already registered - awa" \ + g_debug ("music-player-bridge.vala:186: Application has already registered - awa" \ "ken the hibernation: %s with playlists %s \n", _tmp60_, _tmp63_); _g_free0 (_tmp63_); } @@ -889,7 +888,7 @@ void music_player_bridge_client_has_vanished (MusicPlayerBridge* self, const gch g_return_if_fail (self != NULL); g_return_if_fail (mpris_root_interface != NULL); _tmp0_ = mpris_root_interface; - g_debug ("music-player-bridge.vala:188: MusicPlayerBridge -> client with dbus in" \ + g_debug ("music-player-bridge.vala:192: MusicPlayerBridge -> client with dbus in" \ "terface %s has vanished", _tmp0_); _tmp1_ = self->priv->root_menu; if (_tmp1_ != NULL) { @@ -902,7 +901,7 @@ void music_player_bridge_client_has_vanished (MusicPlayerBridge* self, const gch const gchar* _tmp7_; gboolean _tmp11_; _tmp2_ = mpris_root_interface; - g_debug ("music-player-bridge.vala:191: attempt to remove %s", _tmp2_); + g_debug ("music-player-bridge.vala:195: attempt to remove %s", _tmp2_); _tmp3_ = mpris_root_interface; _tmp4_ = g_strdup (_tmp3_); _tmp5_ = music_player_bridge_determine_key (_tmp4_); @@ -933,7 +932,7 @@ void music_player_bridge_client_has_vanished (MusicPlayerBridge* self, const gch player_controller_hibernate (_tmp15_); _g_object_unref0 (_tmp15_); _tmp16_ = mpris_key; - g_debug ("music-player-bridge.vala:195: Successively offlined client %s", _tmp16_); + g_debug ("music-player-bridge.vala:199: Successively offlined client %s", _tmp16_); } _g_free0 (mpris_key); } @@ -999,7 +998,7 @@ void music_player_bridge_enable_player_specific_items_for_client (MusicPlayerBri if (_tmp5_ == FALSE) { const gchar* _tmp6_; _tmp6_ = desktop_id; - g_warning ("music-player-bridge.vala:214: we don't have a client with desktop id %" \ + g_warning ("music-player-bridge.vala:218: we don't have a client with desktop id %" \ "s registered", _tmp6_); _g_free0 (mpris_key); return; @@ -1041,7 +1040,7 @@ void music_player_bridge_enable_track_specific_items_for_client (MusicPlayerBrid if (_tmp5_ == FALSE) { const gchar* _tmp6_; _tmp6_ = desktop_id; - g_warning ("music-player-bridge.vala:225: we don't have a client with desktop id %" \ + g_warning ("music-player-bridge.vala:229: we don't have a client with desktop id %" \ "s registered", _tmp6_); _g_free0 (mpris_key); return; @@ -1084,7 +1083,7 @@ static GAppInfo* music_player_bridge_create_app_info (const gchar* desktop) { if (_tmp5_) { const gchar* _tmp6_; _tmp6_ = desktop; - g_warning ("music-player-bridge.vala:235: Could not create a desktopappinfo instan" \ + g_warning ("music-player-bridge.vala:239: Could not create a desktopappinfo instan" \ "ce from app: %s", _tmp6_); result = NULL; _g_object_unref0 (info); @@ -1148,7 +1147,7 @@ static gchar* music_player_bridge_fetch_icon_name (const gchar* desktop) { GError* _error_ = NULL; _error_ = _inner_error_; _inner_error_ = NULL; - g_warning ("music-player-bridge.vala:251: Error loading keyfile - FileError"); + g_warning ("music-player-bridge.vala:255: Error loading keyfile - FileError"); result = NULL; _g_error_free0 (_error_); _g_key_file_free0 (desktop_keyfile); @@ -1161,7 +1160,7 @@ static gchar* music_player_bridge_fetch_icon_name (const gchar* desktop) { GError* _error_ = NULL; _error_ = _inner_error_; _inner_error_ = NULL; - g_warning ("music-player-bridge.vala:255: Error loading keyfile - KeyFileError"); + g_warning ("music-player-bridge.vala:259: Error loading keyfile - KeyFileError"); result = NULL; _g_error_free0 (_error_); _g_key_file_free0 (desktop_keyfile); @@ -1204,7 +1203,7 @@ static gchar* music_player_bridge_fetch_icon_name (const gchar* desktop) { GError* _error_ = NULL; _error_ = _inner_error_; _inner_error_ = NULL; - g_warning ("music-player-bridge.vala:264: Error trying to fetch the icon name from" \ + g_warning ("music-player-bridge.vala:268: Error trying to fetch the icon name from" \ " the keyfile"); result = NULL; _g_error_free0 (_error_); diff --git a/src/music-player-bridge.h b/src/music-player-bridge.h index 3a0cb33..7583b11 100644 --- a/src/music-player-bridge.h +++ b/src/music-player-bridge.h @@ -351,7 +351,7 @@ struct _MprisPlaylistsIface { void (*set_Orderings) (MprisPlaylists* self, gchar** value, int value_length1); guint32 (*get_PlaylistCount) (MprisPlaylists* self); void (*set_PlaylistCount) (MprisPlaylists* self, guint32 value); - void (*get_ActivePlaylist) (MprisPlaylists* self, ActivePlaylistContainer* value); + ActivePlaylistContainer* (*get_ActivePlaylist) (MprisPlaylists* self); void (*set_ActivePlaylist) (MprisPlaylists* self, ActivePlaylistContainer* value); }; @@ -532,7 +532,7 @@ gchar** mpris_playlists_get_Orderings (MprisPlaylists* self, int* result_length1 void mpris_playlists_set_Orderings (MprisPlaylists* self, gchar** value, int value_length1); guint32 mpris_playlists_get_PlaylistCount (MprisPlaylists* self); void mpris_playlists_set_PlaylistCount (MprisPlaylists* self, guint32 value); -void mpris_playlists_get_ActivePlaylist (MprisPlaylists* self, ActivePlaylistContainer* result); +ActivePlaylistContainer* mpris_playlists_get_ActivePlaylist (MprisPlaylists* self); void mpris_playlists_set_ActivePlaylist (MprisPlaylists* self, ActivePlaylistContainer* value); GType mpris2_watcher_get_type (void) G_GNUC_CONST; Mpris2Watcher* mpris2_watcher_new (void); diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index c2d6623..18f1c40 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -85,19 +85,20 @@ public class MusicPlayerBridge : GLib.Object DesktopAppInfo desktop_info = info as DesktopAppInfo; var file_path = desktop_info.get_filename (); File f = File.new_for_path (file_path); - FileMonitor monitor; try { - monitor = f.monitor (FileMonitorFlags.SEND_MOVED, null); + FileMonitor monitor = f.monitor (FileMonitorFlags.SEND_MOVED, null); + unowned FileMonitor weak_monitor = monitor; + monitor.changed.connect ((desktop_file, other_file, event_type) => { + this.relevant_desktop_file_changed (desktop_file, other_file, event_type, weak_monitor); + }); + monitor.ref(); // will be unref()ed by relevant_desktop_file_changed() + GLib.debug ("monitoring file '%s'", file_path); + this.file_monitors.set (file_path, mpris_key); } catch (Error e){ warning ("Unable to create a file monitor for %s", info.get_name()); return; } - this.file_monitors.set (file_path, mpris_key); - // Finally watch for a change. - monitor.changed.connect ((desktop_file, other_file, event_type) => { - this.relevant_desktop_file_changed (desktop_file, other_file, event_type, monitor); - }); } private void relevant_desktop_file_changed (File desktop_file, @@ -117,10 +118,13 @@ public class MusicPlayerBridge : GLib.Object warning ("relevant_desktop_file_changed is returning a file which we know nothing about - %s", path); return; - } - this.registered_clients[this.file_monitors[path]].remove_from_menu(); - this.settings_manager.remove_interested (this.file_monitors[path]); - this.registered_clients.unset (this.file_monitors[path]); + } + + var mpris_key = this.file_monitors[path]; + GLib.debug ("file \"%s\" was removed; stopping monitoring \"%s\"", path, mpris_key); + this.registered_clients[mpris_key].remove_from_menu(); + this.settings_manager.remove_interested (mpris_key); + this.registered_clients.unset (mpris_key); monitor.cancel (); monitor.unref(); } diff --git a/src/settings-manager.c b/src/settings-manager.c index ede9947..29e6f13 100644 --- a/src/settings-manager.c +++ b/src/settings-manager.c @@ -40,6 +40,9 @@ typedef struct _SettingsManagerClass SettingsManagerClass; typedef struct _SettingsManagerPrivate SettingsManagerPrivate; #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) #define _g_free0(var) (var = (g_free (var), NULL)) +#define _g_variant_type_free0(var) ((var == NULL) ? NULL : (var = (g_variant_type_free (var), NULL))) +#define _g_variant_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_unref (var), NULL))) +#define _g_variant_builder_unref0(var) ((var == NULL) ? NULL : (var = (g_variant_builder_unref (var), NULL))) struct _SettingsManager { GObject parent_instance; @@ -70,7 +73,6 @@ static gboolean _vala_string_array_contains (gchar** stack, int stack_length, gc void settings_manager_clear_list (SettingsManager* self); void settings_manager_remove_interested (SettingsManager* self, const gchar* app_desktop_name); void settings_manager_add_interested (SettingsManager* self, const gchar* app_desktop_name); -static void _vala_array_add1 (gchar*** array, int* length, int* size, gchar* value); static void settings_manager_on_blacklist_event (SettingsManager* self); static void g_cclosure_user_marshal_VOID__BOXED_INT (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data); static GObject * settings_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties); @@ -223,152 +225,143 @@ void settings_manager_clear_list (SettingsManager* self) { void settings_manager_remove_interested (SettingsManager* self, const gchar* app_desktop_name) { - GSettings* _tmp0_; - gchar** _tmp1_; - gchar** _tmp2_ = NULL; - gchar** already_interested; - gint already_interested_length1; - gint _already_interested_size_; - GeeArrayList* _tmp3_; - GeeArrayList* list; - gchar** _tmp4_; - gint _tmp4__length1; - GSettings* _tmp10_; - GeeArrayList* _tmp11_; - gint _tmp12_ = 0; - gpointer* _tmp13_ = NULL; - gchar** _tmp14_; - gint _tmp14__length1; - GSettings* _tmp15_; + static const char key[] = "interested-media-players"; + GVariantType* _tmp0_; + GVariantType* _tmp1_; + GVariantBuilder* _tmp2_; + GVariantBuilder* _tmp3_; + GVariantBuilder* players; + GSettings* _tmp4_; + gchar** _tmp5_; + gchar** _tmp6_ = NULL; + GSettings* _tmp12_; + GVariantBuilder* _tmp13_; + GVariant* _tmp14_ = NULL; + GVariant* _tmp15_; + GSettings* _tmp16_; g_return_if_fail (self != NULL); g_return_if_fail (app_desktop_name != NULL); - _tmp0_ = self->priv->settings; - _tmp2_ = _tmp1_ = g_settings_get_strv (_tmp0_, "interested-media-players"); - already_interested = _tmp2_; - already_interested_length1 = _vala_array_length (_tmp1_); - _already_interested_size_ = already_interested_length1; - _tmp3_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, g_free, NULL); - list = _tmp3_; - _tmp4_ = already_interested; - _tmp4__length1 = already_interested_length1; + _tmp0_ = g_variant_type_new ("as"); + _tmp1_ = _tmp0_; + _tmp2_ = g_variant_builder_new (_tmp1_); + _tmp3_ = _tmp2_; + _g_variant_type_free0 (_tmp1_); + players = _tmp3_; + _tmp4_ = self->priv->settings; + _tmp6_ = _tmp5_ = g_settings_get_strv (_tmp4_, key); { - gchar** s_collection = NULL; - gint s_collection_length1 = 0; - gint _s_collection_size_ = 0; - gint s_it = 0; - s_collection = _tmp4_; - s_collection_length1 = _tmp4__length1; - for (s_it = 0; s_it < _tmp4__length1; s_it = s_it + 1) { - gchar* _tmp5_; - gchar* s = NULL; - _tmp5_ = g_strdup (s_collection[s_it]); - s = _tmp5_; + gchar** player_collection = NULL; + gint player_collection_length1 = 0; + gint _player_collection_size_ = 0; + gint player_it = 0; + player_collection = _tmp6_; + player_collection_length1 = _vala_array_length (_tmp5_); + for (player_it = 0; player_it < _vala_array_length (_tmp5_); player_it = player_it + 1) { + gchar* _tmp7_; + gchar* player = NULL; + _tmp7_ = g_strdup (player_collection[player_it]); + player = _tmp7_; { - const gchar* _tmp6_; - const gchar* _tmp7_; - GeeArrayList* _tmp8_; + const gchar* _tmp8_; const gchar* _tmp9_; - _tmp6_ = s; - _tmp7_ = app_desktop_name; - if (g_strcmp0 (_tmp6_, _tmp7_) == 0) { - _g_free0 (s); - continue; + _tmp8_ = player; + _tmp9_ = app_desktop_name; + if (g_strcmp0 (_tmp8_, _tmp9_) != 0) { + GVariantBuilder* _tmp10_; + const gchar* _tmp11_; + _tmp10_ = players; + _tmp11_ = player; + g_variant_builder_add (_tmp10_, "s", _tmp11_, NULL); } - _tmp8_ = list; - _tmp9_ = s; - gee_abstract_collection_add ((GeeAbstractCollection*) _tmp8_, _tmp9_); - _g_free0 (s); + _g_free0 (player); } } + player_collection = (_vala_array_free (player_collection, player_collection_length1, (GDestroyNotify) g_free), NULL); } - _tmp10_ = self->priv->settings; - _tmp11_ = list; - _tmp13_ = gee_abstract_collection_to_array ((GeeAbstractCollection*) _tmp11_, &_tmp12_); - _tmp14_ = _tmp13_; - _tmp14__length1 = _tmp12_; - g_settings_set_strv (_tmp10_, "interested-media-players", _tmp14_); - _tmp14_ = (_vala_array_free (_tmp14_, _tmp14__length1, (GDestroyNotify) g_free), NULL); - _tmp15_ = self->priv->settings; - g_settings_apply (_tmp15_); - _g_object_unref0 (list); - already_interested = (_vala_array_free (already_interested, already_interested_length1, (GDestroyNotify) g_free), NULL); -} - - -static void _vala_array_add1 (gchar*** array, int* length, int* size, gchar* value) { - if ((*length) == (*size)) { - *size = (*size) ? (2 * (*size)) : 4; - *array = g_renew (gchar*, *array, (*size) + 1); - } - (*array)[(*length)++] = value; - (*array)[*length] = NULL; + _tmp12_ = self->priv->settings; + _tmp13_ = players; + _tmp14_ = g_variant_builder_end (_tmp13_); + _tmp15_ = g_variant_ref_sink (_tmp14_); + g_settings_set_value (_tmp12_, key, _tmp15_); + _g_variant_unref0 (_tmp15_); + _tmp16_ = self->priv->settings; + g_settings_apply (_tmp16_); + _g_variant_builder_unref0 (players); } void settings_manager_add_interested (SettingsManager* self, const gchar* app_desktop_name) { - GSettings* _tmp0_; - gchar** _tmp1_; - gchar** _tmp2_ = NULL; - gchar** already_interested; - gint already_interested_length1; - gint _already_interested_size_; - gchar** _tmp3_; - gint _tmp3__length1; - gchar** _tmp7_; - gint _tmp7__length1; - const gchar* _tmp8_; - gchar* _tmp9_; - GSettings* _tmp10_; - gchar** _tmp11_; - gint _tmp11__length1; - GSettings* _tmp12_; + static const char key[] = "interested-media-players"; + GVariantType* _tmp0_; + GVariantType* _tmp1_; + GVariantBuilder* _tmp2_; + GVariantBuilder* _tmp3_; + GVariantBuilder* players; + GSettings* _tmp4_; + gchar** _tmp5_; + gchar** _tmp6_ = NULL; + GVariantBuilder* _tmp12_; + const gchar* _tmp13_; + GSettings* _tmp14_; + GVariantBuilder* _tmp15_; + GVariant* _tmp16_ = NULL; + GVariant* _tmp17_; + GSettings* _tmp18_; g_return_if_fail (self != NULL); g_return_if_fail (app_desktop_name != NULL); - _tmp0_ = self->priv->settings; - _tmp2_ = _tmp1_ = g_settings_get_strv (_tmp0_, "interested-media-players"); - already_interested = _tmp2_; - already_interested_length1 = _vala_array_length (_tmp1_); - _already_interested_size_ = already_interested_length1; - _tmp3_ = already_interested; - _tmp3__length1 = already_interested_length1; + _tmp0_ = g_variant_type_new ("as"); + _tmp1_ = _tmp0_; + _tmp2_ = g_variant_builder_new (_tmp1_); + _tmp3_ = _tmp2_; + _g_variant_type_free0 (_tmp1_); + players = _tmp3_; + _tmp4_ = self->priv->settings; + _tmp6_ = _tmp5_ = g_settings_get_strv (_tmp4_, key); { - gchar** s_collection = NULL; - gint s_collection_length1 = 0; - gint _s_collection_size_ = 0; - gint s_it = 0; - s_collection = _tmp3_; - s_collection_length1 = _tmp3__length1; - for (s_it = 0; s_it < _tmp3__length1; s_it = s_it + 1) { - gchar* _tmp4_; - gchar* s = NULL; - _tmp4_ = g_strdup (s_collection[s_it]); - s = _tmp4_; + gchar** player_collection = NULL; + gint player_collection_length1 = 0; + gint _player_collection_size_ = 0; + gint player_it = 0; + player_collection = _tmp6_; + player_collection_length1 = _vala_array_length (_tmp5_); + for (player_it = 0; player_it < _vala_array_length (_tmp5_); player_it = player_it + 1) { + gchar* _tmp7_; + gchar* player = NULL; + _tmp7_ = g_strdup (player_collection[player_it]); + player = _tmp7_; { - const gchar* _tmp5_; - const gchar* _tmp6_; - _tmp5_ = s; - _tmp6_ = app_desktop_name; - if (g_strcmp0 (_tmp5_, _tmp6_) == 0) { - _g_free0 (s); - already_interested = (_vala_array_free (already_interested, already_interested_length1, (GDestroyNotify) g_free), NULL); + const gchar* _tmp8_; + const gchar* _tmp9_; + GVariantBuilder* _tmp10_; + const gchar* _tmp11_; + _tmp8_ = player; + _tmp9_ = app_desktop_name; + if (g_strcmp0 (_tmp8_, _tmp9_) == 0) { + _g_free0 (player); + player_collection = (_vala_array_free (player_collection, player_collection_length1, (GDestroyNotify) g_free), NULL); + _g_variant_builder_unref0 (players); return; } - _g_free0 (s); + _tmp10_ = players; + _tmp11_ = player; + g_variant_builder_add (_tmp10_, "s", _tmp11_, NULL); + _g_free0 (player); } } + player_collection = (_vala_array_free (player_collection, player_collection_length1, (GDestroyNotify) g_free), NULL); } - _tmp7_ = already_interested; - _tmp7__length1 = already_interested_length1; - _tmp8_ = app_desktop_name; - _tmp9_ = g_strdup (_tmp8_); - _vala_array_add1 (&already_interested, &already_interested_length1, &_already_interested_size_, _tmp9_); - _tmp10_ = self->priv->settings; - _tmp11_ = already_interested; - _tmp11__length1 = already_interested_length1; - g_settings_set_strv (_tmp10_, "interested-media-players", _tmp11_); - _tmp12_ = self->priv->settings; - g_settings_apply (_tmp12_); - already_interested = (_vala_array_free (already_interested, already_interested_length1, (GDestroyNotify) g_free), NULL); + _tmp12_ = players; + _tmp13_ = app_desktop_name; + g_variant_builder_add (_tmp12_, "s", _tmp13_, NULL); + _tmp14_ = self->priv->settings; + _tmp15_ = players; + _tmp16_ = g_variant_builder_end (_tmp15_); + _tmp17_ = g_variant_ref_sink (_tmp16_); + g_settings_set_value (_tmp14_, key, _tmp17_); + _g_variant_unref0 (_tmp17_); + _tmp18_ = self->priv->settings; + g_settings_apply (_tmp18_); + _g_variant_builder_unref0 (players); } diff --git a/src/settings-manager.vala b/src/settings-manager.vala index 034cd03..d57241e 100644 --- a/src/settings-manager.vala +++ b/src/settings-manager.vala @@ -58,27 +58,31 @@ public class SettingsManager : GLib.Object public void remove_interested (string app_desktop_name) { - var already_interested = this.settings.get_strv ("interested-media-players"); - var list = new ArrayList(); + const string key = "interested-media-players"; + var players = new GLib.VariantBuilder (new VariantType ("as")); // array of strings - foreach (var s in already_interested){ - if (s == app_desktop_name) continue; - list.add (s); + foreach (var player in this.settings.get_strv (key)) { + if (player != app_desktop_name) + players.add ("s", player); } - this.settings.set_strv("interested-media-players", - list.to_array()); - this.settings.apply(); + + this.settings.set_value(key, players.end()); + this.settings.apply(); } public void add_interested (string app_desktop_name) { - var already_interested = this.settings.get_strv ("interested-media-players"); - foreach (var s in already_interested){ - if ( s == app_desktop_name ) return; + const string key = "interested-media-players"; + var players = new GLib.VariantBuilder (new VariantType ("as")); // array of strings + + foreach (var player in this.settings.get_strv (key)) { + if (player == app_desktop_name) + return; + players.add ("s", player); } - already_interested += (app_desktop_name); - this.settings.set_strv( "interested-media-players", - already_interested ); + + players.add ("s", app_desktop_name); + this.settings.set_value(key, players.end()); this.settings.apply(); } diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 7cad2bc..5e004cb 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -82,11 +82,11 @@ static void sound_service_dbus_finalize (GObject *object); static void show_sound_settings_dialog (DbusmenuMenuitem *mi, gpointer user_data); static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self, - gchar* player_name, + const gchar* player_name, gboolean blacklist); static gboolean sound_service_dbus_is_blacklisted (SoundServiceDbus* self, - gchar* player_name); + const gchar* player_name); G_DEFINE_TYPE (SoundServiceDbus, sound_service_dbus, G_TYPE_OBJECT); @@ -315,8 +315,8 @@ bus_method_call (GDBusConnection * connection, } else if (g_strcmp0(method, "BlacklistMediaPlayer") == 0) { gboolean blacklist; - gchar* player_name; - g_variant_get (params, "(sb)", &player_name, &blacklist); + const gchar* player_name; + g_variant_get (params, "(&sb)", &player_name, &blacklist); g_debug ("BlacklistMediaPlayer - bool %i", blacklist); g_debug ("BlacklistMediaPlayer - name %s", player_name); @@ -326,8 +326,8 @@ bus_method_call (GDBusConnection * connection, retval = g_variant_new ("(b)", result); } else if (g_strcmp0(method, "IsBlacklisted") == 0) { - gchar* player_name; - g_variant_get (params, "(s)", &player_name); + const gchar* player_name; + g_variant_get (params, "(&s)", &player_name); g_debug ("IsBlacklisted - name %s", player_name); gboolean result = sound_service_dbus_is_blacklisted (service, @@ -374,7 +374,7 @@ bus_method_call (GDBusConnection * connection, TODO - Works nicely but refactor into at least two different methods **/ static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self, - gchar* player_name, + const gchar* player_name, gboolean blacklist) { g_return_val_if_fail (player_name != NULL, FALSE); @@ -457,7 +457,7 @@ static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self, } static gboolean sound_service_dbus_is_blacklisted (SoundServiceDbus *self, - gchar *player_name) + const gchar *player_name) { GSettings *our_settings; GVariant *the_black_list; -- cgit v1.2.3