Ejemplo n.º 1
0
GList *
pragha_dnd_uri_list_get_mobj_list (GtkSelectionData *data)
{
	PraghaMusicobject *mobj = NULL;
	gchar **uris = NULL, *filename = NULL;
	GList *list = NULL;
	gint i = 0;

	CDEBUG(DBG_VERBOSE, "Target: URI_LIST");

	uris = gtk_selection_data_get_uris(data);

	if(uris){
		for(i = 0; uris[i] != NULL; i++) {
			filename = g_filename_from_uri(uris[i], NULL, NULL);
			if (g_file_test(filename, G_FILE_TEST_IS_DIR)){
				list = append_mobj_list_from_folder(list, filename);
			}
			else {
				mobj = new_musicobject_from_file(filename, NULL);
				if (G_LIKELY(mobj))
					list = g_list_prepend(list, mobj);
			}

			/* Have to give control to GTK periodically ... */
			pragha_process_gtk_events ();

			g_free(filename);
		}
		g_strfreev(uris);
	}

	return g_list_reverse (list);
}
Ejemplo n.º 2
0
GList *
append_mobj_list_from_unknown_filename(GList *list, gchar *filename)
{
	PraghaMusicobject *mobj;
	PraghaMediaType file_type;

	if (is_dir_and_accessible(filename)) {
		list = append_mobj_list_from_folder (list, filename);
	}
	else {
		file_type = pragha_file_get_media_type (filename);
		switch (file_type) {
			case MEDIA_TYPE_AUDIO:
				mobj = new_musicobject_from_file (filename);
				if (G_LIKELY(mobj)) {
					list = g_list_append(list, mobj);
					add_recent_file(filename);
				}
				break;
			case MEDIA_TYPE_PLAYLIST:
				list = pragha_pl_parser_append_mobj_list_by_extension (list, filename);
				break;
			case MEDIA_TYPE_IMAGE:
			case MEDIA_TYPE_UNKNOWN:
			default:
				break;
		}
	}

	/* Have to give control to GTK periodically ... */
	pragha_process_gtk_events ();

	return list;
}
Ejemplo n.º 3
0
GList *
pragha_dnd_plain_text_get_mobj_list (GtkSelectionData *data)
{
	PraghaMusicobject *mobj = NULL;
	gchar *filename = NULL;
	GList *list = NULL;

	CDEBUG(DBG_VERBOSE, "Target: PLAIN_TEXT");

	filename = (gchar*)gtk_selection_data_get_text(data);

	if (g_file_test(filename, G_FILE_TEST_IS_DIR)) {
		list = append_mobj_list_from_folder(list, filename);
	}
	else {
		mobj = new_musicobject_from_file(filename, NULL);
		if (G_LIKELY(mobj))
			list = g_list_prepend(list, mobj);

		/* Have to give control to GTK periodically ... */
		pragha_process_gtk_events ();
	}
	g_free(filename);

	return g_list_reverse (list);
}
Ejemplo n.º 4
0
GList *
append_mobj_list_from_folder(GList *list, gchar *dir_name)
{
	PraghaPreferences *preferences;
	PraghaMusicobject *mobj = NULL;
	PraghaMediaType file_type;
	GDir *dir;
	const gchar *next_file = NULL;
	gchar *ab_file;
	GError *error = NULL;

	dir = g_dir_open(dir_name, 0, &error);
	if (!dir) {
		g_critical("Unable to open library : %s", dir_name);
		return list;
	}

	next_file = g_dir_read_name(dir);
	while (next_file) {
		ab_file = g_strconcat(dir_name, G_DIR_SEPARATOR_S, next_file, NULL);

		if (is_dir_and_accessible(ab_file)) {
			preferences = pragha_preferences_get();
			if(pragha_preferences_get_add_recursively(preferences))
				list = append_mobj_list_from_folder(list, ab_file);
			g_object_unref(G_OBJECT(preferences));
		}
		else {
			file_type = pragha_file_get_media_type (ab_file);
			switch (file_type) {
				case MEDIA_TYPE_AUDIO:
					mobj = new_musicobject_from_file (ab_file);
					if (G_LIKELY(mobj))
						list = g_list_append(list, mobj);
					break;
				case MEDIA_TYPE_PLAYLIST:
					list = pragha_pl_parser_append_mobj_list_by_extension (list, ab_file);
					break;
				case MEDIA_TYPE_IMAGE:
				case MEDIA_TYPE_UNKNOWN:
				default:
					break;
			}
		}

		/* Have to give control to GTK periodically ... */
		pragha_process_gtk_events ();

		g_free(ab_file);
		next_file = g_dir_read_name(dir);
	}

	g_dir_close(dir);

	return list;
}
Ejemplo n.º 5
0
static void
pragha_scanner_add_track_db(gpointer key,
                            gpointer value,
                            gpointer user_data)
{
	PraghaMusicobject *mobj = value;
	PraghaDatabase *database = user_data;

	pragha_database_add_new_musicobject (database, mobj);

	pragha_process_gtk_events ();
}
Ejemplo n.º 6
0
GList *
append_mobj_list_from_folder(GList *list, gchar *dir_name)
{
	PraghaPreferences *preferences;
	PraghaMusicobject *mobj = NULL;
	GDir *dir;
	const gchar *next_file = NULL;
	gchar *ab_file;
	GError *error = NULL;

	dir = g_dir_open(dir_name, 0, &error);
	if (!dir) {
		g_critical("Unable to open library : %s", dir_name);
		return list;
	}

	next_file = g_dir_read_name(dir);
	while (next_file) {
		ab_file = g_strconcat(dir_name, G_DIR_SEPARATOR_S, next_file, NULL);

		if (is_dir_and_accessible(ab_file)) {
			preferences = pragha_preferences_get();
			if(pragha_preferences_get_add_recursively(preferences))
				list = append_mobj_list_from_folder(list, ab_file);
			g_object_unref(G_OBJECT(preferences));
		}
		else {
			if (is_playable_file(ab_file)) {
				mobj = new_musicobject_from_file(ab_file);
				if (G_LIKELY(mobj))
					list = g_list_append(list, mobj);
			}
		}

		/* Have to give control to GTK periodically ... */
		pragha_process_gtk_events ();

		g_free(ab_file);
		next_file = g_dir_read_name(dir);
	}

	g_dir_close(dir);

	return list;
}
Ejemplo n.º 7
0
void
pragha_application_append_entery_libary (PraghaApplication *pragha)
{
	PraghaPlaylist *playlist;
	PraghaDatabase *cdbase;
	GList *list = NULL;
	PraghaMusicobject *mobj;

	/* Query and insert entries */

	set_watch_cursor (pragha_application_get_window(pragha));

	cdbase = pragha_application_get_database (pragha);

	const gchar *sql = "SELECT id FROM LOCATION";
	PraghaPreparedStatement *statement = pragha_database_create_statement (cdbase, sql);

	while (pragha_prepared_statement_step (statement)) {
		gint location_id = pragha_prepared_statement_get_int (statement, 0);
		mobj = new_musicobject_from_db (cdbase, location_id);

		if (G_LIKELY(mobj))
			list = g_list_prepend (list, mobj);
		else
			g_warning ("Unable to retrieve details for"
			            " location_id : %d",
			            location_id);

		pragha_process_gtk_events ();
	}

	pragha_prepared_statement_free (statement);

	remove_watch_cursor (pragha_application_get_window(pragha));

	if (list) {
		list = g_list_reverse(list);
		playlist = pragha_application_get_playlist (pragha);
		pragha_playlist_append_mobj_list (playlist, list);
		g_list_free(list);
	}
}
Ejemplo n.º 8
0
void
pragha_scanner_update_library(PraghaScanner *scanner)
{
	PraghaPreferences *preferences;
	PraghaDatabase *database;
	PraghaPreparedStatement *statement;
	PraghaMusicobject *mobj = NULL;
	gchar *mask = NULL, *last_scan_time = NULL;
	const gchar *sql = NULL;
	guint location_id;
	GSList *list;

	if(scanner->update_timeout)
		return;

	preferences = pragha_preferences_get();

	/* Get last time that update the library and folders to analyze */

	last_scan_time = pragha_preferences_get_string(preferences,
	                                               GROUP_LIBRARY,
	                                               KEY_LIBRARY_LAST_SCANNED);
	if (last_scan_time) {
		if (!g_time_val_from_iso8601(last_scan_time, &scanner->last_update))
			g_warning("Unable to convert last rescan time");
		g_free(last_scan_time);
	}

	scanner->folder_list =
		pragha_preferences_get_filename_list(preferences,
		                                     GROUP_LIBRARY,
		                                     KEY_LIBRARY_DIR);
	scanner->folder_scanned =
		pragha_preferences_get_filename_list(preferences,
		                                     GROUP_LIBRARY,
		                                     KEY_LIBRARY_SCANNED);
	g_object_unref(G_OBJECT(preferences));

	/* Update the gui */

	scanner->update_timeout = g_timeout_add_seconds(1, (GSourceFunc)pragha_scanner_update_progress, scanner);


	pragha_preferences_set_show_status_bar (preferences, TRUE);
	gtk_widget_show_all(scanner->hbox);

	/* Append the files from database that no changed. */

	database = pragha_database_get();
	for(list = scanner->folder_scanned ; list != NULL; list = list->next) {
		if(is_present_str_list(list->data, scanner->folder_list)) {
			sql = "SELECT id FROM LOCATION WHERE name LIKE ?";
			statement = pragha_database_create_statement (database, sql);
			mask = g_strconcat (list->data, "%", NULL);
			pragha_prepared_statement_bind_string (statement, 1, mask);
			while (pragha_prepared_statement_step (statement)) {
				location_id = pragha_prepared_statement_get_int (statement, 0);
				mobj = new_musicobject_from_db(database, location_id);
				if (G_LIKELY(mobj)) {
					g_hash_table_insert(scanner->tracks_table,
					                    g_strdup(pragha_musicobject_get_file(mobj)),
					                    mobj);
				}

				pragha_process_gtk_events ();
			}
			pragha_prepared_statement_free (statement);
			g_free(mask);
		}
	}
	g_object_unref(database);

	/* Launch threads */

	scanner->no_files_thread = g_thread_new("Count no files", pragha_scanner_count_no_files_worker, scanner);

	scanner->worker_thread = pragha_async_launch_full(pragha_scanner_update_worker,
	                                                  pragha_scanner_worker_finished,
	                                                  scanner);
}