# HG changeset patch # User nemo # Date 1161542300 25200 # Node ID 597bd579d9af613a70c54864f34b0d9b9ae57b28 # Parent 802c9f8461e0ab1a543cf113180430d467e96d36 [svn] Patch by Michael Hanselmann to fetch a per-song image file. diff -r 802c9f8461e0 -r 597bd579d9af ChangeLog --- a/ChangeLog Fri Oct 20 17:00:45 2006 -0700 +++ b/ChangeLog Sun Oct 22 11:38:20 2006 -0700 @@ -1,3 +1,11 @@ +2006-10-21 00:00:45 +0000 William Pitcock + revision [2733] + - enforce extern status here. we do not provide an inlined iir(), so that shouldn't be declared inline. + + trunk/audacious/iir.h | 14 +++++++------- + 1 file changed, 7 insertions(+), 7 deletions(-) + + 2006-10-20 23:58:06 +0000 William Pitcock revision [2731] - icc warning fixes (pass 1) diff -r 802c9f8461e0 -r 597bd579d9af audacious/glade/prefswin.glade --- a/audacious/glade/prefswin.glade Fri Oct 20 17:00:45 2006 -0700 +++ b/audacious/glade/prefswin.glade Sun Oct 22 11:38:20 2006 -0700 @@ -4328,97 +4328,145 @@ False + - - True - 0.5 - 0.5 - 1 - 1 - 0 - 0 - 12 - 0 - - - - True - True - Recursively search for cover - True - GTK_RELIEF_NORMAL - True - False - False - True - - - + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + True + Recursively search for cover + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + + 0 + True + True + - + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 45 + 0 + + + + True + False + 0 + + + True + Search depth: + False + False + GTK_JUSTIFY_LEFT + False + False 0.5 0.5 - 1 - 1 - 0 - 0 - 45 - 0 - - - - True - False - 0 - - - - True - Search depth: - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 4 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - - - - True - True - 1 - 0 - False - GTK_UPDATE_ALWAYS - False - False - 2 0 100 1 10 10 - - - - - - + 4 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + True + True + + + + + + True + True + 1 + 0 + True + GTK_UPDATE_ALWAYS + False + False + 0 0 100 1 10 10 - 0 - False - False + 0 + True + True + + + + + + 0 + False + False + - + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + True + Use per-file cover + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + + 0 + True + True + + + + True GTK_BUTTONBOX_END diff -r 802c9f8461e0 -r 597bd579d9af audacious/main.c --- a/audacious/main.c Fri Oct 20 17:00:45 2006 -0700 +++ b/audacious/main.c Sun Oct 22 11:38:20 2006 -0700 @@ -301,7 +301,8 @@ {"resume_playback_on_startup", &cfg.resume_playback_on_startup, TRUE}, {"playlist_detect", &cfg.playlist_detect, TRUE}, {"show_filepopup_for_tuple", &cfg.show_filepopup_for_tuple, TRUE}, - {"recurse_for_cover", &cfg.recurse_for_cover, TRUE} + {"recurse_for_cover", &cfg.recurse_for_cover, TRUE}, + {"use_file_cover", &cfg.use_file_cover, TRUE}, }; static gint ncfgbent = G_N_ELEMENTS(bmp_boolents); diff -r 802c9f8461e0 -r 597bd579d9af audacious/main.h --- a/audacious/main.h Fri Oct 20 17:00:45 2006 -0700 +++ b/audacious/main.h Sun Oct 22 11:38:20 2006 -0700 @@ -125,6 +125,7 @@ gchar *session_uri_base; gint filepopup_pixelsize; gint filepopup_delay; + gboolean use_file_cover; }; typedef struct _BmpConfig BmpConfig; diff -r 802c9f8461e0 -r 597bd579d9af audacious/prefswin.c --- a/audacious/prefswin.c Fri Oct 20 17:00:45 2006 -0700 +++ b/audacious/prefswin.c Sun Oct 22 11:38:20 2006 -0700 @@ -2038,66 +2038,61 @@ } static void -on_filepopup_for_tuple_settings_clicked(GtkButton *button, gpointer data) +on_recurse_for_cover_toggled(GtkToggleButton *button, gpointer data) { - GladeXML *xml = prefswin_get_xml(); - GtkEntry *cover_name_include = - (GtkEntry*)glade_xml_get_widget(xml, "filepopup_settings_cover_name_include"); - GtkEntry *cover_name_exclude = - (GtkEntry*)glade_xml_get_widget(xml, "filepopup_settings_cover_name_exclude"); - - gtk_entry_set_text(cover_name_include, cfg.cover_name_include); - gtk_entry_set_text(cover_name_exclude, cfg.cover_name_exclude); - - gtk_widget_show(filepopup_settings); -} - -static void -on_recurse_for_cover_depth_realize(GtkSpinButton * button, - gpointer data) -{ - gtk_spin_button_set_value(button, cfg.recurse_for_cover_depth); + gtk_widget_set_sensitive(GTK_WIDGET(data), + gtk_toggle_button_get_active(button)); } static void -on_recurse_for_cover_depth_changed(GtkSpinButton * button, - gpointer data) -{ - cfg.recurse_for_cover_depth = gtk_spin_button_get_value_as_int(button); -} - -static void -on_recurse_for_cover_realize(GtkToggleButton * button, - gpointer data) +on_filepopup_for_tuple_settings_clicked(GtkButton *button, gpointer data) { - gboolean state = cfg.recurse_for_cover; - gtk_toggle_button_set_active(button, state); - gtk_widget_set_sensitive(GTK_WIDGET(data), state); -} - -static void -on_recurse_for_cover_toggled(GtkToggleButton * button, - gpointer data) -{ - gboolean state = gtk_toggle_button_get_active(button); - cfg.recurse_for_cover = state; - gtk_widget_set_sensitive(GTK_WIDGET(data), state); + GladeXML *xml = prefswin_get_xml(); + GtkWidget *widget, *widget2; + + widget = glade_xml_get_widget(xml, "filepopup_settings_cover_name_include"); + gtk_entry_set_text(GTK_ENTRY(widget), cfg.cover_name_include); + + widget = glade_xml_get_widget(xml, "filepopup_settings_cover_name_exclude"); + gtk_entry_set_text(GTK_ENTRY(widget), cfg.cover_name_exclude); + + widget2 = glade_xml_get_widget(xml, "filepopup_settings_recurse_for_cover"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget2), cfg.recurse_for_cover); + + widget = glade_xml_get_widget(xml, "filepopup_settings_recurse_for_cover_depth"); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), cfg.recurse_for_cover_depth); + + widget = glade_xml_get_widget(xml, "filepopup_settings_recurse_for_cover_depth_box"); + on_recurse_for_cover_toggled(GTK_TOGGLE_BUTTON(widget2), widget); + + widget = glade_xml_get_widget(xml, "filepopup_settings_use_file_cover"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), cfg.use_file_cover); + + gtk_widget_show(filepopup_settings); } static void on_filepopup_settings_ok_clicked(GtkButton *button, gpointer data) { GladeXML *xml = prefswin_get_xml(); - GtkEntry *cover_name_include = - (GtkEntry*)glade_xml_get_widget(xml, "filepopup_settings_cover_name_include"); - GtkEntry *cover_name_exclude = - (GtkEntry*)glade_xml_get_widget(xml, "filepopup_settings_cover_name_exclude"); - + GtkWidget *widget; + + widget = glade_xml_get_widget(xml, "filepopup_settings_cover_name_include"); g_free(cfg.cover_name_include); - cfg.cover_name_include = g_strdup(gtk_entry_get_text(cover_name_include)); - + cfg.cover_name_include = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget))); + + widget = glade_xml_get_widget(xml, "filepopup_settings_cover_name_exclude"); g_free(cfg.cover_name_exclude); - cfg.cover_name_exclude = g_strdup(gtk_entry_get_text(cover_name_exclude)); + cfg.cover_name_exclude = g_strdup(gtk_entry_get_text(GTK_ENTRY(widget))); + + widget = glade_xml_get_widget(xml, "filepopup_settings_recurse_for_cover"); + cfg.recurse_for_cover = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + + widget = glade_xml_get_widget(xml, "filepopup_settings_recurse_for_cover_depth"); + cfg.recurse_for_cover_depth = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); + + widget = glade_xml_get_widget(xml, "filepopup_settings_use_file_cover"); + cfg.use_file_cover = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); gtk_widget_hide(filepopup_settings); } @@ -2180,8 +2175,6 @@ FUNC_MAP_ENTRY(on_audio_format_det_cb_realize) FUNC_MAP_ENTRY(on_show_filepopup_for_tuple_realize) FUNC_MAP_ENTRY(on_show_filepopup_for_tuple_toggled) - FUNC_MAP_ENTRY(on_recurse_for_cover_depth_realize) - FUNC_MAP_ENTRY(on_recurse_for_cover_depth_changed) FUNC_MAP_ENTRY(on_filepopup_for_tuple_settings_clicked) FUNC_MAP_ENTRY(on_continue_playback_on_startup_realize) FUNC_MAP_ENTRY(on_continue_playback_on_startup_toggled) @@ -2417,14 +2410,12 @@ /* Create window for filepopup settings */ filepopup_settings = glade_xml_get_widget(xml, "filepopup_for_tuple_settings"); gtk_window_set_transient_for(GTK_WINDOW(filepopup_settings), GTK_WINDOW(prefswin)); - widget = glade_xml_get_widget(xml, "recurse_for_cover_depth_box"); - widget2 = glade_xml_get_widget(xml, "recurse_for_cover"); - g_signal_connect_after(G_OBJECT(widget2), "realize", - G_CALLBACK(on_recurse_for_cover_realize), - widget); - g_signal_connect(G_OBJECT(widget2), "toggled", - G_CALLBACK(on_recurse_for_cover_toggled), - widget); + + widget = glade_xml_get_widget(xml, "filepopup_settings_recurse_for_cover_depth_box"); + widget2 = glade_xml_get_widget(xml, "filepopup_settings_recurse_for_cover"); + g_signal_connect(G_OBJECT(widget2), "toggled", + G_CALLBACK(on_recurse_for_cover_toggled), + widget); } void diff -r 802c9f8461e0 -r 597bd579d9af audacious/ui_fileinfo.c --- a/audacious/ui_fileinfo.c Fri Oct 20 17:00:45 2006 -0700 +++ b/audacious/ui_fileinfo.c Sun Oct 22 11:38:20 2006 -0700 @@ -380,7 +380,7 @@ if (tuple->track_number != 0) fileinfo_entry_set_text_free("entry_track", g_strdup_printf("%d", tuple->track_number)); - tmp = fileinfo_recursive_get_image(tuple->file_path, 0); + tmp = fileinfo_recursive_get_image(tuple->file_path, tuple->file_name, 0); if(tmp) { @@ -392,6 +392,22 @@ } static gboolean +has_front_cover_extension(const gchar *name) +{ + char *ext; + + ext = strrchr(name, '.'); + if (!ext) { + /* No file extension */ + return FALSE; + } + + return g_strcasecmp(ext, ".jpg") == 0 || + g_strcasecmp(ext, ".jpeg") == 0 || + g_strcasecmp(ext, ".png") == 0; +} + +static gboolean cover_name_filter(const gchar *name, const gchar *filter, const gboolean ret_on_empty) { gboolean result = FALSE; @@ -426,29 +442,44 @@ /* Check wether it's an image we want */ static gboolean -is_front_cover_image(const gchar *name) +is_front_cover_image(const gchar *imgfile) { - char *ext; + return cover_name_filter(imgfile, cfg.cover_name_include, TRUE) && + !cover_name_filter(imgfile, cfg.cover_name_exclude, FALSE); +} - ext = strrchr(name, '.'); - if (!ext) { +static gboolean +is_file_image(const gchar *imgfile, const gchar *file_name) +{ + char *imgfile_ext, *file_name_ext; + size_t imgfile_len, file_name_len; + gboolean matches; + + imgfile_ext = strrchr(imgfile, '.'); + if (!imgfile_ext) { /* No file extension */ return FALSE; } - if (g_strcasecmp(ext, ".jpg") != 0 && - g_strcasecmp(ext, ".jpeg") != 0 && - g_strcasecmp(ext, ".png") != 0) { - /* No recognized file extension */ + file_name_ext = strrchr(file_name, '.'); + if (!file_name_ext) { + /* No file extension */ return FALSE; } - return cover_name_filter(name, cfg.cover_name_include, TRUE) && - !cover_name_filter(name, cfg.cover_name_exclude, FALSE); + imgfile_len = (imgfile_ext - imgfile); + file_name_len = (file_name_ext - file_name); + + if (imgfile_len == file_name_len) { + return (g_ascii_strncasecmp(imgfile, file_name, imgfile_len) == 0); + } else { + return FALSE; + } } gchar* -fileinfo_recursive_get_image(const gchar* path, gint depth) +fileinfo_recursive_get_image(const gchar* path, + const gchar* file_name, gint depth) { GDir *d; @@ -458,59 +489,76 @@ d = g_dir_open(path, 0, NULL); if (d) { - const gchar *f = g_dir_read_name(d); - - /* first pass only searches for files. */ - while(f) { - gchar *newpath = g_strdup_printf("%s/%s", path, f); + const gchar *f; - if(!g_file_test(newpath, G_FILE_TEST_IS_DIR)) { - if(is_front_cover_image(f)) { + if (cfg.use_file_cover && file_name) { + /* Look for images matching file name */ + while(f = g_dir_read_name(d)) { + gchar *newpath = g_strconcat(path, "/", f, NULL); + + if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) && + has_front_cover_extension(f) && + is_file_image(f, file_name)) { g_dir_close(d); return newpath; } + + g_free(newpath); } + g_dir_rewind(d); + } + + /* Search for files using filter */ + while (f = g_dir_read_name(d)) { + gchar *newpath = g_strconcat(path, "/", f, NULL); + + if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) && + has_front_cover_extension(f) && + is_front_cover_image(f)) { + g_dir_close(d); + return newpath; + } + g_free(newpath); - f = g_dir_read_name(d); } + g_dir_rewind(d); /* checks whether recursive or not. */ - if(!cfg.recurse_for_cover) { + if (!cfg.recurse_for_cover) { g_dir_close(d); return NULL; } - /* second pass descends directory recursively. */ - g_dir_rewind(d); - f = g_dir_read_name(d); - - while(f) { - gchar *newpath = g_strdup_printf("%s/%s", path, f); + /* Descend into directories recursively. */ + while (f = g_dir_read_name(d)) { + gchar *newpath = g_strconcat(path, "/", f, NULL); if(g_file_test(newpath, G_FILE_TEST_IS_DIR)) { - gchar *tmp = fileinfo_recursive_get_image(newpath, depth+1); + gchar *tmp = fileinfo_recursive_get_image(newpath, + NULL, depth + 1); if(tmp) { g_free(newpath); g_dir_close(d); return tmp; } } + g_free(newpath); - f = g_dir_read_name(d); } g_dir_close(d); - } + } + return NULL; } void filepopup_show_for_tuple(TitleInput *tuple) { - gchar *tmp = NULL; + gchar *tmp = NULL, *fullpath = NULL; gint x, y, x_off = 3, y_off = 3, h, w; - static gchar *lastpath = NULL; + static gchar *last_artwork = NULL; if (tuple == NULL) return; @@ -531,21 +579,29 @@ if (tuple->track_number != 0) filepopup_entry_set_text_free("label_track", g_strdup_printf("%d", tuple->track_number)); - if(strcmp(lastpath?lastpath:"", tuple->file_path)){ - tmp = fileinfo_recursive_get_image(tuple->file_path, 0); - - if(tmp) + if (cfg.use_file_cover) { + /* Use the file name */ + fullpath = g_strconcat(tuple->file_path, "/", tuple->file_name, NULL); + } else { + fullpath = g_strconcat(tuple->file_path, "/", NULL); + } + + if (!last_artwork || strcmp(last_artwork, fullpath)){ + g_free(last_artwork); + last_artwork = g_strdup(fullpath); + + tmp = fileinfo_recursive_get_image(tuple->file_path, tuple->file_name, 0); + if (tmp) { filepopup_entry_set_image("image_artwork", tmp); g_free(tmp); - g_free(lastpath); - lastpath = g_strdup(tuple->file_path); } else { filepopup_entry_set_image("image_artwork", DATA_DIR "/images/audio.png"); - g_free(lastpath); - lastpath = g_strdup(tuple->file_path); } } + + g_free(fullpath); + gdk_window_get_pointer(NULL, &x, &y, NULL); gtk_window_get_size(GTK_WINDOW(filepopup_win), &w, &h); if (gdk_screen_width()-(w+3) < x) x_off = (w*-1)-3; diff -r 802c9f8461e0 -r 597bd579d9af audacious/ui_fileinfo.h --- a/audacious/ui_fileinfo.h Fri Oct 20 17:00:45 2006 -0700 +++ b/audacious/ui_fileinfo.h Sun Oct 22 11:38:20 2006 -0700 @@ -25,7 +25,7 @@ void create_filepopup_window(void); void fileinfo_show_for_tuple(TitleInput *tuple); void filepopup_show_for_tuple(TitleInput *tuple); -gchar* fileinfo_recursive_get_image(const gchar* path, gint depth); +gchar* fileinfo_recursive_get_image(const gchar* path, const gchar* file_name, gint depth); void fileinfo_show_for_path(gchar *path); void filepopup_hide(gpointer unused);