diff options
| author | Simeon Simeonov | 2018-02-26 11:23:00 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2018-02-26 11:23:00 +0100 |
| commit | 0b3cbf57875fd692e4ba0b336fefa4bee1ed00dc (patch) | |
| tree | af916a30553c78ce9d4f2d8658656a175c5b6921 /src/account_dialog.c | |
Initial commit for sylpheed 3.7.0
Diffstat (limited to 'src/account_dialog.c')
| -rw-r--r-- | src/account_dialog.c | 847 |
1 files changed, 847 insertions, 0 deletions
diff --git a/src/account_dialog.c b/src/account_dialog.c new file mode 100644 index 0000000..89f3054 --- /dev/null +++ b/src/account_dialog.c | |||
| @@ -0,0 +1,847 @@ | |||
| 1 | /* | ||
| 2 | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client | ||
| 3 | * Copyright (C) 1999-2014 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 | static struct EditAccount { | ||
| 65 | GtkWidget *window; | ||
| 66 | |||
| 67 | GtkWidget *treeview; | ||
| 68 | GtkListStore *store; | ||
| 69 | GtkTreeSelection *selection; | ||
| 70 | |||
| 71 | GtkWidget *close_btn; | ||
| 72 | } edit_account; | ||
| 73 | |||
| 74 | static void account_edit_create (void); | ||
| 75 | |||
| 76 | static GtkWidget *account_wait_window_create (const gchar *str); | ||
| 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 | GtkWidget *window; | ||
| 191 | window = account_wait_window_create(_("Creating folder tree. Please wait...")); | ||
| 192 | if (folder->klass->create_tree(folder) < 0) | ||
| 193 | alertpanel_error(_("Creation of the folder tree failed.")); | ||
| 194 | statusbar_pop_all(); | ||
| 195 | gtk_widget_destroy(window); | ||
| 196 | } | ||
| 197 | } | ||
| 198 | folderview_set_all(); | ||
| 199 | } | ||
| 200 | } | ||
| 201 | |||
| 202 | void account_open(PrefsAccount *ac_prefs) | ||
| 203 | { | ||
| 204 | gboolean prev_default; | ||
| 205 | gchar *prev_name; | ||
| 206 | |||
| 207 | g_return_if_fail(ac_prefs != NULL); | ||
| 208 | |||
| 209 | prev_default = ac_prefs->is_default; | ||
| 210 | prev_name = g_strdup(ac_prefs->account_name ? ac_prefs->account_name : ""); | ||
| 211 | |||
| 212 | prefs_account_open(ac_prefs); | ||
| 213 | if (edit_account.window && GTK_WIDGET_VISIBLE(edit_account.window)) | ||
| 214 | gtk_window_present(GTK_WINDOW(edit_account.window)); | ||
| 215 | else | ||
| 216 | main_window_popup(main_window_get()); | ||
| 217 | |||
| 218 | if (!prev_default && ac_prefs->is_default) | ||
| 219 | account_set_as_default(ac_prefs); | ||
| 220 | |||
| 221 | if (ac_prefs->folder && | ||
| 222 | strcmp2(prev_name, ac_prefs->account_name) != 0) { | ||
| 223 | folder_set_name(FOLDER(ac_prefs->folder), | ||
| 224 | ac_prefs->account_name); | ||
| 225 | folderview_set_all(); | ||
| 226 | folder_write_list(); | ||
| 227 | } | ||
| 228 | |||
| 229 | g_free(prev_name); | ||
| 230 | |||
| 231 | account_write_config_all(); | ||
| 232 | account_set_menu(); | ||
| 233 | main_window_reflect_prefs_all(); | ||
| 234 | account_updated(); | ||
| 235 | } | ||
| 236 | |||
| 237 | void account_set_missing_folder(void) | ||
| 238 | { | ||
| 239 | PrefsAccount *ap; | ||
| 240 | GList *cur; | ||
| 241 | |||
| 242 | for (cur = account_get_list(); cur != NULL; cur = cur->next) { | ||
| 243 | ap = (PrefsAccount *)cur->data; | ||
| 244 | if ((ap->protocol == A_IMAP4 || ap->protocol == A_NNTP) && | ||
| 245 | !ap->folder) { | ||
| 246 | Folder *folder; | ||
| 247 | |||
| 248 | if (ap->protocol == A_IMAP4) { | ||
| 249 | folder = folder_new(F_IMAP, ap->account_name, | ||
| 250 | ap->recv_server); | ||
| 251 | } else { | ||
| 252 | folder = folder_new(F_NEWS, ap->account_name, | ||
| 253 | ap->nntp_server); | ||
| 254 | } | ||
| 255 | |||
| 256 | folder->account = ap; | ||
| 257 | ap->folder = REMOTE_FOLDER(folder); | ||
| 258 | folder_add(folder); | ||
| 259 | if (ap->protocol == A_IMAP4) { | ||
| 260 | if (main_window_toggle_online_if_offline | ||
| 261 | (main_window_get())) { | ||
| 262 | folder->klass->create_tree(folder); | ||
| 263 | statusbar_pop_all(); | ||
| 264 | } | ||
| 265 | } | ||
| 266 | } | ||
| 267 | } | ||
| 268 | } | ||
| 269 | |||
| 270 | static void account_edit_create(void) | ||
| 271 | { | ||
| 272 | GtkWidget *window; | ||
| 273 | GtkWidget *vbox; | ||
| 274 | GtkWidget *label; | ||
| 275 | GtkWidget *hbox; | ||
| 276 | GtkWidget *scrolledwin; | ||
| 277 | GtkWidget *treeview; | ||
| 278 | GtkListStore *store; | ||
| 279 | GtkTreeSelection *selection; | ||
| 280 | GtkTreeViewColumn *column; | ||
| 281 | GtkCellRenderer *renderer; | ||
| 282 | |||
| 283 | GtkWidget *vbox2; | ||
| 284 | GtkWidget *add_btn; | ||
| 285 | GtkWidget *edit_btn; | ||
| 286 | GtkWidget *del_btn; | ||
| 287 | GtkWidget *up_btn; | ||
| 288 | GtkWidget *down_btn; | ||
| 289 | GtkWidget *image; | ||
| 290 | |||
| 291 | GtkWidget *default_btn; | ||
| 292 | |||
| 293 | GtkWidget *hbbox; | ||
| 294 | GtkWidget *close_btn; | ||
| 295 | |||
| 296 | debug_print(_("Creating account edit window...\n")); | ||
| 297 | |||
| 298 | window = gtk_window_new (GTK_WINDOW_TOPLEVEL); | ||
| 299 | gtk_widget_set_size_request (window, 500 * gtkut_get_dpi_multiplier(), 320 * gtkut_get_dpi_multiplier()); | ||
| 300 | gtk_container_set_border_width (GTK_CONTAINER (window), 8); | ||
| 301 | gtk_window_set_title (GTK_WINDOW (window), _("Edit accounts")); | ||
| 302 | gtk_window_set_position (GTK_WINDOW (window), | ||
| 303 | GTK_WIN_POS_CENTER_ON_PARENT); | ||
| 304 | gtk_window_set_modal (GTK_WINDOW (window), TRUE); | ||
| 305 | g_signal_connect (G_OBJECT (window), "delete_event", | ||
| 306 | G_CALLBACK (account_delete_event), NULL); | ||
| 307 | g_signal_connect (G_OBJECT (window), "key_press_event", | ||
| 308 | G_CALLBACK (account_key_pressed), NULL); | ||
| 309 | MANAGE_WINDOW_SIGNALS_CONNECT (window); | ||
| 310 | gtk_widget_realize(window); | ||
| 311 | |||
| 312 | vbox = gtk_vbox_new (FALSE, 10); | ||
| 313 | gtk_widget_show (vbox); | ||
| 314 | gtk_container_add (GTK_CONTAINER (window), vbox); | ||
| 315 | |||
| 316 | hbox = gtk_hbox_new (FALSE, 0); | ||
| 317 | gtk_widget_show (hbox); | ||
| 318 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); | ||
| 319 | |||
| 320 | label = gtk_label_new | ||
| 321 | (_("New messages will be checked in this order. Check the boxes\n" | ||
| 322 | "on the `G' column to enable message retrieval by `Get all'.")); | ||
| 323 | gtk_widget_show (label); | ||
| 324 | gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4); | ||
| 325 | gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | ||
| 326 | |||
| 327 | hbox = gtk_hbox_new (FALSE, 8); | ||
| 328 | gtk_widget_show (hbox); | ||
| 329 | gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); | ||
| 330 | gtk_container_set_border_width (GTK_CONTAINER (hbox), 2); | ||
| 331 | |||
| 332 | scrolledwin = gtk_scrolled_window_new(NULL, NULL); | ||
| 333 | gtk_widget_show(scrolledwin); | ||
| 334 | gtk_box_pack_start(GTK_BOX(hbox), scrolledwin, TRUE, TRUE, 0); | ||
| 335 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin), | ||
| 336 | GTK_POLICY_AUTOMATIC, | ||
| 337 | GTK_POLICY_AUTOMATIC); | ||
| 338 | gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin), | ||
| 339 | GTK_SHADOW_IN); | ||
| 340 | |||
| 341 | store = gtk_list_store_new | ||
| 342 | (N_COLS, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING, | ||
| 343 | G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN); | ||
| 344 | |||
| 345 | treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | ||
| 346 | g_object_unref(G_OBJECT(store)); | ||
| 347 | gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), TRUE); | ||
| 348 | gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); | ||
| 349 | gtk_tree_view_set_search_column(GTK_TREE_VIEW(treeview), COL_NAME); | ||
| 350 | gtk_tree_view_set_reorderable(GTK_TREE_VIEW(treeview), TRUE); | ||
| 351 | |||
| 352 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | ||
| 353 | gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); | ||
| 354 | gtk_tree_selection_set_select_function(selection, account_selected, | ||
| 355 | NULL, NULL); | ||
| 356 | |||
| 357 | renderer = gtk_cell_renderer_toggle_new(); | ||
| 358 | gtk_cell_renderer_toggle_set_radio(GTK_CELL_RENDERER_TOGGLE(renderer), | ||
| 359 | TRUE); | ||
| 360 | g_signal_connect(renderer, "toggled", | ||
| 361 | G_CALLBACK(account_default_toggled), NULL); | ||
| 362 | column = gtk_tree_view_column_new_with_attributes | ||
| 363 | ("D", renderer, "active", COL_DEFAULT, NULL); | ||
| 364 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | ||
| 365 | |||
| 366 | renderer = gtk_cell_renderer_toggle_new(); | ||
| 367 | g_signal_connect(renderer, "toggled", | ||
| 368 | G_CALLBACK(account_getall_toggled), NULL); | ||
| 369 | column = gtk_tree_view_column_new_with_attributes | ||
| 370 | ("G", renderer, "active", COL_GETALL, "visible", COL_CAN_GETALL, | ||
| 371 | NULL); | ||
| 372 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | ||
| 373 | |||
| 374 | renderer = gtk_cell_renderer_text_new(); | ||
| 375 | column = gtk_tree_view_column_new_with_attributes | ||
| 376 | (_("Name"), renderer, "text", COL_NAME, NULL); | ||
| 377 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | ||
| 378 | |||
| 379 | renderer = gtk_cell_renderer_text_new(); | ||
| 380 | column = gtk_tree_view_column_new_with_attributes | ||
| 381 | (_("Protocol"), renderer, "text", COL_PROTOCOL, NULL); | ||
| 382 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | ||
| 383 | |||
| 384 | renderer = gtk_cell_renderer_text_new(); | ||
| 385 | column = gtk_tree_view_column_new_with_attributes | ||
| 386 | (_("Server"), renderer, "text", COL_SERVER, NULL); | ||
| 387 | gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); | ||
| 388 | |||
| 389 | gtk_widget_show(treeview); | ||
| 390 | gtk_container_add(GTK_CONTAINER(scrolledwin), treeview); | ||
| 391 | |||
| 392 | g_signal_connect(G_OBJECT(treeview), "row-activated", | ||
| 393 | G_CALLBACK(account_row_activated), NULL); | ||
| 394 | g_signal_connect_after(G_OBJECT(store), "rows-reordered", | ||
| 395 | G_CALLBACK(account_row_reordered), NULL); | ||
| 396 | |||
| 397 | vbox2 = gtk_vbox_new (FALSE, 0); | ||
| 398 | gtk_widget_show (vbox2); | ||
| 399 | gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0); | ||
| 400 | |||
| 401 | add_btn = gtk_button_new_from_stock (GTK_STOCK_ADD); | ||
| 402 | gtk_widget_show (add_btn); | ||
| 403 | gtk_box_pack_start (GTK_BOX (vbox2), add_btn, FALSE, FALSE, 4); | ||
| 404 | g_signal_connect (G_OBJECT(add_btn), "clicked", | ||
| 405 | G_CALLBACK (account_add), NULL); | ||
| 406 | |||
| 407 | #ifdef GTK_STOCK_EDIT | ||
| 408 | edit_btn = gtk_button_new_from_stock (GTK_STOCK_EDIT); | ||
| 409 | #else | ||
| 410 | edit_btn = gtk_button_new_with_label (_("Edit")); | ||
| 411 | #endif | ||
| 412 | gtk_widget_show (edit_btn); | ||
| 413 | gtk_box_pack_start (GTK_BOX (vbox2), edit_btn, FALSE, FALSE, 4); | ||
| 414 | g_signal_connect (G_OBJECT(edit_btn), "clicked", | ||
| 415 | G_CALLBACK (account_edit_prefs), NULL); | ||
| 416 | |||
| 417 | del_btn = gtk_button_new_from_stock (GTK_STOCK_DELETE); | ||
| 418 | gtk_widget_show (del_btn); | ||
| 419 | gtk_box_pack_start (GTK_BOX (vbox2), del_btn, FALSE, FALSE, 4); | ||
| 420 | g_signal_connect (G_OBJECT(del_btn), "clicked", | ||
| 421 | G_CALLBACK (account_delete), NULL); | ||
| 422 | |||
| 423 | down_btn = gtk_button_new (); | ||
| 424 | image = gtk_image_new_from_stock (GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_BUTTON); | ||
| 425 | gtk_widget_show (image); | ||
| 426 | gtk_button_set_image (GTK_BUTTON(down_btn), image); | ||
| 427 | gtk_widget_show (down_btn); | ||
| 428 | gtk_box_pack_end (GTK_BOX (vbox2), down_btn, FALSE, FALSE, 4); | ||
| 429 | g_signal_connect (G_OBJECT(down_btn), "clicked", | ||
| 430 | G_CALLBACK (account_down), NULL); | ||
| 431 | |||
| 432 | up_btn = gtk_button_new (); | ||
| 433 | image = gtk_image_new_from_stock (GTK_STOCK_GO_UP, GTK_ICON_SIZE_BUTTON); | ||
| 434 | gtk_widget_show (image); | ||
| 435 | gtk_button_set_image (GTK_BUTTON(up_btn), image); | ||
| 436 | gtk_widget_show (up_btn); | ||
| 437 | gtk_box_pack_end (GTK_BOX (vbox2), up_btn, FALSE, FALSE, 4); | ||
| 438 | g_signal_connect (G_OBJECT(up_btn), "clicked", | ||
| 439 | G_CALLBACK (account_up), NULL); | ||
| 440 | |||
| 441 | hbox = gtk_hbox_new (FALSE, 8); | ||
| 442 | gtk_widget_show (hbox); | ||
| 443 | gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); | ||
| 444 | |||
| 445 | vbox2 = gtk_vbox_new(FALSE, 0); | ||
| 446 | gtk_widget_show (vbox2); | ||
| 447 | gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0); | ||
| 448 | |||
| 449 | default_btn = gtk_button_new_with_mnemonic | ||
| 450 | (_(" _Set as default account ")); | ||
| 451 | gtk_widget_show (default_btn); | ||
| 452 | gtk_box_pack_start (GTK_BOX (vbox2), default_btn, TRUE, FALSE, 0); | ||
| 453 | g_signal_connect (G_OBJECT(default_btn), "clicked", | ||
| 454 | G_CALLBACK (account_set_default), NULL); | ||
| 455 | |||
| 456 | gtkut_stock_button_set_create(&hbbox, &close_btn, GTK_STOCK_CLOSE, | ||
| 457 | NULL, NULL, NULL, NULL); | ||
| 458 | gtk_widget_show(hbbox); | ||
| 459 | gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0); | ||
| 460 | gtk_widget_grab_default (close_btn); | ||
| 461 | |||
| 462 | g_signal_connect (G_OBJECT (close_btn), "clicked", | ||
| 463 | G_CALLBACK (account_edit_close), NULL); | ||
| 464 | |||
| 465 | edit_account.window = window; | ||
| 466 | edit_account.treeview = treeview; | ||
| 467 | edit_account.store = store; | ||
| 468 | edit_account.selection = selection; | ||
| 469 | edit_account.close_btn = close_btn; | ||
| 470 | } | ||
| 471 | |||
| 472 | static GtkWidget *account_wait_window_create(const gchar *str) | ||
| 473 | { | ||
| 474 | GtkWidget *window; | ||
| 475 | GtkWidget *label; | ||
| 476 | |||
| 477 | window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | ||
| 478 | gtk_widget_set_size_request(window, 380 * gtkut_get_dpi_multiplier(), 60 * gtkut_get_dpi_multiplier()); | ||
| 479 | gtk_container_set_border_width(GTK_CONTAINER(window), 8); | ||
| 480 | gtk_window_set_position(GTK_WINDOW(window), | ||
| 481 | GTK_WIN_POS_CENTER_ON_PARENT); | ||
| 482 | gtk_window_set_title(GTK_WINDOW(window), str); | ||
| 483 | gtk_window_set_modal(GTK_WINDOW(window), TRUE); | ||
| 484 | gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE); | ||
| 485 | manage_window_focus_in(edit_account.window, NULL, NULL); | ||
| 486 | manage_window_set_transient(GTK_WINDOW(window)); | ||
| 487 | g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_true), | ||
| 488 | NULL); | ||
| 489 | |||
| 490 | label = gtk_label_new(str); | ||
| 491 | gtk_container_add(GTK_CONTAINER(window), label); | ||
| 492 | gtk_widget_show(label); | ||
| 493 | |||
| 494 | gtk_widget_show(window); | ||
| 495 | |||
| 496 | return window; | ||
| 497 | } | ||
| 498 | |||
| 499 | static void account_edit_prefs(void) | ||
| 500 | { | ||
| 501 | GtkTreeIter iter; | ||
| 502 | PrefsAccount *ac_prefs; | ||
| 503 | |||
| 504 | if (!gtk_tree_selection_get_selected(edit_account.selection, | ||
| 505 | NULL, &iter)) | ||
| 506 | return; | ||
| 507 | |||
| 508 | gtk_tree_model_get(GTK_TREE_MODEL(edit_account.store), &iter, | ||
| 509 | COL_ACCOUNT, &ac_prefs, -1); | ||
| 510 | account_open(ac_prefs); | ||
| 511 | |||
| 512 | account_set_row(ac_prefs, &iter, NULL, FALSE); | ||
| 513 | } | ||
| 514 | |||
| 515 | static void account_delete(void) | ||
| 516 | { | ||
| 517 | GtkTreeIter iter; | ||
| 518 | PrefsAccount *ac_prefs; | ||
| 519 | gchar buf[BUFFSIZE]; | ||
| 520 | |||
| 521 | if (!gtk_tree_selection_get_selected(edit_account.selection, | ||
| 522 | NULL, &iter)) | ||
| 523 | return; | ||
| 524 | |||
| 525 | gtk_tree_model_get(GTK_TREE_MODEL(edit_account.store), &iter, | ||
| 526 | COL_ACCOUNT, &ac_prefs, -1); | ||
| 527 | g_return_if_fail(ac_prefs != NULL); | ||
| 528 | |||
| 529 | g_snprintf(buf, sizeof(buf), | ||
| 530 | _("Do you really want to delete the account '%s'?"), | ||
| 531 | ac_prefs->account_name ? ac_prefs->account_name : | ||
| 532 | _("(Untitled)")); | ||
| 533 | if (alertpanel_full(_("Delete account"), buf, | ||
| 534 | ALERT_QUESTION, G_ALERTALTERNATE, FALSE, | ||
| 535 | GTK_STOCK_YES, GTK_STOCK_NO, NULL) | ||
| 536 | != G_ALERTDEFAULT) | ||
| 537 | return; | ||
| 538 | |||
| 539 | if (ac_prefs->folder) { | ||
| 540 | FolderItem *item; | ||
| 541 | |||
| 542 | item = main_window_get()->summaryview->folder_item; | ||
| 543 | if (item && item->folder == FOLDER(ac_prefs->folder)) | ||
| 544 | summary_clear_all(main_window_get()->summaryview); | ||
| 545 | folder_destroy(FOLDER(ac_prefs->folder)); | ||
| 546 | folderview_set_all(); | ||
| 547 | } | ||
| 548 | |||
| 549 | account_destroy(ac_prefs); | ||
| 550 | gtk_list_store_remove(edit_account.store, &iter); | ||
| 551 | account_update_dialog(); | ||
| 552 | } | ||
| 553 | |||
| 554 | static void account_up(void) | ||
| 555 | { | ||
| 556 | GtkTreeModel *model = GTK_TREE_MODEL(edit_account.store); | ||
| 557 | GtkTreeIter iter, prev; | ||
| 558 | GtkTreePath *path; | ||
| 559 | |||
| 560 | if (!gtk_tree_selection_get_selected(edit_account.selection, | ||
| 561 | NULL, &iter)) | ||
| 562 | return; | ||
| 563 | |||
| 564 | path = gtk_tree_model_get_path(model, &iter); | ||
| 565 | if (gtk_tree_path_prev(path)) { | ||
| 566 | gtk_tree_model_get_iter(model, &prev, path); | ||
| 567 | gtk_list_store_swap(edit_account.store, &iter, &prev); | ||
| 568 | } | ||
| 569 | gtk_tree_path_free(path); | ||
| 570 | } | ||
| 571 | |||
| 572 | static void account_down(void) | ||
| 573 | { | ||
| 574 | GtkTreeIter iter, next; | ||
| 575 | |||
| 576 | if (!gtk_tree_selection_get_selected(edit_account.selection, | ||
| 577 | NULL, &iter)) | ||
| 578 | return; | ||
| 579 | |||
| 580 | next = iter; | ||
| 581 | if (gtk_tree_model_iter_next(GTK_TREE_MODEL(edit_account.store), | ||
| 582 | &next)) | ||
| 583 | gtk_list_store_swap(edit_account.store, &iter, &next); | ||
| 584 | } | ||
| 585 | |||
| 586 | static void account_set_default(void) | ||
| 587 | { | ||
| 588 | GtkTreeIter iter; | ||
| 589 | PrefsAccount *ac_prefs; | ||
| 590 | |||
| 591 | if (!gtk_tree_selection_get_selected(edit_account.selection, | ||
| 592 | NULL, &iter)) | ||
| 593 | return; | ||
| 594 | |||
| 595 | gtk_tree_model_get(GTK_TREE_MODEL(edit_account.store), &iter, | ||
| 596 | COL_ACCOUNT, &ac_prefs, -1); | ||
| 597 | g_return_if_fail(ac_prefs != NULL); | ||
| 598 | |||
| 599 | account_set_as_default(ac_prefs); | ||
| 600 | account_update_dialog(); | ||
| 601 | |||
| 602 | cur_account = ac_prefs; | ||
| 603 | account_set_menu(); | ||
| 604 | main_window_reflect_prefs_all(); | ||
| 605 | } | ||
| 606 | |||
| 607 | static void account_edit_close(void) | ||
| 608 | { | ||
| 609 | GList *account_list; | ||
| 610 | |||
| 611 | account_update_lock(); | ||
| 612 | account_set_list(); | ||
| 613 | account_write_config_all(); | ||
| 614 | |||
| 615 | account_list = account_get_list(); | ||
| 616 | |||
| 617 | if (!cur_account && account_list) { | ||
| 618 | PrefsAccount *ac_prefs = (PrefsAccount *)account_list->data; | ||
| 619 | account_set_as_default(ac_prefs); | ||
| 620 | cur_account = ac_prefs; | ||
| 621 | } | ||
| 622 | |||
| 623 | account_set_menu(); | ||
| 624 | main_window_reflect_prefs_all(); | ||
| 625 | account_update_unlock(); | ||
| 626 | account_updated(); | ||
| 627 | |||
| 628 | gtk_widget_hide(edit_account.window); | ||
| 629 | main_window_popup(main_window_get()); | ||
| 630 | |||
| 631 | inc_unlock(); | ||
| 632 | } | ||
| 633 | |||
| 634 | static gint account_delete_event(GtkWidget *widget, GdkEventAny *event, | ||
| 635 | gpointer data) | ||
| 636 | { | ||
| 637 | account_edit_close(); | ||
| 638 | return TRUE; | ||
| 639 | } | ||
| 640 | |||
| 641 | static gboolean account_selected(GtkTreeSelection *selection, | ||
| 642 | GtkTreeModel *model, GtkTreePath *path, | ||
| 643 | gboolean cur_selected, gpointer data) | ||
| 644 | { | ||
| 645 | return TRUE; | ||
| 646 | } | ||
| 647 | |||
| 648 | static void account_default_toggled(GtkCellRenderer *cell, gchar *path_str, | ||
| 649 | gpointer data) | ||
| 650 | { | ||
| 651 | GtkTreeIter iter; | ||
| 652 | PrefsAccount *ac; | ||
| 653 | GtkTreePath *path; | ||
| 654 | |||
| 655 | path = gtk_tree_path_new_from_string(path_str); | ||
| 656 | gtk_tree_model_get_iter(GTK_TREE_MODEL(edit_account.store), | ||
| 657 | &iter, path); | ||
| 658 | gtk_tree_path_free(path); | ||
| 659 | gtk_tree_model_get(GTK_TREE_MODEL(edit_account.store), &iter, | ||
| 660 | COL_ACCOUNT, &ac, -1); | ||
| 661 | |||
| 662 | account_set_as_default(ac); | ||
| 663 | account_update_dialog(); | ||
| 664 | } | ||
| 665 | |||
| 666 | static void account_getall_toggled(GtkCellRenderer *cell, gchar *path_str, | ||
| 667 | gpointer data) | ||
| 668 | { | ||
| 669 | GtkTreeIter iter; | ||
| 670 | PrefsAccount *ac; | ||
| 671 | GtkTreePath *path; | ||
| 672 | gboolean can_getall; | ||
| 673 | |||
| 674 | path = gtk_tree_path_new_from_string(path_str); | ||
| 675 | gtk_tree_model_get_iter(GTK_TREE_MODEL(edit_account.store), | ||
| 676 | &iter, path); | ||
| 677 | gtk_tree_path_free(path); | ||
| 678 | gtk_tree_model_get(GTK_TREE_MODEL(edit_account.store), &iter, | ||
| 679 | COL_ACCOUNT, &ac, COL_CAN_GETALL, &can_getall, -1); | ||
| 680 | |||
| 681 | if (can_getall) { | ||
| 682 | ac->recv_at_getall ^= TRUE; | ||
| 683 | account_set_row(ac, &iter, NULL, FALSE); | ||
| 684 | } | ||
| 685 | } | ||
| 686 | |||
| 687 | static void account_row_activated(GtkTreeView *treeview, GtkTreePath *path, | ||
| 688 | GtkTreeViewColumn *column, gpointer data) | ||
| 689 | { | ||
| 690 | account_edit_prefs(); | ||
| 691 | } | ||
| 692 | |||
| 693 | static void account_row_reordered (GtkTreeModel *model, | ||
| 694 | GtkTreePath *path, | ||
| 695 | GtkTreeIter *iter, | ||
| 696 | gpointer data) | ||
| 697 | { | ||
| 698 | GtkTreeIter iter_; | ||
| 699 | GtkTreePath *path_; | ||
| 700 | |||
| 701 | if (!gtk_tree_selection_get_selected(edit_account.selection, | ||
| 702 | NULL, &iter_)) | ||
| 703 | return; | ||
| 704 | path_ = gtk_tree_model_get_path | ||
| 705 | (GTK_TREE_MODEL(edit_account.store), &iter_); | ||
| 706 | gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(edit_account.treeview), | ||
| 707 | path_, NULL, FALSE, 0.0, 0.0); | ||
| 708 | gtk_tree_path_free(path_); | ||
| 709 | } | ||
| 710 | |||
| 711 | static gboolean account_key_pressed(GtkWidget *widget, GdkEventKey *event, | ||
| 712 | gpointer data) | ||
| 713 | { | ||
| 714 | if (event && event->keyval == GDK_Escape) | ||
| 715 | account_edit_close(); | ||
| 716 | return FALSE; | ||
| 717 | } | ||
| 718 | |||
| 719 | static void account_set_row(PrefsAccount *ac_prefs, GtkTreeIter *iter, | ||
| 720 | GtkTreeIter *new, gboolean move_view) | ||
| 721 | { | ||
| 722 | GtkListStore *store = edit_account.store; | ||
| 723 | GtkTreeIter iter_; | ||
| 724 | const gchar *protocol, *server; | ||
| 725 | gboolean has_getall; | ||
| 726 | |||
| 727 | g_return_if_fail(ac_prefs != NULL); | ||
| 728 | |||
| 729 | #if USE_SSL | ||
| 730 | protocol = ac_prefs->protocol == A_POP3 ? | ||
| 731 | (ac_prefs->ssl_pop == SSL_TUNNEL ? | ||
| 732 | "POP3 (SSL)" : | ||
| 733 | ac_prefs->ssl_pop == SSL_STARTTLS ? | ||
| 734 | "POP3 (TLS)" : "POP3") : | ||
| 735 | ac_prefs->protocol == A_IMAP4 ? | ||
| 736 | (ac_prefs->ssl_imap == SSL_TUNNEL ? | ||
| 737 | "IMAP4 (SSL)" : | ||
| 738 | ac_prefs->ssl_imap == SSL_STARTTLS ? | ||
| 739 | "IMAP4 (TLS)" : "IMAP4") : | ||
| 740 | ac_prefs->protocol == A_NNTP ? | ||
| 741 | (ac_prefs->ssl_nntp == SSL_TUNNEL ? | ||
| 742 | "NNTP (SSL)" : "NNTP") : | ||
| 743 | ""; | ||
| 744 | #else | ||
| 745 | protocol = ac_prefs->protocol == A_POP3 ? "POP3" : | ||
| 746 | ac_prefs->protocol == A_IMAP4 ? "IMAP4" : | ||
| 747 | ac_prefs->protocol == A_NNTP ? "NNTP" : ""; | ||
| 748 | #endif | ||
| 749 | server = ac_prefs->protocol == A_NNTP ? | ||
| 750 | ac_prefs->nntp_server : ac_prefs->recv_server; | ||
| 751 | |||
| 752 | has_getall = (ac_prefs->protocol == A_POP3 || | ||
| 753 | ac_prefs->protocol == A_IMAP4 || | ||
| 754 | ac_prefs->protocol == A_NNTP); | ||
| 755 | |||
| 756 | if (!iter) | ||
| 757 | gtk_list_store_append(store, &iter_); | ||
| 758 | else | ||
| 759 | iter_ = *iter; | ||
| 760 | |||
| 761 | gtk_list_store_set(store, &iter_, | ||
| 762 | COL_DEFAULT, ac_prefs->is_default, | ||
| 763 | COL_GETALL, has_getall && ac_prefs->recv_at_getall, | ||
| 764 | COL_NAME, ac_prefs->account_name, | ||
| 765 | COL_PROTOCOL, protocol, | ||
| 766 | COL_SERVER, server, | ||
| 767 | COL_ACCOUNT, ac_prefs, | ||
| 768 | COL_CAN_GETALL, has_getall, | ||
| 769 | -1); | ||
| 770 | |||
| 771 | if (new) | ||
| 772 | *new = iter_; | ||
| 773 | |||
| 774 | if (move_view) { | ||
| 775 | GtkTreePath *path; | ||
| 776 | |||
| 777 | path = gtk_tree_model_get_path | ||
| 778 | (GTK_TREE_MODEL(edit_account.store), &iter_); | ||
| 779 | gtk_tree_view_scroll_to_cell | ||
| 780 | (GTK_TREE_VIEW(edit_account.treeview), | ||
| 781 | path, NULL, TRUE, 0.5, 0.0); | ||
| 782 | gtk_tree_path_free(path); | ||
| 783 | } | ||
| 784 | } | ||
| 785 | |||
| 786 | /* set dialog from account list */ | ||
| 787 | static void account_set_dialog(void) | ||
| 788 | { | ||
| 789 | GList *cur; | ||
| 790 | GtkTreeIter iter; | ||
| 791 | GtkTreePath *path; | ||
| 792 | |||
| 793 | gtk_list_store_clear(edit_account.store); | ||
| 794 | |||
| 795 | for (cur = account_get_list(); cur != NULL; cur = cur->next) { | ||
| 796 | account_set_row((PrefsAccount *)cur->data, NULL, &iter, FALSE); | ||
| 797 | if ((PrefsAccount *)cur->data == cur_account) { | ||
| 798 | gtk_tree_selection_select_iter(edit_account.selection, | ||
| 799 | &iter); | ||
| 800 | } | ||
| 801 | } | ||
| 802 | |||
| 803 | if (!gtk_tree_selection_get_selected(edit_account.selection, NULL, | ||
| 804 | &iter)) | ||
| 805 | return; | ||
| 806 | path = gtk_tree_model_get_path(GTK_TREE_MODEL(edit_account.store), | ||
| 807 | &iter); | ||
| 808 | gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(edit_account.treeview), | ||
| 809 | path, NULL, FALSE, 0.0, 0.0); | ||
| 810 | gtk_tree_path_free(path); | ||
| 811 | } | ||
| 812 | |||
| 813 | /* update dialog to the latest state */ | ||
| 814 | static void account_update_dialog(void) | ||
| 815 | { | ||
| 816 | GtkTreeIter iter; | ||
| 817 | GtkTreeModel *model = GTK_TREE_MODEL(edit_account.store); | ||
| 818 | PrefsAccount *ac; | ||
| 819 | |||
| 820 | if (!gtk_tree_model_get_iter_first(model, &iter)) | ||
| 821 | return; | ||
| 822 | |||
| 823 | do { | ||
| 824 | gtk_tree_model_get(model, &iter, COL_ACCOUNT, &ac, -1); | ||
| 825 | if (ac) | ||
| 826 | account_set_row(ac, &iter, NULL, FALSE); | ||
| 827 | } while (gtk_tree_model_iter_next(model, &iter)); | ||
| 828 | } | ||
| 829 | |||
| 830 | /* set account list from dialog */ | ||
| 831 | static void account_set_list(void) | ||
| 832 | { | ||
| 833 | GtkTreeIter iter; | ||
| 834 | GtkTreeModel *model = GTK_TREE_MODEL(edit_account.store); | ||
| 835 | PrefsAccount *ac; | ||
| 836 | |||
| 837 | account_list_free(); | ||
| 838 | |||
| 839 | if (!gtk_tree_model_get_iter_first(model, &iter)) | ||
| 840 | return; | ||
| 841 | |||
| 842 | do { | ||
| 843 | gtk_tree_model_get(model, &iter, COL_ACCOUNT, &ac, -1); | ||
| 844 | if (ac) | ||
| 845 | account_append(ac); | ||
| 846 | } while (gtk_tree_model_iter_next(model, &iter)); | ||
| 847 | } | ||
