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