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