Mercurial > audlegacy-plugins
comparison src/shnplug/gtk.c @ 1305:51bf0e431e02
Add SHNplug.
author | William Pitcock <nenolod@atheme-project.org> |
---|---|
date | Fri, 20 Jul 2007 10:29:54 -0500 |
parents | |
children | f6f5603a0954 |
comparison
equal
deleted
inserted
replaced
1300:c198ae31bb74 | 1305:51bf0e431e02 |
---|---|
1 /* gtk.c - functions to build and display GTK windows | |
2 * Copyright (C) 2000-2007 Jason Jordan <shnutils@freeshell.org> | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * This program is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with this program; if not, write to the Free Software | |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 */ | |
18 | |
19 /* | |
20 * $Id: gtk.c,v 1.27 2007/03/29 00:40:40 jason Exp $ | |
21 */ | |
22 | |
23 #include <stdlib.h> | |
24 #include <glib.h> | |
25 #include <audacious/util.h> | |
26 #include <audacious/configdb.h> | |
27 #include "shorten.h" | |
28 | |
29 #undef XMMS_SHN_LOAD_TEXTFILES | |
30 #ifdef HAVE_DIRENT_H | |
31 # include <sys/types.h> | |
32 # include <dirent.h> | |
33 # ifdef HAVE_OPENDIR | |
34 # ifdef HAVE_READDIR | |
35 # ifdef HAVE_CLOSEDIR | |
36 # define XMMS_SHN_LOAD_TEXTFILES 1 | |
37 # endif | |
38 # endif | |
39 # endif | |
40 #endif | |
41 | |
42 static GtkWidget *shn_configurewin = NULL, | |
43 *about_box, | |
44 *vbox, | |
45 *options_vbox, | |
46 *miscellaneous_vbox, | |
47 *seektables_vbox, | |
48 *bbox, | |
49 *notebook, | |
50 *output_frame, | |
51 *output_vbox, | |
52 *output_label, | |
53 *output_error_stderr, | |
54 *output_error_window, | |
55 *output_error_devnull, | |
56 *misc_frame, | |
57 *misc_vbox, | |
58 *swap_bytes_toggle, | |
59 *verbose_toggle, | |
60 *textfile_toggle, | |
61 *textfile_extensions_entry, | |
62 *textfile_extensions_label, | |
63 *textfile_extensions_hbox, | |
64 *path_frame, | |
65 *path_vbox, | |
66 *path_label, | |
67 *path_entry, | |
68 *path_entry_hbox, | |
69 *path_browse, | |
70 *relative_path_label, | |
71 *relative_path_entry, | |
72 *relative_path_entry_hbox, | |
73 *ok, | |
74 *cancel, | |
75 *apply; | |
76 | |
77 void shn_display_about(void) | |
78 { | |
79 if (about_box != NULL) | |
80 { | |
81 gdk_window_raise(about_box->window); | |
82 return; | |
83 } | |
84 | |
85 about_box = xmms_show_message( | |
86 (gchar *) "About " PACKAGE, | |
87 (gchar *) PACKAGE " version " VERSION "\n" | |
88 "Copyright (C) 2000-2007 Jason Jordan <shnutils@freeshell.org>\n" | |
89 "Portions Copyright (C) 1992-1995 Tony Robinson\n" | |
90 "\n" | |
91 "shorten utilities pages:\n" | |
92 "\n" | |
93 "http://www.etree.org/shnutils/\n" | |
94 "http://shnutils.freeshell.org/", | |
95 (gchar *) "Cool", | |
96 FALSE, NULL, NULL); | |
97 g_signal_connect_swapped(GTK_OBJECT(about_box), "destroy", | |
98 gtk_widget_destroyed, &about_box); | |
99 } | |
100 | |
101 void shn_configurewin_save(void) | |
102 { | |
103 ConfigDb *cfg; | |
104 gchar *filename; | |
105 | |
106 shn_cfg.error_output_method = ERROR_OUTPUT_DEVNULL; | |
107 if (GTK_TOGGLE_BUTTON(output_error_stderr)->active) | |
108 shn_cfg.error_output_method = ERROR_OUTPUT_STDERR; | |
109 else if (GTK_TOGGLE_BUTTON(output_error_window)->active) | |
110 shn_cfg.error_output_method = ERROR_OUTPUT_WINDOW; | |
111 | |
112 g_free(shn_cfg.seek_tables_path); | |
113 shn_cfg.seek_tables_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(path_entry))); | |
114 | |
115 g_free(shn_cfg.relative_seek_tables_path); | |
116 shn_cfg.relative_seek_tables_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(relative_path_entry))); | |
117 | |
118 shn_cfg.verbose = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(verbose_toggle)); | |
119 | |
120 shn_cfg.swap_bytes = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(swap_bytes_toggle)); | |
121 | |
122 shn_cfg.load_textfiles = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(textfile_toggle)); | |
123 | |
124 g_free(shn_cfg.textfile_extensions); | |
125 shn_cfg.textfile_extensions = g_strdup(gtk_entry_get_text(GTK_ENTRY(textfile_extensions_entry))); | |
126 | |
127 filename = g_strconcat(g_get_home_dir(), "/.xmms/config", NULL); | |
128 cfg = bmp_cfg_db_open(); | |
129 bmp_cfg_db_set_int(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.error_output_method_config_name, shn_cfg.error_output_method); | |
130 bmp_cfg_db_set_bool(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.verbose_config_name, shn_cfg.verbose); | |
131 bmp_cfg_db_set_string(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.seek_tables_path_config_name, shn_cfg.seek_tables_path); | |
132 bmp_cfg_db_set_string(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.relative_seek_tables_path_config_name, shn_cfg.relative_seek_tables_path); | |
133 bmp_cfg_db_set_bool(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.swap_bytes_config_name, shn_cfg.swap_bytes); | |
134 bmp_cfg_db_set_bool(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.load_textfiles_config_name, shn_cfg.load_textfiles); | |
135 bmp_cfg_db_set_string(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.textfile_extensions_config_name, shn_cfg.textfile_extensions); | |
136 | |
137 bmp_cfg_db_close(cfg); | |
138 g_free(filename); | |
139 } | |
140 | |
141 void shn_configurewin_apply() | |
142 { | |
143 shn_configurewin_save(); | |
144 } | |
145 | |
146 void shn_configurewin_ok(void) | |
147 { | |
148 shn_configurewin_save(); | |
149 gtk_widget_destroy(shn_configurewin); | |
150 } | |
151 | |
152 void shn_display_configure(void) | |
153 { | |
154 if (shn_configurewin != NULL) | |
155 { | |
156 gdk_window_raise(shn_configurewin->window); | |
157 return; | |
158 } | |
159 | |
160 shn_configurewin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
161 gtk_signal_connect(GTK_OBJECT(shn_configurewin), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &shn_configurewin); | |
162 gtk_window_set_title(GTK_WINDOW(shn_configurewin), (gchar *)"SHN Player Configuration"); | |
163 gtk_window_set_policy(GTK_WINDOW(shn_configurewin), FALSE, FALSE, FALSE); | |
164 gtk_container_border_width(GTK_CONTAINER(shn_configurewin), 10); | |
165 | |
166 vbox = gtk_vbox_new(FALSE, 10); | |
167 gtk_container_add(GTK_CONTAINER(shn_configurewin), vbox); | |
168 | |
169 notebook = gtk_notebook_new(); | |
170 | |
171 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0); | |
172 | |
173 options_vbox = gtk_vbox_new(FALSE, 10); | |
174 gtk_container_set_border_width(GTK_CONTAINER(options_vbox), 5); | |
175 | |
176 seektables_vbox = gtk_vbox_new(FALSE, 10); | |
177 gtk_container_set_border_width(GTK_CONTAINER(seektables_vbox), 5); | |
178 | |
179 miscellaneous_vbox = gtk_vbox_new(FALSE, 10); | |
180 gtk_container_set_border_width(GTK_CONTAINER(miscellaneous_vbox), 5); | |
181 | |
182 /* begin error output box */ | |
183 | |
184 output_frame = gtk_frame_new((gchar *)" Error display options "); | |
185 gtk_container_set_border_width(GTK_CONTAINER(output_frame), 5); | |
186 | |
187 output_vbox = gtk_vbox_new(FALSE, 5); | |
188 gtk_container_set_border_width(GTK_CONTAINER(output_vbox), 5); | |
189 gtk_container_add(GTK_CONTAINER(output_frame), output_vbox); | |
190 | |
191 output_label = gtk_label_new((gchar *)"When an error occurs, display it to:"); | |
192 gtk_misc_set_alignment(GTK_MISC(output_label), 0, 0); | |
193 gtk_label_set_justify(GTK_LABEL(output_label), GTK_JUSTIFY_LEFT); | |
194 gtk_box_pack_start(GTK_BOX(output_vbox), output_label, FALSE, FALSE, 0); | |
195 gtk_widget_show(output_label); | |
196 | |
197 output_error_window = gtk_radio_button_new_with_label(NULL, (gchar *)"a window"); | |
198 if (shn_cfg.error_output_method == ERROR_OUTPUT_WINDOW) | |
199 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(output_error_window), TRUE); | |
200 gtk_box_pack_start(GTK_BOX(output_vbox), output_error_window, FALSE, FALSE, 0); | |
201 gtk_widget_show(output_error_window); | |
202 | |
203 output_error_stderr = gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(output_error_window)), (gchar *)"stderr"); | |
204 if (shn_cfg.error_output_method == ERROR_OUTPUT_STDERR) | |
205 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(output_error_stderr), TRUE); | |
206 gtk_box_pack_start(GTK_BOX(output_vbox), output_error_stderr, FALSE, FALSE, 0); | |
207 gtk_widget_show(output_error_stderr); | |
208 | |
209 output_error_devnull = gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(output_error_window)), (gchar *)"/dev/null"); | |
210 if (shn_cfg.error_output_method == ERROR_OUTPUT_DEVNULL) | |
211 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(output_error_devnull), TRUE); | |
212 gtk_box_pack_start(GTK_BOX(output_vbox), output_error_devnull, FALSE, FALSE, 0); | |
213 gtk_widget_show(output_error_devnull); | |
214 | |
215 gtk_widget_show(output_vbox); | |
216 gtk_widget_show(output_frame); | |
217 | |
218 /* end error output box */ | |
219 | |
220 /* begin misc box */ | |
221 | |
222 misc_frame = gtk_frame_new((gchar *)" Miscellaneous options "); | |
223 gtk_container_set_border_width(GTK_CONTAINER(misc_frame), 5); | |
224 | |
225 misc_vbox = gtk_vbox_new(FALSE, 5); | |
226 gtk_container_set_border_width(GTK_CONTAINER(misc_vbox), 5); | |
227 gtk_container_add(GTK_CONTAINER(misc_frame), misc_vbox); | |
228 | |
229 swap_bytes_toggle = gtk_check_button_new_with_label((gchar *)"Swap audio bytes (toggle if all you hear is static)"); | |
230 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(swap_bytes_toggle), shn_cfg.swap_bytes); | |
231 gtk_box_pack_start(GTK_BOX(misc_vbox), swap_bytes_toggle, FALSE, FALSE, 0); | |
232 gtk_widget_show(swap_bytes_toggle); | |
233 | |
234 verbose_toggle = gtk_check_button_new_with_label((gchar *)"Display debug info to stderr"); | |
235 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(verbose_toggle), shn_cfg.verbose); | |
236 gtk_box_pack_start(GTK_BOX(misc_vbox), verbose_toggle, FALSE, FALSE, 0); | |
237 gtk_widget_show(verbose_toggle); | |
238 | |
239 textfile_toggle = gtk_check_button_new_with_label((gchar *)"Load text files in file information box"); | |
240 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(textfile_toggle), shn_cfg.load_textfiles); | |
241 gtk_box_pack_start(GTK_BOX(misc_vbox), textfile_toggle, FALSE, FALSE, 0); | |
242 gtk_widget_show(textfile_toggle); | |
243 | |
244 textfile_extensions_hbox = gtk_hbox_new(FALSE, 5); | |
245 gtk_container_set_border_width(GTK_CONTAINER(textfile_extensions_hbox), 5); | |
246 gtk_box_pack_start(GTK_BOX(misc_vbox), textfile_extensions_hbox, FALSE, FALSE, 0); | |
247 | |
248 textfile_extensions_label = gtk_label_new((gchar *)" Text file extensions:"); | |
249 gtk_misc_set_alignment(GTK_MISC(textfile_extensions_label), 0, 0); | |
250 gtk_label_set_justify(GTK_LABEL(textfile_extensions_label), GTK_JUSTIFY_LEFT); | |
251 gtk_box_pack_start(GTK_BOX(textfile_extensions_hbox), textfile_extensions_label, FALSE, FALSE, 0); | |
252 gtk_widget_show(textfile_extensions_label); | |
253 | |
254 textfile_extensions_entry = gtk_entry_new(); | |
255 gtk_entry_set_text(GTK_ENTRY(textfile_extensions_entry), shn_cfg.textfile_extensions); | |
256 gtk_box_pack_start(GTK_BOX(textfile_extensions_hbox), textfile_extensions_entry, TRUE, TRUE, 0); | |
257 gtk_widget_show(textfile_extensions_entry); | |
258 | |
259 gtk_widget_show(textfile_extensions_hbox); | |
260 gtk_widget_show(misc_vbox); | |
261 gtk_widget_show(misc_frame); | |
262 | |
263 /* end misc box */ | |
264 | |
265 /* begin seek table path box */ | |
266 | |
267 path_frame = gtk_frame_new((gchar *)" Alternate seek table file locations "); | |
268 gtk_container_set_border_width(GTK_CONTAINER(path_frame), 5); | |
269 | |
270 path_vbox = gtk_vbox_new(FALSE, 5); | |
271 gtk_container_set_border_width(GTK_CONTAINER(path_vbox), 5); | |
272 gtk_container_add(GTK_CONTAINER(path_frame), path_vbox); | |
273 | |
274 relative_path_label = gtk_label_new((gchar *)"Relative seek table path:"); | |
275 gtk_misc_set_alignment(GTK_MISC(relative_path_label), 0, 0); | |
276 gtk_label_set_justify(GTK_LABEL(relative_path_label), GTK_JUSTIFY_LEFT); | |
277 gtk_box_pack_start(GTK_BOX(path_vbox), relative_path_label, FALSE, FALSE, 0); | |
278 gtk_widget_show(relative_path_label); | |
279 | |
280 relative_path_entry_hbox = gtk_hbox_new(FALSE, 5); | |
281 gtk_container_set_border_width(GTK_CONTAINER(relative_path_entry_hbox), 5); | |
282 gtk_box_pack_start(GTK_BOX(path_vbox), relative_path_entry_hbox, TRUE, TRUE, 0); | |
283 | |
284 relative_path_entry = gtk_entry_new(); | |
285 gtk_entry_set_text(GTK_ENTRY(relative_path_entry), shn_cfg.relative_seek_tables_path); | |
286 gtk_box_pack_start(GTK_BOX(relative_path_entry_hbox), relative_path_entry, TRUE, TRUE, 0); | |
287 gtk_widget_show(relative_path_entry); | |
288 | |
289 path_label = gtk_label_new((gchar *)"\nAbsolute seek table path:"); | |
290 gtk_misc_set_alignment(GTK_MISC(path_label), 0, 0); | |
291 gtk_label_set_justify(GTK_LABEL(path_label), GTK_JUSTIFY_LEFT); | |
292 gtk_box_pack_start(GTK_BOX(path_vbox), path_label, FALSE, FALSE, 0); | |
293 gtk_widget_show(path_label); | |
294 | |
295 path_entry_hbox = gtk_hbox_new(FALSE, 5); | |
296 gtk_container_set_border_width(GTK_CONTAINER(path_entry_hbox), 5); | |
297 gtk_box_pack_start(GTK_BOX(path_vbox), path_entry_hbox, TRUE, TRUE, 0); | |
298 | |
299 path_entry = gtk_entry_new(); | |
300 gtk_entry_set_text(GTK_ENTRY(path_entry), shn_cfg.seek_tables_path); | |
301 gtk_box_pack_start(GTK_BOX(path_entry_hbox), path_entry, TRUE, TRUE, 0); | |
302 gtk_widget_show(path_entry); | |
303 | |
304 #if 0 | |
305 path_browse = gtk_button_new_with_label("Browse"); | |
306 gtk_signal_connect(GTK_OBJECT(path_browse), "clicked", GTK_SIGNAL_FUNC(path_browse_cb), NULL); | |
307 gtk_box_pack_start(GTK_BOX(path_entry_hbox), path_browse, FALSE, FALSE, 0); | |
308 gtk_widget_show(path_browse); | |
309 #endif | |
310 | |
311 gtk_widget_show(relative_path_entry_hbox); | |
312 gtk_widget_show(path_entry_hbox); | |
313 gtk_widget_show(path_vbox); | |
314 gtk_widget_show(path_frame); | |
315 | |
316 /* end seek table path box */ | |
317 | |
318 gtk_box_pack_start(GTK_BOX(options_vbox), output_frame, TRUE, TRUE, 0); | |
319 gtk_box_pack_start(GTK_BOX(seektables_vbox), path_frame, TRUE, TRUE, 0); | |
320 gtk_box_pack_start(GTK_BOX(miscellaneous_vbox), misc_frame, TRUE, TRUE, 0); | |
321 | |
322 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), options_vbox, gtk_label_new((gchar *)"Error Display")); | |
323 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), seektables_vbox, gtk_label_new((gchar *)"Seek Tables")); | |
324 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), miscellaneous_vbox, gtk_label_new((gchar *)"Miscellaneous")); | |
325 | |
326 bbox = gtk_hbutton_box_new(); | |
327 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
328 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
329 gtk_box_pack_start(GTK_BOX(vbox), bbox, TRUE, TRUE, 0); | |
330 | |
331 ok = gtk_button_new_with_label((gchar *)"OK"); | |
332 gtk_signal_connect(GTK_OBJECT(ok), "clicked", GTK_SIGNAL_FUNC(shn_configurewin_ok), NULL); | |
333 GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT); | |
334 gtk_box_pack_start(GTK_BOX(bbox), ok, TRUE, TRUE, 0); | |
335 gtk_widget_show(ok); | |
336 gtk_widget_grab_default(ok); | |
337 | |
338 cancel = gtk_button_new_with_label((gchar *)"Cancel"); | |
339 gtk_signal_connect_object(GTK_OBJECT(cancel), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(shn_configurewin)); | |
340 GTK_WIDGET_SET_FLAGS(cancel, GTK_CAN_DEFAULT); | |
341 gtk_box_pack_start(GTK_BOX(bbox), cancel, TRUE, TRUE, 0); | |
342 gtk_widget_show(cancel); | |
343 | |
344 apply = gtk_button_new_with_label((gchar *)"Apply"); | |
345 gtk_signal_connect_object(GTK_OBJECT(apply), "clicked", GTK_SIGNAL_FUNC(shn_configurewin_apply), NULL); | |
346 GTK_WIDGET_SET_FLAGS(apply, GTK_CAN_DEFAULT); | |
347 gtk_box_pack_start(GTK_BOX(bbox), apply, TRUE, TRUE, 0); | |
348 gtk_widget_show(apply); | |
349 | |
350 gtk_widget_show(bbox); | |
351 gtk_widget_show(options_vbox); | |
352 gtk_widget_show(seektables_vbox); | |
353 gtk_widget_show(miscellaneous_vbox); | |
354 gtk_widget_show(notebook); | |
355 gtk_widget_show(vbox); | |
356 gtk_widget_show(shn_configurewin); | |
357 } | |
358 | |
359 void shn_message_box(char *message) | |
360 { | |
361 GtkWidget *mbox_win, | |
362 *mbox_vbox1, | |
363 *mbox_vbox2, | |
364 *mbox_frame, | |
365 *mbox_label, | |
366 *mbox_bbox, | |
367 *mbox_ok; | |
368 | |
369 mbox_win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
370 gtk_signal_connect(GTK_OBJECT(mbox_win), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &mbox_win); | |
371 gtk_window_set_title(GTK_WINDOW(mbox_win), (gchar *)"Shorten file information"); | |
372 gtk_window_set_policy(GTK_WINDOW(mbox_win), FALSE, FALSE, FALSE); | |
373 gtk_container_border_width(GTK_CONTAINER(mbox_win), 10); | |
374 | |
375 mbox_vbox1 = gtk_vbox_new(FALSE, 10); | |
376 gtk_container_add(GTK_CONTAINER(mbox_win), mbox_vbox1); | |
377 | |
378 mbox_frame = gtk_frame_new((gchar *)" " PACKAGE " error "); | |
379 gtk_container_set_border_width(GTK_CONTAINER(mbox_frame), 5); | |
380 gtk_box_pack_start(GTK_BOX(mbox_vbox1), mbox_frame, FALSE, FALSE, 0); | |
381 | |
382 mbox_vbox2 = gtk_vbox_new(FALSE, 10); | |
383 gtk_container_set_border_width(GTK_CONTAINER(mbox_vbox2), 5); | |
384 gtk_container_add(GTK_CONTAINER(mbox_frame), mbox_vbox2); | |
385 | |
386 mbox_label = gtk_label_new((gchar *)message); | |
387 gtk_misc_set_alignment(GTK_MISC(mbox_label), 0, 0); | |
388 gtk_label_set_justify(GTK_LABEL(mbox_label), GTK_JUSTIFY_LEFT); | |
389 gtk_box_pack_start(GTK_BOX(mbox_vbox2), mbox_label, TRUE, TRUE, 0); | |
390 gtk_widget_show(mbox_label); | |
391 | |
392 mbox_bbox = gtk_hbutton_box_new(); | |
393 gtk_button_box_set_layout(GTK_BUTTON_BOX(mbox_bbox), GTK_BUTTONBOX_SPREAD); | |
394 gtk_button_box_set_spacing(GTK_BUTTON_BOX(mbox_bbox), 5); | |
395 gtk_box_pack_start(GTK_BOX(mbox_vbox2), mbox_bbox, FALSE, FALSE, 0); | |
396 | |
397 mbox_ok = gtk_button_new_with_label((gchar *)"OK"); | |
398 gtk_signal_connect_object(GTK_OBJECT(mbox_ok), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(mbox_win)); | |
399 GTK_WIDGET_SET_FLAGS(mbox_ok, GTK_CAN_DEFAULT); | |
400 gtk_box_pack_start(GTK_BOX(mbox_bbox), mbox_ok, TRUE, TRUE, 0); | |
401 gtk_widget_show(mbox_ok); | |
402 gtk_widget_grab_default(mbox_ok); | |
403 | |
404 gtk_widget_show(mbox_bbox); | |
405 gtk_widget_show(mbox_vbox2); | |
406 gtk_widget_show(mbox_frame); | |
407 gtk_widget_show(mbox_vbox1); | |
408 gtk_widget_show(mbox_win); | |
409 } | |
410 | |
411 void load_shntextfile(char *filename,int num,GtkWidget *shntxt_notebook) | |
412 { | |
413 FILE *f; | |
414 char buffer[1024],*shortfilename; | |
415 int nchars; | |
416 GtkWidget *shntxt_frame, | |
417 *shntxt_vbox, | |
418 *shntxt_vbox_inner, | |
419 // *shntxt_text, | |
420 // *shntxt_table, | |
421 // *shntxt_vscrollbar, | |
422 *shntxt_filename_hbox, | |
423 *shntxt_filename_entry, | |
424 *shntxt_filename_label; | |
425 | |
426 shn_debug("Loading text file '%s'",filename); | |
427 | |
428 if ((shortfilename = strrchr(filename,'/'))) | |
429 shortfilename++; | |
430 else | |
431 shortfilename = filename; | |
432 | |
433 shntxt_vbox = gtk_vbox_new(FALSE, 10); | |
434 | |
435 shn_snprintf(buffer,1024," %s ",shortfilename); | |
436 | |
437 shntxt_frame = gtk_frame_new((gchar *)buffer); | |
438 gtk_container_set_border_width(GTK_CONTAINER(shntxt_frame), 10); | |
439 gtk_box_pack_start(GTK_BOX(shntxt_vbox), shntxt_frame, TRUE, TRUE, 0); | |
440 | |
441 shntxt_vbox_inner = gtk_vbox_new(FALSE, 10); | |
442 gtk_container_set_border_width(GTK_CONTAINER(shntxt_vbox_inner), 5); | |
443 gtk_container_add(GTK_CONTAINER(shntxt_frame), shntxt_vbox_inner); | |
444 | |
445 /* begin filename */ | |
446 shntxt_filename_hbox = gtk_hbox_new(FALSE, 10); | |
447 gtk_box_pack_start(GTK_BOX(shntxt_vbox_inner), shntxt_filename_hbox, FALSE, TRUE, 0); | |
448 | |
449 shntxt_filename_label = gtk_label_new((gchar *)"Filename:"); | |
450 gtk_box_pack_start(GTK_BOX(shntxt_filename_hbox), shntxt_filename_label, FALSE, TRUE, 0); | |
451 shntxt_filename_entry = gtk_entry_new(); | |
452 gtk_editable_set_editable(GTK_EDITABLE(shntxt_filename_entry), FALSE); | |
453 gtk_box_pack_start(GTK_BOX(shntxt_filename_hbox), shntxt_filename_entry, TRUE, TRUE, 0); | |
454 | |
455 gtk_entry_set_text(GTK_ENTRY(shntxt_filename_entry), filename); | |
456 gtk_editable_set_position(GTK_EDITABLE(shntxt_filename_entry), -1); | |
457 /* end filename */ | |
458 | |
459 #if 0 | |
460 shntxt_text = gtk_text_new(NULL,NULL); | |
461 | |
462 shntxt_table = gtk_table_new(2,2,FALSE); | |
463 gtk_container_add(GTK_CONTAINER(shntxt_vbox_inner), shntxt_table); | |
464 | |
465 shntxt_vscrollbar = gtk_vscrollbar_new(GTK_TEXT(shntxt_text)->vadj); | |
466 | |
467 gtk_text_set_editable(GTK_TEXT(shntxt_text),FALSE); | |
468 gtk_text_set_word_wrap(GTK_TEXT(shntxt_text),TRUE); | |
469 | |
470 gtk_table_attach(GTK_TABLE(shntxt_table),shntxt_text, 0, 1, 0, 1, GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0); | |
471 gtk_table_attach(GTK_TABLE(shntxt_table),shntxt_vscrollbar, 1, 2, 0, 1, GTK_FILL, GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, 0); | |
472 | |
473 gtk_widget_show(shntxt_vscrollbar); | |
474 gtk_widget_show(shntxt_text); | |
475 gtk_widget_show(shntxt_table); | |
476 #endif | |
477 gtk_widget_show(shntxt_frame); | |
478 gtk_widget_show(shntxt_vbox); | |
479 gtk_widget_show(shntxt_vbox_inner); | |
480 gtk_widget_show(shntxt_filename_hbox); | |
481 gtk_widget_show(shntxt_filename_entry); | |
482 gtk_widget_show(shntxt_filename_label); | |
483 | |
484 if ((f = fopen(filename,"rb"))) | |
485 { | |
486 nchars = fread(buffer,1,1024,f); | |
487 while (nchars > 0) | |
488 { | |
489 // gtk_text_insert(GTK_TEXT(shntxt_text),NULL,NULL,NULL,buffer,nchars); | |
490 nchars = fread(buffer,1,1024,f); | |
491 } | |
492 fclose(f); | |
493 } | |
494 else | |
495 { | |
496 shn_snprintf(buffer,1024,"error loading file: '%s'",filename); | |
497 // gtk_text_insert(GTK_TEXT(shntxt_text),NULL,NULL,NULL,buffer,strlen(buffer)); | |
498 } | |
499 | |
500 shn_snprintf(buffer,1024,"Text file %d",num); | |
501 | |
502 gtk_notebook_append_page(GTK_NOTEBOOK(shntxt_notebook), shntxt_vbox, gtk_label_new((gchar *)buffer)); | |
503 } | |
504 | |
505 void scan_for_textfiles(GtkWidget *this_notebook,char *dirname,int *filenum) | |
506 { | |
507 char *ext,*textfile_exts,buffer[2048]; | |
508 gchar *exts; | |
509 DIR *dp; | |
510 struct dirent *entry; | |
511 | |
512 shn_debug("Searching for text files in directory '%s'",dirname); | |
513 | |
514 if (NULL == (dp = opendir(dirname))) | |
515 { | |
516 shn_debug("Could not open directory '%s'",dirname); | |
517 return; | |
518 } | |
519 | |
520 while ((entry = readdir(dp))) | |
521 { | |
522 exts = g_strdup(shn_cfg.textfile_extensions); | |
523 | |
524 if ((ext = strrchr(entry->d_name,'.'))) | |
525 ext++; | |
526 else | |
527 ext = ""; | |
528 | |
529 textfile_exts = strtok(exts,","); | |
530 while (textfile_exts) | |
531 { | |
532 if ((0 == strcmp(textfile_exts,ext)) || (0 == strcmp(textfile_exts,""))) | |
533 { | |
534 shn_snprintf(buffer,2048,"%s/%s",dirname,entry->d_name); | |
535 | |
536 load_shntextfile(buffer,*filenum,this_notebook); | |
537 *filenum = *filenum + 1; | |
538 break; | |
539 } | |
540 | |
541 textfile_exts = strtok(NULL,","); | |
542 } | |
543 | |
544 g_free(exts); | |
545 } | |
546 | |
547 closedir(dp); | |
548 } | |
549 | |
550 void load_shntextfiles(GtkWidget *this_notebook,char *filename) | |
551 { | |
552 #ifdef XMMS_SHN_LOAD_TEXTFILES | |
553 char *basedir,*uponedir; | |
554 int filenum = 1; | |
555 | |
556 basedir = shn_get_base_directory(filename); | |
557 | |
558 if (NULL == (uponedir = malloc((strlen(basedir) + 5) * sizeof(char)))) | |
559 { | |
560 shn_debug("Could not allocate memory for search directories"); | |
561 return; | |
562 } | |
563 | |
564 shn_snprintf(uponedir,strlen(basedir) + 4,"%s/..",basedir); | |
565 | |
566 scan_for_textfiles(this_notebook,basedir,&filenum); | |
567 scan_for_textfiles(this_notebook,uponedir,&filenum); | |
568 | |
569 free(basedir); | |
570 free(uponedir); | |
571 #else | |
572 shn_debug("Text file support is disabled on your platform because the\n" | |
573 "appropriate functions were not found. Please email me with\n" | |
574 "the specifics of your platform, and I will try to support it."); | |
575 #endif | |
576 } | |
577 | |
578 | |
579 void shn_display_info(shn_file *tmp_file) | |
580 { | |
581 char props[BUF_SIZE]; | |
582 char details[BUF_SIZE]; | |
583 char props_label[BUF_SIZE]; | |
584 char details_label[BUF_SIZE]; | |
585 char misalignment[8]; | |
586 char seektable_revision[8]; | |
587 char id3v2_info[32]; | |
588 GtkWidget *info_win, | |
589 *info_notebook, | |
590 *props_hbox, | |
591 *props_vbox, | |
592 *props_vbox_inner, | |
593 *props_frame, | |
594 *props_label_left, | |
595 *props_label_right, | |
596 *props_filename_hbox, | |
597 *props_filename_label, | |
598 *props_filename_entry, | |
599 *details_hbox, | |
600 *details_vbox, | |
601 *details_vbox_inner, | |
602 *details_frame, | |
603 *details_label_left, | |
604 *details_label_right, | |
605 *details_filename_hbox, | |
606 *details_filename_label, | |
607 *details_filename_entry, | |
608 *main_vbox, | |
609 *info_bbox, | |
610 *info_ok; | |
611 | |
612 shn_snprintf(props_label,BUF_SIZE," Properties for %s ", | |
613 strrchr(tmp_file->wave_header.filename,'/') ? | |
614 strrchr(tmp_file->wave_header.filename,'/') + 1 : | |
615 tmp_file->wave_header.filename); | |
616 | |
617 shn_snprintf(details_label,BUF_SIZE," Details for %s ", | |
618 strrchr(tmp_file->wave_header.filename,'/') ? | |
619 strrchr(tmp_file->wave_header.filename,'/') + 1 : | |
620 tmp_file->wave_header.filename); | |
621 | |
622 shn_snprintf(misalignment,8,"%d",tmp_file->wave_header.data_size % CD_BLOCK_SIZE); | |
623 | |
624 if (NO_SEEK_TABLE != tmp_file->seek_header.version) | |
625 shn_snprintf(seektable_revision,8,"%d",tmp_file->seek_header.version); | |
626 | |
627 shn_snprintf(id3v2_info,32,"yes (%ld bytes)",tmp_file->wave_header.id3v2_tag_size); | |
628 | |
629 shn_snprintf(props,BUF_SIZE, | |
630 "%s\n" | |
631 "%s\n" | |
632 "%s\n" | |
633 "%0.4f\n" | |
634 "\n" | |
635 "%s\n" | |
636 "%s\n" | |
637 "%s bytes\n" | |
638 "%s\n" | |
639 "\n" | |
640 "%s\n" | |
641 "%s\n" | |
642 "\n" | |
643 "%s", | |
644 tmp_file->wave_header.m_ss, | |
645 (tmp_file->vars.seek_table_entries == NO_SEEK_TABLE)?"no":"yes", | |
646 (tmp_file->seek_header.version == NO_SEEK_TABLE)?"n/a":seektable_revision, | |
647 (double)tmp_file->wave_header.actual_size/(double)tmp_file->wave_header.total_size, | |
648 (PROB_NOT_CD(tmp_file->wave_header))?"no":"yes", | |
649 (PROB_NOT_CD(tmp_file->wave_header))?"n/a":((PROB_BAD_BOUND(tmp_file->wave_header))?"no":"yes"), | |
650 (PROB_NOT_CD(tmp_file->wave_header))?"n/a":misalignment, | |
651 (PROB_NOT_CD(tmp_file->wave_header))?"n/a":((PROB_TOO_SHORT(tmp_file->wave_header))?"no":"yes"), | |
652 (PROB_HDR_NOT_CANONICAL(tmp_file->wave_header))?"yes":"no", | |
653 (PROB_EXTRA_CHUNKS(tmp_file->wave_header))?"yes":"no", | |
654 (tmp_file->wave_header.file_has_id3v2_tag)?id3v2_info:"no" | |
655 ); | |
656 | |
657 shn_snprintf(details,BUF_SIZE, | |
658 "\n" | |
659 "0x%04x (%s)\n" | |
660 "%hu\n" | |
661 "%hu\n" | |
662 "%lu\n" | |
663 "%lu\n" | |
664 "%lu bytes/sec\n" | |
665 "%hu\n" | |
666 "%d bytes\n" | |
667 "%lu bytes\n" | |
668 "%lu bytes\n" | |
669 "%lu bytes\n" | |
670 "%lu bytes", | |
671 tmp_file->wave_header.wave_format, | |
672 shn_format_to_str(tmp_file->wave_header.wave_format), | |
673 tmp_file->wave_header.channels, | |
674 tmp_file->wave_header.bits_per_sample, | |
675 tmp_file->wave_header.samples_per_sec, | |
676 tmp_file->wave_header.avg_bytes_per_sec, | |
677 tmp_file->wave_header.rate, | |
678 tmp_file->wave_header.block_align, | |
679 tmp_file->wave_header.header_size, | |
680 tmp_file->wave_header.data_size, | |
681 tmp_file->wave_header.chunk_size, | |
682 tmp_file->wave_header.total_size, | |
683 tmp_file->wave_header.actual_size | |
684 ); | |
685 | |
686 info_win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
687 gtk_signal_connect(GTK_OBJECT(info_win), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &info_win); | |
688 gtk_window_set_title(GTK_WINDOW(info_win), (gchar *)"Shorten file information"); | |
689 gtk_window_set_policy(GTK_WINDOW(info_win), FALSE, FALSE, FALSE); | |
690 gtk_container_border_width(GTK_CONTAINER(info_win), 10); | |
691 | |
692 main_vbox = gtk_vbox_new(FALSE, 10); | |
693 gtk_container_add(GTK_CONTAINER(info_win), main_vbox); | |
694 | |
695 info_notebook = gtk_notebook_new(); | |
696 gtk_container_add(GTK_CONTAINER(main_vbox), info_notebook); | |
697 | |
698 /* begin properties page */ | |
699 | |
700 props_vbox = gtk_vbox_new(FALSE, 10); | |
701 | |
702 props_frame = gtk_frame_new((gchar *)props_label); | |
703 gtk_container_set_border_width(GTK_CONTAINER(props_frame), 10); | |
704 gtk_box_pack_start(GTK_BOX(props_vbox), props_frame, TRUE, TRUE, 0); | |
705 | |
706 props_vbox_inner = gtk_vbox_new(FALSE, 10); | |
707 gtk_container_set_border_width(GTK_CONTAINER(props_vbox_inner), 5); | |
708 gtk_container_add(GTK_CONTAINER(props_frame), props_vbox_inner); | |
709 | |
710 /* begin filename */ | |
711 props_filename_hbox = gtk_hbox_new(FALSE, 10); | |
712 gtk_box_pack_start(GTK_BOX(props_vbox_inner), props_filename_hbox, FALSE, TRUE, 0); | |
713 | |
714 props_filename_label = gtk_label_new((gchar *)"Filename:"); | |
715 gtk_box_pack_start(GTK_BOX(props_filename_hbox), props_filename_label, FALSE, TRUE, 0); | |
716 props_filename_entry = gtk_entry_new(); | |
717 gtk_editable_set_editable(GTK_EDITABLE(props_filename_entry), FALSE); | |
718 gtk_box_pack_start(GTK_BOX(props_filename_hbox), props_filename_entry, TRUE, TRUE, 0); | |
719 | |
720 gtk_entry_set_text(GTK_ENTRY(props_filename_entry), tmp_file->wave_header.filename); | |
721 gtk_editable_set_position(GTK_EDITABLE(props_filename_entry), -1); | |
722 /* end filename */ | |
723 | |
724 props_hbox = gtk_hbox_new(FALSE, 10); | |
725 gtk_box_pack_start(GTK_BOX(props_vbox_inner), props_hbox, TRUE, TRUE, 0); | |
726 | |
727 props_label_left = gtk_label_new((gchar *) | |
728 "Length:\n" | |
729 "Seekable:\n" | |
730 "Seek table revision:\n" | |
731 "Compression ratio:\n" | |
732 "CD-quality properties:\n" | |
733 " CD-quality:\n" | |
734 " Cut on sector boundary:\n" | |
735 " Sector misalignment:\n" | |
736 " Long enough to be burned:\n" | |
737 "WAVE properties:\n" | |
738 " Non-canonical header:\n" | |
739 " Extra RIFF chunks:\n" | |
740 "Possible problems:\n" | |
741 " File contains ID3v2 tag:" | |
742 ); | |
743 | |
744 props_label_right = gtk_label_new((gchar *)props); | |
745 | |
746 gtk_misc_set_alignment(GTK_MISC(props_label_left), 0, 0); | |
747 gtk_label_set_justify(GTK_LABEL(props_label_left), GTK_JUSTIFY_LEFT); | |
748 gtk_box_pack_start(GTK_BOX(props_hbox), props_label_left, TRUE, TRUE, 0); | |
749 gtk_widget_show(props_label_left); | |
750 | |
751 gtk_misc_set_alignment(GTK_MISC(props_label_right), 0, 0); | |
752 gtk_label_set_justify(GTK_LABEL(props_label_right), GTK_JUSTIFY_LEFT); | |
753 gtk_box_pack_start(GTK_BOX(props_hbox), props_label_right, TRUE, TRUE, 0); | |
754 gtk_widget_show(props_label_right); | |
755 | |
756 /* end properties page */ | |
757 | |
758 /* begin details page */ | |
759 | |
760 details_vbox = gtk_vbox_new(FALSE, 10); | |
761 | |
762 details_frame = gtk_frame_new((gchar *)details_label); | |
763 gtk_container_set_border_width(GTK_CONTAINER(details_frame), 10); | |
764 gtk_box_pack_start(GTK_BOX(details_vbox), details_frame, TRUE, TRUE, 0); | |
765 | |
766 details_vbox_inner = gtk_vbox_new(FALSE, 10); | |
767 gtk_container_set_border_width(GTK_CONTAINER(details_vbox_inner), 5); | |
768 gtk_container_add(GTK_CONTAINER(details_frame), details_vbox_inner); | |
769 | |
770 /* begin filename */ | |
771 details_filename_hbox = gtk_hbox_new(FALSE, 10); | |
772 gtk_box_pack_start(GTK_BOX(details_vbox_inner), details_filename_hbox, FALSE, TRUE, 0); | |
773 | |
774 details_filename_label = gtk_label_new((gchar *)"Filename:"); | |
775 gtk_box_pack_start(GTK_BOX(details_filename_hbox), details_filename_label, FALSE, TRUE, 0); | |
776 details_filename_entry = gtk_entry_new(); | |
777 gtk_editable_set_editable(GTK_EDITABLE(details_filename_entry), FALSE); | |
778 gtk_box_pack_start(GTK_BOX(details_filename_hbox), details_filename_entry, TRUE, TRUE, 0); | |
779 | |
780 gtk_entry_set_text(GTK_ENTRY(details_filename_entry), tmp_file->wave_header.filename); | |
781 gtk_editable_set_position(GTK_EDITABLE(details_filename_entry), -1); | |
782 /* end filename */ | |
783 | |
784 details_hbox = gtk_hbox_new(FALSE, 10); | |
785 gtk_box_pack_start(GTK_BOX(details_vbox_inner), details_hbox, TRUE, TRUE, 0); | |
786 | |
787 details_label_left = gtk_label_new((gchar *) | |
788 "\n" | |
789 "WAVE format:\n" | |
790 "Channels:\n" | |
791 "Bits per sample:\n" | |
792 "Samples per second:\n" | |
793 "Average bytes per second:\n" | |
794 "Rate (calculated):\n" | |
795 "Block align:\n" | |
796 "Header size:\n" | |
797 "WAVE data size:\n" | |
798 "Chunk size:\n" | |
799 "Total size (chunk size + 8):\n" | |
800 "Actual file size:" | |
801 ); | |
802 | |
803 details_label_right = gtk_label_new((gchar *)details); | |
804 | |
805 gtk_misc_set_alignment(GTK_MISC(details_label_left), 0, 0); | |
806 gtk_label_set_justify(GTK_LABEL(details_label_left), GTK_JUSTIFY_LEFT); | |
807 gtk_box_pack_start(GTK_BOX(details_hbox), details_label_left, TRUE, TRUE, 0); | |
808 gtk_widget_show(details_label_left); | |
809 | |
810 gtk_misc_set_alignment(GTK_MISC(details_label_right), 0, 0); | |
811 gtk_label_set_justify(GTK_LABEL(details_label_right), GTK_JUSTIFY_LEFT); | |
812 gtk_box_pack_start(GTK_BOX(details_hbox), details_label_right, TRUE, TRUE, 0); | |
813 gtk_widget_show(details_label_right); | |
814 | |
815 /* end details page */ | |
816 | |
817 info_bbox = gtk_hbutton_box_new(); | |
818 gtk_button_box_set_layout(GTK_BUTTON_BOX(info_bbox), GTK_BUTTONBOX_SPREAD); | |
819 gtk_button_box_set_spacing(GTK_BUTTON_BOX(info_bbox), 5); | |
820 gtk_box_pack_start(GTK_BOX(main_vbox), info_bbox, FALSE, FALSE, 0); | |
821 | |
822 info_ok = gtk_button_new_with_label((gchar *)"OK"); | |
823 gtk_signal_connect_object(GTK_OBJECT(info_ok), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(info_win)); | |
824 GTK_WIDGET_SET_FLAGS(info_ok, GTK_CAN_DEFAULT); | |
825 gtk_box_pack_start(GTK_BOX(info_bbox), info_ok, TRUE, TRUE, 0); | |
826 gtk_widget_show(info_ok); | |
827 gtk_widget_grab_default(info_ok); | |
828 | |
829 gtk_notebook_append_page(GTK_NOTEBOOK(info_notebook), props_vbox, gtk_label_new((gchar *)"Properties")); | |
830 gtk_notebook_append_page(GTK_NOTEBOOK(info_notebook), details_vbox, gtk_label_new((gchar *)"Details")); | |
831 | |
832 gtk_widget_show(props_frame); | |
833 gtk_widget_show(props_hbox); | |
834 gtk_widget_show(props_vbox_inner); | |
835 gtk_widget_show(props_vbox); | |
836 gtk_widget_show(props_filename_hbox); | |
837 gtk_widget_show(props_filename_entry); | |
838 gtk_widget_show(props_filename_label); | |
839 gtk_widget_show(details_frame); | |
840 gtk_widget_show(details_hbox); | |
841 gtk_widget_show(details_vbox_inner); | |
842 gtk_widget_show(details_vbox); | |
843 gtk_widget_show(details_filename_hbox); | |
844 gtk_widget_show(details_filename_entry); | |
845 gtk_widget_show(details_filename_label); | |
846 | |
847 /* begin any text files pages */ | |
848 | |
849 if (shn_cfg.load_textfiles) | |
850 load_shntextfiles(info_notebook,tmp_file->wave_header.filename); | |
851 | |
852 /* end any text files pages */ | |
853 | |
854 gtk_notebook_set_page(GTK_NOTEBOOK(info_notebook), 0); | |
855 | |
856 gtk_widget_show(info_notebook); | |
857 gtk_widget_show(main_vbox); | |
858 gtk_widget_show(info_bbox); | |
859 gtk_widget_show(info_win); | |
860 } |