2313
|
1 /* Audacious - Cross-platform multimedia player
|
|
2 * Copyright (C) 2005-2007 Audacious development team.
|
|
3 *
|
|
4 * Based on BMP:
|
|
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; under version 2 of the License.
|
|
13 *
|
|
14 * This program is distributed in the hope that it will be useful,
|
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 * GNU General Public License for more details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU General Public License
|
|
20 * along with this program; if not, write to the Free Software
|
|
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
22 */
|
|
23
|
|
24 #ifdef HAVE_CONFIG_H
|
|
25 # include "config.h"
|
|
26 #endif
|
|
27
|
|
28 #include "main.h"
|
|
29
|
|
30 #include <glib.h>
|
|
31 #include <glib/gi18n.h>
|
|
32 #include <glib/gprintf.h>
|
|
33 #include <gdk/gdk.h>
|
|
34 #include <stdlib.h>
|
|
35 #include <string.h>
|
|
36 #include <getopt.h>
|
|
37 #include <ctype.h>
|
|
38 #include <time.h>
|
|
39
|
|
40 #include <unistd.h>
|
|
41 #include <errno.h>
|
|
42 #include <sys/types.h>
|
|
43 #include <sys/stat.h>
|
|
44 #include <signal.h>
|
|
45
|
|
46 #include "platform/smartinclude.h"
|
|
47
|
|
48 #include "libaudacious/configdb.h"
|
|
49 #include "libaudacious/beepctrl.h"
|
|
50 #include "libaudacious/util.h"
|
|
51 #include "vfs.h"
|
|
52
|
|
53 #include "controlsocket.h"
|
|
54 #include "dnd.h"
|
|
55 #include "effect.h"
|
|
56 #include "ui_equalizer.h"
|
|
57 #include "general.h"
|
|
58 #include "genevent.h"
|
|
59 #include "hints.h"
|
|
60 #include "input.h"
|
|
61 #include "logger.h"
|
|
62 #include "ui_main.h"
|
|
63 #include "ui_manager.h"
|
|
64 #include "output.h"
|
|
65 #include "playback.h"
|
|
66 #include "playlist.h"
|
|
67 #include "ui_playlist.h"
|
|
68 #include "ui_preferences.h"
|
|
69 #include "pluginenum.h"
|
|
70 #include "ui_skinselector.h"
|
|
71 #include "util.h"
|
|
72 #include "visualization.h"
|
|
73 #include "build_stamp.h"
|
|
74 #include "ui_fileinfo.h"
|
|
75 #include "signals.h"
|
|
76
|
|
77 #include "icons-csource.h"
|
|
78 #include "icons-stock.h"
|
|
79 #include "images/audacious_player.xpm"
|
|
80
|
|
81 gboolean has_x11_connection = FALSE; /* do we have an X11 connection? */
|
|
82
|
|
83 /* Translatable string for beep.desktop's comment field */
|
|
84 const gchar *desktop_comment = N_("Audacious");
|
|
85
|
|
86 const gchar *application_name = N_("Audacious");
|
|
87
|
|
88
|
|
89 struct _BmpCmdLineOpt {
|
|
90 GList *filenames;
|
|
91 gint session;
|
|
92 gboolean play, stop, pause, fwd, rew, play_pause, playcd, show_jump_box;
|
|
93 gboolean enqueue, mainwin, remote, activate;
|
|
94 gboolean load_skins;
|
|
95 gboolean headless;
|
|
96 gboolean no_log;
|
|
97 gboolean enqueue_to_temp;
|
|
98 gchar *previous_session_id;
|
|
99 };
|
|
100
|
|
101 typedef struct _BmpCmdLineOpt BmpCmdLineOpt;
|
|
102
|
|
103 BmpCmdLineOpt options;
|
|
104
|
|
105 BmpConfig cfg;
|
|
106
|
|
107 BmpConfig bmp_default_config = {
|
|
108 MAINWIN_DEFAULT_POS_X, /* mainwin x position */
|
|
109 MAINWIN_DEFAULT_POS_Y, /* mainwin y position */
|
|
110 EQUALIZER_DEFAULT_POS_X, /* equalizer x position */
|
|
111 EQUALIZER_DEFAULT_POS_Y, /* equalizer y position */
|
|
112 PLAYLISTWIN_DEFAULT_POS_X, /* playlistwin x position */
|
|
113 PLAYLISTWIN_DEFAULT_POS_Y, /* playlistwin y position */
|
|
114 PLAYLISTWIN_DEFAULT_WIDTH, /* playlistwin width */
|
|
115 PLAYLISTWIN_DEFAULT_HEIGHT, /* playlistwin height */
|
|
116 10, /* snap distance */
|
|
117 FALSE, /* real-time priority */
|
|
118 FALSE, FALSE, /* shuffle, repeat */
|
|
119 FALSE, /* UNUSED (double size) */
|
|
120 TRUE, /* autoscroll */
|
|
121 TRUE, /* analyzer peaks */
|
|
122 FALSE, /* equalizer autoload */
|
|
123 FALSE, /* easy move */
|
|
124 FALSE, /* equalizer active */
|
|
125 FALSE, /* playlistwin visible */
|
|
126 FALSE, /* equalizer visible */
|
|
127 TRUE, /* player visible */
|
|
128 FALSE, /* player shaded */
|
|
129 FALSE, /* playlistwin shaded */
|
|
130 FALSE, /* equalizer shaded */
|
|
131 FALSE, /* allow multiple instances */
|
|
132 TRUE, /* always show cb */
|
|
133 TRUE, TRUE, TRUE, /* convert '_', %20 and '\' */
|
|
134 TRUE, /* show numbers in playlist */
|
|
135 TRUE, /* snap windows */
|
|
136 TRUE, /* save window positions */
|
|
137 TRUE, /* dim titlebar */
|
|
138 FALSE, /* get playlist info on load */
|
|
139 TRUE, /* get playlist info on demand */
|
|
140 TRUE, /* UNUSED (equalizer doublesize linked) */
|
|
141 FALSE, /* sort jump to file */
|
|
142 FALSE, /* use effect plugins */
|
|
143 FALSE, /* always on top */
|
|
144 FALSE, /* sticky */
|
|
145 FALSE, /* no playlist advance */
|
|
146 FALSE, /* stop after current song */
|
|
147 TRUE, /* refresh file list */
|
|
148 TRUE, /* UNUSED (smooth title scrolling) */
|
|
149 TRUE, /* use playlist metadata */
|
|
150 TRUE, /* warn about unplayables */
|
|
151 FALSE, /* use \ as directory delimiter */
|
|
152 FALSE, /* random skin on play */
|
|
153 FALSE, /* use fontsets */
|
|
154 FALSE, /* use X font for mainwin */
|
|
155 TRUE, /* use custom cursors */
|
|
156 TRUE, /* close dialog on open */
|
|
157 TRUE, /* close dialog on add */
|
|
158 0.0, /* equalizer preamp */
|
|
159 {0, 0, 0, 0, 0, /* equalizer bands */
|
|
160 0, 0, 0, 0, 0},
|
|
161 NULL, /* skin */
|
|
162 NULL, /* output plugin */
|
|
163 NULL, /* file selector path */
|
|
164 NULL, /* playlist path */
|
|
165 NULL, /* playlist font */
|
|
166 NULL, /* mainwin font */
|
|
167 NULL, /* disabled input plugins */
|
|
168 NULL, /* enabled general plugins */
|
|
169 NULL, /* enabled visualization plugins */
|
|
170 NULL, /* enabled effect plugins */
|
|
171 NULL, /* equalizer preset default file */
|
|
172 NULL, /* equalizer preset extension */
|
|
173 NULL, /* URL history */
|
|
174 0, /* timer mode */
|
|
175 VIS_ANALYZER, /* visualizer type */
|
|
176 ANALYZER_NORMAL, /* analyzer mode */
|
|
177 ANALYZER_BARS, /* analyzer type */
|
|
178 SCOPE_DOT, /* scope mode */
|
|
179 VOICEPRINT_NORMAL, /* voiceprint mode */
|
|
180 VU_SMOOTH, /* VU mode */
|
|
181 REFRESH_FULL, /* visualizer refresh rate */
|
|
182 FALLOFF_FAST, /* analyzer fall off rate */
|
|
183 FALLOFF_SLOW, /* peaks fall off rate */
|
|
184 0, /* playlist position */
|
|
185 2, /* pause between songs time */
|
|
186 FALSE, /* pause between songs */
|
|
187 FALSE, /* show window decorations */
|
|
188 8, /* mouse wheel scroll step */
|
|
189 FALSE, /* playlist transparent */
|
|
190 2, /* 3rd preset (ARTIST - ALBUM - TITLE) */
|
|
191 NULL, /* title format */
|
|
192 FALSE, /* software volume control enabled */
|
|
193 TRUE, /* UNUSED (XMMS compatibility mode) */
|
|
194 TRUE, /* extra eq filtering */
|
|
195 3, /* scroll pl by */
|
|
196 FALSE, /* resume playback on startup */
|
|
197 -1, /* resume playback on startup time */
|
|
198 TRUE, /* show seperators in pl */
|
|
199 NULL,
|
|
200 NULL,
|
|
201 3000, /* audio buffer size */
|
|
202 FALSE, /* whether or not to postpone format detection on initial add */
|
|
203 TRUE, /* show filepopup for tuple */
|
|
204 NULL, /* words identifying covers */
|
|
205 NULL, /* words that might not show up in cover names */
|
|
206 FALSE,
|
|
207 0,
|
|
208 NULL, /* default session uri base (non-NULL = custom session uri base) */
|
|
209 150, /* short side length of the picture in the filepopup */
|
|
210 20, /* delay until the filepopup comes up */
|
|
211 FALSE, /* use filename.jpg for coverart */
|
|
212 FALSE, /* use XMMS-style file selection */
|
|
213 TRUE, /* use extension probing */
|
|
214 255, 255, 255, /* colorize r, g, b */
|
|
215 FALSE, /* internal: whether or not to terminate */
|
|
216 };
|
|
217
|
|
218 typedef struct bmp_cfg_boolent_t {
|
|
219 char const *be_vname;
|
|
220 gboolean *be_vloc;
|
|
221 gboolean be_wrt;
|
|
222 } bmp_cfg_boolent;
|
|
223
|
|
224 typedef struct bmp_cfg_nument_t {
|
|
225 char const *ie_vname;
|
|
226 gint *ie_vloc;
|
|
227 gboolean ie_wrt;
|
|
228 } bmp_cfg_nument;
|
|
229
|
|
230 typedef struct bmp_cfg_strent_t {
|
|
231 char const *se_vname;
|
|
232 char **se_vloc;
|
|
233 gboolean se_wrt;
|
|
234 } bmp_cfg_strent;
|
|
235
|
|
236 const gchar *bmp_titlestring_presets[] = {
|
|
237 "%t",
|
|
238 "%{p:%p - %}%t",
|
|
239 "%{p:%p - %}%{a:%a - %}%t",
|
|
240 "%{p:%p - %}%{a:%a - %}%{n:%n. %}%t",
|
|
241 "%{p:%p %}%{a:[ %a ] %}%{p:- %}%{n:%n. %}%{t:%t%}",
|
|
242 "%{a:%a - %}%t"
|
|
243 };
|
|
244
|
|
245 const guint n_titlestring_presets = G_N_ELEMENTS(bmp_titlestring_presets);
|
|
246
|
|
247 const gchar *chardet_detector_presets[] = {
|
|
248 "None",
|
|
249 "Japanese",
|
|
250 "Taiwanese",
|
|
251 "Chinese",
|
|
252 "Korean",
|
|
253 "Russian",
|
|
254 #ifdef HAVE_UDET
|
|
255 "Universal"
|
|
256 #endif
|
|
257 };
|
|
258
|
|
259 const guint n_chardet_detector_presets = G_N_ELEMENTS(chardet_detector_presets);
|
|
260
|
|
261 static bmp_cfg_boolent bmp_boolents[] = {
|
|
262 {"allow_multiple_instances", &cfg.allow_multiple_instances, TRUE},
|
|
263 {"use_realtime", &cfg.use_realtime, TRUE},
|
|
264 {"always_show_cb", &cfg.always_show_cb, TRUE},
|
|
265 {"convert_underscore", &cfg.convert_underscore, TRUE},
|
|
266 {"convert_twenty", &cfg.convert_twenty, TRUE},
|
|
267 {"convert_slash", &cfg.convert_slash, TRUE },
|
|
268 {"show_numbers_in_pl", &cfg.show_numbers_in_pl, TRUE},
|
|
269 {"show_separator_in_pl", &cfg.show_separator_in_pl, TRUE},
|
|
270 {"snap_windows", &cfg.snap_windows, TRUE},
|
|
271 {"save_window_positions", &cfg.save_window_position, TRUE},
|
|
272 {"dim_titlebar", &cfg.dim_titlebar, TRUE},
|
|
273 {"get_info_on_load", &cfg.get_info_on_load, TRUE},
|
|
274 {"get_info_on_demand", &cfg.get_info_on_demand, TRUE},
|
|
275 {"eq_doublesize_linked", &cfg.eq_doublesize_linked, TRUE},
|
|
276 {"no_playlist_advance", &cfg.no_playlist_advance, TRUE},
|
|
277 {"refresh_file_list", &cfg.refresh_file_list, TRUE},
|
|
278 {"sort_jump_to_file", &cfg.sort_jump_to_file, TRUE},
|
|
279 {"use_pl_metadata", &cfg.use_pl_metadata, TRUE},
|
|
280 {"warn_about_unplayables", &cfg.warn_about_unplayables, TRUE},
|
|
281 {"use_backslash_as_dir_delimiter", &cfg.use_backslash_as_dir_delimiter, TRUE},
|
|
282 {"player_shaded", &cfg.player_shaded, TRUE},
|
|
283 {"player_visible", &cfg.player_visible, TRUE},
|
|
284 {"shuffle", &cfg.shuffle, TRUE},
|
|
285 {"repeat", &cfg.repeat, TRUE},
|
|
286 {"doublesize", &cfg.doublesize, TRUE},
|
|
287 {"autoscroll_songname", &cfg.autoscroll, TRUE},
|
|
288 {"stop_after_current_song", &cfg.stopaftersong, TRUE},
|
|
289 {"playlist_shaded", &cfg.playlist_shaded, TRUE},
|
|
290 {"playlist_visible", &cfg.playlist_visible, TRUE},
|
|
291 {"playlist_transparent", &cfg.playlist_transparent, TRUE},
|
|
292 {"use_fontsets", &cfg.use_fontsets, TRUE},
|
|
293 {"mainwin_use_xfont", &cfg.mainwin_use_xfont, FALSE},
|
|
294 {"equalizer_visible", &cfg.equalizer_visible, TRUE},
|
|
295 {"equalizer_active", &cfg.equalizer_active, TRUE},
|
|
296 {"equalizer_shaded", &cfg.equalizer_shaded, TRUE},
|
|
297 {"equalizer_autoload", &cfg.equalizer_autoload, TRUE},
|
|
298 {"easy_move", &cfg.easy_move, TRUE},
|
|
299 {"use_eplugins", &cfg.use_eplugins, TRUE},
|
|
300 {"always_on_top", &cfg.always_on_top, TRUE},
|
|
301 {"sticky", &cfg.sticky, TRUE},
|
|
302 {"random_skin_on_play", &cfg.random_skin_on_play, TRUE},
|
|
303 {"pause_between_songs", &cfg.pause_between_songs, TRUE},
|
|
304 {"show_wm_decorations", &cfg.show_wm_decorations, TRUE},
|
|
305 {"eq_extra_filtering", &cfg.eq_extra_filtering, TRUE},
|
|
306 {"analyzer_peaks", &cfg.analyzer_peaks, TRUE},
|
|
307 {"custom_cursors", &cfg.custom_cursors, TRUE},
|
|
308 {"close_dialog_open", &cfg.close_dialog_open, TRUE},
|
|
309 {"close_dialog_add", &cfg.close_dialog_add, TRUE},
|
|
310 {"resume_playback_on_startup", &cfg.resume_playback_on_startup, TRUE},
|
|
311 {"playlist_detect", &cfg.playlist_detect, TRUE},
|
|
312 {"show_filepopup_for_tuple", &cfg.show_filepopup_for_tuple, TRUE},
|
|
313 {"recurse_for_cover", &cfg.recurse_for_cover, TRUE},
|
|
314 {"use_file_cover", &cfg.use_file_cover, TRUE},
|
|
315 {"use_xmms_style_fileselector", &cfg.use_xmms_style_fileselector, TRUE},
|
|
316 {"use_extension_probing", &cfg.use_extension_probing, TRUE},
|
|
317 };
|
|
318
|
|
319 static gint ncfgbent = G_N_ELEMENTS(bmp_boolents);
|
|
320
|
|
321 static bmp_cfg_nument bmp_numents[] = {
|
|
322 {"player_x", &cfg.player_x, TRUE},
|
|
323 {"player_y", &cfg.player_y, TRUE},
|
|
324 {"timer_mode", &cfg.timer_mode, TRUE},
|
|
325 {"vis_type", &cfg.vis_type, TRUE},
|
|
326 {"analyzer_mode", &cfg.analyzer_mode, TRUE},
|
|
327 {"analyzer_type", &cfg.analyzer_type, TRUE},
|
|
328 {"scope_mode", &cfg.scope_mode, TRUE},
|
|
329 {"vu_mode", &cfg.vu_mode, TRUE},
|
|
330 {"voiceprint_mode", &cfg.voiceprint_mode, TRUE},
|
|
331 {"vis_refresh_rate", &cfg.vis_refresh, TRUE},
|
|
332 {"analyzer_falloff", &cfg.analyzer_falloff, TRUE},
|
|
333 {"peaks_falloff", &cfg.peaks_falloff, TRUE},
|
|
334 {"playlist_x", &cfg.playlist_x, TRUE},
|
|
335 {"playlist_y", &cfg.playlist_y, TRUE},
|
|
336 {"playlist_width", &cfg.playlist_width, TRUE},
|
|
337 {"playlist_height", &cfg.playlist_height, TRUE},
|
|
338 {"playlist_position", &cfg.playlist_position, TRUE},
|
|
339 {"equalizer_x", &cfg.equalizer_x, TRUE},
|
|
340 {"equalizer_y", &cfg.equalizer_y, TRUE},
|
|
341 {"snap_distance", &cfg.snap_distance, TRUE},
|
|
342 {"pause_between_songs_time", &cfg.pause_between_songs_time, TRUE},
|
|
343 {"mouse_wheel_change", &cfg.mouse_change, TRUE},
|
|
344 {"scroll_pl_by", &cfg.scroll_pl_by, TRUE},
|
|
345 {"titlestring_preset", &cfg.titlestring_preset, TRUE},
|
|
346 {"resume_playback_on_startup_time", &cfg.resume_playback_on_startup_time, TRUE},
|
|
347 {"output_buffer_size", &cfg.output_buffer_size, TRUE},
|
|
348 {"recurse_for_cover_depth", &cfg.recurse_for_cover_depth, TRUE},
|
|
349 {"filepopup_pixelsize", &cfg.filepopup_pixelsize, TRUE},
|
|
350 {"filepopup_delay", &cfg.filepopup_delay, TRUE},
|
|
351 {"colorize_r", &cfg.colorize_r, TRUE},
|
|
352 {"colorize_g", &cfg.colorize_g, TRUE},
|
|
353 {"colorize_b", &cfg.colorize_b, TRUE},
|
|
354 };
|
|
355
|
|
356 static gint ncfgient = G_N_ELEMENTS(bmp_numents);
|
|
357
|
|
358 static bmp_cfg_strent bmp_strents[] = {
|
|
359 {"playlist_font", &cfg.playlist_font, TRUE},
|
|
360 {"mainwin_font", &cfg.mainwin_font, TRUE},
|
|
361 {"eqpreset_default_file", &cfg.eqpreset_default_file, TRUE},
|
|
362 {"eqpreset_extension", &cfg.eqpreset_extension, TRUE},
|
|
363 {"skin", &cfg.skin, FALSE},
|
|
364 {"output_plugin", &cfg.outputplugin, FALSE},
|
|
365 {"disabled_iplugins", &cfg.disabled_iplugins, TRUE},
|
|
366 {"enabled_gplugins", &cfg.enabled_gplugins, FALSE},
|
|
367 {"enabled_vplugins", &cfg.enabled_vplugins, FALSE},
|
|
368 {"enabled_eplugins", &cfg.enabled_eplugins, FALSE},
|
|
369 {"filesel_path", &cfg.filesel_path, FALSE},
|
|
370 {"playlist_path", &cfg.playlist_path, FALSE},
|
|
371 {"generic_title_format", &cfg.gentitle_format, TRUE},
|
|
372 {"chardet_detector", &cfg.chardet_detector, TRUE},
|
|
373 {"chardet_fallback", &cfg.chardet_fallback, TRUE},
|
|
374 {"cover_name_include", &cfg.cover_name_include, TRUE},
|
|
375 {"cover_name_exclude", &cfg.cover_name_exclude, TRUE},
|
|
376 {"session_uri_base", &cfg.session_uri_base, TRUE}
|
|
377 };
|
|
378
|
|
379 static gint ncfgsent = G_N_ELEMENTS(bmp_strents);
|
|
380
|
|
381 gchar *bmp_paths[BMP_PATH_COUNT] = {};
|
|
382
|
|
383 GList *dock_window_list = NULL;
|
|
384
|
|
385 gboolean pposition_broken = FALSE;
|
|
386
|
|
387 gboolean starting_up = TRUE;
|
|
388
|
|
389 /* XXX: case-sensitivity is bad for lazy nenolods. :( -nenolod */
|
|
390 static gchar *pl_candidates[] = {
|
|
391 PLUGIN_FILENAME("ALSA"),
|
|
392 PLUGIN_FILENAME("coreaudio"),
|
|
393 PLUGIN_FILENAME("OSS"),
|
|
394 PLUGIN_FILENAME("sun"),
|
|
395 PLUGIN_FILENAME("ESD"),
|
|
396 PLUGIN_FILENAME("pulse_audio"),
|
|
397 PLUGIN_FILENAME("disk_writer"),
|
|
398 NULL
|
|
399 };
|
|
400
|
|
401 GCond *cond_scan;
|
|
402 GMutex *mutex_scan;
|
|
403
|
|
404 static GSList *
|
|
405 get_feature_list(void)
|
|
406 {
|
|
407 GSList *features = NULL;
|
|
408
|
|
409 #ifdef HAVE_GCONF
|
|
410 features = g_slist_append(features, "GConf");
|
|
411 #endif
|
|
412
|
|
413 return features;
|
|
414 }
|
|
415
|
|
416 static void
|
|
417 dump_version(void)
|
|
418 {
|
|
419 GSList *features;
|
|
420
|
|
421 g_printf("%s %s [%s]", _(application_name), VERSION, svn_stamp);
|
|
422
|
|
423 features = get_feature_list();
|
|
424
|
|
425 if (features) {
|
|
426 GSList *item;
|
|
427
|
|
428 g_printf(" (");
|
|
429
|
|
430 for (item = features; g_slist_next(item); item = g_slist_next(item))
|
|
431 g_printf("%s, ", (const gchar *) item->data);
|
|
432
|
|
433 g_printf("%s)", (const gchar *) item->data);
|
|
434
|
|
435 g_slist_free(features);
|
|
436 }
|
|
437
|
|
438 g_printf("\n");
|
|
439 }
|
|
440
|
|
441 const gchar *
|
|
442 xmms_get_gentitle_format(void)
|
|
443 {
|
|
444 guint titlestring_preset = cfg.titlestring_preset;
|
|
445
|
|
446 if (titlestring_preset < n_titlestring_presets)
|
|
447 return bmp_titlestring_presets[titlestring_preset];
|
|
448
|
|
449 return cfg.gentitle_format;
|
|
450 }
|
|
451
|
|
452 void
|
|
453 make_directory(const gchar * path, mode_t mode)
|
|
454 {
|
|
455 if (mkdir(path, mode) == 0)
|
|
456 return;
|
|
457
|
|
458 if (errno == EEXIST)
|
|
459 return;
|
|
460
|
|
461 g_printerr(_("Could not create directory (%s): %s"), path,
|
|
462 g_strerror(errno));
|
|
463 }
|
|
464
|
|
465 static void
|
|
466 bmp_make_user_dir(void)
|
|
467 {
|
|
468 const mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
|
469
|
|
470 make_directory(bmp_paths[BMP_PATH_USER_DIR], mode755);
|
|
471 make_directory(bmp_paths[BMP_PATH_USER_PLUGIN_DIR], mode755);
|
|
472 make_directory(bmp_paths[BMP_PATH_USER_SKIN_DIR], mode755);
|
|
473 make_directory(bmp_paths[BMP_PATH_SKIN_THUMB_DIR], mode755);
|
|
474 }
|
|
475
|
|
476 static void
|
|
477 bmp_free_paths(void)
|
|
478 {
|
|
479 int i;
|
|
480
|
|
481 for (i = 0; i < BMP_PATH_COUNT; i++)
|
|
482 {
|
|
483 g_free(bmp_paths[i]);
|
|
484 bmp_paths[i] = 0;
|
|
485 }
|
|
486 }
|
|
487
|
|
488
|
|
489 #define USER_PATH(path) \
|
|
490 g_build_filename(bmp_paths[BMP_PATH_USER_DIR], path, NULL);
|
|
491
|
|
492 static void
|
|
493 bmp_init_paths(void)
|
|
494 {
|
|
495 bmp_paths[BMP_PATH_USER_DIR] = g_build_filename(g_get_home_dir(), BMP_RCPATH, NULL);
|
|
496
|
|
497 bmp_paths[BMP_PATH_USER_PLUGIN_DIR] = USER_PATH(BMP_USER_PLUGIN_DIR_BASENAME);
|
|
498 bmp_paths[BMP_PATH_USER_SKIN_DIR] = USER_PATH(BMP_SKIN_DIR_BASENAME);
|
|
499 bmp_paths[BMP_PATH_SKIN_THUMB_DIR] = USER_PATH(BMP_SKIN_THUMB_DIR_BASENAME);
|
|
500 bmp_paths[BMP_PATH_CONFIG_FILE] = USER_PATH(BMP_CONFIG_BASENAME);
|
|
501 bmp_paths[BMP_PATH_PLAYLIST_FILE] = USER_PATH(BMP_PLAYLIST_BASENAME);
|
|
502 bmp_paths[BMP_PATH_ACCEL_FILE] = USER_PATH(BMP_ACCEL_BASENAME);
|
|
503 bmp_paths[BMP_PATH_LOG_FILE] = USER_PATH(BMP_LOG_BASENAME);
|
|
504
|
|
505 g_atexit(bmp_free_paths);
|
|
506 }
|
|
507
|
|
508
|
|
509 void
|
|
510 bmp_config_load(void)
|
|
511 {
|
|
512 ConfigDb *db;
|
|
513 gint i, length;
|
|
514
|
|
515 memcpy(&cfg, &bmp_default_config, sizeof(BmpConfig));
|
|
516
|
|
517 db = bmp_cfg_db_open();
|
|
518 for (i = 0; i < ncfgbent; ++i) {
|
|
519 bmp_cfg_db_get_bool(db, NULL,
|
|
520 bmp_boolents[i].be_vname,
|
|
521 bmp_boolents[i].be_vloc);
|
|
522 }
|
|
523
|
|
524 for (i = 0; i < ncfgient; ++i) {
|
|
525 bmp_cfg_db_get_int(db, NULL,
|
|
526 bmp_numents[i].ie_vname,
|
|
527 bmp_numents[i].ie_vloc);
|
|
528 }
|
|
529
|
|
530 for (i = 0; i < ncfgsent; ++i) {
|
|
531 bmp_cfg_db_get_string(db, NULL,
|
|
532 bmp_strents[i].se_vname,
|
|
533 bmp_strents[i].se_vloc);
|
|
534 }
|
|
535
|
|
536 /* Preset */
|
|
537 bmp_cfg_db_get_float(db, NULL, "equalizer_preamp", &cfg.equalizer_preamp);
|
|
538 for (i = 0; i < 10; i++) {
|
|
539 gchar eqtext[18];
|
|
540
|
|
541 g_snprintf(eqtext, sizeof(eqtext), "equalizer_band%d", i);
|
|
542 bmp_cfg_db_get_float(db, NULL, eqtext, &cfg.equalizer_bands[i]);
|
|
543 }
|
|
544
|
|
545 /* History */
|
|
546 if (bmp_cfg_db_get_int(db, NULL, "url_history_length", &length)) {
|
|
547 for (i = 1; i <= length; i++) {
|
|
548 gchar str[19], *tmp;
|
|
549
|
|
550 g_snprintf(str, sizeof(str), "url_history%d", i);
|
|
551 if (bmp_cfg_db_get_string(db, NULL, str, &tmp))
|
|
552 cfg.url_history = g_list_append(cfg.url_history, tmp);
|
|
553 }
|
|
554 }
|
|
555
|
|
556 bmp_cfg_db_close(db);
|
|
557
|
|
558
|
|
559 if (cfg.playlist_font && strlen(cfg.playlist_font) == 0) {
|
|
560 g_free(cfg.playlist_font);
|
|
561 cfg.playlist_font = NULL;
|
|
562 }
|
|
563
|
|
564 if (cfg.mainwin_font && strlen(cfg.mainwin_font) == 0) {
|
|
565 g_free(cfg.mainwin_font);
|
|
566 cfg.mainwin_font = NULL;
|
|
567 }
|
|
568
|
|
569 if (!cfg.playlist_font)
|
|
570 cfg.playlist_font = g_strdup(PLAYLISTWIN_DEFAULT_FONT);
|
|
571
|
|
572 if (!cfg.mainwin_font)
|
|
573 cfg.mainwin_font = g_strdup(MAINWIN_DEFAULT_FONT);
|
|
574
|
|
575 if (!cfg.gentitle_format)
|
|
576 cfg.gentitle_format = g_strdup("%{p:%p - %}%{a:%a - %}%t");
|
|
577
|
|
578 if (!cfg.outputplugin) {
|
|
579 gint iter;
|
|
580 gchar *pl_path = g_build_filename(PLUGIN_DIR, plugin_dir_list[0], NULL);
|
|
581
|
|
582 for (iter = 0; pl_candidates[iter] != NULL && cfg.outputplugin == NULL; iter++)
|
|
583 {
|
|
584 cfg.outputplugin = find_file_recursively(pl_path, pl_candidates[iter]);
|
|
585 }
|
|
586
|
|
587 g_free(pl_path);
|
|
588 }
|
|
589
|
|
590 if (!cfg.eqpreset_default_file)
|
|
591 cfg.eqpreset_default_file = g_strdup(EQUALIZER_DEFAULT_DIR_PRESET);
|
|
592
|
|
593 if (!cfg.eqpreset_extension)
|
|
594 cfg.eqpreset_extension = g_strdup(EQUALIZER_DEFAULT_PRESET_EXT);
|
|
595
|
|
596 if (!cfg.chardet_detector)
|
|
597 cfg.chardet_detector = g_strdup("");
|
|
598
|
|
599 if (!cfg.chardet_fallback)
|
|
600 cfg.chardet_fallback = g_strdup("");
|
|
601
|
|
602 if (!cfg.cover_name_include)
|
|
603 cfg.cover_name_include = g_strdup("");
|
|
604
|
|
605 if (!cfg.cover_name_exclude)
|
|
606 cfg.cover_name_exclude = g_strdup("back");
|
|
607
|
|
608 if (!cfg.session_uri_base)
|
|
609 cfg.session_uri_base = g_strdup("");
|
|
610
|
|
611 /* at least one of these should be true */
|
|
612 if ((!cfg.get_info_on_demand) && (!cfg.get_info_on_load))
|
|
613 cfg.get_info_on_demand = TRUE;
|
|
614 }
|
|
615
|
|
616
|
|
617 void
|
|
618 bmp_config_save(void)
|
|
619 {
|
|
620 GList *node;
|
|
621 gchar *str;
|
|
622 gint i, cur_pb_time;
|
|
623 ConfigDb *db;
|
|
624 Playlist *playlist = playlist_get_active();
|
|
625
|
|
626 cfg.disabled_iplugins = input_stringify_disabled_list();
|
|
627
|
|
628
|
|
629 db = bmp_cfg_db_open();
|
|
630
|
|
631 for (i = 0; i < ncfgbent; ++i)
|
|
632 if (bmp_boolents[i].be_wrt)
|
|
633 bmp_cfg_db_set_bool(db, NULL,
|
|
634 bmp_boolents[i].be_vname,
|
|
635 *bmp_boolents[i].be_vloc);
|
|
636
|
|
637 for (i = 0; i < ncfgient; ++i)
|
|
638 if (bmp_numents[i].ie_wrt)
|
|
639 bmp_cfg_db_set_int(db, NULL,
|
|
640 bmp_numents[i].ie_vname,
|
|
641 *bmp_numents[i].ie_vloc);
|
|
642
|
|
643 /* This is a bit lame .. it'll end up being written twice,
|
|
644 * could do with being done a bit neater. -larne */
|
|
645 bmp_cfg_db_set_int(db, NULL, "playlist_position",
|
|
646 playlist_get_position(playlist));
|
|
647
|
|
648 bmp_cfg_db_set_bool(db, NULL, "mainwin_use_xfont",
|
|
649 cfg.mainwin_use_xfont);
|
|
650
|
|
651 for (i = 0; i < ncfgsent; ++i) {
|
|
652 if (bmp_strents[i].se_wrt)
|
|
653 bmp_cfg_db_set_string(db, NULL,
|
|
654 bmp_strents[i].se_vname,
|
|
655 *bmp_strents[i].se_vloc);
|
|
656 }
|
|
657
|
|
658 bmp_cfg_db_set_float(db, NULL, "equalizer_preamp", cfg.equalizer_preamp);
|
|
659
|
|
660 for (i = 0; i < 10; i++) {
|
|
661 str = g_strdup_printf("equalizer_band%d", i);
|
|
662 bmp_cfg_db_set_float(db, NULL, str, cfg.equalizer_bands[i]);
|
|
663 g_free(str);
|
|
664 }
|
|
665
|
|
666 if (bmp_active_skin != NULL)
|
|
667 {
|
|
668 if (bmp_active_skin->path)
|
|
669 bmp_cfg_db_set_string(db, NULL, "skin", bmp_active_skin->path);
|
|
670 else
|
|
671 bmp_cfg_db_unset_key(db, NULL, "skin");
|
|
672 }
|
|
673
|
|
674 if (get_current_output_plugin())
|
|
675 bmp_cfg_db_set_string(db, NULL, "output_plugin",
|
|
676 get_current_output_plugin()->filename);
|
|
677 else
|
|
678 bmp_cfg_db_unset_key(db, NULL, "output_plugin");
|
|
679
|
|
680 str = general_stringify_enabled_list();
|
|
681 if (str) {
|
|
682 bmp_cfg_db_set_string(db, NULL, "enabled_gplugins", str);
|
|
683 g_free(str);
|
|
684 }
|
|
685 else
|
|
686 bmp_cfg_db_unset_key(db, NULL, "enabled_gplugins");
|
|
687
|
|
688 str = vis_stringify_enabled_list();
|
|
689 if (str) {
|
|
690 bmp_cfg_db_set_string(db, NULL, "enabled_vplugins", str);
|
|
691 g_free(str);
|
|
692 }
|
|
693 else
|
|
694 bmp_cfg_db_unset_key(db, NULL, "enabled_vplugins");
|
|
695
|
|
696 str = effect_stringify_enabled_list();
|
|
697 if (str) {
|
|
698 bmp_cfg_db_set_string(db, NULL, "enabled_eplugins", str);
|
|
699 g_free(str);
|
|
700 }
|
|
701 else
|
|
702 bmp_cfg_db_unset_key(db, NULL, "enabled_eplugins");
|
|
703
|
|
704 if (cfg.filesel_path)
|
|
705 bmp_cfg_db_set_string(db, NULL, "filesel_path", cfg.filesel_path);
|
|
706
|
|
707 if (cfg.playlist_path)
|
|
708 bmp_cfg_db_set_string(db, NULL, "playlist_path", cfg.playlist_path);
|
|
709
|
|
710 bmp_cfg_db_set_int(db, NULL, "url_history_length",
|
|
711 g_list_length(cfg.url_history));
|
|
712
|
|
713 for (node = cfg.url_history, i = 1; node; node = g_list_next(node), i++) {
|
|
714 str = g_strdup_printf("url_history%d", i);
|
|
715 bmp_cfg_db_set_string(db, NULL, str, node->data);
|
|
716 g_free(str);
|
|
717 }
|
|
718
|
|
719 if (playback_get_playing()) {
|
|
720 cur_pb_time = playback_get_time();
|
|
721 } else
|
|
722 cur_pb_time = -1;
|
|
723 cfg.resume_playback_on_startup_time = cur_pb_time;
|
|
724 bmp_cfg_db_set_int(db, NULL, "resume_playback_on_startup_time",
|
|
725 cfg.resume_playback_on_startup_time);
|
|
726
|
|
727 bmp_cfg_db_close(db);
|
|
728
|
|
729 playlist_save(playlist, bmp_paths[BMP_PATH_PLAYLIST_FILE]);
|
|
730 }
|
|
731
|
|
732 static void
|
|
733 bmp_set_default_icon(void)
|
|
734 {
|
|
735 GdkPixbuf *icon;
|
|
736
|
|
737 icon = gdk_pixbuf_new_from_xpm_data((const gchar **) audacious_player_xpm);
|
|
738 gtk_window_set_default_icon(icon);
|
|
739 g_object_unref(icon);
|
|
740 }
|
|
741
|
|
742 static void
|
|
743 register_aud_stock_icons(void)
|
|
744 {
|
|
745 GtkIconFactory *iconfactory = gtk_icon_factory_new();
|
|
746 GtkIconSet *iconset;
|
|
747 GdkPixbuf *pixbuf;
|
|
748
|
|
749 /* pick images in icons-csource.h */
|
|
750 pixbuf = gdk_pixbuf_new_from_inline( -1 , removedups_pixbuf , FALSE , NULL );
|
|
751 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
752 gtk_icon_factory_add( iconfactory , AUD_STOCK_REMOVEDUPS , iconset );
|
|
753 pixbuf = gdk_pixbuf_new_from_inline( -1 , removeunavail_pixbuf , FALSE , NULL );
|
|
754 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
755 gtk_icon_factory_add( iconfactory , AUD_STOCK_REMOVEUNAVAIL , iconset );
|
|
756 pixbuf = gdk_pixbuf_new_from_inline( -1 , randomizepl_pixbuf , FALSE , NULL );
|
|
757 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
758 gtk_icon_factory_add( iconfactory , AUD_STOCK_RANDOMIZEPL , iconset );
|
|
759 pixbuf = gdk_pixbuf_new_from_inline( -1 , sortbytitle_pixbuf , FALSE , NULL );
|
|
760 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
761 gtk_icon_factory_add( iconfactory , AUD_STOCK_SORTBYTITLE , iconset );
|
|
762 pixbuf = gdk_pixbuf_new_from_inline( -1 , sortbyfilename_pixbuf , FALSE , NULL );
|
|
763 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
764 gtk_icon_factory_add( iconfactory , AUD_STOCK_SORTBYFILENAME , iconset );
|
|
765 pixbuf = gdk_pixbuf_new_from_inline( -1 , sortbyartist_pixbuf , FALSE , NULL );
|
|
766 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
767 gtk_icon_factory_add( iconfactory , AUD_STOCK_SORTBYARTIST , iconset );
|
|
768 pixbuf = gdk_pixbuf_new_from_inline( -1 , sortbypathfile_pixbuf , FALSE , NULL );
|
|
769 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
770 gtk_icon_factory_add( iconfactory , AUD_STOCK_SORTBYPATHFILE , iconset );
|
|
771 pixbuf = gdk_pixbuf_new_from_inline( -1 , selectnone_pixbuf , FALSE , NULL );
|
|
772 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
773 gtk_icon_factory_add( iconfactory , AUD_STOCK_SELECTNONE , iconset );
|
|
774 pixbuf = gdk_pixbuf_new_from_inline( -1 , selectall_pixbuf , FALSE , NULL );
|
|
775 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
776 gtk_icon_factory_add( iconfactory , AUD_STOCK_SELECTALL , iconset );
|
|
777 pixbuf = gdk_pixbuf_new_from_inline( -1 , selectinvert_pixbuf , FALSE , NULL );
|
|
778 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
779 gtk_icon_factory_add( iconfactory , AUD_STOCK_SELECTINVERT , iconset );
|
|
780 pixbuf = gdk_pixbuf_new_from_inline( -1 , invertpl_pixbuf , FALSE , NULL );
|
|
781 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
782 gtk_icon_factory_add( iconfactory , AUD_STOCK_INVERTPL , iconset );
|
|
783 pixbuf = gdk_pixbuf_new_from_inline( -1 , queuetoggle_pixbuf , FALSE , NULL );
|
|
784 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
785 gtk_icon_factory_add( iconfactory , AUD_STOCK_QUEUETOGGLE , iconset );
|
|
786 pixbuf = gdk_pixbuf_new_from_inline( -1 , info_pixbuf , FALSE , NULL );
|
|
787 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
788 gtk_icon_factory_add( iconfactory , AUD_STOCK_INFO , iconset );
|
|
789 pixbuf = gdk_pixbuf_new_from_inline( -1 , playlist_pixbuf , FALSE , NULL );
|
|
790 iconset = gtk_icon_set_new_from_pixbuf( pixbuf ); g_object_unref( pixbuf );
|
|
791 gtk_icon_factory_add( iconfactory , AUD_STOCK_PLAYLIST , iconset );
|
|
792
|
|
793 gtk_icon_factory_add_default( iconfactory );
|
|
794 g_object_unref( iconfactory );
|
|
795 }
|
|
796
|
|
797 static void
|
|
798 display_usage(void)
|
|
799 {
|
|
800 g_print(_("Usage: audacious [options] [files] ...\n\n"
|
|
801 "Options:\n"
|
|
802 "--------\n"));
|
|
803 g_print("\n-h, --help ");
|
|
804 /* -h, --help switch */
|
|
805 g_print(_("Display this text and exit"));
|
|
806 g_print("\n-n, --session ");
|
|
807 /* -n, --session switch */
|
|
808 g_print(_("Select Audacious/BMP/XMMS session (Default: 0)"));
|
|
809 g_print("\n-r, --rew ");
|
|
810 /* -r, --rew switch */
|
|
811 g_print(_("Skip backwards in playlist"));
|
|
812 g_print("\n-p, --play ");
|
|
813 /* -p, --play switch */
|
|
814 g_print(_("Start playing current playlist"));
|
|
815 g_print("\n-u, --pause ");
|
|
816 /* -u, --pause switch */
|
|
817 g_print(_("Pause current song"));
|
|
818 g_print("\n-s, --stop ");
|
|
819 /* -s, --stop switch */
|
|
820 g_print(_("Stop current song"));
|
|
821 g_print("\n-t, --play-pause ");
|
|
822 /* -t, --play-pause switch */
|
|
823 g_print(_("Pause if playing, play otherwise"));
|
|
824 g_print("\n-f, --fwd ");
|
|
825 /* -f, --fwd switch */
|
|
826 g_print(_("Skip forward in playlist"));
|
|
827 g_print("\n-j, --show-jump-box ");
|
|
828 /* -j, --show-jump-box switch */
|
|
829 g_print(_("Display Jump to file dialog"));
|
|
830 g_print("\n-e, --enqueue ");
|
|
831 /* -e, --enqueue switch */
|
|
832 g_print(_("Don't clear the playlist"));
|
|
833 g_print("\n-m, --show-main-window ");
|
|
834 /* -m, --show-main-window switch */
|
|
835 g_print(_("Show the main window"));
|
|
836 g_print("\n-a, --activate ");
|
|
837 /* -a, --activate switch */
|
|
838 g_print(_("Activate Audacious"));
|
|
839 g_print("\n-i, --sm-client-id ");
|
|
840 /* -i, --sm-client-id switch */
|
|
841 g_print(_("Previous session ID"));
|
|
842 g_print("\n-H, --headless ");
|
|
843 /* -h, --headless switch */
|
|
844 g_print(_("Headless operation [experimental]"));
|
|
845 g_print("\n-N, --no-log ");
|
|
846 /* -N, --no-log switch */
|
|
847 g_print(_("Disable error/warning interception (logging)"));
|
|
848 g_print("\n-v, --version ");
|
|
849 /* -v, --version switch */
|
|
850 g_print(_("Print version number and exit\n"));
|
|
851
|
|
852 exit(EXIT_SUCCESS);
|
|
853 }
|
|
854
|
|
855 static void
|
|
856 parse_cmd_line(gint argc,
|
|
857 gchar ** argv,
|
|
858 BmpCmdLineOpt * options)
|
|
859 {
|
|
860 static struct option long_options[] = {
|
|
861 {"help", 0, NULL, 'h'},
|
|
862 {"session", 1, NULL, 'n'},
|
|
863 {"rew", 0, NULL, 'r'},
|
|
864 {"play", 0, NULL, 'p'},
|
|
865 {"pause", 0, NULL, 'u'},
|
|
866 {"play-pause", 0, NULL, 't'},
|
|
867 {"stop", 0, NULL, 's'},
|
|
868 {"fwd", 0, NULL, 'f'},
|
|
869 {"show-jump-box", 0, NULL, 'j'},
|
|
870 {"enqueue", 0, NULL, 'e'},
|
|
871 {"enqueue-to-temp", 0, NULL, 'E'},
|
|
872 {"show-main-window", 0, NULL, 'm'},
|
|
873 {"activate", 0, NULL, 'a'},
|
|
874 {"version", 0, NULL, 'v'},
|
|
875 {"sm-client-id", 1, NULL, 'i'},
|
|
876 {"xmms", 0, NULL, 'x'},
|
|
877 {"headless", 0, NULL, 'H'},
|
|
878 {"no-log", 0, NULL, 'N'},
|
|
879 {0, 0, 0, 0}
|
|
880 };
|
|
881
|
|
882 gchar *filename, *current_dir;
|
|
883 gint c, i;
|
|
884
|
|
885 memset(options, 0, sizeof(BmpCmdLineOpt));
|
|
886 options->session = -1;
|
|
887
|
|
888 while ((c = getopt_long(argc, argv, "chn:HrpusfemavtLSjE", long_options,
|
|
889 NULL)) != -1) {
|
|
890 switch (c) {
|
|
891 case 'h':
|
|
892 display_usage();
|
|
893 break;
|
|
894 case 'n':
|
|
895 options->session = atoi(optarg);
|
|
896 break;
|
|
897 case 'H':
|
|
898 options->headless = TRUE;
|
|
899 break;
|
|
900 case 'r':
|
|
901 options->rew = TRUE;
|
|
902 break;
|
|
903 case 'p':
|
|
904 options->play = TRUE;
|
|
905 break;
|
|
906 case 'u':
|
|
907 options->pause = TRUE;
|
|
908 break;
|
|
909 case 's':
|
|
910 options->stop = TRUE;
|
|
911 break;
|
|
912 case 'f':
|
|
913 options->fwd = TRUE;
|
|
914 break;
|
|
915 case 't':
|
|
916 options->play_pause = TRUE;
|
|
917 break;
|
|
918 case 'j':
|
|
919 options->show_jump_box = TRUE;
|
|
920 break;
|
|
921 case 'm':
|
|
922 options->mainwin = TRUE;
|
|
923 break;
|
|
924 case 'a':
|
|
925 options->activate = TRUE;
|
|
926 break;
|
|
927 case 'E':
|
|
928 options->enqueue_to_temp = TRUE;
|
|
929 break;
|
|
930 case 'e':
|
|
931 options->enqueue = TRUE;
|
|
932 break;
|
|
933 case 'v':
|
|
934 dump_version();
|
|
935 exit(EXIT_SUCCESS);
|
|
936 break;
|
|
937 case 'i':
|
|
938 options->previous_session_id = g_strdup(optarg);
|
|
939 break;
|
|
940 case 'c':
|
|
941 options->playcd = TRUE;
|
|
942 break;
|
|
943 case 'S':
|
|
944 options->load_skins = TRUE;
|
|
945 break;
|
|
946 case 'N':
|
|
947 options->no_log = TRUE;
|
|
948 break;
|
|
949 }
|
|
950 }
|
|
951
|
|
952 current_dir = g_get_current_dir();
|
|
953
|
|
954 for (i = optind; i < argc; i++) {
|
|
955 if (argv[i][0] == '/' || strstr(argv[i], "://"))
|
|
956 filename = g_strdup(argv[i]);
|
|
957 else
|
|
958 filename = g_build_filename(current_dir, argv[i], NULL);
|
|
959
|
|
960 options->filenames = g_list_prepend(options->filenames, filename);
|
|
961 }
|
|
962
|
|
963 options->filenames = g_list_reverse(options->filenames);
|
|
964
|
|
965 g_free(current_dir);
|
|
966 }
|
|
967
|
|
968 static void
|
|
969 handle_cmd_line_options(BmpCmdLineOpt * options,
|
|
970 gboolean remote)
|
|
971 {
|
|
972 GList *filenames = options->filenames;
|
|
973 gint session = options->session;
|
|
974
|
|
975 if (session == -1) {
|
|
976 if (!remote)
|
|
977 session = ctrlsocket_get_session_id();
|
|
978 else
|
|
979 session = 0;
|
|
980 }
|
|
981
|
|
982 if (filenames) {
|
|
983 gint pos = 0;
|
|
984
|
|
985 if (options->load_skins) {
|
|
986 xmms_remote_set_skin(session, filenames->data);
|
|
987 skin_install_skin(filenames->data);
|
|
988 }
|
|
989 else {
|
|
990 if (options->enqueue_to_temp)
|
|
991 xmms_remote_playlist_enqueue_to_temp(session, filenames->data);
|
|
992
|
|
993 if (options->enqueue && options->play)
|
|
994 pos = xmms_remote_get_playlist_length(session);
|
|
995
|
|
996 if (!options->enqueue)
|
|
997 xmms_remote_playlist_clear(session);
|
|
998
|
|
999 xmms_remote_playlist_add(session, filenames);
|
|
1000
|
|
1001 if (options->enqueue && options->play &&
|
|
1002 xmms_remote_get_playlist_length(session) > pos)
|
|
1003 xmms_remote_set_playlist_pos(session, pos);
|
|
1004
|
|
1005 if (!options->enqueue)
|
|
1006 xmms_remote_play(session);
|
|
1007 }
|
|
1008
|
|
1009 g_list_foreach(filenames, (GFunc) g_free, NULL);
|
|
1010 g_list_free(filenames);
|
|
1011 }
|
|
1012
|
|
1013 if (options->rew)
|
|
1014 xmms_remote_playlist_prev(session);
|
|
1015
|
|
1016 if (options->play)
|
|
1017 xmms_remote_play(session);
|
|
1018
|
|
1019 if (options->pause)
|
|
1020 xmms_remote_pause(session);
|
|
1021
|
|
1022 if (options->stop)
|
|
1023 xmms_remote_stop(session);
|
|
1024
|
|
1025 if (options->fwd)
|
|
1026 xmms_remote_playlist_next(session);
|
|
1027
|
|
1028 if (options->play_pause)
|
|
1029 xmms_remote_play_pause(session);
|
|
1030
|
|
1031 if (options->show_jump_box)
|
|
1032 xmms_remote_show_jtf_box(session);
|
|
1033
|
|
1034 if (options->mainwin)
|
|
1035 xmms_remote_main_win_toggle(session, TRUE);
|
|
1036
|
|
1037 if (options->activate)
|
|
1038 xmms_remote_activate(session);
|
|
1039
|
|
1040 if (options->playcd)
|
|
1041 play_medium();
|
|
1042 }
|
|
1043
|
|
1044 static void
|
|
1045 bmp_setup_logger(void)
|
|
1046 {
|
|
1047 if (!bmp_logger_start(bmp_paths[BMP_PATH_LOG_FILE]))
|
|
1048 return;
|
|
1049
|
|
1050 g_atexit(bmp_logger_stop);
|
|
1051 }
|
|
1052
|
|
1053 static void
|
|
1054 run_load_skin_error_dialog(const gchar * skin_path)
|
|
1055 {
|
|
1056 const gchar *markup =
|
|
1057 N_("<b><big>Unable to load skin.</big></b>\n"
|
|
1058 "\n"
|
|
1059 "Check that skin at '%s' is usable and default skin is properly "
|
|
1060 "installed at '%s'\n");
|
|
1061
|
|
1062 GtkWidget *dialog =
|
|
1063 gtk_message_dialog_new_with_markup(NULL,
|
|
1064 GTK_DIALOG_MODAL,
|
|
1065 GTK_MESSAGE_ERROR,
|
|
1066 GTK_BUTTONS_CLOSE,
|
|
1067 _(markup),
|
|
1068 skin_path,
|
|
1069 BMP_DEFAULT_SKIN_PATH);
|
|
1070 gtk_dialog_run(GTK_DIALOG(dialog));
|
|
1071 gtk_widget_destroy(dialog);
|
|
1072 }
|
|
1073
|
|
1074 // use a format string?
|
|
1075 void report_error(const gchar *error_text)
|
|
1076 {
|
|
1077 fprintf(stderr,error_text);
|
|
1078 if (options.headless!=1) {
|
|
1079 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(err),
|
|
1080 error_text);
|
|
1081 gtk_dialog_run(GTK_DIALOG(err));
|
|
1082 gtk_widget_hide(err);
|
|
1083 }
|
|
1084 }
|
|
1085
|
|
1086 gint
|
|
1087 main(gint argc, gchar ** argv)
|
|
1088 {
|
|
1089 gboolean gtk_init_check_ok;
|
|
1090 Playlist *playlist;
|
|
1091
|
|
1092 /* Setup l10n early so we can print localized error messages */
|
|
1093 gtk_set_locale();
|
|
1094 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
|
|
1095 bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
|
|
1096 textdomain(PACKAGE_NAME);
|
|
1097
|
|
1098 bmp_init_paths();
|
|
1099 bmp_make_user_dir();
|
|
1100
|
|
1101 /* Check GTK version. Really, this is only needed for binary
|
|
1102 * distribution since configure already checks. */
|
|
1103 if (!GTK_CHECK_VERSION(2, 6, 0)) {
|
|
1104 g_printerr(_("Sorry, your GTK+ version (%d.%d.%d) does not work with Audacious.\n"
|
|
1105 "Please use GTK+ %s or newer.\n"),
|
|
1106 gtk_major_version, gtk_minor_version, gtk_micro_version,
|
|
1107 "2.6.0");
|
|
1108 exit(EXIT_FAILURE);
|
|
1109 }
|
|
1110
|
|
1111 g_set_application_name(_(application_name));
|
|
1112
|
|
1113 g_thread_init(NULL);
|
|
1114 if (!g_thread_supported()) {
|
|
1115 g_printerr(_("Sorry, threads isn't supported on your platform.\n\n"
|
|
1116 "If you're on a libc5 based linux system and installed Glib & GTK+ before you\n"
|
|
1117 "installed LinuxThreads you need to recompile Glib & GTK+.\n"));
|
|
1118 exit(EXIT_FAILURE);
|
|
1119 }
|
|
1120
|
|
1121 gdk_threads_init();
|
|
1122
|
|
1123 cond_scan = g_cond_new();
|
|
1124 mutex_scan = g_mutex_new();
|
|
1125
|
|
1126 gtk_init_check_ok = gtk_init_check(&argc, &argv);
|
|
1127 /* Now let's parse the command line options first. */
|
|
1128 parse_cmd_line(argc, argv, &options);
|
|
1129 if (!gtk_init_check_ok) {
|
|
1130 if (argc < 2) {
|
|
1131 /* GTK check failed, and no arguments passed to indicate
|
|
1132 that user is intending to only remote control a running
|
|
1133 session */
|
|
1134 g_printerr(_("audacious: Unable to open display, exiting.\n"));
|
|
1135 exit(EXIT_FAILURE);
|
|
1136 }
|
|
1137
|
|
1138 handle_cmd_line_options(&options, TRUE);
|
|
1139
|
|
1140 /* we could be running headless, so GTK probably wont matter */
|
|
1141 if (options.headless != 1)
|
|
1142 exit(EXIT_SUCCESS);
|
|
1143 }
|
|
1144
|
|
1145 if (options.no_log == FALSE)
|
|
1146 bmp_setup_logger();
|
|
1147
|
|
1148 signal_handlers_init();
|
|
1149
|
|
1150 g_random_set_seed(time(NULL));
|
|
1151
|
|
1152 bmp_config_load();
|
|
1153
|
|
1154 if (options.session != -1 || !ctrlsocket_setup()) {
|
|
1155 handle_cmd_line_options(&options, TRUE);
|
|
1156 exit(EXIT_SUCCESS);
|
|
1157 }
|
|
1158
|
|
1159 plugin_system_init();
|
|
1160
|
|
1161 /* Initialize the playlist system. */
|
|
1162 playlist_init();
|
|
1163
|
|
1164 if (options.headless != 1)
|
|
1165 {
|
|
1166 /* register icons in stock */
|
|
1167 register_aud_stock_icons();
|
|
1168
|
|
1169 bmp_set_default_icon();
|
|
1170
|
|
1171 gtk_accel_map_load(bmp_paths[BMP_PATH_ACCEL_FILE]);
|
|
1172
|
|
1173 /* uimanager */
|
|
1174 ui_manager_init();
|
|
1175 ui_manager_create_menus();
|
|
1176
|
|
1177 if (!init_skins(cfg.skin)) {
|
|
1178 run_load_skin_error_dialog(cfg.skin);
|
|
1179 exit(EXIT_FAILURE);
|
|
1180 }
|
|
1181
|
|
1182 GDK_THREADS_ENTER();
|
|
1183 }
|
|
1184
|
|
1185 /* Load the default playlist in. */
|
|
1186 playlist = playlist_get_active();
|
|
1187 playlist_load(playlist, bmp_paths[BMP_PATH_PLAYLIST_FILE]);
|
|
1188 playlist_set_position(playlist, cfg.playlist_position);
|
|
1189
|
|
1190 /* this needs to be called after all 3 windows are created and
|
|
1191 * input plugins are setup'ed
|
|
1192 * but not if we're running headless --nenolod
|
|
1193 */
|
|
1194 mainwin_setup_menus();
|
|
1195
|
|
1196 if (options.headless != 1)
|
|
1197 GDK_THREADS_LEAVE();
|
|
1198
|
|
1199 ctrlsocket_start();
|
|
1200
|
|
1201 handle_cmd_line_options(&options, FALSE);
|
|
1202
|
|
1203 if (options.headless != 1)
|
|
1204 {
|
|
1205 GDK_THREADS_ENTER();
|
|
1206
|
|
1207 read_volume(VOLSET_STARTUP);
|
|
1208 mainwin_set_info_text();
|
|
1209
|
|
1210 /* FIXME: delayed, because it deals directly with the plugin
|
|
1211 * interface to set menu items */
|
|
1212 create_prefs_window();
|
|
1213
|
|
1214 create_fileinfo_window();
|
|
1215 create_filepopup_window();
|
|
1216
|
|
1217 if (cfg.player_visible)
|
|
1218 mainwin_show(TRUE);
|
|
1219 else if (!cfg.playlist_visible && !cfg.equalizer_visible)
|
|
1220 mainwin_show(TRUE);
|
|
1221
|
|
1222 if (cfg.equalizer_visible)
|
|
1223 equalizerwin_show(TRUE);
|
|
1224
|
|
1225 if (cfg.playlist_visible)
|
|
1226 playlistwin_show();
|
|
1227
|
|
1228 hint_set_always(cfg.always_on_top);
|
|
1229
|
|
1230 playlist_start_get_info_thread();
|
|
1231 mainwin_attach_idle_func();
|
|
1232
|
|
1233 starting_up = FALSE;
|
|
1234
|
|
1235 has_x11_connection = TRUE;
|
|
1236
|
|
1237 if (cfg.resume_playback_on_startup) {
|
|
1238 if (cfg.resume_playback_on_startup_time != -1 && playlist_get_length(playlist) > 0) {
|
|
1239 int i;
|
|
1240 gint l=0, r=0;
|
|
1241 while (gtk_events_pending()) gtk_main_iteration();
|
|
1242 output_get_volume(&l, &r);
|
|
1243 output_set_volume(0,0);
|
|
1244 playback_initiate();
|
|
1245
|
|
1246 /* Busy wait; loop is fairly tight to minimize duration of "frozen" GUI. Feel free to
|
|
1247 * tune. --chainsaw
|
|
1248 */
|
|
1249 for (i = 0; i < 20; i++) {
|
|
1250 g_usleep(1000);
|
|
1251 if (!ip_data.playing)
|
|
1252 break;
|
|
1253 }
|
|
1254 playback_seek(cfg.resume_playback_on_startup_time /
|
|
1255 1000);
|
|
1256 output_set_volume(l, r);
|
|
1257 }
|
|
1258 }
|
|
1259
|
|
1260 gtk_main();
|
|
1261
|
|
1262 GDK_THREADS_LEAVE();
|
|
1263
|
|
1264 g_cond_free(cond_scan);
|
|
1265 g_mutex_free(mutex_scan);
|
|
1266
|
|
1267 return EXIT_SUCCESS;
|
|
1268 }
|
|
1269 else
|
|
1270 {
|
|
1271 mainwin_set_info_text();
|
|
1272 playlist_start_get_info_thread();
|
|
1273
|
|
1274 starting_up = FALSE;
|
|
1275
|
|
1276 for (;;)
|
|
1277 {
|
|
1278 /* headless eventloop */
|
|
1279 audcore_generic_events();
|
|
1280 free_vis_data(); /* to prevent buffer overflow -- paranoia */
|
|
1281 xmms_usleep(10000);
|
|
1282 }
|
|
1283
|
|
1284 return EXIT_SUCCESS;
|
|
1285 }
|
|
1286 }
|