2007-07-09 [colin] 2.10.0cvs10
[claws.git] / src / prefs_toolbar.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2002-2007 Hiroyuki Yamamoto & the Claws Mail 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 static 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 static 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_EMPTY; i++) {
297                 GdkPixbuf *pixbuf;
298                 if (i == STOCK_PIXMAP_CLAWS_MAIL_LOGO)
299                         continue;/* that's too big */
300
301                 stock_pixbuf_gdk(prefs_toolbar->window, i, &pixbuf);
302                 
303                 gtk_list_store_append(store, &iter);
304                 gtk_list_store_set(store, &iter,
305                                    SET_ICON, pixbuf,
306                                    SET_FILENAME, stock_pixmap_get_name((StockPixmap) i),
307                                    SET_ICON_TEXT, NULL,
308                                    SET_ICON_IS_TEXT, FALSE,
309                                    -1);
310         }
311
312         gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
313         gtk_tree_selection_select_iter(gtk_tree_view_get_selection
314                                                 (list_view_icons),
315                                        &iter);          
316
317         prefs_toolbar_set_displayed(prefs_toolbar);
318
319         toolbar_clear_list(prefs_toolbar->source);
320 }
321
322 static gboolean is_duplicate(ToolbarPage *prefs_toolbar, gchar *chosen_action)
323 {
324         GtkTreeView *list_view_set = GTK_TREE_VIEW
325                                         (prefs_toolbar->list_view_set);
326         GtkTreeModel *model_set = gtk_tree_view_get_model(list_view_set);                                       
327         gchar *entry;
328         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
329         GtkTreeIter iter;
330         gboolean result;
331
332         g_return_val_if_fail(chosen_action != NULL, TRUE);
333
334         if (!gtk_tree_model_iter_n_children(model_set, NULL))
335                 return FALSE;
336         
337         /* allow duplicate entries (A_SYL_ACTIONS) */
338         if (g_utf8_collate(syl_act, chosen_action) == 0)
339                 return FALSE;
340
341         if (!gtk_tree_model_get_iter_first(model_set, &iter))
342                 return FALSE;
343
344         result = FALSE;
345         do {
346                 gtk_tree_model_get(model_set, &iter,
347                                    SET_EVENT, &entry, 
348                                    -1);
349                 if (g_utf8_collate(chosen_action, entry) == 0) 
350                         result = TRUE;
351                 g_free(entry);                  
352         } while (!result && gtk_tree_model_iter_next(model_set, &iter));
353
354         return result;
355 }
356
357 static void prefs_toolbar_default(GtkButton *button, ToolbarPage *prefs_toolbar)
358 {
359         toolbar_clear_list(prefs_toolbar->source);
360         toolbar_set_default(prefs_toolbar->source);
361         prefs_toolbar_set_displayed(prefs_toolbar);
362 }
363
364 /*!
365  *\return       String that should be freed by caller.
366  */
367 static void get_action_name(const gchar *entry, gchar **menu)
368 {
369         gchar *act, *act_p;
370         
371         *menu = NULL;
372
373         if (prefs_common.actions_list != NULL) {
374                 
375                 act = g_strdup(entry);
376                 act_p = strstr(act, ": ");
377                 if (act_p != NULL)
378                         act_p[0] = 0x00;
379                 /* freed by calling func */
380                 *menu = act;
381         }
382 }
383
384 static void prefs_toolbar_register(GtkButton *button, ToolbarPage *prefs_toolbar)
385 {
386         GtkTreeView *list_view_set   = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
387         GtkTreeView *list_view_icons = GTK_TREE_VIEW(prefs_toolbar->list_view_icons);
388         GtkTreeModel *model_icons = gtk_tree_view_get_model(list_view_icons);
389         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
390         GtkListStore *store_set;
391         GtkTreeIter iter;
392         gchar *fname = NULL;
393
394         /* move selection in icon list view to set list view */
395
396         if (!gtk_tree_model_iter_n_children(model_icons, NULL))
397                 return;
398         
399         if (!gtk_tree_selection_get_selected
400                         (gtk_tree_view_get_selection(list_view_icons),
401                          NULL, &iter))
402                 return;
403
404         gtk_tree_model_get(model_icons, &iter,
405                            SET_FILENAME, &fname,
406                            -1);
407
408         store_set = GTK_LIST_STORE(gtk_tree_view_get_model(list_view_set));
409
410         /* SEPARATOR or other ? */
411         if (g_utf8_collate(fname, toolbar_ret_descr_from_val(A_SEPARATOR)) == 0) {
412                 gtk_list_store_append(store_set, &iter);
413                 gtk_list_store_set(store_set, &iter,
414                                    SET_ICON, NULL,
415                                    SET_FILENAME, toolbar_ret_descr_from_val(A_SEPARATOR),
416                                    SET_TEXT, NULL,
417                                    SET_EVENT, toolbar_ret_descr_from_val(A_SEPARATOR),
418                                    SET_ICON_TEXT, (const gchar *) SEPARATOR_PIXMAP,
419                                    SET_ICON_IS_TEXT, TRUE,
420                                    -1);
421         } else {
422                 GdkPixbuf *pixbuf;
423                 gchar *event, *text;
424                 
425                 event = g_strdup(gtk_entry_get_text
426                                 (GTK_ENTRY(prefs_toolbar->combo_entry)));
427
428                 if (is_duplicate(prefs_toolbar, event)) {
429                         alertpanel_error(ERROR_MSG);
430                         g_free(event);
431                         g_free(fname);
432                         return;
433                 }
434
435                 stock_pixbuf_gdk(prefs_toolbar->window, 
436                                  stock_pixmap_get_icon(fname),
437                                  &pixbuf);
438
439                 if (g_utf8_collate(event, syl_act) == 0) {
440                         const gchar *entry = gtk_entry_get_text(GTK_ENTRY(prefs_toolbar->combo_syl_entry));
441                         get_action_name(entry, &text);
442                 } else
443                         text = gtk_editable_get_chars
444                                 (GTK_EDITABLE(prefs_toolbar->entry_icon_text), 0, -1);
445
446                 if (text != NULL) {
447                         gtk_list_store_append(store_set, &iter);
448                         gtk_list_store_set(store_set, &iter,
449                                            SET_ICON, pixbuf,
450                                            SET_FILENAME, fname,
451                                            SET_TEXT, text,
452                                            SET_EVENT, event,
453                                            SET_ICON_TEXT, NULL,
454                                            SET_ICON_IS_TEXT, FALSE,
455                                            -1);
456                 }
457                 g_free(text);
458                 g_free(event);
459         }
460
461         g_free(fname);
462         
463         gtk_tree_selection_select_iter(gtk_tree_view_get_selection
464                                                 (list_view_set),
465                                        &iter);
466 }
467
468 static void prefs_toolbar_substitute(GtkButton *button, ToolbarPage *prefs_toolbar)
469 {
470         GtkTreeView *list_view_set   = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
471         GtkTreeView *list_view_icons = GTK_TREE_VIEW(prefs_toolbar->list_view_icons);
472         GtkTreeModel *model_icons = gtk_tree_view_get_model(list_view_icons);
473         GtkListStore *store_set   = GTK_LIST_STORE(gtk_tree_view_get_model(list_view_set));
474         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
475         GtkTreeSelection *sel_icons;
476         GtkTreeSelection *sel_set;
477         GtkTreeIter iter_icons;
478         GtkTreeIter iter_set;
479         gchar *icon_fname;
480
481         /* replace selection in set list with the one in icon list */
482
483         if (!gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store_set), NULL))
484                 return;
485                 
486         sel_icons = gtk_tree_view_get_selection(list_view_icons);
487         if (!gtk_tree_selection_get_selected(sel_icons, NULL, &iter_icons))
488                 return;
489                 
490         sel_set = gtk_tree_view_get_selection(list_view_set);           
491         if (!gtk_tree_selection_get_selected(sel_set, NULL, &iter_set))
492                 return;
493
494         gtk_tree_model_get(model_icons, &iter_icons, 
495                            SET_FILENAME, &icon_fname, 
496                            -1);
497         
498         if (g_utf8_collate(icon_fname, toolbar_ret_descr_from_val(A_SEPARATOR)) == 0) {
499                 gtk_list_store_set(store_set, &iter_set, 
500                                    SET_ICON, NULL,
501                                    SET_TEXT, NULL,
502                                    SET_EVENT, toolbar_ret_descr_from_val(A_SEPARATOR),
503                                    SET_FILENAME, icon_fname,
504                                    SET_ICON_TEXT, (const gchar *) SEPARATOR_PIXMAP,
505                                    SET_ICON_IS_TEXT, TRUE,
506                                    -1);
507         } else {
508                 GdkPixbuf *pixbuf;
509                 gchar *icon_event, *set_event, *text;
510
511                 icon_event = gtk_editable_get_chars
512                                 (GTK_EDITABLE(prefs_toolbar->combo_entry), 
513                                  0, -1);
514
515                 gtk_tree_model_get(GTK_TREE_MODEL(store_set), &iter_set, 
516                                                   SET_EVENT, &set_event,
517                                                   -1);
518
519                 if (is_duplicate(prefs_toolbar, icon_event) 
520                 &&  g_utf8_collate(icon_event, set_event) != 0){
521                         alertpanel_error(ERROR_MSG);
522                         g_free(set_event);
523                         g_free(icon_event);
524                         g_free(icon_fname);
525                         return;
526                 }
527
528                 stock_pixbuf_gdk(prefs_toolbar->window, 
529                                  stock_pixmap_get_icon(icon_fname),
530                                  &pixbuf);
531
532                 if (g_utf8_collate(icon_event, syl_act) == 0) {
533                         const gchar *entry = gtk_entry_get_text(GTK_ENTRY(prefs_toolbar->combo_syl_entry));
534                         get_action_name(entry, &text);
535                 } else {
536                         text = gtk_editable_get_chars(GTK_EDITABLE(prefs_toolbar->entry_icon_text),
537                                                       0, -1);
538                 }
539
540                 /* change the row */
541                 if (text != NULL) {
542                         gtk_list_store_set(store_set, &iter_set,
543                                            SET_ICON, pixbuf,
544                                            SET_FILENAME, icon_fname,
545                                            SET_TEXT, text,
546                                            SET_EVENT, icon_event,
547                                            SET_ICON_TEXT, NULL,
548                                            SET_ICON_IS_TEXT, FALSE,
549                                            -1);
550                 }       
551                 g_free(icon_event);
552                 g_free(set_event);
553                 g_free(text);
554         }
555         
556         g_free(icon_fname);
557 }
558
559 static void prefs_toolbar_delete(GtkButton *button, ToolbarPage *prefs_toolbar)
560 {
561         GtkTreeView *list_view_set = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
562         GtkListStore *store_set = GTK_LIST_STORE(gtk_tree_view_get_model
563                                                         (list_view_set));
564         GtkTreeIter iter_set;                                                   
565
566         if (!gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store_set), NULL))
567                 return;
568         
569         if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection
570                                                         (list_view_set),
571                                              NULL,
572                                              &iter_set))
573                 return;                                      
574         
575         gtk_list_store_remove(store_set, &iter_set);
576
577         /* XXX: may need to select a list item */
578 }
579
580 static void prefs_toolbar_up(GtkButton *button, ToolbarPage *prefs_toolbar)
581 {
582         GtkTreePath *prev, *sel;
583         GtkTreeIter isel;
584         GtkListStore *store = NULL;
585         GtkTreeModel *model = NULL;
586         GtkTreeIter iprev;
587         
588         if (!gtk_tree_selection_get_selected
589                 (gtk_tree_view_get_selection
590                         (GTK_TREE_VIEW(prefs_toolbar->list_view_set)),
591                  &model,        
592                  &isel))
593                 return;
594         store = (GtkListStore *)model;
595
596         sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
597         if (!sel)
598                 return;
599         
600         /* no move if we're at row 0... */
601         prev = gtk_tree_path_copy(sel);
602         if (!gtk_tree_path_prev(prev)) {
603                 gtk_tree_path_free(prev);
604                 gtk_tree_path_free(sel);
605                 return;
606         }
607
608         gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
609                                 &iprev, prev);
610         gtk_tree_path_free(sel);
611         gtk_tree_path_free(prev);
612
613         gtk_list_store_swap(store, &iprev, &isel);
614 }
615
616 static void prefs_toolbar_down(GtkButton *button, ToolbarPage *prefs_toolbar)
617 {
618         GtkListStore *store = NULL;
619         GtkTreeModel *model = NULL;
620         GtkTreeIter next, sel;
621         
622         if (!gtk_tree_selection_get_selected
623                 (gtk_tree_view_get_selection
624                         (GTK_TREE_VIEW(prefs_toolbar->list_view_set)),
625                  &model,
626                  &sel))
627                 return;
628
629         store = (GtkListStore *)model;
630         next = sel;
631         if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next)) 
632                 return;
633
634         gtk_list_store_swap(store, &next, &sel);
635 }
636
637 static void prefs_toolbar_selection_changed(GtkList *list,
638                                             ToolbarPage *prefs_toolbar)
639 {
640         gchar *cur_entry = g_strdup(gtk_entry_get_text(GTK_ENTRY(prefs_toolbar->combo_entry)));
641         gchar *actions_entry = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
642
643         gtk_widget_set_sensitive(prefs_toolbar->combo_syl_action, TRUE);
644
645         if (g_utf8_collate(cur_entry, actions_entry) == 0) {
646                 gtk_widget_hide(prefs_toolbar->entry_icon_text);
647                 gtk_widget_show(prefs_toolbar->combo_syl_action);
648                 gtk_label_set_text(GTK_LABEL(prefs_toolbar->label_icon_text), _("Claws Mail Action"));
649
650                 if (prefs_common.actions_list == NULL) {
651                     gtk_widget_set_sensitive(prefs_toolbar->combo_syl_action, FALSE);
652                 }
653
654         } else {
655                 gtk_widget_hide(prefs_toolbar->combo_syl_action);
656                 gtk_widget_show(prefs_toolbar->entry_icon_text);
657                 gtk_label_set_text(GTK_LABEL(prefs_toolbar->label_icon_text), _("Toolbar text"));
658         }
659
660         gtk_misc_set_alignment(GTK_MISC(prefs_toolbar->label_icon_text), 1, 0.5);
661         gtk_widget_show(prefs_toolbar->label_icon_text);
662         g_free(cur_entry);
663 }
664
665 static void prefs_toolbar_create(ToolbarPage *prefs_toolbar)
666 {
667         GtkWidget *main_vbox;
668         GtkWidget *top_hbox;
669         GtkWidget *compose_frame;
670         GtkWidget *reg_hbox;
671         GtkWidget *arrow;
672         GtkWidget *btn_hbox;
673 #ifdef MAEMO
674         GtkWidget *hbox;
675 #endif
676         GtkWidget *reg_btn;
677         GtkWidget *subst_btn;
678         GtkWidget *del_btn;
679         GtkWidget *default_btn;
680         GtkWidget *vbox_frame;
681         GtkWidget *table;
682         GtkWidget *scrolledwindow_list_view_icons;
683         GtkWidget *list_view_icons;
684         GtkWidget *label_icon_text;
685         GtkWidget *entry_icon_text;
686         GtkWidget *label_action_sel;
687         GtkWidget *combo_action;
688         GtkWidget *combo_entry;
689         GtkWidget *combo_list;
690         GtkWidget *combo_syl_action;
691         GtkWidget *combo_syl_entry;
692         GtkWidget *combo_syl_list;
693         GtkWidget *frame_toolbar_items;
694         GtkWidget *hbox_bottom;
695         GtkWidget *scrolledwindow_list_view_set;
696         GtkWidget *list_view_set;
697
698         GtkWidget *btn_vbox;
699         GtkWidget *up_btn;
700         GtkWidget *down_btn;
701
702         debug_print("Creating custom toolbar window...\n");
703
704         main_vbox = gtk_vbox_new(FALSE, 0);
705         gtk_widget_show(main_vbox);
706         
707         top_hbox = gtk_hbox_new(FALSE, 0);
708         gtk_box_pack_start(GTK_BOX(main_vbox), top_hbox, TRUE, TRUE, 0);
709   
710         compose_frame = gtk_frame_new(_("Available toolbar icons"));
711         gtk_box_pack_start(GTK_BOX(top_hbox), compose_frame, TRUE, TRUE, 0);
712         gtk_container_set_border_width(GTK_CONTAINER(compose_frame), 5);
713
714         vbox_frame = gtk_vbox_new(FALSE, 0);
715         gtk_container_add(GTK_CONTAINER(compose_frame), vbox_frame);
716
717         /* available icons */
718         scrolledwindow_list_view_icons = gtk_scrolled_window_new(NULL, NULL);
719         gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow_list_view_icons), 5);
720         gtk_box_pack_start(GTK_BOX(vbox_frame), scrolledwindow_list_view_icons,
721                            TRUE, TRUE, 0);
722         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow_list_view_icons), 
723                                        GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
724         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow_list_view_icons),
725                                             GTK_SHADOW_IN);
726
727         list_view_icons = create_icon_list_view(prefs_toolbar);
728         gtk_widget_show(list_view_icons);
729         gtk_container_add(GTK_CONTAINER(scrolledwindow_list_view_icons), list_view_icons);
730         gtk_container_set_border_width(GTK_CONTAINER(list_view_icons), 1);
731         gtk_widget_set_size_request(list_view_icons, 225, 108);
732
733         table = gtk_table_new (2, 3, FALSE);
734         gtk_box_pack_start(GTK_BOX(vbox_frame), table,
735                            FALSE, FALSE, 0);
736         gtk_container_set_border_width (GTK_CONTAINER (table), 8);
737         gtk_table_set_row_spacings (GTK_TABLE (table), 8);
738         gtk_table_set_col_spacings (GTK_TABLE (table), 8);
739         
740         /* icon description */
741         label_icon_text = gtk_label_new("");
742         gtk_misc_set_alignment(GTK_MISC(label_icon_text), 0, 0.5);
743         gtk_widget_show (label_icon_text);
744         gtk_table_attach (GTK_TABLE (table), label_icon_text, 0, 1, 0, 1,
745                           (GtkAttachOptions) (GTK_FILL),
746                           (GtkAttachOptions) (0), 0, 0);
747
748         entry_icon_text = gtk_entry_new();
749         gtk_table_attach (GTK_TABLE (table), entry_icon_text, 1, 3, 0, 1,
750                           (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
751                           (GtkAttachOptions) (0), 0, 0);
752
753         /* Sylpheed Action Combo Box */
754         combo_syl_action = gtk_combo_new();
755         combo_syl_list = GTK_COMBO(combo_syl_action)->list;
756         combo_syl_entry = GTK_COMBO(combo_syl_action)->entry;
757         gtk_entry_set_editable(GTK_ENTRY(combo_syl_entry), FALSE);
758         gtk_table_attach (GTK_TABLE (table), combo_syl_action, 1, 3, 0, 1,
759                           (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
760                           (GtkAttachOptions) (0), 0, 0);
761
762         /* available actions */
763         label_action_sel = gtk_label_new(_("Event executed on click"));
764         gtk_misc_set_alignment(GTK_MISC(label_action_sel), 0, 0.5);
765         gtk_table_attach (GTK_TABLE (table), label_action_sel, 0, 1, 1, 2,
766                           (GtkAttachOptions) (GTK_FILL),
767                           (GtkAttachOptions) (0), 0, 0);
768
769         combo_action = gtk_combo_new();
770         gtk_table_attach (GTK_TABLE (table), combo_action, 1, 3, 1, 2,
771                           (GtkAttachOptions) (GTK_FILL),
772                           (GtkAttachOptions) (0), 0, 0);
773         
774         combo_list = GTK_COMBO(combo_action)->list;
775         combo_entry = GTK_COMBO(combo_action)->entry;
776         gtk_entry_set_editable(GTK_ENTRY(combo_entry), FALSE);
777         
778         /* register / substitute / delete */
779         reg_hbox = gtk_hbox_new(FALSE, 4);
780         gtk_box_pack_start(GTK_BOX(main_vbox), reg_hbox, FALSE, FALSE, 0);
781         gtk_container_set_border_width(GTK_CONTAINER(reg_hbox), 10);
782
783         arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
784         gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
785         gtk_widget_set_size_request(arrow, -1, 16);
786
787         btn_hbox = gtk_hbox_new(TRUE, 4);
788         gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
789
790         reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
791         gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
792         g_signal_connect(G_OBJECT(reg_btn), "clicked",
793                          G_CALLBACK(prefs_toolbar_register), 
794                          prefs_toolbar);
795
796         subst_btn = gtkut_get_replace_btn(_("Replace"));
797         gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
798         g_signal_connect(G_OBJECT(subst_btn), "clicked",
799                          G_CALLBACK(prefs_toolbar_substitute),
800                          prefs_toolbar);
801
802         del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
803         gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
804         g_signal_connect(G_OBJECT(del_btn), "clicked",
805                          G_CALLBACK(prefs_toolbar_delete), 
806                           prefs_toolbar);
807
808         default_btn = gtk_button_new_with_label(_(" Use default "));
809 #ifndef MAEMO
810         gtk_box_pack_end(GTK_BOX(reg_hbox), default_btn, FALSE, TRUE, 0);
811 #else
812         hbox = gtk_hbox_new(FALSE, 0);
813         gtk_box_pack_start(GTK_BOX(main_vbox), hbox, FALSE, FALSE, 0);
814         gtk_box_pack_start(GTK_BOX(hbox), default_btn, FALSE, FALSE, 0);
815 #endif
816         g_signal_connect(G_OBJECT(default_btn), "clicked",
817                          G_CALLBACK(prefs_toolbar_default), 
818                          prefs_toolbar);
819
820         /* currently active toolbar items */
821         frame_toolbar_items = gtk_frame_new(_("Displayed toolbar items"));
822         gtk_box_pack_start(GTK_BOX(main_vbox), frame_toolbar_items, TRUE, TRUE, 0);
823         gtk_container_set_border_width(GTK_CONTAINER(frame_toolbar_items), 5);
824         
825         hbox_bottom = gtk_hbox_new(FALSE, 0);
826         gtk_container_add(GTK_CONTAINER(frame_toolbar_items), hbox_bottom);
827         
828         scrolledwindow_list_view_set = gtk_scrolled_window_new(NULL, NULL);
829         gtk_box_pack_start(GTK_BOX(hbox_bottom), scrolledwindow_list_view_set, TRUE, TRUE, 0);
830         gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow_list_view_set), 1);
831         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow_list_view_set), 
832                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
833         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow_list_view_set),
834                                             GTK_SHADOW_IN);
835
836         list_view_set = create_set_list_view(prefs_toolbar); 
837         gtk_widget_show(list_view_set);
838         gtk_container_add(GTK_CONTAINER(scrolledwindow_list_view_set), list_view_set);
839         gtk_widget_set_size_request(list_view_set, 225, 120);
840
841         btn_vbox = gtk_vbox_new(FALSE, 8);
842         gtk_widget_show(btn_vbox);
843         gtk_box_pack_start(GTK_BOX(hbox_bottom), btn_vbox, FALSE, FALSE, 5);
844
845         up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
846         gtk_widget_show(up_btn);
847         gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 2);
848
849         down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
850         gtk_widget_show(down_btn);
851         gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
852
853         g_signal_connect(G_OBJECT(combo_list), "selection-changed",
854                          G_CALLBACK(prefs_toolbar_selection_changed),
855                          prefs_toolbar);
856         g_signal_connect(G_OBJECT(up_btn), "clicked",
857                          G_CALLBACK(prefs_toolbar_up), prefs_toolbar);
858         g_signal_connect(G_OBJECT(down_btn), "clicked",
859                          G_CALLBACK(prefs_toolbar_down), prefs_toolbar);
860         
861         gtk_widget_show_all(main_vbox);
862
863         prefs_toolbar->list_view_icons  = list_view_icons;
864         prefs_toolbar->list_view_set    = list_view_set;
865         prefs_toolbar->combo_action     = combo_action;
866         prefs_toolbar->combo_entry      = combo_entry;
867         prefs_toolbar->combo_list       = combo_list;
868         prefs_toolbar->entry_icon_text  = entry_icon_text;
869         prefs_toolbar->combo_syl_action = combo_syl_action;
870         prefs_toolbar->combo_syl_list   = combo_syl_list;
871         prefs_toolbar->combo_syl_entry  = combo_syl_entry;
872
873         prefs_toolbar->label_icon_text  = label_icon_text;
874         prefs_toolbar->label_action_sel = label_action_sel;
875
876         prefs_toolbar->page.widget = main_vbox;
877 }
878
879 ToolbarPage *prefs_toolbar_mainwindow;
880 ToolbarPage *prefs_toolbar_composewindow;
881 ToolbarPage *prefs_toolbar_messageview;
882
883 void prefs_toolbar_init(void)
884 {
885         ToolbarPage *page;
886         static gchar *mainpath[3], *messagepath[3], *composepath[3];
887
888         mainpath[0] = _("Customize Toolbars");
889         mainpath[1] = _("Main Window");
890         mainpath[2] = NULL;
891
892         page = g_new0(ToolbarPage, 1);
893         page->page.path = mainpath;
894         page->page.create_widget = prefs_toolbar_create_widget;
895         page->page.destroy_widget = prefs_toolbar_destroy_widget;
896         page->page.save_page = prefs_toolbar_save;
897         page->source = TOOLBAR_MAIN;
898         page->page.weight = 50.0;
899         prefs_gtk_register_page((PrefsPage *) page);
900         prefs_toolbar_mainwindow = page;
901
902         messagepath[0] = _("Customize Toolbars");
903         messagepath[1] = _("Message Window");
904         messagepath[2] = NULL;
905
906         page = g_new0(ToolbarPage, 1);
907         page->page.path = messagepath;
908         page->page.create_widget = prefs_toolbar_create_widget;
909         page->page.destroy_widget = prefs_toolbar_destroy_widget;
910         page->page.save_page = prefs_toolbar_save;
911         page->source = TOOLBAR_MSGVIEW;
912         page->page.weight = 45.0;
913         prefs_gtk_register_page((PrefsPage *) page);
914         prefs_toolbar_messageview = page;
915
916         composepath[0] = _("Customize Toolbars");
917         composepath[1] = _("Compose Window");
918         composepath[2] = NULL;
919
920         page = g_new0(ToolbarPage, 1);
921         page->page.path = composepath;
922         page->page.create_widget = prefs_toolbar_create_widget;
923         page->page.destroy_widget = prefs_toolbar_destroy_widget;
924         page->page.save_page = prefs_toolbar_save;
925         page->source = TOOLBAR_COMPOSE;
926         page->page.weight = 40.0;
927         prefs_gtk_register_page((PrefsPage *) page);
928         prefs_toolbar_composewindow = page;
929 }
930
931 void prefs_toolbar_done(void)
932 {
933         prefs_gtk_unregister_page((PrefsPage *) prefs_toolbar_mainwindow);
934         g_free(prefs_toolbar_mainwindow);
935         prefs_gtk_unregister_page((PrefsPage *) prefs_toolbar_composewindow);
936         g_free(prefs_toolbar_composewindow);
937         prefs_gtk_unregister_page((PrefsPage *) prefs_toolbar_messageview);
938         g_free(prefs_toolbar_messageview);
939 }
940
941 static void set_visible_if_not_text(GtkTreeViewColumn *col,
942                                     GtkCellRenderer   *renderer,
943                                     GtkTreeModel      *model,
944                                     GtkTreeIter       *iter,
945                                     gpointer           user_data)
946 {
947         gboolean is_text;
948         GdkPixbuf *pixbuf;
949
950         gtk_tree_model_get(model, iter, SET_ICON_IS_TEXT, &is_text, -1);
951         if (is_text) {
952                 g_object_set(renderer, "visible", FALSE, NULL); 
953         } else {
954                 pixbuf = NULL;
955                 gtk_tree_model_get(model, iter, 
956                                    SET_ICON, &pixbuf,
957                                    -1);
958                 /* note getting a pixbuf from a tree model increases
959                  * its refcount ... */
960                 g_object_unref(pixbuf);
961                 
962                 g_object_set(renderer, "visible", TRUE, NULL);
963                 g_object_set(renderer, "pixbuf",  pixbuf, NULL);
964         }
965 }
966
967 static GtkWidget *create_icon_list_view(ToolbarPage *prefs_toolbar)
968 {
969         GtkTreeView *list_view;
970         GtkListStore *store;
971         GtkCellRenderer *renderer;
972         GtkTreeViewColumn *column;
973         GtkTreeSelection *selector;
974
975         /* XXX: for icon list we don't need SET_TEXT, and SET_EVENT */
976         store = gtk_list_store_new(N_SET_COLUMNS, 
977                                    GDK_TYPE_PIXBUF,
978                                    G_TYPE_STRING,
979                                    G_TYPE_STRING,
980                                    G_TYPE_STRING,
981                                    G_TYPE_STRING,
982                                    G_TYPE_BOOLEAN,
983                                    -1);
984         list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
985         g_object_unref(G_OBJECT(store));
986
987         column = gtk_tree_view_column_new();
988         renderer = gtk_cell_renderer_pixbuf_new();
989         gtk_tree_view_column_pack_start(column, renderer, FALSE);
990         
991         /* tell pixbuf renderer it is only visible if 
992          * the icon is not represented by text */
993         gtk_tree_view_column_set_cell_data_func(column, renderer,
994                                                 set_visible_if_not_text,
995                                                 NULL, NULL);
996         
997         renderer = gtk_cell_renderer_text_new();
998         gtk_tree_view_column_pack_start(column, renderer, FALSE);
999         
1000         /* tell the text renderer it is only visible if the icon
1001          * is represented by an image */
1002         gtk_tree_view_column_set_attributes(column, renderer,
1003                                             "visible", SET_ICON_IS_TEXT, 
1004                                             "text", SET_ICON_TEXT,
1005                                             NULL);
1006
1007         gtk_tree_view_append_column(list_view, column);
1008
1009         column = gtk_tree_view_column_new();
1010         renderer = gtk_cell_renderer_text_new();
1011         gtk_tree_view_column_pack_start(column, renderer, TRUE);
1012         gtk_tree_view_column_set_attributes(column, renderer,
1013                                             "text", SET_FILENAME,
1014                                             NULL);
1015         
1016         gtk_tree_view_append_column(list_view, column);
1017
1018         /* various other tree view attributes */
1019         gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1020         gtk_tree_view_set_headers_visible(list_view, FALSE);
1021         
1022         selector = gtk_tree_view_get_selection(list_view);
1023         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1024         gtk_tree_selection_set_select_function
1025                 (selector, (GtkTreeSelectionFunc) icon_list_selected,
1026                  prefs_toolbar, NULL);
1027
1028         return GTK_WIDGET(list_view);   
1029 }
1030
1031 static GtkWidget *create_set_list_view(ToolbarPage *prefs_toolbar)
1032 {
1033         GtkTreeView *list_view;
1034         GtkListStore *store;
1035         GtkCellRenderer *renderer;
1036         GtkTreeViewColumn *column;
1037         GtkTreeSelection *selector;
1038
1039         store = gtk_list_store_new(N_SET_COLUMNS, 
1040                                    GDK_TYPE_PIXBUF,
1041                                    G_TYPE_STRING,
1042                                    G_TYPE_STRING,
1043                                    G_TYPE_STRING,
1044                                    G_TYPE_STRING,
1045                                    G_TYPE_BOOLEAN,
1046                                    -1);
1047         list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
1048         g_object_unref(G_OBJECT(store));
1049
1050         column = gtk_tree_view_column_new();
1051         gtk_tree_view_column_set_title(column, _("Icon"));
1052         renderer = gtk_cell_renderer_pixbuf_new();
1053         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1054         
1055         /* tell pixbuf renderer it is only visible if 
1056          * the icon is not represented by text */
1057         gtk_tree_view_column_set_cell_data_func(column, renderer,
1058                                                 set_visible_if_not_text,
1059                                                 NULL, NULL);
1060         
1061         renderer = gtk_cell_renderer_text_new();
1062         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1063         
1064         /* tell the text renderer it is only visible if the icon
1065          * is represented by an image */
1066         gtk_tree_view_column_set_attributes(column, renderer,
1067                                             "visible", SET_ICON_IS_TEXT,
1068                                             "text", SET_ICON_TEXT,
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, _("File name"));
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_FILENAME,
1079                                             NULL);
1080         
1081         gtk_tree_view_append_column(list_view, column);
1082
1083         column = gtk_tree_view_column_new();
1084         gtk_tree_view_column_set_title(column, _("Icon text"));
1085         renderer = gtk_cell_renderer_text_new();
1086         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1087         gtk_tree_view_column_set_attributes(column, renderer,
1088                                             "text", SET_TEXT,
1089                                             NULL);
1090         gtk_tree_view_append_column(list_view, column);
1091
1092         column = gtk_tree_view_column_new();
1093         gtk_tree_view_column_set_title(column, _("Mapped event"));
1094         renderer = gtk_cell_renderer_text_new();
1095         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1096         gtk_tree_view_column_set_attributes(column, renderer,
1097                                             "text", SET_EVENT,
1098                                             NULL);
1099         gtk_tree_view_append_column(list_view, column);
1100
1101         /* various other tree view attributes */
1102         gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1103         
1104         selector = gtk_tree_view_get_selection(list_view);
1105         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1106         gtk_tree_selection_set_select_function
1107                 (selector, (GtkTreeSelectionFunc) set_list_selected,
1108                  prefs_toolbar, NULL);
1109
1110         return GTK_WIDGET(list_view);   
1111
1112 }
1113
1114 static gboolean icon_list_selected(GtkTreeSelection *selector,
1115                                    GtkTreeModel *model, 
1116                                    GtkTreePath *path,
1117                                    gboolean currently_selected,
1118                                    ToolbarPage *prefs_toolbar)
1119 {
1120         GtkTreeIter iter;
1121         gchar *text;
1122         
1123         if (currently_selected ||!gtk_tree_model_get_iter(model, &iter, path))
1124                 return TRUE;
1125
1126         text = NULL;
1127         gtk_tree_model_get(model, &iter, 
1128                            SET_FILENAME, &text,
1129                            -1);
1130         if (!text) 
1131                 return TRUE;
1132
1133         if (g_utf8_collate(toolbar_ret_descr_from_val(A_SEPARATOR), text) == 0) {
1134                 gtk_widget_set_sensitive(prefs_toolbar->combo_action,     FALSE);
1135                 gtk_widget_set_sensitive(prefs_toolbar->entry_icon_text,  FALSE);
1136                 gtk_widget_set_sensitive(prefs_toolbar->combo_syl_action, FALSE);
1137         } else {
1138                 gtk_widget_set_sensitive(prefs_toolbar->combo_action,     TRUE);
1139                 gtk_widget_set_sensitive(prefs_toolbar->entry_icon_text,  TRUE);
1140                 gtk_widget_set_sensitive(prefs_toolbar->combo_syl_action, TRUE);
1141         }
1142         
1143         g_free(text);
1144
1145         return TRUE;
1146 }
1147
1148 static gboolean set_list_selected(GtkTreeSelection *selector,
1149                                   GtkTreeModel *model, 
1150                                   GtkTreePath *path,
1151                                   gboolean currently_selected,
1152                                   ToolbarPage *prefs_toolbar)
1153 {
1154         GtkTreeIter iter;
1155         GtkTreeView *list_ico = GTK_TREE_VIEW(prefs_toolbar->list_view_icons);
1156         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
1157         gchar *file, *icon_text, *descr;
1158         GList *cur;
1159         gint item_num;
1160         GtkTreeModel *model_ico;
1161         
1162         if (currently_selected || !gtk_tree_model_get_iter(model, &iter, path))
1163                 return TRUE;
1164         
1165         gtk_tree_model_get(model, &iter,
1166                            SET_FILENAME, &file,
1167                            SET_TEXT, &icon_text,
1168                            SET_EVENT, &descr,
1169                            -1);
1170
1171         /* Separator */
1172         if (icon_text == NULL) {
1173                 return TRUE;
1174         }
1175
1176         if (g_utf8_collate(descr, syl_act))
1177                 gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->entry_icon_text), 
1178                                    icon_text);
1179         
1180         /* scan combo list for selected description an set combo item accordingly */
1181         for (cur = prefs_toolbar->combo_action_list, item_num = 0; cur != NULL; 
1182              cur = cur->next) {
1183                 gchar *item_str = (gchar*)cur->data;
1184                 if (g_utf8_collate(item_str, descr) == 0) {
1185                         gtk_list_select_item(GTK_LIST(prefs_toolbar->combo_list), item_num);
1186                         break;
1187                 }
1188                 else
1189                         item_num++;
1190         }
1191
1192         model_ico = gtk_tree_view_get_model(list_ico);
1193         if (gtk_tree_model_get_iter_first(model_ico, &iter)) {
1194                 gchar *entry;
1195                 gboolean found = FALSE;
1196                 
1197                 /* find in icon list, scroll to item */
1198                 do {
1199                         entry = NULL;
1200                         gtk_tree_model_get(model_ico, &iter,
1201                                            SET_FILENAME, &entry,
1202                                            -1);
1203                         found = entry && !g_utf8_collate(entry, file);
1204                         g_free(entry);
1205                         if (found) 
1206                                 break;
1207                 } while(gtk_tree_model_iter_next(model_ico, &iter));
1208
1209                 if (found) {
1210                         GtkTreePath *path;
1211
1212                         gtk_tree_selection_select_iter
1213                                 (gtk_tree_view_get_selection(list_ico), &iter); 
1214                         path = gtk_tree_model_get_path(model_ico, &iter); 
1215                         gtk_tree_view_set_cursor(list_ico, path, NULL, FALSE);
1216                         gtk_tree_path_free(path);
1217                 }
1218         }
1219
1220         g_free(file);
1221         g_free(icon_text);
1222         g_free(descr);
1223
1224         return TRUE;
1225 }