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