sync with Hiroyuki's 0.5.0claws2-3
[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_mail_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_mail_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 &&
191                     !strcmp2(address, ac->address))
192                         return ac;
193         }
194
195         return NULL;
196 }
197
198 PrefsAccount *account_find_from_id(gint id)
199 {
200         GList *cur;
201         PrefsAccount *ac;
202
203         for (cur = account_list; cur != NULL; cur = cur->next) {
204                 ac = (PrefsAccount *)cur->data;
205                 if (id == ac->account_id)
206                         return ac;
207         }
208
209         return NULL;
210 }
211
212 void account_set_menu(void)
213 {
214         main_window_set_account_menu(account_list);
215 }
216
217 void account_foreach(AccountFunc func, gpointer user_data)
218 {
219         GList *cur;
220
221         for (cur = account_list; cur != NULL; cur = cur->next)
222                 if (func((PrefsAccount *)cur->data, user_data) != 0)
223                         return;
224 }
225
226 GList *account_get_list(void)
227 {
228         return account_list;
229 }
230
231 void account_edit_open(void)
232 {
233         inc_autocheck_timer_remove();
234
235         if (compose_get_compose_list()) {
236                 alertpanel_notice(_("Some composing windows are open.\n"
237                                     "Please close all the composing windows before editing the accounts."));
238                 inc_autocheck_timer_set();
239                 return;
240         }
241
242         debug_print(_("Opening account edit window...\n"));
243
244         if (!edit_account.window)
245                 account_edit_create();
246
247         account_clist_set();
248
249         manage_window_set_transient(GTK_WINDOW(edit_account.window));
250         gtk_widget_grab_focus(edit_account.close_btn);
251         gtk_widget_show(edit_account.window);
252
253         manage_window_focus_in(edit_account.window, NULL, NULL);
254 }
255
256 void account_add(void)
257 {
258         PrefsAccount *ac_prefs;
259
260         ac_prefs = prefs_account_open(NULL);
261         inc_autocheck_timer_remove();
262
263         if (!ac_prefs) return;
264
265         account_list = g_list_append(account_list, ac_prefs);
266
267         if (ac_prefs->is_default)
268                 account_set_as_default(ac_prefs);
269
270         account_clist_set();
271
272         if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
273                 Folder *folder;
274
275                 if (ac_prefs->protocol == A_IMAP4) {
276                         folder = folder_new(F_IMAP, ac_prefs->account_name,
277                                             ac_prefs->recv_server);
278                 } else {
279                         folder = folder_new(F_NEWS, ac_prefs->account_name,
280                                             ac_prefs->nntp_server);
281                 }
282
283                 folder->account = ac_prefs;
284                 ac_prefs->folder = REMOTE_FOLDER(folder);
285                 folder_add(folder);
286                 if (ac_prefs->protocol == A_IMAP4)
287                         folder->create_tree(folder);
288                 folderview_set_all();
289         }
290 }
291
292 void account_set_as_default(PrefsAccount *ac_prefs)
293 {
294         PrefsAccount *ap;
295         GList *cur;
296
297         for (cur = account_list; cur != NULL; cur = cur->next) {
298                 ap = (PrefsAccount *)cur->data;
299                 if (ap->is_default)
300                         ap->is_default = FALSE;
301         }
302
303         ac_prefs->is_default = TRUE;
304 }
305
306 PrefsAccount *account_get_default(void)
307 {
308         PrefsAccount *ap;
309         GList *cur;
310
311         for (cur = account_list; cur != NULL; cur = cur->next) {
312                 ap = (PrefsAccount *)cur->data;
313                 if (ap->is_default)
314                         return ap;
315         }
316
317         return NULL;
318 }
319
320 void account_set_missing_folder(void)
321 {
322         PrefsAccount *ap;
323         GList *cur;
324
325         for (cur = account_list; cur != NULL; cur = cur->next) {
326                 ap = (PrefsAccount *)cur->data;
327                 if ((ap->protocol == A_IMAP4 || ap->protocol == A_NNTP) &&
328                     !ap->folder) {
329                         Folder *folder;
330
331                         if (ap->protocol == A_IMAP4) {
332                                 folder = folder_new(F_IMAP, ap->account_name,
333                                                     ap->recv_server);
334                         } else {
335                                 folder = folder_new(F_NEWS, ap->account_name,
336                                                     ap->nntp_server);
337                         }
338
339                         folder->account = ap;
340                         ap->folder = REMOTE_FOLDER(folder);
341                         folder_add(folder);
342                         if (ap->protocol == A_IMAP4)
343                                 folder->create_tree(folder);
344                 }
345         }
346 }
347
348 void account_destroy(PrefsAccount *ac_prefs)
349 {
350         g_return_if_fail(ac_prefs != NULL);
351
352         prefs_account_free(ac_prefs);
353         account_list = g_list_remove(account_list, ac_prefs);
354
355         if (cur_account == ac_prefs) cur_account = NULL;
356         if (!cur_account && account_list) {
357                 cur_account = account_get_default();
358                 if (!cur_account) {
359                         ac_prefs = (PrefsAccount *)account_list->data;
360                         account_set_as_default(ac_prefs);
361                         cur_account = ac_prefs;
362                 }
363         }
364 }
365
366
367 static void account_edit_create(void)
368 {
369         GtkWidget *window;
370         GtkWidget *vbox;
371         GtkWidget *hbox;
372         GtkWidget *scrolledwin;
373         GtkWidget *clist;
374         gchar *titles[N_EDIT_ACCOUNT_COLS];
375         gint i;
376
377         GtkWidget *vbox2;
378         GtkWidget *add_btn;
379         GtkWidget *edit_btn;
380         GtkWidget *del_btn;
381         GtkWidget *up_btn;
382         GtkWidget *down_btn;
383
384         GtkWidget *default_btn;
385
386         GtkWidget *hbbox;
387         GtkWidget *close_btn;
388
389         debug_print(_("Creating account edit window...\n"));
390
391         window = gtk_window_new (GTK_WINDOW_DIALOG);
392         gtk_widget_set_usize (window, 500, 320);
393         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
394         gtk_window_set_title (GTK_WINDOW (window), _("Edit accounts"));
395         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
396         gtk_signal_connect (GTK_OBJECT (window), "delete_event",
397                             GTK_SIGNAL_FUNC (account_delete_event), NULL);
398         gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
399                             GTK_SIGNAL_FUNC (account_key_pressed), NULL);
400         gtk_signal_connect (GTK_OBJECT (window), "focus_in_event",
401                             GTK_SIGNAL_FUNC (manage_window_focus_in), NULL);
402         gtk_signal_connect (GTK_OBJECT (window), "focus_out_event",
403                             GTK_SIGNAL_FUNC (manage_window_focus_out), NULL);
404
405         vbox = gtk_vbox_new (FALSE, 12);
406         gtk_widget_show (vbox);
407         gtk_container_add (GTK_CONTAINER (window), vbox);
408
409         hbox = gtk_hbox_new (FALSE, 8);
410         gtk_widget_show (hbox);
411         gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
412         gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
413
414         scrolledwin = gtk_scrolled_window_new (NULL, NULL);
415         gtk_widget_show (scrolledwin);
416         gtk_box_pack_start (GTK_BOX (hbox), scrolledwin, TRUE, TRUE, 0);
417         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin),
418                                         GTK_POLICY_AUTOMATIC,
419                                         GTK_POLICY_AUTOMATIC);
420
421         titles[COL_DEFAULT]  = "";
422         titles[COL_NAME]     = _("Name");
423         titles[COL_PROTOCOL] = _("Protocol");
424         titles[COL_SERVER]   = _("Server");
425
426         clist = gtk_clist_new_with_titles (N_EDIT_ACCOUNT_COLS, titles);
427         gtk_widget_show (clist);
428         gtk_container_add (GTK_CONTAINER (scrolledwin), clist);
429         gtk_clist_set_column_width (GTK_CLIST(clist), COL_DEFAULT , 16);
430         gtk_clist_set_column_width (GTK_CLIST(clist), COL_NAME    , 100);
431         gtk_clist_set_column_width (GTK_CLIST(clist), COL_PROTOCOL, 70);
432         gtk_clist_set_column_width (GTK_CLIST(clist), COL_SERVER  , 100);
433         gtk_clist_set_selection_mode (GTK_CLIST(clist), GTK_SELECTION_BROWSE);
434
435         for (i = 0; i < N_EDIT_ACCOUNT_COLS; i++)
436                 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button,
437                                        GTK_CAN_FOCUS);
438
439         gtk_signal_connect (GTK_OBJECT (clist), "select_row",
440                             GTK_SIGNAL_FUNC (account_selected), NULL);
441
442         vbox2 = gtk_vbox_new (FALSE, 0);
443         gtk_widget_show (vbox2);
444         gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
445
446         add_btn = gtk_button_new_with_label (_("Add"));
447         gtk_widget_show (add_btn);
448         gtk_box_pack_start (GTK_BOX (vbox2), add_btn, FALSE, FALSE, 4);
449         gtk_signal_connect (GTK_OBJECT(add_btn), "clicked",
450                             GTK_SIGNAL_FUNC (account_add), NULL);
451
452         edit_btn = gtk_button_new_with_label (_("Edit"));
453         gtk_widget_show (edit_btn);
454         gtk_box_pack_start (GTK_BOX (vbox2), edit_btn, FALSE, FALSE, 4);
455         gtk_signal_connect (GTK_OBJECT(edit_btn), "clicked",
456                             GTK_SIGNAL_FUNC (account_edit_prefs), NULL);
457
458         del_btn = gtk_button_new_with_label (_(" Delete "));
459         gtk_widget_show (del_btn);
460         gtk_box_pack_start (GTK_BOX (vbox2), del_btn, FALSE, FALSE, 4);
461         gtk_signal_connect (GTK_OBJECT(del_btn), "clicked",
462                             GTK_SIGNAL_FUNC (account_delete), NULL);
463
464         down_btn = gtk_button_new_with_label (_("Down"));
465         gtk_widget_show (down_btn);
466         gtk_box_pack_end (GTK_BOX (vbox2), down_btn, FALSE, FALSE, 4);
467         gtk_signal_connect (GTK_OBJECT(down_btn), "clicked",
468                             GTK_SIGNAL_FUNC (account_down), NULL);
469
470         up_btn = gtk_button_new_with_label (_("Up"));
471         gtk_widget_show (up_btn);
472         gtk_box_pack_end (GTK_BOX (vbox2), up_btn, FALSE, FALSE, 4);
473         gtk_signal_connect (GTK_OBJECT(up_btn), "clicked",
474                             GTK_SIGNAL_FUNC (account_up), NULL);
475
476         hbox = gtk_hbox_new (FALSE, 8);
477         gtk_widget_show (hbox);
478         gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
479
480         vbox2 = gtk_vbox_new(FALSE, 0);
481         gtk_widget_show (vbox2);
482         gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
483
484         default_btn = gtk_button_new_with_label (_(" Set as usually used account "));
485         gtk_widget_show (default_btn);
486         gtk_box_pack_start (GTK_BOX (vbox2), default_btn, TRUE, FALSE, 0);
487         gtk_signal_connect (GTK_OBJECT(default_btn), "clicked",
488                             GTK_SIGNAL_FUNC (account_set_default), NULL);
489
490         gtkut_button_set_create(&hbbox, &close_btn, _("Close"),
491                                 NULL, NULL, NULL, NULL);
492         gtk_widget_show(hbbox);
493         gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
494         gtk_widget_grab_default (close_btn);
495
496         gtk_signal_connect (GTK_OBJECT (close_btn), "clicked",
497                             GTK_SIGNAL_FUNC (account_edit_close),
498                             NULL);
499
500         edit_account.window    = window;
501         edit_account.clist     = clist;
502         edit_account.close_btn = close_btn;
503 }
504
505 static void account_edit_prefs(void)
506 {
507         GtkCList *clist = GTK_CLIST(edit_account.clist);
508         PrefsAccount *ac_prefs;
509         gint row;
510         gboolean prev_default;
511         gchar *ac_name;
512
513         if (!clist->selection) return;
514
515         row = GPOINTER_TO_INT(clist->selection->data);
516         ac_prefs = gtk_clist_get_row_data(clist, row);
517         prev_default = ac_prefs->is_default;
518         Xstrdup_a(ac_name, ac_prefs->account_name, return);
519
520         prefs_account_open(ac_prefs);
521         inc_autocheck_timer_remove();
522
523         if (!prev_default && ac_prefs->is_default)
524                 account_set_as_default(ac_prefs);
525
526         if ((ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) &&
527             ac_prefs->folder && strcmp(ac_name, ac_prefs->account_name) != 0) {
528                 folder_set_name(FOLDER(ac_prefs->folder),
529                                 ac_prefs->account_name);
530                 folderview_update_all();
531         }
532
533         account_clist_set();
534 }
535
536 static void account_delete(void)
537 {
538         GtkCList *clist = GTK_CLIST(edit_account.clist);
539         PrefsAccount *ac_prefs;
540         gint row;
541
542         if (!clist->selection) return;
543
544         if (alertpanel(_("Delete account"),
545                        _("Do you really want to delete this account?"),
546                        _("Yes"), _("+No"), NULL) != G_ALERTDEFAULT)
547                 return;
548
549         row = GPOINTER_TO_INT(clist->selection->data);
550         ac_prefs = gtk_clist_get_row_data(clist, row);
551         if (ac_prefs->folder) {
552                 folder_destroy(FOLDER(ac_prefs->folder));
553                 folderview_update_all();
554         }
555         account_destroy(ac_prefs);
556         account_clist_set();
557 }
558
559 static void account_up(void)
560 {
561         GtkCList *clist = GTK_CLIST(edit_account.clist);
562         gint row;
563
564         if (!clist->selection) return;
565
566         row = GPOINTER_TO_INT(clist->selection->data);
567         if (row > 0) {
568                 gtk_clist_row_move(clist, row, row - 1);
569                 account_list_set();
570         }
571 }
572
573 static void account_down(void)
574 {
575         GtkCList *clist = GTK_CLIST(edit_account.clist);
576         gint row;
577
578         if (!clist->selection) return;
579
580         row = GPOINTER_TO_INT(clist->selection->data);
581         if (row < clist->rows - 1) {
582                 gtk_clist_row_move(clist, row, row + 1);
583                 account_list_set();
584         }
585 }
586
587 static void account_set_default(void)
588 {
589         GtkCList *clist = GTK_CLIST(edit_account.clist);
590         gint row;
591         PrefsAccount *ac_prefs;
592
593         if (!clist->selection) return;
594
595         row = GPOINTER_TO_INT(clist->selection->data);
596         ac_prefs = gtk_clist_get_row_data(clist, row);
597         account_set_as_default(ac_prefs);
598         account_clist_set();
599
600         cur_account = ac_prefs;
601         account_set_menu();
602         main_window_reflect_prefs_all();
603 }
604
605 static void account_edit_close(void)
606 {
607         account_list_set();
608         account_save_config_all();
609
610         if (!cur_account && account_list) {
611                 PrefsAccount *ac_prefs = (PrefsAccount *)account_list->data;
612                 account_set_as_default(ac_prefs);
613                 cur_account = ac_prefs;
614         }
615
616         account_set_menu();
617         main_window_reflect_prefs_all();
618
619         gtk_widget_hide(edit_account.window);
620
621         inc_autocheck_timer_set();
622 }
623
624 static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
625                                  gpointer data)
626 {
627         account_edit_close();
628         return TRUE;
629 }
630
631 static void account_selected(GtkCList *clist, gint row, gint column,
632                              GdkEvent *event, gpointer data)
633 {
634         if (event && event->type == GDK_2BUTTON_PRESS)
635                 account_edit_prefs();
636 }
637
638 static void account_key_pressed(GtkWidget *widget, GdkEventKey *event,
639                                 gpointer data)
640 {
641         if (event && event->keyval == GDK_Escape)
642                 account_edit_close();
643 }
644
645 /* set one CList row or add new row */
646 static gint account_clist_set_row(PrefsAccount *ac_prefs, gint row)
647 {
648         GtkCList *clist = GTK_CLIST(edit_account.clist);
649         gchar *text[N_EDIT_ACCOUNT_COLS];
650
651         text[COL_DEFAULT] = ac_prefs->is_default ? "*" : "";
652         text[COL_NAME] = ac_prefs->account_name;
653         text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3  ? "POP3"  :
654                              ac_prefs->protocol == A_APOP  ? "APOP"  :
655                              ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
656                              ac_prefs->protocol == A_LOCAL ? "Local" :
657                              ac_prefs->protocol == A_NNTP  ? "NNTP"  :  "";
658         text[COL_SERVER] = ac_prefs->protocol == A_NNTP
659                 ? ac_prefs->nntp_server : ac_prefs->recv_server;
660
661         if (row < 0)
662                 row = gtk_clist_append(clist, text);
663         else {
664                 gtk_clist_set_text(clist, row, COL_DEFAULT, text[COL_DEFAULT]);
665                 gtk_clist_set_text(clist, row, COL_NAME, text[COL_NAME]);
666                 gtk_clist_set_text(clist, row, COL_PROTOCOL, text[COL_PROTOCOL]);
667                 gtk_clist_set_text(clist, row, COL_SERVER, text[COL_SERVER]);
668         }
669
670         gtk_clist_set_row_data(clist, row, ac_prefs);
671
672         return row;
673 }
674
675 /* set CList from account list */
676 static void account_clist_set(void)
677 {
678         GtkCList *clist = GTK_CLIST(edit_account.clist);
679         GList *cur;
680         gint prev_row;
681
682         if (clist->selection)
683                 prev_row = GPOINTER_TO_INT(clist->selection->data);
684         else
685                 prev_row = -1;
686
687         gtk_clist_freeze(clist);
688         gtk_clist_clear(clist);
689
690         for (cur = account_list; cur != NULL; cur = cur->next) {
691                 gint row;
692
693                 row = account_clist_set_row((PrefsAccount *)cur->data, -1);
694                 if ((PrefsAccount *)cur->data == cur_account) {
695                         gtk_clist_select_row(clist, row, -1);
696                         gtkut_clist_set_focus_row(clist, row);
697                 }
698         }
699
700         if (prev_row >= 0) {
701                 gtk_clist_select_row(clist, prev_row, -1);
702                 gtkut_clist_set_focus_row(clist, prev_row);
703         }
704
705         gtk_clist_thaw(clist);
706 }
707
708 /* set account list from CList */
709 static void account_list_set(void)
710 {
711         GtkCList *clist = GTK_CLIST(edit_account.clist);
712         gint row;
713         PrefsAccount *ac_prefs;
714
715         while (account_list)
716                 account_list = g_list_remove(account_list, account_list->data);
717
718         for (row = 0; (ac_prefs = gtk_clist_get_row_data(clist, row)) != NULL;
719              row++)
720                 account_list = g_list_append(account_list, ac_prefs);
721 }