static RhythmDBEntry * rb_linear_play_order_loop_get_previous (RBPlayOrder *porder) { RhythmDBQueryModel *model; RhythmDBEntry *entry; RhythmDBEntry *prev = NULL; g_return_val_if_fail (porder != NULL, NULL); g_return_val_if_fail (RB_IS_LINEAR_PLAY_ORDER_LOOP (porder), NULL); model = rb_play_order_get_query_model (porder); if (model == NULL) return NULL; g_object_get (porder, "playing-entry", &entry, NULL); if (entry != NULL) { prev = rhythmdb_query_model_get_previous_from_entry (model, entry); rhythmdb_entry_unref (entry); } if (prev == NULL) { /* loop to last entry */ GtkTreeIter iter; gint num_entries = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), NULL); if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (model), &iter, NULL, num_entries-1)) return NULL; prev = rhythmdb_query_model_iter_to_entry (model, &iter); } return prev; }
static void missing_plugins_retry_cb (gpointer instance, gboolean installed, RBImportErrorsSource *source) { GtkTreeIter iter; RhythmDBEntryType *error_entry_type; gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (source->priv->infobar), GTK_RESPONSE_OK, TRUE); if (installed == FALSE) { rb_debug ("installer failed, not retrying imports"); return; } g_object_get (source, "entry-type", &error_entry_type, NULL); do { RhythmDBEntry *entry; entry = rhythmdb_query_model_iter_to_entry (source->priv->missing_plugin_model, &iter); rhythmdb_add_uri_with_types (source->priv->db, rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION), source->priv->normal_entry_type, source->priv->ignore_entry_type, error_entry_type); } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (source->priv->missing_plugin_model), &iter)); g_object_unref (error_entry_type); }
static RhythmDBEntry * rb_linear_play_order_get_next (RBPlayOrder *porder) { RhythmDBQueryModel *model; RhythmDBEntry *entry; g_return_val_if_fail (porder != NULL, NULL); g_return_val_if_fail (RB_IS_LINEAR_PLAY_ORDER (porder), NULL); model = rb_play_order_get_query_model (porder); if (model == NULL) return NULL; entry = rb_play_order_get_playing_entry (porder); if (entry != NULL) { RhythmDBEntry *next; next = rhythmdb_query_model_get_next_from_entry (model, entry); rhythmdb_entry_unref (entry); return next; } else { GtkTreeIter iter; if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) return NULL; return rhythmdb_query_model_iter_to_entry (model, &iter); } }
static void impl_get_entries (RBMediaPlayerSource *source, const char *category, GHashTable *map) { RhythmDBQueryModel *model; GtkTreeIter iter; gboolean podcast; /* we don't have anything else to distinguish podcasts from regular * tracks, so just use the genre. */ podcast = (g_str_equal (category, SYNC_CATEGORY_PODCAST)); g_object_get (source, "base-query-model", &model, NULL); if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter) == FALSE) { g_object_unref (model); return; } do { RhythmDBEntry *entry; const char *genre; entry = rhythmdb_query_model_iter_to_entry (model, &iter); genre = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_GENRE); if (g_str_equal (genre, "Podcast") == podcast) { _rb_media_player_source_add_to_map (map, entry); } } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter)); g_object_unref (model); }
static RhythmDBEntry * rb_linear_play_order_loop_get_next (RBPlayOrder *porder) { RhythmDBQueryModel *model; RhythmDBEntry *entry; g_return_val_if_fail (porder != NULL, NULL); g_return_val_if_fail (RB_IS_LINEAR_PLAY_ORDER_LOOP (porder), NULL); model = rb_play_order_get_query_model (porder); if (model == NULL) return NULL; g_object_get (porder, "playing-entry", &entry, NULL); if (entry != NULL) { RhythmDBEntry *next; next = rhythmdb_query_model_get_next_from_entry (model, entry); rhythmdb_entry_unref (entry); entry = next; } if (entry == NULL) { /* loop back to (or start from) the first entry */ GtkTreeIter iter; if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) return NULL; return rhythmdb_query_model_iter_to_entry (model, &iter); } return entry; }
static gboolean save_playlist_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, SavePlaylistData *data) { RBGenericPlayerPlaylistSourcePrivate *priv = GET_PRIVATE (data->source); RhythmDBEntry *entry; TotemPlPlaylistIter pl_iter; const char *host_uri; char *uri; entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model), iter); if (entry == NULL) { return FALSE; } host_uri = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION); uri = rb_generic_player_source_uri_to_playlist_uri (priv->player_source, host_uri, data->playlist_type); totem_pl_playlist_append (data->playlist, &pl_iter); totem_pl_playlist_set (data->playlist, &pl_iter, TOTEM_PL_PARSER_FIELD_URI, uri, NULL); set_field_from_property (data->playlist, &pl_iter, entry, RHYTHMDB_PROP_ARTIST, TOTEM_PL_PARSER_FIELD_AUTHOR); set_field_from_property (data->playlist, &pl_iter, entry, RHYTHMDB_PROP_GENRE, TOTEM_PL_PARSER_FIELD_GENRE); set_field_from_property (data->playlist, &pl_iter, entry, RHYTHMDB_PROP_ALBUM, TOTEM_PL_PARSER_FIELD_ALBUM); set_field_from_property (data->playlist, &pl_iter, entry, RHYTHMDB_PROP_TITLE, TOTEM_PL_PARSER_FIELD_TITLE); rhythmdb_entry_unref (entry); g_free (uri); return FALSE; }
static void extract_toggled_cb (GtkCellRendererToggle *renderer, char *path_str, RBAudioCdSource *source) { RhythmDBQueryModel *model; GtkTreePath *path; GtkTreeIter iter; g_object_get (source, "query-model", &model, NULL); path = gtk_tree_path_new_from_string (path_str); if (gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path)) { RhythmDBEntry *entry; entry = rhythmdb_query_model_iter_to_entry (model, &iter); if (entry != NULL) { RBAudioCDEntryData *extra_data; extra_data = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RBAudioCDEntryData); extra_data->extract = !extra_data->extract; rhythmdb_entry_unref (entry); gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter); } } gtk_tree_path_free (path); g_object_unref (model); }
static gboolean collect_entries (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, GList **list) { RhythmDBEntry *entry; entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model), iter); *list = g_list_prepend (*list, rhythmdb_entry_ref (entry)); return FALSE; }
static gboolean copy_entry (RhythmDBQueryModel *model, GtkTreePath *path, GtkTreeIter *iter, GList **list) { GList *l; l = g_list_append (*list, rhythmdb_query_model_iter_to_entry (model, iter)); *list = l; return FALSE; }
static void playlist_row_inserted_cb (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, RBDiscRecorderPlugin *pi) { RhythmDBEntry *entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model), iter); playlist_entries_changed (model, entry, pi); rhythmdb_entry_unref (entry); }
static gboolean _remove_entry_cb (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, RhythmDBPropertyModel *propmodel) { RhythmDBEntry *entry; entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model), iter); rhythmdb_property_model_entry_removed_cb (RHYTHMDB_QUERY_MODEL (model), entry, propmodel); rhythmdb_entry_unref (entry); return FALSE; }
static void rhythmdb_property_model_row_inserted_cb (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, RhythmDBPropertyModel *propmodel) { RhythmDBEntry *entry; entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model), iter); rhythmdb_property_model_insert (propmodel, entry); rhythmdb_property_model_sync (propmodel); rhythmdb_entry_unref (entry); }
static void infobar_response_cb (GtkInfoBar *infobar, gint response, RBImportErrorsSource *source) { char **details = NULL; GtkTreeIter iter; GClosure *closure; int i; /* gather plugin installer detail strings */ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (source->priv->missing_plugin_model), &iter) == FALSE) { return; } i = 0; do { RhythmDBEntry *entry; char **bits; int j; entry = rhythmdb_query_model_iter_to_entry (source->priv->missing_plugin_model, &iter); bits = g_strsplit (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_COMMENT), "\n", 0); for (j = 0; bits[j] != NULL; j++) { if (rb_str_in_strv (bits[j], (const char **)details) == FALSE) { details = g_realloc (details, sizeof (char *) * i+2); details[i++] = g_strdup (bits[j]); details[i] = NULL; } } g_strfreev (bits); } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (source->priv->missing_plugin_model), &iter)); /* run the installer */ closure = g_cclosure_new ((GCallback) missing_plugins_retry_cb, g_object_ref (source), (GClosureNotify) missing_plugins_retry_cleanup); g_closure_set_marshal (closure, g_cclosure_marshal_VOID__BOOLEAN); if (rb_missing_plugins_install ((const char **)details, TRUE, closure) == TRUE) { /* disable the button while the installer is running */ gtk_info_bar_set_response_sensitive (infobar, response, FALSE); } g_closure_sink (closure); g_strfreev (details); }
static void extract_cell_data_func (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *tree_model, GtkTreeIter *iter, RBAudioCdSource *source) { RBAudioCDEntryData *extra_data; RhythmDBEntry *entry; entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (tree_model), iter); if (entry != NULL) { extra_data = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RBAudioCDEntryData); gtk_cell_renderer_toggle_set_active (GTK_CELL_RENDERER_TOGGLE (renderer), extra_data->extract); rhythmdb_entry_unref (entry); } }
static gboolean set_extract (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { RBAudioCDEntryData *extra_data; RhythmDBEntry *entry; entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model), iter); if (entry != NULL) { extra_data = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RBAudioCDEntryData); extra_data->extract = GPOINTER_TO_INT (data); gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, iter); rhythmdb_entry_unref (entry); } return FALSE; }
static void save_playlist_entry (GtkTreeModel *model, GtkTreeIter *iter, char **uri, char **title, gboolean *custom_title, RBGenericPlayerPlaylistSource *source) { RBGenericPlayerPlaylistSourcePrivate *priv = GET_PRIVATE (source); RhythmDBEntry *entry; const char *host_uri; entry = rhythmdb_query_model_iter_to_entry (RHYTHMDB_QUERY_MODEL (model), iter); if (entry == NULL) { return; } host_uri = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION); *uri = rb_generic_player_source_uri_to_playlist_uri (priv->player_source, host_uri); *title = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_TITLE); *custom_title = TRUE; }
static gboolean copy_entry (RhythmDBQueryModel *model, GtkTreePath *path, GtkTreeIter *iter, GList **list) { RBAudioCDEntryData *extra_data; RhythmDBEntry *entry; GList *l; entry = rhythmdb_query_model_iter_to_entry (model, iter); extra_data = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RBAudioCDEntryData); if (extra_data->extract) { rb_debug ("adding track %s to transfer list", rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION)); l = g_list_append (*list, entry); *list = l; } else { rb_debug ("skipping track %s", rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION)); rhythmdb_entry_unref (entry); } return FALSE; }
static void sync_playlists (RBMediaPlayerSource *source) { RBMediaPlayerSourcePrivate *priv = MEDIA_PLAYER_SOURCE_GET_PRIVATE (source); RBMediaPlayerSourceClass *klass = RB_MEDIA_PLAYER_SOURCE_GET_CLASS (source); RBPlaylistManager *playlist_manager; RBShell *shell; GHashTable *device; GList *all_playlists; GList *l; if (klass->add_playlist == NULL || klass->remove_playlists == NULL) { rb_debug ("source class doesn't support playlists"); return; } /* build an updated device contents map, so we can find the device entries * corresponding to the entries in the local playlists. */ device = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)rhythmdb_entry_unref); rb_media_player_source_get_entries (source, SYNC_CATEGORY_MUSIC, device); /* remove all playlists from the device, then add the synced playlists. */ klass->remove_playlists (source); /* get all local playlists */ g_object_get (source, "shell", &shell, NULL); g_object_get (shell, "playlist-manager", &playlist_manager, NULL); all_playlists = rb_playlist_manager_get_playlists (playlist_manager); g_object_unref (playlist_manager); g_object_unref (shell); for (l = all_playlists; l != NULL; l = l->next) { char *name; RBSource *playlist_source = RB_SOURCE (l->data); RhythmDBQueryModel *model; GList *tracks = NULL; GtkTreeIter iter; /* is this playlist selected for syncing? */ g_object_get (playlist_source, "name", &name, NULL); if (rb_sync_settings_sync_group (priv->sync_settings, SYNC_CATEGORY_MUSIC, name) == FALSE) { rb_debug ("not syncing playlist %s", name); g_free (name); continue; } /* match playlist entries to entries on the device */ g_object_get (playlist_source, "base-query-model", &model, NULL); if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter) == FALSE) { rb_debug ("not syncing empty playlist %s", name); g_free (name); g_object_unref (model); continue; } do { char *trackid; RhythmDBEntry *entry; RhythmDBEntry *device_entry; entry = rhythmdb_query_model_iter_to_entry (model, &iter); trackid = rb_sync_state_make_track_uuid (entry); device_entry = g_hash_table_lookup (device, trackid); if (device_entry != NULL) { tracks = g_list_prepend (tracks, device_entry); } else { rb_debug ("unable to find entry on device for track %s (id %s)", rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION), trackid); } g_free (trackid); } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter)); tracks = g_list_reverse (tracks); /* transfer the playlist to the device */ rb_debug ("syncing playlist %s", name); klass->add_playlist (source, name, tracks); g_free (name); g_list_free (tracks); g_object_unref (model); } g_hash_table_destroy (device); }