static void impl_save_contents_to_xml (RBPlaylistSource *source, xmlNodePtr node) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source); GtkTreeIter iter; xmlSetProp (node, RB_PLAYLIST_TYPE, RB_PLAYLIST_STATIC); if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->base_model), &iter)) return; do { xmlNodePtr child_node = xmlNewChild (node, NULL, RB_PLAYLIST_LOCATION, NULL); RhythmDBEntry *entry; xmlChar *encoded; const char *location; gtk_tree_model_get (GTK_TREE_MODEL (priv->base_model), &iter, 0, &entry, -1); location = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION); encoded = xmlEncodeEntitiesReentrant (NULL, BAD_CAST location); xmlNodeSetContent (child_node, encoded); g_free (encoded); rhythmdb_entry_unref (entry); } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->base_model), &iter)); }
static void rb_static_playlist_source_add_location_internal (RBStaticPlaylistSource *source, const char *location, gint index) { RhythmDB *db; RhythmDBEntry *entry; RBPlaylistSource *psource = RB_PLAYLIST_SOURCE (source); if (rb_playlist_source_location_in_map (psource, location)) return; db = rb_playlist_source_get_db (psource); entry = rhythmdb_entry_lookup_by_location (db, location); if (entry) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source); if (_rb_source_check_entry_type (RB_SOURCE (source), entry)) { rhythmdb_entry_ref (entry); rhythmdb_query_model_add_entry (priv->base_model, entry, index); rhythmdb_entry_unref (entry); } } rb_playlist_source_add_to_map (psource, location); rb_playlist_source_mark_dirty (psource); }
static GList * impl_get_property_views (RBSource *source) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source); GList *ret; ret = rb_library_browser_get_property_views (priv->browser); return ret; }
/** * rb_static_playlist_source_move_entry: * @source: an #RBStaticPlaylistSource * @entry: the entry to move * @index: new location for the entry * * Moves an entry within the playlist. */ void rb_static_playlist_source_move_entry (RBStaticPlaylistSource *source, RhythmDBEntry *entry, gint index) { RBPlaylistSource *psource = RB_PLAYLIST_SOURCE (source); RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source); rhythmdb_query_model_move_entry (priv->base_model, entry, index); rb_playlist_source_mark_dirty (psource); }
static void impl_browser_toggled (RBSource *source, gboolean enabled) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source); priv->browser_shown = enabled; if (enabled) gtk_widget_show (GTK_WIDGET (priv->browser)); else gtk_widget_hide (GTK_WIDGET (priv->browser)); }
static void rb_static_playlist_source_finalize (GObject *object) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (object); rb_debug ("Finalizing static playlist source %p", object); if (priv->search_query != NULL) { rhythmdb_query_free (priv->search_query); priv->search_query = NULL; } G_OBJECT_CLASS (rb_static_playlist_source_parent_class)->finalize (object); }
static void rb_static_playlist_source_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (object); switch (prop_id) { case PROP_BASE_QUERY_MODEL: g_value_set_object (value, priv->base_model); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static GPtrArray * construct_query_from_selection (RBStaticPlaylistSource *source) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source); RBPlaylistSource *psource = RB_PLAYLIST_SOURCE (source); RhythmDB *db = rb_playlist_source_get_db (RB_PLAYLIST_SOURCE (psource)); GPtrArray *query = NULL; query = g_ptr_array_new(); if (priv->search_query != NULL) { rhythmdb_query_append (db, query, RHYTHMDB_QUERY_SUBQUERY, priv->search_query, RHYTHMDB_QUERY_END); } return query; }
static void impl_search (RBSource *source, RBSourceSearch *search, const char *cur_text, const char *new_text) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source); RhythmDB *db; if (search == NULL) { search = priv->default_search; } /* replace our search query */ if (priv->search_query != NULL) { rhythmdb_query_free (priv->search_query); priv->search_query = NULL; } db = rb_playlist_source_get_db (RB_PLAYLIST_SOURCE (source)); priv->search_query = rb_source_search_create_query (search, db, new_text); rb_static_playlist_source_do_query (RB_STATIC_PLAYLIST_SOURCE (source)); }
static void impl_reset_filters (RBSource *source) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source); gboolean changed = FALSE; if (rb_library_browser_reset (priv->browser)) changed = TRUE; if (priv->search_query != NULL) { changed = TRUE; rhythmdb_query_free (priv->search_query); priv->search_query = NULL; } if (changed) { rb_static_playlist_source_do_query (RB_STATIC_PLAYLIST_SOURCE (source)); rb_source_notify_filter_changed (source); } }
static void rb_static_playlist_source_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (object); switch (prop_id) { case PROP_SHOW_BROWSER: if (g_value_get_boolean (value)) gtk_widget_show (GTK_WIDGET (priv->browser)); else gtk_widget_hide (GTK_WIDGET (priv->browser)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void rb_static_playlist_source_do_query (RBStaticPlaylistSource *source) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source); RBPlaylistSource *psource = RB_PLAYLIST_SOURCE (source); RhythmDB *db = rb_playlist_source_get_db (psource); GPtrArray *query; if (priv->filter_model != NULL) { g_object_unref (priv->filter_model); } priv->filter_model = rhythmdb_query_model_new_empty (db); g_object_set (priv->filter_model, "base-model", priv->base_model, NULL); query = construct_query_from_selection (source); g_object_set (priv->filter_model, "query", query, NULL); rhythmdb_query_free (query); rhythmdb_query_model_reapply_query (priv->filter_model, TRUE); rb_library_browser_set_model (priv->browser, priv->filter_model, FALSE); }
static void rb_static_playlist_source_dispose (GObject *object) { RBStaticPlaylistSourcePrivate *priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (object); if (priv->dispose_has_run) { /* If dispose did already run, return. */ rb_debug ("Dispose has already run for static playlist source %p", object); return; } /* Make sure dispose does not run twice. */ priv->dispose_has_run = TRUE; rb_debug ("Disposing static playlist source %p", object); if (priv->base_model != NULL) { g_object_unref (priv->base_model); priv->base_model = NULL; } if (priv->filter_model != NULL) { g_object_unref (priv->filter_model); priv->filter_model = NULL; } if (priv->action_group != NULL) { g_object_unref (priv->action_group); priv->action_group = NULL; } if (priv->default_search != NULL) { g_object_unref (priv->default_search); priv->default_search = NULL; } G_OBJECT_CLASS (rb_static_playlist_source_parent_class)->dispose (object); }
static void rb_static_playlist_source_constructed (GObject *object) { RBStaticPlaylistSource *source; RBStaticPlaylistSourcePrivate *priv; RBPlaylistSource *psource; RBEntryView *songs; RBShell *shell; RhythmDBEntryType *entry_type; RB_CHAIN_GOBJECT_METHOD (rb_static_playlist_source_parent_class, constructed, object); source = RB_STATIC_PLAYLIST_SOURCE (object); priv = RB_STATIC_PLAYLIST_SOURCE_GET_PRIVATE (source); psource = RB_PLAYLIST_SOURCE (source); priv->base_model = rb_playlist_source_get_query_model (RB_PLAYLIST_SOURCE (psource)); g_object_set (priv->base_model, "show-hidden", TRUE, NULL); g_object_ref (priv->base_model); g_signal_connect_object (priv->base_model, "filter-entry-drop", G_CALLBACK (rb_static_playlist_source_filter_entry_drop), source, 0); priv->paned = gtk_vpaned_new (); g_object_get (source, "shell", &shell, NULL); priv->action_group = _rb_display_page_register_action_group (RB_DISPLAY_PAGE (source), "StaticPlaylistActions", NULL, 0, shell); if (gtk_action_group_get_action (priv->action_group, rb_static_playlist_source_radio_actions[0].name) == NULL) { gtk_action_group_add_radio_actions (priv->action_group, rb_static_playlist_source_radio_actions, G_N_ELEMENTS (rb_static_playlist_source_radio_actions), 0, NULL, NULL); rb_source_search_basic_create_for_actions (priv->action_group, rb_static_playlist_source_radio_actions, G_N_ELEMENTS (rb_static_playlist_source_radio_actions)); } priv->default_search = rb_source_search_basic_new (RHYTHMDB_PROP_SEARCH_MATCH); g_object_unref (shell); g_object_get (source, "entry-type", &entry_type, NULL); priv->browser = rb_library_browser_new (rb_playlist_source_get_db (RB_PLAYLIST_SOURCE (source)), entry_type); if (entry_type != NULL) { g_object_unref (entry_type); } gtk_paned_pack1 (GTK_PANED (priv->paned), GTK_WIDGET (priv->browser), TRUE, FALSE); g_signal_connect_object (priv->browser, "notify::output-model", G_CALLBACK (rb_static_playlist_source_browser_changed_cb), source, 0); rb_library_browser_set_model (priv->browser, priv->base_model, FALSE); rb_static_playlist_source_do_query (source); /* reparent the entry view */ songs = rb_source_get_entry_view (RB_SOURCE (source)); g_object_ref (songs); gtk_container_remove (GTK_CONTAINER (source), GTK_WIDGET (songs)); gtk_paned_pack2 (GTK_PANED (priv->paned), GTK_WIDGET (songs), TRUE, FALSE); gtk_container_add (GTK_CONTAINER (source), priv->paned); rb_source_bind_settings (RB_SOURCE (source), GTK_WIDGET (songs), priv->paned, GTK_WIDGET (priv->browser)); g_object_unref (songs); /* watch these to find out when things are dropped into the entry view */ g_signal_connect_object (priv->base_model, "row-inserted", G_CALLBACK (rb_static_playlist_source_row_inserted), source, 0); g_signal_connect_object (priv->base_model, "non-entry-dropped", G_CALLBACK (rb_static_playlist_source_non_entry_dropped), source, 0); g_signal_connect_object (priv->base_model, "rows-reordered", G_CALLBACK (rb_static_playlist_source_rows_reordered), source, 0); gtk_widget_show_all (GTK_WIDGET (source)); }