Statistics
| Revision:

root / src / account_dialog.c @ 2164

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