root / src / account_dialog.c @ 730
History | View | Annotate | Download (21.3 kB)
| 1 | /*
|
|---|---|
| 2 | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 | * Copyright (C) 1999-2005 Hiroyuki Yamamoto |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
| 20 | #ifdef HAVE_CONFIG_H
|
| 21 | # include "config.h" |
| 22 | #endif
|
| 23 | |
| 24 | #include "defs.h" |
| 25 | |
| 26 | #include <glib.h> |
| 27 | #include <glib/gi18n.h> |
| 28 | #include <gtk/gtk.h> |
| 29 | #include <gdk/gdkkeysyms.h> |
| 30 | #include <stdio.h> |
| 31 | #include <errno.h> |
| 32 | |
| 33 | #include "main.h" |
| 34 | #include "mainwindow.h" |
| 35 | #include "folderview.h" |
| 36 | #include "folder.h" |
| 37 | #include "account.h" |
| 38 | #include "prefs.h" |
| 39 | #include "prefs_account.h" |
| 40 | #include "prefs_account_dialog.h" |
| 41 | #include "procmsg.h" |
| 42 | #include "procheader.h" |
| 43 | #include "compose.h" |
| 44 | #include "manage_window.h" |
| 45 | #include "stock_pixmap.h" |
| 46 | #include "statusbar.h" |
| 47 | #include "inc.h" |
| 48 | #include "gtkutils.h" |
| 49 | #include "utils.h" |
| 50 | #include "alertpanel.h" |
| 51 | |
| 52 | enum
|
| 53 | {
|
| 54 | COL_DEFAULT, |
| 55 | COL_GETALL, |
| 56 | COL_NAME, |
| 57 | COL_PROTOCOL, |
| 58 | COL_SERVER, |
| 59 | COL_ACCOUNT, |
| 60 | COL_CAN_GETALL, |
| 61 | N_COLS |
| 62 | }; |
| 63 | |
| 64 | #define PREFSBUFSIZE 1024 |
| 65 | |
| 66 | static struct EditAccount { |
| 67 | GtkWidget *window; |
| 68 | |
| 69 | GtkWidget *treeview; |
| 70 | GtkListStore *store; |
| 71 | GtkTreeSelection *selection; |
| 72 | |
| 73 | GtkWidget *close_btn; |
| 74 | } edit_account; |
| 75 | |
| 76 | static void account_edit_create (void); |
| 77 | |
| 78 | static void account_edit_prefs (void); |
| 79 | static void account_delete (void); |
| 80 | |
| 81 | static void account_up (void); |
| 82 | static void account_down (void); |
| 83 | |
| 84 | static void account_set_default (void); |
| 85 | |
| 86 | static void account_edit_close (void); |
| 87 | |
| 88 | static gboolean account_selected (GtkTreeSelection *selection,
|
| 89 | GtkTreeModel *model, |
| 90 | GtkTreePath *path, |
| 91 | gboolean cur_selected, |
| 92 | gpointer data); |
| 93 | |
| 94 | static void account_default_toggled (GtkCellRenderer *cell, |
| 95 | gchar *path, |
| 96 | gpointer data); |
| 97 | static void account_getall_toggled (GtkCellRenderer *cell, |
| 98 | gchar *path, |
| 99 | gpointer data); |
| 100 | |
| 101 | static void account_row_activated (GtkTreeView *treeview, |
| 102 | GtkTreePath *path, |
| 103 | GtkTreeViewColumn *column, |
| 104 | gpointer data); |
| 105 | static void account_row_reordered (GtkTreeModel *model, |
| 106 | GtkTreePath *path, |
| 107 | GtkTreeIter *iter, |
| 108 | gpointer data); |
| 109 | |
| 110 | static gint account_delete_event (GtkWidget *widget,
|
| 111 | GdkEventAny *event, |
| 112 | gpointer data); |
| 113 | static gboolean account_key_pressed (GtkWidget *widget,
|
| 114 | GdkEventKey *event, |
| 115 | gpointer data); |
| 116 | |
| 117 | static void account_set_row (PrefsAccount *ac_prefs, |
| 118 | GtkTreeIter *iter, |
| 119 | GtkTreeIter *new, |
| 120 | gboolean move_view); |
| 121 | static void account_set_dialog (void); |
| 122 | static void account_update_dialog (void); |
| 123 | |
| 124 | static void account_set_list (void); |
| 125 | |
| 126 | |
| 127 | void account_set_menu(void) |
| 128 | {
|
| 129 | main_window_set_account_menu(account_get_list()); |
| 130 | } |
| 131 | |
| 132 | void account_edit_open(void) |
| 133 | {
|
| 134 | inc_lock(); |
| 135 | |
| 136 | if (compose_get_compose_list()) {
|
| 137 | alertpanel_notice(_("Some composing windows are open.\n"
|
| 138 | "Please close all the composing windows before editing the accounts."));
|
| 139 | inc_unlock(); |
| 140 | return;
|
| 141 | } |
| 142 | |
| 143 | debug_print(_("Opening account edit window...\n"));
|
| 144 | |
| 145 | if (!edit_account.window)
|
| 146 | account_edit_create(); |
| 147 | |
| 148 | account_set_dialog(); |
| 149 | |
| 150 | manage_window_set_transient(GTK_WINDOW(edit_account.window)); |
| 151 | gtk_widget_grab_focus(edit_account.close_btn); |
| 152 | gtk_widget_show(edit_account.window); |
| 153 | |
| 154 | manage_window_focus_in(edit_account.window, NULL, NULL); |
| 155 | } |
| 156 | |
| 157 | void account_add(void) |
| 158 | {
|
| 159 | PrefsAccount *ac_prefs; |
| 160 | |
| 161 | ac_prefs = prefs_account_open(NULL);
|
| 162 | gtk_window_present(GTK_WINDOW(edit_account.window)); |
| 163 | |
| 164 | if (!ac_prefs) return; |
| 165 | |
| 166 | account_append(ac_prefs); |
| 167 | |
| 168 | if (ac_prefs->is_default)
|
| 169 | account_set_as_default(ac_prefs); |
| 170 | |
| 171 | account_set_row(ac_prefs, NULL, NULL, TRUE); |
| 172 | |
| 173 | if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
|
| 174 | Folder *folder; |
| 175 | |
| 176 | if (ac_prefs->protocol == A_IMAP4) {
|
| 177 | folder = folder_new(F_IMAP, ac_prefs->account_name, |
| 178 | ac_prefs->recv_server); |
| 179 | } else {
|
| 180 | folder = folder_new(F_NEWS, ac_prefs->account_name, |
| 181 | ac_prefs->nntp_server); |
| 182 | } |
| 183 | |
| 184 | folder->account = ac_prefs; |
| 185 | ac_prefs->folder = REMOTE_FOLDER(folder); |
| 186 | folder_add(folder); |
| 187 | if (ac_prefs->protocol == A_IMAP4) {
|
| 188 | if (main_window_toggle_online_if_offline
|
| 189 | (main_window_get())) {
|
| 190 | folder->klass->create_tree(folder); |
| 191 | statusbar_pop_all(); |
| 192 | } |
| 193 | } |
| 194 | folderview_set_all(); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | void account_open(PrefsAccount *ac_prefs)
|
| 199 | {
|
| 200 | gboolean prev_default; |
| 201 | gchar *ac_name; |
| 202 | |
| 203 | g_return_if_fail(ac_prefs != NULL);
|
| 204 | |
| 205 | prev_default = ac_prefs->is_default; |
| 206 | Xstrdup_a(ac_name, ac_prefs->account_name ? ac_prefs->account_name : "",
|
| 207 | return);
|
| 208 | |
| 209 | prefs_account_open(ac_prefs); |
| 210 | gtk_window_present(GTK_WINDOW(edit_account.window)); |
| 211 | |
| 212 | if (!prev_default && ac_prefs->is_default)
|
| 213 | account_set_as_default(ac_prefs); |
| 214 | |
| 215 | if (ac_prefs->folder && strcmp2(ac_name, ac_prefs->account_name) != 0) { |
| 216 | folder_set_name(FOLDER(ac_prefs->folder), |
| 217 | ac_prefs->account_name); |
| 218 | folderview_set_all(); |
| 219 | } |
| 220 | |
| 221 | account_write_config_all(); |
| 222 | account_set_menu(); |
| 223 | main_window_reflect_prefs_all(); |
| 224 | } |
| 225 | |
| 226 | void account_set_missing_folder(void) |
| 227 | {
|
| 228 | PrefsAccount *ap; |
| 229 | GList *cur; |
| 230 | |
| 231 | for (cur = account_get_list(); cur != NULL; cur = cur->next) { |
| 232 | ap = (PrefsAccount *)cur->data; |
| 233 | if ((ap->protocol == A_IMAP4 || ap->protocol == A_NNTP) &&
|
| 234 | !ap->folder) {
|
| 235 | Folder *folder; |
| 236 | |
| 237 | if (ap->protocol == A_IMAP4) {
|
| 238 | folder = folder_new(F_IMAP, ap->account_name, |
| 239 | ap->recv_server); |
| 240 | } else {
|
| 241 | folder = folder_new(F_NEWS, ap->account_name, |
| 242 | ap->nntp_server); |
| 243 | } |
| 244 | |
| 245 | folder->account = ap; |
| 246 | ap->folder = REMOTE_FOLDER(folder); |
| 247 | folder_add(folder); |
| 248 | if (ap->protocol == A_IMAP4) {
|
| 249 | if (main_window_toggle_online_if_offline
|
| 250 | (main_window_get())) {
|
| 251 | folder->klass->create_tree(folder); |
| 252 | statusbar_pop_all(); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | static void account_edit_create(void) |
| 260 | {
|
| 261 | GtkWidget *window; |
| 262 | GtkWidget *vbox; |
| 263 | GtkWidget *label; |
| 264 | GtkWidget *hbox; |
| 265 | GtkWidget *scrolledwin; |
| 266 | GtkWidget *treeview; |
| 267 | GtkListStore *store; |
| 268 | GtkTreeSelection *selection; |
| 269 | GtkTreeViewColumn *column; |
| 270 | GtkCellRenderer *renderer; |
| 271 | |
| 272 | GtkWidget *vbox2; |
| 273 | GtkWidget *add_btn; |
| 274 | GtkWidget *edit_btn; |
| 275 | GtkWidget *del_btn; |
| 276 | GtkWidget *up_btn; |
| 277 | GtkWidget *down_btn; |
| 278 | |
| 279 | GtkWidget *default_btn; |
| 280 | |
| 281 | GtkWidget *hbbox; |
| 282 | GtkWidget *close_btn; |
| 283 | |
| 284 | debug_print(_("Creating account edit window...\n"));
|
| 285 | |
| 286 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); |
| 287 | gtk_widget_set_size_request (window, 500, 320); |
| 288 | gtk_container_set_border_width (GTK_CONTAINER (window), 8);
|
| 289 | gtk_window_set_title (GTK_WINDOW (window), _("Edit accounts"));
|
| 290 | gtk_window_set_modal (GTK_WINDOW (window), TRUE); |
| 291 | g_signal_connect (G_OBJECT (window), "delete_event",
|
| 292 | G_CALLBACK (account_delete_event), NULL);
|
| 293 | g_signal_connect (G_OBJECT (window), "key_press_event",
|
| 294 | G_CALLBACK (account_key_pressed), NULL);
|
| 295 | MANAGE_WINDOW_SIGNALS_CONNECT (window); |
| 296 | gtk_widget_realize(window); |
| 297 | |
| 298 | vbox = gtk_vbox_new (FALSE, 10);
|
| 299 | gtk_widget_show (vbox); |
| 300 | gtk_container_add (GTK_CONTAINER (window), vbox); |
| 301 | |
| 302 | hbox = gtk_hbox_new (FALSE, 0);
|
| 303 | gtk_widget_show (hbox); |
| 304 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
| 305 | |
| 306 | label = gtk_label_new |
| 307 | (_("New messages will be checked in this order. Check the boxes\n"
|
| 308 | "on the `G' column to enable message retrieval by `Get all'."));
|
| 309 | gtk_widget_show (label); |
| 310 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
|
| 311 | gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); |
| 312 | |
| 313 | hbox = gtk_hbox_new (FALSE, 8);
|
| 314 | gtk_widget_show (hbox); |
| 315 | gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
|
| 316 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
|
| 317 | |
| 318 | scrolledwin = gtk_scrolled_window_new(NULL, NULL); |
| 319 | gtk_widget_show(scrolledwin); |
| 320 | gtk_box_pack_start(GTK_BOX(hbox), scrolledwin, TRUE, TRUE, 0);
|
| 321 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), |
| 322 | GTK_POLICY_AUTOMATIC, |
| 323 | GTK_POLICY_AUTOMATIC); |
| 324 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin), |
| 325 | GTK_SHADOW_IN); |
| 326 | |
| 327 | store = gtk_list_store_new |
| 328 | (N_COLS, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING, |
| 329 | G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN); |
| 330 | |
| 331 | treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
| 332 | g_object_unref(G_OBJECT(store)); |
| 333 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE); |
| 334 | gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); |
| 335 | gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview), COL_NAME); |
| 336 | gtk_tree_view_set_reorderable(GTK_TREE_VIEW(treeview), TRUE); |
| 337 | |
| 338 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); |
| 339 | gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); |
| 340 | gtk_tree_selection_set_select_function(selection, account_selected, |
| 341 | NULL, NULL); |
| 342 | |
| 343 | renderer = gtk_cell_renderer_toggle_new(); |
| 344 | gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(renderer), |
| 345 | TRUE); |
| 346 | g_signal_connect(renderer, "toggled",
|
| 347 | G_CALLBACK(account_default_toggled), NULL);
|
| 348 | column = gtk_tree_view_column_new_with_attributes |
| 349 | ("D", renderer, "active", COL_DEFAULT, NULL); |
| 350 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); |
| 351 | |
| 352 | renderer = gtk_cell_renderer_toggle_new(); |
| 353 | g_signal_connect(renderer, "toggled",
|
| 354 | G_CALLBACK(account_getall_toggled), NULL);
|
| 355 | column = gtk_tree_view_column_new_with_attributes |
| 356 | ("G", renderer, "active", COL_GETALL, "visible", COL_CAN_GETALL, |
| 357 | NULL);
|
| 358 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); |
| 359 | |
| 360 | renderer = gtk_cell_renderer_text_new(); |
| 361 | column = gtk_tree_view_column_new_with_attributes |
| 362 | (_("Name"), renderer, "text", COL_NAME, NULL); |
| 363 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); |
| 364 | |
| 365 | renderer = gtk_cell_renderer_text_new(); |
| 366 | column = gtk_tree_view_column_new_with_attributes |
| 367 | (_("Protocol"), renderer, "text", COL_PROTOCOL, NULL); |
| 368 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); |
| 369 | |
| 370 | renderer = gtk_cell_renderer_text_new(); |
| 371 | column = gtk_tree_view_column_new_with_attributes |
| 372 | (_("Server"), renderer, "text", COL_SERVER, NULL); |
| 373 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); |
| 374 | |
| 375 | gtk_widget_show(treeview); |
| 376 | gtk_container_add(GTK_CONTAINER(scrolledwin), treeview); |
| 377 | |
| 378 | g_signal_connect(G_OBJECT(treeview), "row-activated",
|
| 379 | G_CALLBACK(account_row_activated), NULL);
|
| 380 | g_signal_connect_after(G_OBJECT(store), "rows-reordered",
|
| 381 | G_CALLBACK(account_row_reordered), NULL);
|
| 382 | |
| 383 | vbox2 = gtk_vbox_new (FALSE, 0);
|
| 384 | gtk_widget_show (vbox2); |
| 385 | gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
|
| 386 | |
| 387 | add_btn = gtk_button_new_from_stock (GTK_STOCK_ADD); |
| 388 | gtk_widget_show (add_btn); |
| 389 | gtk_box_pack_start (GTK_BOX (vbox2), add_btn, FALSE, FALSE, 4);
|
| 390 | g_signal_connect (G_OBJECT(add_btn), "clicked",
|
| 391 | G_CALLBACK (account_add), NULL);
|
| 392 | |
| 393 | #ifdef GTK_STOCK_EDIT
|
| 394 | edit_btn = gtk_button_new_from_stock (GTK_STOCK_EDIT); |
| 395 | #else
|
| 396 | edit_btn = gtk_button_new_with_label (_("Edit"));
|
| 397 | #endif
|
| 398 | gtk_widget_show (edit_btn); |
| 399 | gtk_box_pack_start (GTK_BOX (vbox2), edit_btn, FALSE, FALSE, 4);
|
| 400 | g_signal_connect (G_OBJECT(edit_btn), "clicked",
|
| 401 | G_CALLBACK (account_edit_prefs), NULL);
|
| 402 | |
| 403 | del_btn = gtk_button_new_from_stock (GTK_STOCK_DELETE); |
| 404 | gtk_widget_show (del_btn); |
| 405 | gtk_box_pack_start (GTK_BOX (vbox2), del_btn, FALSE, FALSE, 4);
|
| 406 | g_signal_connect (G_OBJECT(del_btn), "clicked",
|
| 407 | G_CALLBACK (account_delete), NULL);
|
| 408 | |
| 409 | down_btn = gtk_button_new_from_stock (GTK_STOCK_GO_DOWN); |
| 410 | gtk_widget_show (down_btn); |
| 411 | gtk_box_pack_end (GTK_BOX (vbox2), down_btn, FALSE, FALSE, 4);
|
| 412 | g_signal_connect (G_OBJECT(down_btn), "clicked",
|
| 413 | G_CALLBACK (account_down), NULL);
|
| 414 | |
| 415 | up_btn = gtk_button_new_from_stock (GTK_STOCK_GO_UP); |
| 416 | gtk_widget_show (up_btn); |
| 417 | gtk_box_pack_end (GTK_BOX (vbox2), up_btn, FALSE, FALSE, 4);
|
| 418 | g_signal_connect (G_OBJECT(up_btn), "clicked",
|
| 419 | G_CALLBACK (account_up), NULL);
|
| 420 | |
| 421 | hbox = gtk_hbox_new (FALSE, 8);
|
| 422 | gtk_widget_show (hbox); |
| 423 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
| 424 | |
| 425 | vbox2 = gtk_vbox_new(FALSE, 0);
|
| 426 | gtk_widget_show (vbox2); |
| 427 | gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
|
| 428 | |
| 429 | default_btn = gtk_button_new_with_mnemonic |
| 430 | (_(" _Set as default account "));
|
| 431 | gtk_widget_show (default_btn); |
| 432 | gtk_box_pack_start (GTK_BOX (vbox2), default_btn, TRUE, FALSE, 0);
|
| 433 | g_signal_connect (G_OBJECT(default_btn), "clicked",
|
| 434 | G_CALLBACK (account_set_default), NULL);
|
| 435 | |
| 436 | gtkut_stock_button_set_create(&hbbox, &close_btn, GTK_STOCK_CLOSE, |
| 437 | NULL, NULL, NULL, NULL); |
| 438 | gtk_widget_show(hbbox); |
| 439 | gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
|
| 440 | gtk_widget_grab_default (close_btn); |
| 441 | |
| 442 | g_signal_connect (G_OBJECT (close_btn), "clicked",
|
| 443 | G_CALLBACK (account_edit_close), NULL);
|
| 444 | |
| 445 | edit_account.window = window; |
| 446 | edit_account.treeview = treeview; |
| 447 | edit_account.store = store; |
| 448 | edit_account.selection = selection; |
| 449 | edit_account.close_btn = close_btn; |
| 450 | } |
| 451 | |
| 452 | static void account_edit_prefs(void) |
| 453 | {
|
| 454 | GtkTreeIter iter; |
| 455 | PrefsAccount *ac_prefs; |
| 456 | |
| 457 | if (!gtk_tree_selection_get_selected(edit_account.selection,
|
| 458 | NULL, &iter))
|
| 459 | return;
|
| 460 | |
| 461 | gtk_tree_model_get(GTK_TREE_MODEL(edit_account.store), &iter, |
| 462 | COL_ACCOUNT, &ac_prefs, -1);
|
| 463 | account_open(ac_prefs); |
| 464 | |
| 465 | account_set_row(ac_prefs, &iter, NULL, FALSE);
|
| 466 | } |
| 467 | |
| 468 | static void account_delete(void) |
| 469 | {
|
| 470 | GtkTreeIter iter; |
| 471 | PrefsAccount *ac_prefs; |
| 472 | gchar buf[BUFFSIZE]; |
| 473 | |
| 474 | if (!gtk_tree_selection_get_selected(edit_account.selection,
|
| 475 | NULL, &iter))
|
| 476 | return;
|
| 477 | |
| 478 | gtk_tree_model_get(GTK_TREE_MODEL(edit_account.store), &iter, |
| 479 | COL_ACCOUNT, &ac_prefs, -1);
|
| 480 | g_return_if_fail(ac_prefs != NULL);
|
| 481 | |
| 482 | g_snprintf(buf, sizeof(buf),
|
| 483 | _("Do you really want to delete the account '%s'?"),
|
| 484 | ac_prefs->account_name ? ac_prefs->account_name : |
| 485 | _("(Untitled)"));
|
| 486 | if (alertpanel_full(_("Delete account"), buf, |
| 487 | ALERT_QUESTION, G_ALERTALTERNATE, FALSE, |
| 488 | GTK_STOCK_YES, GTK_STOCK_NO, NULL)
|
| 489 | != G_ALERTDEFAULT) |
| 490 | return;
|
| 491 | |
| 492 | if (ac_prefs->folder) {
|
| 493 | FolderItem *item; |
| 494 | |
| 495 | item = main_window_get()->summaryview->folder_item; |
| 496 | if (item && item->folder == FOLDER(ac_prefs->folder))
|
| 497 | summary_clear_all(main_window_get()->summaryview); |
| 498 | folder_destroy(FOLDER(ac_prefs->folder)); |
| 499 | folderview_set_all(); |
| 500 | } |
| 501 | |
| 502 | account_destroy(ac_prefs); |
| 503 | gtk_list_store_remove(edit_account.store, &iter); |
| 504 | account_update_dialog(); |
| 505 | } |
| 506 | |
| 507 | static void account_up(void) |
| 508 | {
|
| 509 | GtkTreeModel *model = GTK_TREE_MODEL(edit_account.store); |
| 510 | GtkTreeIter iter, prev; |
| 511 | GtkTreePath *path; |
| 512 | |
| 513 | if (!gtk_tree_selection_get_selected(edit_account.selection,
|
| 514 | NULL, &iter))
|
| 515 | return;
|
| 516 | |
| 517 | path = gtk_tree_model_get_path(model, &iter); |
| 518 | if (gtk_tree_path_prev(path)) {
|
| 519 | gtk_tree_model_get_iter(model, &prev, path); |
| 520 | gtk_list_store_swap(edit_account.store, &iter, &prev); |
| 521 | } |
| 522 | gtk_tree_path_free(path); |
| 523 | } |
| 524 | |
| 525 | static void account_down(void) |
| 526 | {
|
| 527 | GtkTreeIter iter, next; |
| 528 | |
| 529 | if (!gtk_tree_selection_get_selected(edit_account.selection,
|
| 530 | NULL, &iter))
|
| 531 | return;
|
| 532 | |
| 533 | next = iter; |
| 534 | if (gtk_tree_model_iter_next(GTK_TREE_MODEL(edit_account.store),
|
| 535 | &next)) |
| 536 | gtk_list_store_swap(edit_account.store, &iter, &next); |
| 537 | } |
| 538 | |
| 539 | static void account_set_default(void) |
| 540 | {
|
| 541 | GtkTreeIter iter; |
| 542 | PrefsAccount *ac_prefs; |
| 543 | |
| 544 | if (!gtk_tree_selection_get_selected(edit_account.selection,
|
| 545 | NULL, &iter))
|
| 546 | return;
|
| 547 | |
| 548 | gtk_tree_model_get(GTK_TREE_MODEL(edit_account.store), &iter, |
| 549 | COL_ACCOUNT, &ac_prefs, -1);
|
| 550 | g_return_if_fail(ac_prefs != NULL);
|
| 551 | |
| 552 | account_set_as_default(ac_prefs); |
| 553 | account_update_dialog(); |
| 554 | |
| 555 | cur_account = ac_prefs; |
| 556 | account_set_menu(); |
| 557 | main_window_reflect_prefs_all(); |
| 558 | } |
| 559 | |
| 560 | static void account_edit_close(void) |
| 561 | {
|
| 562 | GList *account_list; |
| 563 | |
| 564 | account_set_list(); |
| 565 | account_write_config_all(); |
| 566 | |
| 567 | account_list = account_get_list(); |
| 568 | |
| 569 | if (!cur_account && account_list) {
|
| 570 | PrefsAccount *ac_prefs = (PrefsAccount *)account_list->data; |
| 571 | account_set_as_default(ac_prefs); |
| 572 | cur_account = ac_prefs; |
| 573 | } |
| 574 | |
| 575 | account_set_menu(); |
| 576 | main_window_reflect_prefs_all(); |
| 577 | |
| 578 | gtk_widget_hide(edit_account.window); |
| 579 | main_window_popup(main_window_get()); |
| 580 | |
| 581 | inc_unlock(); |
| 582 | } |
| 583 | |
| 584 | static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
|
| 585 | gpointer data) |
| 586 | {
|
| 587 | account_edit_close(); |
| 588 | return TRUE;
|
| 589 | } |
| 590 | |
| 591 | static gboolean account_selected(GtkTreeSelection *selection,
|
| 592 | GtkTreeModel *model, GtkTreePath *path, |
| 593 | gboolean cur_selected, gpointer data) |
| 594 | {
|
| 595 | return TRUE;
|
| 596 | } |
| 597 | |
| 598 | static void account_default_toggled(GtkCellRenderer *cell, gchar *path_str, |
| 599 | gpointer data) |
| 600 | {
|
| 601 | GtkTreeIter iter; |
| 602 | PrefsAccount *ac; |
| 603 | GtkTreePath *path; |
| 604 | |
| 605 | path = gtk_tree_path_new_from_string(path_str); |
| 606 | gtk_tree_model_get_iter(GTK_TREE_MODEL(edit_account.store), |
| 607 | &iter, path); |
| 608 | gtk_tree_path_free(path); |
| 609 | gtk_tree_model_get(GTK_TREE_MODEL(edit_account.store), &iter, |
| 610 | COL_ACCOUNT, &ac, -1);
|
| 611 | |
| 612 | account_set_as_default(ac); |
| 613 | account_update_dialog(); |
| 614 | } |
| 615 | |
| 616 | static void account_getall_toggled(GtkCellRenderer *cell, gchar *path_str, |
| 617 | gpointer data) |
| 618 | {
|
| 619 | GtkTreeIter iter; |
| 620 | PrefsAccount *ac; |
| 621 | GtkTreePath *path; |
| 622 | gboolean can_getall; |
| 623 | |
| 624 | path = gtk_tree_path_new_from_string(path_str); |
| 625 | gtk_tree_model_get_iter(GTK_TREE_MODEL(edit_account.store), |
| 626 | &iter, path); |
| 627 | gtk_tree_path_free(path); |
| 628 | gtk_tree_model_get(GTK_TREE_MODEL(edit_account.store), &iter, |
| 629 | COL_ACCOUNT, &ac, COL_CAN_GETALL, &can_getall, -1);
|
| 630 | |
| 631 | if (can_getall) {
|
| 632 | ac->recv_at_getall ^= TRUE; |
| 633 | account_set_row(ac, &iter, NULL, FALSE);
|
| 634 | } |
| 635 | } |
| 636 | |
| 637 | static void account_row_activated(GtkTreeView *treeview, GtkTreePath *path, |
| 638 | GtkTreeViewColumn *column, gpointer data) |
| 639 | {
|
| 640 | account_edit_prefs(); |
| 641 | } |
| 642 | |
| 643 | static void account_row_reordered (GtkTreeModel *model, |
| 644 | GtkTreePath *path, |
| 645 | GtkTreeIter *iter, |
| 646 | gpointer data) |
| 647 | {
|
| 648 | GtkTreeIter iter_; |
| 649 | GtkTreePath *path_; |
| 650 | |
| 651 | if (!gtk_tree_selection_get_selected(edit_account.selection,
|
| 652 | NULL, &iter_))
|
| 653 | return;
|
| 654 | path_ = gtk_tree_model_get_path |
| 655 | (GTK_TREE_MODEL(edit_account.store), &iter_); |
| 656 | gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(edit_account.treeview), |
| 657 | path_, NULL, FALSE, 0.0, 0.0); |
| 658 | gtk_tree_path_free(path_); |
| 659 | } |
| 660 | |
| 661 | static gboolean account_key_pressed(GtkWidget *widget, GdkEventKey *event,
|
| 662 | gpointer data) |
| 663 | {
|
| 664 | if (event && event->keyval == GDK_Escape)
|
| 665 | account_edit_close(); |
| 666 | return FALSE;
|
| 667 | } |
| 668 | |
| 669 | static void account_set_row(PrefsAccount *ac_prefs, GtkTreeIter *iter, |
| 670 | GtkTreeIter *new, gboolean move_view) |
| 671 | {
|
| 672 | GtkListStore *store = edit_account.store; |
| 673 | GtkTreeIter iter_; |
| 674 | const gchar *protocol, *server;
|
| 675 | gboolean has_getall; |
| 676 | |
| 677 | g_return_if_fail(ac_prefs != NULL);
|
| 678 | |
| 679 | #if USE_SSL
|
| 680 | protocol = ac_prefs->protocol == A_POP3 ? |
| 681 | (ac_prefs->ssl_pop == SSL_TUNNEL ? |
| 682 | "POP3 (SSL)" :
|
| 683 | ac_prefs->ssl_pop == SSL_STARTTLS ? |
| 684 | "POP3 (TLS)" : "POP3") : |
| 685 | ac_prefs->protocol == A_IMAP4 ? |
| 686 | (ac_prefs->ssl_imap == SSL_TUNNEL ? |
| 687 | "IMAP4 (SSL)" :
|
| 688 | ac_prefs->ssl_imap == SSL_STARTTLS ? |
| 689 | "IMAP4 (TLS)" : "IMAP4") : |
| 690 | ac_prefs->protocol == A_NNTP ? |
| 691 | (ac_prefs->ssl_nntp == SSL_TUNNEL ? |
| 692 | "NNTP (SSL)" : "NNTP") : |
| 693 | "";
|
| 694 | #else
|
| 695 | protocol = ac_prefs->protocol == A_POP3 ? "POP3" :
|
| 696 | ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
|
| 697 | ac_prefs->protocol == A_NNTP ? "NNTP" : ""; |
| 698 | #endif
|
| 699 | server = ac_prefs->protocol == A_NNTP ? |
| 700 | ac_prefs->nntp_server : ac_prefs->recv_server; |
| 701 | |
| 702 | has_getall = (ac_prefs->protocol == A_POP3 || |
| 703 | ac_prefs->protocol == A_IMAP4 || |
| 704 | ac_prefs->protocol == A_NNTP); |
| 705 | |
| 706 | if (!iter)
|
| 707 | gtk_list_store_append(store, &iter_); |
| 708 | else
|
| 709 | iter_ = *iter; |
| 710 | |
| 711 | gtk_list_store_set(store, &iter_, |
| 712 | COL_DEFAULT, ac_prefs->is_default, |
| 713 | COL_GETALL, has_getall && ac_prefs->recv_at_getall, |
| 714 | COL_NAME, ac_prefs->account_name, |
| 715 | COL_PROTOCOL, protocol, |
| 716 | COL_SERVER, server, |
| 717 | COL_ACCOUNT, ac_prefs, |
| 718 | COL_CAN_GETALL, has_getall, |
| 719 | -1);
|
| 720 | |
| 721 | if (new)
|
| 722 | *new = iter_; |
| 723 | |
| 724 | if (move_view) {
|
| 725 | GtkTreePath *path; |
| 726 | |
| 727 | path = gtk_tree_model_get_path |
| 728 | (GTK_TREE_MODEL(edit_account.store), &iter_); |
| 729 | gtk_tree_view_scroll_to_cell |
| 730 | (GTK_TREE_VIEW(edit_account.treeview), |
| 731 | path, NULL, TRUE, 0.5, 0.0); |
| 732 | gtk_tree_path_free(path); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | /* set dialog from account list */
|
| 737 | static void account_set_dialog(void) |
| 738 | {
|
| 739 | GList *cur; |
| 740 | GtkTreeIter iter; |
| 741 | GtkTreePath *path; |
| 742 | |
| 743 | gtk_list_store_clear(edit_account.store); |
| 744 | |
| 745 | for (cur = account_get_list(); cur != NULL; cur = cur->next) { |
| 746 | account_set_row((PrefsAccount *)cur->data, NULL, &iter, FALSE);
|
| 747 | if ((PrefsAccount *)cur->data == cur_account) {
|
| 748 | gtk_tree_selection_select_iter(edit_account.selection, |
| 749 | &iter); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | if (!gtk_tree_selection_get_selected(edit_account.selection, NULL, |
| 754 | &iter)) |
| 755 | return;
|
| 756 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(edit_account.store), |
| 757 | &iter); |
| 758 | gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(edit_account.treeview), |
| 759 | path, NULL, FALSE, 0.0, 0.0); |
| 760 | gtk_tree_path_free(path); |
| 761 | } |
| 762 | |
| 763 | /* update dialog to the latest state */
|
| 764 | static void account_update_dialog(void) |
| 765 | {
|
| 766 | GtkTreeIter iter; |
| 767 | GtkTreeModel *model = GTK_TREE_MODEL(edit_account.store); |
| 768 | PrefsAccount *ac; |
| 769 | |
| 770 | if (!gtk_tree_model_get_iter_first(model, &iter))
|
| 771 | return;
|
| 772 | |
| 773 | do {
|
| 774 | gtk_tree_model_get(model, &iter, COL_ACCOUNT, &ac, -1);
|
| 775 | if (ac)
|
| 776 | account_set_row(ac, &iter, NULL, FALSE);
|
| 777 | } while (gtk_tree_model_iter_next(model, &iter));
|
| 778 | } |
| 779 | |
| 780 | /* set account list from dialog */
|
| 781 | static void account_set_list(void) |
| 782 | {
|
| 783 | GtkTreeIter iter; |
| 784 | GtkTreeModel *model = GTK_TREE_MODEL(edit_account.store); |
| 785 | PrefsAccount *ac; |
| 786 | |
| 787 | account_list_free(); |
| 788 | |
| 789 | if (!gtk_tree_model_get_iter_first(model, &iter))
|
| 790 | return;
|
| 791 | |
| 792 | do {
|
| 793 | gtk_tree_model_get(model, &iter, COL_ACCOUNT, &ac, -1);
|
| 794 | if (ac)
|
| 795 | account_append(ac); |
| 796 | } while (gtk_tree_model_iter_next(model, &iter));
|
| 797 | } |