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); }
/** * rb_transfer_target_track_added: * @target: an #RBTransferTarget * @entry: the source #RhythmDBEntry for the transfer * @uri: the destination URI * @filesize: size of the destination file * @media_type: media type of the destination file * * This is called when a transfer to the target has completed. * If the source's @track_added method returns %TRUE, the destination * URI will be added to the database using the entry type for the device. * * If the target uses a temporary area as the destination for transfers, * it can instead upload the destination file to the device and create an * entry for it, then return %FALSE. */ void rb_transfer_target_track_added (RBTransferTarget *target, RhythmDBEntry *entry, const char *uri, guint64 filesize, const char *media_type) { RBTransferTargetInterface *iface = RB_TRANSFER_TARGET_GET_IFACE (target); gboolean add_to_db = TRUE; if (iface->track_added) add_to_db = iface->track_added (target, entry, uri, filesize, media_type); if (add_to_db) { RhythmDBEntryType *entry_type; RhythmDB *db; RBShell *shell; g_object_get (target, "shell", &shell, NULL); g_object_get (shell, "db", &db, NULL); g_object_unref (shell); g_object_get (target, "entry-type", &entry_type, NULL); rhythmdb_add_uri_with_types (db, uri, entry_type, NULL, NULL); g_object_unref (entry_type); g_object_unref (db); } }
static gboolean uri_recurse_func (GFile *file, GFileInfo *info, RhythmDBImportJob *job) { RhythmDBEntry *entry; char *uri; if (g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE) == G_FILE_TYPE_DIRECTORY) { return TRUE; } if (g_cancellable_is_cancelled (job->priv->cancel)) return FALSE; if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK)) { GFile *r; r = rb_file_resolve_symlink (file, NULL); if (r != NULL) { uri = g_file_get_uri (r); g_object_unref (r); } else { return FALSE; } } else { uri = g_file_get_uri (file); } /* if it's not already in the db, add it to the list of things to process */ entry = rhythmdb_entry_lookup_by_location (job->priv->db, uri); if (entry == NULL) { rb_debug ("waiting for entry %s", uri); g_mutex_lock (&job->priv->lock); job->priv->total++; g_queue_push_tail (job->priv->outstanding, g_strdup (uri)); if (job->priv->status_changed_id == 0) { job->priv->status_changed_id = g_idle_add ((GSourceFunc) emit_status_changed, job); } maybe_start_more (job); g_mutex_unlock (&job->priv->lock); } else { /* skip it if it's a different entry type */ RhythmDBEntryType *et; et = rhythmdb_entry_get_entry_type (entry); if (et == job->priv->entry_type || et == job->priv->ignore_type || et == job->priv->error_type) { rhythmdb_add_uri_with_types (job->priv->db, uri, job->priv->entry_type, job->priv->ignore_type, job->priv->error_type); } } g_free (uri); return TRUE; }
static gboolean uri_recurse_func (GFile *file, gboolean dir, RhythmDBImportJob *job) { RhythmDBEntry *entry; char *uri; if (dir) { return TRUE; } if (g_cancellable_is_cancelled (job->priv->cancel)) return FALSE; uri = g_file_get_uri (file); /* if it's not already in the db, add it to the list of things to process */ entry = rhythmdb_entry_lookup_by_location (job->priv->db, uri); if (entry == NULL) { rb_debug ("waiting for entry %s", uri); g_mutex_lock (&job->priv->lock); job->priv->total++; g_queue_push_tail (job->priv->outstanding, g_strdup (uri)); if (job->priv->status_changed_id == 0) { job->priv->status_changed_id = g_idle_add ((GSourceFunc) emit_status_changed, job); } maybe_start_more (job); g_mutex_unlock (&job->priv->lock); } else { /* skip it if it's a different entry type */ RhythmDBEntryType *et; et = rhythmdb_entry_get_entry_type (entry); if (et == job->priv->entry_type || et == job->priv->ignore_type || et == job->priv->error_type) { rhythmdb_add_uri_with_types (job->priv->db, uri, job->priv->entry_type, job->priv->ignore_type, job->priv->error_type); } } g_free (uri); return TRUE; }
static void missing_plugins_retry_cb (gpointer instance, gboolean installed, RhythmDBImportJob *job) { GSList *retry = NULL; GSList *i; g_mutex_lock (&job->priv->lock); g_assert (job->priv->retried == FALSE); if (installed == FALSE) { rb_debug ("plugin installation was not successful; job complete"); g_signal_emit (job, signals[COMPLETE], 0, job->priv->total); } else { job->priv->retried = TRUE; /* reset the job state to just show the retry information */ job->priv->total = g_slist_length (job->priv->retry_entries); rb_debug ("plugin installation was successful, retrying %d entries", job->priv->total); job->priv->imported = 0; /* remove the import error entries and build the list of URIs to retry */ for (i = job->priv->retry_entries; i != NULL; i = i->next) { RhythmDBEntry *entry = (RhythmDBEntry *)i->data; char *uri; uri = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_LOCATION); rhythmdb_entry_delete (job->priv->db, entry); g_hash_table_insert (job->priv->outstanding, g_strdup (uri), GINT_TO_POINTER (1)); retry = g_slist_prepend (retry, uri); } rhythmdb_commit (job->priv->db); retry = g_slist_reverse (retry); } g_mutex_unlock (&job->priv->lock); for (i = retry; i != NULL; i = i->next) { char *uri = (char *)i->data; rhythmdb_add_uri_with_types (job->priv->db, uri, job->priv->entry_type, job->priv->ignore_type, job->priv->error_type); } rb_slist_deep_free (retry); }
static void rhythmdb_mount_added_cb (GVolumeMonitor *monitor, GMount *mount, RhythmDB *db) { GList *l; RhythmDBQueryResultList *list; char *mountpoint; GFile *root; root = g_mount_get_root (mount); mountpoint = g_file_get_uri (root); rb_debug ("volume %s mounted", mountpoint); g_object_unref (root); list = rhythmdb_query_result_list_new (); rhythmdb_do_full_query (db, RHYTHMDB_QUERY_RESULTS (list), RHYTHMDB_QUERY_PROP_EQUALS, RHYTHMDB_PROP_TYPE, RHYTHMDB_ENTRY_TYPE_SONG, RHYTHMDB_QUERY_PROP_EQUALS, RHYTHMDB_PROP_MOUNTPOINT, mountpoint, RHYTHMDB_QUERY_END); l = rhythmdb_query_result_list_get_results (list); rb_debug ("%d mounted entries to process", g_list_length (l)); for (; l != NULL; l = l->next) { RhythmDBEntry *entry = l->data; const char *location = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION); rhythmdb_entry_update_availability (entry, RHYTHMDB_ENTRY_AVAIL_MOUNTED); if (rb_uri_is_local (location)) { rhythmdb_add_uri_with_types (db, location, RHYTHMDB_ENTRY_TYPE_SONG, RHYTHMDB_ENTRY_TYPE_IGNORE, RHYTHMDB_ENTRY_TYPE_IMPORT_ERROR); } } g_object_unref (list); g_free (mountpoint); rhythmdb_commit (db); }
static void uri_recurse_func (GFile *file, gboolean dir, RhythmDBImportJob *job) { RhythmDBEntry *entry; char *uri; if (dir) { return; } uri = g_file_get_uri (file); /* only add the entry to the map of entries we're waiting for * if it's not already in the db. */ entry = rhythmdb_entry_lookup_by_location (job->priv->db, uri); if (entry == NULL) { rb_debug ("waiting for entry %s", uri); g_mutex_lock (&job->priv->lock); job->priv->total++; g_hash_table_insert (job->priv->outstanding, g_strdup (uri), GINT_TO_POINTER (1)); if (job->priv->status_changed_id == 0) { job->priv->status_changed_id = g_idle_add ((GSourceFunc) emit_status_changed, job); } g_mutex_unlock (&job->priv->lock); } rhythmdb_add_uri_with_types (job->priv->db, uri, job->priv->entry_type, job->priv->ignore_type, job->priv->error_type); g_free (uri); }
/* must be called with lock held */ static void maybe_start_more (RhythmDBImportJob *job) { if (g_cancellable_is_cancelled (job->priv->cancel)) { return; } while (g_queue_get_length (job->priv->processing) < PROCESSING_LIMIT) { char *uri; uri = g_queue_pop_head (job->priv->outstanding); if (uri == NULL) { return; } g_queue_push_tail (job->priv->processing, uri); rhythmdb_add_uri_with_types (job->priv->db, uri, job->priv->entry_type, job->priv->ignore_type, job->priv->error_type); } }