Mercurial > pidgin.yaz
comparison src/multi.c @ 4966:54cd43869333
[gaim-migrate @ 5300]
fun stuff
this makes the modify account dialog make a little more sense for jabber,
and makes irc accounts distinguishable in the assorted dropdowns.
however, there is a slight catch. IRC accounts now take the form of
nick@server. The first time you log on with an IRC account, it will change
it for you. However, if you try to edit the account before it gets signed
on, the server will revert to the default (irc.freenode.net).
So go log in with all of your IRC accounts before you go editing them ;-)
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Thu, 03 Apr 2003 02:34:48 +0000 |
parents | b6fd57ba76e8 |
children | 1f92610b0772 |
comparison
equal
deleted
inserted
replaced
4965:6e7082cf0892 | 4966:54cd43869333 |
---|---|
57 | 57 |
58 struct mod_account { | 58 struct mod_account { |
59 struct gaim_account *account; | 59 struct gaim_account *account; |
60 | 60 |
61 /* these are temporary */ | 61 /* these are temporary */ |
62 char username[64]; | |
63 char show[400]; | |
64 char password[32]; | |
62 int options; | 65 int options; |
63 int protocol; | 66 int protocol; |
64 char proto_opt[7][256]; | 67 char proto_opt[7][256]; |
65 | 68 |
66 /* stuff for modify window */ | 69 /* stuff for modify window */ |
69 GtkWidget *name; | 72 GtkWidget *name; |
70 GtkWidget *alias; | 73 GtkWidget *alias; |
71 GtkWidget *pwdbox; | 74 GtkWidget *pwdbox; |
72 GtkWidget *pass; | 75 GtkWidget *pass; |
73 GtkWidget *rempass; | 76 GtkWidget *rempass; |
77 GtkWidget *login_frame; | |
74 GtkWidget *user_frame; | 78 GtkWidget *user_frame; |
75 GtkWidget *proto_frame; | 79 GtkWidget *proto_frame; |
76 GtkSizeGroup *sg; | 80 GtkSizeGroup *sg; |
81 GList *user_split_entries; | |
77 GList *opt_entries; | 82 GList *opt_entries; |
78 | 83 |
79 /* stuff for icon selection */ | 84 /* stuff for icon selection */ |
80 char iconfile[256]; | 85 char iconfile[256]; |
81 GtkWidget *iconsel; | 86 GtkWidget *iconsel; |
118 return ma; | 123 return ma; |
119 m = m->next; | 124 m = m->next; |
120 } | 125 } |
121 return NULL; | 126 return NULL; |
122 } | 127 } |
123 | |
124 static void generate_protocol_options(struct mod_account *, GtkWidget *); | |
125 | 128 |
126 | 129 |
127 struct gaim_connection *new_gaim_conn(struct gaim_account *account) | 130 struct gaim_connection *new_gaim_conn(struct gaim_account *account) |
128 { | 131 { |
129 struct gaim_connection *gc = g_new0(struct gaim_connection, 1); | 132 struct gaim_connection *gc = g_new0(struct gaim_connection, 1); |
359 g_signal_connect(GTK_OBJECT(button), "destroy", G_CALLBACK(free_mao), mao); | 362 g_signal_connect(GTK_OBJECT(button), "destroy", G_CALLBACK(free_mao), mao); |
360 gtk_widget_show(button); | 363 gtk_widget_show(button); |
361 return button; | 364 return button; |
362 } | 365 } |
363 | 366 |
367 static void process_login_opts(struct mod_account *ma) { | |
368 struct prpl *p = find_prpl(ma->protocol); | |
369 const char *entry_text; | |
370 char *username = g_strdup(gtk_entry_get_text(GTK_ENTRY(ma->name))); | |
371 char *tmp; | |
372 GList *entries = ma->user_split_entries; | |
373 GList *user_splits = NULL; | |
374 if(p) | |
375 user_splits = p->user_splits; | |
376 while(user_splits) { | |
377 GtkWidget *entry = entries->data; | |
378 struct proto_user_split *pus = user_splits->data; | |
379 char tmp_sep[2] = " "; | |
380 entry_text = gtk_entry_get_text(GTK_ENTRY(entry)); | |
381 | |
382 tmp_sep[0] = pus->sep; | |
383 tmp = g_strconcat(username, tmp_sep, *entry_text ? entry_text : pus->def, NULL); | |
384 g_free(username); | |
385 username = tmp; | |
386 | |
387 entries = entries->next; | |
388 user_splits = user_splits->next; | |
389 } | |
390 | |
391 g_snprintf(ma->username, sizeof(ma->username), "%s", username); | |
392 g_free(username); | |
393 | |
394 entry_text = gtk_entry_get_text(GTK_ENTRY(ma->pass)); | |
395 g_snprintf(ma->password, sizeof(ma->password), "%s", entry_text); | |
396 | |
397 entry_text = gtk_entry_get_text(GTK_ENTRY(ma->alias)); | |
398 g_snprintf(ma->show, sizeof(ma->show), "%s", entry_text); | |
399 } | |
400 | |
364 static void ok_mod(GtkWidget *w, struct mod_account *ma) | 401 static void ok_mod(GtkWidget *w, struct mod_account *ma) |
365 { | 402 { |
366 GList *tmp; | 403 GList *tmp; |
367 const char *txt; | 404 const char *txt; |
368 struct gaim_account *a; | 405 struct gaim_account *a; |
369 struct prpl *p; | 406 struct prpl *p = find_prpl(ma->protocol); |
370 GtkTreeIter iter; | 407 GtkTreeIter iter; |
371 int proxytype; | 408 int proxytype; |
372 | 409 |
373 if (!ma->account) { | 410 if (!ma->account) { |
374 txt = gtk_entry_get_text(GTK_ENTRY(ma->name)); | 411 txt = gtk_entry_get_text(GTK_ENTRY(ma->name)); |
376 } | 413 } |
377 a = ma->account; | 414 a = ma->account; |
378 | 415 |
379 a->options = ma->options; | 416 a->options = ma->options; |
380 a->protocol = ma->protocol; | 417 a->protocol = ma->protocol; |
381 txt = gtk_entry_get_text(GTK_ENTRY(ma->name)); | 418 |
382 g_snprintf(a->username, sizeof(a->username), "%s", txt); | 419 process_login_opts(ma); |
383 txt = gtk_entry_get_text(GTK_ENTRY(ma->alias)); | 420 g_snprintf(a->username, sizeof(a->username), "%s", ma->username); |
384 g_snprintf(a->alias, sizeof(a->alias), "%s", txt); | 421 g_snprintf(a->alias, sizeof(a->alias), "%s", ma->show); |
385 txt = gtk_entry_get_text(GTK_ENTRY(ma->pass)); | 422 |
386 if (a->options & OPT_ACCT_REM_PASS) | 423 if (a->options & OPT_ACCT_REM_PASS) |
387 g_snprintf(a->password, sizeof(a->password), "%s", txt); | 424 g_snprintf(a->password, sizeof(a->password), "%s", ma->password); |
388 else | 425 else |
389 a->password[0] = '\0'; | 426 a->password[0] = '\0'; |
390 | 427 |
391 if (get_iter_from_data(GTK_TREE_VIEW(treeview), a, &iter)) { | 428 if (get_iter_from_data(GTK_TREE_VIEW(treeview), a, &iter)) { |
392 gtk_list_store_set(model, &iter, | 429 gtk_list_store_set(model, &iter, |
441 } | 478 } |
442 | 479 |
443 /* | 480 /* |
444 * See if user registration is supported/required | 481 * See if user registration is supported/required |
445 */ | 482 */ |
446 if((p = find_prpl(ma->protocol)) == NULL) { | 483 if(!p) { |
447 /* TBD: error dialog here! (This should never happen, you know...) */ | 484 /* TBD: error dialog here! (This should never happen, you know...) */ |
448 fprintf(stderr, "dbg: couldn't find protocol for protocol number %d!\n", ma->protocol); | 485 fprintf(stderr, "dbg: couldn't find protocol for protocol number %d!\n", ma->protocol); |
449 fflush(stderr); | 486 fflush(stderr); |
450 } else { | 487 } else { |
451 if(p->register_user != NULL && | 488 if(p->register_user != NULL && |
472 gtk_widget_destroy(ma->icondlg); | 509 gtk_widget_destroy(ma->icondlg); |
473 ma->icondlg = NULL; | 510 ma->icondlg = NULL; |
474 gtk_widget_destroy(ma->mod); | 511 gtk_widget_destroy(ma->mod); |
475 } | 512 } |
476 | 513 |
514 static void generate_login_options(struct mod_account *ma, GtkWidget *box); | |
515 static void generate_user_options(struct mod_account *ma, GtkWidget *box); | |
516 static void generate_protocol_options(struct mod_account *ma, GtkWidget *box); | |
517 | |
477 static void set_prot(GtkWidget *opt, int proto) | 518 static void set_prot(GtkWidget *opt, int proto) |
478 { | 519 { |
479 struct mod_account *ma = g_object_get_data(G_OBJECT(opt), "mod_account"); | 520 struct mod_account *ma = g_object_get_data(G_OBJECT(opt), "mod_account"); |
480 struct prpl *p, *q; | 521 struct prpl *p; |
481 q = find_prpl(proto); | |
482 if (ma->protocol != proto) { | 522 if (ma->protocol != proto) { |
483 int i; | 523 int i; |
524 | |
484 for (i = 0; i < 7; i++) | 525 for (i = 0; i < 7; i++) |
485 ma->proto_opt[i][0] = '\0'; | 526 ma->proto_opt[i][0] = '\0'; |
486 p = find_prpl(ma->protocol); | 527 p = find_prpl(ma->protocol); |
487 | 528 |
488 if (!(p->options & OPT_PROTO_NO_PASSWORD) && (q->options & OPT_PROTO_NO_PASSWORD)) { | 529 process_login_opts(ma); |
489 gtk_widget_hide(ma->pwdbox); | |
490 gtk_widget_hide(ma->rempass); | |
491 } else if ((p->options & OPT_PROTO_NO_PASSWORD) && !(q->options & OPT_PROTO_NO_PASSWORD)) { | |
492 gtk_widget_show(ma->pwdbox); | |
493 gtk_widget_show(ma->rempass); | |
494 } | |
495 if (!(p->options & OPT_PROTO_MAIL_CHECK) && (q->options & OPT_PROTO_MAIL_CHECK)) { | |
496 gtk_widget_show(ma->checkmail); | |
497 } else if ((p->options & OPT_PROTO_MAIL_CHECK) && !(q->options & OPT_PROTO_MAIL_CHECK)) { | |
498 gtk_widget_hide(ma->checkmail); | |
499 } | |
500 | |
501 if (!(p->options & OPT_PROTO_BUDDY_ICON) && (q->options & OPT_PROTO_BUDDY_ICON)) { | |
502 gtk_widget_show(ma->iconsel); | |
503 } else if ((p->options & OPT_PROTO_BUDDY_ICON) && !(q->options & OPT_PROTO_BUDDY_ICON)) { | |
504 gtk_widget_hide(ma->iconsel); | |
505 } | |
506 | |
507 if ((q->options & OPT_PROTO_BUDDY_ICON) || (q->options & OPT_PROTO_MAIL_CHECK)) | |
508 gtk_widget_show(ma->user_frame); | |
509 else | |
510 gtk_widget_hide(ma->user_frame); | |
511 | 530 |
512 ma->protocol = proto; | 531 ma->protocol = proto; |
532 | |
533 if(!ma->account) | |
534 g_snprintf(ma->username, sizeof(ma->username), "%s", | |
535 gtk_entry_get_text(GTK_ENTRY(ma->name))); | |
536 | |
537 generate_login_options(ma, ma->main); | |
538 generate_user_options(ma, ma->main); | |
513 generate_protocol_options(ma, ma->main); | 539 generate_protocol_options(ma, ma->main); |
514 } | 540 } |
515 } | 541 } |
516 | 542 |
517 static GtkWidget *make_protocol_menu(GtkWidget *box, struct mod_account *ma) | 543 static GtkWidget *make_protocol_menu(GtkWidget *box, struct mod_account *ma) |
657 return hbox; | 683 return hbox; |
658 } | 684 } |
659 | 685 |
660 static void generate_login_options(struct mod_account *ma, GtkWidget *box) | 686 static void generate_login_options(struct mod_account *ma, GtkWidget *box) |
661 { | 687 { |
662 GtkWidget *frame, *frame_parent; | 688 GtkWidget *frame; |
663 GtkWidget *vbox; | 689 GtkWidget *vbox; |
664 GtkWidget *hbox; | 690 GtkWidget *hbox; |
665 GtkWidget *label; | 691 GtkWidget *label; |
692 GList *user_splits = NULL; | |
693 GList *split_entries; | |
666 | 694 |
667 struct prpl *p; | 695 struct prpl *p; |
668 | 696 |
697 char *username = NULL; | |
698 char *start; | |
699 | |
700 if(ma->login_frame) | |
701 gtk_widget_destroy(ma->login_frame); | |
702 ma->login_frame = NULL; | |
703 | |
669 frame = make_frame(box, _("Login Options")); | 704 frame = make_frame(box, _("Login Options")); |
670 frame_parent = gtk_widget_get_parent(gtk_widget_get_parent(frame)); | 705 ma->login_frame = gtk_widget_get_parent(gtk_widget_get_parent(frame)); |
671 | 706 |
672 vbox = gtk_vbox_new(FALSE, 5); | 707 vbox = gtk_vbox_new(FALSE, 5); |
673 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); | 708 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); |
674 gtk_container_add(GTK_CONTAINER(frame), vbox); | 709 gtk_container_add(GTK_CONTAINER(frame), vbox); |
675 | 710 |
676 hbox = gtk_hbox_new(FALSE, 5); | 711 hbox = gtk_hbox_new(FALSE, 5); |
677 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | 712 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); |
713 gtk_widget_show(hbox); | |
714 | |
715 label = gtk_label_new(_("Protocol:")); | |
716 gtk_size_group_add_widget(ma->sg, label); | |
717 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
718 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
719 | |
720 make_protocol_menu(hbox, ma); | |
721 | |
722 hbox = gtk_hbox_new(FALSE, 5); | |
723 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
724 | |
725 p = find_prpl(ma->protocol); | |
726 if(p) | |
727 user_splits = p->user_splits; | |
678 | 728 |
679 label = gtk_label_new(_("Screenname:")); | 729 label = gtk_label_new(_("Screenname:")); |
680 gtk_size_group_add_widget(ma->sg, label); | 730 gtk_size_group_add_widget(ma->sg, label); |
681 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | 731 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); |
682 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | 732 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
683 | 733 |
684 ma->name = gtk_entry_new(); | 734 ma->name = gtk_entry_new(); |
685 gtk_box_pack_start(GTK_BOX(hbox), ma->name, TRUE, TRUE, 0); | 735 gtk_box_pack_start(GTK_BOX(hbox), ma->name, TRUE, TRUE, 0); |
686 | 736 |
737 if(ma->user_split_entries) { | |
738 g_list_free(ma->user_split_entries); | |
739 ma->user_split_entries = NULL; | |
740 } | |
741 | |
742 while(user_splits) { | |
743 struct proto_user_split *pus = user_splits->data; | |
744 GtkWidget *entry; | |
745 | |
746 hbox = gtk_hbox_new(FALSE, 5); | |
747 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
748 | |
749 label = gtk_label_new(pus->label); | |
750 gtk_size_group_add_widget(ma->sg, label); | |
751 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
752 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
753 user_splits = user_splits->next; | |
754 | |
755 entry = gtk_entry_new(); | |
756 gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); | |
757 | |
758 ma->user_split_entries = g_list_append(ma->user_split_entries, entry); | |
759 } | |
760 | |
687 ma->pwdbox = gtk_hbox_new(FALSE, 5); | 761 ma->pwdbox = gtk_hbox_new(FALSE, 5); |
688 gtk_box_pack_start(GTK_BOX(vbox), ma->pwdbox, FALSE, FALSE, 0); | 762 gtk_box_pack_start(GTK_BOX(vbox), ma->pwdbox, FALSE, FALSE, 0); |
689 | 763 |
690 label = gtk_label_new(_("Password:")); | 764 label = gtk_label_new(_("Password:")); |
691 gtk_size_group_add_widget(ma->sg, label); | 765 gtk_size_group_add_widget(ma->sg, label); |
705 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | 779 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); |
706 | 780 |
707 ma->alias = gtk_entry_new(); | 781 ma->alias = gtk_entry_new(); |
708 gtk_box_pack_start(GTK_BOX(hbox), ma->alias, TRUE, TRUE, 0); | 782 gtk_box_pack_start(GTK_BOX(hbox), ma->alias, TRUE, TRUE, 0); |
709 | 783 |
710 hbox = gtk_hbox_new(FALSE, 5); | |
711 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
712 gtk_widget_show(hbox); | |
713 | |
714 label = gtk_label_new(_("Protocol:")); | |
715 gtk_size_group_add_widget(ma->sg, label); | |
716 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); | |
717 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
718 | |
719 make_protocol_menu(hbox, ma); | |
720 | |
721 ma->rempass = acct_button(_("Remember Password"), ma, OPT_ACCT_REM_PASS, vbox); | 784 ma->rempass = acct_button(_("Remember Password"), ma, OPT_ACCT_REM_PASS, vbox); |
722 acct_button(_("Auto-Login"), ma, OPT_ACCT_AUTO, vbox); | 785 acct_button(_("Auto-Login"), ma, OPT_ACCT_AUTO, vbox); |
723 | 786 |
724 gtk_widget_show_all(frame_parent); | 787 gtk_widget_show_all(ma->login_frame); |
725 | 788 |
726 if (ma->account) { | 789 if(p) |
727 gtk_entry_set_text(GTK_ENTRY(ma->name), ma->account->username); | 790 user_splits = g_list_last(p->user_splits); |
728 gtk_entry_set_text(GTK_ENTRY(ma->alias), ma->account->alias); | 791 |
729 gtk_entry_set_text(GTK_ENTRY(ma->pass), ma->account->password); | 792 username = g_strdup(ma->username); |
730 } | 793 split_entries = g_list_last(ma->user_split_entries); |
731 | 794 |
732 p = find_prpl(ma->protocol); | 795 while(user_splits) { |
796 struct proto_user_split *pus = user_splits->data; | |
797 GtkWidget *entry = split_entries->data; | |
798 start = strrchr(username, pus->sep); | |
799 if(start) { | |
800 *start = '\0'; | |
801 start++; | |
802 gtk_entry_set_text(GTK_ENTRY(entry), start); | |
803 } else { | |
804 gtk_entry_set_text(GTK_ENTRY(entry), pus->def); | |
805 } | |
806 user_splits = user_splits->prev; | |
807 split_entries = split_entries->prev; | |
808 } | |
809 | |
810 gtk_entry_set_text(GTK_ENTRY(ma->name), username); | |
811 gtk_entry_set_text(GTK_ENTRY(ma->alias), ma->show); | |
812 gtk_entry_set_text(GTK_ENTRY(ma->pass), ma->password); | |
813 g_free(username); | |
814 | |
733 if (p && (p->options & OPT_PROTO_NO_PASSWORD)) { | 815 if (p && (p->options & OPT_PROTO_NO_PASSWORD)) { |
734 gtk_widget_hide(ma->pwdbox); | 816 gtk_widget_hide(ma->pwdbox); |
735 gtk_widget_hide(ma->rempass); | 817 gtk_widget_hide(ma->rempass); |
736 } | 818 } |
737 } | 819 } |
749 | 831 |
750 GtkWidget *vbox; | 832 GtkWidget *vbox; |
751 GtkWidget *frame; | 833 GtkWidget *frame; |
752 | 834 |
753 struct prpl *p = find_prpl(ma->protocol); | 835 struct prpl *p = find_prpl(ma->protocol); |
836 | |
837 if(ma->user_frame) | |
838 gtk_widget_destroy(ma->user_frame); | |
839 ma->user_frame = NULL; | |
754 | 840 |
755 frame = make_frame(box, _("User Options")); | 841 frame = make_frame(box, _("User Options")); |
756 ma->user_frame = gtk_widget_get_parent(gtk_widget_get_parent(frame)); | 842 ma->user_frame = gtk_widget_get_parent(gtk_widget_get_parent(frame)); |
757 gtk_widget_show_all(ma->user_frame); | 843 gtk_widget_show_all(ma->user_frame); |
758 | 844 |
1069 else if (protocols) | 1155 else if (protocols) |
1070 ma->protocol = ((struct prpl *)protocols->data)->protocol; | 1156 ma->protocol = ((struct prpl *)protocols->data)->protocol; |
1071 else | 1157 else |
1072 ma->protocol = -1; | 1158 ma->protocol = -1; |
1073 g_snprintf(ma->iconfile, sizeof(ma->iconfile), "%s", a->iconfile); | 1159 g_snprintf(ma->iconfile, sizeof(ma->iconfile), "%s", a->iconfile); |
1160 g_snprintf(ma->username, sizeof(ma->username), "%s", a->username); | |
1161 g_snprintf(ma->show, sizeof(ma->show), "%s", a->alias); | |
1162 g_snprintf(ma->password, sizeof(ma->password), "%s", a->password); | |
1163 | |
1074 for (i = 0; i < 7; i++) | 1164 for (i = 0; i < 7; i++) |
1075 g_snprintf(ma->proto_opt[i], sizeof(ma->proto_opt[i]), "%s", | 1165 g_snprintf(ma->proto_opt[i], sizeof(ma->proto_opt[i]), "%s", |
1076 a->proto_opt[i]); | 1166 a->proto_opt[i]); |
1077 } else { | 1167 } else { |
1078 ma->options = OPT_ACCT_REM_PASS; | 1168 ma->options = OPT_ACCT_REM_PASS; |