diff options
Diffstat (limited to 'src/playlists-menu-item.c')
-rw-r--r-- | src/playlists-menu-item.c | 225 |
1 files changed, 84 insertions, 141 deletions
diff --git a/src/playlists-menu-item.c b/src/playlists-menu-item.c index ced54cf..ed78fc8 100644 --- a/src/playlists-menu-item.c +++ b/src/playlists-menu-item.c @@ -34,7 +34,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <stdlib.h> #include <string.h> #include <glib/gi18n-lib.h> -#include <gio/gio.h> #define TYPE_PLAYER_ITEM (player_item_get_type ()) @@ -155,7 +154,7 @@ void playlists_menuitem_update (PlaylistsMenuitem* self, PlaylistDetails* playli static Block1Data* block1_data_ref (Block1Data* _data1_); static void block1_data_unref (Block1Data* _data1_); static gboolean playlists_menuitem_already_observed (PlaylistsMenuitem* self, PlaylistDetails* new_detail); -static gchar* playlists_menuitem_parse_icon_path (PlaylistsMenuitem* self, const gchar* path); +static gboolean playlists_menuitem_is_video_related (PlaylistsMenuitem* self, PlaylistDetails* new_detail); static void _lambda1_ (Block1Data* _data1_); static void playlists_menuitem_submenu_item_activated (PlaylistsMenuitem* self, gint menu_item_id); static void __lambda1__dbusmenu_menuitem_item_activated (DbusmenuMenuitem* _sender, guint timestamp, gpointer self); @@ -167,9 +166,6 @@ void mpris2_controller_activate_playlist (Mpris2Controller* self, const char* pa GeeHashSet* playlists_menuitem_attributes_format (void); static GObject * playlists_menuitem_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties); static void playlists_menuitem_finalize (GObject* obj); -static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func); -static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func); -static gint _vala_array_length (gpointer array); PlaylistsMenuitem* playlists_menuitem_construct (GType object_type, PlayerController* parent) { @@ -231,37 +227,38 @@ void playlists_menuitem_update (PlaylistsMenuitem* self, PlaylistDetails* playli detail = _tmp0_; { Block1Data* _data1_; - gboolean _tmp2_; - DbusmenuMenuitem* _tmp3_ = NULL; - gchar* _tmp4_ = NULL; - gchar* _result_; - gint _tmp5_; + gboolean _tmp2_ = FALSE; + gboolean _tmp3_; + DbusmenuMenuitem* _tmp5_ = NULL; + gint _tmp6_; _data1_ = g_slice_new0 (Block1Data); _data1_->_ref_count_ = 1; _data1_->self = g_object_ref (self); - _tmp2_ = playlists_menuitem_already_observed (self, &detail); + _tmp3_ = playlists_menuitem_already_observed (self, &detail); + if (_tmp3_) { + _tmp2_ = TRUE; + } else { + gboolean _tmp4_; + _tmp4_ = playlists_menuitem_is_video_related (self, &detail); + _tmp2_ = _tmp4_; + } if (_tmp2_) { playlist_details_destroy (&detail); block1_data_unref (_data1_); _data1_ = NULL; continue; } - _tmp3_ = dbusmenu_menuitem_new (); - _data1_->menuitem = _tmp3_; + _tmp5_ = dbusmenu_menuitem_new (); + _data1_->menuitem = _tmp5_; dbusmenu_menuitem_property_set (_data1_->menuitem, DBUSMENU_MENUITEM_PROP_LABEL, detail.name); - _tmp4_ = playlists_menuitem_parse_icon_path (self, detail.icon_path); - _result_ = _tmp4_; - if (_result_ != NULL) { - dbusmenu_menuitem_property_set (_data1_->menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME, (const gchar*) _result_); - } + dbusmenu_menuitem_property_set (_data1_->menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME, "playlist-symbolic"); dbusmenu_menuitem_property_set (_data1_->menuitem, DBUSMENU_PLAYLIST_MENUITEM_PATH, (const gchar*) detail.path); dbusmenu_menuitem_property_set_bool (_data1_->menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); dbusmenu_menuitem_property_set_bool (_data1_->menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); g_signal_connect_data (_data1_->menuitem, "item-activated", (GCallback) __lambda1__dbusmenu_menuitem_item_activated, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0); - _tmp5_ = dbusmenu_menuitem_get_id (_data1_->menuitem); - gee_abstract_map_set ((GeeAbstractMap*) self->priv->current_playlists, GINT_TO_POINTER (_tmp5_), _data1_->menuitem); + _tmp6_ = dbusmenu_menuitem_get_id (_data1_->menuitem); + gee_abstract_map_set ((GeeAbstractMap*) self->priv->current_playlists, GINT_TO_POINTER (_tmp6_), _data1_->menuitem); dbusmenu_menuitem_child_append (self->root_item, _data1_->menuitem); - _g_free0 (_result_); playlist_details_destroy (&detail); block1_data_unref (_data1_); _data1_ = NULL; @@ -269,28 +266,28 @@ void playlists_menuitem_update (PlaylistsMenuitem* self, PlaylistDetails* playli } } { - GeeCollection* _tmp6_ = NULL; - GeeCollection* _tmp7_; - GeeIterator* _tmp8_ = NULL; - GeeIterator* _tmp9_; + GeeCollection* _tmp7_ = NULL; + GeeCollection* _tmp8_; + GeeIterator* _tmp9_ = NULL; + GeeIterator* _tmp10_; GeeIterator* _item_it; - _tmp6_ = gee_map_get_values ((GeeMap*) self->priv->current_playlists); - _tmp7_ = _tmp6_; - _tmp8_ = gee_iterable_iterator ((GeeIterable*) _tmp7_); - _tmp9_ = _tmp8_; - _g_object_unref0 (_tmp7_); - _item_it = _tmp9_; + _tmp7_ = gee_map_get_values ((GeeMap*) self->priv->current_playlists); + _tmp8_ = _tmp7_; + _tmp9_ = gee_iterable_iterator ((GeeIterable*) _tmp8_); + _tmp10_ = _tmp9_; + _g_object_unref0 (_tmp8_); + _item_it = _tmp10_; while (TRUE) { - gboolean _tmp10_; - gpointer _tmp11_ = NULL; + gboolean _tmp11_; + gpointer _tmp12_ = NULL; DbusmenuMenuitem* item; gboolean within; - _tmp10_ = gee_iterator_next (_item_it); - if (!_tmp10_) { + _tmp11_ = gee_iterator_next (_item_it); + if (!_tmp11_) { break; } - _tmp11_ = gee_iterator_get (_item_it); - item = (DbusmenuMenuitem*) _tmp11_; + _tmp12_ = gee_iterator_get (_item_it); + item = (DbusmenuMenuitem*) _tmp12_; within = FALSE; { PlaylistDetails* detail_collection; @@ -299,16 +296,16 @@ void playlists_menuitem_update (PlaylistsMenuitem* self, PlaylistDetails* playli detail_collection = playlists; detail_collection_length1 = playlists_length1; for (detail_it = 0; detail_it < playlists_length1; detail_it = detail_it + 1) { - PlaylistDetails _tmp12_; - PlaylistDetails _tmp13_ = {0}; + PlaylistDetails _tmp13_; + PlaylistDetails _tmp14_ = {0}; PlaylistDetails detail; - playlist_details_copy (&detail_collection[detail_it], &_tmp13_); - _tmp12_ = _tmp13_; - detail = _tmp12_; + playlist_details_copy (&detail_collection[detail_it], &_tmp14_); + _tmp13_ = _tmp14_; + detail = _tmp13_; { - const gchar* _tmp14_ = NULL; - _tmp14_ = dbusmenu_menuitem_property_get (item, DBUSMENU_PLAYLIST_MENUITEM_PATH); - if (g_strcmp0 (detail.path, _tmp14_) == 0) { + const gchar* _tmp15_ = NULL; + _tmp15_ = dbusmenu_menuitem_property_get (item, DBUSMENU_PLAYLIST_MENUITEM_PATH); + if (g_strcmp0 (detail.path, _tmp15_) == 0) { within = TRUE; playlist_details_destroy (&detail); break; @@ -318,14 +315,14 @@ void playlists_menuitem_update (PlaylistsMenuitem* self, PlaylistDetails* playli } } if (within == FALSE) { - const gchar* _tmp15_ = NULL; const gchar* _tmp16_ = NULL; - _tmp15_ = dbusmenu_menuitem_property_get (self->root_item, DBUSMENU_PLAYLIST_MENUITEM_PATH); - _tmp16_ = dbusmenu_menuitem_property_get (item, DBUSMENU_PLAYLIST_MENUITEM_PATH); - if (g_strcmp0 (_tmp15_, _tmp16_) == 0) { - const gchar* _tmp17_ = NULL; - _tmp17_ = _ ("Choose Playlist"); - dbusmenu_menuitem_property_set (self->root_item, DBUSMENU_MENUITEM_PROP_LABEL, _tmp17_); + const gchar* _tmp17_ = NULL; + _tmp16_ = dbusmenu_menuitem_property_get (self->root_item, DBUSMENU_PLAYLIST_MENUITEM_PATH); + _tmp17_ = dbusmenu_menuitem_property_get (item, DBUSMENU_PLAYLIST_MENUITEM_PATH); + if (g_strcmp0 (_tmp16_, _tmp17_) == 0) { + const gchar* _tmp18_ = NULL; + _tmp18_ = _ ("Choose Playlist"); + dbusmenu_menuitem_property_set (self->root_item, DBUSMENU_MENUITEM_PROP_LABEL, _tmp18_); } dbusmenu_menuitem_child_delete (self->root_item, item); } @@ -336,55 +333,8 @@ void playlists_menuitem_update (PlaylistsMenuitem* self, PlaylistDetails* playli } -static gchar* playlists_menuitem_parse_icon_path (PlaylistsMenuitem* self, const gchar* path) { - gchar* result = NULL; - GFile* _tmp0_ = NULL; - GFile* icon_file; - gchar* _tmp1_ = NULL; - gchar* _tmp2_; - gboolean _tmp3_; - gchar* _tmp4_ = NULL; - gchar* _tmp5_; - gchar** _tmp6_; - gchar** _tmp7_ = NULL; - gchar** _tmp8_; - gint _tmp8__length1; - gchar* _tmp9_; - gchar* _tmp10_; - g_return_val_if_fail (self != NULL, NULL); - g_return_val_if_fail (path != NULL, NULL); - if (g_strcmp0 (path, "") == 0) { - result = NULL; - return result; - } - _tmp0_ = g_file_new_for_path (path); - icon_file = _tmp0_; - _tmp1_ = g_file_get_path (icon_file); - _tmp2_ = _tmp1_; - _tmp3_ = _tmp2_ == NULL; - _g_free0 (_tmp2_); - if (_tmp3_) { - result = NULL; - _g_object_unref0 (icon_file); - return result; - } - _tmp4_ = g_file_get_basename (icon_file); - _tmp5_ = _tmp4_; - _tmp7_ = _tmp6_ = g_strsplit (_tmp5_, ".", 0); - _tmp8_ = _tmp7_; - _tmp8__length1 = _vala_array_length (_tmp6_); - _tmp9_ = g_strdup (_tmp8_[0]); - _tmp10_ = _tmp9_; - _tmp8_ = (_vala_array_free (_tmp8_, _tmp8__length1, (GDestroyNotify) g_free), NULL); - _g_free0 (_tmp5_); - result = _tmp10_; - _g_object_unref0 (icon_file); - return result; -} - - void playlists_menuitem_update_individual_playlist (PlaylistsMenuitem* self, PlaylistDetails* new_detail) { - const gchar* _tmp8_ = NULL; + const gchar* _tmp7_ = NULL; g_return_if_fail (self != NULL); { GeeCollection* _tmp0_ = NULL; @@ -411,22 +361,14 @@ void playlists_menuitem_update_individual_playlist (PlaylistsMenuitem* self, Pla item = (DbusmenuMenuitem*) _tmp5_; _tmp6_ = dbusmenu_menuitem_property_get (item, DBUSMENU_PLAYLIST_MENUITEM_PATH); if (g_strcmp0 ((*new_detail).path, _tmp6_) == 0) { - gchar* _tmp7_ = NULL; - gchar* _result_; dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_LABEL, (*new_detail).name); - _tmp7_ = playlists_menuitem_parse_icon_path (self, (*new_detail).icon_path); - _result_ = _tmp7_; - if (_result_ != NULL) { - dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_ICON_NAME, _result_); - } - _g_free0 (_result_); } _g_object_unref0 (item); } _g_object_unref0 (_item_it); } - _tmp8_ = dbusmenu_menuitem_property_get (self->root_item, DBUSMENU_PLAYLIST_MENUITEM_PATH); - if (g_strcmp0 (_tmp8_, (*new_detail).path) == 0) { + _tmp7_ = dbusmenu_menuitem_property_get (self->root_item, DBUSMENU_PLAYLIST_MENUITEM_PATH); + if (g_strcmp0 (_tmp7_, (*new_detail).path) == 0) { dbusmenu_menuitem_property_set (self->root_item, DBUSMENU_MENUITEM_PROP_LABEL, (*new_detail).name); } } @@ -480,6 +422,37 @@ static gboolean playlists_menuitem_already_observed (PlaylistsMenuitem* self, Pl } +static gboolean string_contains (const gchar* self, const gchar* needle) { + gboolean result = FALSE; + gchar* _tmp0_ = NULL; + g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (needle != NULL, FALSE); + _tmp0_ = strstr ((gchar*) self, (gchar*) needle); + result = _tmp0_ != NULL; + return result; +} + + +static gboolean playlists_menuitem_is_video_related (PlaylistsMenuitem* self, PlaylistDetails* new_detail) { + gboolean result = FALSE; + gchar* _tmp0_; + gchar* location; + gboolean _tmp1_; + g_return_val_if_fail (self != NULL, FALSE); + _tmp0_ = g_strdup ((const gchar*) (*new_detail).path); + location = _tmp0_; + _tmp1_ = string_contains (location, "/VideoLibrarySource/"); + if (_tmp1_) { + result = TRUE; + _g_free0 (location); + return result; + } + result = FALSE; + _g_free0 (location); + return result; +} + + void playlists_menuitem_active_playlist_update (PlaylistsMenuitem* self, PlaylistDetails* detail) { gchar* _tmp0_; gchar* update; @@ -509,7 +482,7 @@ static void playlists_menuitem_submenu_item_activated (PlaylistsMenuitem* self, g_return_if_fail (self != NULL); _tmp0_ = gee_abstract_map_has_key ((GeeAbstractMap*) self->priv->current_playlists, GINT_TO_POINTER (menu_item_id)); if (!_tmp0_) { - g_warning ("playlists-menu-item.vala:133: item %i was activated but we don't have " \ + g_warning ("playlists-menu-item.vala:126: item %i was activated but we don't have " \ "a corresponding playlist", menu_item_id); return; } @@ -592,34 +565,4 @@ GType playlists_menuitem_get_type (void) { } -static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) { - if ((array != NULL) && (destroy_func != NULL)) { - int i; - for (i = 0; i < array_length; i = i + 1) { - if (((gpointer*) array)[i] != NULL) { - destroy_func (((gpointer*) array)[i]); - } - } - } -} - - -static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) { - _vala_array_destroy (array, array_length, destroy_func); - g_free (array); -} - - -static gint _vala_array_length (gpointer array) { - int length; - length = 0; - if (array) { - while (((gpointer*) array)[length]) { - length++; - } - } - return length; -} - - |