Statistics
| Revision:

root / src / account_dialog.c @ 761

History | View | Annotate | Download (21.4 kB)

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