Mercurial > audlegacy
annotate audacious/main.c @ 486:c4a560cb40f9 trunk
[svn] Always on top fix.
author | nenolod |
---|---|
date | Mon, 23 Jan 2006 14:07:43 -0800 |
parents | 59739d266dba |
children | 1947144093bc |
rev | line source |
---|---|
197
ccd034857702
[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
nenolod
parents:
196
diff
changeset
|
1 /* Audacious - Cross-platform multimedia platform. |
ccd034857702
[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
nenolod
parents:
196
diff
changeset
|
2 * Copyright (C) 2005 Audacious development team. |
ccd034857702
[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
nenolod
parents:
196
diff
changeset
|
3 * |
ccd034857702
[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
nenolod
parents:
196
diff
changeset
|
4 * Based on BMP: |
0 | 5 * Copyright (C) 2003-2004 BMP development team. |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
23 */ | |
24 | |
25 #ifdef HAVE_CONFIG_H | |
26 # include "config.h" | |
27 #endif | |
28 | |
29 #include "main.h" | |
30 | |
31 #include <glib.h> | |
32 #include <glib/gi18n.h> | |
33 #include <glib/gprintf.h> | |
34 #include <gdk/gdk.h> | |
35 #include <stdlib.h> | |
36 #include <string.h> | |
37 #include <getopt.h> | |
38 #include <ctype.h> | |
39 #include <time.h> | |
40 | |
41 #include <unistd.h> | |
42 #include <errno.h> | |
43 #include <sys/types.h> | |
44 #include <sys/stat.h> | |
45 #include <signal.h> | |
46 #include <gdk/gdkx.h> | |
47 #include <X11/Xlib.h> | |
48 #include <X11/Xatom.h> | |
49 | |
50 #include "libaudacious/configdb.h" | |
51 #include "libaudacious/beepctrl.h" | |
52 #include "libaudacious/util.h" | |
53 #include "libaudacious/vfs.h" | |
54 | |
55 #include "controlsocket.h" | |
56 #include "dnd.h" | |
57 #include "dock.h" | |
58 #include "effect.h" | |
59 #include "equalizer.h" | |
60 #include "general.h" | |
197
ccd034857702
[svn] Split up generic events into audcore_generic_events(), and client-specific stuff remains in mainwin_idle_func().
nenolod
parents:
196
diff
changeset
|
61 #include "genevent.h" |
0 | 62 #include "hints.h" |
63 #include "input.h" | |
64 #include "logger.h" | |
65 #include "mainwin.h" | |
66 #include "output.h" | |
284 | 67 #include "libaudcore/playback.h" |
0 | 68 #include "playlist.h" |
383 | 69 #include "ui_playlist.h" |
0 | 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 | |
486 | 315 gboolean starting_up = TRUE; |
0 | 316 |
317 static GSList * | |
318 get_feature_list(void) | |
319 { | |
320 GSList *features = NULL; | |
321 | |
322 #ifdef HAVE_GNOME_VFS | |
323 features = g_slist_append(features, "GNOME VFS"); | |
324 #endif | |
325 | |
326 #ifdef HAVE_GCONF | |
327 features = g_slist_append(features, "GConf"); | |
328 #endif | |
329 | |
330 return features; | |
331 } | |
332 | |
333 static void | |
334 dump_version(void) | |
335 { | |
336 GSList *features; | |
337 | |
338 g_printf("%s %s", _(application_name), VERSION); | |
339 | |
340 features = get_feature_list(); | |
341 | |
342 if (features) { | |
343 GSList *item; | |
344 | |
345 g_printf(" ("); | |
346 | |
347 for (item = features; g_slist_next(item); item = g_slist_next(item)) | |
348 g_printf("%s, ", (const gchar *) item->data); | |
349 | |
350 g_printf("%s)", (const gchar *) item->data); | |
351 | |
352 g_slist_free(features); | |
353 } | |
354 | |
355 g_printf("\n"); | |
356 } | |
357 | |
358 const gchar * | |
359 xmms_get_gentitle_format(void) | |
360 { | |
361 gint titlestring_preset = cfg.titlestring_preset; | |
362 | |
363 if (titlestring_preset < n_titlestring_presets) | |
364 return bmp_titlestring_presets[titlestring_preset]; | |
365 | |
366 return cfg.gentitle_format; | |
367 } | |
368 | |
369 static void | |
370 make_directory(const gchar * path, mode_t mode) | |
371 { | |
372 if (mkdir(path, mode) == 0) | |
373 return; | |
374 | |
375 if (errno == EEXIST) | |
376 return; | |
377 | |
378 g_printerr(_("Could not create directory (%s): %s"), path, | |
379 g_strerror(errno)); | |
380 } | |
381 | |
382 static void | |
383 bmp_make_user_dir(void) | |
384 { | |
385 const mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; | |
386 | |
387 make_directory(bmp_paths[BMP_PATH_USER_DIR], mode755); | |
388 make_directory(bmp_paths[BMP_PATH_USER_PLUGIN_DIR], mode755); | |
389 make_directory(bmp_paths[BMP_PATH_USER_SKIN_DIR], mode755); | |
390 make_directory(bmp_paths[BMP_PATH_SKIN_THUMB_DIR], mode755); | |
391 } | |
392 | |
393 static void | |
394 bmp_free_paths(void) | |
395 { | |
396 int i; | |
397 | |
398 for (i = 0; i < BMP_PATH_COUNT; i++) | |
399 { | |
400 g_free(bmp_paths[i]); | |
401 bmp_paths[i] = 0; | |
402 } | |
403 } | |
404 | |
405 | |
406 #define USER_PATH(path) \ | |
407 g_build_filename(bmp_paths[BMP_PATH_USER_DIR], path, NULL); | |
408 | |
409 static void | |
410 bmp_init_paths(void) | |
411 { | |
412 bmp_paths[BMP_PATH_USER_DIR] = g_build_filename(g_get_home_dir(), BMP_RCPATH, NULL); | |
413 | |
414 bmp_paths[BMP_PATH_USER_PLUGIN_DIR] = USER_PATH(BMP_USER_PLUGIN_DIR_BASENAME); | |
415 bmp_paths[BMP_PATH_USER_SKIN_DIR] = USER_PATH(BMP_SKIN_DIR_BASENAME); | |
416 bmp_paths[BMP_PATH_SKIN_THUMB_DIR] = USER_PATH(BMP_SKIN_THUMB_DIR_BASENAME); | |
417 bmp_paths[BMP_PATH_CONFIG_FILE] = USER_PATH(BMP_CONFIG_BASENAME); | |
418 bmp_paths[BMP_PATH_PLAYLIST_FILE] = USER_PATH(BMP_PLAYLIST_BASENAME); | |
419 bmp_paths[BMP_PATH_ACCEL_FILE] = USER_PATH(BMP_ACCEL_BASENAME); | |
420 bmp_paths[BMP_PATH_LOG_FILE] = USER_PATH(BMP_LOG_BASENAME); | |
421 | |
422 g_atexit(bmp_free_paths); | |
423 } | |
424 | |
425 | |
426 void | |
427 bmp_config_load(void) | |
428 { | |
429 ConfigDb *db; | |
430 gint i, length; | |
431 | |
432 memcpy(&cfg, &bmp_default_config, sizeof(BmpConfig)); | |
433 | |
434 db = bmp_cfg_db_open(); | |
435 for (i = 0; i < ncfgbent; ++i) { | |
436 bmp_cfg_db_get_bool(db, NULL, | |
437 bmp_boolents[i].be_vname, | |
438 bmp_boolents[i].be_vloc); | |
439 } | |
440 | |
441 for (i = 0; i < ncfgient; ++i) { | |
442 bmp_cfg_db_get_int(db, NULL, | |
443 bmp_numents[i].ie_vname, | |
444 bmp_numents[i].ie_vloc); | |
445 } | |
446 | |
447 for (i = 0; i < ncfgsent; ++i) { | |
448 bmp_cfg_db_get_string(db, NULL, | |
449 bmp_strents[i].se_vname, | |
450 bmp_strents[i].se_vloc); | |
451 } | |
452 | |
453 /* Preset */ | |
454 bmp_cfg_db_get_float(db, NULL, "equalizer_preamp", &cfg.equalizer_preamp); | |
455 for (i = 0; i < 10; i++) { | |
456 gchar eqtext[18]; | |
457 | |
458 g_snprintf(eqtext, sizeof(eqtext), "equalizer_band%d", i); | |
459 bmp_cfg_db_get_float(db, NULL, eqtext, &cfg.equalizer_bands[i]); | |
460 } | |
461 | |
462 /* History */ | |
463 if (bmp_cfg_db_get_int(db, NULL, "url_history_length", &length)) { | |
464 for (i = 1; i <= length; i++) { | |
465 gchar str[19], *tmp; | |
466 | |
467 g_snprintf(str, sizeof(str), "url_history%d", i); | |
468 if (bmp_cfg_db_get_string(db, NULL, str, &tmp)) | |
469 cfg.url_history = g_list_append(cfg.url_history, tmp); | |
470 } | |
471 } | |
472 | |
473 bmp_cfg_db_close(db); | |
474 | |
475 | |
476 if (cfg.playlist_font && strlen(cfg.playlist_font) == 0) { | |
477 g_free(cfg.playlist_font); | |
478 cfg.playlist_font = NULL; | |
479 } | |
480 | |
481 if (cfg.mainwin_font && strlen(cfg.mainwin_font) == 0) { | |
482 g_free(cfg.mainwin_font); | |
483 cfg.mainwin_font = NULL; | |
484 } | |
485 | |
486 if (!cfg.playlist_font) | |
487 cfg.playlist_font = g_strdup(PLAYLISTWIN_DEFAULT_FONT); | |
488 | |
489 if (!cfg.mainwin_font) | |
490 cfg.mainwin_font = g_strdup(MAINWIN_DEFAULT_FONT); | |
491 | |
492 if (!cfg.gentitle_format) | |
493 cfg.gentitle_format = g_strdup("%p - %t"); | |
494 | |
495 if (!cfg.outputplugin) { | |
496 #ifdef HAVE_OSS | |
497 cfg.outputplugin = g_build_filename(PLUGIN_DIR, plugin_dir_list[0], | |
498 PLUGIN_FILENAME("OSS"), NULL); | |
499 #else | |
500 /* FIXME: This implicitly means the output plugin that is | |
501 * first in the alphabet will be used (usually the disk writer | |
502 * plugin) */ | |
503 cfg.outputplugin = g_strdup(""); | |
504 #endif | |
505 } | |
506 | |
507 if (!cfg.eqpreset_default_file) | |
508 cfg.eqpreset_default_file = g_strdup(EQUALIZER_DEFAULT_DIR_PRESET); | |
509 | |
510 if (!cfg.eqpreset_extension) | |
511 cfg.eqpreset_extension = g_strdup(EQUALIZER_DEFAULT_PRESET_EXT); | |
512 } | |
513 | |
514 | |
515 void | |
516 bmp_config_save(void) | |
517 { | |
518 GList *node; | |
519 gchar *str; | |
520 gint i; | |
521 ConfigDb *db; | |
522 | |
523 cfg.disabled_iplugins = input_stringify_disabled_list(); | |
524 | |
525 | |
526 db = bmp_cfg_db_open(); | |
527 | |
528 for (i = 0; i < ncfgbent; ++i) | |
529 if (bmp_boolents[i].be_wrt) | |
530 bmp_cfg_db_set_bool(db, NULL, | |
531 bmp_boolents[i].be_vname, | |
532 *bmp_boolents[i].be_vloc); | |
533 | |
534 /* HACK: Work-around for bug #129 */ | |
80 | 535 /* |
0 | 536 bmp_cfg_db_set_bool(db, NULL, "playlist_shaded", |
537 FALSE); | |
80 | 538 */ |
0 | 539 for (i = 0; i < ncfgient; ++i) |
540 if (bmp_numents[i].ie_wrt) | |
541 bmp_cfg_db_set_int(db, NULL, | |
542 bmp_numents[i].ie_vname, | |
543 *bmp_numents[i].ie_vloc); | |
544 | |
545 /* This is a bit lame .. it'll end up being written twice, | |
546 * could do with being done a bit neater. -larne */ | |
547 bmp_cfg_db_set_int(db, NULL, "playlist_position", | |
548 playlist_get_position()); | |
549 | |
207
e152a92d3f45
[svn] Save the preference to enable or disable bitmap fonts.
nenolod
parents:
198
diff
changeset
|
550 bmp_cfg_db_set_bool(db, NULL, "mainwin_use_xfont", |
e152a92d3f45
[svn] Save the preference to enable or disable bitmap fonts.
nenolod
parents:
198
diff
changeset
|
551 cfg.mainwin_use_xfont); |
e152a92d3f45
[svn] Save the preference to enable or disable bitmap fonts.
nenolod
parents:
198
diff
changeset
|
552 |
0 | 553 for (i = 0; i < ncfgsent; ++i) { |
554 if (bmp_strents[i].se_wrt) | |
555 bmp_cfg_db_set_string(db, NULL, | |
556 bmp_strents[i].se_vname, | |
557 *bmp_strents[i].se_vloc); | |
558 } | |
559 | |
560 bmp_cfg_db_set_float(db, NULL, "equalizer_preamp", cfg.equalizer_preamp); | |
561 | |
562 for (i = 0; i < 10; i++) { | |
563 str = g_strdup_printf("equalizer_band%d", i); | |
564 bmp_cfg_db_set_float(db, NULL, str, cfg.equalizer_bands[i]); | |
565 g_free(str); | |
566 } | |
567 | |
196 | 568 if (bmp_active_skin != NULL) |
569 { | |
570 if (bmp_active_skin->path) | |
571 bmp_cfg_db_set_string(db, NULL, "skin", bmp_active_skin->path); | |
572 else | |
573 bmp_cfg_db_unset_key(db, NULL, "skin"); | |
574 } | |
0 | 575 |
576 if (get_current_output_plugin()) | |
577 bmp_cfg_db_set_string(db, NULL, "output_plugin", | |
578 get_current_output_plugin()->filename); | |
579 else | |
580 bmp_cfg_db_unset_key(db, NULL, "output_plugin"); | |
581 | |
582 str = general_stringify_enabled_list(); | |
583 if (str) { | |
584 bmp_cfg_db_set_string(db, NULL, "enabled_gplugins", str); | |
585 g_free(str); | |
586 } | |
587 else | |
588 bmp_cfg_db_unset_key(db, NULL, "enabled_gplugins"); | |
589 | |
590 str = vis_stringify_enabled_list(); | |
591 if (str) { | |
592 bmp_cfg_db_set_string(db, NULL, "enabled_vplugins", str); | |
593 g_free(str); | |
594 } | |
595 else | |
596 bmp_cfg_db_unset_key(db, NULL, "enabled_vplugins"); | |
597 | |
598 str = effect_stringify_enabled_list(); | |
599 if (str) { | |
600 bmp_cfg_db_set_string(db, NULL, "enabled_eplugins", str); | |
601 g_free(str); | |
602 } | |
603 else | |
604 bmp_cfg_db_unset_key(db, NULL, "enabled_eplugins"); | |
605 | |
606 if (cfg.filesel_path) | |
607 bmp_cfg_db_set_string(db, NULL, "filesel_path", cfg.filesel_path); | |
608 | |
609 if (cfg.playlist_path) | |
610 bmp_cfg_db_set_string(db, NULL, "playlist_path", cfg.playlist_path); | |
611 | |
612 bmp_cfg_db_set_int(db, NULL, "url_history_length", | |
613 g_list_length(cfg.url_history)); | |
614 | |
615 for (node = cfg.url_history, i = 1; node; node = g_list_next(node), i++) { | |
616 str = g_strdup_printf("url_history%d", i); | |
617 bmp_cfg_db_set_string(db, NULL, str, node->data); | |
618 g_free(str); | |
619 } | |
620 | |
621 bmp_cfg_db_close(db); | |
622 | |
623 playlist_save(bmp_paths[BMP_PATH_PLAYLIST_FILE], FALSE); | |
624 } | |
625 | |
626 static void | |
627 bmp_set_default_icon(void) | |
628 { | |
629 GdkPixbuf *icon; | |
630 | |
120 | 631 icon = gdk_pixbuf_new_from_xpm_data((const gchar **) audacious_player_xpm); |
0 | 632 gtk_window_set_default_icon(icon); |
633 g_object_unref(icon); | |
634 } | |
635 | |
636 static void | |
637 display_usage(void) | |
638 { | |
44 | 639 g_print(_("Usage: audacious [options] [files] ...\n\n" |
0 | 640 "Options:\n" |
641 "--------\n")); | |
642 g_print("\n-h, --help "); | |
643 /* -h, --help switch */ | |
644 g_print(_("Display this text and exit")); | |
645 g_print("\n-n, --session "); | |
646 /* -n, --session switch */ | |
257
256b3acc87d4
[svn] Properly report Audacious instead of XMMS or BMP in all places. Patch by laci; closes bug #379.
chainsaw
parents:
216
diff
changeset
|
647 g_print(_("Select Audacious/BMP/XMMS session (Default: 0)")); |
0 | 648 g_print("\n-r, --rew "); |
649 /* -r, --rew switch */ | |
650 g_print(_("Skip backwards in playlist")); | |
651 g_print("\n-p, --play "); | |
652 /* -p, --play switch */ | |
653 g_print(_("Start playing current playlist")); | |
654 g_print("\n-u, --pause "); | |
655 /* -u, --pause switch */ | |
656 g_print(_("Pause current song")); | |
657 g_print("\n-s, --stop "); | |
658 /* -s, --stop switch */ | |
659 g_print(_("Stop current song")); | |
660 g_print("\n-t, --play-pause "); | |
661 /* -t, --play-pause switch */ | |
662 g_print(_("Pause if playing, play otherwise")); | |
663 g_print("\n-f, --fwd "); | |
664 /* -f, --fwd switch */ | |
665 g_print(_("Skip forward in playlist")); | |
666 g_print("\n-e, --enqueue "); | |
667 /* -e, --enqueue switch */ | |
668 g_print(_("Don't clear the playlist")); | |
669 g_print("\n-m, --show-main-window "); | |
670 /* -m, --show-main-window switch */ | |
671 g_print(_("Show the main window")); | |
672 g_print("\n-a, --activate "); | |
673 /* -a, --activate switch */ | |
257
256b3acc87d4
[svn] Properly report Audacious instead of XMMS or BMP in all places. Patch by laci; closes bug #379.
chainsaw
parents:
216
diff
changeset
|
674 g_print(_("Activate Audacious")); |
0 | 675 g_print("\n-i, --sm-client-id "); |
676 /* -i, --sm-client-id switch */ | |
677 g_print(_("Previous session ID")); | |
316
950f104f2e11
[svn] Fix spacing in --help output, patch by Mikachu.
chainsaw
parents:
284
diff
changeset
|
678 g_print("\n-H, --headless "); |
193 | 679 /* -h, --headless switch */ |
680 g_print(_("Headless operation [experimental]")); | |
0 | 681 g_print("\n-v, --version "); |
682 /* -v, --version switch */ | |
683 g_print(_("Print version number and exit\n")); | |
684 | |
685 exit(EXIT_SUCCESS); | |
686 } | |
687 | |
688 static void | |
689 parse_cmd_line(gint argc, | |
690 gchar ** argv, | |
691 BmpCmdLineOpt * options) | |
692 { | |
693 static struct option long_options[] = { | |
694 {"help", 0, NULL, 'h'}, | |
695 {"session", 1, NULL, 'n'}, | |
696 {"rew", 0, NULL, 'r'}, | |
697 {"play", 0, NULL, 'p'}, | |
698 {"pause", 0, NULL, 'u'}, | |
699 {"play-pause", 0, NULL, 't'}, | |
700 {"stop", 0, NULL, 's'}, | |
701 {"fwd", 0, NULL, 'f'}, | |
702 {"enqueue", 0, NULL, 'e'}, | |
703 {"show-main-window", 0, NULL, 'm'}, | |
704 {"activate", 0, NULL, 'a'}, | |
705 {"version", 0, NULL, 'v'}, | |
706 {"sm-client-id", 1, NULL, 'i'}, | |
707 {"xmms", 0, NULL, 'x'}, | |
191 | 708 {"headless", 0, NULL, 'H'}, |
0 | 709 {0, 0, 0, 0} |
710 }; | |
711 | |
712 gchar *filename, *current_dir; | |
713 gint c, i; | |
714 | |
715 memset(options, 0, sizeof(BmpCmdLineOpt)); | |
716 options->session = -1; | |
717 | |
191 | 718 while ((c = getopt_long(argc, argv, "chn:HrpusfemavtLS", long_options, |
0 | 719 NULL)) != -1) { |
720 switch (c) { | |
721 case 'h': | |
722 display_usage(); | |
723 break; | |
724 case 'n': | |
725 options->session = atoi(optarg); | |
726 break; | |
191 | 727 case 'H': |
728 options->headless = TRUE; | |
729 break; | |
0 | 730 case 'r': |
731 options->rew = TRUE; | |
732 break; | |
733 case 'p': | |
734 options->play = TRUE; | |
735 break; | |
736 case 'u': | |
737 options->pause = TRUE; | |
738 break; | |
739 case 's': | |
740 options->stop = TRUE; | |
741 break; | |
742 case 'f': | |
743 options->fwd = TRUE; | |
744 break; | |
745 case 't': | |
746 options->play_pause = TRUE; | |
747 break; | |
748 case 'm': | |
749 options->mainwin = TRUE; | |
750 break; | |
751 case 'a': | |
752 options->activate = TRUE; | |
753 break; | |
754 case 'e': | |
755 options->enqueue = TRUE; | |
756 break; | |
757 case 'v': | |
758 dump_version(); | |
759 exit(EXIT_SUCCESS); | |
760 break; | |
761 case 'i': | |
762 options->previous_session_id = g_strdup(optarg); | |
763 break; | |
764 case 'c': | |
765 options->playcd = TRUE; | |
766 break; | |
767 case 'S': | |
768 options->load_skins = TRUE; | |
769 break; | |
770 } | |
771 } | |
772 | |
773 current_dir = g_get_current_dir(); | |
774 | |
775 for (i = optind; i < argc; i++) { | |
776 if (argv[i][0] == '/' || strstr(argv[i], "://")) | |
777 filename = g_strdup(argv[i]); | |
778 else | |
779 filename = g_build_filename(current_dir, argv[i], NULL); | |
780 | |
781 options->filenames = g_list_prepend(options->filenames, filename); | |
782 } | |
783 | |
784 options->filenames = g_list_reverse(options->filenames); | |
785 | |
786 g_free(current_dir); | |
787 } | |
788 | |
789 static void | |
790 handle_cmd_line_options(BmpCmdLineOpt * options, | |
791 gboolean remote) | |
792 { | |
793 GList *filenames = options->filenames; | |
794 gint session = options->session; | |
795 | |
796 if (session == -1) { | |
797 if (!remote) | |
798 session = ctrlsocket_get_session_id(); | |
799 else | |
800 session = 0; | |
801 } | |
802 | |
803 if (filenames) { | |
804 gint pos = 0; | |
805 | |
806 if (options->load_skins) { | |
807 xmms_remote_set_skin(session, filenames->data); | |
808 skin_install_skin(filenames->data); | |
809 } | |
810 else { | |
811 if (options->enqueue && options->play) | |
812 pos = xmms_remote_get_playlist_length(session); | |
813 | |
814 if (!options->enqueue) | |
815 xmms_remote_playlist_clear(session); | |
816 | |
817 xmms_remote_playlist_add(session, filenames); | |
818 | |
819 if (options->enqueue && options->play && | |
820 xmms_remote_get_playlist_length(session) > pos) | |
821 xmms_remote_set_playlist_pos(session, pos); | |
822 | |
823 if (!options->enqueue) | |
824 xmms_remote_play(session); | |
825 } | |
826 | |
827 g_list_foreach(filenames, (GFunc) g_free, NULL); | |
828 g_list_free(filenames); | |
829 } | |
830 | |
831 if (options->rew) | |
832 xmms_remote_playlist_prev(session); | |
833 | |
834 if (options->play) | |
835 xmms_remote_play(session); | |
836 | |
837 if (options->pause) | |
838 xmms_remote_pause(session); | |
839 | |
840 if (options->stop) | |
841 xmms_remote_stop(session); | |
842 | |
843 if (options->fwd) | |
844 xmms_remote_playlist_next(session); | |
845 | |
846 if (options->play_pause) | |
847 xmms_remote_play_pause(session); | |
848 | |
849 if (options->mainwin) | |
850 xmms_remote_main_win_toggle(session, TRUE); | |
851 | |
852 if (options->activate) | |
853 xmms_remote_activate(session); | |
854 | |
855 if (options->playcd) | |
856 play_medium(); | |
857 } | |
858 | |
859 static void | |
860 segfault_handler(gint sig) | |
861 { | |
862 g_printerr(_("\nReceived SIGSEGV\n\n" | |
27
d160ae2251e9
[svn] Update SIGSEGV message, contained the BMP mailing information.
nenolod
parents:
0
diff
changeset
|
863 "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
|
864 "file a bug at http://bugs.nenolod.net/\n\n")); |
0 | 865 #ifdef HANDLE_SIGSEGV |
866 exit(EXIT_FAILURE); | |
867 #else | |
868 abort(); | |
869 #endif | |
870 } | |
871 | |
872 static void | |
873 bmp_setup_logger(void) | |
874 { | |
875 if (!bmp_logger_start(bmp_paths[BMP_PATH_LOG_FILE])) | |
876 return; | |
877 | |
878 g_atexit(bmp_logger_stop); | |
879 } | |
880 | |
881 static void | |
882 run_load_skin_error_dialog(const gchar * skin_path) | |
883 { | |
884 const gchar *markup = | |
885 N_("<b><big>Unable to load skin.</big></b>\n" | |
886 "\n" | |
887 "Check that skin at '%s' is usable and default skin is properly " | |
888 "installed at '%s'\n"); | |
889 | |
890 GtkWidget *dialog = | |
891 gtk_message_dialog_new_with_markup(NULL, | |
892 GTK_DIALOG_MODAL, | |
893 GTK_MESSAGE_ERROR, | |
894 GTK_BUTTONS_CLOSE, | |
895 _(markup), | |
896 skin_path, | |
897 BMP_DEFAULT_SKIN_PATH); | |
898 gtk_dialog_run(GTK_DIALOG(dialog)); | |
899 gtk_widget_destroy(dialog); | |
900 } | |
901 | |
902 gint | |
903 main(gint argc, gchar ** argv) | |
904 { | |
905 BmpCmdLineOpt options; | |
44 | 906 gboolean gtk_init_check_ok; |
0 | 907 |
908 /* Setup l10n early so we can print localized error messages */ | |
909 gtk_set_locale(); | |
910 bindtextdomain(PACKAGE, LOCALEDIR); | |
911 bind_textdomain_codeset(PACKAGE, "UTF-8"); | |
912 textdomain(PACKAGE); | |
913 | |
914 bmp_init_paths(); | |
915 bmp_make_user_dir(); | |
916 bmp_setup_logger(); | |
917 | |
918 /* Check GTK version. Really, this is only needed for binary | |
919 * distribution since configure already checks. */ | |
920 if (!GTK_CHECK_VERSION(2, 4, 0)) { | |
257
256b3acc87d4
[svn] Properly report Audacious instead of XMMS or BMP in all places. Patch by laci; closes bug #379.
chainsaw
parents:
216
diff
changeset
|
921 g_printerr(_("Sorry, your GTK+ version (%d.%d.%d) does not work with Audacious.\n" |
0 | 922 "Please use GTK+ %s or newer.\n"), |
923 gtk_major_version, gtk_minor_version, gtk_micro_version, | |
924 "2.4.0"); | |
925 exit(EXIT_FAILURE); | |
926 } | |
927 | |
928 g_set_application_name(_(application_name)); | |
929 | |
930 g_thread_init(NULL); | |
931 if (!g_thread_supported()) { | |
932 g_printerr(_("Sorry, threads isn't supported on your platform.\n\n" | |
933 "If you're on a libc5 based linux system and installed Glib & GTK+ before you\n" | |
934 "installed LinuxThreads you need to recompile Glib & GTK+.\n")); | |
935 exit(EXIT_FAILURE); | |
936 } | |
937 | |
938 gdk_threads_init(); | |
939 | |
44 | 940 gtk_init_check_ok = gtk_init_check(&argc, &argv); |
941 /* Now let's parse the command line options first. */ | |
942 parse_cmd_line(argc, argv, &options); | |
943 if (!gtk_init_check_ok) { | |
944 // if (!gtk_init_check(&argc, &argv)) { | |
0 | 945 if (argc < 2) { |
946 /* GTK check failed, and no arguments passed to indicate | |
947 that user is intending to only remote control a running | |
948 session */ | |
44 | 949 g_printerr(_("audacious: Unable to open display, exiting.\n")); |
0 | 950 exit(EXIT_FAILURE); |
951 } | |
952 | |
953 handle_cmd_line_options(&options, TRUE); | |
191 | 954 |
955 /* we could be running headless, so GTK probably wont matter */ | |
956 if (options.headless != 1) | |
957 exit(EXIT_SUCCESS); | |
0 | 958 } |
959 | |
960 if (!vfs_init()) { | |
961 g_printerr(Q_("Could not initialize VFS.\n")); | |
962 exit(EXIT_FAILURE); | |
963 } | |
964 | |
965 signal(SIGPIPE, SIG_IGN); /* for controlsocket.c */ | |
966 signal(SIGSEGV, segfault_handler); | |
967 | |
968 g_random_set_seed(time(NULL)); | |
969 | |
970 bmp_config_load(); | |
971 | |
972 if (options.session != -1 || !ctrlsocket_setup()) { | |
973 handle_cmd_line_options(&options, TRUE); | |
974 exit(EXIT_SUCCESS); | |
975 } | |
976 | |
191 | 977 if (options.headless != 1) |
978 { | |
979 bmp_set_default_icon(); | |
0 | 980 |
191 | 981 gtk_accel_map_load(bmp_paths[BMP_PATH_ACCEL_FILE]); |
0 | 982 |
191 | 983 mainwin_create(); |
984 playlistwin_create(); | |
985 equalizerwin_create(); | |
0 | 986 |
191 | 987 if (!init_skins(cfg.skin)) { |
988 run_load_skin_error_dialog(cfg.skin); | |
989 exit(EXIT_FAILURE); | |
990 } | |
991 | |
992 GDK_THREADS_ENTER(); | |
0 | 993 } |
994 | |
995 plugin_system_init(); | |
996 | |
997 playlist_load(bmp_paths[BMP_PATH_PLAYLIST_FILE]); | |
998 playlist_set_position(cfg.playlist_position); | |
999 | |
1000 /* this needs to be called after all 3 windows are created and | |
191 | 1001 * input plugins are setup'ed |
1002 * but not if we're running headless --nenolod | |
1003 */ | |
0 | 1004 mainwin_setup_menus(); |
1005 | |
191 | 1006 if (options.headless != 1) |
1007 GDK_THREADS_LEAVE(); | |
0 | 1008 |
1009 ctrlsocket_start(); | |
1010 | |
1011 handle_cmd_line_options(&options, FALSE); | |
1012 | |
191 | 1013 if (options.headless != 1) |
1014 { | |
1015 GDK_THREADS_ENTER(); | |
0 | 1016 |
191 | 1017 read_volume(VOLSET_STARTUP); |
1018 mainwin_set_info_text(); | |
1019 | |
1020 /* FIXME: delayed, because it deals directly with the plugin | |
1021 * interface to set menu items */ | |
1022 create_prefs_window(); | |
0 | 1023 |
191 | 1024 if (cfg.player_visible) |
1025 mainwin_show(TRUE); | |
1026 else if (!cfg.playlist_visible && !cfg.equalizer_visible) | |
1027 mainwin_show(TRUE); | |
125 | 1028 |
191 | 1029 if (cfg.equalizer_visible) |
1030 equalizerwin_show(TRUE); | |
1031 | |
1032 if (cfg.playlist_visible) | |
1033 playlistwin_show(); | |
0 | 1034 |
191 | 1035 hint_set_always(cfg.always_on_top); |
0 | 1036 |
191 | 1037 playlist_start_get_info_thread(); |
1038 mainwin_attach_idle_func(); | |
1039 | |
486 | 1040 starting_up = FALSE; |
1041 | |
191 | 1042 gtk_main(); |
1043 | |
1044 GDK_THREADS_LEAVE(); | |
0 | 1045 |
191 | 1046 return EXIT_SUCCESS; |
1047 } | |
1048 else | |
1049 { | |
1050 mainwin_set_info_text(); | |
1051 playlist_start_get_info_thread(); | |
0 | 1052 |
486 | 1053 starting_up = FALSE; |
1054 | |
191 | 1055 for (;;) |
192
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
191
diff
changeset
|
1056 { |
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
|
1057 /* 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
|
1058 audcore_generic_events(); |
198 | 1059 free_vis_data(); /* to prevent buffer overflow -- paranoia */ |
191 | 1060 xmms_usleep(10000); |
192
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
191
diff
changeset
|
1061 } |
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
191
diff
changeset
|
1062 |
191 | 1063 return EXIT_SUCCESS; |
1064 } | |
0 | 1065 } |