Ejemplo n.º 1
0
GList *
prepend_song_with_artist_and_title_to_mobj_list(const gchar *artist,
						const gchar *title,
						GList *list,
						struct con_win *cwin)
{
	PraghaMusicobject *mobj = NULL;
	gint location_id = 0;

	if(pragha_mobj_list_already_has_title_of_artist(list, title, artist) ||
	   pragha_playlist_already_has_title_of_artist(cwin->cplaylist, title, artist))
		return list;

	const gchar *sql = "SELECT TRACK.title, ARTIST.name, LOCATION.id "
				"FROM TRACK, ARTIST, LOCATION "
				"WHERE ARTIST.id = TRACK.artist AND LOCATION.id = TRACK.location "
				"AND TRACK.title = ? COLLATE NOCASE "
				"AND ARTIST.name = ? COLLATE NOCASE "
				"ORDER BY RANDOM() LIMIT 1;";
	PraghaPreparedStatement *statement = pragha_database_create_statement (cwin->cdbase, sql);
	pragha_prepared_statement_bind_string (statement, 1, title);
	pragha_prepared_statement_bind_string (statement, 2, artist);

	if (pragha_prepared_statement_step (statement)) {
		location_id = pragha_prepared_statement_get_int (statement, 2);
		mobj = new_musicobject_from_db (cwin->cdbase, location_id);
		list = g_list_prepend (list, mobj);
	}

	pragha_prepared_statement_free (statement);

	return list;
}
Ejemplo n.º 2
0
gint
pragha_database_find_radio (PraghaDatabase *database, const gchar *radio)
{
	gint radio_id = 0;
	const gchar *sql = "SELECT id FROM RADIO WHERE name = ?";
	PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql);
	pragha_prepared_statement_bind_string (statement, 1, radio);
	if (pragha_prepared_statement_step (statement))
		radio_id = pragha_prepared_statement_get_int (statement, 0);
	pragha_prepared_statement_free (statement);
	return radio_id;
}
Ejemplo n.º 3
0
gint
pragha_database_find_year (PraghaDatabase *database, gint year)
{
	gint year_id = 0;
	const gchar *sql = "SELECT id FROM YEAR WHERE year = ?";
	PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql);
	pragha_prepared_statement_bind_int (statement, 1, year);
	if (pragha_prepared_statement_step (statement))
		year_id = pragha_prepared_statement_get_int (statement, 0);
	pragha_prepared_statement_free (statement);
	return year_id;
}
Ejemplo n.º 4
0
gint
pragha_database_find_playlist (PraghaDatabase *database, const gchar *playlist)
{
	gint playlist_id = 0;
	const gchar *sql = "SELECT id FROM PLAYLIST WHERE name = ?";
	PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql);
	pragha_prepared_statement_bind_string (statement, 1, playlist);
	if (pragha_prepared_statement_step (statement))
		playlist_id = pragha_prepared_statement_get_int (statement, 0);
	pragha_prepared_statement_free (statement);
	return playlist_id;
}
Ejemplo n.º 5
0
gint
pragha_database_find_genre (PraghaDatabase *database, const gchar *genre)
{
	gint genre_id = 0;
	const gchar *sql = "SELECT id FROM GENRE WHERE name = ?";
	PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql);
	pragha_prepared_statement_bind_string (statement, 1, genre);
	if (pragha_prepared_statement_step (statement))
		genre_id = pragha_prepared_statement_get_int (statement, 0);
	pragha_prepared_statement_free (statement);
	return genre_id;
}
Ejemplo n.º 6
0
gint
pragha_database_find_comment (PraghaDatabase *database, const gchar *comment)
{
	gint comment_id = 0;
	const gchar *sql = "SELECT id FROM COMMENT WHERE name = ?";
	PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql);
	pragha_prepared_statement_bind_string (statement, 1, comment);
	if (pragha_prepared_statement_step (statement))
		comment_id = pragha_prepared_statement_get_int (statement, 0);
	pragha_prepared_statement_free (statement);
	return comment_id;
}
Ejemplo n.º 7
0
gint
pragha_database_find_album (PraghaDatabase *database, const gchar *album)
{
	gint album_id = 0;
	const gchar *sql = "SELECT id FROM ALBUM WHERE name = ?";
	PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql);
	pragha_prepared_statement_bind_string (statement, 1, album);
	if (pragha_prepared_statement_step (statement))
		album_id = pragha_prepared_statement_get_int (statement, 0);
	pragha_prepared_statement_free (statement);
	return album_id;
}
Ejemplo n.º 8
0
gint
pragha_database_find_mime_type (PraghaDatabase *database, const gchar *mime_type)
{
	gint mime_type_id = 0;
	const gchar *sql = "SELECT id FROM MIME_TYPE WHERE name = ?";
	PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql);
	pragha_prepared_statement_bind_string (statement, 1, mime_type);
	if (pragha_prepared_statement_step (statement))
		mime_type_id = pragha_prepared_statement_get_int (statement, 0);
	pragha_prepared_statement_free (statement);
	return mime_type_id;
}
Ejemplo n.º 9
0
gint
pragha_database_find_location (PraghaDatabase *database, const gchar *location)
{
	gint location_id = 0;
	const gchar *sql = "SELECT id FROM LOCATION WHERE name = ?";
	PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql);
	pragha_prepared_statement_bind_string (statement, 1, location);
	if (pragha_prepared_statement_step (statement))
		location_id = pragha_prepared_statement_get_int (statement, 0);
	pragha_prepared_statement_free (statement);
	return location_id;
}
Ejemplo n.º 10
0
gint
pragha_database_get_version (PraghaDatabase *database)
{
	gint version = 0;

	const gchar *sql = "PRAGMA user_version";
	PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql);
	if (pragha_prepared_statement_step (statement))
		version = pragha_prepared_statement_get_int (statement, 0);
	pragha_prepared_statement_free (statement);

	return version;
}
Ejemplo n.º 11
0
gint
pragha_database_get_playlist_count (PraghaDatabase *database)
{
	gint n_playlists = 0;

	const gchar *sql = "SELECT COUNT() FROM PLAYLIST WHERE name != ?";
	PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql);
	pragha_prepared_statement_bind_string (statement, 1, SAVE_PLAYLIST_STATE);
	if (pragha_prepared_statement_step (statement))
		n_playlists = pragha_prepared_statement_get_int (statement, 0);
	pragha_prepared_statement_free (statement);

	return n_playlists;
}
Ejemplo n.º 12
0
static gint
pragha_database_get_table_count (PraghaDatabase *database, const gchar *table)
{
	gchar *sql;
	gint count = 0;

	sql = g_strdup_printf ("SELECT COUNT() FROM %s;", table);
	PraghaPreparedStatement *statement = pragha_database_create_statement (database, sql);
	if (pragha_prepared_statement_step (statement))
		count = pragha_prepared_statement_get_int (statement, 0);
	pragha_prepared_statement_free (statement);
	g_free (sql);

	return count;
}
Ejemplo n.º 13
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.º 14
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);
}
Ejemplo n.º 15
0
PraghaMusicobject *
new_musicobject_from_db(PraghaDatabase *cdbase, gint location_id)
{
	PraghaMusicobject *mobj = NULL;

	CDEBUG(DBG_MOBJ, "Creating new musicobject with location id: %d",
	       location_id);

	const gchar *sql = "SELECT \
MIME_TYPE.name, \
TRACK.samplerate, \
TRACK.channels, \
TRACK.length, \
TRACK.bitrate, \
COMMENT.name, \
YEAR.year, \
TRACK.track_no, \
GENRE.name, \
ALBUM.name, \
ARTIST.name, \
TRACK.title, \
LOCATION.name \
FROM MIME_TYPE, TRACK, COMMENT, YEAR, GENRE, ALBUM, ARTIST, LOCATION \
WHERE TRACK.location = ? \
AND MIME_TYPE.id = TRACK.file_type \
AND COMMENT.id = TRACK.comment \
AND YEAR.id = TRACK.year \
AND GENRE.id = TRACK.genre \
AND ALBUM.id = TRACK.album \
AND ARTIST.id = TRACK.artist \
AND LOCATION.id = ?";

	PraghaPreparedStatement *statement = pragha_database_create_statement (cdbase, sql);
	pragha_prepared_statement_bind_int (statement, 1, location_id);
	pragha_prepared_statement_bind_int (statement, 2, location_id);

	if (pragha_prepared_statement_step (statement)) {
		mobj = g_object_new (PRAGHA_TYPE_MUSICOBJECT,
		                     "file", pragha_prepared_statement_get_string (statement, 12),
		                     "source", FILE_LOCAL,
		                     "mime-type", pragha_prepared_statement_get_string (statement, 0),
		                     "title", pragha_prepared_statement_get_string (statement, 11),
		                     "artist", pragha_prepared_statement_get_string (statement, 10),
		                     "album", pragha_prepared_statement_get_string (statement, 9),
		                     "genre", pragha_prepared_statement_get_string (statement, 8),
		                     "comment", pragha_prepared_statement_get_string (statement, 5),
		                     "year", pragha_prepared_statement_get_int (statement, 6),
		                     "track-no", pragha_prepared_statement_get_int (statement, 7),
		                     "length", pragha_prepared_statement_get_int (statement, 3),
		                     "bitrate", pragha_prepared_statement_get_int (statement, 4),
		                     "channels", pragha_prepared_statement_get_int (statement, 2),
		                     "samplerate", pragha_prepared_statement_get_int (statement, 1),
		                     NULL);
	}
	else {
		g_critical("Track with location id : %d not found in DB",
			   location_id);
	}

	pragha_prepared_statement_free (statement);

	return mobj;
}