Statistics
| Revision:

root / src / account_dialog.c @ 2968

History | View | Annotate | Download (23 kB)

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