Esempio n. 1
0
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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
static void
entry_added_cb (RhythmDB *db,
		RhythmDBEntry *entry,
		RhythmDBImportJob *job)
{
	const char *uri;
	GList *link;

	uri = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION);

	g_mutex_lock (&job->priv->lock);
	link = g_queue_find_custom (job->priv->processing, uri, (GCompareFunc) g_strcmp0);

	if (link != NULL) {
		const char *details;
		RhythmDBEntryType *entry_type;

		entry_type = rhythmdb_entry_get_entry_type (entry);

		job->priv->processed++;

		if (entry_type == job->priv->entry_type) {
			job->priv->imported++;
			g_signal_emit (job, signals[ENTRY_ADDED], 0, entry);
		}
		rb_debug ("got entry %s; %d imported, %d processed", uri, job->priv->imported, job->priv->processed);

		/* if it's an import error with missing plugins, add it to the retry list */
		details = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_COMMENT);
		if (entry_type == job->priv->error_type &&
		    (details != NULL && details[0] != '\0')) {
			rb_debug ("entry %s is an import error with missing plugin details: %s", uri, details);
			job->priv->retry_entries = g_slist_prepend (job->priv->retry_entries, rhythmdb_entry_ref (entry));
		}

		if (job->priv->status_changed_id == 0) {
			job->priv->status_changed_id = g_idle_add ((GSourceFunc) emit_status_changed, job);
		}

		g_queue_delete_link (job->priv->processing, link);
		maybe_start_more (job);
	}
	g_mutex_unlock (&job->priv->lock);
}
Esempio n. 4
0
static void
missing_plugins_retry_cb (gpointer instance, gboolean installed, RhythmDBImportJob *job)
{
	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");
		job->priv->complete = TRUE;
		g_signal_emit (job, signals[COMPLETE], 0, job->priv->total);
		g_object_notify (G_OBJECT (job), "task-outcome");
	} 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->processed = 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_queue_push_tail (job->priv->outstanding, g_strdup (uri));
		}
		rhythmdb_commit (job->priv->db);
	}

	maybe_start_more (job);

	g_mutex_unlock (&job->priv->lock);
}