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