comparison pidgin/gtkmain.c @ 17850:1f060ef64f77

Make -l do something slightly more sane than it does now, even though it doesn't really fit in with our normal utilization of multiple accounts. This will now disable all accounts and then only enable those requested on the command line. Fixes #1257.
author Stu Tomlinson <stu@nosnilmot.com>
date Wed, 13 Jun 2007 02:20:11 +0000
parents 57e81bfeab3d
children 40d51793f2d7
comparison
equal deleted inserted replaced
17849:662710d7ecf0 17850:1f060ef64f77
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
437 gboolean opt_nologin = FALSE; 432 gboolean opt_nologin = FALSE;
438 gboolean opt_version = FALSE; 433 gboolean opt_version = FALSE;
439 char *opt_config_dir_arg = NULL; 434 char *opt_config_dir_arg = NULL;
440 char *opt_login_arg = NULL; 435 char *opt_login_arg = NULL;
441 char *opt_session_arg = NULL; 436 char *opt_session_arg = NULL;
442 int dologin_ret = -1;
443 char *search_path; 437 char *search_path;
444 GList *accounts; 438 GList *accounts;
445 #ifdef HAVE_SIGNAL_H 439 #ifdef HAVE_SIGNAL_H
446 int sig_indx; /* for setting up signal catching */ 440 int sig_indx; /* for setting up signal catching */
447 sigset_t sigset; 441 sigset_t sigset;
786 780
787 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/debug/enabled")) 781 if (purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/debug/enabled"))
788 pidgin_debug_window_show(); 782 pidgin_debug_window_show();
789 783
790 if (opt_login) { 784 if (opt_login) {
791 dologin_ret = dologin_named(opt_login_arg); 785 /* disable all accounts */
786 for (accounts = purple_accounts_get_all(); accounts != NULL; accounts = accounts->next) {
787 PurpleAccount *account = accounts->data;
788 purple_account_set_enabled(account, PIDGIN_UI, FALSE);
789 }
790 /* honor the startup status preference */
791 if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status"))
792 purple_savedstatus_activate(purple_savedstatus_get_startup());
793 /* now enable the requested ones */
794 dologin_named(opt_login_arg);
792 if (opt_login_arg != NULL) { 795 if (opt_login_arg != NULL) {
793 g_free(opt_login_arg); 796 g_free(opt_login_arg);
794 opt_login_arg = NULL; 797 opt_login_arg = NULL;
795 } 798 }
796 } 799 }
797 800
798 if (opt_nologin) 801 if (opt_nologin && !opt_login)
799 { 802 {
800 /* Set all accounts to "offline" */ 803 /* Set all accounts to "offline" */
801 PurpleSavedStatus *saved_status; 804 PurpleSavedStatus *saved_status;
802 805
803 /* If we've used this type+message before, lookup the transient status */ 806 /* If we've used this type+message before, lookup the transient status */
809 saved_status = purple_savedstatus_new(NULL, PURPLE_STATUS_OFFLINE); 812 saved_status = purple_savedstatus_new(NULL, PURPLE_STATUS_OFFLINE);
810 813
811 /* Set the status for each account */ 814 /* Set the status for each account */
812 purple_savedstatus_activate(saved_status); 815 purple_savedstatus_activate(saved_status);
813 } 816 }
814 else 817 else if (!opt_login)
815 { 818 {
816 /* Everything is good to go--sign on already */ 819 /* Everything is good to go--sign on already */
817 if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status")) 820 if (!purple_prefs_get_bool("/purple/savedstatus/startup_current_status"))
818 purple_savedstatus_activate(purple_savedstatus_get_startup()); 821 purple_savedstatus_activate(purple_savedstatus_get_startup());
819 purple_accounts_restore_current_statuses(); 822 purple_accounts_restore_current_statuses();