pidgin/libpidgin.c

changeset 38064
7cb860a7bb2e
parent 38048
a3aaf7cef832
child 38240
0552f69f1996
equal deleted inserted replaced
38063:2e71489e2672 38064:7cb860a7bb2e
68 #include "gtksound.h" 68 #include "gtksound.h"
69 #include "gtkutils.h" 69 #include "gtkutils.h"
70 #include "pidginstock.h" 70 #include "pidginstock.h"
71 #include "gtkwhiteboard.h" 71 #include "gtkwhiteboard.h"
72 72
73 #ifndef _WIN32
73 #include <signal.h> 74 #include <signal.h>
75 #endif
74 76
75 #include <getopt.h> 77 #include <getopt.h>
76 78
79 #ifndef _WIN32
77 80
78 /* 81 /*
79 * Lists of signals we wish to catch and those we wish to ignore. 82 * Lists of signals we wish to catch and those we wish to ignore.
80 * Each list terminated with -1 83 * Each list terminated with -1
81 */ 84 */
90 93
91 static const int ignore_sig_list[] = { 94 static const int ignore_sig_list[] = {
92 SIGPIPE, 95 SIGPIPE,
93 -1 96 -1
94 }; 97 };
98 #endif /* !_WIN32 */
95 99
96 static void 100 static void
97 dologin_named(const char *name) 101 dologin_named(const char *name)
98 { 102 {
99 PurpleAccount *account; 103 PurpleAccount *account;
119 purple_account_set_enabled(account, PIDGIN_UI, TRUE); 123 purple_account_set_enabled(account, PIDGIN_UI, TRUE);
120 } 124 }
121 } 125 }
122 } 126 }
123 127
128 #ifndef _WIN32
124 static char *segfault_message; 129 static char *segfault_message;
125 130
126 static int signal_sockets[2]; 131 static int signal_sockets[2];
127 132
128 static void sighandler(int sig); 133 static void sighandler(int sig);
187 purple_core_quit(); 192 purple_core_quit();
188 } 193 }
189 194
190 return TRUE; 195 return TRUE;
191 } 196 }
197 #endif /* !_WIN32 */
192 198
193 static int 199 static int
194 ui_main(void) 200 ui_main(void)
195 { 201 {
196 #ifndef _WIN32 202 #ifndef _WIN32
425 char *opt_session_arg = NULL; 431 char *opt_session_arg = NULL;
426 char *search_path; 432 char *search_path;
427 GtkCssProvider *provider; 433 GtkCssProvider *provider;
428 GdkScreen *screen; 434 GdkScreen *screen;
429 GList *accounts; 435 GList *accounts;
436 #ifndef _WIN32
430 int sig_indx; /* for setting up signal catching */ 437 int sig_indx; /* for setting up signal catching */
431 sigset_t sigset; 438 sigset_t sigset;
432 char errmsg[BUFSIZ]; 439 char errmsg[BUFSIZ];
433 GIOChannel *signal_channel; 440 GIOChannel *signal_channel;
434 GIOStatus signal_status; 441 GIOStatus signal_status;
435 guint signal_channel_watcher; 442 guint signal_channel_watcher;
436 GError *error;
437 #ifndef DEBUG 443 #ifndef DEBUG
438 char *segfault_message_tmp; 444 char *segfault_message_tmp;
439 #endif /* DEBUG */ 445 #endif /* DEBUG */
446 #endif /* !_WIN32 */
440 int opt; 447 int opt;
441 gboolean gui_check; 448 gboolean gui_check;
442 gboolean debug_enabled, debug_colored; 449 gboolean debug_enabled, debug_colored;
443 GList *active_accounts; 450 GList *active_accounts;
444 GStatBuf st; 451 GStatBuf st;
452 GError *error;
445 453
446 struct option long_options[] = { 454 struct option long_options[] = {
447 {"config", required_argument, NULL, 'c'}, 455 {"config", required_argument, NULL, 'c'},
448 {"debug", optional_argument, NULL, 'd'}, 456 {"debug", optional_argument, NULL, 'd'},
449 {"force-online", no_argument, NULL, 'f'}, 457 {"force-online", no_argument, NULL, 'f'},
471 textdomain(PACKAGE); 479 textdomain(PACKAGE);
472 #endif 480 #endif
473 481
474 /* Locale initialization is not complete here. See gtk_init_check() */ 482 /* Locale initialization is not complete here. See gtk_init_check() */
475 setlocale(LC_ALL, ""); 483 setlocale(LC_ALL, "");
484
485 #ifndef _WIN32
476 486
477 #ifndef DEBUG 487 #ifndef DEBUG
478 /* We translate this here in case the crash breaks gettext. */ 488 /* We translate this here in case the crash breaks gettext. */
479 segfault_message_tmp = g_strdup_printf(_( 489 segfault_message_tmp = g_strdup_printf(_(
480 "%s %s has segfaulted and attempted to dump a core file.\n" 490 "%s %s has segfaulted and attempted to dump a core file.\n"
572 582
573 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { 583 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) {
574 snprintf(errmsg, sizeof(errmsg), "Warning: couldn't unblock signals"); 584 snprintf(errmsg, sizeof(errmsg), "Warning: couldn't unblock signals");
575 perror(errmsg); 585 perror(errmsg);
576 } 586 }
587 #endif /* !_WIN32 */
577 588
578 /* scan command-line options */ 589 /* scan command-line options */
579 opterr = 1; 590 opterr = 1;
580 while ((opt = getopt_long(argc, argv, 591 while ((opt = getopt_long(argc, argv,
581 #ifndef _WIN32 592 #ifndef _WIN32
624 /* handled by gtk_init_check below */ 635 /* handled by gtk_init_check below */
625 break; 636 break;
626 case '?': /* show terse help */ 637 case '?': /* show terse help */
627 default: 638 default:
628 show_usage(argv[0], TRUE); 639 show_usage(argv[0], TRUE);
640 #ifndef _WIN32
629 g_free(segfault_message); 641 g_free(segfault_message);
642 #endif
630 return 0; 643 return 0;
631 break; 644 break;
632 } 645 }
633 } 646 }
634 647
635 /* show help message */ 648 /* show help message */
636 if (opt_help) { 649 if (opt_help) {
637 show_usage(argv[0], FALSE); 650 show_usage(argv[0], FALSE);
651 #ifndef _WIN32
638 g_free(segfault_message); 652 g_free(segfault_message);
653 #endif
639 return 0; 654 return 0;
640 } 655 }
641 /* show version message */ 656 /* show version message */
642 if (opt_version) { 657 if (opt_version) {
643 printf("%s %s (libpurple %s)\n", PIDGIN_NAME, DISPLAY_VERSION, 658 printf("%s %s (libpurple %s)\n", PIDGIN_NAME, DISPLAY_VERSION,
644 purple_core_get_version()); 659 purple_core_get_version());
660 #ifndef _WIN32
645 g_free(segfault_message); 661 g_free(segfault_message);
662 #endif
646 return 0; 663 return 0;
647 } 664 }
648 665
649 /* set a user-specified config directory */ 666 /* set a user-specified config directory */
650 if (opt_config_dir_arg != NULL) { 667 if (opt_config_dir_arg != NULL) {
675 const char *display = gdk_display_get_name(gdk_display_get_default()); 692 const char *display = gdk_display_get_name(gdk_display_get_default());
676 693
677 printf("%s %s\n", PIDGIN_NAME, DISPLAY_VERSION); 694 printf("%s %s\n", PIDGIN_NAME, DISPLAY_VERSION);
678 695
679 g_warning("cannot open display: %s", display ? display : "unset"); 696 g_warning("cannot open display: %s", display ? display : "unset");
697 #ifndef _WIN32
680 g_free(segfault_message); 698 g_free(segfault_message);
699 #endif
681 700
682 return 1; 701 return 1;
683 } 702 }
684 703
685 search_path = g_build_filename(purple_user_dir(), "gtk-3.0.css", NULL); 704 search_path = g_build_filename(purple_user_dir(), "gtk-3.0.css", NULL);
709 728
710 if (!purple_core_init(PIDGIN_UI)) { 729 if (!purple_core_init(PIDGIN_UI)) {
711 fprintf(stderr, 730 fprintf(stderr,
712 "Initialization of the libpurple core failed. Dumping core.\n" 731 "Initialization of the libpurple core failed. Dumping core.\n"
713 "Please report this!\n"); 732 "Please report this!\n");
733 #ifndef _WIN32
714 g_free(segfault_message); 734 g_free(segfault_message);
735 #endif
715 abort(); 736 abort();
716 } 737 }
717 738
718 search_path = g_build_filename(purple_user_dir(), "plugins", NULL); 739 search_path = g_build_filename(purple_user_dir(), "plugins", NULL);
719 if (!g_stat(search_path, &st)) 740 if (!g_stat(search_path, &st))
735 dbus_message_unref(message); 756 dbus_message_unref(message);
736 #endif 757 #endif
737 gdk_notify_startup_complete(); 758 gdk_notify_startup_complete();
738 purple_core_quit(); 759 purple_core_quit();
739 g_printerr(_("Exiting because another libpurple client is already running.\n")); 760 g_printerr(_("Exiting because another libpurple client is already running.\n"));
761 #ifndef _WIN32
740 g_free(segfault_message); 762 g_free(segfault_message);
763 #endif
741 return 0; 764 return 0;
742 } 765 }
743 766
744 /* load plugins we had when we quit */ 767 /* load plugins we had when we quit */
745 purple_plugins_load_saved(PIDGIN_PREFS_ROOT "/plugins/loaded"); 768 purple_plugins_load_saved(PIDGIN_PREFS_ROOT "/plugins/loaded");
820 winpidgin_post_init(); 843 winpidgin_post_init();
821 #endif 844 #endif
822 845
823 gtk_main(); 846 gtk_main();
824 847
848 #ifndef _WIN32
825 g_free(segfault_message); 849 g_free(segfault_message);
826 g_source_remove(signal_channel_watcher); 850 g_source_remove(signal_channel_watcher);
827 close(signal_sockets[0]); 851 close(signal_sockets[0]);
828 close(signal_sockets[1]); 852 close(signal_sockets[1]);
853 #endif
829 854
830 #ifdef _WIN32 855 #ifdef _WIN32
831 winpidgin_cleanup(); 856 winpidgin_cleanup();
832 #endif 857 #endif
833 858

mercurial