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; }
GList * pragha_dnd_library_get_mobj_list (GtkSelectionData *data, PraghaDatabase *cdbase) { gint n = 0, location_id = 0; gchar *name = NULL, *uri, **uris; PraghaMusicobject *mobj = NULL; GList *list = NULL; CDEBUG(DBG_VERBOSE, "Dnd: Library"); uris = g_uri_list_extract_uris ((const gchar *) gtk_selection_data_get_data (data)); if (!uris) { g_warning("No selections to process in DnD"); return list; } /* Dnd from the library, so will read everything from database. */ pragha_database_begin_transaction (cdbase); /* Get the mobjs from the path of the library. */ for (n = 0; uris[n] != NULL; n++) { uri = uris[n]; if (g_str_has_prefix(uri, "Location:/")) { location_id = atoi(uri + strlen("Location:/")); mobj = new_musicobject_from_db (cdbase, location_id); if (G_LIKELY(mobj)) list = g_list_prepend(list, mobj); } else if(g_str_has_prefix(uri, "Playlist:/")) { name = uri + strlen("Playlist:/"); list = add_playlist_to_mobj_list (cdbase, name, list); } else if(g_str_has_prefix(uri, "Radio:/")) { name = uri + strlen("Radio:/"); list = add_radio_to_mobj_list (cdbase, name, list); } } pragha_database_commit_transaction (cdbase); g_strfreev(uris); return g_list_reverse (list); }
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); } }
gint tag_edit_dialog(struct tags *otag, struct tags *ntag, gchar *file, struct con_win *cwin) { GtkWidget *dialog; GtkWidget *tag_table; GtkWidget *label_title, *label_artist, *label_album, *label_genre, *label_tno, *label_year, *label_comment, *label_file; GtkWidget *chk_title, *chk_artist, *chk_album, *chk_genre, *chk_tno, *chk_year, *chk_comment; GtkWidget *entry_title, *entry_artist, *entry_album, *entry_genre, *entry_tno, *entry_year, *entry_comment, *entry_file; GtkWidget *hbox_title, *hbox_artist, *hbox_album, *hbox_genre, *hbox_tno, *hbox_year, *hbox_comment; GtkWidget *hbox_spins, *comment_view_scroll, *chk_alignment; GtkTextBuffer *buffer; GtkTextIter start, end; gpointer storage; gint location_id, result, changed = 0; struct musicobject *mobj = NULL; gchar *uri = NULL; /*Create table*/ tag_table = gtk_table_new(8, 2, FALSE); gtk_table_set_col_spacings(GTK_TABLE(tag_table), 5); gtk_table_set_row_spacings(GTK_TABLE(tag_table), 5); gtk_container_set_border_width(GTK_CONTAINER(tag_table), 5); /* Create labels */ label_title = gtk_label_new(_("Title")); label_artist = gtk_label_new(_("Artist")); label_album = gtk_label_new(_("Album")); label_genre = gtk_label_new(_("Genre")); label_tno = gtk_label_new(_("Track No")); label_year = gtk_label_new(_("Year")); label_comment = gtk_label_new(_("Comment")); label_file = gtk_label_new(_("File")); gtk_misc_set_alignment(GTK_MISC (label_title), 1, 0.5); gtk_misc_set_alignment(GTK_MISC (label_artist), 1, 0.5); gtk_misc_set_alignment(GTK_MISC (label_album), 1, 0.5); gtk_misc_set_alignment(GTK_MISC (label_genre), 1, 0.5); gtk_misc_set_alignment(GTK_MISC (label_tno), 1, 0.5); gtk_misc_set_alignment(GTK_MISC (label_year), 1, 0.5); gtk_misc_set_alignment(GTK_MISC (label_comment), 1, 0); gtk_misc_set_alignment(GTK_MISC (label_file), 1, 0.5); /* Create entry fields */ entry_title = gtk_entry_new(); entry_artist = gtk_entry_new(); entry_album = gtk_entry_new(); entry_genre = gtk_entry_new(); entry_tno = gtk_spin_button_new_with_range (0, 2030, 1); entry_year = gtk_spin_button_new_with_range (0, 2030, 1); entry_comment = gtk_text_view_new(); gtk_text_view_set_accepts_tab (GTK_TEXT_VIEW (entry_comment), FALSE); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (entry_comment)); entry_file = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(entry_title), TAG_MAX_LEN); gtk_entry_set_max_length(GTK_ENTRY(entry_artist), TAG_MAX_LEN); gtk_entry_set_max_length(GTK_ENTRY(entry_album), TAG_MAX_LEN); gtk_entry_set_max_length(GTK_ENTRY(entry_genre), TAG_MAX_LEN); gtk_entry_set_completion(GTK_ENTRY(entry_artist), cwin->completion[0]); gtk_entry_set_completion(GTK_ENTRY(entry_album), cwin->completion[1]); gtk_entry_set_completion(GTK_ENTRY(entry_genre), cwin->completion[2]); gtk_entry_set_icon_from_stock (GTK_ENTRY(entry_title), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR); gtk_entry_set_icon_from_stock (GTK_ENTRY(entry_artist), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR); gtk_entry_set_icon_from_stock (GTK_ENTRY(entry_album), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR); gtk_entry_set_icon_from_stock (GTK_ENTRY(entry_genre), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR); gtk_entry_set_icon_from_stock (GTK_ENTRY(entry_file), GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_DIRECTORY); gtk_entry_set_icon_from_stock (GTK_ENTRY(entry_file), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_JUMP_TO); gtk_entry_set_editable (GTK_ENTRY(entry_file), FALSE); /* Create checkboxes */ chk_title = gtk_check_button_new(); chk_artist = gtk_check_button_new(); chk_album = gtk_check_button_new(); chk_genre = gtk_check_button_new(); chk_year = gtk_check_button_new(); chk_tno = gtk_check_button_new(); chk_comment = gtk_check_button_new(); hbox_title = gtk_hbox_new(FALSE, 0); hbox_artist = gtk_hbox_new(FALSE, 0); hbox_album = gtk_hbox_new(FALSE, 0); hbox_genre = gtk_hbox_new(FALSE, 0); hbox_year = gtk_hbox_new(FALSE, 0); hbox_tno = gtk_hbox_new(FALSE, 0); hbox_comment = gtk_hbox_new(FALSE, 0); hbox_spins = gtk_hbox_new(FALSE, 5); /* Create hobxs(ENTRY CHECHK) and attach in table */ gtk_box_pack_start(GTK_BOX(hbox_title), entry_title, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox_title), chk_title, FALSE, FALSE, 0); gtk_table_attach(GTK_TABLE (tag_table), label_title, 0, 1, 0, 1, GTK_FILL, GTK_SHRINK, 0, 0); gtk_table_attach(GTK_TABLE (tag_table), hbox_title, 1, 2, 0, 1, GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0); gtk_box_pack_start(GTK_BOX(hbox_artist), entry_artist, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox_artist), chk_artist, FALSE, FALSE, 0); gtk_table_attach(GTK_TABLE (tag_table), label_artist, 0, 1, 1, 2, GTK_FILL, GTK_SHRINK, 0, 0); gtk_table_attach(GTK_TABLE (tag_table), hbox_artist, 1, 2, 1, 2, GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0); gtk_box_pack_start(GTK_BOX(hbox_album), entry_album, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox_album), chk_album, FALSE, FALSE, 0); gtk_table_attach(GTK_TABLE (tag_table), label_album, 0, 1, 2, 3, GTK_FILL, GTK_SHRINK, 0, 0); gtk_table_attach(GTK_TABLE (tag_table), hbox_album, 1, 2, 2, 3, GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0); gtk_box_pack_start(GTK_BOX(hbox_genre), entry_genre, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox_genre), chk_genre, FALSE, FALSE, 0); gtk_table_attach(GTK_TABLE (tag_table), label_genre, 0, 1, 3, 4, GTK_FILL, GTK_SHRINK, 0, 0); gtk_table_attach(GTK_TABLE (tag_table), hbox_genre, 1, 2, 3, 4, GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0); gtk_box_pack_start(GTK_BOX(hbox_tno), entry_tno, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox_tno), chk_tno, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox_year), label_year, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(hbox_year), entry_year, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox_year), chk_year, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox_spins), hbox_tno, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox_spins), hbox_year, TRUE, TRUE, 0); gtk_table_attach(GTK_TABLE (tag_table), label_tno, 0, 1, 4, 5, GTK_FILL, GTK_SHRINK, 0, 0); gtk_table_attach(GTK_TABLE (tag_table), hbox_spins, 1, 2, 4, 5, GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0); comment_view_scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(comment_view_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(comment_view_scroll), GTK_SHADOW_IN); gtk_container_add(GTK_CONTAINER(comment_view_scroll), entry_comment); chk_alignment = gtk_alignment_new(0.5, 0, 0, 0); gtk_container_add(GTK_CONTAINER(chk_alignment), chk_comment); gtk_box_pack_start(GTK_BOX(hbox_comment), comment_view_scroll, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox_comment), chk_alignment, FALSE, FALSE, 0); gtk_table_attach(GTK_TABLE (tag_table), label_comment, 0, 1, 5, 7, GTK_FILL, GTK_FILL|GTK_EXPAND, 0, 0); gtk_table_attach(GTK_TABLE (tag_table), hbox_comment, 1, 2, 5, 7, GTK_FILL|GTK_EXPAND, GTK_FILL|GTK_EXPAND, 0, 0); gtk_table_attach(GTK_TABLE (tag_table), label_file, 0, 1, 7, 8, GTK_FILL, GTK_SHRINK, 0, 0); gtk_table_attach(GTK_TABLE (tag_table), entry_file, 1, 2, 7, 8, GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0); /* The main edit dialog */ dialog = gtk_dialog_new_with_buttons(_("Edit tags"), GTK_WINDOW(cwin->mainwindow), GTK_DIALOG_MODAL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_window_set_default_size(GTK_WINDOW (dialog), 450, -1); /* Add to the dialog's main vbox */ gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), tag_table); /* Fill in initial entries */ if (otag->title) gtk_entry_set_text(GTK_ENTRY(entry_title), otag->title); if (otag->artist) gtk_entry_set_text(GTK_ENTRY(entry_artist), otag->artist); if (otag->album) gtk_entry_set_text(GTK_ENTRY(entry_album), otag->album); if (otag->genre) gtk_entry_set_text(GTK_ENTRY(entry_genre), otag->genre); if (otag->track_no > 0) gtk_spin_button_set_value(GTK_SPIN_BUTTON(entry_tno), (int)otag->track_no); if (otag->year > 0) gtk_spin_button_set_value(GTK_SPIN_BUTTON(entry_year), (int)otag->year); if (otag->comment) gtk_text_buffer_set_text (buffer, otag->comment, -1); if (file) { gtk_entry_set_text(GTK_ENTRY(entry_file), file); gtk_editable_set_position(GTK_EDITABLE(entry_file), strlen(file)); gtk_dialog_add_button(GTK_DIALOG(dialog), _("Details"), GTK_RESPONSE_HELP); } else gtk_widget_set_sensitive(GTK_WIDGET(entry_file), FALSE); /* Connect to check the save changes when change the entry. */ g_signal_connect(G_OBJECT(entry_title), "changed", G_CALLBACK(check_entry), chk_title); g_signal_connect(G_OBJECT(entry_artist), "changed", G_CALLBACK(check_entry), chk_artist); g_signal_connect(G_OBJECT(entry_album), "changed", G_CALLBACK(check_entry), chk_album); g_signal_connect(G_OBJECT(entry_genre), "changed", G_CALLBACK(check_entry), chk_genre); g_signal_connect(G_OBJECT(entry_tno), "changed", G_CALLBACK(check_entry), chk_tno); g_signal_connect(G_OBJECT(entry_year), "changed", G_CALLBACK(check_entry), chk_year); g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(check_entry), chk_comment); /* Save changes when press enter. */ gtk_entry_set_activates_default (GTK_ENTRY(entry_title), TRUE); gtk_entry_set_activates_default (GTK_ENTRY(entry_artist), TRUE); gtk_entry_set_activates_default (GTK_ENTRY(entry_album), TRUE); gtk_entry_set_activates_default (GTK_ENTRY(entry_genre), TRUE); gtk_entry_set_activates_default (GTK_ENTRY(entry_tno), TRUE); gtk_entry_set_activates_default (GTK_ENTRY(entry_year), TRUE); /* Connect to set clear check when click the icon. */ g_signal_connect (G_OBJECT(entry_title), "icon-press", G_CALLBACK (clear_pressed), NULL); g_signal_connect (G_OBJECT(entry_artist), "icon-press", G_CALLBACK (clear_pressed), NULL); g_signal_connect (G_OBJECT(entry_album), "icon-press", G_CALLBACK (clear_pressed), NULL); g_signal_connect (G_OBJECT(entry_genre), "icon-press", G_CALLBACK (clear_pressed), NULL); g_signal_connect (G_OBJECT(entry_file), "icon-press", G_CALLBACK (directory_pressed), file); /* Genereate storage of gtk_entry and cwin, * and add popup menu to copy selection to tags. */ storage = g_object_new(G_TYPE_OBJECT, NULL); g_object_set_data(storage, "entry_title", entry_title); g_object_set_data(storage, "entry_artist", entry_artist); g_object_set_data(storage, "entry_album", entry_album); g_object_set_data(storage, "entry_genre", entry_genre); g_object_set_data(storage, "entry_comment", entry_comment); g_object_set_data(storage, "entry_file", entry_file); g_object_set_data(storage, "cwin", cwin); g_signal_connect (G_OBJECT(entry_file), "populate-popup", G_CALLBACK (file_entry_populate_popup), storage); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); gtk_widget_show_all(dialog); while ((result = gtk_dialog_run (GTK_DIALOG (dialog))) && (result != GTK_RESPONSE_CANCEL) && (result != GTK_RESPONSE_OK) && (result != GTK_RESPONSE_DELETE_EVENT)) { if(result == GTK_RESPONSE_HELP){ if (g_str_has_prefix(file, "cdda://")) mobj = new_musicobject_from_cdda(cwin, otag->track_no); else { uri = sanitize_string_sqlite3(file); if ((location_id = find_location_db(uri, cwin))) mobj = new_musicobject_from_db(location_id, cwin); else mobj = new_musicobject_from_file(file); } track_properties(mobj, cwin); } } switch (result) { case GTK_RESPONSE_OK: if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk_tno))) { ntag->track_no = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(entry_tno)); changed |= TAG_TNO_CHANGED; } if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk_title))) { ntag->title = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry_title))); changed |= TAG_TITLE_CHANGED; } if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk_artist))) { ntag->artist = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry_artist))); changed |= TAG_ARTIST_CHANGED; } if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk_album))) { ntag->album = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry_album))); changed |= TAG_ALBUM_CHANGED; } if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk_genre))) { ntag->genre = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry_genre))); changed |= TAG_GENRE_CHANGED; } if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk_year))) { ntag->year = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(entry_year)); changed |= TAG_YEAR_CHANGED; } if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(chk_comment))) { gtk_text_buffer_get_start_iter (buffer, &start); gtk_text_buffer_get_end_iter (buffer, &end); ntag->comment = g_strdup(gtk_text_buffer_get_text (buffer, &start, &end, FALSE)); changed |= TAG_COMMENT_CHANGED; } break; case GTK_RESPONSE_DELETE_EVENT: break; case GTK_RESPONSE_CANCEL: break; default: break; } gtk_widget_destroy(dialog); if (mobj) delete_musicobject(mobj); g_free(uri); return changed; }
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); }