comparison src/audacious/main.c @ 4355:3aeb45aeeaed

fixed headless mode; minor cleanups
author mf0102 <0102@gmx.at>
date Sun, 16 Mar 2008 23:18:35 +0100
parents ac1f6d211223
children 87cb9d3402d4
comparison
equal deleted inserted replaced
4354:168479ee6aab 4355:3aeb45aeeaed
99 gboolean headless; 99 gboolean headless;
100 gboolean no_log; 100 gboolean no_log;
101 gboolean enqueue_to_temp; 101 gboolean enqueue_to_temp;
102 gboolean version; 102 gboolean version;
103 gchar *previous_session_id; 103 gchar *previous_session_id;
104 gboolean macpack; 104 gboolean macpack;
105 }; 105 };
106 106
107 typedef struct _AudCmdLineOpt AudCmdLineOpt; 107 typedef struct _AudCmdLineOpt AudCmdLineOpt;
108 108
109 AudCmdLineOpt options; 109 AudCmdLineOpt options;
309 rowstride = gdk_pixbuf_get_rowstride(pixbuf); 309 rowstride = gdk_pixbuf_get_rowstride(pixbuf);
310 has_alpha = gdk_pixbuf_get_has_alpha(pixbuf); 310 has_alpha = gdk_pixbuf_get_has_alpha(pixbuf);
311 311
312 /* create the colourspace for the CGImage. */ 312 /* create the colourspace for the CGImage. */
313 colorspace = CGColorSpaceCreateDeviceRGB(); 313 colorspace = CGColorSpaceCreateDeviceRGB();
314 data_provider = CGDataProviderCreateWithData(NULL, data, pixbuf_height * rowstride, NULL); 314 data_provider = CGDataProviderCreateWithData(NULL, data,
315 pixbuf_height * rowstride,
316 NULL);
315 image = CGImageCreate(pixbuf_width, pixbuf_height, 8, 317 image = CGImageCreate(pixbuf_width, pixbuf_height, 8,
316 has_alpha ? 32 : 24, rowstride, colorspace, 318 has_alpha ? 32 : 24, rowstride, colorspace,
317 has_alpha ? kCGImageAlphaLast : 0, 319 has_alpha ? kCGImageAlphaLast : 0,
318 data_provider, NULL, FALSE, 320 data_provider, NULL, FALSE,
319 kCGRenderingIntentDefault); 321 kCGRenderingIntentDefault);
320 322
321 /* release the colourspace and data provider, we have what we want. */ 323 /* release the colourspace and data provider, we have what we want. */
322 CGDataProviderRelease(data_provider); 324 CGDataProviderRelease(data_provider);
323 CGColorSpaceRelease(colorspace); 325 CGColorSpaceRelease(colorspace);
324 326
347 {"show-main-window", 'm', 0, G_OPTION_ARG_NONE, &options.mainwin, N_("Display the main window"), NULL}, 349 {"show-main-window", 'm', 0, G_OPTION_ARG_NONE, &options.mainwin, N_("Display the main window"), NULL},
348 {"activate", 'a', 0, G_OPTION_ARG_NONE, &options.activate, N_("Display all open Audacious windows"), NULL}, 350 {"activate", 'a', 0, G_OPTION_ARG_NONE, &options.activate, N_("Display all open Audacious windows"), NULL},
349 {"headless", 'H', 0, G_OPTION_ARG_NONE, &options.headless, N_("Enable headless operation"), NULL}, 351 {"headless", 'H', 0, G_OPTION_ARG_NONE, &options.headless, N_("Enable headless operation"), NULL},
350 {"no-log", 'N', 0, G_OPTION_ARG_NONE, &options.no_log, N_("Print all errors and warnings to stdout"), NULL}, 352 {"no-log", 'N', 0, G_OPTION_ARG_NONE, &options.no_log, N_("Print all errors and warnings to stdout"), NULL},
351 {"version", 'v', 0, G_OPTION_ARG_NONE, &options.version, N_("Show version and builtin features"), NULL}, 353 {"version", 'v', 0, G_OPTION_ARG_NONE, &options.version, N_("Show version and builtin features"), NULL},
352 #ifdef GDK_WINDOWING_QUARTZ 354 #ifdef GDK_WINDOWING_QUARTZ
353 {"macpack", 'n', 0, G_OPTION_ARG_NONE, &options.macpack, N_("Used in macpacking"), NULL}, /* Make this hidden */ 355 {"macpack", 'n', 0, G_OPTION_ARG_NONE, &options.macpack, N_("Used in macpacking"), NULL}, /* Make this hidden */
354 #endif 356 #endif
355 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &options.filenames, N_("FILE..."), NULL}, 357 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &options.filenames, N_("FILE..."), NULL},
356 {NULL}, 358 {NULL},
357 }; 359 };
358 360
359 static gboolean 361 static gboolean
393 for (i = 0; filenames[i] != NULL; i++) 395 for (i = 0; filenames[i] != NULL; i++)
394 { 396 {
395 gchar *filename; 397 gchar *filename;
396 gchar *current_dir = g_get_current_dir(); 398 gchar *current_dir = g_get_current_dir();
397 399
398 if (!strstr(filenames[i], "://")) 400 if (!strstr(filenames[i], "://"))
399 { 401 {
400 if (filenames[i][0] == '/') 402 if (filenames[i][0] == '/')
401 filename = g_strdup_printf("file:///%s", filenames[i]); 403 filename = g_strdup_printf("file:///%s", filenames[i]);
402 else 404 else
403 filename = g_strdup_printf("file:///%s/%s", current_dir, filenames[i]); 405 filename = g_strdup_printf("file:///%s/%s", current_dir,
404 } 406 filenames[i]);
407 }
405 else 408 else
406 filename = g_strdup(filenames[i]); 409 filename = g_strdup(filenames[i]);
407 410
408 fns = g_list_prepend(fns, filename); 411 fns = g_list_prepend(fns, filename);
409 412
491 for (i = 0; filenames[i] != NULL; i++) 494 for (i = 0; filenames[i] != NULL; i++)
492 { 495 {
493 gchar *filename; 496 gchar *filename;
494 gchar *current_dir = g_get_current_dir(); 497 gchar *current_dir = g_get_current_dir();
495 498
496 if (!strstr(filenames[i], "://")) 499 if (!strstr(filenames[i], "://"))
497 { 500 {
498 if (filenames[i][0] == '/') 501 if (filenames[i][0] == '/')
499 filename = g_strdup_printf("file:///%s", filenames[i]); 502 filename = g_strdup_printf("file:///%s", filenames[i]);
500 else 503 else
501 filename = g_strdup_printf("file:///%s/%s", current_dir, filenames[i]); 504 filename = g_strdup_printf("file:///%s/%s", current_dir,
502 } 505 filenames[i]);
506 }
503 else 507 else
504 filename = g_strdup(filenames[i]); 508 filename = g_strdup(filenames[i]);
505 509
506 fns = g_list_prepend(fns, filename); 510 fns = g_list_prepend(fns, filename);
507 511
668 672
669 cond_scan = g_cond_new(); 673 cond_scan = g_cond_new();
670 mutex_scan = g_mutex_new(); 674 mutex_scan = g_mutex_new();
671 gtk_rc_add_default_file(bmp_paths[BMP_PATH_GTKRC_FILE]); 675 gtk_rc_add_default_file(bmp_paths[BMP_PATH_GTKRC_FILE]);
672 676
673 gtk_init_check_ok = gtk_init_check(&argc, &argv);
674
675 memset(&options, '\0', sizeof(AudCmdLineOpt)); 677 memset(&options, '\0', sizeof(AudCmdLineOpt));
676 options.session = -1; 678 options.session = -1;
677 679
678 context = g_option_context_new(_("- play multimedia files")); 680 context = g_option_context_new(_("- play multimedia files"));
679 g_option_context_add_main_entries(context, cmd_entries, PACKAGE_NAME); 681 g_option_context_add_main_entries(context, cmd_entries, PACKAGE_NAME);
680 g_option_context_add_group(context, gtk_get_option_group(TRUE)); 682 g_option_context_add_group(context, gtk_get_option_group(FALSE));
681 g_option_context_add_group(context, egg_sm_client_get_option_group()); 683 g_option_context_add_group(context, egg_sm_client_get_option_group());
682 g_option_context_parse(context, &argc, &argv, &error); 684 g_option_context_parse(context, &argc, &argv, &error);
683 685
686
687 gtk_init_check_ok = gtk_init_check(&argc, &argv);
688
689
684 if (error != NULL) 690 if (error != NULL)
685 { 691 {
686 if(error->message) 692 /* checking for MacOS X -psn_0_* errors*/
687 { /* checking for MacOS X -psn_0_* errors*/ 693 if(error->message && !g_strrstr(error->message,"-psn_0_")) {
688 char* s = g_strrstr(error->message,"-psn_0_"); 694 g_printerr(_("%s: %s\nTry `%s --help' for more information.\n"),
689 if(!s) 695 argv[0], error->message, argv[0]);
690 { 696 exit(EXIT_FAILURE);
691 g_printerr(_("%s: %s\nTry `%s --help' for more information.\n"),
692 argv[0], error->message, argv[0]);
693 exit(EXIT_FAILURE);
694 }
695 } 697 }
696 } 698
697 699 if (!gtk_init_check_ok && argc < 2) {
698 if (!gtk_init_check_ok) {
699 if (argc < 2) {
700 /* GTK check failed, and no arguments passed to indicate 700 /* GTK check failed, and no arguments passed to indicate
701 that user is intending to only remote control a running 701 that user is intending to only remote control a running
702 session */ 702 session */
703 g_printerr(_("%s: Unable to open display, exiting.\n"), argv[0]); 703 g_printerr(_("%s: Unable to open display, exiting.\n"), argv[0]);
704 exit(EXIT_FAILURE); 704 exit(EXIT_FAILURE);
705 } 705 }
706 706
707 handle_cmd_line_options(&options, TRUE); 707 handle_cmd_line_options(&options, TRUE);
708 708
709 /* we could be running headless, so GTK probably wont matter */ 709 /* we could be running headless, so GTK probably wont matter */
710 if (options.headless != 1) 710 if (options.headless == FALSE)
711 exit(EXIT_SUCCESS); 711 exit(EXIT_SUCCESS);
712 } 712 }
713 713
714 if (options.no_log == FALSE) 714 if (options.no_log == FALSE)
715 bmp_setup_logger(); 715 bmp_setup_logger();
721 721
722 bmp_config_load(); 722 bmp_config_load();
723 723
724 mowgli_init(); 724 mowgli_init();
725 725
726 if (options.headless != 1) 726 if (options.headless == FALSE)
727 { 727 {
728 ui_main_check_theme_engine(); 728 ui_main_check_theme_engine();
729 729
730 /* register icons in stock 730 /* register icons in stock
731 NOTE: should be called before UIManager */ 731 NOTE: should be called before UIManager */
750 750
751 #ifdef USE_DBUS 751 #ifdef USE_DBUS
752 init_dbus(); 752 init_dbus();
753 #endif 753 #endif
754 754
755 if (options.headless != 1) 755 if (options.headless == FALSE)
756 { 756 {
757 bmp_set_default_icon(); 757 bmp_set_default_icon();
758 #ifdef GDK_WINDOWING_QUARTZ 758 #ifdef GDK_WINDOWING_QUARTZ
759 set_dock_icon(); 759 set_dock_icon();
760 #endif 760 #endif
779 * input plugins are setup'ed 779 * input plugins are setup'ed
780 * but not if we're running headless --nenolod 780 * but not if we're running headless --nenolod
781 */ 781 */
782 mainwin_setup_menus(); 782 mainwin_setup_menus();
783 783
784 if (options.headless != 1) 784 if (options.headless == FALSE)
785 { 785 {
786 ui_main_set_initial_volume(); 786 ui_main_set_initial_volume();
787 787
788 /* FIXME: delayed, because it deals directly with the plugin 788 /* FIXME: delayed, because it deals directly with the plugin
789 * interface to set menu items */ 789 * interface to set menu items */