Mercurial > pidgin
annotate src/multi.c @ 984:7ec6b092f227
[gaim-migrate @ 994]
this helps :-P
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Fri, 13 Oct 2000 08:45:42 +0000 |
| parents | 09e5065fe22c |
| children | 9523b772e546 |
| 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); | |
|
984
7ec6b092f227
[gaim-migrate @ 994]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
982
diff
changeset
|
241 aim_users = g_list_append(aim_users, u); |
| 960 | 242 } |
| 243 save_prefs(); | |
| 244 } | |
| 245 | |
| 246 static void cancel_mod(GtkWidget *w, struct aim_user *u) | |
| 247 { | |
| 248 if (u) { | |
| 249 gtk_widget_destroy(u->mod); | |
| 250 } else { | |
| 251 gtk_widget_destroy(newmod); | |
| 252 } | |
| 253 } | |
| 254 | |
| 255 static void set_prot(GtkWidget *opt, int proto) | |
| 256 { | |
| 257 struct aim_user *u = gtk_object_get_user_data(GTK_OBJECT(opt)); | |
| 258 if (u) { | |
| 259 u->tmp_protocol = proto; | |
| 260 } else { | |
| 261 tmpusr.protocol = proto; | |
| 262 } | |
| 263 } | |
| 264 | |
| 265 static GtkWidget *make_protocol_menu(GtkWidget *box, struct aim_user *u) | |
| 266 { | |
| 267 GtkWidget *optmenu; | |
| 268 GtkWidget *menu; | |
| 269 GtkWidget *opt; | |
|
981
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
270 GSList *p = protocols; |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
271 struct prpl *e; |
| 960 | 272 |
| 273 /* PRPL: should we set some way to update these when new protocols get added? */ | |
| 274 optmenu = gtk_option_menu_new(); | |
| 275 gtk_box_pack_start(GTK_BOX(box), optmenu, FALSE, FALSE, 5); | |
| 276 gtk_widget_show(optmenu); | |
| 277 | |
| 278 menu = gtk_menu_new(); | |
| 279 | |
|
981
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
280 while (p) { |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
281 e = (struct prpl *)p->data; |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
282 if (e->name) |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
283 opt = gtk_menu_item_new_with_label((*e->name)()); |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
284 else |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
285 opt = gtk_menu_item_new_with_label("Unknown"); |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
286 gtk_object_set_user_data(GTK_OBJECT(opt), u); |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
287 gtk_signal_connect(GTK_OBJECT(opt), "activate", |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
288 GTK_SIGNAL_FUNC(set_prot), (void *)e->protocol); |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
289 gtk_menu_append(GTK_MENU(menu), opt); |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
290 gtk_widget_show(opt); |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
291 p = p->next; |
|
7e231bc0018a
[gaim-migrate @ 991]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
980
diff
changeset
|
292 } |
| 960 | 293 |
| 294 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu); | |
| 295 if (u) { | |
| 296 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), u->protocol); | |
|
982
09e5065fe22c
[gaim-migrate @ 992]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
981
diff
changeset
|
297 u->tmp_protocol = u->protocol; |
| 960 | 298 } else { |
| 299 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), PROTO_TOC); | |
| 300 } | |
| 301 | |
| 302 return optmenu; | |
| 303 } | |
| 304 | |
| 305 static void show_acct_mod(struct aim_user *u) | |
| 306 { | |
| 307 /* here we can have all the aim_user options, including ones not shown in the main acctedit | |
| 308 * window. this can keep the size of the acctedit window small and readable, and make this | |
| 309 * one the powerful editor. this is where things like name/password are edited, but can | |
| 310 * also have toggles (and even more complex options) like whether to autologin or whether | |
| 311 * to send keepalives or whatever. this would be the perfect place to specify which protocol | |
| 312 * to use. make sure to account for the possibility of protocol plugins. */ | |
| 313 GtkWidget *mod; | |
| 314 GtkWidget *frame; | |
| 315 GtkWidget *vbox; | |
| 316 GtkWidget *hbox; | |
| 317 GtkWidget *label; | |
| 318 GtkWidget *name; | |
| 319 GtkWidget *pass; | |
| 320 GtkWidget *button; | |
| 321 | |
| 322 if (!u && newmod) { | |
| 323 gtk_widget_show(newmod); | |
| 324 return; | |
| 325 } | |
| 326 if (u && u->mod) { | |
| 327 gtk_widget_show(u->mod); | |
| 328 return; | |
| 329 } | |
| 330 | |
| 331 mod = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 332 gtk_window_set_wmclass(GTK_WINDOW(mod), "account", "Gaim"); | |
| 333 gtk_widget_realize(mod); | |
| 334 aol_icon(mod->window); | |
| 335 gtk_container_border_width(GTK_CONTAINER(mod), 10); | |
| 336 gtk_window_set_title(GTK_WINDOW(mod), _("Gaim - Modify Account")); | |
| 337 gtk_signal_connect(GTK_OBJECT(mod), "destroy", | |
| 338 GTK_SIGNAL_FUNC(delmod), u); | |
| 339 | |
| 340 frame = gtk_frame_new(_("Modify Account")); | |
| 341 gtk_container_add(GTK_CONTAINER(mod), frame); | |
| 342 gtk_widget_show(frame); | |
| 343 | |
| 344 vbox = gtk_vbox_new(FALSE, 0); | |
| 345 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
| 346 gtk_widget_show(vbox); | |
| 347 | |
| 348 hbox = gtk_hbox_new(FALSE, 0); | |
| 349 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 350 gtk_widget_show(hbox); | |
| 351 | |
| 352 label = gtk_label_new(_("Screenname:")); | |
| 353 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
| 354 gtk_widget_show(label); | |
| 355 | |
| 356 name = gtk_entry_new(); | |
| 357 gtk_box_pack_start(GTK_BOX(hbox), name, FALSE, FALSE, 5); | |
| 358 gtk_widget_show(name); | |
| 359 | |
| 360 hbox = gtk_hbox_new(FALSE, 5); | |
| 361 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 362 gtk_widget_show(hbox); | |
| 363 | |
| 364 label = gtk_label_new(_("Password:")); | |
| 365 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
| 366 gtk_widget_show(label); | |
| 367 | |
| 368 pass = gtk_entry_new(); | |
| 369 gtk_box_pack_start(GTK_BOX(hbox), pass, FALSE, FALSE, 5); | |
| 370 gtk_entry_set_visibility(GTK_ENTRY(pass), FALSE); | |
| 371 gtk_widget_show(pass); | |
| 372 | |
| 373 hbox = gtk_hbox_new(FALSE, 5); | |
| 374 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 375 gtk_widget_show(hbox); | |
| 376 | |
| 377 make_protocol_menu(hbox, u); | |
| 378 | |
| 379 acct_button(_("Remember Password"), u, OPT_USR_REM_PASS, vbox); | |
| 380 acct_button(_("Auto-Login"), u, OPT_USR_AUTO, vbox); | |
| 381 acct_button(_("Send KeepAlive packet (6 bytes/second)"), u, OPT_USR_KEEPALV, vbox); | |
| 382 | |
| 383 hbox = gtk_hbox_new(FALSE, 5); | |
| 384 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 385 gtk_widget_show(hbox); | |
| 386 | |
| 387 button = picture_button(mod, _("Cancel"), cancel_xpm); | |
| 388 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
| 389 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(cancel_mod), u); | |
| 390 gtk_widget_show(button); | |
| 391 | |
| 392 button = picture_button(mod, _("OK"), ok_xpm); | |
| 393 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
| 394 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(ok_mod), u); | |
| 395 gtk_widget_show(button); | |
| 396 | |
| 397 if (u) { | |
| 398 u->mod = mod; | |
| 399 u->name = name; | |
| 400 u->pass = pass; | |
| 401 u->tmp_options = u->options; | |
| 402 gtk_entry_set_text(GTK_ENTRY(name), u->username); | |
| 403 gtk_entry_set_text(GTK_ENTRY(pass), u->password); | |
| 404 gtk_entry_set_editable(GTK_ENTRY(name), FALSE); | |
| 405 } else { | |
| 406 newmod = mod; | |
| 407 tmpusr.name = name; | |
| 408 tmpusr.pass = pass; | |
| 409 } | |
| 410 | |
| 411 gtk_widget_show(mod); | |
| 412 } | |
| 413 | |
| 414 static void add_acct(GtkWidget *w, gpointer d) | |
| 415 { | |
| 416 show_acct_mod(NULL); | |
| 417 } | |
| 418 | |
| 419 static void mod_acct(GtkWidget *w, gpointer d) | |
| 420 { | |
| 421 int row = -1; | |
| 422 char *name; | |
| 423 struct aim_user *u; | |
| 424 if (GTK_CLIST(list)->selection) | |
| 425 row = (int)GTK_CLIST(list)->selection->data; | |
| 426 if (row != -1) { | |
| 427 gtk_clist_get_text(GTK_CLIST(list), row, 0, &name); | |
| 428 u = find_user(name); | |
| 429 if (u) | |
| 430 show_acct_mod(u); | |
| 431 } | |
| 432 } | |
| 433 | |
| 434 static void pass_des(GtkWidget *w, struct aim_user *u) | |
| 435 { | |
| 436 gtk_widget_destroy(w); | |
| 437 u->passprmt = NULL; | |
| 438 } | |
| 439 | |
| 440 static void pass_cancel(GtkWidget *w, struct aim_user *u) | |
| 441 { | |
| 442 gtk_widget_destroy(u->passprmt); | |
| 443 u->passprmt = NULL; | |
| 444 } | |
| 445 | |
| 446 static void pass_signon(GtkWidget *w, struct aim_user *u) | |
| 447 { | |
| 448 char *txt = gtk_entry_get_text(GTK_ENTRY(u->passentry)); | |
|
980
82c5865f7cfe
[gaim-migrate @ 990]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
977
diff
changeset
|
449 g_snprintf(u->password, sizeof(u->password), "%s", txt); |
| 960 | 450 #ifdef USE_APPLET |
| 451 set_user_state(signing_on); | |
| 452 #endif | |
| 453 gtk_widget_destroy(u->passprmt); | |
| 454 u->passprmt = NULL; | |
|
980
82c5865f7cfe
[gaim-migrate @ 990]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
977
diff
changeset
|
455 serv_login(u); |
| 960 | 456 } |
| 457 | |
| 458 static void do_pass_dlg(struct aim_user *u) | |
| 459 { | |
| 460 /* we can safely assume that u is not NULL */ | |
| 461 GtkWidget *frame; | |
| 462 GtkWidget *vbox; | |
| 463 GtkWidget *hbox; | |
| 464 char buf[96]; | |
| 465 GtkWidget *label; | |
| 466 GtkWidget *button; | |
| 467 | |
| 468 if (u->passprmt) { gtk_widget_show(u->passprmt); return; } | |
| 469 u->passprmt = gtk_window_new(GTK_WINDOW_DIALOG); | |
| 470 gtk_window_set_wmclass(GTK_WINDOW(u->passprmt), "password", "Gaim"); | |
| 471 gtk_container_border_width(GTK_CONTAINER(u->passprmt), 5); | |
| 472 gtk_signal_connect(GTK_OBJECT(u->passprmt), "destroy", GTK_SIGNAL_FUNC(pass_des), u); | |
| 473 gtk_widget_realize(u->passprmt); | |
| 474 aol_icon(u->passprmt->window); | |
| 475 | |
| 476 frame = gtk_frame_new(_("Enter Password")); | |
| 477 gtk_container_add(GTK_CONTAINER(u->passprmt), frame); | |
| 478 gtk_widget_show(frame); | |
| 479 | |
| 480 vbox = gtk_vbox_new(FALSE, 5); | |
| 481 gtk_container_add(GTK_CONTAINER(frame), vbox); | |
| 482 gtk_widget_show(vbox); | |
| 483 | |
| 484 hbox = gtk_hbox_new(FALSE, 5); | |
| 485 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 486 gtk_widget_show(hbox); | |
| 487 | |
| 488 g_snprintf(buf, sizeof(buf), "Password for %s:", u->username); | |
| 489 label = gtk_label_new(buf); | |
| 490 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); | |
| 491 gtk_widget_show(label); | |
| 492 | |
| 493 u->passentry = gtk_entry_new(); | |
| 494 gtk_entry_set_visibility(GTK_ENTRY(u->passentry), FALSE); | |
| 495 gtk_box_pack_start(GTK_BOX(hbox), u->passentry, FALSE, FALSE, 5); | |
| 496 gtk_signal_connect(GTK_OBJECT(u->passentry), "activate", GTK_SIGNAL_FUNC(pass_signon), u); | |
| 497 gtk_widget_grab_focus(u->passentry); | |
| 498 gtk_widget_show(u->passentry); | |
| 499 | |
| 500 hbox = gtk_hbox_new(FALSE, 5); | |
| 501 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
| 502 gtk_widget_show(hbox); | |
| 503 | |
| 504 button = picture_button(u->passprmt, _("Cancel"), cancel_xpm); | |
| 505 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(pass_cancel), u); | |
| 506 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
| 507 | |
| 508 button = picture_button(u->passprmt, _("Signon"), ok_xpm); | |
| 509 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(pass_signon), u); | |
| 510 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 5); | |
| 511 | |
| 512 gtk_widget_show(u->passprmt); | |
| 513 } | |
| 514 | |
| 515 static void acct_signin(GtkWidget *w, gpointer d) | |
| 516 { | |
| 517 int row = -1; | |
| 518 char *name; | |
| 519 struct aim_user *u; | |
| 520 struct gaim_connection *gc; | |
| 521 if (GTK_CLIST(list)->selection) | |
| 522 row = (int)GTK_CLIST(list)->selection->data; | |
| 523 if (row != -1) { | |
| 524 gtk_clist_get_text(GTK_CLIST(list), row, 0, &name); | |
| 525 u = find_user(name); | |
| 526 gc = find_gaim_conn_by_name(name); | |
| 527 if (!gc) { | |
| 528 if (!u->password[0]) { | |
| 529 do_pass_dlg(u); | |
| 530 } else { | |
| 531 #ifdef USE_APPLET | |
| 532 set_user_state(signing_on); | |
| 533 #endif /* USE_APPLET */ | |
|
980
82c5865f7cfe
[gaim-migrate @ 990]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
977
diff
changeset
|
534 serv_login(u); |
| 960 | 535 } |
| 536 } else { | |
| 537 signoff(gc); | |
| 538 } | |
| 539 } | |
| 540 } | |
| 541 | |
| 542 static void del_acct(GtkWidget *w, gpointer d) | |
| 543 { | |
| 544 int row = -1; | |
| 545 char *name; | |
| 546 struct aim_user *u; | |
| 547 if (GTK_CLIST(list)->selection) | |
| 548 row = (int)GTK_CLIST(list)->selection->data; | |
| 549 if (row != -1) { | |
| 550 gtk_clist_get_text(GTK_CLIST(list), row, 0, &name); | |
| 551 u = find_user(name); | |
| 552 if (u) { | |
| 553 aim_users = g_list_remove(aim_users, u); | |
| 554 save_prefs(); | |
| 555 } | |
| 556 gtk_clist_remove(GTK_CLIST(list), row); | |
| 557 } | |
| 558 } | |
| 559 | |
| 560 void account_editor(GtkWidget *w, GtkWidget *W) | |
| 561 { | |
| 562 /* please kill me */ | |
| 563 GtkWidget *frame; | |
| 564 GtkWidget *box; | |
| 565 GtkWidget *list; | |
| 566 GtkWidget *hbox; | |
| 567 GtkWidget *button; /* used for many things */ | |
| 568 | |
| 569 if (acctedit) { gtk_widget_show(acctedit); return; } | |
| 570 | |
| 571 acctedit = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 572 gtk_window_set_title(GTK_WINDOW(acctedit), _("Gaim - Account Editor")); | |
| 573 gtk_window_set_wmclass(GTK_WINDOW(acctedit), "accounteditor", "Gaim"); | |
| 574 gtk_widget_realize(acctedit); | |
| 575 aol_icon(acctedit->window); | |
| 576 gtk_container_border_width(GTK_CONTAINER(acctedit), 10); | |
| 577 gtk_widget_set_usize(acctedit, -1, 200); | |
| 578 gtk_signal_connect(GTK_OBJECT(acctedit), "destroy", | |
| 579 GTK_SIGNAL_FUNC(delete_acctedit), NULL); | |
| 580 | |
| 581 frame = gtk_frame_new(_("Account Editor")); | |
| 582 gtk_container_add(GTK_CONTAINER(acctedit), frame); | |
| 583 gtk_widget_show(frame); | |
| 584 | |
| 585 box = gtk_vbox_new(FALSE, 5); | |
| 586 gtk_container_add(GTK_CONTAINER(frame), box); | |
| 587 gtk_widget_show(box); | |
| 588 | |
| 589 list = generate_list(); | |
| 590 gtk_box_pack_start(GTK_BOX(box), list, TRUE, TRUE, 5); | |
| 591 | |
| 592 hbox = gtk_hbox_new(TRUE, 5); | |
| 593 gtk_box_pack_end(GTK_BOX(box), hbox, FALSE, FALSE, 5); | |
| 594 gtk_widget_show(hbox); | |
| 595 | |
| 596 button = picture_button(acctedit, _("Add"), gnome_add_xpm); | |
| 597 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5); | |
| 598 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(add_acct), NULL); | |
| 599 | |
| 600 button = picture_button(acctedit, _("Modify"), gnome_preferences_xpm); | |
| 601 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5); | |
| 602 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(mod_acct), NULL); | |
| 603 | |
| 604 button = picture_button(acctedit, _("Sign On/Off"), join_xpm); | |
| 605 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5); | |
| 606 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(acct_signin), NULL); | |
| 607 | |
| 608 button = picture_button(acctedit, _("Delete"), gnome_remove_xpm); | |
| 609 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5); | |
| 610 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(del_acct), NULL); | |
| 611 | |
| 612 button = picture_button(acctedit, _("Close"), gnome_close_xpm); | |
| 613 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 5); | |
| 614 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(acctedit_close), NULL); | |
| 615 | |
| 616 gtk_widget_show(acctedit); | |
| 617 } | |
| 618 | |
| 619 void account_online(struct gaim_connection *gc) | |
| 620 { | |
| 621 struct aim_user *u; | |
| 622 int i; | |
| 623 if (!acctedit) return; | |
| 624 u = find_user(gc->username); | |
| 625 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
|
626 gtk_clist_set_text(GTK_CLIST(list), i, 1, "Yes"); |
| 960 | 627 gtk_clist_set_text(GTK_CLIST(list), i, 3, proto_name(gc->protocol)); |
| 628 redo_convo_menus(); | |
| 629 } | |
| 630 | |
| 631 void account_offline(struct gaim_connection *gc) | |
| 632 { | |
| 633 struct aim_user *u; | |
| 634 int i; | |
| 635 if (!acctedit) return; | |
| 636 u = find_user(gc->username); | |
| 637 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
|
638 gtk_clist_set_text(GTK_CLIST(list), i, 1, "No"); |
| 960 | 639 } |
| 640 | |
| 641 void auto_login() | |
| 642 { | |
| 643 GList *u = aim_users; | |
| 644 struct aim_user *a = NULL; | |
| 645 | |
| 646 while (u) { | |
| 647 a = (struct aim_user *)u->data; | |
| 648 if ((a->options & OPT_USR_AUTO) && (a->options & OPT_USR_REM_PASS)) { | |
| 649 #ifdef USE_APPLET | |
| 650 set_user_state(signing_on); | |
| 651 #endif /* USE_APPLET */ | |
|
980
82c5865f7cfe
[gaim-migrate @ 990]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
977
diff
changeset
|
652 serv_login(a); |
| 960 | 653 } |
| 654 u = u->next; | |
| 655 } | |
| 656 } |
