more sync with Hiroyuki's 0.5.1cvs5
[claws.git] / src / account.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <gtk/gtk.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <stdio.h>
30 #include <errno.h>
31
32 #include "intl.h"
33 #include "main.h"
34 #include "mainwindow.h"
35 #include "folderview.h"
36 #include "folder.h"
37 #include "account.h"
38 #include "prefs.h"
39 #include "prefs_account.h"
40 #include "compose.h"
41 #include "manage_window.h"
42 #include "inc.h"
43 #include "gtkutils.h"
44 #include "utils.h"
45 #include "alertpanel.h"
46
47 typedef enum
48 {
49         COL_DEFAULT     = 0,
50         COL_NAME        = 1,
51         COL_PROTOCOL    = 2,
52         COL_SERVER      = 3
53 } EditAccountColumnPos;
54
55 # define N_EDIT_ACCOUNT_COLS    4
56
57 #define PREFSBUFSIZE            1024
58
59 PrefsAccount *cur_account;
60
61 static GList *account_list = NULL;
62
63 static struct EditAccount {
64         GtkWidget *window;
65         GtkWidget *clist;
66         GtkWidget *close_btn;
67 } edit_account;
68
69 static void account_edit_create         (void);
70
71 static void account_edit_prefs          (void);
72 static void account_delete              (void);
73
74 static void account_up                  (void);
75 static void account_down                (void);
76
77 static void account_set_default         (void);
78
79 static void account_edit_close          (void);
80 static gint account_delete_event        (GtkWidget      *widget,
81                                          GdkEventAny    *event,
82                                          gpointer        data);
83 static void account_selected            (GtkCList       *clist,
84                                          gint            row,
85                                          gint            column,
86                                          GdkEvent       *event,
87                                          gpointer        data);
88 static void account_key_pressed         (GtkWidget      *widget,
89                                          GdkEventKey    *event,
90                                          gpointer        data);
91
92 static gint account_clist_set_row       (PrefsAccount   *ac_prefs,
93                                          gint            row);
94 static void account_clist_set           (void);
95
96 static void account_list_set            (void);
97
98 void account_read_config_all(void)
99 {
100         GSList *ac_label_list = NULL, *cur;
101         gchar *rcpath;
102         FILE *fp;
103         gchar buf[PREFSBUFSIZE];
104         PrefsAccount *ac_prefs;
105
106         debug_print(_("Reading all config for each account...\n"));
107
108         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
109         if ((fp = fopen(rcpath, "r")) == NULL) {
110                 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
111                 g_free(rcpath);
112                 return;
113         }
114         g_free(rcpath);
115
116         while (fgets(buf, sizeof(buf), fp) != NULL) {
117                 if (!strncmp(buf, "[Account: ", 10)) {
118                         strretchomp(buf);
119                         memmove(buf, buf + 1, strlen(buf));
120                         buf[strlen(buf) - 1] = '\0';
121                         debug_print(_("Found label: %s\n"), buf);
122                         ac_label_list = g_slist_append(ac_label_list,
123                                                        g_strdup(buf));
124                 }
125         }
126         fclose(fp);
127
128         /* read config data from file */
129         cur_account = NULL;
130         for (cur = ac_label_list; cur != NULL; cur = cur->next) {
131                 ac_prefs = g_new0(PrefsAccount, 1);
132                 prefs_account_read_config(ac_prefs, (gchar *)cur->data);
133                 account_list = g_list_append(account_list, ac_prefs);
134                 if (ac_prefs->is_default)
135                         cur_account = ac_prefs;
136         }
137         /* if default is not set, assume first account as default */
138         if (!cur_account && account_list) {
139                 ac_prefs = (PrefsAccount *)account_list->data;
140                 account_set_as_default(ac_prefs);
141                 cur_account = ac_prefs;
142         }
143
144         account_set_menu();
145         main_window_reflect_prefs_all();
146
147         while (ac_label_list) {
148                 g_free(ac_label_list->data);
149                 ac_label_list = g_slist_remove(ac_label_list,
150                                                ac_label_list->data);
151         }
152 }
153
154 void account_save_config_all(void)
155 {
156         prefs_account_save_config_all(account_list);
157 }
158
159 PrefsAccount *account_find_from_smtp_server(const gchar *address,
160                                             const gchar *smtp_server)
161 {
162         GList *cur;
163         PrefsAccount *ac;
164
165         for (cur = account_list; cur != NULL; cur = cur->next) {
166                 ac = (PrefsAccount *)cur->data;
167                 if (!strcmp2(address, ac->address) &&
168                     !strcmp2(smtp_server, ac->smtp_server))
169                         return ac;
170         }
171
172         return NULL;
173 }
174
175 /*
176  * account_find_from_address:
177  * @address: Email address string.
178  *
179  * Find a mail (not news) account with the specified email address.
180  *
181  * Return value: The found account, or NULL if not found.
182  */
183 PrefsAccount *account_find_from_address(const gchar *address)
184 {
185         GList *cur;
186         PrefsAccount *ac;
187
188         for (cur = account_list; cur != NULL; cur = cur->next) {
189                 ac = (PrefsAccount *)cur->data;
190                 if (ac->protocol != A_NNTP && !strcmp2(address, ac->address))
191                         return ac;
192         }
193
194         return NULL;
195 }
196
197 PrefsAccount *account_find_from_id(gint id)
198 {
199         GList *cur;
200         PrefsAccount *ac;
201
202         for (cur = account_list; cur != NULL; cur = cur->next) {
203                 ac = (PrefsAccount *)cur->data;
204                 if (id == ac->account_id)
205                         return ac;
206         }
207
208         return NULL;
209 }
210
211 void account_set_menu(void)
212 {
213         main_window_set_account_menu(account_list);
214 }
215
216 void account_foreach(AccountFunc func, gpointer user_data)
217 {
218         GList *cur;
219
220         for (cur = account_list; cur != NULL; cur = cur->next)
221                 if (func((PrefsAccount *)cur->data, user_data) != 0)
222                         return;
223 }
224
225 GList *account_get_list(void)
226 {
227         return account_list;
228 }
229
230 void account_edit_open(void)
231 {
232         inc_autocheck_timer_remove();
233
234         if (compose_get_compose_list()) {
235                 alertpanel_notice(_("Some composing windows are open.\n"
236                                     "Please close all the composing windows before editing the accounts."));
237                 inc_autocheck_timer_set();
238                 return;
239         }
240
241         debug_print(_("Opening account edit window...\n"));
242
243         if (!edit_account.window)
244                 account_edit_create();
245
246         account_clist_set();
247
248         manage_window_set_transient(GTK_WINDOW(edit_account.window));
249         gtk_widget_grab_focus(edit_account.close_btn);
250         gtk_widget_show(edit_account.window);
251
252         manage_window_focus_in(edit_account.window, NULL, NULL);
253 }
254
255 void account_add(void)
256 {
257         PrefsAccount *ac_prefs;
258
259         ac_prefs = prefs_account_open(NULL);
260         inc_autocheck_timer_remove();
261
262         if (!ac_prefs) return;
263
264         account_list = g_list_append(account_list, ac_prefs);
265
266         if (ac_prefs->is_default)
267                 account_set_as_default(ac_prefs);
268
269         account_clist_set();
270
271         if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
272                 Folder *folder;
273
274                 if (ac_prefs->protocol == A_IMAP4) {
275                         folder = folder_new(F_IMAP, ac_prefs->account_name,
276                                             ac_prefs->recv_server);
277                 } else {
278                         folder = folder_new(F_NEWS, ac_prefs->account_name,
279                                             ac_prefs->nntp_server);
280                 }
281
282                 folder->account = ac_prefs;
283                 ac_prefs->folder = REMOTE_FOLDER(folder);
284                 folder_add(folder);
285                 if (ac_prefs->protocol == A_IMAP4)
286                         folder->create_tree(folder);
287                 folderview_set_all();
288         }
289 }
290
291 void account_set_as_default(PrefsAccount *ac_prefs)
292 {
293         PrefsAccount *ap;
294         GList *cur;
295
296         for (cur = account_list; cur != NULL; cur = cur->next) {
297                 ap = (PrefsAccount *)cur->data;
298                 if (ap->is_default)
299                         ap->is_default = FALSE;
300         }
301
302         ac_prefs->is_default = TRUE;
303 }
304
305 PrefsAccount *account_get_default(void)
306 {
307         PrefsAccount *ap;
308         GList *cur;
309
310         for (cur = account_list; cur != NULL; cur = cur->next) {
311                 ap = (PrefsAccount *)cur->data;
312                 if (ap->is_default)
313                         return ap;
314         }
315
316         return NULL;
317 }
318
319 void account_set_missing_folder(void)
320 {
321         PrefsAccount *ap;
322         GList *cur;
323
324         for (cur = account_list; cur != NULL; cur = cur->next) {
325                 ap = (PrefsAccount *)cur->data;
326                 if ((ap->protocol == A_IMAP4 || ap->protocol == A_NNTP) &&
327                     !ap->folder) {
328                         Folder *folder;
329
330                         if (ap->protocol == A_IMAP4) {
331                                 folder = folder_new(F_IMAP, ap->account_name,
332                                                     ap->recv_server);
333                         } else {
334                                 folder = folder_new(F_NEWS, ap->account_name,
335                                                     ap->nntp_server);
336                         }
337
338                         folder->account = ap;
339                         ap->folder = REMOTE_FOLDER(folder);
340                         folder_add(folder);
341                         if (ap->protocol == A_IMAP4)
342                                 folder->create_tree(folder);
343                 }
344         }
345 }
346
347 void account_destroy(PrefsAccount *ac_prefs)
348 {
349         g_return_if_fail(ac_prefs != NULL);
350
351         prefs_account_free(ac_prefs);
352         account_list = g_list_remove(account_list, ac_prefs);
353
354         if (cur_account == ac_prefs) cur_account = NULL;
355         if (!cur_account && account_list) {
356                 cur_account = account_get_default();
357                 if (!cur_account) {
358                         ac_prefs = (PrefsAccount *)account_list->data;
359                         account_set_as_default(ac_prefs);
360                         cur_account = ac_prefs;
361                 }
362         }
363 }
364
365
366 static void account_edit_create(void)
367 {
368         GtkWidget *window;
369         GtkWidget *vbox;
370         GtkWidget *hbox;
371         GtkWidget *scrolledwin;
372         GtkWidget *clist;
373         gchar *titles[N_EDIT_ACCOUNT_COLS];
374         gint i;
375
376         GtkWidget *vbox2;
377         GtkWidget *add_btn;
378         GtkWidget *edit_btn;
379         GtkWidget *del_btn;
380         GtkWidget *up_btn;
381         GtkWidget *down_btn;
382
383         GtkWidget *default_btn;
384
385         GtkWidget *hbbox;
386         GtkWidget *close_btn;
387
388         debug_print(_("Creating account edit window...\n"));
389
390         window = gtk_window_new (GTK_WINDOW_DIALOG);
391         gtk_widget_set_usize (window, 500, 320);
392         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
393         gtk_window_set_title (GTK_WINDOW (window), _("Edit accounts"));
394         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
395         gtk_signal_connect (GTK_OBJECT (window), "delete_event",
396                             GTK_SIGNAL_FUNC (account_delete_event), NULL);
397         gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
398                             GTK_SIGNAL_FUNC (account_key_pressed), NULL);
399         gtk_signal_connect (GTK_OBJECT (window), "focus_in_event",
400                             GTK_SIGNAL_FUNC (manage_window_focus_in), NULL);
401         gtk_signal_connect (GTK_OBJECT (window), "focus_out_event",
402                             GTK_SIGNAL_FUNC (manage_window_focus_out), NULL);
403
404         vbox = gtk_vbox_new (FALSE, 12);
405         gtk_widget_show (vbox);
406         gtk_container_add (GTK_CONTAINER (window), vbox);
407
408         hbox = gtk_hbox_new (FALSE, 8);
409         gtk_widget_show (hbox);
410         gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
411         gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
412
413         scrolledwin = gtk_scrolled_window_new (NULL, NULL);
414         gtk_widget_show (scrolledwin);
415         gtk_box_pack_start (GTK_BOX (hbox), scrolledwin, TRUE, TRUE, 0);
416         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin),
417                                         GTK_POLICY_AUTOMATIC,
418                                         GTK_POLICY_AUTOMATIC);
419
420         titles[COL_DEFAULT]  = "";
421         titles[COL_NAME]     = _("Name");
422         titles[COL_PROTOCOL] = _("Protocol");
423         titles[COL_SERVER]   = _("Server");
424
425         clist = gtk_clist_new_with_titles (N_EDIT_ACCOUNT_COLS, titles);
426         gtk_widget_show (clist);
427         gtk_container_add (GTK_CONTAINER (scrolledwin), clist);
428         gtk_clist_set_column_width (GTK_CLIST(clist), COL_DEFAULT , 16);
429         gtk_clist_set_column_width (GTK_CLIST(clist), COL_NAME    , 100);
430         gtk_clist_set_column_width (GTK_CLIST(clist), COL_PROTOCOL, 70);
431         gtk_clist_set_column_width (GTK_CLIST(clist), COL_SERVER  , 100);
432         gtk_clist_set_selection_mode (GTK_CLIST(clist), GTK_SELECTION_BROWSE);
433
434         for (i = 0; i < N_EDIT_ACCOUNT_COLS; i++)
435                 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button,
436                                        GTK_CAN_FOCUS);
437
438         gtk_signal_connect (GTK_OBJECT (clist), "select_row",
439                             GTK_SIGNAL_FUNC (account_selected), NULL);
440
441         vbox2 = gtk_vbox_new (FALSE, 0);
442         gtk_widget_show (vbox2);
443         gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
444
445         add_btn = gtk_button_new_with_label (_("Add"));
446         gtk_widget_show (add_btn);
447         gtk_box_pack_start (GTK_BOX (vbox2), add_btn, FALSE, FALSE, 4);
448         gtk_signal_connect (GTK_OBJECT(add_btn), "clicked",
449                             GTK_SIGNAL_FUNC (account_add), NULL);
450
451         edit_btn = gtk_button_new_with_label (_("Edit"));
452         gtk_widget_show (edit_btn);
453         gtk_box_pack_start (GTK_BOX (vbox2), edit_btn, FALSE, FALSE, 4);
454         gtk_signal_connect (GTK_OBJECT(edit_btn), "clicked",
455                             GTK_SIGNAL_FUNC (account_edit_prefs), NULL);
456
457         del_btn = gtk_button_new_with_label (_(" Delete "));
458         gtk_widget_show (del_btn);
459         gtk_box_pack_start (GTK_BOX (vbox2), del_btn, FALSE, FALSE, 4);
460         gtk_signal_connect (GTK_OBJECT(del_btn), "clicked",
461                             GTK_SIGNAL_FUNC (account_delete), NULL);
462
463         down_btn = gtk_button_new_with_label (_("Down"));
464         gtk_widget_show (down_btn);
465         gtk_box_pack_end (GTK_BOX (vbox2), down_btn, FALSE, FALSE, 4);
466         gtk_signal_connect (GTK_OBJECT(down_btn), "clicked",
467                             GTK_SIGNAL_FUNC (account_down), NULL);
468
469         up_btn = gtk_button_new_with_label (_("Up"));
470         gtk_widget_show (up_btn);
471         gtk_box_pack_end (GTK_BOX (vbox2), up_btn, FALSE, FALSE, 4);
472         gtk_signal_connect (GTK_OBJECT(up_btn), "clicked",
473                             GTK_SIGNAL_FUNC (account_up), NULL);
474
475         hbox = gtk_hbox_new (FALSE, 8);
476         gtk_widget_show (hbox);
477         gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
478
479         vbox2 = gtk_vbox_new(FALSE, 0);
480         gtk_widget_show (vbox2);
481         gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
482
483         default_btn = gtk_button_new_with_label (_(" Set as default account "));
484         gtk_widget_show (default_btn);
485         gtk_box_pack_start (GTK_BOX (vbox2), default_btn, TRUE, FALSE, 0);
486         gtk_signal_connect (GTK_OBJECT(default_btn), "clicked",
487                             GTK_SIGNAL_FUNC (account_set_default), NULL);
488
489         gtkut_button_set_create(&hbbox, &close_btn, _("Close"),
490                                 NULL, NULL, NULL, NULL);
491         gtk_widget_show(hbbox);
492         gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
493         gtk_widget_grab_default (close_btn);
494
495         gtk_signal_connect (GTK_OBJECT (close_btn), "clicked",
496                             GTK_SIGNAL_FUNC (account_edit_close),
497                             NULL);
498
499         edit_account.window    = window;
500         edit_account.clist     = clist;
501         edit_account.close_btn = close_btn;
502 }
503
504 static void account_edit_prefs(void)
505 {
506         GtkCList *clist = GTK_CLIST(edit_account.clist);
507         PrefsAccount *ac_prefs;
508         gint row;
509         gboolean prev_default;
510         gchar *ac_name;
511
512         if (!clist->selection) return;
513
514         row = GPOINTER_TO_INT(clist->selection->data);
515         ac_prefs = gtk_clist_get_row_data(clist, row);
516         prev_default = ac_prefs->is_default;
517         Xstrdup_a(ac_name, ac_prefs->account_name, return);
518
519         prefs_account_open(ac_prefs);
520         inc_autocheck_timer_remove();
521
522         if (!prev_default && ac_prefs->is_default)
523                 account_set_as_default(ac_prefs);
524
525         if ((ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) &&
526             ac_prefs->folder && strcmp(ac_name, ac_prefs->account_name) != 0) {
527                 folder_set_name(FOLDER(ac_prefs->folder),
528                                 ac_prefs->account_name);
529                 folderview_update_all();
530         }
531
532         account_clist_set();
533 }
534
535 static void account_delete(void)
536 {
537         GtkCList *clist = GTK_CLIST(edit_account.clist);
538         PrefsAccount *ac_prefs;
539         gint row;
540
541         if (!clist->selection) return;
542
543         if (alertpanel(_("Delete account"),
544                        _("Do you really want to delete this account?"),
545                        _("Yes"), _("+No"), NULL) != G_ALERTDEFAULT)
546                 return;
547
548         row = GPOINTER_TO_INT(clist->selection->data);
549         ac_prefs = gtk_clist_get_row_data(clist, row);
550         if (ac_prefs->folder) {
551                 folder_destroy(FOLDER(ac_prefs->folder));
552                 folderview_update_all();
553         }
554         account_destroy(ac_prefs);
555         account_clist_set();
556 }
557
558 static void account_up(void)
559 {
560         GtkCList *clist = GTK_CLIST(edit_account.clist);
561         gint row;
562
563         if (!clist->selection) return;
564
565         row = GPOINTER_TO_INT(clist->selection->data);
566         if (row > 0) {
567                 gtk_clist_row_move(clist, row, row - 1);
568                 account_list_set();
569         }
570 }
571
572 static void account_down(void)
573 {
574         GtkCList *clist = GTK_CLIST(edit_account.clist);
575         gint row;
576
577         if (!clist->selection) return;
578
579         row = GPOINTER_TO_INT(clist->selection->data);
580         if (row < clist->rows - 1) {
581                 gtk_clist_row_move(clist, row, row + 1);
582                 account_list_set();
583         }
584 }
585
586 static void account_set_default(void)
587 {
588         GtkCList *clist = GTK_CLIST(edit_account.clist);
589         gint row;
590         PrefsAccount *ac_prefs;
591
592         if (!clist->selection) return;
593
594         row = GPOINTER_TO_INT(clist->selection->data);
595         ac_prefs = gtk_clist_get_row_data(clist, row);
596         account_set_as_default(ac_prefs);
597         account_clist_set();
598
599         cur_account = ac_prefs;
600         account_set_menu();
601         main_window_reflect_prefs_all();
602 }
603
604 static void account_edit_close(void)
605 {
606         account_list_set();
607         account_save_config_all();
608
609         if (!cur_account && account_list) {
610                 PrefsAccount *ac_prefs = (PrefsAccount *)account_list->data;
611                 account_set_as_default(ac_prefs);
612                 cur_account = ac_prefs;
613         }
614
615         account_set_menu();
616         main_window_reflect_prefs_all();
617
618         gtk_widget_hide(edit_account.window);
619
620         inc_autocheck_timer_set();
621 }
622
623 static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
624                                  gpointer data)
625 {
626         account_edit_close();
627         return TRUE;
628 }
629
630 static void account_selected(GtkCList *clist, gint row, gint column,
631                              GdkEvent *event, gpointer data)
632 {
633         if (event && event->type == GDK_2BUTTON_PRESS)
634                 account_edit_prefs();
635 }
636
637 static void account_key_pressed(GtkWidget *widget, GdkEventKey *event,
638                                 gpointer data)
639 {
640         if (event && event->keyval == GDK_Escape)
641                 account_edit_close();
642 }
643
644 /* set one CList row or add new row */
645 static gint account_clist_set_row(PrefsAccount *ac_prefs, gint row)
646 {
647         GtkCList *clist = GTK_CLIST(edit_account.clist);
648         gchar *text[N_EDIT_ACCOUNT_COLS];
649
650         text[COL_DEFAULT] = ac_prefs->is_default ? "*" : "";
651         text[COL_NAME] = ac_prefs->account_name;
652         text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3  ? "POP3"  :
653                              ac_prefs->protocol == A_APOP  ? "APOP"  :
654                              ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
655                              ac_prefs->protocol == A_LOCAL ? "Local" :
656                              ac_prefs->protocol == A_NNTP  ? "NNTP"  :  "";
657         text[COL_SERVER] = ac_prefs->protocol == A_NNTP
658                 ? ac_prefs->nntp_server : ac_prefs->recv_server;
659
660         if (row < 0)
661                 row = gtk_clist_append(clist, text);
662         else {
663                 gtk_clist_set_text(clist, row, COL_DEFAULT, text[COL_DEFAULT]);
664                 gtk_clist_set_text(clist, row, COL_NAME, text[COL_NAME]);
665                 gtk_clist_set_text(clist, row, COL_PROTOCOL, text[COL_PROTOCOL]);
666                 gtk_clist_set_text(clist, row, COL_SERVER, text[COL_SERVER]);
667         }
668
669         gtk_clist_set_row_data(clist, row, ac_prefs);
670
671         return row;
672 }
673
674 /* set CList from account list */
675 static void account_clist_set(void)
676 {
677         GtkCList *clist = GTK_CLIST(edit_account.clist);
678         GList *cur;
679         gint prev_row;
680
681         if (clist->selection)
682                 prev_row = GPOINTER_TO_INT(clist->selection->data);
683         else
684                 prev_row = -1;
685
686         gtk_clist_freeze(clist);
687         gtk_clist_clear(clist);
688
689         for (cur = account_list; cur != NULL; cur = cur->next) {
690                 gint row;
691
692                 row = account_clist_set_row((PrefsAccount *)cur->data, -1);
693                 if ((PrefsAccount *)cur->data == cur_account) {
694                         gtk_clist_select_row(clist, row, -1);
695                         gtkut_clist_set_focus_row(clist, row);
696                 }
697         }
698
699         if (prev_row >= 0) {
700                 gtk_clist_select_row(clist, prev_row, -1);
701                 gtkut_clist_set_focus_row(clist, prev_row);
702         }
703
704         gtk_clist_thaw(clist);
705 }
706
707 /* set account list from CList */
708 static void account_list_set(void)
709 {
710         GtkCList *clist = GTK_CLIST(edit_account.clist);
711         gint row;
712         PrefsAccount *ac_prefs;
713
714         while (account_list)
715                 account_list = g_list_remove(account_list, account_list->data);
716
717         for (row = 0; (ac_prefs = gtk_clist_get_row_data(clist, row)) != NULL;
718              row++)
719                 account_list = g_list_append(account_list, ac_prefs);
720 }