Mercurial > audlegacy
annotate audacious/main.c @ 363:eaaee9e0519c trunk
[svn] Properly fall back to file name if the tag information is invalid (SPC).
author | chainsaw |
---|---|
date | Sat, 31 Dec 2005 12:30:19 -0800 |
parents | 950f104f2e11 |
children | 5c457dac866a |
rev | line source |
---|---|
197
ccd034857702
[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
nenolod
parents:
196
diff
changeset
|
1 /* Audacious - Cross-platform multimedia platform. |
ccd034857702
[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
nenolod
parents:
196
diff
changeset
|
2 * Copyright (C) 2005 Audacious development team. |
ccd034857702
[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
nenolod
parents:
196
diff
changeset
|
3 * |
ccd034857702
[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
nenolod
parents:
196
diff
changeset
|
4 * Based on BMP: |
0 | 5 * Copyright (C) 2003-2004 BMP development team. |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 # include "config.h" | |
27 #endif | |
28 | |
29 #include "main.h" | |
30 | |
31 #include <glib.h> | |
32 #include <glib/gi18n.h> | |
33 #include <glib/gprintf.h> | |
34 #include <gdk/gdk.h> | |
35 #include <stdlib.h> | |
36 #include <string.h> | |
37 #include <getopt.h> | |
38 #include <ctype.h> | |
39 #include <time.h> | |
40 | |
41 #include <unistd.h> | |
42 #include <errno.h> | |
43 #include <sys/types.h> | |
44 #include <sys/stat.h> | |
45 #include <signal.h> | |
46 #include <gdk/gdkx.h> | |
47 #include <X11/Xlib.h> | |
48 #include <X11/Xatom.h> | |
49 | |
50 #include "libaudacious/configdb.h" | |
51 #include "libaudacious/beepctrl.h" | |
52 #include "libaudacious/util.h" | |
53 #include "libaudacious/vfs.h" | |
54 | |
55 #include "controlsocket.h" | |
56 #include "dnd.h" | |
57 #include "dock.h" | |
58 #include "effect.h" | |
59 #include "equalizer.h" | |
60 #include "general.h" | |
197
ccd034857702
[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
nenolod
parents:
196
diff
changeset
|
61 #include "genevent.h" |
0 | 62 #include "hints.h" |
63 #include "input.h" | |
64 #include "logger.h" | |
65 #include "mainwin.h" | |
66 #include "output.h" | |
284 | 67 #include "libaudcore/playback.h" |
0 | 68 #include "playlist.h" |
69 #include "playlistwin.h" | |
70 #include "pluginenum.h" | |
71 #include "prefswin.h" | |
72 #include "skin.h" | |
73 #include "skinwin.h" | |
74 #include "util.h" | |
75 #include "visualization.h" | |
76 | |
77 #include "pixmaps.h" | |
120 | 78 #include "images/audacious_player.xpm" |
0 | 79 |
80 | |
81 /* Translatable string for beep.desktop's comment field */ | |
85
8c8a20f72ace
[svn] s/static GTKItemFactoryEntry/GTKItemFactoryEntry/g.
nenolod
parents:
80
diff
changeset
|
82 const gchar *desktop_comment = N_("Audacious"); |
0 | 83 |
85
8c8a20f72ace
[svn] s/static GTKItemFactoryEntry/GTKItemFactoryEntry/g.
nenolod
parents:
80
diff
changeset
|
84 const gchar *application_name = N_("Audacious"); |
0 | 85 |
86 | |
87 struct _BmpCmdLineOpt { | |
88 GList *filenames; | |
89 gint session; | |
90 gboolean play, stop, pause, fwd, rew, play_pause, playcd; | |
91 gboolean enqueue, mainwin, remote, activate; | |
92 gboolean load_skins; | |
191 | 93 gboolean headless; |
0 | 94 gchar *previous_session_id; |
95 }; | |
96 | |
97 typedef struct _BmpCmdLineOpt BmpCmdLineOpt; | |
98 | |
99 | |
100 BmpConfig cfg; | |
101 | |
102 BmpConfig bmp_default_config = { | |
103 MAINWIN_DEFAULT_POS_X, /* mainwin x position */ | |
104 MAINWIN_DEFAULT_POS_Y, /* mainwin y position */ | |
105 EQUALIZER_DEFAULT_POS_X, /* equalizer x position */ | |
106 EQUALIZER_DEFAULT_POS_Y, /* equalizer y position */ | |
107 PLAYLISTWIN_DEFAULT_POS_X, /* playlistwin x position */ | |
108 PLAYLISTWIN_DEFAULT_POS_Y, /* playlistwin y position */ | |
109 PLAYLISTWIN_DEFAULT_WIDTH, /* playlistwin width */ | |
110 PLAYLISTWIN_DEFAULT_HEIGHT, /* playlistwin height */ | |
111 10, /* snap distance */ | |
112 FALSE, /* real-time priority */ | |
113 FALSE, FALSE, /* shuffle, repeat */ | |
114 FALSE, /* UNUSED (double size) */ | |
115 TRUE, /* autoscroll */ | |
116 TRUE, /* analyzer peaks */ | |
117 FALSE, /* equalizer autoload */ | |
118 FALSE, /* easy move */ | |
119 FALSE, /* equalizer active */ | |
120 FALSE, /* playlistwin visible */ | |
121 FALSE, /* equalizer visible */ | |
122 TRUE, /* player visible */ | |
123 FALSE, /* player shaded */ | |
124 FALSE, /* playlistwin shaded */ | |
125 FALSE, /* equalizer shaded */ | |
126 FALSE, /* allow multiple instances */ | |
127 TRUE, /* always show cb */ | |
128 TRUE, TRUE, /* convert '_' and %20 */ | |
129 TRUE, /* show numbers in playlist */ | |
130 TRUE, /* snap windows */ | |
131 TRUE, /* save window positions */ | |
132 TRUE, /* dim titlebar */ | |
133 FALSE, /* get playlist info on load */ | |
134 TRUE, /* get playlist info on demand */ | |
135 TRUE, /* UNUSED (equalizer doublesize linked) */ | |
136 FALSE, /* sort jump to file */ | |
137 FALSE, /* use effect plugins */ | |
138 FALSE, /* always on top */ | |
139 FALSE, /* sticky */ | |
140 FALSE, /* no playlist advance */ | |
141 TRUE, /* UNUSED (smooth title scrolling) */ | |
142 TRUE, /* use playlist metadata */ | |
143 TRUE, /* warn about unplayables */ | |
144 FALSE, /* use \ as directory delimiter */ | |
145 FALSE, /* random skin on play */ | |
146 FALSE, /* use fontsets */ | |
147 FALSE, /* use X font for mainwin */ | |
148 TRUE, /* use custom cursors */ | |
149 TRUE, /* close dialog on open */ | |
150 TRUE, /* close dialog on add */ | |
151 0.0, /* equalizer preamp */ | |
152 {0, 0, 0, 0, 0, /* equalizer bands */ | |
153 0, 0, 0, 0, 0}, | |
154 NULL, /* skin */ | |
155 NULL, /* output plugin */ | |
156 NULL, /* file selector path */ | |
157 NULL, /* playlist path */ | |
158 NULL, /* playlist font */ | |
159 NULL, /* mainwin font */ | |
160 NULL, /* disabled input plugins */ | |
161 NULL, /* enabled general plugins */ | |
162 NULL, /* enabled visualization plugins */ | |
163 NULL, /* enabled effect plugins */ | |
164 NULL, /* equalizer preset default file */ | |
165 NULL, /* equalizer preset extension */ | |
166 NULL, /* URL history */ | |
167 0, /* timer mode */ | |
168 VIS_ANALYZER, /* visualizer type */ | |
169 ANALYZER_NORMAL, /* analyzer mode */ | |
170 ANALYZER_BARS, /* analyzer type */ | |
171 SCOPE_DOT, /* scope mode */ | |
172 VU_SMOOTH, /* VU mode */ | |
173 REFRESH_FULL, /* visualizer refresh rate */ | |
174 FALLOFF_FAST, /* analyzer fall off rate */ | |
175 FALLOFF_SLOW, /* peaks fall off rate */ | |
176 0, /* playlist position */ | |
177 2, /* pause between songs time */ | |
178 FALSE, /* pause between songs */ | |
179 FALSE, /* show window decorations */ | |
180 8, /* mouse wheel scroll step */ | |
181 FALSE, /* playlist transparent */ | |
182 1, /* 2nd preset (ARTIST - TITLE) */ | |
183 NULL, /* title format */ | |
184 FALSE, /* software volume control enabled */ | |
185 TRUE, /* UNUSED (XMMS compatibility mode) */ | |
186 TRUE, /* extra eq filtering */ | |
187 3 /* scroll pl by */ | |
188 }; | |
189 | |
190 typedef struct bmp_cfg_boolent_t { | |
191 char const *be_vname; | |
192 gboolean *be_vloc; | |
193 gboolean be_wrt; | |
194 } bmp_cfg_boolent; | |
195 | |
196 typedef struct bmp_cfg_nument_t { | |
197 char const *ie_vname; | |
198 gint *ie_vloc; | |
199 gboolean ie_wrt; | |
200 } bmp_cfg_nument; | |
201 | |
202 typedef struct bmp_cfg_strent_t { | |
203 char const *se_vname; | |
204 char **se_vloc; | |
205 gboolean se_wrt; | |
206 } bmp_cfg_strent; | |
207 | |
208 const gchar *bmp_titlestring_presets[] = { | |
209 "%t", | |
210 "%p - %t", | |
211 "%p - %a - %t", | |
212 "%a - %t" | |
213 }; | |
214 | |
215 const guint n_titlestring_presets = G_N_ELEMENTS(bmp_titlestring_presets); | |
216 | |
217 static bmp_cfg_boolent bmp_boolents[] = { | |
218 {"allow_multiple_instances", &cfg.allow_multiple_instances, TRUE}, | |
219 {"use_realtime", &cfg.use_realtime, TRUE}, | |
220 {"always_show_cb", &cfg.always_show_cb, TRUE}, | |
221 {"convert_underscore", &cfg.convert_underscore, TRUE}, | |
222 {"convert_twenty", &cfg.convert_twenty, TRUE}, | |
223 {"show_numbers_in_pl", &cfg.show_numbers_in_pl, TRUE}, | |
224 {"snap_windows", &cfg.snap_windows, TRUE}, | |
225 {"save_window_positions", &cfg.save_window_position, TRUE}, | |
226 {"dim_titlebar", &cfg.dim_titlebar, TRUE}, | |
227 {"get_info_on_load", &cfg.get_info_on_load, TRUE}, | |
228 {"get_info_on_demand", &cfg.get_info_on_demand, TRUE}, | |
229 {"no_playlist_advance", &cfg.no_playlist_advance, TRUE}, | |
230 {"sort_jump_to_file", &cfg.sort_jump_to_file, TRUE}, | |
231 {"use_pl_metadata", &cfg.use_pl_metadata, TRUE}, | |
232 {"warn_about_unplayables", &cfg.warn_about_unplayables, TRUE}, | |
233 {"use_backslash_as_dir_delimiter", &cfg.use_backslash_as_dir_delimiter, TRUE}, | |
234 {"player_shaded", &cfg.player_shaded, TRUE}, | |
235 {"player_visible", &cfg.player_visible, TRUE}, | |
236 {"shuffle", &cfg.shuffle, TRUE}, | |
237 {"repeat", &cfg.repeat, TRUE}, | |
238 {"autoscroll_songname", &cfg.autoscroll, TRUE}, | |
239 {"playlist_shaded", &cfg.playlist_shaded, TRUE}, | |
240 {"playlist_visible", &cfg.playlist_visible, TRUE}, | |
241 {"playlist_transparent", &cfg.playlist_transparent, TRUE}, | |
242 {"use_fontsets", &cfg.use_fontsets, TRUE}, | |
85
8c8a20f72ace
[svn] s/static GTKItemFactoryEntry/GTKItemFactoryEntry/g.
nenolod
parents:
80
diff
changeset
|
243 {"mainwin_use_xfont", &cfg.mainwin_use_xfont, FALSE}, |
0 | 244 {"equalizer_visible", &cfg.equalizer_visible, TRUE}, |
245 {"equalizer_active", &cfg.equalizer_active, TRUE}, | |
246 {"equalizer_shaded", &cfg.equalizer_shaded, TRUE}, | |
247 {"equalizer_autoload", &cfg.equalizer_autoload, TRUE}, | |
248 {"use_eplugins", &cfg.use_eplugins, TRUE}, | |
249 {"always_on_top", &cfg.always_on_top, TRUE}, | |
250 {"sticky", &cfg.sticky, TRUE}, | |
251 {"random_skin_on_play", &cfg.random_skin_on_play, TRUE}, | |
252 {"pause_between_songs", &cfg.pause_between_songs, TRUE}, | |
253 {"show_wm_decorations", &cfg.show_wm_decorations, TRUE}, | |
254 {"eq_extra_filtering", &cfg.eq_extra_filtering, TRUE}, | |
255 {"analyzer_peaks", &cfg.analyzer_peaks, TRUE}, | |
256 {"custom_cursors", &cfg.custom_cursors, TRUE}, | |
257 {"close_dialog_open", &cfg.close_dialog_open, TRUE}, | |
258 {"close_dialog_add", &cfg.close_dialog_add, TRUE} | |
259 }; | |
260 | |
261 static gint ncfgbent = G_N_ELEMENTS(bmp_boolents); | |
262 | |
263 static bmp_cfg_nument bmp_numents[] = { | |
264 {"player_x", &cfg.player_x, TRUE}, | |
265 {"player_y", &cfg.player_y, TRUE}, | |
266 {"timer_mode", &cfg.timer_mode, TRUE}, | |
267 {"vis_type", &cfg.vis_type, TRUE}, | |
268 {"analyzer_mode", &cfg.analyzer_mode, TRUE}, | |
269 {"analyzer_type", &cfg.analyzer_type, TRUE}, | |
270 {"scope_mode", &cfg.scope_mode, TRUE}, | |
271 {"vu_mode", &cfg.vu_mode, TRUE}, | |
272 {"vis_refresh_rate", &cfg.vis_refresh, TRUE}, | |
273 {"analyzer_falloff", &cfg.analyzer_falloff, TRUE}, | |
274 {"peaks_falloff", &cfg.peaks_falloff, TRUE}, | |
275 {"playlist_x", &cfg.playlist_x, TRUE}, | |
276 {"playlist_y", &cfg.playlist_y, TRUE}, | |
277 {"playlist_width", &cfg.playlist_width, TRUE}, | |
278 {"playlist_height", &cfg.playlist_height, TRUE}, | |
279 {"playlist_position", &cfg.playlist_position, TRUE}, | |
280 {"equalizer_x", &cfg.equalizer_x, TRUE}, | |
281 {"equalizer_y", &cfg.equalizer_y, TRUE}, | |
282 {"snap_distance", &cfg.snap_distance, TRUE}, | |
283 {"pause_between_songs_time", &cfg.pause_between_songs_time, TRUE}, | |
284 {"mouse_wheel_change", &cfg.mouse_change, TRUE}, | |
285 {"scroll_pl_by", &cfg.scroll_pl_by, TRUE}, | |
286 {"titlestring_preset", &cfg.titlestring_preset, TRUE}, | |
287 }; | |
288 | |
289 static gint ncfgient = G_N_ELEMENTS(bmp_numents); | |
290 | |
291 static bmp_cfg_strent bmp_strents[] = { | |
292 {"playlist_font", &cfg.playlist_font, TRUE}, | |
293 {"mainwin_font", &cfg.mainwin_font, TRUE}, | |
294 {"eqpreset_default_file", &cfg.eqpreset_default_file, TRUE}, | |
295 {"eqpreset_extension", &cfg.eqpreset_extension, TRUE}, | |
296 {"skin", &cfg.skin, FALSE}, | |
297 {"output_plugin", &cfg.outputplugin, FALSE}, | |
298 {"disabled_iplugins", &cfg.disabled_iplugins, TRUE}, | |
299 {"enabled_gplugins", &cfg.enabled_gplugins, FALSE}, | |
300 {"enabled_vplugins", &cfg.enabled_vplugins, FALSE}, | |
301 {"enabled_eplugins", &cfg.enabled_eplugins, FALSE}, | |
302 {"filesel_path", &cfg.filesel_path, FALSE}, | |
303 {"playlist_path", &cfg.playlist_path, FALSE}, | |
304 {"generic_title_format", &cfg.gentitle_format, TRUE}, | |
305 }; | |
306 | |
307 static gint ncfgsent = G_N_ELEMENTS(bmp_strents); | |
308 | |
309 gchar *bmp_paths[BMP_PATH_COUNT] = {}; | |
310 | |
311 GList *dock_window_list = NULL; | |
312 | |
313 gboolean pposition_broken = FALSE; | |
314 | |
315 | |
316 static GSList * | |
317 get_feature_list(void) | |
318 { | |
319 GSList *features = NULL; | |
320 | |
321 #ifdef HAVE_GNOME_VFS | |
322 features = g_slist_append(features, "GNOME VFS"); | |
323 #endif | |
324 | |
325 #ifdef HAVE_GCONF | |
326 features = g_slist_append(features, "GConf"); | |
327 #endif | |
328 | |
329 return features; | |
330 } | |
331 | |
332 static void | |
333 dump_version(void) | |
334 { | |
335 GSList *features; | |
336 | |
337 g_printf("%s %s", _(application_name), VERSION); | |
338 | |
339 features = get_feature_list(); | |
340 | |
341 if (features) { | |
342 GSList *item; | |
343 | |
344 g_printf(" ("); | |
345 | |
346 for (item = features; g_slist_next(item); item = g_slist_next(item)) | |
347 g_printf("%s, ", (const gchar *) item->data); | |
348 | |
349 g_printf("%s)", (const gchar *) item->data); | |
350 | |
351 g_slist_free(features); | |
352 } | |
353 | |
354 g_printf("\n"); | |
355 } | |
356 | |
357 const gchar * | |
358 xmms_get_gentitle_format(void) | |
359 { | |
360 gint titlestring_preset = cfg.titlestring_preset; | |
361 | |
362 if (titlestring_preset < n_titlestring_presets) | |
363 return bmp_titlestring_presets[titlestring_preset]; | |
364 | |
365 return cfg.gentitle_format; | |
366 } | |
367 | |
368 static void | |
369 make_directory(const gchar * path, mode_t mode) | |
370 { | |
371 if (mkdir(path, mode) == 0) | |
372 return; | |
373 | |
374 if (errno == EEXIST) | |
375 return; | |
376 | |
377 g_printerr(_("Could not create directory (%s): %s"), path, | |
378 g_strerror(errno)); | |
379 } | |
380 | |
381 static void | |
382 bmp_make_user_dir(void) | |
383 { | |
384 const mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; | |
385 | |
386 make_directory(bmp_paths[BMP_PATH_USER_DIR], mode755); | |
387 make_directory(bmp_paths[BMP_PATH_USER_PLUGIN_DIR], mode755); | |
388 make_directory(bmp_paths[BMP_PATH_USER_SKIN_DIR], mode755); | |
389 make_directory(bmp_paths[BMP_PATH_SKIN_THUMB_DIR], mode755); | |
390 } | |
391 | |
392 static void | |
393 bmp_free_paths(void) | |
394 { | |
395 int i; | |
396 | |
397 for (i = 0; i < BMP_PATH_COUNT; i++) | |
398 { | |
399 g_free(bmp_paths[i]); | |
400 bmp_paths[i] = 0; | |
401 } | |
402 } | |
403 | |
404 | |
405 #define USER_PATH(path) \ | |
406 g_build_filename(bmp_paths[BMP_PATH_USER_DIR], path, NULL); | |
407 | |
408 static void | |
409 bmp_init_paths(void) | |
410 { | |
411 bmp_paths[BMP_PATH_USER_DIR] = g_build_filename(g_get_home_dir(), BMP_RCPATH, NULL); | |
412 | |
413 bmp_paths[BMP_PATH_USER_PLUGIN_DIR] = USER_PATH(BMP_USER_PLUGIN_DIR_BASENAME); | |
414 bmp_paths[BMP_PATH_USER_SKIN_DIR] = USER_PATH(BMP_SKIN_DIR_BASENAME); | |
415 bmp_paths[BMP_PATH_SKIN_THUMB_DIR] = USER_PATH(BMP_SKIN_THUMB_DIR_BASENAME); | |
416 bmp_paths[BMP_PATH_CONFIG_FILE] = USER_PATH(BMP_CONFIG_BASENAME); | |
417 bmp_paths[BMP_PATH_PLAYLIST_FILE] = USER_PATH(BMP_PLAYLIST_BASENAME); | |
418 bmp_paths[BMP_PATH_ACCEL_FILE] = USER_PATH(BMP_ACCEL_BASENAME); | |
419 bmp_paths[BMP_PATH_LOG_FILE] = USER_PATH(BMP_LOG_BASENAME); | |
420 | |
421 g_atexit(bmp_free_paths); | |
422 } | |
423 | |
424 | |
425 void | |
426 bmp_config_load(void) | |
427 { | |
428 ConfigDb *db; | |
429 gint i, length; | |
430 | |
431 memcpy(&cfg, &bmp_default_config, sizeof(BmpConfig)); | |
432 | |
433 db = bmp_cfg_db_open(); | |
434 for (i = 0; i < ncfgbent; ++i) { | |
435 bmp_cfg_db_get_bool(db, NULL, | |
436 bmp_boolents[i].be_vname, | |
437 bmp_boolents[i].be_vloc); | |
438 } | |
439 | |
440 for (i = 0; i < ncfgient; ++i) { | |
441 bmp_cfg_db_get_int(db, NULL, | |
442 bmp_numents[i].ie_vname, | |
443 bmp_numents[i].ie_vloc); | |
444 } | |
445 | |
446 for (i = 0; i < ncfgsent; ++i) { | |
447 bmp_cfg_db_get_string(db, NULL, | |
448 bmp_strents[i].se_vname, | |
449 bmp_strents[i].se_vloc); | |
450 } | |
451 | |
452 /* Preset */ | |
453 bmp_cfg_db_get_float(db, NULL, "equalizer_preamp", &cfg.equalizer_preamp); | |
454 for (i = 0; i < 10; i++) { | |
455 gchar eqtext[18]; | |
456 | |
457 g_snprintf(eqtext, sizeof(eqtext), "equalizer_band%d", i); | |
458 bmp_cfg_db_get_float(db, NULL, eqtext, &cfg.equalizer_bands[i]); | |
459 } | |
460 | |
461 /* History */ | |
462 if (bmp_cfg_db_get_int(db, NULL, "url_history_length", &length)) { | |
463 for (i = 1; i <= length; i++) { | |
464 gchar str[19], *tmp; | |
465 | |
466 g_snprintf(str, sizeof(str), "url_history%d", i); | |
467 if (bmp_cfg_db_get_string(db, NULL, str, &tmp)) | |
468 cfg.url_history = g_list_append(cfg.url_history, tmp); | |
469 } | |
470 } | |
471 | |
472 bmp_cfg_db_close(db); | |
473 | |
474 | |
475 if (cfg.playlist_font && strlen(cfg.playlist_font) == 0) { | |
476 g_free(cfg.playlist_font); | |
477 cfg.playlist_font = NULL; | |
478 } | |
479 | |
480 if (cfg.mainwin_font && strlen(cfg.mainwin_font) == 0) { | |
481 g_free(cfg.mainwin_font); | |
482 cfg.mainwin_font = NULL; | |
483 } | |
484 | |
485 if (!cfg.playlist_font) | |
486 cfg.playlist_font = g_strdup(PLAYLISTWIN_DEFAULT_FONT); | |
487 | |
488 if (!cfg.mainwin_font) | |
489 cfg.mainwin_font = g_strdup(MAINWIN_DEFAULT_FONT); | |
490 | |
491 if (!cfg.gentitle_format) | |
492 cfg.gentitle_format = g_strdup("%p - %t"); | |
493 | |
494 if (!cfg.outputplugin) { | |
495 #ifdef HAVE_OSS | |
496 cfg.outputplugin = g_build_filename(PLUGIN_DIR, plugin_dir_list[0], | |
497 PLUGIN_FILENAME("OSS"), NULL); | |
498 #else | |
499 /* FIXME: This implicitly means the output plugin that is | |
500 * first in the alphabet will be used (usually the disk writer | |
501 * plugin) */ | |
502 cfg.outputplugin = g_strdup(""); | |
503 #endif | |
504 } | |
505 | |
506 if (!cfg.eqpreset_default_file) | |
507 cfg.eqpreset_default_file = g_strdup(EQUALIZER_DEFAULT_DIR_PRESET); | |
508 | |
509 if (!cfg.eqpreset_extension) | |
510 cfg.eqpreset_extension = g_strdup(EQUALIZER_DEFAULT_PRESET_EXT); | |
511 } | |
512 | |
513 | |
514 void | |
515 bmp_config_save(void) | |
516 { | |
517 GList *node; | |
518 gchar *str; | |
519 gint i; | |
520 ConfigDb *db; | |
521 | |
522 cfg.disabled_iplugins = input_stringify_disabled_list(); | |
523 | |
524 | |
525 db = bmp_cfg_db_open(); | |
526 | |
527 for (i = 0; i < ncfgbent; ++i) | |
528 if (bmp_boolents[i].be_wrt) | |
529 bmp_cfg_db_set_bool(db, NULL, | |
530 bmp_boolents[i].be_vname, | |
531 *bmp_boolents[i].be_vloc); | |
532 | |
533 /* HACK: Work-around for bug #129 */ | |
80 | 534 /* |
0 | 535 bmp_cfg_db_set_bool(db, NULL, "playlist_shaded", |
536 FALSE); | |
80 | 537 */ |
0 | 538 for (i = 0; i < ncfgient; ++i) |
539 if (bmp_numents[i].ie_wrt) | |
540 bmp_cfg_db_set_int(db, NULL, | |
541 bmp_numents[i].ie_vname, | |
542 *bmp_numents[i].ie_vloc); | |
543 | |
544 /* This is a bit lame .. it'll end up being written twice, | |
545 * could do with being done a bit neater. -larne */ | |
546 bmp_cfg_db_set_int(db, NULL, "playlist_position", | |
547 playlist_get_position()); | |
548 | |
207
e152a92d3f45
[svn] Save the preference to enable or disable bitmap fonts.
nenolod
parents:
198
diff
changeset
|
549 bmp_cfg_db_set_bool(db, NULL, "mainwin_use_xfont", |
e152a92d3f45
[svn] Save the preference to enable or disable bitmap fonts.
nenolod
parents:
198
diff
changeset
|
550 cfg.mainwin_use_xfont); |
e152a92d3f45
[svn] Save the preference to enable or disable bitmap fonts.
nenolod
parents:
198
diff
changeset
|
551 |
0 | 552 for (i = 0; i < ncfgsent; ++i) { |
553 if (bmp_strents[i].se_wrt) | |
554 bmp_cfg_db_set_string(db, NULL, | |
555 bmp_strents[i].se_vname, | |
556 *bmp_strents[i].se_vloc); | |
557 } | |
558 | |
559 bmp_cfg_db_set_float(db, NULL, "equalizer_preamp", cfg.equalizer_preamp); | |
560 | |
561 for (i = 0; i < 10; i++) { | |
562 str = g_strdup_printf("equalizer_band%d", i); | |
563 bmp_cfg_db_set_float(db, NULL, str, cfg.equalizer_bands[i]); | |
564 g_free(str); | |
565 } | |
566 | |
196 | 567 if (bmp_active_skin != NULL) |
568 { | |
569 if (bmp_active_skin->path) | |
570 bmp_cfg_db_set_string(db, NULL, "skin", bmp_active_skin->path); | |
571 else | |
572 bmp_cfg_db_unset_key(db, NULL, "skin"); | |
573 } | |
0 | 574 |
575 if (get_current_output_plugin()) | |
576 bmp_cfg_db_set_string(db, NULL, "output_plugin", | |
577 get_current_output_plugin()->filename); | |
578 else | |
579 bmp_cfg_db_unset_key(db, NULL, "output_plugin"); | |
580 | |
581 str = general_stringify_enabled_list(); | |
582 if (str) { | |
583 bmp_cfg_db_set_string(db, NULL, "enabled_gplugins", str); | |
584 g_free(str); | |
585 } | |
586 else | |
587 bmp_cfg_db_unset_key(db, NULL, "enabled_gplugins"); | |
588 | |
589 str = vis_stringify_enabled_list(); | |
590 if (str) { | |
591 bmp_cfg_db_set_string(db, NULL, "enabled_vplugins", str); | |
592 g_free(str); | |
593 } | |
594 else | |
595 bmp_cfg_db_unset_key(db, NULL, "enabled_vplugins"); | |
596 | |
597 str = effect_stringify_enabled_list(); | |
598 if (str) { | |
599 bmp_cfg_db_set_string(db, NULL, "enabled_eplugins", str); | |
600 g_free(str); | |
601 } | |
602 else | |
603 bmp_cfg_db_unset_key(db, NULL, "enabled_eplugins"); | |
604 | |
605 if (cfg.filesel_path) | |
606 bmp_cfg_db_set_string(db, NULL, "filesel_path", cfg.filesel_path); | |
607 | |
608 if (cfg.playlist_path) | |
609 bmp_cfg_db_set_string(db, NULL, "playlist_path", cfg.playlist_path); | |
610 | |
611 bmp_cfg_db_set_int(db, NULL, "url_history_length", | |
612 g_list_length(cfg.url_history)); | |
613 | |
614 for (node = cfg.url_history, i = 1; node; node = g_list_next(node), i++) { | |
615 str = g_strdup_printf("url_history%d", i); | |
616 bmp_cfg_db_set_string(db, NULL, str, node->data); | |
617 g_free(str); | |
618 } | |
619 | |
620 bmp_cfg_db_close(db); | |
621 | |
622 playlist_save(bmp_paths[BMP_PATH_PLAYLIST_FILE], FALSE); | |
623 } | |
624 | |
625 static void | |
626 bmp_set_default_icon(void) | |
627 { | |
628 GdkPixbuf *icon; | |
629 | |
120 | 630 icon = gdk_pixbuf_new_from_xpm_data((const gchar **) audacious_player_xpm); |
0 | 631 gtk_window_set_default_icon(icon); |
632 g_object_unref(icon); | |
633 } | |
634 | |
635 static void | |
636 display_usage(void) | |
637 { | |
44 | 638 g_print(_("Usage: audacious [options] [files] ...\n\n" |
0 | 639 "Options:\n" |
640 "--------\n")); | |
641 g_print("\n-h, --help "); | |
642 /* -h, --help switch */ | |
643 g_print(_("Display this text and exit")); | |
644 g_print("\n-n, --session "); | |
645 /* -n, --session switch */ | |
257
256b3acc87d4
[svn] Properly report Audacious instead of XMMS or BMP in all places. Patch by laci; closes bug #379.
chainsaw
parents:
216
diff
changeset
|
646 g_print(_("Select Audacious/BMP/XMMS session (Default: 0)")); |
0 | 647 g_print("\n-r, --rew "); |
648 /* -r, --rew switch */ | |
649 g_print(_("Skip backwards in playlist")); | |
650 g_print("\n-p, --play "); | |
651 /* -p, --play switch */ | |
652 g_print(_("Start playing current playlist")); | |
653 g_print("\n-u, --pause "); | |
654 /* -u, --pause switch */ | |
655 g_print(_("Pause current song")); | |
656 g_print("\n-s, --stop "); | |
657 /* -s, --stop switch */ | |
658 g_print(_("Stop current song")); | |
659 g_print("\n-t, --play-pause "); | |
660 /* -t, --play-pause switch */ | |
661 g_print(_("Pause if playing, play otherwise")); | |
662 g_print("\n-f, --fwd "); | |
663 /* -f, --fwd switch */ | |
664 g_print(_("Skip forward in playlist")); | |
665 g_print("\n-e, --enqueue "); | |
666 /* -e, --enqueue switch */ | |
667 g_print(_("Don't clear the playlist")); | |
668 g_print("\n-m, --show-main-window "); | |
669 /* -m, --show-main-window switch */ | |
670 g_print(_("Show the main window")); | |
671 g_print("\n-a, --activate "); | |
672 /* -a, --activate switch */ | |
257
256b3acc87d4
[svn] Properly report Audacious instead of XMMS or BMP in all places. Patch by laci; closes bug #379.
chainsaw
parents:
216
diff
changeset
|
673 g_print(_("Activate Audacious")); |
0 | 674 g_print("\n-i, --sm-client-id "); |
675 /* -i, --sm-client-id switch */ | |
676 g_print(_("Previous session ID")); | |
316
950f104f2e11
[svn] Fix spacing in --help output, patch by Mikachu.
chainsaw
parents:
284
diff
changeset
|
677 g_print("\n-H, --headless "); |
193 | 678 /* -h, --headless switch */ |
679 g_print(_("Headless operation [experimental]")); | |
0 | 680 g_print("\n-v, --version "); |
681 /* -v, --version switch */ | |
682 g_print(_("Print version number and exit\n")); | |
683 | |
684 exit(EXIT_SUCCESS); | |
685 } | |
686 | |
687 static void | |
688 parse_cmd_line(gint argc, | |
689 gchar ** argv, | |
690 BmpCmdLineOpt * options) | |
691 { | |
692 static struct option long_options[] = { | |
693 {"help", 0, NULL, 'h'}, | |
694 {"session", 1, NULL, 'n'}, | |
695 {"rew", 0, NULL, 'r'}, | |
696 {"play", 0, NULL, 'p'}, | |
697 {"pause", 0, NULL, 'u'}, | |
698 {"play-pause", 0, NULL, 't'}, | |
699 {"stop", 0, NULL, 's'}, | |
700 {"fwd", 0, NULL, 'f'}, | |
701 {"enqueue", 0, NULL, 'e'}, | |
702 {"show-main-window", 0, NULL, 'm'}, | |
703 {"activate", 0, NULL, 'a'}, | |
704 {"version", 0, NULL, 'v'}, | |
705 {"sm-client-id", 1, NULL, 'i'}, | |
706 {"xmms", 0, NULL, 'x'}, | |
191 | 707 {"headless", 0, NULL, 'H'}, |
0 | 708 {0, 0, 0, 0} |
709 }; | |
710 | |
711 gchar *filename, *current_dir; | |
712 gint c, i; | |
713 | |
714 memset(options, 0, sizeof(BmpCmdLineOpt)); | |
715 options->session = -1; | |
716 | |
191 | 717 while ((c = getopt_long(argc, argv, "chn:HrpusfemavtLS", long_options, |
0 | 718 NULL)) != -1) { |
719 switch (c) { | |
720 case 'h': | |
721 display_usage(); | |
722 break; | |
723 case 'n': | |
724 options->session = atoi(optarg); | |
725 break; | |
191 | 726 case 'H': |
727 options->headless = TRUE; | |
728 break; | |
0 | 729 case 'r': |
730 options->rew = TRUE; | |
731 break; | |
732 case 'p': | |
733 options->play = TRUE; | |
734 break; | |
735 case 'u': | |
736 options->pause = TRUE; | |
737 break; | |
738 case 's': | |
739 options->stop = TRUE; | |
740 break; | |
741 case 'f': | |
742 options->fwd = TRUE; | |
743 break; | |
744 case 't': | |
745 options->play_pause = TRUE; | |
746 break; | |
747 case 'm': | |
748 options->mainwin = TRUE; | |
749 break; | |
750 case 'a': | |
751 options->activate = TRUE; | |
752 break; | |
753 case 'e': | |
754 options->enqueue = TRUE; | |
755 break; | |
756 case 'v': | |
757 dump_version(); | |
758 exit(EXIT_SUCCESS); | |
759 break; | |
760 case 'i': | |
761 options->previous_session_id = g_strdup(optarg); | |
762 break; | |
763 case 'c': | |
764 options->playcd = TRUE; | |
765 break; | |
766 case 'S': | |
767 options->load_skins = TRUE; | |
768 break; | |
769 } | |
770 } | |
771 | |
772 current_dir = g_get_current_dir(); | |
773 | |
774 for (i = optind; i < argc; i++) { | |
775 if (argv[i][0] == '/' || strstr(argv[i], "://")) | |
776 filename = g_strdup(argv[i]); | |
777 else | |
778 filename = g_build_filename(current_dir, argv[i], NULL); | |
779 | |
780 options->filenames = g_list_prepend(options->filenames, filename); | |
781 } | |
782 | |
783 options->filenames = g_list_reverse(options->filenames); | |
784 | |
785 g_free(current_dir); | |
786 } | |
787 | |
788 static void | |
789 handle_cmd_line_options(BmpCmdLineOpt * options, | |
790 gboolean remote) | |
791 { | |
792 GList *filenames = options->filenames; | |
793 gint session = options->session; | |
794 | |
795 if (session == -1) { | |
796 if (!remote) | |
797 session = ctrlsocket_get_session_id(); | |
798 else | |
799 session = 0; | |
800 } | |
801 | |
802 if (filenames) { | |
803 gint pos = 0; | |
804 | |
805 if (options->load_skins) { | |
806 xmms_remote_set_skin(session, filenames->data); | |
807 skin_install_skin(filenames->data); | |
808 } | |
809 else { | |
810 if (options->enqueue && options->play) | |
811 pos = xmms_remote_get_playlist_length(session); | |
812 | |
813 if (!options->enqueue) | |
814 xmms_remote_playlist_clear(session); | |
815 | |
816 xmms_remote_playlist_add(session, filenames); | |
817 | |
818 if (options->enqueue && options->play && | |
819 xmms_remote_get_playlist_length(session) > pos) | |
820 xmms_remote_set_playlist_pos(session, pos); | |
821 | |
822 if (!options->enqueue) | |
823 xmms_remote_play(session); | |
824 } | |
825 | |
826 g_list_foreach(filenames, (GFunc) g_free, NULL); | |
827 g_list_free(filenames); | |
828 } | |
829 | |
830 if (options->rew) | |
831 xmms_remote_playlist_prev(session); | |
832 | |
833 if (options->play) | |
834 xmms_remote_play(session); | |
835 | |
836 if (options->pause) | |
837 xmms_remote_pause(session); | |
838 | |
839 if (options->stop) | |
840 xmms_remote_stop(session); | |
841 | |
842 if (options->fwd) | |
843 xmms_remote_playlist_next(session); | |
844 | |
845 if (options->play_pause) | |
846 xmms_remote_play_pause(session); | |
847 | |
848 if (options->mainwin) | |
849 xmms_remote_main_win_toggle(session, TRUE); | |
850 | |
851 if (options->activate) | |
852 xmms_remote_activate(session); | |
853 | |
854 if (options->playcd) | |
855 play_medium(); | |
856 } | |
857 | |
858 static void | |
859 segfault_handler(gint sig) | |
860 { | |
861 g_printerr(_("\nReceived SIGSEGV\n\n" | |
27
d160ae2251e9
[svn] Update SIGSEGV message, contained the BMP mailing information.
nenolod
parents:
0
diff
changeset
|
862 "This could be a bug in Audacious. If you don't know why this happened, " |
d160ae2251e9
[svn] Update SIGSEGV message, contained the BMP mailing information.
nenolod
parents:
0
diff
changeset
|
863 "file a bug at http://bugs.nenolod.net/\n\n")); |
0 | 864 #ifdef HANDLE_SIGSEGV |
865 exit(EXIT_FAILURE); | |
866 #else | |
867 abort(); | |
868 #endif | |
869 } | |
870 | |
871 static void | |
872 bmp_setup_logger(void) | |
873 { | |
874 if (!bmp_logger_start(bmp_paths[BMP_PATH_LOG_FILE])) | |
875 return; | |
876 | |
877 g_atexit(bmp_logger_stop); | |
878 } | |
879 | |
880 static void | |
881 run_load_skin_error_dialog(const gchar * skin_path) | |
882 { | |
883 const gchar *markup = | |
884 N_("<b><big>Unable to load skin.</big></b>\n" | |
885 "\n" | |
886 "Check that skin at '%s' is usable and default skin is properly " | |
887 "installed at '%s'\n"); | |
888 | |
889 GtkWidget *dialog = | |
890 gtk_message_dialog_new_with_markup(NULL, | |
891 GTK_DIALOG_MODAL, | |
892 GTK_MESSAGE_ERROR, | |
893 GTK_BUTTONS_CLOSE, | |
894 _(markup), | |
895 skin_path, | |
896 BMP_DEFAULT_SKIN_PATH); | |
897 gtk_dialog_run(GTK_DIALOG(dialog)); | |
898 gtk_widget_destroy(dialog); | |
899 } | |
900 | |
901 gint | |
902 main(gint argc, gchar ** argv) | |
903 { | |
904 BmpCmdLineOpt options; | |
44 | 905 gboolean gtk_init_check_ok; |
0 | 906 |
907 /* Setup l10n early so we can print localized error messages */ | |
908 gtk_set_locale(); | |
909 bindtextdomain(PACKAGE, LOCALEDIR); | |
910 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
911 textdomain(PACKAGE); | |
912 | |
913 bmp_init_paths(); | |
914 bmp_make_user_dir(); | |
915 bmp_setup_logger(); | |
916 | |
917 /* Check GTK version. Really, this is only needed for binary | |
918 * distribution since configure already checks. */ | |
919 if (!GTK_CHECK_VERSION(2, 4, 0)) { | |
257
256b3acc87d4
[svn] Properly report Audacious instead of XMMS or BMP in all places. Patch by laci; closes bug #379.
chainsaw
parents:
216
diff
changeset
|
920 g_printerr(_("Sorry, your GTK+ version (%d.%d.%d) does not work with Audacious.\n" |
0 | 921 "Please use GTK+ %s or newer.\n"), |
922 gtk_major_version, gtk_minor_version, gtk_micro_version, | |
923 "2.4.0"); | |
924 exit(EXIT_FAILURE); | |
925 } | |
926 | |
927 g_set_application_name(_(application_name)); | |
928 | |
929 g_thread_init(NULL); | |
930 if (!g_thread_supported()) { | |
931 g_printerr(_("Sorry, threads isn't supported on your platform.\n\n" | |
932 "If you're on a libc5 based linux system and installed Glib & GTK+ before you\n" | |
933 "installed LinuxThreads you need to recompile Glib & GTK+.\n")); | |
934 exit(EXIT_FAILURE); | |
935 } | |
936 | |
937 gdk_threads_init(); | |
938 | |
44 | 939 gtk_init_check_ok = gtk_init_check(&argc, &argv); |
940 /* Now let's parse the command line options first. */ | |
941 parse_cmd_line(argc, argv, &options); | |
942 if (!gtk_init_check_ok) { | |
943 // if (!gtk_init_check(&argc, &argv)) { | |
0 | 944 if (argc < 2) { |
945 /* GTK check failed, and no arguments passed to indicate | |
946 that user is intending to only remote control a running | |
947 session */ | |
44 | 948 g_printerr(_("audacious: Unable to open display, exiting.\n")); |
0 | 949 exit(EXIT_FAILURE); |
950 } | |
951 | |
952 handle_cmd_line_options(&options, TRUE); | |
191 | 953 |
954 /* we could be running headless, so GTK probably wont matter */ | |
955 if (options.headless != 1) | |
956 exit(EXIT_SUCCESS); | |
0 | 957 } |
958 | |
959 if (!vfs_init()) { | |
960 g_printerr(Q_("Could not initialize VFS.\n")); | |
961 exit(EXIT_FAILURE); | |
962 } | |
963 | |
964 signal(SIGPIPE, SIG_IGN); /* for controlsocket.c */ | |
965 signal(SIGSEGV, segfault_handler); | |
966 | |
967 g_random_set_seed(time(NULL)); | |
968 | |
969 bmp_config_load(); | |
970 | |
971 if (options.session != -1 || !ctrlsocket_setup()) { | |
972 handle_cmd_line_options(&options, TRUE); | |
973 exit(EXIT_SUCCESS); | |
974 } | |
975 | |
191 | 976 if (options.headless != 1) |
977 { | |
978 check_wm_hints(); | |
0 | 979 |
191 | 980 bmp_set_default_icon(); |
0 | 981 |
191 | 982 gtk_accel_map_load(bmp_paths[BMP_PATH_ACCEL_FILE]); |
0 | 983 |
191 | 984 mainwin_create(); |
985 playlistwin_create(); | |
986 equalizerwin_create(); | |
0 | 987 |
191 | 988 if (!init_skins(cfg.skin)) { |
989 run_load_skin_error_dialog(cfg.skin); | |
990 exit(EXIT_FAILURE); | |
991 } | |
992 | |
993 GDK_THREADS_ENTER(); | |
0 | 994 } |
995 | |
996 plugin_system_init(); | |
997 | |
998 playlist_load(bmp_paths[BMP_PATH_PLAYLIST_FILE]); | |
999 playlist_set_position(cfg.playlist_position); | |
1000 | |
1001 /* this needs to be called after all 3 windows are created and | |
191 | 1002 * input plugins are setup'ed |
1003 * but not if we're running headless --nenolod | |
1004 */ | |
0 | 1005 mainwin_setup_menus(); |
1006 | |
191 | 1007 if (options.headless != 1) |
1008 GDK_THREADS_LEAVE(); | |
0 | 1009 |
1010 ctrlsocket_start(); | |
1011 | |
1012 handle_cmd_line_options(&options, FALSE); | |
1013 | |
191 | 1014 if (options.headless != 1) |
1015 { | |
1016 GDK_THREADS_ENTER(); | |
0 | 1017 |
191 | 1018 read_volume(VOLSET_STARTUP); |
1019 mainwin_set_info_text(); | |
1020 | |
1021 /* FIXME: delayed, because it deals directly with the plugin | |
1022 * interface to set menu items */ | |
1023 create_prefs_window(); | |
0 | 1024 |
191 | 1025 if (cfg.player_visible) |
1026 mainwin_show(TRUE); | |
1027 else if (!cfg.playlist_visible && !cfg.equalizer_visible) | |
1028 mainwin_show(TRUE); | |
125 | 1029 |
191 | 1030 if (cfg.equalizer_visible) |
1031 equalizerwin_show(TRUE); | |
1032 | |
1033 if (cfg.playlist_visible) | |
1034 playlistwin_show(); | |
0 | 1035 |
191 | 1036 /* FIXME: move this away */ |
1037 hint_set_always(cfg.always_on_top); | |
0 | 1038 |
191 | 1039 playlist_start_get_info_thread(); |
1040 mainwin_attach_idle_func(); | |
1041 | |
1042 gtk_main(); | |
1043 | |
1044 GDK_THREADS_LEAVE(); | |
0 | 1045 |
191 | 1046 return EXIT_SUCCESS; |
1047 } | |
1048 else | |
1049 { | |
1050 mainwin_set_info_text(); | |
1051 playlist_start_get_info_thread(); | |
0 | 1052 |
191 | 1053 for (;;) |
192
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
191
diff
changeset
|
1054 { |
197
ccd034857702
[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
nenolod
parents:
196
diff
changeset
|
1055 /* headless eventloop */ |
ccd034857702
[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
nenolod
parents:
196
diff
changeset
|
1056 audcore_generic_events(); |
198 | 1057 free_vis_data(); /* to prevent buffer overflow -- paranoia */ |
191 | 1058 xmms_usleep(10000); |
192
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
191
diff
changeset
|
1059 } |
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
191
diff
changeset
|
1060 |
191 | 1061 return EXIT_SUCCESS; |
1062 } | |
0 | 1063 } |