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