Mercurial > audlegacy
annotate src/audacious/ui_fileinfo.c @ 2399:9b7b11176d4e trunk
[svn] - should not pass null fd to input plugins.
author | yaz |
---|---|
date | Wed, 24 Jan 2007 18:40:07 -0800 |
parents | ab2b1b6f6179 |
children | 0fd7f4f969ad |
rev | line source |
---|---|
2313 | 1 /* |
2 * Audacious: A cross-platform multimedia player | |
3 * Copyright (c) 2006 William Pitcock, Tony Vroon, George Averill, | |
4 * Giacomo Lozito, Derek Pomery and Yoshiki Yazawa. | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; under version 2 of the License. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program; if not, write to the Free Software | |
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
18 * 02110-1301, USA. | |
19 */ | |
20 | |
21 #ifdef HAVE_CONFIG_H | |
22 # include "config.h" | |
23 #endif | |
24 | |
25 #include <glib.h> | |
26 #include <glib/gi18n.h> | |
27 #include <gtk/gtk.h> | |
28 #include <glade/glade.h> | |
29 #include <string.h> | |
30 #include <stddef.h> | |
31 #include <stdio.h> | |
32 #include <sys/types.h> | |
33 #include <dirent.h> | |
34 #include <unistd.h> | |
35 #include <errno.h> | |
36 #include <sys/types.h> | |
37 #include <sys/stat.h> | |
38 | |
39 #include "glade.h" | |
40 | |
41 #include "plugin.h" | |
42 #include "pluginenum.h" | |
43 #include "input.h" | |
44 #include "effect.h" | |
2385
ab2b1b6f6179
[svn] - add missing inclusion of strings.h where necessary, do not export main.h and export strings.h
giacomo
parents:
2348
diff
changeset
|
45 #include "strings.h" |
2313 | 46 #include "general.h" |
47 #include "output.h" | |
48 #include "visualization.h" | |
49 | |
50 #include "main.h" | |
51 #include "libaudacious/urldecode.h" | |
52 #include "util.h" | |
53 #include "dnd.h" | |
54 #include "titlestring.h" | |
55 | |
56 #include "libaudacious/configdb.h" | |
57 | |
58 #include "playlist.h" | |
59 | |
60 #include "ui_main.h" | |
61 #include "ui_playlist.h" | |
62 #include "build_stamp.h" | |
63 #include "ui_fileinfo.h" | |
64 #include "ui_playlist.h" | |
65 | |
66 GtkWidget *fileinfo_win; | |
67 | |
68 static void | |
69 fileinfo_entry_set_text(const char *entry, const char *text) | |
70 { | |
71 GladeXML *xml = g_object_get_data(G_OBJECT(fileinfo_win), "glade-xml"); | |
72 GtkWidget *widget = glade_xml_get_widget(xml, entry); | |
73 | |
74 if (xml == NULL || widget == NULL) | |
75 return; | |
76 | |
77 gtk_entry_set_text(GTK_ENTRY(widget), text); | |
78 } | |
79 | |
80 static void | |
81 fileinfo_entry_set_text_free(const char *entry, char *text) | |
82 { | |
83 GladeXML *xml = g_object_get_data(G_OBJECT(fileinfo_win), "glade-xml"); | |
84 GtkWidget *widget = glade_xml_get_widget(xml, entry); | |
85 | |
86 if (xml == NULL || widget == NULL) | |
87 return; | |
88 | |
89 gtk_entry_set_text(GTK_ENTRY(widget), text); | |
90 | |
91 g_free(text); | |
92 } | |
93 | |
94 static void | |
95 fileinfo_entry_set_image(const char *entry, const char *text) | |
96 { | |
97 GladeXML *xml = g_object_get_data(G_OBJECT(fileinfo_win), "glade-xml"); | |
98 GtkWidget *widget = glade_xml_get_widget(xml, entry); | |
99 GdkPixbuf *pixbuf; | |
100 int width, height; | |
101 double aspect; | |
102 GdkPixbuf *pixbuf2; | |
103 | |
104 if (xml == NULL || widget == NULL) | |
105 return; | |
106 | |
107 pixbuf = gdk_pixbuf_new_from_file(text, NULL); | |
108 | |
109 if (pixbuf == NULL) | |
110 return; | |
111 | |
112 width = gdk_pixbuf_get_width(GDK_PIXBUF(pixbuf)); | |
113 height = gdk_pixbuf_get_height(GDK_PIXBUF(pixbuf)); | |
114 | |
115 if(strcmp(DATA_DIR "/images/audio.png", text)) | |
116 { | |
117 if(width == 0) | |
118 width = 1; | |
119 aspect = (double)height / (double)width; | |
120 if(aspect > 1.0) { | |
121 height = (int)(cfg.filepopup_pixelsize * aspect); | |
122 width = cfg.filepopup_pixelsize; | |
123 } else { | |
124 height = cfg.filepopup_pixelsize; | |
125 width = (int)(cfg.filepopup_pixelsize / aspect); | |
126 } | |
127 pixbuf2 = gdk_pixbuf_scale_simple(GDK_PIXBUF(pixbuf), width, height, GDK_INTERP_BILINEAR); | |
128 g_object_unref(G_OBJECT(pixbuf)); | |
129 pixbuf = pixbuf2; | |
130 } | |
131 | |
132 gtk_image_set_from_pixbuf(GTK_IMAGE(widget), GDK_PIXBUF(pixbuf)); | |
133 g_object_unref(G_OBJECT(pixbuf)); | |
134 } | |
135 | |
136 void fileinfo_hide(gpointer unused) | |
137 { | |
138 gtk_widget_hide(fileinfo_win); | |
139 | |
140 /* Clear it out. */ | |
141 fileinfo_entry_set_text("entry_title", ""); | |
142 fileinfo_entry_set_text("entry_artist", ""); | |
143 fileinfo_entry_set_text("entry_album", ""); | |
144 fileinfo_entry_set_text("entry_comment", ""); | |
145 fileinfo_entry_set_text("entry_genre", ""); | |
146 fileinfo_entry_set_text("entry_year", ""); | |
147 fileinfo_entry_set_text("entry_track", ""); | |
148 fileinfo_entry_set_text("entry_location", ""); | |
149 | |
150 fileinfo_entry_set_image("image_artwork", DATA_DIR "/images/audio.png"); | |
151 } | |
152 | |
153 void | |
154 create_fileinfo_window(void) | |
155 { | |
156 const gchar *glade_file = DATA_DIR "/glade/fileinfo.glade"; | |
157 GladeXML *xml; | |
158 GtkWidget *widget; | |
159 | |
160 xml = glade_xml_new_or_die(_("Track Information Window"), glade_file, NULL, NULL); | |
161 | |
162 glade_xml_signal_autoconnect(xml); | |
163 | |
164 fileinfo_win = glade_xml_get_widget(xml, "fileinfo_win"); | |
165 g_object_set_data(G_OBJECT(fileinfo_win), "glade-xml", xml); | |
166 gtk_window_set_transient_for(GTK_WINDOW(fileinfo_win), GTK_WINDOW(mainwin)); | |
167 | |
168 widget = glade_xml_get_widget(xml, "image_artwork"); | |
169 gtk_image_set_from_file(GTK_IMAGE(widget), DATA_DIR "/images/audio.png"); | |
170 | |
171 widget = glade_xml_get_widget(xml, "btn_close"); | |
172 g_signal_connect(G_OBJECT(widget), "clicked", (GCallback) fileinfo_hide, NULL); | |
173 } | |
174 | |
175 void | |
176 fileinfo_show_for_tuple(TitleInput *tuple) | |
177 { | |
178 gchar *tmp = NULL; | |
179 | |
180 if (tuple == NULL) | |
181 return; | |
182 | |
183 gtk_widget_realize(fileinfo_win); | |
184 | |
185 if (tuple->track_name) | |
186 fileinfo_entry_set_text("entry_title", tuple->track_name); | |
187 if (tuple->performer) | |
188 fileinfo_entry_set_text("entry_artist", tuple->performer); | |
189 if (tuple->album_name) | |
190 fileinfo_entry_set_text("entry_album", tuple->album_name); | |
191 if (tuple->comment) | |
192 fileinfo_entry_set_text("entry_comment", tuple->comment); | |
193 if (tuple->genre) | |
194 fileinfo_entry_set_text("entry_genre", tuple->genre); | |
195 | |
196 tmp = g_strdup_printf("%s/%s", tuple->file_path, tuple->file_name); | |
197 if(tmp){ | |
198 fileinfo_entry_set_text_free("entry_location", str_to_utf8(tmp)); | |
199 g_free(tmp); | |
200 tmp = NULL; | |
201 } | |
202 | |
203 if (tuple->year != 0) | |
204 fileinfo_entry_set_text_free("entry_year", g_strdup_printf("%d", tuple->year)); | |
205 | |
206 if (tuple->track_number != 0) | |
207 fileinfo_entry_set_text_free("entry_track", g_strdup_printf("%d", tuple->track_number)); | |
208 | |
209 tmp = fileinfo_recursive_get_image(tuple->file_path, tuple->file_name, 0); | |
210 | |
211 if(tmp) | |
212 { | |
213 fileinfo_entry_set_image("image_artwork", tmp); | |
214 g_free(tmp); | |
215 } | |
216 | |
217 gtk_widget_show(fileinfo_win); | |
218 } | |
219 | |
220 static gboolean | |
221 has_front_cover_extension(const gchar *name) | |
222 { | |
223 char *ext; | |
224 | |
225 ext = strrchr(name, '.'); | |
226 if (!ext) { | |
227 /* No file extension */ | |
228 return FALSE; | |
229 } | |
230 | |
231 return g_strcasecmp(ext, ".jpg") == 0 || | |
232 g_strcasecmp(ext, ".jpeg") == 0 || | |
233 g_strcasecmp(ext, ".png") == 0; | |
234 } | |
235 | |
236 static gboolean | |
237 cover_name_filter(const gchar *name, const gchar *filter, const gboolean ret_on_empty) | |
238 { | |
239 gboolean result = FALSE; | |
240 gchar **splitted; | |
241 gchar *current; | |
242 gchar *lname; | |
243 gint i; | |
244 | |
245 if (!filter || strlen(filter) == 0) { | |
246 return ret_on_empty; | |
247 } | |
248 | |
249 splitted = g_strsplit(filter, ",", 0); | |
250 | |
251 lname = g_strdup(name); | |
252 g_strdown(lname); | |
253 | |
254 for (i = 0; !result && (current = splitted[i]); i++) { | |
255 gchar *stripped = g_strstrip(g_strdup(current)); | |
256 g_strdown(stripped); | |
257 | |
258 result = result || strstr(lname, stripped); | |
259 | |
260 g_free(stripped); | |
261 } | |
262 | |
263 g_free(lname); | |
264 g_strfreev(splitted); | |
265 | |
266 return result; | |
267 } | |
268 | |
269 /* Check wether it's an image we want */ | |
270 static gboolean | |
271 is_front_cover_image(const gchar *imgfile) | |
272 { | |
273 return cover_name_filter(imgfile, cfg.cover_name_include, TRUE) && | |
274 !cover_name_filter(imgfile, cfg.cover_name_exclude, FALSE); | |
275 } | |
276 | |
277 static gboolean | |
278 is_file_image(const gchar *imgfile, const gchar *file_name) | |
279 { | |
280 char *imgfile_ext, *file_name_ext; | |
281 size_t imgfile_len, file_name_len; | |
282 | |
283 imgfile_ext = strrchr(imgfile, '.'); | |
284 if (!imgfile_ext) { | |
285 /* No file extension */ | |
286 return FALSE; | |
287 } | |
288 | |
289 file_name_ext = strrchr(file_name, '.'); | |
290 if (!file_name_ext) { | |
291 /* No file extension */ | |
292 return FALSE; | |
293 } | |
294 | |
295 imgfile_len = (imgfile_ext - imgfile); | |
296 file_name_len = (file_name_ext - file_name); | |
297 | |
298 if (imgfile_len == file_name_len) { | |
299 return (g_ascii_strncasecmp(imgfile, file_name, imgfile_len) == 0); | |
300 } else { | |
301 return FALSE; | |
302 } | |
303 } | |
304 | |
305 gchar* | |
306 fileinfo_recursive_get_image(const gchar* path, | |
307 const gchar* file_name, gint depth) | |
308 { | |
309 GDir *d; | |
310 | |
311 if (cfg.recurse_for_cover && depth > cfg.recurse_for_cover_depth) | |
312 return NULL; | |
313 | |
314 d = g_dir_open(path, 0, NULL); | |
315 | |
316 if (d) { | |
317 const gchar *f; | |
318 | |
319 if (cfg.use_file_cover && file_name) { | |
320 /* Look for images matching file name */ | |
2328 | 321 while((f = g_dir_read_name(d))) { |
2313 | 322 gchar *newpath = g_strconcat(path, "/", f, NULL); |
323 | |
324 if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) && | |
325 has_front_cover_extension(f) && | |
326 is_file_image(f, file_name)) { | |
327 g_dir_close(d); | |
328 return newpath; | |
329 } | |
330 | |
331 g_free(newpath); | |
332 } | |
333 g_dir_rewind(d); | |
334 } | |
335 | |
336 /* Search for files using filter */ | |
2328 | 337 while ((f = g_dir_read_name(d))) { |
2313 | 338 gchar *newpath = g_strconcat(path, "/", f, NULL); |
339 | |
340 if (!g_file_test(newpath, G_FILE_TEST_IS_DIR) && | |
341 has_front_cover_extension(f) && | |
342 is_front_cover_image(f)) { | |
343 g_dir_close(d); | |
344 return newpath; | |
345 } | |
346 | |
347 g_free(newpath); | |
348 } | |
349 g_dir_rewind(d); | |
350 | |
351 /* checks whether recursive or not. */ | |
352 if (!cfg.recurse_for_cover) { | |
353 g_dir_close(d); | |
354 return NULL; | |
355 } | |
356 | |
357 /* Descend into directories recursively. */ | |
2328 | 358 while ((f = g_dir_read_name(d))) { |
2313 | 359 gchar *newpath = g_strconcat(path, "/", f, NULL); |
360 | |
361 if(g_file_test(newpath, G_FILE_TEST_IS_DIR)) { | |
362 gchar *tmp = fileinfo_recursive_get_image(newpath, | |
363 NULL, depth + 1); | |
364 if(tmp) { | |
365 g_free(newpath); | |
366 g_dir_close(d); | |
367 return tmp; | |
368 } | |
369 } | |
370 | |
371 g_free(newpath); | |
372 } | |
373 | |
374 g_dir_close(d); | |
375 } | |
376 | |
377 return NULL; | |
378 } | |
379 | |
380 void | |
381 fileinfo_show_for_path(gchar *path) | |
382 { | |
383 TitleInput *tuple = input_get_song_tuple(path); | |
384 | |
385 if (tuple == NULL) | |
386 return input_file_info_box(path); | |
387 | |
388 fileinfo_show_for_tuple(tuple); | |
389 | |
390 bmp_title_input_free(tuple); | |
391 tuple = NULL; | |
392 } |