Mercurial > audlegacy
changeset 4009:ba6258a39662
icon, codec and quality info added to file info box. Added new tuple field FIELD_MIMETYPE used for icon resolving
author | Eugene Zagidullin <e.asphyx@gmail.com> |
---|---|
date | Sun, 25 Nov 2007 02:07:20 +0300 |
parents | 3496674a54b5 |
children | ce791ae274aa |
files | src/audacious/tuple.c src/audacious/tuple.h src/audacious/ui_fileinfo.c |
diffstat | 3 files changed, 150 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/audacious/tuple.c Sat Nov 24 17:25:51 2007 +0100 +++ b/src/audacious/tuple.c Sun Nov 25 02:07:20 2007 +0300 @@ -51,6 +51,7 @@ { "subsong-id", TUPLE_INT }, { "subsong-num", TUPLE_INT }, + { "mime-type", TUPLE_STRING }, }; static mowgli_heap_t *tuple_heap = NULL;
--- a/src/audacious/tuple.h Sat Nov 24 17:25:51 2007 +0100 +++ b/src/audacious/tuple.h Sun Nov 25 02:07:20 2007 +0300 @@ -52,6 +52,7 @@ FIELD_SUBSONG_ID, FIELD_SUBSONG_NUM, + FIELD_MIMETYPE, /* special field, must always be last */ FIELD_LAST
--- a/src/audacious/ui_fileinfo.c Sat Nov 24 17:25:51 2007 +0100 +++ b/src/audacious/ui_fileinfo.c Sun Nov 25 02:07:20 2007 +0300 @@ -29,6 +29,7 @@ #include <string.h> #include <stddef.h> #include <stdio.h> +#include <stdarg.h> #include <sys/types.h> #include <dirent.h> #include <unistd.h> @@ -71,6 +72,10 @@ GtkWidget *image_artwork; +GtkWidget *image_fileicon; +GtkWidget *label_codec_name; +GtkWidget *label_quality; + static void fileinfo_entry_set_text(GtkWidget *widget, const char *text) { @@ -81,6 +86,25 @@ } static void +fileinfo_label_set_text(GtkWidget *widget, const char *text) +{ + gchar *tmp; + + if (widget == NULL) + return; + + if (text) { + tmp = g_strdup_printf("<span size=\"small\">%s</span>", text); + gtk_label_set_text(GTK_LABEL(widget), tmp); + gtk_label_set_use_markup(GTK_LABEL(widget), TRUE); + g_free(tmp); + } else { + gtk_label_set_text(GTK_LABEL(widget), _("<span size=\"small\">n/a</span>")); + gtk_label_set_use_markup(GTK_LABEL(widget), TRUE); + } +} + +static void fileinfo_entry_set_text_free(GtkWidget *widget, char *text) { if (widget == NULL) @@ -148,6 +172,67 @@ fileinfo_entry_set_image(image_artwork, DATA_DIR "/images/audio.png"); } +GdkPixbuf * +themed_icon_lookup(gint size, const gchar *name, ...) /* NULL-terminated list of icon names */ +{ + GtkIconTheme *icon_theme; + GdkPixbuf *pixbuf; + GError *error = NULL; + gchar *n; + va_list par; + + icon_theme = gtk_icon_theme_get_default (); + //fprintf(stderr, "looking for %s\n", name); + pixbuf = gtk_icon_theme_load_icon (icon_theme, name, size, 0, &error); + if(pixbuf) return pixbuf; + + if(error != NULL) g_error_free(error); + + /* fallback */ + va_start(par, name); + while((n = (gchar*)va_arg(par, gchar *)) != NULL) { + //fprintf(stderr, "looking for %s\n", n); + error = NULL; + pixbuf = gtk_icon_theme_load_icon (icon_theme, n, size, 0, &error); + if(pixbuf) { + //fprintf(stderr, "%s is ok\n", n); + va_end(par); + return pixbuf; + } + if(error != NULL) g_error_free(error); + } + + return NULL; +} + +GdkPixbuf * +mime_icon_lookup(gint size, const gchar *mime_type) /* smart icon resolving routine :) */ +{ + gchar *mime_as_is; /* audio-x-mp3 */ + gchar *mime_gnome; /* gnome-mime-audio-x-mp3 */ + gchar *mime_generic; /* audio-x-generic */ + gchar *mime_gnome_generic; /* gnome-mime-audio */ + + GdkPixbuf *icon = NULL; + + gchar **s = g_strsplit(mime_type, "/", 2); + if(s[1] != NULL) { + mime_as_is = g_strdup_printf("%s-%s", s[0], s[1]); + mime_gnome = g_strdup_printf("gnome-mime-%s-%s", s[0], s[1]); + mime_generic = g_strdup_printf("%s-x-generic", s[0]); + mime_gnome_generic = g_strdup_printf("gnome-mime-%s", s[0]); + //fprintf(stderr, "will look for %s, %s, %s, %s, %s\n", mime_as_is, mime_gnome, mime_generic, mime_gnome_generic, s[0]); + icon = themed_icon_lookup(size, mime_as_is, mime_gnome, mime_generic, mime_gnome_generic, s[0], NULL); /* s[0] is category */ + g_free(mime_gnome_generic); + g_free(mime_generic); + g_free(mime_gnome); + g_free(mime_as_is); + } + g_strfreev(s); + + return icon; +} + void create_fileinfo_window(void) { @@ -162,6 +247,11 @@ GtkWidget *label_year; GtkWidget *label_track; GtkWidget *label_location; + GtkWidget *label_codec; + GtkWidget *label_codec_label; + GtkWidget *label_quality_label; + GtkWidget *codec_hbox; + GtkWidget *codec_table; GtkWidget *table1; GtkWidget *bbox_close; GtkWidget *btn_close; @@ -288,6 +378,53 @@ entry_location = gtk_entry_new(); gtk_container_add(GTK_CONTAINER(alignment), entry_location); + + label_codec = gtk_label_new(_("<span size=\"small\">Codec</span>")); + gtk_box_pack_start (GTK_BOX (vbox2), label_codec, FALSE, FALSE, 0); + gtk_label_set_use_markup(GTK_LABEL(label_codec), TRUE); + gtk_misc_set_alignment(GTK_MISC(label_codec), 0, 0.5); + + alignment = gtk_alignment_new (0.5, 0.5, 1, 1); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 6, 6, 0, 0); + gtk_box_pack_start (GTK_BOX (vbox2), alignment, FALSE, FALSE, 0); + + codec_hbox = gtk_hbox_new(FALSE, 6); + gtk_container_add (GTK_CONTAINER(alignment), codec_hbox); + + image_fileicon = gtk_image_new_from_stock (GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_DIALOG); + gtk_box_pack_start (GTK_BOX (codec_hbox), image_fileicon, FALSE, FALSE, 0); + + codec_table = gtk_table_new(2, 2, FALSE); + gtk_table_set_row_spacings (GTK_TABLE(codec_table), 6); + gtk_table_set_col_spacings (GTK_TABLE(codec_table), 12); + gtk_box_pack_start (GTK_BOX (codec_hbox), codec_table, FALSE, FALSE, 0); + + label_codec_label = gtk_label_new(_("<span size=\"small\">Codec name:</span>")); + gtk_label_set_use_markup(GTK_LABEL(label_codec_label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label_codec_label), 0, 0.5); + label_quality_label = gtk_label_new(_("<span size=\"small\">Quality:</span>")); + gtk_label_set_use_markup(GTK_LABEL(label_quality_label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label_quality_label), 0, 0.5); + + label_codec_name = gtk_label_new(_("<span size=\"small\">n/a</span>")); + gtk_label_set_use_markup(GTK_LABEL(label_codec_name), TRUE); + gtk_misc_set_alignment(GTK_MISC(label_codec_name), 0, 0.5); + label_quality = gtk_label_new(_("<span size=\"small\">n/a</span>")); + gtk_label_set_use_markup(GTK_LABEL(label_quality), TRUE); + gtk_misc_set_alignment(GTK_MISC(label_quality), 0, 0.5); + + gtk_table_attach(GTK_TABLE(codec_table), label_codec_label, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_table_attach(GTK_TABLE(codec_table), label_codec_name, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_table_attach(GTK_TABLE(codec_table), label_quality_label, 0, 1, 1, 2, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_table_attach(GTK_TABLE(codec_table), label_quality, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); bbox_close = gtk_hbutton_box_new(); gtk_box_pack_start(GTK_BOX(vbox1), bbox_close, FALSE, FALSE, 0); @@ -305,6 +442,7 @@ fileinfo_show_for_tuple(Tuple *tuple) { gchar *tmp = NULL; + GdkPixbuf *icon = NULL; if (tuple == NULL) return; @@ -334,6 +472,16 @@ fileinfo_entry_set_text_free(entry_track, g_strdup_printf("%d", tuple_get_int(tuple, FIELD_TRACK_NUMBER, NULL))); + fileinfo_label_set_text(label_codec_name, tuple_get_string(tuple, FIELD_CODEC, NULL)); + fileinfo_label_set_text(label_quality, tuple_get_string(tuple, FIELD_QUALITY, NULL)); + + tmp = (gchar *)tuple_get_string(tuple, FIELD_MIMETYPE, NULL); + icon = mime_icon_lookup(48, tmp ? tmp : "audio/x-generic"); + if (icon) { + if (image_fileicon) gtk_image_set_from_pixbuf (GTK_IMAGE(image_fileicon), icon); + g_object_unref(icon); + } + tmp = fileinfo_recursive_get_image( tuple_get_string(tuple, FIELD_FILE_PATH, NULL), tuple_get_string(tuple, FIELD_FILE_NAME, NULL), 0);