Mercurial > pidgin
comparison src/multi.c @ 960:fa681641643d
[gaim-migrate @ 970]
*** MULTIPLE-CONNECTIONS ***
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Tue, 10 Oct 2000 00:02:02 +0000 |
| parents | |
| children | f7886476f9d9 |
comparison
equal
deleted
inserted
replaced
| 959:034d5d1d53eb | 960:fa681641643d |
|---|---|
| 1 /* | |
| 2 * gaim | |
| 3 * | |
| 4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
| 5 * | |
| 6 * This program is free software; you can redistribute it and/or modify | |
| 7 * it under the terms of the GNU General Public License as published by | |
| 8 * the Free Software Foundation; either version 2 of the License, or | |
| 9 * (at your option) any later version. | |
| 10 * | |
| 11 * This program is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 * GNU General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU General Public License | |
| 17 * along with this program; if not, write to the Free Software | |
| 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 * | |
| 20 */ | |
| 21 | |
| 22 #include <gtk/gtk.h> | |
| 23 #include "multi.h" | |
| 24 #include "gaim.h" | |
| 25 #include "aim.h" | |
| 26 | |
| 27 #include "pixmaps/gnome_add.xpm" | |
| 28 #include "pixmaps/gnome_preferences.xpm" | |
| 29 #include "pixmaps/join.xpm" | |
| 30 #include "pixmaps/gnome_remove.xpm" | |
| 31 #include "pixmaps/gnome_close.xpm" | |
| 32 #include "pixmaps/cancel.xpm" | |
| 33 #include "pixmaps/ok.xpm" | |
| 34 | |
| 35 GSList *connections; | |
| 36 | |
| 37 static GtkWidget *acctedit = NULL; | |
| 38 static GtkWidget *list = NULL; /* the clist of names in the accteditor */ | |
| 39 static GtkWidget *newmod = NULL; /* the dialog for creating a new account */ | |
| 40 static struct aim_user tmpusr; | |
| 41 | |
| 42 struct mod_usr_opt { | |
| 43 struct aim_user *user; | |
| 44 int opt; | |
| 45 }; | |
| 46 | |
| 47 struct gaim_connection *new_gaim_conn(int proto, char *username, char *password) | |
| 48 { | |
| 49 struct gaim_connection *gc = g_new0(struct gaim_connection, 1); | |
| 50 gc->protocol = proto; | |
| 51 g_snprintf(gc->username, sizeof(gc->username), "%s", username); | |
| 52 g_snprintf(gc->password, sizeof(gc->password), "%s", password); | |
| 53 gc->keepalive = -1; | |
| 54 | |
| 55 switch(proto) { | |
| 56 case PROTO_TOC: | |
| 57 gc->toc_fd = -1; | |
| 58 gc->seqno = 0; | |
| 59 gc->state = 0; | |
| 60 gc->inpa = -1; | |
| 61 break; | |
| 62 case PROTO_OSCAR: | |
| 63 gc->oscar_sess = NULL; | |
| 64 gc->oscar_conn = NULL; | |
| 65 gc->inpa = -1; | |
| 66 gc->cnpa = -1; | |
| 67 gc->paspa = -1; | |
| 68 gc->create_exchange = 0; | |
| 69 gc->create_name = NULL; | |
| 70 gc->oscar_chats = NULL; | |
| 71 break; | |
| 72 default: /* damn plugins */ | |
| 73 /* PRPL */ | |
| 74 break; | |
| 75 } | |
| 76 | |
| 77 connections = g_slist_append(connections, gc); | |
| 78 | |
| 79 return gc; | |
| 80 } | |
| 81 | |
| 82 void destroy_gaim_conn(struct gaim_connection *gc) | |
| 83 { | |
| 84 switch (gc->protocol) { | |
| 85 case PROTO_TOC: | |
| 86 break; | |
| 87 case PROTO_OSCAR: | |
| 88 break; | |
| 89 default: | |
| 90 /* PRPL */ | |
| 91 break; | |
| 92 } | |
| 93 connections = g_slist_remove(connections, gc); | |
| 94 g_free(gc); | |
| 95 redo_convo_menus(); | |
| 96 } | |
| 97 | |
| 98 struct gaim_connection *find_gaim_conn_by_name(char *name) { | |
| 99 char *who = g_strdup(normalize(name)); | |
| 100 GSList *c = connections; | |
| 101 struct gaim_connection *g = NULL; | |
| 102 | |
| 103 while (c) { | |
| 104 g = (struct gaim_connection *)c->data; | |
| 105 if (!strcmp(normalize(g->username), who)) { | |
| 106 g_free(who); | |
| 107 return g; | |
| 108 } | |
| 109 c = c->next; | |
| 110 } | |
| 111 | |
| 112 g_free(who); | |
| 113 return NULL; | |
| 114 } | |
| 115 | |
| 116 static void delete_acctedit(GtkWidget *w, gpointer d) | |
| 117 { | |
| 118 if (acctedit) { | |
| 119 save_prefs(); | |
| 120 gtk_widget_destroy(acctedit); | |
| 121 } | |
| 122 acctedit = NULL; | |
| 123 } | |
| 124 | |
| 125 static gint acctedit_close(GtkWidget *w, gpointer d) | |
| 126 { | |
| 127 gtk_widget_destroy(acctedit); | |
| 128 return FALSE; | |
| 129 } | |
| 130 | |
| 131 static char *proto_name(int proto) | |
| 132 { | |
| 133 switch (proto) { | |
| 134 case PROTO_TOC: | |
| 135 return "TOC"; | |
| 136 case PROTO_OSCAR: | |
| 137 return "Oscar"; | |
| 138 default: | |
| 139 /* PRPL */ | |
| 140 return "Other"; | |
| 141 } | |
| 142 } | |
| 143 | |
| 144 static GtkWidget *generate_list() | |
| 145 { | |
| 146 GtkWidget *win; | |
| 147 char *titles[4] = {"Screenname", "Currently Online", "Auto-login", "Protocol"}; | |
| 148 GList *u = aim_users; | |
| 149 struct aim_user *a; | |
| 150 int i; | |
| 151 | |
| 152 win = gtk_scrolled_window_new(0, 0); | |
| 153 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(win), GTK_POLICY_AUTOMATIC, | |
| 154 GTK_POLICY_ALWAYS); | |
| 155 | |
| 156 list = gtk_clist_new_with_titles(4, titles); | |
| 157 gtk_clist_set_column_width(GTK_CLIST(list), 0, 90); | |
| 158 gtk_clist_set_selection_mode(GTK_CLIST(list), GTK_SELECTION_BROWSE); | |
| 159 gtk_clist_column_titles_passive(GTK_CLIST(list)); | |
| 160 gtk_container_add(GTK_CONTAINER(win), list); | |
| 161 gtk_widget_show(list); | |
| 162 | |
| 163 while (u) { | |
| 164 a = (struct aim_user *)u->data; | |
| 165 titles[0] = a->username; | |
| 166 titles[1] = find_gaim_conn_by_name(a->username) ? "True" : "False"; | |
| 167 titles[2] = (a->options & OPT_USR_AUTO) ? "True" : "False"; | |
| 168 titles[3] = proto_name(a->protocol); | |
| 169 i = gtk_clist_append(GTK_CLIST(list), titles); | |
| 170 gtk_clist_set_row_data(GTK_CLIST(list), i, a); | |
| 171 u = u->next; | |
| 172 } | |
| 173 | |
| 174 gtk_widget_show(win); | |
| 175 return win; | |
| 176 } | |
| 177 | |
| 178 static void delmod(GtkWidget *w, struct aim_user *u) | |
| 179 { | |
| 180 gtk_widget_destroy(w); | |
| 181 if (u) { | |
| 182 u->mod = NULL; | |
| 183 } else { | |
| 184 newmod = NULL; | |
| 185 } | |
| 186 } | |
| 187 | |
| 188 static void mod_opt(GtkWidget *b, struct mod_usr_opt *m) | |
| 189 { | |
| 190 if (m->user) { | |
| 191 m->user->tmp_options = m->user->tmp_options ^ m->opt; | |
| 192 } else { | |
| 193 tmpusr.options = tmpusr.options ^ m->opt; | |
| 194 } | |
| 195 } | |
| 196 | |
| 197 static GtkWidget *acct_button(const char *text, struct aim_user *u, int option, GtkWidget *box) | |
| 198 { | |
| 199 GtkWidget *button; | |
| 200 struct mod_usr_opt *muo = g_new0(struct mod_usr_opt, 1); | |
| 201 button = gtk_check_button_new_with_label(text); | |
| 202 if (u) { | |
| 203 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), (u->options & option)); | |
| 204 } else { | |
| 205 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), (tmpusr.options & option)); | |
| 206 } | |
| 207 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0); | |
| 208 muo->user = u; muo->opt = option; | |
| 209 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(mod_opt), muo); | |
| 210 gtk_widget_show(button); | |
| 211 return button; | |
| 212 } | |
| 213 | |
| 214 static void ok_mod(GtkWidget *w, struct aim_user *u) | |
| 215 { | |
| 216 char *txt; | |
| 217 int i; | |
| 218 if (u) { | |
| 219 u->options = u->tmp_options; | |
| 220 u->protocol = u->tmp_protocol; | |
| 221 txt = gtk_entry_get_text(GTK_ENTRY(u->pass)); | |
| 222 if (u->options & OPT_USR_REM_PASS) | |
| 223 g_snprintf(u->password, sizeof(u->password), "%s", txt); | |
| 224 else | |
| 225 u->password[0] = '\0'; | |
| 226 gtk_widget_destroy(u->mod); | |
| 227 i = gtk_clist_find_row_from_data(GTK_CLIST(list), u); | |
| 228 gtk_clist_set_text(GTK_CLIST(list), i, 2, (u->options & OPT_USR_AUTO) ? "True" : "False"); | |
| 229 gtk_clist_set_text(GTK_CLIST(list), i, 3, proto_name(u->protocol)); | |
| 230 } else { | |
| 231 char *titles[4]; | |
| 232 txt = gtk_entry_get_text(GTK_ENTRY(tmpusr.name)); | |
| 233 if (!find_user(txt)) { | |
| 234 /* PRPL: also need to check protocol. remember TOC and Oscar are both AIM */ | |
| 235 gtk_widget_destroy(newmod); | |
| 236 return; | |
| 237 } | |
| 238 u = g_new0(struct aim_user, 1); | |
| 239 u->protocol = PROTO_TOC; | |
| 240 g_snprintf(u->username, sizeof(u->username), "%s", txt); | |
| 241 txt = gtk_entry_get_text(GTK_ENTRY(tmpusr.pass)); | |
| 242 g_snprintf(u->password, sizeof(u->password), "%s", txt); | |
| 243 u->options = tmpusr.options; | |
| 244 u->protocol = tmpusr.protocol; | |
| 245 gtk_widget_destroy(newmod); | |
| 246 titles[0] = u->username; | |
| 247 titles[1] = find_gaim_conn_by_name(u->username) ? "True" : "False"; | |
| 248 titles[2] = (u->options & OPT_USR_AUTO) ? "True" : "False"; | |
| 249 titles[3] = proto_name(u->protocol); | |
| 250 i = gtk_clist_append(GTK_CLIST(list), titles); | |
| 251 gtk_clist_set_row_data(GTK_CLIST(list), i, u); | |
| 252 } | |
| 253 save_prefs(); | |
| 254 } | |
| 255 | |
| 256 static void cancel_mod(GtkWidget *w, struct aim_user *u) | |
| 257 { | |
| 258 if (u) { | |
| 259 gtk_widget_destroy(u->mod); | |
| 260 } else { | |
| 261 gtk_widget_destroy(newmod); | |
| 262 } | |
| 263 } | |
| 264 | |
| 265 static void set_prot(GtkWidget *opt, int proto) | |
| 266 { | |
| 267 struct aim_user *u = gtk_object_get_user_data(GTK_OBJECT(opt)); | |
| 268 if (u) { | |
| 269 u->tmp_protocol = proto; | |
| 270 } else { | |
| 271 tmpusr.protocol = proto; | |
| 272 } | |
| 273 } | |
| 274 | |
| 275 static GtkWidget *make_protocol_menu(GtkWidget *box, struct aim_user *u) | |
| 276 { | |
| 277 GtkWidget *optmenu; | |
| 278 GtkWidget *menu; | |
| 279 GtkWidget *opt; | |
| 280 | |
| 281 /* PRPL: should we set some way to update these when new protocols get added? */ | |
| 282 optmenu = gtk_option_menu_new(); | |
| 283 gtk_box_pack_start(GTK_BOX(box), optmenu, FALSE, FALSE, 5); | |
| 284 gtk_widget_show(optmenu); | |
| 285 | |
| 286 menu = gtk_menu_new(); | |
| 287 | |
| 288 /* PRPL: we need to have some way of getting all the plugin names, etc */ | |
| 289 opt = gtk_menu_item_new_with_label("TOC"); | |
| 290 gtk_object_set_user_data(GTK_OBJECT(opt), u); | |
| 291 gtk_signal_connect(GTK_OBJECT(opt), "activate", GTK_SIGNAL_FUNC(set_prot), (void *)PROTO_TOC); | |
| 292 gtk_menu_append(GTK_MENU(menu), opt); | |
| 293 gtk_widget_show(opt); | |
| 294 | |
| 295 opt = gtk_menu_item_new_with_label("Oscar"); | |
| 296 gtk_object_set_user_data(GTK_OBJECT(opt), u); | |
| 297 gtk_signal_connect(GTK_OBJECT(opt), "activate", GTK_SIGNAL_FUNC(set_prot), (void *)PROTO_OSCAR); | |
| 298 gtk_menu_append(GTK_MENU(menu), opt); | |
| 299 gtk_widget_show(opt); | |
| 300 | |
| 301 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | |
| 302 if (u) { | |
| 303 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), u->protocol); | |
| 304 } else { | |
| 305 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), PROTO_TOC); | |
| 306 } | |
| 307 | |
| 308 return optmenu; | |
| 309 } | |
| 310 | |
| 311 static void show_acct_mod(struct aim_user *u) | |
| 312 { | |
| 313 /* here we can have all the aim_user options, including ones not shown in the main acctedit | |
| 314 * window. this can keep the size of the acctedit window small and readable, and make this | |
| 315 * one the powerful editor. this is where things like name/password are edited, but can | |
| 316 * also have toggles (and even more complex options) like whether to autologin or whether | |
| 317 * to send keepalives or whatever. this would be the perfect place to specify which protocol | |
| 318 * to use. make sure to account for the possibility of protocol plugins. */ | |
| 319 GtkWidget *mod; | |
| 320 GtkWidget *frame; | |
| 321 GtkWidget *vbox; | |
| 322 GtkWidget *hbox; | |
| 323 GtkWidget *label; | |
| 324 GtkWidget *name; | |
| 325 GtkWidget *pass; | |
| 326 GtkWidget *button; | |
| 327 | |
| 328 if (!u && newmod) { | |
| 329 gtk_widget_show(newmod); | |
| 330 return; | |
| 331 } | |
| 332 if (u && u->mod) { | |
| 333 gtk_widget_show(u->mod); | |
| 334 return; | |
| 335 } | |
| 336 | |
| 337 mod = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 338 gtk_window_set_wmclass(GTK_WINDOW(mod), "account", "Gaim"); | |
| 339 gtk_widget_realize(mod); | |
| 340 aol_icon(mod->window); | |
| 341 gtk_container_border_width(GTK_CONTAINER(mod), 10); | |
| 342 gtk_window_set_title(GTK_WINDOW(mod), _("Gaim - Modify Account")); | |
| 343 gtk_signal_connect(GTK_OBJECT(mod), "destroy", | |
| 344 GTK_SIGNAL_FUNC(delmod), u); | |
| 345 | |
| 346 frame = gtk_frame_new(_("Modify Account")); | |
| 347 gtk_container_add(GTK_CONTAINER(mod), frame); | |
| 348 gtk_widget_show(frame); | |
| 349 | |
| 350 vbox = gtk_vbox_new(FALSE, 0); | |
| 351 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
| 352 gtk_widget_show(vbox); | |
| 353 | |
| 354 hbox = gtk_hbox_new(FALSE, 0); | |
| 355 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 356 gtk_widget_show(hbox); | |
| 357 | |
| 358 label = gtk_label_new(_("Screenname:")); | |
| 359 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
| 360 gtk_widget_show(label); | |
| 361 | |
| 362 name = gtk_entry_new(); | |
| 363 gtk_box_pack_start(GTK_BOX(hbox), name, FALSE, FALSE, 5); | |
| 364 gtk_widget_show(name); | |
| 365 | |
| 366 hbox = gtk_hbox_new(FALSE, 5); | |
| 367 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 368 gtk_widget_show(hbox); | |
| 369 | |
| 370 label = gtk_label_new(_("Password:")); | |
| 371 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
| 372 gtk_widget_show(label); | |
| 373 | |
| 374 pass = gtk_entry_new(); | |
| 375 gtk_box_pack_start(GTK_BOX(hbox), pass, FALSE, FALSE, 5); | |
| 376 gtk_entry_set_visibility(GTK_ENTRY(pass), FALSE); | |
| 377 gtk_widget_show(pass); | |
| 378 | |
| 379 hbox = gtk_hbox_new(FALSE, 5); | |
| 380 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 381 gtk_widget_show(hbox); | |
| 382 | |
| 383 make_protocol_menu(hbox, u); | |
| 384 | |
| 385 acct_button(_("Remember Password"), u, OPT_USR_REM_PASS, vbox); | |
| 386 acct_button(_("Auto-Login"), u, OPT_USR_AUTO, vbox); | |
| 387 acct_button(_("Send KeepAlive packet (6 bytes/second)"), u, OPT_USR_KEEPALV, vbox); | |
| 388 | |
| 389 hbox = gtk_hbox_new(FALSE, 5); | |
| 390 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 391 gtk_widget_show(hbox); | |
| 392 | |
| 393 button = picture_button(mod, _("Cancel"), cancel_xpm); | |
| 394 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
| 395 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(cancel_mod), u); | |
| 396 gtk_widget_show(button); | |
| 397 | |
| 398 button = picture_button(mod, _("OK"), ok_xpm); | |
| 399 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
| 400 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(ok_mod), u); | |
| 401 gtk_widget_show(button); | |
| 402 | |
| 403 if (u) { | |
| 404 u->mod = mod; | |
| 405 u->name = name; | |
| 406 u->pass = pass; | |
| 407 u->tmp_options = u->options; | |
| 408 gtk_entry_set_text(GTK_ENTRY(name), u->username); | |
| 409 gtk_entry_set_text(GTK_ENTRY(pass), u->password); | |
| 410 gtk_entry_set_editable(GTK_ENTRY(name), FALSE); | |
| 411 } else { | |
| 412 newmod = mod; | |
| 413 tmpusr.name = name; | |
| 414 tmpusr.pass = pass; | |
| 415 } | |
| 416 | |
| 417 gtk_widget_show(mod); | |
| 418 } | |
| 419 | |
| 420 static void add_acct(GtkWidget *w, gpointer d) | |
| 421 { | |
| 422 show_acct_mod(NULL); | |
| 423 } | |
| 424 | |
| 425 static void mod_acct(GtkWidget *w, gpointer d) | |
| 426 { | |
| 427 int row = -1; | |
| 428 char *name; | |
| 429 struct aim_user *u; | |
| 430 if (GTK_CLIST(list)->selection) | |
| 431 row = (int)GTK_CLIST(list)->selection->data; | |
| 432 if (row != -1) { | |
| 433 gtk_clist_get_text(GTK_CLIST(list), row, 0, &name); | |
| 434 u = find_user(name); | |
| 435 if (u) | |
| 436 show_acct_mod(u); | |
| 437 } | |
| 438 } | |
| 439 | |
| 440 static void pass_des(GtkWidget *w, struct aim_user *u) | |
| 441 { | |
| 442 gtk_widget_destroy(w); | |
| 443 u->passprmt = NULL; | |
| 444 } | |
| 445 | |
| 446 static void pass_cancel(GtkWidget *w, struct aim_user *u) | |
| 447 { | |
| 448 gtk_widget_destroy(u->passprmt); | |
| 449 u->passprmt = NULL; | |
| 450 } | |
| 451 | |
| 452 static void pass_signon(GtkWidget *w, struct aim_user *u) | |
| 453 { | |
| 454 char *txt = gtk_entry_get_text(GTK_ENTRY(u->passentry)); | |
| 455 char *un, *ps; | |
| 456 #ifdef USE_APPLET | |
| 457 set_user_state(signing_on); | |
| 458 #endif | |
| 459 un = g_strdup(u->username); | |
| 460 ps = g_strdup(txt); | |
| 461 gtk_widget_destroy(u->passprmt); | |
| 462 u->passprmt = NULL; | |
| 463 serv_login(un, ps); | |
| 464 g_free(un); | |
| 465 g_free(ps); | |
| 466 } | |
| 467 | |
| 468 static void do_pass_dlg(struct aim_user *u) | |
| 469 { | |
| 470 /* we can safely assume that u is not NULL */ | |
| 471 GtkWidget *frame; | |
| 472 GtkWidget *vbox; | |
| 473 GtkWidget *hbox; | |
| 474 char buf[96]; | |
| 475 GtkWidget *label; | |
| 476 GtkWidget *button; | |
| 477 | |
| 478 if (u->passprmt) { gtk_widget_show(u->passprmt); return; } | |
| 479 u->passprmt = gtk_window_new(GTK_WINDOW_DIALOG); | |
| 480 gtk_window_set_wmclass(GTK_WINDOW(u->passprmt), "password", "Gaim"); | |
| 481 gtk_container_border_width(GTK_CONTAINER(u->passprmt), 5); | |
| 482 gtk_signal_connect(GTK_OBJECT(u->passprmt), "destroy", GTK_SIGNAL_FUNC(pass_des), u); | |
| 483 gtk_widget_realize(u->passprmt); | |
| 484 aol_icon(u->passprmt->window); | |
| 485 | |
| 486 frame = gtk_frame_new(_("Enter Password")); | |
| 487 gtk_container_add(GTK_CONTAINER(u->passprmt), frame); | |
| 488 gtk_widget_show(frame); | |
| 489 | |
| 490 vbox = gtk_vbox_new(FALSE, 5); | |
| 491 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
| 492 gtk_widget_show(vbox); | |
| 493 | |
| 494 hbox = gtk_hbox_new(FALSE, 5); | |
| 495 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 496 gtk_widget_show(hbox); | |
| 497 | |
| 498 g_snprintf(buf, sizeof(buf), "Password for %s:", u->username); | |
| 499 label = gtk_label_new(buf); | |
| 500 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
| 501 gtk_widget_show(label); | |
| 502 | |
| 503 u->passentry = gtk_entry_new(); | |
| 504 gtk_entry_set_visibility(GTK_ENTRY(u->passentry), FALSE); | |
| 505 gtk_box_pack_start(GTK_BOX(hbox), u->passentry, FALSE, FALSE, 5); | |
| 506 gtk_signal_connect(GTK_OBJECT(u->passentry), "activate", GTK_SIGNAL_FUNC(pass_signon), u); | |
| 507 gtk_widget_grab_focus(u->passentry); | |
| 508 gtk_widget_show(u->passentry); | |
| 509 | |
| 510 hbox = gtk_hbox_new(FALSE, 5); | |
| 511 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 512 gtk_widget_show(hbox); | |
| 513 | |
| 514 button = picture_button(u->passprmt, _("Cancel"), cancel_xpm); | |
| 515 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(pass_cancel), u); | |
| 516 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
| 517 | |
| 518 button = picture_button(u->passprmt, _("Signon"), ok_xpm); | |
| 519 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(pass_signon), u); | |
| 520 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
| 521 | |
| 522 gtk_widget_show(u->passprmt); | |
| 523 } | |
| 524 | |
| 525 static void acct_signin(GtkWidget *w, gpointer d) | |
| 526 { | |
| 527 int row = -1; | |
| 528 char *name; | |
| 529 struct aim_user *u; | |
| 530 struct gaim_connection *gc; | |
| 531 if (GTK_CLIST(list)->selection) | |
| 532 row = (int)GTK_CLIST(list)->selection->data; | |
| 533 if (row != -1) { | |
| 534 gtk_clist_get_text(GTK_CLIST(list), row, 0, &name); | |
| 535 u = find_user(name); | |
| 536 gc = find_gaim_conn_by_name(name); | |
| 537 if (!gc) { | |
| 538 char *un, *ps; | |
| 539 if (!u->password[0]) { | |
| 540 do_pass_dlg(u); | |
| 541 } else { | |
| 542 #ifdef USE_APPLET | |
| 543 set_user_state(signing_on); | |
| 544 #endif /* USE_APPLET */ | |
| 545 | |
| 546 un = g_strdup(u->username); | |
| 547 ps = g_strdup(u->password); | |
| 548 gc = serv_login(un, ps); | |
| 549 g_free(un); | |
| 550 g_free(ps); | |
| 551 } | |
| 552 } else { | |
| 553 signoff(gc); | |
| 554 } | |
| 555 } | |
| 556 } | |
| 557 | |
| 558 static void del_acct(GtkWidget *w, gpointer d) | |
| 559 { | |
| 560 int row = -1; | |
| 561 char *name; | |
| 562 struct aim_user *u; | |
| 563 if (GTK_CLIST(list)->selection) | |
| 564 row = (int)GTK_CLIST(list)->selection->data; | |
| 565 if (row != -1) { | |
| 566 gtk_clist_get_text(GTK_CLIST(list), row, 0, &name); | |
| 567 u = find_user(name); | |
| 568 if (u) { | |
| 569 aim_users = g_list_remove(aim_users, u); | |
| 570 save_prefs(); | |
| 571 } | |
| 572 gtk_clist_remove(GTK_CLIST(list), row); | |
| 573 } | |
| 574 } | |
| 575 | |
| 576 void account_editor(GtkWidget *w, GtkWidget *W) | |
| 577 { | |
| 578 /* please kill me */ | |
| 579 GtkWidget *frame; | |
| 580 GtkWidget *box; | |
| 581 GtkWidget *list; | |
| 582 GtkWidget *hbox; | |
| 583 GtkWidget *button; /* used for many things */ | |
| 584 | |
| 585 if (acctedit) { gtk_widget_show(acctedit); return; } | |
| 586 | |
| 587 acctedit = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 588 gtk_window_set_title(GTK_WINDOW(acctedit), _("Gaim - Account Editor")); | |
| 589 gtk_window_set_wmclass(GTK_WINDOW(acctedit), "accounteditor", "Gaim"); | |
| 590 gtk_widget_realize(acctedit); | |
| 591 aol_icon(acctedit->window); | |
| 592 gtk_container_border_width(GTK_CONTAINER(acctedit), 10); | |
| 593 gtk_widget_set_usize(acctedit, -1, 200); | |
| 594 gtk_signal_connect(GTK_OBJECT(acctedit), "destroy", | |
| 595 GTK_SIGNAL_FUNC(delete_acctedit), NULL); | |
| 596 | |
| 597 frame = gtk_frame_new(_("Account Editor")); | |
| 598 gtk_container_add(GTK_CONTAINER(acctedit), frame); | |
| 599 gtk_widget_show(frame); | |
| 600 | |
| 601 box = gtk_vbox_new(FALSE, 5); | |
| 602 gtk_container_add(GTK_CONTAINER(frame), box); | |
| 603 gtk_widget_show(box); | |
| 604 | |
| 605 list = generate_list(); | |
| 606 gtk_box_pack_start(GTK_BOX(box), list, TRUE, TRUE, 5); | |
| 607 | |
| 608 hbox = gtk_hbox_new(TRUE, 5); | |
| 609 gtk_box_pack_end(GTK_BOX(box), hbox, FALSE, FALSE, 5); | |
| 610 gtk_widget_show(hbox); | |
| 611 | |
| 612 button = picture_button(acctedit, _("Add"), gnome_add_xpm); | |
| 613 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5); | |
| 614 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(add_acct), NULL); | |
| 615 | |
| 616 button = picture_button(acctedit, _("Modify"), gnome_preferences_xpm); | |
| 617 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5); | |
| 618 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(mod_acct), NULL); | |
| 619 | |
| 620 button = picture_button(acctedit, _("Sign On/Off"), join_xpm); | |
| 621 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5); | |
| 622 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(acct_signin), NULL); | |
| 623 | |
| 624 button = picture_button(acctedit, _("Delete"), gnome_remove_xpm); | |
| 625 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5); | |
| 626 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(del_acct), NULL); | |
| 627 | |
| 628 button = picture_button(acctedit, _("Close"), gnome_close_xpm); | |
| 629 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5); | |
| 630 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(acctedit_close), NULL); | |
| 631 | |
| 632 gtk_widget_show(acctedit); | |
| 633 } | |
| 634 | |
| 635 void account_online(struct gaim_connection *gc) | |
| 636 { | |
| 637 struct aim_user *u; | |
| 638 int i; | |
| 639 if (!acctedit) return; | |
| 640 u = find_user(gc->username); | |
| 641 i = gtk_clist_find_row_from_data(GTK_CLIST(list), u); | |
| 642 gtk_clist_set_text(GTK_CLIST(list), i, 1, "True"); | |
| 643 gtk_clist_set_text(GTK_CLIST(list), i, 3, proto_name(gc->protocol)); | |
| 644 redo_convo_menus(); | |
| 645 } | |
| 646 | |
| 647 void account_offline(struct gaim_connection *gc) | |
| 648 { | |
| 649 struct aim_user *u; | |
| 650 int i; | |
| 651 if (!acctedit) return; | |
| 652 u = find_user(gc->username); | |
| 653 i = gtk_clist_find_row_from_data(GTK_CLIST(list), u); | |
| 654 gtk_clist_set_text(GTK_CLIST(list), i, 1, "False"); | |
| 655 } | |
| 656 | |
| 657 void auto_login() | |
| 658 { | |
| 659 GList *u = aim_users; | |
| 660 struct aim_user *a = NULL; | |
| 661 char *un, *ps; | |
| 662 | |
| 663 while (u) { | |
| 664 a = (struct aim_user *)u->data; | |
| 665 if ((a->options & OPT_USR_AUTO) && (a->options & OPT_USR_REM_PASS)) { | |
| 666 #ifdef USE_APPLET | |
| 667 set_user_state(signing_on); | |
| 668 #endif /* USE_APPLET */ | |
| 669 | |
| 670 un = g_strdup(a->username); | |
| 671 ps = g_strdup(a->password); | |
| 672 serv_login(un, ps); | |
| 673 g_free(un); | |
| 674 g_free(ps); | |
| 675 } | |
| 676 u = u->next; | |
| 677 } | |
| 678 } |
