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