comparison src/gtkaccount.c @ 8405:1c4402a2ac71

[gaim-migrate @ 9135] - Deleting an account while modifying it will no longer crash gaim. - Only one account preference window will now appear per account when clicking Modify. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 08 Mar 2004 02:41:50 +0000
parents 19459d9eead2
children f8b8ee06f26c
comparison
equal deleted inserted replaced
8404:3f384e95c5c0 8405:1c4402a2ac71
74 GtkListStore *model; 74 GtkListStore *model;
75 GtkTreeIter drag_iter; 75 GtkTreeIter drag_iter;
76 76
77 GtkTreeViewColumn *screenname_col; 77 GtkTreeViewColumn *screenname_col;
78 78
79 GHashTable *account_pref_wins;
80
79 } AccountsWindow; 81 } AccountsWindow;
80 82
81 typedef struct 83 typedef struct
82 { 84 {
83 GaimGtkAccountDialogType type; 85 GaimGtkAccountDialogType type;
164 * Add/Modify Account dialog 166 * Add/Modify Account dialog
165 **************************************************************************/ 167 **************************************************************************/
166 static void add_login_options(AccountPrefsDialog *dialog, GtkWidget *parent); 168 static void add_login_options(AccountPrefsDialog *dialog, GtkWidget *parent);
167 static void add_user_options(AccountPrefsDialog *dialog, GtkWidget *parent); 169 static void add_user_options(AccountPrefsDialog *dialog, GtkWidget *parent);
168 static void add_protocol_options(AccountPrefsDialog *dialog, 170 static void add_protocol_options(AccountPrefsDialog *dialog,
169 GtkWidget *parent); 171 GtkWidget *parent);
170 static void add_proxy_options(AccountPrefsDialog *dialog, GtkWidget *parent); 172 static void add_proxy_options(AccountPrefsDialog *dialog, GtkWidget *parent);
171 173
172 static GtkWidget * 174 static GtkWidget *
173 add_pref_box(AccountPrefsDialog *dialog, GtkWidget *parent, 175 add_pref_box(AccountPrefsDialog *dialog, GtkWidget *parent,
174 const char *text, GtkWidget *widget) 176 const char *text, GtkWidget *widget)
175 { 177 {
176 GtkWidget *hbox; 178 GtkWidget *hbox;
177 GtkWidget *label; 179 GtkWidget *label;
178 180
179 hbox = gtk_hbox_new(FALSE, 6); 181 hbox = gtk_hbox_new(FALSE, 6);
193 return hbox; 195 return hbox;
194 } 196 }
195 197
196 static void 198 static void
197 set_account_protocol_cb(GtkWidget *item, const char *id, 199 set_account_protocol_cb(GtkWidget *item, const char *id,
198 AccountPrefsDialog *dialog) 200 AccountPrefsDialog *dialog)
199 { 201 {
200 if ((dialog->plugin = gaim_find_prpl(id)) != NULL) { 202 if ((dialog->plugin = gaim_find_prpl(id)) != NULL) {
201 dialog->prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(dialog->plugin); 203 dialog->prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(dialog->plugin);
202 204
203 if (dialog->protocol_id != NULL) 205 if (dialog->protocol_id != NULL)
314 } 316 }
315 317
316 dialog->buddy_icon_filesel = gtk_file_selection_new(_("Buddy Icon")); 318 dialog->buddy_icon_filesel = gtk_file_selection_new(_("Buddy Icon"));
317 dialog->buddy_icon_preview = gtk_image_new(); 319 dialog->buddy_icon_preview = gtk_image_new();
318 dialog->buddy_icon_text = gtk_label_new(NULL); 320 dialog->buddy_icon_text = gtk_label_new(NULL);
321
319 gtk_widget_set_size_request(GTK_WIDGET(dialog->buddy_icon_preview), -1, 50); 322 gtk_widget_set_size_request(GTK_WIDGET(dialog->buddy_icon_preview), -1, 50);
320 hbox = gtk_hbox_new(FALSE, 6); 323 hbox = gtk_hbox_new(FALSE, 6);
321 gtk_box_pack_start(GTK_BOX(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->main_vbox), hbox, 324 gtk_box_pack_start(
322 FALSE, FALSE, 0); 325 GTK_BOX(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->main_vbox),
323 gtk_box_pack_end(GTK_BOX(hbox), dialog->buddy_icon_preview, FALSE, FALSE, 0); 326 hbox, FALSE, FALSE, 0);
327 gtk_box_pack_end(GTK_BOX(hbox), dialog->buddy_icon_preview,
328 FALSE, FALSE, 0);
324 gtk_box_pack_end(GTK_BOX(hbox), dialog->buddy_icon_text, FALSE, FALSE, 0); 329 gtk_box_pack_end(GTK_BOX(hbox), dialog->buddy_icon_text, FALSE, FALSE, 0);
325 330
326 tv = GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->file_list; 331 tv = GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->file_list;
327 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)); 332 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv));
328 g_signal_connect(G_OBJECT(sel), "changed", G_CALLBACK(buddy_icon_preview_change_cb), dialog); 333
329 334 g_signal_connect(G_OBJECT(sel), "changed",
330 g_signal_connect(G_OBJECT(dialog->buddy_icon_filesel), "destroy", G_CALLBACK(buddy_icon_filesel_delete_cb), dialog); 335 G_CALLBACK(buddy_icon_preview_change_cb), dialog);
331 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->cancel_button), "clicked", 336
332 G_CALLBACK(buddy_icon_filesel_delete_cb), dialog); 337 g_signal_connect(G_OBJECT(dialog->buddy_icon_filesel), "destroy",
333 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->ok_button), "clicked", G_CALLBACK(buddy_icon_filesel_choose), 338 G_CALLBACK(buddy_icon_filesel_delete_cb), dialog);
334 dialog); 339 g_signal_connect(
340 G_OBJECT(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->cancel_button),
341 "clicked",
342 G_CALLBACK(buddy_icon_filesel_delete_cb), dialog);
343 g_signal_connect(
344 G_OBJECT(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->ok_button),
345 "clicked",
346 G_CALLBACK(buddy_icon_filesel_choose), dialog);
335 347
336 gtk_widget_show_all(GTK_WIDGET(dialog->buddy_icon_filesel)); 348 gtk_widget_show_all(GTK_WIDGET(dialog->buddy_icon_filesel));
337 if (dialog->account && (gaim_account_get_buddy_icon(dialog->account) != NULL)) { 349
338 gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog->buddy_icon_filesel), 350 if (dialog->account &&
339 gaim_account_get_buddy_icon(dialog->account)); 351 (gaim_account_get_buddy_icon(dialog->account) != NULL))
352 {
353 gtk_file_selection_set_filename(
354 GTK_FILE_SELECTION(dialog->buddy_icon_filesel),
355 gaim_account_get_buddy_icon(dialog->account));
356
340 buddy_icon_preview_change_cb(NULL, dialog); 357 buddy_icon_preview_change_cb(NULL, dialog);
341 } 358 }
342 359
343 } 360 }
344 361
637 if (dialog->protocol_opt_entries != NULL) { 654 if (dialog->protocol_opt_entries != NULL) {
638 g_list_free(dialog->protocol_opt_entries); 655 g_list_free(dialog->protocol_opt_entries);
639 dialog->protocol_opt_entries = NULL; 656 dialog->protocol_opt_entries = NULL;
640 } 657 }
641 658
642 for (l = dialog->prpl_info->protocol_options; l != NULL; l = l->next) { 659 for (l = dialog->prpl_info->protocol_options; l != NULL; l = l->next)
660 {
643 option = (GaimAccountOption *)l->data; 661 option = (GaimAccountOption *)l->data;
644 662
645 switch (gaim_account_option_get_type(option)) { 663 switch (gaim_account_option_get_type(option))
664 {
646 case GAIM_PREF_BOOLEAN: 665 case GAIM_PREF_BOOLEAN:
647 if (account == NULL || strcmp(gaim_account_get_protocol_id(account), dialog->protocol_id)) { 666 if (account == NULL ||
667 strcmp(gaim_account_get_protocol_id(account),
668 dialog->protocol_id))
669 {
648 bool_value = gaim_account_option_get_default_bool(option); 670 bool_value = gaim_account_option_get_default_bool(option);
649 } else { 671 }
672 else
673 {
650 bool_value = gaim_account_get_bool(account, 674 bool_value = gaim_account_get_bool(account,
651 gaim_account_option_get_setting(option), 675 gaim_account_option_get_setting(option),
652 gaim_account_option_get_default_bool(option)); 676 gaim_account_option_get_default_bool(option));
653 } 677 }
654 678
665 g_list_append(dialog->protocol_opt_entries, check); 689 g_list_append(dialog->protocol_opt_entries, check);
666 690
667 break; 691 break;
668 692
669 case GAIM_PREF_INT: 693 case GAIM_PREF_INT:
670 if (account == NULL || strcmp(gaim_account_get_protocol_id(account), dialog->protocol_id)) { 694 if (account == NULL ||
695 strcmp(gaim_account_get_protocol_id(account),
696 dialog->protocol_id))
697 {
671 int_value = gaim_account_option_get_default_int(option); 698 int_value = gaim_account_option_get_default_int(option);
672 } else { 699 }
700 else
701 {
673 int_value = gaim_account_get_int(account, 702 int_value = gaim_account_get_int(account,
674 gaim_account_option_get_setting(option), 703 gaim_account_option_get_setting(option),
675 gaim_account_option_get_default_int(option)); 704 gaim_account_option_get_default_int(option));
676 } 705 }
677 706
691 g_list_append(dialog->protocol_opt_entries, entry); 720 g_list_append(dialog->protocol_opt_entries, entry);
692 721
693 break; 722 break;
694 723
695 case GAIM_PREF_STRING: 724 case GAIM_PREF_STRING:
696 if (account == NULL || strcmp(gaim_account_get_protocol_id(account), dialog->protocol_id)) { 725 if (account == NULL ||
726 strcmp(gaim_account_get_protocol_id(account),
727 dialog->protocol_id))
728 {
697 str_value = gaim_account_option_get_default_string(option); 729 str_value = gaim_account_option_get_default_string(option);
698 } else { 730 }
731 else
732 {
699 str_value = gaim_account_get_string(account, 733 str_value = gaim_account_get_string(account,
700 gaim_account_option_get_setting(option), 734 gaim_account_option_get_setting(option),
701 gaim_account_option_get_default_string(option)); 735 gaim_account_option_get_default_string(option));
702 } 736 }
703 737
916 G_CALLBACK(proxy_type_changed_cb), dialog); 950 G_CALLBACK(proxy_type_changed_cb), dialog);
917 } 951 }
918 952
919 static void 953 static void
920 account_win_destroy_cb(GtkWidget *w, GdkEvent *event, 954 account_win_destroy_cb(GtkWidget *w, GdkEvent *event,
921 AccountPrefsDialog *dialog) 955 AccountPrefsDialog *dialog)
922 { 956 {
957 g_hash_table_remove(accounts_window->account_pref_wins, dialog->account);
958
923 gtk_widget_destroy(dialog->window); 959 gtk_widget_destroy(dialog->window);
924 960
925 if (dialog->user_split_entries != NULL) 961 if (dialog->user_split_entries != NULL)
926 g_list_free(dialog->user_split_entries); 962 g_list_free(dialog->user_split_entries);
927 963
953 char *tmp; 989 char *tmp;
954 size_t index; 990 size_t index;
955 GtkTreeIter iter; 991 GtkTreeIter iter;
956 GaimAccount *ret; 992 GaimAccount *ret;
957 993
958 if (dialog->account == NULL) { 994 if (dialog->account == NULL)
995 {
959 const char *screenname; 996 const char *screenname;
960 997
961 screenname = gtk_entry_get_text(GTK_ENTRY(dialog->screenname_entry)); 998 screenname = gtk_entry_get_text(GTK_ENTRY(dialog->screenname_entry));
962 999
963 dialog->account = gaim_account_new(screenname, dialog->protocol_id); 1000 dialog->account = gaim_account_new(screenname, dialog->protocol_id);
964 } 1001 }
965 else { 1002 else
1003 {
966 /* Protocol */ 1004 /* Protocol */
967 gaim_account_set_protocol_id(dialog->account, dialog->protocol_id); 1005 gaim_account_set_protocol_id(dialog->account, dialog->protocol_id);
968 } 1006 }
969 1007
970 /* Clear the existing settings. */ 1008 /* Clear the existing settings. */
1014 1052
1015 /* Build the username string. */ 1053 /* Build the username string. */
1016 username = 1054 username =
1017 g_strdup(gtk_entry_get_text(GTK_ENTRY(dialog->screenname_entry))); 1055 g_strdup(gtk_entry_get_text(GTK_ENTRY(dialog->screenname_entry)));
1018 1056
1019 if(dialog->prpl_info) { 1057 if (dialog->prpl_info != NULL)
1020 for (l = dialog->prpl_info->user_splits, l2 = dialog->user_split_entries; 1058 {
1021 l != NULL && l2 != NULL; 1059 for (l = dialog->prpl_info->user_splits,
1022 l = l->next, l2 = l2->next) { 1060 l2 = dialog->user_split_entries;
1023 1061 l != NULL && l2 != NULL;
1062 l = l->next, l2 = l2->next)
1063 {
1024 GaimAccountUserSplit *split = l->data; 1064 GaimAccountUserSplit *split = l->data;
1025 GtkEntry *entry = l2->data; 1065 GtkEntry *entry = l2->data;
1026 char sep[2] = " "; 1066 char sep[2] = " ";
1027 1067
1028 value = gtk_entry_get_text(entry); 1068 value = gtk_entry_get_text(entry);
1178 GtkWidget *dbox; 1218 GtkWidget *dbox;
1179 GtkWidget *disclosure; 1219 GtkWidget *disclosure;
1180 GtkWidget *sep; 1220 GtkWidget *sep;
1181 GtkWidget *button; 1221 GtkWidget *button;
1182 1222
1223 if (accounts_window != NULL && account != NULL &&
1224 (dialog = g_hash_table_lookup(accounts_window->account_pref_wins,
1225 account)) != NULL)
1226 {
1227 gtk_window_present(GTK_WINDOW(dialog->window));
1228 return;
1229 }
1230
1183 dialog = g_new0(AccountPrefsDialog, 1); 1231 dialog = g_new0(AccountPrefsDialog, 1);
1232
1233 if (accounts_window != NULL && account != NULL)
1234 {
1235 g_hash_table_insert(accounts_window->account_pref_wins,
1236 account, dialog);
1237 }
1184 1238
1185 dialog->account = account; 1239 dialog->account = account;
1186 dialog->type = type; 1240 dialog->type = type;
1187 dialog->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); 1241 dialog->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1188 1242
1189 if (dialog->account == NULL) { 1243 if (dialog->account == NULL)
1190 dialog->protocol_id = g_strdup(GAIM_PROTO_DEFAULT); 1244 dialog->protocol_id = g_strdup(GAIM_PROTO_DEFAULT);
1191 } 1245 else
1192 else { 1246 {
1193 dialog->protocol_id = 1247 dialog->protocol_id =
1194 g_strdup(gaim_account_get_protocol_id(dialog->account)); 1248 g_strdup(gaim_account_get_protocol_id(dialog->account));
1195 } 1249 }
1196 1250
1197 if ((dialog->plugin = gaim_find_prpl(dialog->protocol_id)) != NULL) 1251 if ((dialog->plugin = gaim_find_prpl(dialog->protocol_id)) != NULL)
1379 } 1433 }
1380 } 1434 }
1381 1435
1382 static void 1436 static void
1383 drag_data_get_cb(GtkWidget *widget, GdkDragContext *ctx, 1437 drag_data_get_cb(GtkWidget *widget, GdkDragContext *ctx,
1384 GtkSelectionData *data, guint info, guint time, 1438 GtkSelectionData *data, guint info, guint time,
1385 AccountsWindow *dialog) 1439 AccountsWindow *dialog)
1386 { 1440 {
1387 if (data->target == gdk_atom_intern("GAIM_ACCOUNT", FALSE)) { 1441 if (data->target == gdk_atom_intern("GAIM_ACCOUNT", FALSE)) {
1388 GtkTreeRowReference *ref; 1442 GtkTreeRowReference *ref;
1389 GtkTreePath *source_row; 1443 GtkTreePath *source_row;
1390 GtkTreeIter iter; 1444 GtkTreeIter iter;
1449 gtk_list_store_remove(store, iter); 1503 gtk_list_store_remove(store, iter);
1450 } 1504 }
1451 1505
1452 static void 1506 static void
1453 drag_data_received_cb(GtkWidget *widget, GdkDragContext *ctx, 1507 drag_data_received_cb(GtkWidget *widget, GdkDragContext *ctx,
1454 guint x, guint y, GtkSelectionData *sd, 1508 guint x, guint y, GtkSelectionData *sd,
1455 guint info, guint t, AccountsWindow *dialog) 1509 guint info, guint t, AccountsWindow *dialog)
1456 { 1510 {
1457 if (sd->target == gdk_atom_intern("GAIM_ACCOUNT", FALSE) && sd->data) { 1511 if (sd->target == gdk_atom_intern("GAIM_ACCOUNT", FALSE) && sd->data) {
1458 size_t dest_index; 1512 size_t dest_index;
1459 GaimAccount *a = NULL; 1513 GaimAccount *a = NULL;
1460 GtkTreePath *path = NULL; 1514 GtkTreePath *path = NULL;
1549 gaim_gtk_account_dialog_show(GAIM_GTK_ADD_ACCOUNT_DIALOG, NULL); 1603 gaim_gtk_account_dialog_show(GAIM_GTK_ADD_ACCOUNT_DIALOG, NULL);
1550 } 1604 }
1551 1605
1552 static void 1606 static void
1553 modify_account_sel(GtkTreeModel *model, GtkTreePath *path, 1607 modify_account_sel(GtkTreeModel *model, GtkTreePath *path,
1554 GtkTreeIter *iter, gpointer data) 1608 GtkTreeIter *iter, gpointer data)
1555 { 1609 {
1556 GaimAccount *account; 1610 GaimAccount *account;
1557 1611
1558 gtk_tree_model_get(model, iter, COLUMN_DATA, &account, -1); 1612 gtk_tree_model_get(model, iter, COLUMN_DATA, &account, -1);
1559 1613
1566 { 1620 {
1567 GtkTreeSelection *selection; 1621 GtkTreeSelection *selection;
1568 1622
1569 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview)); 1623 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->treeview));
1570 1624
1571 gtk_tree_selection_selected_foreach(selection, modify_account_sel, 1625 gtk_tree_selection_selected_foreach(selection, modify_account_sel, dialog);
1572 dialog);
1573 } 1626 }
1574 1627
1575 static void 1628 static void
1576 delete_account_cb(GaimAccount *account) 1629 delete_account_cb(GaimAccount *account)
1577 { 1630 {
1578 size_t index; 1631 size_t index;
1579 GtkTreeIter iter; 1632 GtkTreeIter iter;
1580 1633
1581 index = g_list_index(gaim_accounts_get_all(), account); 1634 index = g_list_index(gaim_accounts_get_all(), account);
1582 1635
1583 if ((accounts_window != NULL) && 1636 if (accounts_window != NULL)
1584 gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(accounts_window->model), 1637 {
1585 &iter, NULL, index)) { 1638 AccountPrefsDialog *dialog;
1586 1639
1587 gtk_list_store_remove(accounts_window->model, &iter); 1640 if (gtk_tree_model_iter_nth_child(
1641 GTK_TREE_MODEL(accounts_window->model), &iter, NULL, index))
1642 {
1643 gtk_list_store_remove(accounts_window->model, &iter);
1644 }
1645
1646 if ((dialog = g_hash_table_lookup(accounts_window->account_pref_wins,
1647 account)) != NULL)
1648 {
1649 account_win_destroy_cb(NULL, NULL, dialog);
1650 }
1588 } 1651 }
1589 1652
1590 gaim_accounts_delete(account); 1653 gaim_accounts_delete(account);
1591 } 1654 }
1592 1655
1593 static void 1656 static void
1594 ask_delete_account_sel(GtkTreeModel *model, GtkTreePath *path, 1657 ask_delete_account_sel(GtkTreeModel *model, GtkTreePath *path,
1595 GtkTreeIter *iter, gpointer data) 1658 GtkTreeIter *iter, gpointer data)
1596 { 1659 {
1597 GaimAccount *account; 1660 GaimAccount *account;
1598 1661
1599 gtk_tree_model_get(model, iter, COLUMN_DATA, &account, -1); 1662 gtk_tree_model_get(model, iter, COLUMN_DATA, &account, -1);
1600 1663
1904 return; 1967 return;
1905 } 1968 }
1906 1969
1907 accounts_window = dialog = g_new0(AccountsWindow, 1); 1970 accounts_window = dialog = g_new0(AccountsWindow, 1);
1908 1971
1972 accounts_window->account_pref_wins =
1973 g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
1974
1909 width = gaim_prefs_get_int("/gaim/gtk/accounts/dialog/width"); 1975 width = gaim_prefs_get_int("/gaim/gtk/accounts/dialog/width");
1910 height = gaim_prefs_get_int("/gaim/gtk/accounts/dialog/height"); 1976 height = gaim_prefs_get_int("/gaim/gtk/accounts/dialog/height");
1911 1977
1912 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL); 1978 dialog->window = win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1913 gtk_window_set_default_size(GTK_WINDOW(win), width, height); 1979 gtk_window_set_default_size(GTK_WINDOW(win), width, height);
1992 { 2058 {
1993 if (accounts_window == NULL) 2059 if (accounts_window == NULL)
1994 return; 2060 return;
1995 2061
1996 gaim_signals_disconnect_by_handle(accounts_window); 2062 gaim_signals_disconnect_by_handle(accounts_window);
2063
2064 g_hash_table_destroy(accounts_window->account_pref_wins);
1997 2065
1998 g_free(accounts_window); 2066 g_free(accounts_window);
1999 accounts_window = NULL; 2067 accounts_window = NULL;
2000 2068
2001 /* See if we're the main window here. */ 2069 /* See if we're the main window here. */