4649c97d40b5ee80feac18d56429f6e911ffc917
[claws.git] / src / prefs_toolbar.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2002 Hiroyuki Yamamoto & the Sylpheed-Claws team
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 /*
21  * General functions for accessing address book files.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include "defs.h"
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include <gtk/gtk.h>
33 #include <gtk/gtkoptionmenu.h>
34 #include <gdk/gdkkeysyms.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #include "stock_pixmap.h"
39 #include "manage_window.h"
40 #include "gtkutils.h"
41 #include "mainwindow.h"
42 #include "alertpanel.h"
43 #include "prefs_common.h"
44
45 #include "utils.h"
46
47 #include "toolbar.h"
48 #include "prefs_toolbar.h"
49 #include "prefswindow.h"
50 #include "prefs_gtk.h"
51
52 enum
53 {
54         SET_ICON          = 0,
55         SET_FILENAME      = 1,
56         SET_TEXT          = 2,
57         SET_EVENT         = 3,
58         SET_ICON_TEXT     = 4,          /*!< "icon" text (separator) */ 
59         SET_ICON_IS_TEXT  = 5,          /*!< icon is text representation */
60         N_SET_COLUMNS
61 };
62
63 typedef struct _ToolbarPage
64 {
65         PrefsPage  page;
66
67         GtkWidget *window;              /* do not modify */
68
69         GtkWidget *list_view_icons;
70         GtkWidget *list_view_set;
71         GtkWidget *combo_action;
72         GtkWidget *combo_entry;
73         GtkWidget *combo_list;
74         GtkWidget *label_icon_text;
75         GtkWidget *label_action_sel;
76         GtkWidget *entry_icon_text;
77         GtkWidget *combo_syl_action;
78         GtkWidget *combo_syl_list;
79         GtkWidget *combo_syl_entry;
80
81         ToolbarType source;
82         GList      *combo_action_list;
83
84 } ToolbarPage;
85
86 #define ERROR_MSG _("Selected Action already set.\nPlease choose another Action from List")
87
88 static void prefs_toolbar_populate               (ToolbarPage *prefs_toolbar);
89 static gboolean is_duplicate                     (ToolbarPage *prefs_toolbar,
90                                                   gchar            *chosen_action);
91 static void prefs_toolbar_save                   (PrefsPage        *_page);
92
93 static void prefs_toolbar_register               (GtkButton        *button,
94                                                   ToolbarPage *prefs_toolbar);
95 static void prefs_toolbar_substitute             (GtkButton        *button,
96                                                   ToolbarPage *prefs_toolbar);
97 static void prefs_toolbar_delete                 (GtkButton        *button,
98                                                   ToolbarPage *prefs_toolbar);
99
100 static void prefs_toolbar_up                     (GtkButton        *button,
101                                                   ToolbarPage *prefs_toolbar);
102
103 static void prefs_toolbar_down                   (GtkButton        *button,
104                                                   ToolbarPage *prefs_toolbar);
105
106 static void prefs_toolbar_create                 (ToolbarPage *prefs_toolbar);
107
108 static void prefs_toolbar_selection_changed      (GtkList *list, 
109                                                   ToolbarPage *prefs_toolbar);
110
111 static GtkWidget *create_icon_list_view          (ToolbarPage *prefs_toolbar);
112
113 static GtkWidget *create_set_list_view           (ToolbarPage *prefs_toolbar);
114
115 static gboolean icon_list_selected               (GtkTreeSelection *selector,
116                                                   GtkTreeModel *model, 
117                                                   GtkTreePath *path,
118                                                   gboolean currently_selected,
119                                                   ToolbarPage *prefs_toolbar);
120
121 static gboolean set_list_selected                (GtkTreeSelection *selector,
122                                                   GtkTreeModel *model, 
123                                                   GtkTreePath *path,
124                                                   gboolean currently_selected,
125                                                   ToolbarPage *prefs_toolbar);
126
127 void prefs_toolbar_create_widget(PrefsPage *_page, GtkWindow *window, gpointer data)
128 {
129         ToolbarPage *prefs_toolbar = (ToolbarPage *) _page;
130         gchar *win_titles[3];
131         win_titles[TOOLBAR_MAIN]    = _("Main toolbar configuration");
132         win_titles[TOOLBAR_COMPOSE] = _("Compose toolbar configuration");  
133         win_titles[TOOLBAR_MSGVIEW] = _("Message view toolbar configuration");  
134
135         prefs_toolbar->window = GTK_WIDGET(window);
136
137         toolbar_read_config_file(prefs_toolbar->source);
138
139         prefs_toolbar_create(prefs_toolbar);
140         prefs_toolbar_populate(prefs_toolbar);
141 }
142
143 void prefs_toolbar_save(PrefsPage *_page)
144 {
145         ToolbarPage *prefs_toolbar = (ToolbarPage *) _page;
146         GtkTreeView *list_view = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
147         GtkTreeModel *model = gtk_tree_view_get_model(list_view);
148         GtkTreeIter iter;
149         
150         toolbar_clear_list(prefs_toolbar->source);
151
152         if (!gtk_tree_model_iter_n_children(model, NULL)
153         ||  !gtk_tree_model_get_iter_first(model, &iter))
154                 toolbar_set_default(prefs_toolbar->source);
155         else {
156                 do {
157                         ToolbarItem *item;
158                         gchar *fname, *text, *event; 
159                         
160                         item = g_new0(ToolbarItem, 1);
161
162                         gtk_tree_model_get(model, &iter,
163                                            SET_FILENAME, &fname,
164                                            SET_TEXT, &text,
165                                            SET_EVENT, &event,
166                                            -1);
167
168                         /* XXX: remember that G_TYPE_STRING returned by model
169                          * is owned by caller of gtk_tree_model_get() */
170                         item->file  = fname;
171                         item->text  = text;
172                         item->index = toolbar_ret_val_from_descr(event);
173                         g_free(event);
174
175                         /* TODO: save A_SYL_ACTIONS only if they are still active */
176                         toolbar_set_list_item(item, prefs_toolbar->source);
177
178                         g_free(item->file);
179                         g_free(item->text);
180                         g_free(item);
181                 } while (gtk_tree_model_iter_next(model, &iter));
182         }
183
184         toolbar_save_config_file(prefs_toolbar->source);
185
186         if (prefs_toolbar->source == TOOLBAR_MAIN) 
187                 main_window_reflect_prefs_all_real(TRUE);
188         else if (prefs_toolbar->source == TOOLBAR_COMPOSE)
189                 compose_reflect_prefs_pixmap_theme();
190         else if (prefs_toolbar->source == TOOLBAR_MSGVIEW)
191                 messageview_reflect_prefs_pixmap_theme();
192 }
193
194 static void prefs_toolbar_destroy_widget(PrefsPage *_page)
195 {
196         ToolbarPage *prefs_toolbar = (ToolbarPage *) _page;
197
198         g_list_free(prefs_toolbar->combo_action_list);
199         prefs_toolbar->combo_action_list = NULL;
200 }
201
202 static void prefs_toolbar_set_displayed(ToolbarPage *prefs_toolbar)
203 {
204         GSList *cur;
205         GtkTreeView *list_view_set = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
206         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model
207                                                 (list_view_set));
208         GSList *toolbar_list = toolbar_get_list(prefs_toolbar->source);
209         GtkTreeIter iter;
210
211         gtk_list_store_clear(store);
212
213         /* set currently active toolbar entries */
214         for (cur = toolbar_list; cur != NULL; cur = cur->next) {
215                 ToolbarItem *item = (ToolbarItem*) cur->data;
216
217                 gtk_list_store_append(store, &iter);
218         
219                 if (item->index != A_SEPARATOR) {
220                         GdkPixbuf *pix;
221                         StockPixmap icon = stock_pixmap_get_icon(item->file);
222                         
223                         stock_pixbuf_gdk(prefs_toolbar->window, icon, &pix);
224
225                         gtk_list_store_set(store, &iter, 
226                                            SET_ICON, pix,
227                                            SET_FILENAME, item->file,
228                                            SET_TEXT, item->text,
229                                            SET_EVENT, toolbar_ret_descr_from_val(item->index),
230                                            SET_ICON_TEXT, NULL, 
231                                            SET_ICON_IS_TEXT, FALSE,
232                                            -1);
233                 } else {
234                         gtk_list_store_set(store, &iter,
235                                            SET_ICON, NULL,
236                                            SET_FILENAME, toolbar_ret_descr_from_val(A_SEPARATOR),
237                                            SET_TEXT, (const gchar *) "", 
238                                            SET_EVENT, toolbar_ret_descr_from_val(A_SEPARATOR),
239                                            SET_ICON_TEXT, (const gchar *) SEPARATOR_PIXMAP,
240                                            SET_ICON_IS_TEXT, TRUE,
241                                            -1);
242                 }
243         }
244
245         /* select first */
246         gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
247         gtk_tree_selection_select_iter(gtk_tree_view_get_selection
248                                                 (list_view_set),
249                                        &iter);  
250 }
251
252 static void prefs_toolbar_populate(ToolbarPage *prefs_toolbar)
253 {
254         gint i;
255         GSList *cur;
256         GList *syl_actions = NULL;
257         GtkTreeView *list_view_icons = GTK_TREE_VIEW
258                         (prefs_toolbar->list_view_icons);
259         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model
260                                                 (list_view_icons));                     
261         gchar *act;
262         GtkTreeIter iter;
263         
264         gtk_list_store_clear(store);
265
266         /* set available icons */
267         gtk_list_store_append(store, &iter);
268         gtk_list_store_set(store, &iter,
269                            SET_ICON, NULL,
270                            SET_ICON_TEXT, SEPARATOR_PIXMAP,
271                            SET_ICON_IS_TEXT, TRUE,
272                            SET_FILENAME, toolbar_ret_descr_from_val(A_SEPARATOR),
273                            -1);
274
275         prefs_toolbar->combo_action_list = toolbar_get_action_items(prefs_toolbar->source);
276         gtk_combo_set_popdown_strings(GTK_COMBO(prefs_toolbar->combo_action),   
277                                       prefs_toolbar->combo_action_list);
278         gtk_combo_set_value_in_list(GTK_COMBO(prefs_toolbar->combo_action), 0, FALSE);
279         gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->combo_entry), prefs_toolbar->combo_action_list->data);
280
281         /* get currently defined sylpheed actions */
282         if (prefs_common.actions_list != NULL) {
283
284                 for (cur = prefs_common.actions_list; cur != NULL; cur = cur->next) {
285                         act = (gchar *)cur->data;
286                         syl_actions = g_list_append(syl_actions, act);
287                 } 
288
289                 gtk_combo_set_popdown_strings(GTK_COMBO(prefs_toolbar->combo_syl_action), syl_actions);
290                 gtk_combo_set_value_in_list(GTK_COMBO(prefs_toolbar->combo_syl_action), 0, FALSE);
291                 gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->combo_syl_entry), syl_actions->data);
292                 prefs_toolbar_selection_changed(GTK_LIST(prefs_toolbar->combo_syl_list), prefs_toolbar);
293                 g_list_free(syl_actions);
294         }
295
296         for (i = 0; i < STOCK_PIXMAP_SYLPHEED_LOGO; i++) {
297                 GdkPixbuf *pixbuf;
298
299                 stock_pixbuf_gdk(prefs_toolbar->window, i, &pixbuf);
300                 
301                 gtk_list_store_append(store, &iter);
302                 gtk_list_store_set(store, &iter,
303                                    SET_ICON, pixbuf,
304                                    SET_FILENAME, stock_pixmap_get_name((StockPixmap) i),
305                                    SET_ICON_TEXT, NULL,
306                                    SET_ICON_IS_TEXT, FALSE,
307                                    -1);
308         }
309
310         gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
311         gtk_tree_selection_select_iter(gtk_tree_view_get_selection
312                                                 (list_view_icons),
313                                        &iter);          
314
315         prefs_toolbar_set_displayed(prefs_toolbar);
316
317         toolbar_clear_list(prefs_toolbar->source);
318 }
319
320 static gboolean is_duplicate(ToolbarPage *prefs_toolbar, gchar *chosen_action)
321 {
322         GtkTreeView *list_view_set = GTK_TREE_VIEW
323                                         (prefs_toolbar->list_view_set);
324         GtkTreeModel *model_set = gtk_tree_view_get_model(list_view_set);                                       
325         gchar *entry;
326         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
327         GtkTreeIter iter;
328         gboolean result;
329
330         g_return_val_if_fail(chosen_action != NULL, TRUE);
331
332         if (!gtk_tree_model_iter_n_children(model_set, NULL))
333                 return FALSE;
334         
335         /* allow duplicate entries (A_SYL_ACTIONS) */
336         if (g_utf8_collate(syl_act, chosen_action) == 0)
337                 return FALSE;
338
339         if (!gtk_tree_model_get_iter_first(model_set, &iter))
340                 return FALSE;
341
342         result = FALSE;
343         do {
344                 gtk_tree_model_get(model_set, &iter,
345                                    SET_EVENT, &entry, 
346                                    -1);
347                 if (g_utf8_collate(chosen_action, entry) == 0) 
348                         result = TRUE;
349                 g_free(entry);                  
350         } while (!result && gtk_tree_model_iter_next(model_set, &iter));
351
352         return result;
353 }
354
355 static void prefs_toolbar_default(GtkButton *button, ToolbarPage *prefs_toolbar)
356 {
357         toolbar_clear_list(prefs_toolbar->source);
358         toolbar_set_default(prefs_toolbar->source);
359         prefs_toolbar_set_displayed(prefs_toolbar);
360 }
361
362 /*!
363  *\return       String that should be freed by caller.
364  */
365 static void get_action_name(const gchar *entry, gchar **menu)
366 {
367         gchar *act, *act_p;
368
369         if (prefs_common.actions_list != NULL) {
370                 
371                 act = g_strdup(entry);
372                 act_p = strstr(act, ": ");
373                 if (act_p != NULL)
374                         act_p[0] = 0x00;
375                 /* freed by calling func */
376                 *menu = act;
377         }
378 }
379
380 static void prefs_toolbar_register(GtkButton *button, ToolbarPage *prefs_toolbar)
381 {
382         GtkTreeView *list_view_set   = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
383         GtkTreeView *list_view_icons = GTK_TREE_VIEW(prefs_toolbar->list_view_icons);
384         GtkTreeModel *model_icons = gtk_tree_view_get_model(list_view_icons);
385         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
386         GtkListStore *store_set;
387         GtkTreeIter iter;
388         gchar *fname;
389
390         /* move selection in icon list view to set list view */
391
392         if (!gtk_tree_model_iter_n_children(model_icons, NULL))
393                 return;
394         
395         if (!gtk_tree_selection_get_selected
396                         (gtk_tree_view_get_selection(list_view_icons),
397                          NULL, &iter))
398                 return;
399
400         gtk_tree_model_get(model_icons, &iter,
401                            SET_FILENAME, &fname,
402                            -1);
403
404         store_set = GTK_LIST_STORE(gtk_tree_view_get_model(list_view_set));
405
406         /* SEPARATOR or other ? */
407         if (g_utf8_collate(fname, toolbar_ret_descr_from_val(A_SEPARATOR)) == 0) {
408                 gtk_list_store_append(store_set, &iter);
409                 gtk_list_store_set(store_set, &iter,
410                                    SET_ICON, NULL,
411                                    SET_FILENAME, NULL,
412                                    SET_TEXT, NULL,
413                                    SET_EVENT, toolbar_ret_descr_from_val(A_SEPARATOR),
414                                    SET_ICON_TEXT, (const gchar *) SEPARATOR_PIXMAP,
415                                    SET_ICON_IS_TEXT, TRUE,
416                                    -1);
417         } else {
418                 GdkPixbuf *pixbuf;
419                 gchar *event, *text;
420                 
421                 event = g_strdup(gtk_entry_get_text
422                                 (GTK_ENTRY(prefs_toolbar->combo_entry)));
423
424                 if (is_duplicate(prefs_toolbar, event)) {
425                         alertpanel_error(ERROR_MSG);
426                         g_free(event);
427                         g_free(fname);
428                         return;
429                 }
430
431                 stock_pixbuf_gdk(prefs_toolbar->window, 
432                                  stock_pixmap_get_icon(fname),
433                                  &pixbuf);
434
435                 if (g_utf8_collate(event, syl_act) == 0) {
436                         const gchar *entry = gtk_entry_get_text(GTK_ENTRY(prefs_toolbar->combo_syl_entry));
437                         get_action_name(entry, &text);
438                 } else
439                         text = gtk_editable_get_chars
440                                 (GTK_EDITABLE(prefs_toolbar->entry_icon_text), 0, -1);
441
442                 gtk_list_store_append(store_set, &iter);
443                 gtk_list_store_set(store_set, &iter,
444                                    SET_ICON, pixbuf,
445                                    SET_FILENAME, fname,
446                                    SET_TEXT, text,
447                                    SET_EVENT, event,
448                                    SET_ICON_TEXT, NULL,
449                                    SET_ICON_IS_TEXT, FALSE,
450                                    -1);
451                 g_free(text);
452                 g_free(event);
453         }
454
455         g_free(fname);
456         
457         gtk_tree_selection_select_iter(gtk_tree_view_get_selection
458                                                 (list_view_set),
459                                        &iter);
460 }
461
462 static void prefs_toolbar_substitute(GtkButton *button, ToolbarPage *prefs_toolbar)
463 {
464         GtkTreeView *list_view_set   = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
465         GtkTreeView *list_view_icons = GTK_TREE_VIEW(prefs_toolbar->list_view_icons);
466         GtkTreeModel *model_icons = gtk_tree_view_get_model(list_view_icons);
467         GtkListStore *store_set   = GTK_LIST_STORE(gtk_tree_view_get_model(list_view_set));
468         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
469         GtkTreeSelection *sel_icons;
470         GtkTreeSelection *sel_set;
471         GtkTreeIter iter_icons;
472         GtkTreeIter iter_set;
473         gchar *icon_fname;
474
475         /* replace selection in set list with the one in icon list */
476
477         if (!gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store_set), NULL))
478                 return;
479                 
480         sel_icons = gtk_tree_view_get_selection(list_view_icons);
481         if (!gtk_tree_selection_get_selected(sel_icons, NULL, &iter_icons))
482                 return;
483                 
484         sel_set = gtk_tree_view_get_selection(list_view_set);           
485         if (!gtk_tree_selection_get_selected(sel_set, NULL, &iter_set))
486                 return;
487
488         gtk_tree_model_get(model_icons, &iter_icons, 
489                            SET_FILENAME, &icon_fname, 
490                            -1);
491         
492         if (g_utf8_collate(icon_fname, toolbar_ret_descr_from_val(A_SEPARATOR)) == 0) {
493                 gtk_list_store_set(store_set, &iter_set, 
494                                    SET_ICON, NULL,
495                                    SET_TEXT, NULL,
496                                    SET_EVENT, toolbar_ret_descr_from_val(A_SEPARATOR),
497                                    SET_FILENAME, icon_fname,
498                                    SET_ICON_TEXT, (const gchar *) SEPARATOR_PIXMAP,
499                                    SET_ICON_IS_TEXT, TRUE,
500                                    -1);
501         } else {
502                 GdkPixbuf *pixbuf;
503                 gchar *icon_event, *set_event, *text;
504
505                 icon_event = gtk_editable_get_chars
506                                 (GTK_EDITABLE(prefs_toolbar->combo_entry), 
507                                  0, -1);
508
509                 gtk_tree_model_get(GTK_TREE_MODEL(store_set), &iter_set, 
510                                                   SET_EVENT, &set_event,
511                                                   -1);
512
513                 if (is_duplicate(prefs_toolbar, icon_event) 
514                 &&  g_utf8_collate(icon_event, set_event) != 0){
515                         alertpanel_error(ERROR_MSG);
516                         g_free(set_event);
517                         g_free(icon_event);
518                         g_free(icon_fname);
519                         return;
520                 }
521
522                 stock_pixbuf_gdk(prefs_toolbar->window, 
523                                  stock_pixmap_get_icon(icon_fname),
524                                  &pixbuf);
525
526                 if (g_utf8_collate(icon_event, syl_act) == 0) {
527                         const gchar *entry = gtk_entry_get_text(GTK_ENTRY(prefs_toolbar->combo_syl_entry));
528                         get_action_name(entry, &text);
529                 } else {
530                         text = gtk_editable_get_chars(GTK_EDITABLE(prefs_toolbar->entry_icon_text),
531                                                       0, -1);
532                 }
533
534                 /* change the row */
535                 gtk_list_store_set(store_set, &iter_set,
536                                    SET_ICON, pixbuf,
537                                    SET_FILENAME, icon_fname,
538                                    SET_TEXT, text,
539                                    SET_EVENT, icon_event,
540                                    SET_ICON_TEXT, NULL,
541                                    SET_ICON_IS_TEXT, FALSE,
542                                    -1);
543         
544                 g_free(icon_event);
545                 g_free(set_event);
546                 g_free(text);
547         }
548         
549         g_free(icon_fname);
550 }
551
552 static void prefs_toolbar_delete(GtkButton *button, ToolbarPage *prefs_toolbar)
553 {
554         GtkTreeView *list_view_set = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
555         GtkListStore *store_set = GTK_LIST_STORE(gtk_tree_view_get_model
556                                                         (list_view_set));
557         GtkTreeIter iter_set;                                                   
558
559         if (!gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store_set), NULL))
560                 return;
561         
562         if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection
563                                                         (list_view_set),
564                                              NULL,
565                                              &iter_set))
566                 return;                                      
567         
568         gtk_list_store_remove(store_set, &iter_set);
569
570         /* XXX: may need to select a list item */
571 }
572
573 static void prefs_toolbar_up(GtkButton *button, ToolbarPage *prefs_toolbar)
574 {
575         GtkTreePath *prev, *sel;
576         GtkTreeIter isel;
577         GtkListStore *store = NULL;
578         GtkTreeModel *model = NULL;
579         GtkTreeIter iprev;
580         
581         if (!gtk_tree_selection_get_selected
582                 (gtk_tree_view_get_selection
583                         (GTK_TREE_VIEW(prefs_toolbar->list_view_set)),
584                  &model,        
585                  &isel))
586                 return;
587         store = (GtkListStore *)model;
588
589         sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
590         if (!sel)
591                 return;
592         
593         /* no move if we're at row 0... */
594         prev = gtk_tree_path_copy(sel);
595         if (!gtk_tree_path_prev(prev)) {
596                 gtk_tree_path_free(prev);
597                 gtk_tree_path_free(sel);
598                 return;
599         }
600
601         gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
602                                 &iprev, prev);
603         gtk_tree_path_free(sel);
604         gtk_tree_path_free(prev);
605
606         gtk_list_store_swap(store, &iprev, &isel);
607 }
608
609 static void prefs_toolbar_down(GtkButton *button, ToolbarPage *prefs_toolbar)
610 {
611         GtkListStore *store = NULL;
612         GtkTreeModel *model = NULL;
613         GtkTreeIter next, sel;
614         
615         if (!gtk_tree_selection_get_selected
616                 (gtk_tree_view_get_selection
617                         (GTK_TREE_VIEW(prefs_toolbar->list_view_set)),
618                  &model,
619                  &sel))
620                 return;
621
622         store = (GtkListStore *)model;
623         next = sel;
624         if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next)) 
625                 return;
626
627         gtk_list_store_swap(store, &next, &sel);
628 }
629
630 static void prefs_toolbar_selection_changed(GtkList *list,
631                                             ToolbarPage *prefs_toolbar)
632 {
633         gchar *cur_entry = g_strdup(gtk_entry_get_text(GTK_ENTRY(prefs_toolbar->combo_entry)));
634         gchar *actions_entry = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
635
636         gtk_widget_set_sensitive(prefs_toolbar->combo_syl_action, TRUE);
637
638         if (g_utf8_collate(cur_entry, actions_entry) == 0) {
639                 gtk_widget_hide(prefs_toolbar->entry_icon_text);
640                 gtk_widget_show(prefs_toolbar->combo_syl_action);
641                 gtk_label_set_text(GTK_LABEL(prefs_toolbar->label_icon_text), _("Sylpheed-Claws Action"));
642
643                 if (prefs_common.actions_list == NULL) {
644                     gtk_widget_set_sensitive(prefs_toolbar->combo_syl_action, FALSE);
645                 }
646
647         } else {
648                 gtk_widget_hide(prefs_toolbar->combo_syl_action);
649                 gtk_widget_show(prefs_toolbar->entry_icon_text);
650                 gtk_label_set_text(GTK_LABEL(prefs_toolbar->label_icon_text), _("Toolbar text"));
651         }
652
653         gtk_misc_set_alignment(GTK_MISC(prefs_toolbar->label_icon_text), 1, 0.5);
654         gtk_widget_show(prefs_toolbar->label_icon_text);
655         g_free(cur_entry);
656 }
657
658 static void prefs_toolbar_create(ToolbarPage *prefs_toolbar)
659 {
660         GtkWidget *main_vbox;
661         GtkWidget *top_hbox;
662         GtkWidget *compose_frame;
663         GtkWidget *reg_hbox;
664         GtkWidget *arrow;
665         GtkWidget *btn_hbox;
666         GtkWidget *reg_btn;
667         GtkWidget *subst_btn;
668         GtkWidget *del_btn;
669         GtkWidget *default_btn;
670         GtkWidget *vbox_frame;
671         GtkWidget *table;
672         GtkWidget *scrolledwindow_list_view_icons;
673         GtkWidget *list_view_icons;
674         GtkWidget *label_icon_text;
675         GtkWidget *entry_icon_text;
676         GtkWidget *label_action_sel;
677         GtkWidget *empty_label;
678         GtkWidget *combo_action;
679         GtkWidget *combo_entry;
680         GtkWidget *combo_list;
681         GtkWidget *combo_syl_action;
682         GtkWidget *combo_syl_entry;
683         GtkWidget *combo_syl_list;
684         GtkWidget *frame_toolbar_items;
685         GtkWidget *hbox_bottom;
686         GtkWidget *scrolledwindow_list_view_set;
687         GtkWidget *list_view_set;
688
689         GtkWidget *btn_vbox;
690         GtkWidget *up_btn;
691         GtkWidget *down_btn;
692
693         debug_print("Creating custom toolbar window...\n");
694
695         main_vbox = gtk_vbox_new(FALSE, 0);
696         gtk_widget_show(main_vbox);
697         
698         top_hbox = gtk_hbox_new(FALSE, 0);
699         gtk_box_pack_start(GTK_BOX(main_vbox), top_hbox, TRUE, TRUE, 0);
700   
701         compose_frame = gtk_frame_new(_("Available toolbar icons"));
702         gtk_box_pack_start(GTK_BOX(top_hbox), compose_frame, TRUE, TRUE, 0);
703         gtk_container_set_border_width(GTK_CONTAINER(compose_frame), 5);
704
705         vbox_frame = gtk_vbox_new(FALSE, 0);
706         gtk_container_add(GTK_CONTAINER(compose_frame), vbox_frame);
707
708         /* available icons */
709         scrolledwindow_list_view_icons = gtk_scrolled_window_new(NULL, NULL);
710         gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow_list_view_icons), 5);
711         gtk_box_pack_start(GTK_BOX(vbox_frame), scrolledwindow_list_view_icons,
712                            TRUE, TRUE, 0);
713         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow_list_view_icons), 
714                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
715
716         list_view_icons = create_icon_list_view(prefs_toolbar);
717         gtk_widget_show(list_view_icons);
718         gtk_container_add(GTK_CONTAINER(scrolledwindow_list_view_icons), list_view_icons);
719         gtk_container_set_border_width(GTK_CONTAINER(list_view_icons), 1);
720         gtk_widget_set_size_request(list_view_icons, 225, 108);
721
722         table = gtk_table_new (2, 3, FALSE);
723         gtk_box_pack_start(GTK_BOX(vbox_frame), table,
724                            FALSE, FALSE, 0);
725         gtk_container_set_border_width (GTK_CONTAINER (table), 8);
726         gtk_table_set_row_spacings (GTK_TABLE (table), 8);
727         gtk_table_set_col_spacings (GTK_TABLE (table), 8);
728         
729         /* icon description */
730         label_icon_text = gtk_label_new("");
731         gtk_misc_set_alignment(GTK_MISC(label_icon_text), 0, 0.5);
732         gtk_widget_show (label_icon_text);
733         gtk_table_attach (GTK_TABLE (table), label_icon_text, 0, 1, 0, 1,
734                           (GtkAttachOptions) (GTK_FILL),
735                           (GtkAttachOptions) (0), 0, 0);
736
737         entry_icon_text = gtk_entry_new();
738         gtk_table_attach (GTK_TABLE (table), entry_icon_text, 1, 2, 0, 1,
739                           (GtkAttachOptions) (/*GTK_EXPAND | */GTK_FILL),
740                           (GtkAttachOptions) (0), 0, 0);
741
742         /* Sylpheed Action Combo Box */
743         combo_syl_action = gtk_combo_new();
744         combo_syl_list = GTK_COMBO(combo_syl_action)->list;
745         combo_syl_entry = GTK_COMBO(combo_syl_action)->entry;
746         gtk_entry_set_editable(GTK_ENTRY(combo_syl_entry), FALSE);
747         gtk_table_attach (GTK_TABLE (table), combo_syl_action, 1, 2, 0, 1,
748                           (GtkAttachOptions) (/*GTK_EXPAND | */GTK_FILL),
749                           (GtkAttachOptions) (0), 0, 0);
750
751         empty_label = gtk_label_new("");
752         gtk_table_attach (GTK_TABLE (table), empty_label, 2, 3, 0, 1,
753                           (GtkAttachOptions) (GTK_EXPAND),
754                           (GtkAttachOptions) (0), 0, 0);
755         /* available actions */
756         label_action_sel = gtk_label_new(_("Event executed on click"));
757         gtk_misc_set_alignment(GTK_MISC(label_action_sel), 0, 0.5);
758         gtk_table_attach (GTK_TABLE (table), label_action_sel, 0, 1, 1, 2,
759                           (GtkAttachOptions) (GTK_FILL),
760                           (GtkAttachOptions) (0), 0, 0);
761
762         combo_action = gtk_combo_new();
763         gtk_table_attach (GTK_TABLE (table), combo_action, 1, 2, 1, 2,
764                           (GtkAttachOptions) (GTK_FILL),
765                           (GtkAttachOptions) (0), 0, 0);
766         
767         combo_list = GTK_COMBO(combo_action)->list;
768         combo_entry = GTK_COMBO(combo_action)->entry;
769         gtk_entry_set_editable(GTK_ENTRY(combo_entry), FALSE);
770         
771         empty_label = gtk_label_new("");
772         gtk_table_attach (GTK_TABLE (table), empty_label, 2, 3, 1, 2,
773                           (GtkAttachOptions) (GTK_EXPAND),
774                           (GtkAttachOptions) (0), 0, 0);
775
776         /* register / substitute / delete */
777         reg_hbox = gtk_hbox_new(FALSE, 4);
778         gtk_box_pack_start(GTK_BOX(main_vbox), reg_hbox, FALSE, FALSE, 0);
779         gtk_container_set_border_width(GTK_CONTAINER(reg_hbox), 10);
780
781         arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
782         gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
783         gtk_widget_set_size_request(arrow, -1, 16);
784
785         btn_hbox = gtk_hbox_new(TRUE, 4);
786         gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
787
788         reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
789         gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
790         g_signal_connect(G_OBJECT(reg_btn), "clicked",
791                          G_CALLBACK(prefs_toolbar_register), 
792                          prefs_toolbar);
793
794         subst_btn = gtk_button_new_with_label(_("  Replace  "));
795         gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
796         g_signal_connect(G_OBJECT(subst_btn), "clicked",
797                          G_CALLBACK(prefs_toolbar_substitute),
798                          prefs_toolbar);
799
800         del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
801         gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
802         g_signal_connect(G_OBJECT(del_btn), "clicked",
803                          G_CALLBACK(prefs_toolbar_delete), 
804                           prefs_toolbar);
805
806         default_btn = gtk_button_new_with_label(_(" Use default "));
807         gtk_box_pack_end(GTK_BOX(reg_hbox), default_btn, FALSE, TRUE, 0);
808         g_signal_connect(G_OBJECT(default_btn), "clicked",
809                          G_CALLBACK(prefs_toolbar_default), 
810                          prefs_toolbar);
811
812         /* currently active toolbar items */
813         frame_toolbar_items = gtk_frame_new(_("Displayed toolbar items"));
814         gtk_box_pack_start(GTK_BOX(main_vbox), frame_toolbar_items, TRUE, TRUE, 0);
815         gtk_container_set_border_width(GTK_CONTAINER(frame_toolbar_items), 5);
816         
817         hbox_bottom = gtk_hbox_new(FALSE, 0);
818         gtk_container_add(GTK_CONTAINER(frame_toolbar_items), hbox_bottom);
819         
820         scrolledwindow_list_view_set = gtk_scrolled_window_new(NULL, NULL);
821         gtk_box_pack_start(GTK_BOX(hbox_bottom), scrolledwindow_list_view_set, TRUE, TRUE, 0);
822         gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow_list_view_set), 1);
823         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow_list_view_set), 
824                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
825
826         list_view_set = create_set_list_view(prefs_toolbar); 
827         gtk_widget_show(list_view_set);
828         gtk_container_add(GTK_CONTAINER(scrolledwindow_list_view_set), list_view_set);
829         gtk_widget_set_size_request(list_view_set, 225, 120);
830
831         btn_vbox = gtk_vbox_new(FALSE, 8);
832         gtk_widget_show(btn_vbox);
833         gtk_box_pack_start(GTK_BOX(hbox_bottom), btn_vbox, FALSE, FALSE, 5);
834
835         up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
836         gtk_widget_show(up_btn);
837         gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 2);
838
839         down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
840         gtk_widget_show(down_btn);
841         gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
842
843         g_signal_connect(G_OBJECT(combo_list), "selection-changed",
844                          G_CALLBACK(prefs_toolbar_selection_changed),
845                          prefs_toolbar);
846         g_signal_connect(G_OBJECT(up_btn), "clicked",
847                          G_CALLBACK(prefs_toolbar_up), prefs_toolbar);
848         g_signal_connect(G_OBJECT(down_btn), "clicked",
849                          G_CALLBACK(prefs_toolbar_down), prefs_toolbar);
850         
851         gtk_widget_show_all(main_vbox);
852
853         prefs_toolbar->list_view_icons  = list_view_icons;
854         prefs_toolbar->list_view_set    = list_view_set;
855         prefs_toolbar->combo_action     = combo_action;
856         prefs_toolbar->combo_entry      = combo_entry;
857         prefs_toolbar->combo_list       = combo_list;
858         prefs_toolbar->entry_icon_text  = entry_icon_text;
859         prefs_toolbar->combo_syl_action = combo_syl_action;
860         prefs_toolbar->combo_syl_list   = combo_syl_list;
861         prefs_toolbar->combo_syl_entry  = combo_syl_entry;
862
863         prefs_toolbar->label_icon_text  = label_icon_text;
864         prefs_toolbar->label_action_sel = label_action_sel;
865
866         prefs_toolbar->page.widget = main_vbox;
867 }
868
869 ToolbarPage *prefs_toolbar_mainwindow;
870 ToolbarPage *prefs_toolbar_composewindow;
871 ToolbarPage *prefs_toolbar_messageview;
872
873 void prefs_toolbar_init(void)
874 {
875         ToolbarPage *page;
876         static gchar *mainpath[3], *messagepath[3], *composepath[3];
877
878         mainpath[0] = _("Customize Toolbars");
879         mainpath[1] = _("Main Window");
880         mainpath[2] = NULL;
881
882         page = g_new0(ToolbarPage, 1);
883         page->page.path = mainpath;
884         page->page.create_widget = prefs_toolbar_create_widget;
885         page->page.destroy_widget = prefs_toolbar_destroy_widget;
886         page->page.save_page = prefs_toolbar_save;
887         page->source = TOOLBAR_MAIN;
888         page->page.weight = 50.0;
889         prefs_gtk_register_page((PrefsPage *) page);
890         prefs_toolbar_mainwindow = page;
891
892         messagepath[0] = _("Customize Toolbars");
893         messagepath[1] = _("Message Window");
894         messagepath[2] = NULL;
895
896         page = g_new0(ToolbarPage, 1);
897         page->page.path = messagepath;
898         page->page.create_widget = prefs_toolbar_create_widget;
899         page->page.destroy_widget = prefs_toolbar_destroy_widget;
900         page->page.save_page = prefs_toolbar_save;
901         page->source = TOOLBAR_MSGVIEW;
902         page->page.weight = 45.0;
903         prefs_gtk_register_page((PrefsPage *) page);
904         prefs_toolbar_messageview = page;
905
906         composepath[0] = _("Customize Toolbars");
907         composepath[1] = _("Compose Window");
908         composepath[2] = NULL;
909
910         page = g_new0(ToolbarPage, 1);
911         page->page.path = composepath;
912         page->page.create_widget = prefs_toolbar_create_widget;
913         page->page.destroy_widget = prefs_toolbar_destroy_widget;
914         page->page.save_page = prefs_toolbar_save;
915         page->source = TOOLBAR_COMPOSE;
916         page->page.weight = 40.0;
917         prefs_gtk_register_page((PrefsPage *) page);
918         prefs_toolbar_composewindow = page;
919 }
920
921 void prefs_toolbar_done(void)
922 {
923         prefs_gtk_unregister_page((PrefsPage *) prefs_toolbar_mainwindow);
924         g_free(prefs_toolbar_mainwindow);
925         prefs_gtk_unregister_page((PrefsPage *) prefs_toolbar_composewindow);
926         g_free(prefs_toolbar_composewindow);
927         prefs_gtk_unregister_page((PrefsPage *) prefs_toolbar_messageview);
928         g_free(prefs_toolbar_messageview);
929 }
930
931 static void set_visible_if_not_text(GtkTreeViewColumn *col,
932                                     GtkCellRenderer   *renderer,
933                                     GtkTreeModel      *model,
934                                     GtkTreeIter       *iter,
935                                     gpointer           user_data)
936 {
937         gboolean is_text;
938         GdkPixbuf *pixbuf;
939
940         gtk_tree_model_get(model, iter, SET_ICON_IS_TEXT, &is_text, -1);
941         if (is_text) {
942                 g_object_set(renderer, "visible", FALSE, NULL); 
943         } else {
944                 pixbuf = NULL;
945                 gtk_tree_model_get(model, iter, 
946                                    SET_ICON, &pixbuf,
947                                    -1);
948                 /* note getting a pixbuf from a tree model increases
949                  * its refcount ... */
950                 g_object_unref(pixbuf);
951                 
952                 g_object_set(renderer, "visible", TRUE, NULL);
953                 g_object_set(renderer, "pixbuf",  pixbuf, NULL);
954         }
955 }
956
957 static GtkWidget *create_icon_list_view(ToolbarPage *prefs_toolbar)
958 {
959         GtkTreeView *list_view;
960         GtkListStore *store;
961         GtkCellRenderer *renderer;
962         GtkTreeViewColumn *column;
963         GtkTreeSelection *selector;
964
965         /* XXX: for icon list we don't need SET_TEXT, and SET_EVENT */
966         store = gtk_list_store_new(N_SET_COLUMNS, 
967                                    GDK_TYPE_PIXBUF,
968                                    G_TYPE_STRING,
969                                    G_TYPE_STRING,
970                                    G_TYPE_STRING,
971                                    G_TYPE_STRING,
972                                    G_TYPE_BOOLEAN,
973                                    -1);
974         list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
975         g_object_unref(G_OBJECT(store));
976
977         column = gtk_tree_view_column_new();
978         renderer = gtk_cell_renderer_pixbuf_new();
979         gtk_tree_view_column_pack_start(column, renderer, FALSE);
980         
981         /* tell pixbuf renderer it is only visible if 
982          * the icon is not represented by text */
983         gtk_tree_view_column_set_cell_data_func(column, renderer,
984                                                 set_visible_if_not_text,
985                                                 NULL, NULL);
986         
987         renderer = gtk_cell_renderer_text_new();
988         gtk_tree_view_column_pack_start(column, renderer, FALSE);
989         
990         /* tell the text renderer it is only visible if the icon
991          * is represented by an image */
992         gtk_tree_view_column_set_attributes(column, renderer,
993                                             "visible", SET_ICON_IS_TEXT, 
994                                             "text", SET_ICON_TEXT,
995                                             NULL);
996
997         gtk_tree_view_append_column(list_view, column);
998
999         column = gtk_tree_view_column_new();
1000         renderer = gtk_cell_renderer_text_new();
1001         gtk_tree_view_column_pack_start(column, renderer, TRUE);
1002         gtk_tree_view_column_set_attributes(column, renderer,
1003                                             "text", SET_FILENAME,
1004                                             NULL);
1005         
1006         gtk_tree_view_append_column(list_view, column);
1007
1008         /* various other tree view attributes */
1009         gtk_tree_view_set_rules_hint(list_view, prefs_common.enable_rules_hint);
1010         gtk_tree_view_set_headers_visible(list_view, FALSE);
1011         
1012         selector = gtk_tree_view_get_selection(list_view);
1013         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1014         gtk_tree_selection_set_select_function
1015                 (selector, (GtkTreeSelectionFunc) icon_list_selected,
1016                  prefs_toolbar, NULL);
1017
1018         return GTK_WIDGET(list_view);   
1019 }
1020
1021 static GtkWidget *create_set_list_view(ToolbarPage *prefs_toolbar)
1022 {
1023         GtkTreeView *list_view;
1024         GtkListStore *store;
1025         GtkCellRenderer *renderer;
1026         GtkTreeViewColumn *column;
1027         GtkTreeSelection *selector;
1028
1029         store = gtk_list_store_new(N_SET_COLUMNS, 
1030                                    GDK_TYPE_PIXBUF,
1031                                    G_TYPE_STRING,
1032                                    G_TYPE_STRING,
1033                                    G_TYPE_STRING,
1034                                    G_TYPE_STRING,
1035                                    G_TYPE_BOOLEAN,
1036                                    -1);
1037         list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
1038         g_object_unref(G_OBJECT(store));
1039
1040         column = gtk_tree_view_column_new();
1041         gtk_tree_view_column_set_title(column, _("Icon"));
1042         renderer = gtk_cell_renderer_pixbuf_new();
1043         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1044         
1045         /* tell pixbuf renderer it is only visible if 
1046          * the icon is not represented by text */
1047         gtk_tree_view_column_set_cell_data_func(column, renderer,
1048                                                 set_visible_if_not_text,
1049                                                 NULL, NULL);
1050         
1051         renderer = gtk_cell_renderer_text_new();
1052         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1053         
1054         /* tell the text renderer it is only visible if the icon
1055          * is represented by an image */
1056         gtk_tree_view_column_set_attributes(column, renderer,
1057                                             "visible", SET_ICON_IS_TEXT,
1058                                             "text", SET_ICON_TEXT,
1059                                             NULL);
1060
1061         gtk_tree_view_append_column(list_view, column);
1062
1063         column = gtk_tree_view_column_new();
1064         gtk_tree_view_column_set_title(column, _("File name"));
1065         renderer = gtk_cell_renderer_text_new();
1066         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1067         gtk_tree_view_column_set_attributes(column, renderer,
1068                                             "text", SET_FILENAME,
1069                                             NULL);
1070         
1071         gtk_tree_view_append_column(list_view, column);
1072
1073         column = gtk_tree_view_column_new();
1074         gtk_tree_view_column_set_title(column, _("Icon text"));
1075         renderer = gtk_cell_renderer_text_new();
1076         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1077         gtk_tree_view_column_set_attributes(column, renderer,
1078                                             "text", SET_TEXT,
1079                                             NULL);
1080         gtk_tree_view_append_column(list_view, column);
1081
1082         column = gtk_tree_view_column_new();
1083         gtk_tree_view_column_set_title(column, _("Mapped event"));
1084         renderer = gtk_cell_renderer_text_new();
1085         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1086         gtk_tree_view_column_set_attributes(column, renderer,
1087                                             "text", SET_EVENT,
1088                                             NULL);
1089         gtk_tree_view_append_column(list_view, column);
1090
1091         /* various other tree view attributes */
1092         gtk_tree_view_set_rules_hint(list_view, prefs_common.enable_rules_hint);
1093         
1094         selector = gtk_tree_view_get_selection(list_view);
1095         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1096         gtk_tree_selection_set_select_function
1097                 (selector, (GtkTreeSelectionFunc) set_list_selected,
1098                  prefs_toolbar, NULL);
1099
1100         return GTK_WIDGET(list_view);   
1101
1102 }
1103
1104 static gboolean icon_list_selected(GtkTreeSelection *selector,
1105                                    GtkTreeModel *model, 
1106                                    GtkTreePath *path,
1107                                    gboolean currently_selected,
1108                                    ToolbarPage *prefs_toolbar)
1109 {
1110         GtkTreeIter iter;
1111         gchar *text;
1112         
1113         if (currently_selected ||!gtk_tree_model_get_iter(model, &iter, path))
1114                 return TRUE;
1115
1116         text = NULL;
1117         gtk_tree_model_get(model, &iter, 
1118                            SET_FILENAME, &text,
1119                            -1);
1120         if (!text) 
1121                 return TRUE;
1122
1123         if (g_utf8_collate(toolbar_ret_descr_from_val(A_SEPARATOR), text) == 0) {
1124                 gtk_widget_set_sensitive(prefs_toolbar->combo_action,     FALSE);
1125                 gtk_widget_set_sensitive(prefs_toolbar->entry_icon_text,  FALSE);
1126                 gtk_widget_set_sensitive(prefs_toolbar->combo_syl_action, FALSE);
1127         } else {
1128                 gtk_widget_set_sensitive(prefs_toolbar->combo_action,     TRUE);
1129                 gtk_widget_set_sensitive(prefs_toolbar->entry_icon_text,  TRUE);
1130                 gtk_widget_set_sensitive(prefs_toolbar->combo_syl_action, TRUE);
1131         }
1132         
1133         g_free(text);
1134
1135         return TRUE;
1136 }
1137
1138 static gboolean set_list_selected(GtkTreeSelection *selector,
1139                                   GtkTreeModel *model, 
1140                                   GtkTreePath *path,
1141                                   gboolean currently_selected,
1142                                   ToolbarPage *prefs_toolbar)
1143 {
1144         GtkTreeIter iter;
1145         GtkTreeView *list_ico = GTK_TREE_VIEW(prefs_toolbar->list_view_icons);
1146         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
1147         gchar *file, *icon_text, *descr;
1148         GList *cur;
1149         gint item_num;
1150         GtkTreeModel *model_ico;
1151         
1152         if (currently_selected ||!gtk_tree_model_get_iter(model, &iter, path))
1153                 return TRUE;
1154         
1155         gtk_tree_model_get(model, &iter,
1156                            SET_FILENAME, &file,
1157                            SET_TEXT, &icon_text,
1158                            SET_EVENT, &descr,
1159                            -1);
1160
1161         if (g_utf8_collate(descr, syl_act)) 
1162                 gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->entry_icon_text), 
1163                                    icon_text);
1164         
1165         /* scan combo list for selected description an set combo item accordingly */
1166         for (cur = prefs_toolbar->combo_action_list, item_num = 0; cur != NULL; 
1167              cur = cur->next) {
1168                 gchar *item_str = (gchar*)cur->data;
1169                 if (g_utf8_collate(item_str, descr) == 0) {
1170                         gtk_list_select_item(GTK_LIST(prefs_toolbar->combo_list), item_num);
1171                         break;
1172                 }
1173                 else
1174                         item_num++;
1175         }
1176
1177         model_ico = gtk_tree_view_get_model(list_ico);
1178         if (gtk_tree_model_get_iter_first(model_ico, &iter)) {
1179                 gchar *entry;
1180                 gboolean found = FALSE;
1181                 
1182                 /* find in icon list, scroll to item */
1183                 do {
1184                         entry = NULL;
1185                         gtk_tree_model_get(model_ico, &iter,
1186                                            SET_FILENAME, &entry,
1187                                            -1);
1188                         found = entry && !g_utf8_collate(entry, file);
1189                         g_free(entry);
1190                         if (found) 
1191                                 break;
1192                 } while(gtk_tree_model_iter_next(model_ico, &iter));
1193
1194                 if (found) {
1195                         GtkTreePath *path;
1196
1197                         gtk_tree_selection_select_iter
1198                                 (gtk_tree_view_get_selection(list_ico), &iter); 
1199                         path = gtk_tree_model_get_path(model_ico, &iter); 
1200                         gtk_tree_view_set_cursor(list_ico, path, NULL, FALSE);
1201                         gtk_tree_path_free(path);
1202                 }
1203         }
1204
1205         g_free(file);
1206         g_free(icon_text);
1207         g_free(descr);
1208
1209         return TRUE;
1210 }