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