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