sync with sylpheed 0.4.99cvs11
[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_key_pressed         (GtkWidget      *widget,
84                                          GdkEventKey    *event,
85                                          gpointer        data);
86
87 static gint account_clist_set_row       (PrefsAccount   *ac_prefs,
88                                          gint            row);
89 static void account_clist_set           (void);
90
91 static void account_list_set            (void);
92
93 void account_read_config_all(void)
94 {
95         GSList *ac_label_list = NULL, *cur;
96         gchar *rcpath;
97         FILE *fp;
98         gchar buf[PREFSBUFSIZE];
99         PrefsAccount *ac_prefs;
100
101         debug_print(_("Reading all config for each account...\n"));
102
103         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
104         if ((fp = fopen(rcpath, "r")) == NULL) {
105                 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
106                 g_free(rcpath);
107                 return;
108         }
109         g_free(rcpath);
110
111         while (fgets(buf, sizeof(buf), fp) != NULL) {
112                 if (!strncmp(buf, "[Account: ", 10)) {
113                         strretchomp(buf);
114                         memmove(buf, buf + 1, strlen(buf));
115                         buf[strlen(buf) - 1] = '\0';
116                         debug_print(_("Found label: %s\n"), buf);
117                         ac_label_list = g_slist_append(ac_label_list,
118                                                        g_strdup(buf));
119                 }
120         }
121         fclose(fp);
122
123         /* read config data from file */
124         cur_account = NULL;
125         for (cur = ac_label_list; cur != NULL; cur = cur->next) {
126                 ac_prefs = g_new0(PrefsAccount, 1);
127                 prefs_account_read_config(ac_prefs, (gchar *)cur->data);
128                 account_list = g_list_append(account_list, ac_prefs);
129                 if (ac_prefs->is_default)
130                         cur_account = ac_prefs;
131         }
132         /* if default is not set, assume first account as default */
133         if (!cur_account && account_list) {
134                 ac_prefs = (PrefsAccount *)account_list->data;
135                 account_set_as_default(ac_prefs);
136                 cur_account = ac_prefs;
137         }
138
139         account_set_menu();
140         main_window_reflect_prefs_all();
141
142         while (ac_label_list) {
143                 g_free(ac_label_list->data);
144                 ac_label_list = g_slist_remove(ac_label_list,
145                                                ac_label_list->data);
146         }
147 }
148
149 void account_save_config_all(void)
150 {
151         prefs_account_save_config_all(account_list);
152 }
153
154 PrefsAccount *account_find_from_smtp_server(const gchar *address,
155                                             const gchar *smtp_server)
156 {
157         GList *cur;
158         PrefsAccount *ac;
159
160         for (cur = account_list; cur != NULL; cur = cur->next) {
161                 ac = (PrefsAccount *)cur->data;
162                 if (!strcmp2(address, ac->address) &&
163                     !strcmp2(smtp_server, ac->smtp_server))
164                         return ac;
165         }
166
167         return NULL;
168 }
169
170 /**
171  * account_find_mail_from_address:
172  * @address: Email address string.
173  * 
174  * Find a mail (not news) account with the specified email address.
175  * 
176  * Return value: The found account, or NULL if not found.
177  **/
178 PrefsAccount *account_find_mail_from_address(const gchar *address)
179 {
180         GList *cur;
181         PrefsAccount *ac;
182
183         for (cur = account_list; cur != NULL; cur = cur->next) {
184                 ac = (PrefsAccount *)cur->data;
185                 if (ac->protocol != A_NNTP &&
186                     !strcmp2(address, ac->address))
187                         return ac;
188         }
189
190         return NULL;
191 }
192
193 PrefsAccount *account_find_from_id(gint id)
194 {
195         GList *cur;
196         PrefsAccount *ac;
197
198         for (cur = account_list; cur != NULL; cur = cur->next) {
199                 ac = (PrefsAccount *)cur->data;
200                 if (id == ac->account_id)
201                         return ac;
202         }
203
204         return NULL;
205 }
206
207 void account_set_menu(void)
208 {
209         main_window_set_account_menu(account_list);
210 }
211
212 void account_foreach(AccountFunc func, gpointer user_data)
213 {
214         GList *cur;
215
216         for (cur = account_list; cur != NULL; cur = cur->next)
217                 if (func((PrefsAccount *)cur->data, user_data) != 0)
218                         return;
219 }
220
221 GList *account_get_list(void)
222 {
223         return account_list;
224 }
225
226 void account_edit_open(void)
227 {
228         inc_autocheck_timer_remove();
229
230         if (compose_get_compose_list()) {
231                 alertpanel_notice(_("Some composing windows are open.\n"
232                                     "Please close all the composing windows before editing the accounts."));
233                 inc_autocheck_timer_set();
234                 return;
235         }
236
237         debug_print(_("Opening account edit window...\n"));
238
239         if (!edit_account.window)
240                 account_edit_create();
241
242         account_clist_set();
243
244         manage_window_set_transient(GTK_WINDOW(edit_account.window));
245         gtk_widget_grab_focus(edit_account.close_btn);
246         gtk_widget_show(edit_account.window);
247
248         manage_window_focus_in(edit_account.window, NULL, NULL);
249 }
250
251 void account_add(void)
252 {
253         PrefsAccount *ac_prefs;
254
255         ac_prefs = prefs_account_open(NULL);
256         inc_autocheck_timer_remove();
257
258         if (!ac_prefs) return;
259
260         account_list = g_list_append(account_list, ac_prefs);
261
262         if (ac_prefs->is_default)
263                 account_set_as_default(ac_prefs);
264
265         account_clist_set();
266
267         if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
268                 Folder *folder;
269
270                 if (ac_prefs->protocol == A_IMAP4) {
271                         folder = folder_new(F_IMAP, ac_prefs->account_name,
272                                             ac_prefs->recv_server);
273                         folder_item_append(FOLDER_ITEM(folder->node->data),
274                                            folder_item_new("INBOX", "INBOX"));
275                 } else {
276                         folder = folder_new(F_NEWS, ac_prefs->account_name,
277                                             ac_prefs->nntp_server);
278                 }
279
280                 folder->account = ac_prefs;
281                 ac_prefs->folder = REMOTE_FOLDER(folder);
282                 folder_add(folder);
283                 if (ac_prefs->protocol == A_IMAP4)
284                         folder->create_tree(folder);
285                 folderview_update_all();
286         }
287 }
288
289 void account_set_as_default(PrefsAccount *ac_prefs)
290 {
291         PrefsAccount *ap;
292         GList *cur;
293
294         for (cur = account_list; cur != NULL; cur = cur->next) {
295                 ap = (PrefsAccount *)cur->data;
296                 if (ap->is_default)
297                         ap->is_default = FALSE;
298         }
299
300         ac_prefs->is_default = TRUE;
301 }
302
303 PrefsAccount *account_get_default(void)
304 {
305         PrefsAccount *ap;
306         GList *cur;
307
308         for (cur = account_list; cur != NULL; cur = cur->next) {
309                 ap = (PrefsAccount *)cur->data;
310                 if (ap->is_default)
311                         return ap;
312         }
313
314         return NULL;
315 }
316
317 void account_set_missing_folder(void)
318 {
319         PrefsAccount *ap;
320         GList *cur;
321
322         for (cur = account_list; cur != NULL; cur = cur->next) {
323                 ap = (PrefsAccount *)cur->data;
324                 if ((ap->protocol == A_IMAP4 || ap->protocol == A_NNTP) &&
325                     !ap->folder) {
326                         Folder *folder;
327
328                         if (ap->protocol == A_IMAP4) {
329                                 folder = folder_new(F_IMAP, ap->account_name,
330                                                     ap->recv_server);
331                                 folder_item_append
332                                         (FOLDER_ITEM(folder->node->data),
333                                          folder_item_new("INBOX", "INBOX"));
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         vbox2 = gtk_vbox_new (FALSE, 0);
440         gtk_widget_show (vbox2);
441         gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
442
443         add_btn = gtk_button_new_with_label (_("Add"));
444         gtk_widget_show (add_btn);
445         gtk_box_pack_start (GTK_BOX (vbox2), add_btn, FALSE, FALSE, 4);
446         gtk_signal_connect (GTK_OBJECT(add_btn), "clicked",
447                             GTK_SIGNAL_FUNC (account_add), NULL);
448
449         edit_btn = gtk_button_new_with_label (_("Edit"));
450         gtk_widget_show (edit_btn);
451         gtk_box_pack_start (GTK_BOX (vbox2), edit_btn, FALSE, FALSE, 4);
452         gtk_signal_connect (GTK_OBJECT(edit_btn), "clicked",
453                             GTK_SIGNAL_FUNC (account_edit_prefs), NULL);
454
455         del_btn = gtk_button_new_with_label (_(" Delete "));
456         gtk_widget_show (del_btn);
457         gtk_box_pack_start (GTK_BOX (vbox2), del_btn, FALSE, FALSE, 4);
458         gtk_signal_connect (GTK_OBJECT(del_btn), "clicked",
459                             GTK_SIGNAL_FUNC (account_delete), NULL);
460
461         down_btn = gtk_button_new_with_label (_("Down"));
462         gtk_widget_show (down_btn);
463         gtk_box_pack_end (GTK_BOX (vbox2), down_btn, FALSE, FALSE, 4);
464         gtk_signal_connect (GTK_OBJECT(down_btn), "clicked",
465                             GTK_SIGNAL_FUNC (account_down), NULL);
466
467         up_btn = gtk_button_new_with_label (_("Up"));
468         gtk_widget_show (up_btn);
469         gtk_box_pack_end (GTK_BOX (vbox2), up_btn, FALSE, FALSE, 4);
470         gtk_signal_connect (GTK_OBJECT(up_btn), "clicked",
471                             GTK_SIGNAL_FUNC (account_up), NULL);
472
473         hbox = gtk_hbox_new (FALSE, 8);
474         gtk_widget_show (hbox);
475         gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
476
477         vbox2 = gtk_vbox_new(FALSE, 0);
478         gtk_widget_show (vbox2);
479         gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
480
481         default_btn = gtk_button_new_with_label (_(" Set as usually used account "));
482         gtk_widget_show (default_btn);
483         gtk_box_pack_start (GTK_BOX (vbox2), default_btn, TRUE, FALSE, 0);
484         gtk_signal_connect (GTK_OBJECT(default_btn), "clicked",
485                             GTK_SIGNAL_FUNC (account_set_default), NULL);
486
487         gtkut_button_set_create(&hbbox, &close_btn, _("Close"),
488                                 NULL, NULL, NULL, NULL);
489         gtk_widget_show(hbbox);
490         gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
491         gtk_widget_grab_default (close_btn);
492
493         gtk_signal_connect (GTK_OBJECT (close_btn), "clicked",
494                             GTK_SIGNAL_FUNC (account_edit_close),
495                             NULL);
496
497         edit_account.window    = window;
498         edit_account.clist     = clist;
499         edit_account.close_btn = close_btn;
500 }
501
502 static void account_edit_prefs(void)
503 {
504         GtkCList *clist = GTK_CLIST(edit_account.clist);
505         PrefsAccount *ac_prefs;
506         gint row;
507         gboolean prev_default;
508         gchar *ac_name;
509
510         if (!clist->selection) return;
511
512         row = GPOINTER_TO_INT(clist->selection->data);
513         ac_prefs = gtk_clist_get_row_data(clist, row);
514         prev_default = ac_prefs->is_default;
515         Xstrdup_a(ac_name, ac_prefs->account_name, return);
516
517         prefs_account_open(ac_prefs);
518         inc_autocheck_timer_remove();
519
520         if (!prev_default && ac_prefs->is_default)
521                 account_set_as_default(ac_prefs);
522
523         if ((ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) &&
524             ac_prefs->folder && strcmp(ac_name, ac_prefs->account_name) != 0) {
525                 folder_set_name(FOLDER(ac_prefs->folder),
526                                 ac_prefs->account_name);
527                 folderview_update_all();
528         }
529
530         account_clist_set();
531 }
532
533 static void account_delete(void)
534 {
535         GtkCList *clist = GTK_CLIST(edit_account.clist);
536         PrefsAccount *ac_prefs;
537         gint row;
538
539         if (!clist->selection) return;
540
541         if (alertpanel(_("Delete account"),
542                        _("Do you really want to delete this account?"),
543                        _("Yes"), _("+No"), NULL) != G_ALERTDEFAULT)
544                 return;
545
546         row = GPOINTER_TO_INT(clist->selection->data);
547         ac_prefs = gtk_clist_get_row_data(clist, row);
548         if (ac_prefs->folder) {
549                 folder_destroy(FOLDER(ac_prefs->folder));
550                 folderview_update_all();
551         }
552         account_destroy(ac_prefs);
553         account_clist_set();
554 }
555
556 static void account_up(void)
557 {
558         GtkCList *clist = GTK_CLIST(edit_account.clist);
559         gint row;
560
561         if (!clist->selection) return;
562
563         row = GPOINTER_TO_INT(clist->selection->data);
564         if (row > 0) {
565                 gtk_clist_row_move(clist, row, row - 1);
566                 account_list_set();
567         }
568 }
569
570 static void account_down(void)
571 {
572         GtkCList *clist = GTK_CLIST(edit_account.clist);
573         gint row;
574
575         if (!clist->selection) return;
576
577         row = GPOINTER_TO_INT(clist->selection->data);
578         if (row < clist->rows - 1) {
579                 gtk_clist_row_move(clist, row, row + 1);
580                 account_list_set();
581         }
582 }
583
584 static void account_set_default(void)
585 {
586         GtkCList *clist = GTK_CLIST(edit_account.clist);
587         gint row;
588         PrefsAccount *ac_prefs;
589
590         if (!clist->selection) return;
591
592         row = GPOINTER_TO_INT(clist->selection->data);
593         ac_prefs = gtk_clist_get_row_data(clist, row);
594         account_set_as_default(ac_prefs);
595         account_clist_set();
596
597         cur_account = ac_prefs;
598         account_set_menu();
599         main_window_reflect_prefs_all();
600 }
601
602 static void account_edit_close(void)
603 {
604         account_list_set();
605         account_save_config_all();
606
607         if (!cur_account && account_list) {
608                 PrefsAccount *ac_prefs = (PrefsAccount *)account_list->data;
609                 account_set_as_default(ac_prefs);
610                 cur_account = ac_prefs;
611         }
612
613         account_set_menu();
614         main_window_reflect_prefs_all();
615
616         gtk_widget_hide(edit_account.window);
617
618         inc_autocheck_timer_set();
619 }
620
621 static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
622                                  gpointer data)
623 {
624         account_edit_close();
625         return TRUE;
626 }
627
628 static void account_key_pressed(GtkWidget *widget, GdkEventKey *event,
629                                 gpointer data)
630 {
631         if (event && event->keyval == GDK_Escape)
632                 account_edit_close();
633 }
634
635 /* set one CList row or add new row */
636 static gint account_clist_set_row(PrefsAccount *ac_prefs, gint row)
637 {
638         GtkCList *clist = GTK_CLIST(edit_account.clist);
639         gchar *text[N_EDIT_ACCOUNT_COLS];
640
641         text[COL_DEFAULT] = ac_prefs->is_default ? "*" : "";
642         text[COL_NAME] = ac_prefs->account_name;
643         text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3  ? "POP3"  :
644                              ac_prefs->protocol == A_APOP  ? "APOP"  :
645                              ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
646                              ac_prefs->protocol == A_LOCAL ? "Local" :
647                              ac_prefs->protocol == A_NNTP  ? "NNTP"  :  "";
648         text[COL_SERVER] = ac_prefs->protocol == A_NNTP
649                 ? ac_prefs->nntp_server : ac_prefs->recv_server;
650
651         if (row < 0)
652                 row = gtk_clist_append(clist, text);
653         else {
654                 gtk_clist_set_text(clist, row, COL_DEFAULT, text[COL_DEFAULT]);
655                 gtk_clist_set_text(clist, row, COL_NAME, text[COL_NAME]);
656                 gtk_clist_set_text(clist, row, COL_PROTOCOL, text[COL_PROTOCOL]);
657                 gtk_clist_set_text(clist, row, COL_SERVER, text[COL_SERVER]);
658         }
659
660         gtk_clist_set_row_data(clist, row, ac_prefs);
661
662         return row;
663 }
664
665 /* set CList from account list */
666 static void account_clist_set(void)
667 {
668         GtkCList *clist = GTK_CLIST(edit_account.clist);
669         GList *cur;
670         gint prev_row;
671
672         if (clist->selection)
673                 prev_row = GPOINTER_TO_INT(clist->selection->data);
674         else
675                 prev_row = -1;
676
677         gtk_clist_freeze(clist);
678         gtk_clist_clear(clist);
679
680         for (cur = account_list; cur != NULL; cur = cur->next) {
681                 gint row;
682
683                 row = account_clist_set_row((PrefsAccount *)cur->data, -1);
684                 if ((PrefsAccount *)cur->data == cur_account)
685                         gtk_clist_select_row(clist, row, -1);
686         }
687
688         if (prev_row >= 0)
689                 gtk_clist_select_row(clist, prev_row, -1);
690
691         gtk_clist_thaw(clist);
692 }
693
694 /* set account list from CList */
695 static void account_list_set(void)
696 {
697         GtkCList *clist = GTK_CLIST(edit_account.clist);
698         gint row;
699         PrefsAccount *ac_prefs;
700
701         while (account_list)
702                 account_list = g_list_remove(account_list, account_list->data);
703
704         for (row = 0; (ac_prefs = gtk_clist_get_row_data(clist, row)) != NULL;
705              row++)
706                 account_list = g_list_append(account_list, ac_prefs);
707 }