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