Mercurial > audlegacy
annotate audacious/main.c @ 196:b3b2fc5c8fe9 trunk
[svn] - Fix playback-stop RPC call crash.
- Fix shutdown RPC call crash.
author | nenolod |
---|---|
date | Tue, 15 Nov 2005 19:24:17 -0800 |
parents | 2f351f6e4041 |
children | ccd034857702 |
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 | |
196 | 559 if (bmp_active_skin != NULL) |
560 { | |
561 if (bmp_active_skin->path) | |
562 bmp_cfg_db_set_string(db, NULL, "skin", bmp_active_skin->path); | |
563 else | |
564 bmp_cfg_db_unset_key(db, NULL, "skin"); | |
565 } | |
0 | 566 |
567 if (get_current_output_plugin()) | |
568 bmp_cfg_db_set_string(db, NULL, "output_plugin", | |
569 get_current_output_plugin()->filename); | |
570 else | |
571 bmp_cfg_db_unset_key(db, NULL, "output_plugin"); | |
572 | |
573 str = general_stringify_enabled_list(); | |
574 if (str) { | |
575 bmp_cfg_db_set_string(db, NULL, "enabled_gplugins", str); | |
576 g_free(str); | |
577 } | |
578 else | |
579 bmp_cfg_db_unset_key(db, NULL, "enabled_gplugins"); | |
580 | |
581 str = vis_stringify_enabled_list(); | |
582 if (str) { | |
583 bmp_cfg_db_set_string(db, NULL, "enabled_vplugins", str); | |
584 g_free(str); | |
585 } | |
586 else | |
587 bmp_cfg_db_unset_key(db, NULL, "enabled_vplugins"); | |
588 | |
589 str = effect_stringify_enabled_list(); | |
590 if (str) { | |
591 bmp_cfg_db_set_string(db, NULL, "enabled_eplugins", str); | |
592 g_free(str); | |
593 } | |
594 else | |
595 bmp_cfg_db_unset_key(db, NULL, "enabled_eplugins"); | |
596 | |
597 if (cfg.filesel_path) | |
598 bmp_cfg_db_set_string(db, NULL, "filesel_path", cfg.filesel_path); | |
599 | |
600 if (cfg.playlist_path) | |
601 bmp_cfg_db_set_string(db, NULL, "playlist_path", cfg.playlist_path); | |
602 | |
603 bmp_cfg_db_set_int(db, NULL, "url_history_length", | |
604 g_list_length(cfg.url_history)); | |
605 | |
606 for (node = cfg.url_history, i = 1; node; node = g_list_next(node), i++) { | |
607 str = g_strdup_printf("url_history%d", i); | |
608 bmp_cfg_db_set_string(db, NULL, str, node->data); | |
609 g_free(str); | |
610 } | |
611 | |
612 bmp_cfg_db_close(db); | |
613 | |
614 playlist_save(bmp_paths[BMP_PATH_PLAYLIST_FILE], FALSE); | |
615 } | |
616 | |
617 static void | |
618 bmp_set_default_icon(void) | |
619 { | |
620 GdkPixbuf *icon; | |
621 | |
120 | 622 icon = gdk_pixbuf_new_from_xpm_data((const gchar **) audacious_player_xpm); |
0 | 623 gtk_window_set_default_icon(icon); |
624 g_object_unref(icon); | |
625 } | |
626 | |
627 static void | |
628 display_usage(void) | |
629 { | |
44 | 630 g_print(_("Usage: audacious [options] [files] ...\n\n" |
0 | 631 "Options:\n" |
632 "--------\n")); | |
633 g_print("\n-h, --help "); | |
634 /* -h, --help switch */ | |
635 g_print(_("Display this text and exit")); | |
636 g_print("\n-n, --session "); | |
637 /* -n, --session switch */ | |
44 | 638 g_print(_("Select audacious/BMP/XMMS session (Default: 0)")); |
0 | 639 g_print("\n-r, --rew "); |
640 /* -r, --rew switch */ | |
641 g_print(_("Skip backwards in playlist")); | |
642 g_print("\n-p, --play "); | |
643 /* -p, --play switch */ | |
644 g_print(_("Start playing current playlist")); | |
645 g_print("\n-u, --pause "); | |
646 /* -u, --pause switch */ | |
647 g_print(_("Pause current song")); | |
648 g_print("\n-s, --stop "); | |
649 /* -s, --stop switch */ | |
650 g_print(_("Stop current song")); | |
651 g_print("\n-t, --play-pause "); | |
652 /* -t, --play-pause switch */ | |
653 g_print(_("Pause if playing, play otherwise")); | |
654 g_print("\n-f, --fwd "); | |
655 /* -f, --fwd switch */ | |
656 g_print(_("Skip forward in playlist")); | |
657 g_print("\n-e, --enqueue "); | |
658 /* -e, --enqueue switch */ | |
659 g_print(_("Don't clear the playlist")); | |
660 g_print("\n-m, --show-main-window "); | |
661 /* -m, --show-main-window switch */ | |
662 g_print(_("Show the main window")); | |
663 g_print("\n-a, --activate "); | |
664 /* -a, --activate switch */ | |
44 | 665 g_print(_("Activate audacious")); |
0 | 666 g_print("\n-i, --sm-client-id "); |
667 /* -i, --sm-client-id switch */ | |
668 g_print(_("Previous session ID")); | |
194
2f351f6e4041
[svn] Fix an error on line 666, reported by Mikachu. Ironic that it *would* be line *666*.
nenolod
parents:
193
diff
changeset
|
669 g_print("\n-H, --headless "); |
193 | 670 /* -h, --headless switch */ |
671 g_print(_("Headless operation [experimental]")); | |
0 | 672 g_print("\n-v, --version "); |
673 /* -v, --version switch */ | |
674 g_print(_("Print version number and exit\n")); | |
675 | |
676 exit(EXIT_SUCCESS); | |
677 } | |
678 | |
679 static void | |
680 parse_cmd_line(gint argc, | |
681 gchar ** argv, | |
682 BmpCmdLineOpt * options) | |
683 { | |
684 static struct option long_options[] = { | |
685 {"help", 0, NULL, 'h'}, | |
686 {"session", 1, NULL, 'n'}, | |
687 {"rew", 0, NULL, 'r'}, | |
688 {"play", 0, NULL, 'p'}, | |
689 {"pause", 0, NULL, 'u'}, | |
690 {"play-pause", 0, NULL, 't'}, | |
691 {"stop", 0, NULL, 's'}, | |
692 {"fwd", 0, NULL, 'f'}, | |
693 {"enqueue", 0, NULL, 'e'}, | |
694 {"show-main-window", 0, NULL, 'm'}, | |
695 {"activate", 0, NULL, 'a'}, | |
696 {"version", 0, NULL, 'v'}, | |
697 {"sm-client-id", 1, NULL, 'i'}, | |
698 {"xmms", 0, NULL, 'x'}, | |
191 | 699 {"headless", 0, NULL, 'H'}, |
0 | 700 {0, 0, 0, 0} |
701 }; | |
702 | |
703 gchar *filename, *current_dir; | |
704 gint c, i; | |
705 | |
706 memset(options, 0, sizeof(BmpCmdLineOpt)); | |
707 options->session = -1; | |
708 | |
191 | 709 while ((c = getopt_long(argc, argv, "chn:HrpusfemavtLS", long_options, |
0 | 710 NULL)) != -1) { |
711 switch (c) { | |
712 case 'h': | |
713 display_usage(); | |
714 break; | |
715 case 'n': | |
716 options->session = atoi(optarg); | |
717 break; | |
191 | 718 case 'H': |
719 options->headless = TRUE; | |
720 break; | |
0 | 721 case 'r': |
722 options->rew = TRUE; | |
723 break; | |
724 case 'p': | |
725 options->play = TRUE; | |
726 break; | |
727 case 'u': | |
728 options->pause = TRUE; | |
729 break; | |
730 case 's': | |
731 options->stop = TRUE; | |
732 break; | |
733 case 'f': | |
734 options->fwd = TRUE; | |
735 break; | |
736 case 't': | |
737 options->play_pause = TRUE; | |
738 break; | |
739 case 'm': | |
740 options->mainwin = TRUE; | |
741 break; | |
742 case 'a': | |
743 options->activate = TRUE; | |
744 break; | |
745 case 'e': | |
746 options->enqueue = TRUE; | |
747 break; | |
748 case 'v': | |
749 dump_version(); | |
750 exit(EXIT_SUCCESS); | |
751 break; | |
752 case 'i': | |
753 options->previous_session_id = g_strdup(optarg); | |
754 break; | |
755 case 'c': | |
756 options->playcd = TRUE; | |
757 break; | |
758 case 'S': | |
759 options->load_skins = TRUE; | |
760 break; | |
761 } | |
762 } | |
763 | |
764 current_dir = g_get_current_dir(); | |
765 | |
766 for (i = optind; i < argc; i++) { | |
767 if (argv[i][0] == '/' || strstr(argv[i], "://")) | |
768 filename = g_strdup(argv[i]); | |
769 else | |
770 filename = g_build_filename(current_dir, argv[i], NULL); | |
771 | |
772 options->filenames = g_list_prepend(options->filenames, filename); | |
773 } | |
774 | |
775 options->filenames = g_list_reverse(options->filenames); | |
776 | |
777 g_free(current_dir); | |
778 } | |
779 | |
780 static void | |
781 handle_cmd_line_options(BmpCmdLineOpt * options, | |
782 gboolean remote) | |
783 { | |
784 GList *filenames = options->filenames; | |
785 gint session = options->session; | |
786 | |
787 if (session == -1) { | |
788 if (!remote) | |
789 session = ctrlsocket_get_session_id(); | |
790 else | |
791 session = 0; | |
792 } | |
793 | |
794 if (filenames) { | |
795 gint pos = 0; | |
796 | |
797 if (options->load_skins) { | |
798 xmms_remote_set_skin(session, filenames->data); | |
799 skin_install_skin(filenames->data); | |
800 } | |
801 else { | |
802 if (options->enqueue && options->play) | |
803 pos = xmms_remote_get_playlist_length(session); | |
804 | |
805 if (!options->enqueue) | |
806 xmms_remote_playlist_clear(session); | |
807 | |
808 xmms_remote_playlist_add(session, filenames); | |
809 | |
810 if (options->enqueue && options->play && | |
811 xmms_remote_get_playlist_length(session) > pos) | |
812 xmms_remote_set_playlist_pos(session, pos); | |
813 | |
814 if (!options->enqueue) | |
815 xmms_remote_play(session); | |
816 } | |
817 | |
818 g_list_foreach(filenames, (GFunc) g_free, NULL); | |
819 g_list_free(filenames); | |
820 } | |
821 | |
822 if (options->rew) | |
823 xmms_remote_playlist_prev(session); | |
824 | |
825 if (options->play) | |
826 xmms_remote_play(session); | |
827 | |
828 if (options->pause) | |
829 xmms_remote_pause(session); | |
830 | |
831 if (options->stop) | |
832 xmms_remote_stop(session); | |
833 | |
834 if (options->fwd) | |
835 xmms_remote_playlist_next(session); | |
836 | |
837 if (options->play_pause) | |
838 xmms_remote_play_pause(session); | |
839 | |
840 if (options->mainwin) | |
841 xmms_remote_main_win_toggle(session, TRUE); | |
842 | |
843 if (options->activate) | |
844 xmms_remote_activate(session); | |
845 | |
846 if (options->playcd) | |
847 play_medium(); | |
848 } | |
849 | |
850 static void | |
851 segfault_handler(gint sig) | |
852 { | |
853 g_printerr(_("\nReceived SIGSEGV\n\n" | |
27
d160ae2251e9
[svn] Update SIGSEGV message, contained the BMP mailing information.
nenolod
parents:
0
diff
changeset
|
854 "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
|
855 "file a bug at http://bugs.nenolod.net/\n\n")); |
0 | 856 #ifdef HANDLE_SIGSEGV |
857 exit(EXIT_FAILURE); | |
858 #else | |
859 abort(); | |
860 #endif | |
861 } | |
862 | |
863 static void | |
864 bmp_setup_logger(void) | |
865 { | |
866 if (!bmp_logger_start(bmp_paths[BMP_PATH_LOG_FILE])) | |
867 return; | |
868 | |
869 g_atexit(bmp_logger_stop); | |
870 } | |
871 | |
872 static void | |
873 run_load_skin_error_dialog(const gchar * skin_path) | |
874 { | |
875 const gchar *markup = | |
876 N_("<b><big>Unable to load skin.</big></b>\n" | |
877 "\n" | |
878 "Check that skin at '%s' is usable and default skin is properly " | |
879 "installed at '%s'\n"); | |
880 | |
881 GtkWidget *dialog = | |
882 gtk_message_dialog_new_with_markup(NULL, | |
883 GTK_DIALOG_MODAL, | |
884 GTK_MESSAGE_ERROR, | |
885 GTK_BUTTONS_CLOSE, | |
886 _(markup), | |
887 skin_path, | |
888 BMP_DEFAULT_SKIN_PATH); | |
889 gtk_dialog_run(GTK_DIALOG(dialog)); | |
890 gtk_widget_destroy(dialog); | |
891 } | |
892 | |
893 gint | |
894 main(gint argc, gchar ** argv) | |
895 { | |
896 BmpCmdLineOpt options; | |
44 | 897 gboolean gtk_init_check_ok; |
0 | 898 |
899 /* Setup l10n early so we can print localized error messages */ | |
900 gtk_set_locale(); | |
901 bindtextdomain(PACKAGE, LOCALEDIR); | |
902 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
903 textdomain(PACKAGE); | |
904 | |
905 bmp_init_paths(); | |
906 bmp_make_user_dir(); | |
907 bmp_setup_logger(); | |
908 | |
909 /* Check GTK version. Really, this is only needed for binary | |
910 * distribution since configure already checks. */ | |
911 if (!GTK_CHECK_VERSION(2, 4, 0)) { | |
44 | 912 g_printerr(_("Sorry, your GTK+ version (%d.%d.%d) does not work with audacious.\n" |
0 | 913 "Please use GTK+ %s or newer.\n"), |
914 gtk_major_version, gtk_minor_version, gtk_micro_version, | |
915 "2.4.0"); | |
916 exit(EXIT_FAILURE); | |
917 } | |
918 | |
919 g_set_application_name(_(application_name)); | |
920 | |
921 g_thread_init(NULL); | |
922 if (!g_thread_supported()) { | |
923 g_printerr(_("Sorry, threads isn't supported on your platform.\n\n" | |
924 "If you're on a libc5 based linux system and installed Glib & GTK+ before you\n" | |
925 "installed LinuxThreads you need to recompile Glib & GTK+.\n")); | |
926 exit(EXIT_FAILURE); | |
927 } | |
928 | |
929 gdk_threads_init(); | |
930 | |
44 | 931 gtk_init_check_ok = gtk_init_check(&argc, &argv); |
932 /* Now let's parse the command line options first. */ | |
933 parse_cmd_line(argc, argv, &options); | |
934 if (!gtk_init_check_ok) { | |
935 // if (!gtk_init_check(&argc, &argv)) { | |
0 | 936 if (argc < 2) { |
937 /* GTK check failed, and no arguments passed to indicate | |
938 that user is intending to only remote control a running | |
939 session */ | |
44 | 940 g_printerr(_("audacious: Unable to open display, exiting.\n")); |
0 | 941 exit(EXIT_FAILURE); |
942 } | |
943 | |
944 handle_cmd_line_options(&options, TRUE); | |
191 | 945 |
946 /* we could be running headless, so GTK probably wont matter */ | |
947 if (options.headless != 1) | |
948 exit(EXIT_SUCCESS); | |
0 | 949 } |
950 | |
951 if (!vfs_init()) { | |
952 g_printerr(Q_("Could not initialize VFS.\n")); | |
953 exit(EXIT_FAILURE); | |
954 } | |
955 | |
956 signal(SIGPIPE, SIG_IGN); /* for controlsocket.c */ | |
957 signal(SIGSEGV, segfault_handler); | |
958 | |
959 g_random_set_seed(time(NULL)); | |
960 | |
961 bmp_config_load(); | |
962 | |
963 if (options.session != -1 || !ctrlsocket_setup()) { | |
964 handle_cmd_line_options(&options, TRUE); | |
965 exit(EXIT_SUCCESS); | |
966 } | |
967 | |
191 | 968 if (options.headless != 1) |
969 { | |
970 check_wm_hints(); | |
0 | 971 |
191 | 972 bmp_set_default_icon(); |
0 | 973 |
191 | 974 gtk_accel_map_load(bmp_paths[BMP_PATH_ACCEL_FILE]); |
0 | 975 |
191 | 976 mainwin_create(); |
977 playlistwin_create(); | |
978 equalizerwin_create(); | |
0 | 979 |
191 | 980 if (!init_skins(cfg.skin)) { |
981 run_load_skin_error_dialog(cfg.skin); | |
982 exit(EXIT_FAILURE); | |
983 } | |
984 | |
985 GDK_THREADS_ENTER(); | |
0 | 986 } |
987 | |
988 plugin_system_init(); | |
989 | |
990 playlist_load(bmp_paths[BMP_PATH_PLAYLIST_FILE]); | |
991 playlist_set_position(cfg.playlist_position); | |
992 | |
993 /* this needs to be called after all 3 windows are created and | |
191 | 994 * input plugins are setup'ed |
995 * but not if we're running headless --nenolod | |
996 */ | |
0 | 997 mainwin_setup_menus(); |
998 | |
191 | 999 if (options.headless != 1) |
1000 GDK_THREADS_LEAVE(); | |
0 | 1001 |
1002 ctrlsocket_start(); | |
1003 | |
1004 handle_cmd_line_options(&options, FALSE); | |
1005 | |
191 | 1006 if (options.headless != 1) |
1007 { | |
1008 GDK_THREADS_ENTER(); | |
0 | 1009 |
191 | 1010 read_volume(VOLSET_STARTUP); |
1011 mainwin_set_info_text(); | |
1012 | |
1013 /* FIXME: delayed, because it deals directly with the plugin | |
1014 * interface to set menu items */ | |
1015 create_prefs_window(); | |
0 | 1016 |
191 | 1017 if (cfg.player_visible) |
1018 mainwin_show(TRUE); | |
1019 else if (!cfg.playlist_visible && !cfg.equalizer_visible) | |
1020 mainwin_show(TRUE); | |
125 | 1021 |
191 | 1022 if (cfg.equalizer_visible) |
1023 equalizerwin_show(TRUE); | |
1024 | |
1025 if (cfg.playlist_visible) | |
1026 playlistwin_show(); | |
0 | 1027 |
191 | 1028 /* FIXME: move this away */ |
1029 hint_set_always(cfg.always_on_top); | |
0 | 1030 |
191 | 1031 playlist_start_get_info_thread(); |
1032 mainwin_attach_idle_func(); | |
1033 | |
1034 gtk_main(); | |
1035 | |
1036 GDK_THREADS_LEAVE(); | |
0 | 1037 |
191 | 1038 return EXIT_SUCCESS; |
1039 } | |
1040 else | |
1041 { | |
1042 mainwin_set_info_text(); | |
1043 playlist_start_get_info_thread(); | |
0 | 1044 |
191 | 1045 for (;;) |
192
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
191
diff
changeset
|
1046 { |
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
191
diff
changeset
|
1047 ctrlsocket_check(); |
191 | 1048 xmms_usleep(10000); |
192
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
191
diff
changeset
|
1049 } |
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
191
diff
changeset
|
1050 |
191 | 1051 return EXIT_SUCCESS; |
1052 } | |
0 | 1053 } |