pidgin/gtkmain.c

changeset 18545
5af898e91ec2
parent 18345
a51a9c1e4314
child 18606
102d3ca556ea
equal deleted inserted replaced
17398:1edf059a4a26 18545:5af898e91ec2
106 SIGPIPE, 106 SIGPIPE,
107 -1 107 -1
108 }; 108 };
109 #endif 109 #endif
110 110
111 static int 111 static void
112 dologin_named(const char *name) 112 dologin_named(const char *name)
113 { 113 {
114 PurpleAccount *account; 114 PurpleAccount *account;
115 char **names; 115 char **names;
116 int i; 116 int i;
117 int ret = -1;
118 117
119 if (name != NULL) { /* list of names given */ 118 if (name != NULL) { /* list of names given */
120 names = g_strsplit(name, ",", 64); 119 names = g_strsplit(name, ",", 64);
121 for (i = 0; names[i] != NULL; i++) { 120 for (i = 0; names[i] != NULL; i++) {
122 account = purple_accounts_find(names[i], NULL); 121 account = purple_accounts_find(names[i], NULL);
123 if (account != NULL) { /* found a user */ 122 if (account != NULL) { /* found a user */
124 ret = 0; 123 purple_account_set_enabled(account, PIDGIN_UI, TRUE);
125 purple_account_connect(account);
126 } 124 }
127 } 125 }
128 g_strfreev(names); 126 g_strfreev(names);
129 } else { /* no name given, use the first account */ 127 } else { /* no name given, use the first account */
130 GList *accounts; 128 GList *accounts;
131 129
132 accounts = purple_accounts_get_all(); 130 accounts = purple_accounts_get_all();
133 if (accounts != NULL) 131 if (accounts != NULL)
134 { 132 {
135 account = (PurpleAccount *)accounts->data; 133 account = (PurpleAccount *)accounts->data;
136 ret = 0; 134 purple_account_set_enabled(account, PIDGIN_UI, TRUE);
137 purple_account_connect(account); 135 }
138 } 136 }
139 }
140
141 return ret;
142 } 137 }
143 138
144 #ifdef HAVE_SIGNAL_H 139 #ifdef HAVE_SIGNAL_H
145 static void sighandler(int sig); 140 static void sighandler(int sig);
146 141
375 text = g_strdup_printf(_("%s %s\n" 370 text = g_strdup_printf(_("%s %s\n"
376 "Usage: %s [OPTION]...\n\n" 371 "Usage: %s [OPTION]...\n\n"
377 " -c, --config=DIR use DIR for config files\n" 372 " -c, --config=DIR use DIR for config files\n"
378 " -d, --debug print debugging messages to stdout\n" 373 " -d, --debug print debugging messages to stdout\n"
379 " -h, --help display this help and exit\n" 374 " -h, --help display this help and exit\n"
375 " -m, --multiple do not ensure single instance\n"
380 " -n, --nologin don't automatically login\n" 376 " -n, --nologin don't automatically login\n"
381 " -l, --login[=NAME] automatically login (optional argument NAME specifies\n" 377 " -l, --login[=NAME] automatically login (optional argument NAME specifies\n"
382 " account(s) to use, separated by commas)\n" 378 " account(s) to use, separated by commas)\n"
383 " -v, --version display the current version and exit\n"), PIDGIN_NAME, VERSION, name); 379 " -v, --version display the current version and exit\n"), PIDGIN_NAME, VERSION, name);
384 } 380 }
434 { 430 {
435 gboolean opt_help = FALSE; 431 gboolean opt_help = FALSE;
436 gboolean opt_login = FALSE; 432 gboolean opt_login = FALSE;
437 gboolean opt_nologin = FALSE; 433 gboolean opt_nologin = FALSE;
438 gboolean opt_version = FALSE; 434 gboolean opt_version = FALSE;
435 gboolean opt_si = TRUE; /* Check for single instance? */
439 char *opt_config_dir_arg = NULL; 436 char *opt_config_dir_arg = NULL;
440 char *opt_login_arg = NULL; 437 char *opt_login_arg = NULL;
441 char *opt_session_arg = NULL; 438 char *opt_session_arg = NULL;
442 int dologin_ret = -1;
443 char *search_path; 439 char *search_path;
444 GList *accounts; 440 GList *accounts;
445 #ifdef HAVE_SIGNAL_H 441 #ifdef HAVE_SIGNAL_H
446 int sig_indx; /* for setting up signal catching */ 442 int sig_indx; /* for setting up signal catching */
447 sigset_t sigset; 443 sigset_t sigset;
454 #endif 450 #endif
455 int opt; 451 int opt;
456 gboolean gui_check; 452 gboolean gui_check;
457 gboolean debug_enabled; 453 gboolean debug_enabled;
458 gboolean migration_failed = FALSE; 454 gboolean migration_failed = FALSE;
455 GList *active_accounts;
459 456
460 struct option long_options[] = { 457 struct option long_options[] = {
461 {"config", required_argument, NULL, 'c'}, 458 {"config", required_argument, NULL, 'c'},
462 {"debug", no_argument, NULL, 'd'}, 459 {"debug", no_argument, NULL, 'd'},
463 {"help", no_argument, NULL, 'h'}, 460 {"help", no_argument, NULL, 'h'},
464 {"login", optional_argument, NULL, 'l'}, 461 {"login", optional_argument, NULL, 'l'},
462 {"multiple", no_argument, NULL, 'm'},
465 {"nologin", no_argument, NULL, 'n'}, 463 {"nologin", no_argument, NULL, 'n'},
466 {"session", required_argument, NULL, 's'}, 464 {"session", required_argument, NULL, 's'},
467 {"version", no_argument, NULL, 'v'}, 465 {"version", no_argument, NULL, 'v'},
468 {0, 0, 0, 0} 466 {0, 0, 0, 0}
469 }; 467 };
471 #ifdef DEBUG 469 #ifdef DEBUG
472 debug_enabled = TRUE; 470 debug_enabled = TRUE;
473 #else 471 #else
474 debug_enabled = FALSE; 472 debug_enabled = FALSE;
475 #endif 473 #endif
476 474
475 /* This is the first Glib function call. Make sure to initialize GThread bfeore then */
476 g_thread_init(NULL);
477
477 #ifdef ENABLE_NLS 478 #ifdef ENABLE_NLS
478 bindtextdomain(PACKAGE, LOCALEDIR); 479 bindtextdomain(PACKAGE, LOCALEDIR);
479 bind_textdomain_codeset(PACKAGE, "UTF-8"); 480 bind_textdomain_codeset(PACKAGE, "UTF-8");
480 textdomain(PACKAGE); 481 textdomain(PACKAGE);
481 #endif 482 #endif
493 "%s has segfaulted and attempted to dump a core file.\n" 494 "%s has segfaulted and attempted to dump a core file.\n"
494 "This is a bug in the software and has happened through\n" 495 "This is a bug in the software and has happened through\n"
495 "no fault of your own.\n\n" 496 "no fault of your own.\n\n"
496 "If you can reproduce the crash, please notify the developers\n" 497 "If you can reproduce the crash, please notify the developers\n"
497 "by reporting a bug at:\n" 498 "by reporting a bug at:\n"
498 "%snewticket/\n\n" 499 "%ssimpleticket/\n\n"
499 "Please make sure to specify what you were doing at the time\n" 500 "Please make sure to specify what you were doing at the time\n"
500 "and post the backtrace from the core file. If you do not know\n" 501 "and post the backtrace from the core file. If you do not know\n"
501 "how to get the backtrace, please read the instructions at\n" 502 "how to get the backtrace, please read the instructions at\n"
502 "%swiki/GetABacktrace\n\n" 503 "%swiki/GetABacktrace\n\n"
503 "If you need further assistance, please IM either SeanEgn or \n" 504 "If you need further assistance, please IM either SeanEgn or \n"
570 571
571 /* scan command-line options */ 572 /* scan command-line options */
572 opterr = 1; 573 opterr = 1;
573 while ((opt = getopt_long(argc, argv, 574 while ((opt = getopt_long(argc, argv,
574 #ifndef _WIN32 575 #ifndef _WIN32
575 "c:dhnl::s:v", 576 "c:dhmnl::s:v",
576 #else 577 #else
577 "c:dhnl::v", 578 "c:dhnl::v",
578 #endif 579 #endif
579 long_options, NULL)) != -1) { 580 long_options, NULL)) != -1) {
580 switch (opt) { 581 switch (opt) {
602 opt_session_arg = g_strdup(optarg); 603 opt_session_arg = g_strdup(optarg);
603 break; 604 break;
604 case 'v': /* version */ 605 case 'v': /* version */
605 opt_version = TRUE; 606 opt_version = TRUE;
606 break; 607 break;
608 case 'm': /* do not ensure single instance. */
609 opt_si = FALSE;
610 break;
607 case '?': /* show terse help */ 611 case '?': /* show terse help */
608 default: 612 default:
609 show_usage(argv[0], TRUE); 613 show_usage(argv[0], TRUE);
610 #ifdef HAVE_SIGNAL_H 614 #ifdef HAVE_SIGNAL_H
611 g_free(segfault_message); 615 g_free(segfault_message);
670 g_free(segfault_message); 674 g_free(segfault_message);
671 #endif 675 #endif
672 676
673 return 1; 677 return 1;
674 } 678 }
679
680 g_set_application_name(_("Pidgin"));
675 681
676 #ifdef _WIN32 682 #ifdef _WIN32
677 winpidgin_init(hint); 683 winpidgin_init(hint);
678 #endif 684 #endif
679 685
727 #ifdef HAVE_SIGNAL_H 733 #ifdef HAVE_SIGNAL_H
728 g_free(segfault_message); 734 g_free(segfault_message);
729 #endif 735 #endif
730 abort(); 736 abort();
731 } 737 }
738
739 if (opt_si && !purple_core_ensure_single_instance()) {
740 purple_core_quit();
741 #ifdef HAVE_SIGNAL_H
742 g_free(segfault_message);
743 #endif
744 return 0;
745 }
746
732 747
733 /* TODO: Move blist loading into purple_blist_init() */ 748 /* TODO: Move blist loading into purple_blist_init() */
734 purple_set_blist(purple_blist_new()); 749 purple_set_blist(purple_blist_new());
735 purple_blist_load(); 750 purple_blist_load();
736 751
783 798
784 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/debug/enabled")) 799 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/debug/enabled"))
785 pidgin_debug_window_show(); 800 pidgin_debug_window_show();
786 801
787 if (opt_login) { 802 if (opt_login) {
788 dologin_ret = dologin_named(opt_login_arg); 803 /* disable all accounts */
804 for (accounts = purple_accounts_get_all(); accounts != NULL; accounts = accounts->next) {
805 PurpleAccount *account = accounts->data;
806 purple_account_set_enabled(account, PIDGIN_UI, FALSE);
807 }
808 /* honor the startup status preference */
809 if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status"))
810 purple_savedstatus_activate(purple_savedstatus_get_startup());
811 /* now enable the requested ones */
812 dologin_named(opt_login_arg);
789 if (opt_login_arg != NULL) { 813 if (opt_login_arg != NULL) {
790 g_free(opt_login_arg); 814 g_free(opt_login_arg);
791 opt_login_arg = NULL; 815 opt_login_arg = NULL;
792 } 816 }
793 } 817 }
794 818
795 if (opt_nologin) 819 if (opt_nologin && !opt_login)
796 { 820 {
797 /* Set all accounts to "offline" */ 821 /* Set all accounts to "offline" */
798 PurpleSavedStatus *saved_status; 822 PurpleSavedStatus *saved_status;
799 823
800 /* If we've used this type+message before, lookup the transient status */ 824 /* If we've used this type+message before, lookup the transient status */
806 saved_status = purple_savedstatus_new(NULL, PURPLE_STATUS_OFFLINE); 830 saved_status = purple_savedstatus_new(NULL, PURPLE_STATUS_OFFLINE);
807 831
808 /* Set the status for each account */ 832 /* Set the status for each account */
809 purple_savedstatus_activate(saved_status); 833 purple_savedstatus_activate(saved_status);
810 } 834 }
811 else 835 else if (!opt_login)
812 { 836 {
813 /* Everything is good to go--sign on already */ 837 /* Everything is good to go--sign on already */
814 if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status")) 838 if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status"))
815 purple_savedstatus_activate(purple_savedstatus_get_startup()); 839 purple_savedstatus_activate(purple_savedstatus_get_startup());
816 purple_accounts_restore_current_statuses(); 840 purple_accounts_restore_current_statuses();
817 } 841 }
818 842
819 if ((accounts = purple_accounts_get_all_active()) == NULL) 843 if ((active_accounts = purple_accounts_get_all_active()) == NULL)
820 { 844 {
821 pidgin_accounts_window_show(); 845 pidgin_accounts_window_show();
822 } 846 }
823 else 847 else
824 { 848 {
825 g_list_free(accounts); 849 g_list_free(active_accounts);
826 } 850 }
827 851
828 #ifdef HAVE_STARTUP_NOTIFICATION 852 #ifdef HAVE_STARTUP_NOTIFICATION
829 startup_notification_complete(); 853 startup_notification_complete();
830 #endif 854 #endif

mercurial