⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cddb_lookup.c

📁 Aqualung is an advanced music player primarily targeted for the GNU/Linux operating system, but als
💻 C
📖 第 1 页 / 共 3 页
字号:
/*                                                     -*- linux-c -*-    Copyright (C) 2004 Tom Szilagyi    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    $Id: cddb_lookup.c,v 1.23 2006/09/26 12:46:19 peterszilagyi Exp $*/#include <config.h>#ifdef HAVE_CDDB#include <stdio.h>#include <stdlib.h>#include <string.h>#include <gtk/gtk.h>#include <cddb/cddb.h>#ifdef _WIN32#include <glib.h>#else#include <pthread.h>#endif /* _WIN32 */#include "common.h"#include "i18n.h"#include "options.h"#include "decoder/file_decoder.h"#include "gui_main.h"#include "music_browser.h"#include "build_store.h"#include "cddb_lookup.h"#define CASE_UP    0#define CASE_DOWN  1extern options_t options;extern GtkWidget* gui_stock_label_button(gchar *blabel, const gchar *bstock);extern GtkWidget * browser_window;extern GtkTreeStore * music_store;extern GtkTreeSelection * music_select;AQUALUNG_THREAD_DECLARE(cddb_thread_id)int cddb_thread_state = CDDB_THREAD_FREE;volatile int cddb_query_aborted = 0;volatile int cddb_data_locked = 0;GtkTreeIter iter_record;GtkWidget * progress_win = NULL;GtkWidget * progress_label;GtkWidget * progbar;int progress_counter = 0;int progress_prev = 0;GtkWidget * combo;GtkListStore * track_store;GtkWidget * artist_entry;GtkWidget * title_entry;GtkWidget * year_entry;GtkWidget * year_spinner;GtkWidget * category_entry;GtkWidget * category_combo;GtkWidget * genre_entry;GtkWidget * ext_entry;int * frames = NULL;int record_length;int track_count;cddb_disc_t ** records = NULL;int record_count;static voidabort_cb(GtkWidget * widget, gpointer data) {	cddb_query_aborted = 1;}static voidcreate_progress_window(void) {	GtkWidget * vbox;	GtkWidget * hbuttonbox;	GtkWidget * hseparator;	GtkWidget * abort_button;	progress_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);        gtk_window_set_title(GTK_WINDOW(progress_win), _("CDDB query"));        gtk_window_set_position(GTK_WINDOW(progress_win), GTK_WIN_POS_CENTER);        gtk_window_resize(GTK_WINDOW(progress_win), 330, 120);        g_signal_connect(G_OBJECT(progress_win), "delete_event",			 G_CALLBACK(abort_cb), NULL);        gtk_container_set_border_width(GTK_CONTAINER(progress_win), 10);		vbox = gtk_vbox_new(FALSE, 0);	gtk_container_add(GTK_CONTAINER(progress_win), vbox);	progress_label = gtk_label_new(_("Retrieving matches from server..."));	gtk_box_pack_start(GTK_BOX(vbox), progress_label, FALSE, FALSE, 0);		progbar = gtk_progress_bar_new();	gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progbar), _("Connecting to CDDB server..."));	gtk_box_pack_start(GTK_BOX(vbox), progbar, FALSE, FALSE, 6);	        hseparator = gtk_hseparator_new ();        gtk_widget_show (hseparator);        gtk_box_pack_start (GTK_BOX (vbox), hseparator, FALSE, TRUE, 5);	hbuttonbox = gtk_hbutton_box_new();	gtk_box_pack_end(GTK_BOX(vbox), hbuttonbox, FALSE, TRUE, 0);	gtk_button_box_set_layout(GTK_BUTTON_BOX(hbuttonbox), GTK_BUTTONBOX_END);        abort_button = gui_stock_label_button(_("Abort"), GTK_STOCK_CANCEL);        g_signal_connect(G_OBJECT(abort_button), "clicked",			 G_CALLBACK(abort_cb), NULL);  	gtk_container_add(GTK_CONTAINER(hbuttonbox), abort_button);           gtk_widget_grab_focus(abort_button);	gtk_widget_show_all(progress_win);}static voiddestroy_progress_window() {	gtk_widget_destroy(progress_win);	progress_win = NULL;}static intinit_query_data() {	GtkTreeIter iter_track;	char * pfile;	char file[MAXLEN];	int i;	float duration = 0.0f;	float length = 0.0f;	float fr_offset = SECONDS_TO_FRAMES(2.0f); /* leading 2 secs in frames */	track_count = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(music_store), &iter_record);	if ((frames = (int *)malloc(sizeof(int) * track_count)) == NULL) {		fprintf(stderr, "cddb_lookup.c: init_query_data(): malloc error\n");		return 1;	}	for (i = 0; gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(music_store),						  &iter_track, &iter_record, i); i++) {		gtk_tree_model_get(GTK_TREE_MODEL(music_store),				   &iter_track, 2, &pfile, 4, &duration, -1);		strncpy(file, pfile, MAXLEN-1);		g_free(pfile);		if (duration == 0.0f) {			if ((duration = get_file_duration(file)) == 0.0f) {				return 1;			}			gtk_tree_store_set(music_store, &iter_track, 4, duration, -1);			music_store_mark_changed(&iter_track);		}		frames[i] = (int)fr_offset;		length += duration;		fr_offset += SECONDS_TO_FRAMES(duration);	}	record_length = length;	return 0;}static intinit_query_data_from_tracklist(build_track_t * tracks) {	int i;	float length = 0.0f;	float fr_offset = SECONDS_TO_FRAMES(2.0f); /* leading 2 secs in frames */	build_track_t * ptrack = NULL;	for (track_count = 0, ptrack = tracks; ptrack; track_count++, ptrack = ptrack->next);	if ((frames = (int *)malloc(sizeof(int) * track_count)) == NULL) {		fprintf(stderr, "cddb_lookup.c: init_query_data_from_tracklist(): malloc error\n");		return 1;	}	for (i = 0, ptrack = tracks; ptrack; i++, ptrack = ptrack->next) {		frames[i] = (int)fr_offset;		length += ptrack->duration;		fr_offset += SECONDS_TO_FRAMES(ptrack->duration);	}	record_length = length;	return 0;}static voidload_disc(cddb_disc_t * disc) {	GtkTreeIter iter;	char str[MAXLEN];	int i;	gtk_entry_set_text(GTK_ENTRY(artist_entry), cddb_disc_get_artist(disc));	gtk_entry_set_text(GTK_ENTRY(title_entry), cddb_disc_get_title(disc));	snprintf(str, MAXLEN-1, "%d", cddb_disc_get_year(disc));	gtk_entry_set_text(GTK_ENTRY(year_entry), str);	gtk_entry_set_text(GTK_ENTRY(category_entry), cddb_disc_get_category_str(disc));	gtk_entry_set_text(GTK_ENTRY(genre_entry), cddb_disc_get_genre(disc));	gtk_entry_set_text(GTK_ENTRY(ext_entry), cddb_disc_get_ext_data(disc));	gtk_list_store_clear(GTK_LIST_STORE(track_store));	for (i = 0; i < track_count; i++) {		gtk_list_store_append(track_store, &iter);		gtk_list_store_set(track_store, &iter,				   0, cddb_track_get_title(cddb_disc_get_track(disc, i)), -1);	}}static voidadd_to_comments(GtkWidget * widget, gpointer data) {	char * pcomment;	char comment[MAXLEN];	if (data == NULL) return;	gtk_tree_model_get(GTK_TREE_MODEL(music_store), &iter_record, 3, &pcomment, -1);	comment[0] = '\0';	if (pcomment != NULL) {		strncpy(comment, pcomment, MAXLEN-1);	}	strncat(comment, (char *)data, MAXLEN-1);	gtk_tree_store_set(music_store, &iter_record, 3, comment, -1);	tree_selection_changed_cb(music_select, NULL);	music_store_mark_changed(&iter_record);}static voidimport_as_artist(GtkWidget * widget, gpointer data) {	GtkTreeIter iter;	GtkTreePath * path;	path = gtk_tree_model_get_path(GTK_TREE_MODEL(music_store), &iter_record);	gtk_tree_path_up(path);	gtk_tree_model_get_iter(GTK_TREE_MODEL(music_store), &iter, path);	gtk_tree_store_set(music_store, &iter, 0, gtk_entry_get_text(GTK_ENTRY(artist_entry)), -1);	music_store_mark_changed(&iter);}static voidimport_as_title(GtkWidget * widget, gpointer data) {	gtk_tree_store_set(music_store, &iter_record, 0, gtk_entry_get_text(GTK_ENTRY(title_entry)), -1);	music_store_mark_changed(&iter_record);}static voidimport_as_sort_key(GtkWidget * widget, gpointer data) {	gtk_tree_store_set(music_store, &iter_record, 1, gtk_entry_get_text(GTK_ENTRY(year_entry)), -1);	music_store_mark_changed(&iter_record);}static voidchanged_combo(GtkWidget * widget, gpointer * data) {	int i = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));	if (i >= 0 && i < record_count) {		load_disc(records[i]);	}}static voidcell_edited_callback(GtkCellRendererText * cell, gchar * path, gchar * text, gpointer data) {	GtkTreeIter iter;	if (gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(track_store), &iter, path)) {		gtk_list_store_set(track_store, &iter, 0, text, -1);	}}static voidcreate_cddb_dialog(void) {	GtkWidget * dialog;	GtkWidget * table;	GtkWidget * hbox;	GtkWidget * label;	GtkWidget * button;	GtkWidget * track_list;	GtkWidget * viewport;	GtkWidget * scrollwin;	GtkCellRenderer * renderer;	GtkTreeViewColumn * column;	GtkTreeIter iter_track;	GtkTreeIter iter_trlist;	int i;	char text[MAXLEN];        dialog = gtk_dialog_new_with_buttons(_("CDDB query"),					     GTK_WINDOW(browser_window),					     GTK_DIALOG_DESTROY_WITH_PARENT,					     GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,					     GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,					     NULL);	gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);        gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_REJECT);	gtk_window_set_modal(GTK_WINDOW(dialog), FALSE);	table = gtk_table_new(8, 3, FALSE);        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table, FALSE, FALSE, 2);	hbox = gtk_hbox_new(FALSE, 0);	gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 5, 3);	label = gtk_label_new(_("Matches:"));        gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2);	combo = gtk_combo_box_new_text();	for (i = 0; i < record_count; i++) {		snprintf(text, MAXLEN, "%d. %s: %s (%s)",			 i + 1,			 cddb_disc_get_artist(records[i]),			 cddb_disc_get_title(records[i]),			 cddb_disc_get_category_str(records[i]));		gtk_combo_box_append_text(GTK_COMBO_BOX(combo), text);	}	gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);	g_signal_connect(combo, "changed", G_CALLBACK(changed_combo), NULL);			 	gtk_table_attach(GTK_TABLE(table), combo, 1, 3, 0, 1, GTK_FILL, GTK_FILL, 5, 3);	hbox = gtk_hbox_new(FALSE, 0);	gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 5, 3);	label = gtk_label_new(_("Artist:"));        gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2);	artist_entry = gtk_entry_new();	gtk_table_attach(GTK_TABLE(table), artist_entry, 1, 2, 1, 2,			 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 5, 3);	button = gtk_button_new_with_label(_("Import as Artist"));	g_signal_connect(G_OBJECT(button), "clicked",			 G_CALLBACK(import_as_artist), NULL);	gtk_table_attach(GTK_TABLE(table), button, 2, 3, 1, 2, GTK_FILL, GTK_FILL, 5, 3);	hbox = gtk_hbox_new(FALSE, 0);	gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 5, 3);	label = gtk_label_new(_("Title:"));        gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2);	title_entry = gtk_entry_new();	gtk_table_attach(GTK_TABLE(table), title_entry, 1, 2, 2, 3,			 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 5, 3);	button = gtk_button_new_with_label(_("Import as Title"));	g_signal_connect(G_OBJECT(button), "clicked",			 G_CALLBACK(import_as_title), NULL);	gtk_table_attach(GTK_TABLE(table), button, 2, 3, 2, 3, GTK_FILL, GTK_FILL, 5, 3);	hbox = gtk_hbox_new(FALSE, 0);	gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, 3, 4, GTK_FILL, GTK_FILL, 5, 3);	label = gtk_label_new(_("Year:"));        gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2);	year_entry = gtk_entry_new();	gtk_table_attach(GTK_TABLE(table), year_entry, 1, 2, 3, 4,			 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 5, 3);	button = gtk_button_new_with_label(_("Import as Sort Key"));	g_signal_connect(G_OBJECT(button), "clicked",			 G_CALLBACK(import_as_sort_key), NULL);	gtk_table_attach(GTK_TABLE(table), button, 2, 3, 3, 4, GTK_FILL, GTK_FILL, 5, 3);	hbox = gtk_hbox_new(FALSE, 0);	gtk_table_attach(GTK_TABLE(table), hbox, 0, 1, 4, 5, GTK_FILL, GTK_FILL, 5, 3);	label = gtk_label_new(_("Category:"));        gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2);	category_entry = gtk_entry_new();	gtk_table_attach(GTK_TABLE(table), category_entry, 1, 2, 4, 5,			 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 5, 3);	button = gtk_button_new_with_label(_("Add to Comments"));	g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(add_to_comments),			 (gpointer)gtk_entry_get_text(GTK_ENTRY(category_entry)));	gtk_table_attach(GTK_TABLE(table), button, 2, 3, 4, 5, GTK_FILL, GTK_FILL, 5, 3);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -