2009-11-17 [holger] 3.7.3cvs14
[claws.git] / src / prefs_toolbar.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2002-2009 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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
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 <gdk/gdkkeysyms.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36
37 #include "stock_pixmap.h"
38 #include "manage_window.h"
39 #include "combobox.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 #include "plugin.h"
52
53 enum
54 {
55         SET_ICON          = 0,
56         SET_FILENAME      = 1,
57         SET_TEXT          = 2,
58         SET_EVENT         = 3,
59         SET_ICON_TEXT     = 4,          /*!< "icon" text (separator) */ 
60         SET_ICON_IS_TEXT  = 5,          /*!< icon is text representation */
61         N_SET_COLUMNS
62 };
63
64 enum
65 {
66         ITEM_FUNCTION     = 0,
67         ITEM_USER_ACTION  = 1,
68         ITEM_SEPARATOR    = 2,
69         ITEM_PLUGIN       = 3,
70 };
71
72 static const gint ToolbarIcons[] =
73 {
74         STOCK_PIXMAP_ADDRESS_BOOK,
75         STOCK_PIXMAP_ADDRESS_SEARCH,
76         STOCK_PIXMAP_BOOK,
77         STOCK_PIXMAP_CATEGORY,
78         STOCK_PIXMAP_CHECK_SPELLING,
79         STOCK_PIXMAP_CLOSE,
80         STOCK_PIXMAP_DOWN_ARROW,
81         STOCK_PIXMAP_UP_ARROW,
82         STOCK_PIXMAP_EDIT_EXTERN,
83         STOCK_PIXMAP_ERROR,
84         STOCK_PIXMAP_EXEC,
85         STOCK_PIXMAP_GROUP,
86         STOCK_PIXMAP_INSERT_FILE,
87         STOCK_PIXMAP_INTERFACE,
88         STOCK_PIXMAP_JPILOT,
89         STOCK_PIXMAP_LDAP,
90         STOCK_PIXMAP_LINEWRAP_CURRENT,
91         STOCK_PIXMAP_LINEWRAP_ALL,
92         STOCK_PIXMAP_MAIL,
93         STOCK_PIXMAP_MAIL_ATTACH,
94         STOCK_PIXMAP_MAIL_COMPOSE,
95         STOCK_PIXMAP_MAIL_FORWARD,
96         STOCK_PIXMAP_MAIL_RECEIVE,
97         STOCK_PIXMAP_MAIL_RECEIVE_ALL,
98         STOCK_PIXMAP_MAIL_REPLY,
99         STOCK_PIXMAP_MAIL_REPLY_TO_ALL,
100         STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR,
101         STOCK_PIXMAP_MAIL_REPLY_TO_LIST,
102         STOCK_PIXMAP_MAIL_SEND,
103         STOCK_PIXMAP_MAIL_SEND_QUEUE,
104         STOCK_PIXMAP_MAIL_SIGN,
105         STOCK_PIXMAP_OPEN_MAIL,
106         STOCK_PIXMAP_NEWS_COMPOSE,
107         STOCK_PIXMAP_PASTE,
108         STOCK_PIXMAP_PREFERENCES,
109         STOCK_PIXMAP_PROPERTIES,
110         STOCK_PIXMAP_VCARD,
111         STOCK_PIXMAP_ONLINE,
112         STOCK_PIXMAP_OFFLINE,
113         STOCK_PIXMAP_NOTICE_WARN,               /* small warning */
114         STOCK_PIXMAP_NOTICE_ERROR,              /* small error   */
115         STOCK_PIXMAP_NOTICE_NOTE,               /* small message */
116         STOCK_PIXMAP_GO_FOLDERS,
117         STOCK_PIXMAP_MIME_TEXT_PLAIN,
118         STOCK_PIXMAP_MIME_TEXT_HTML,
119         STOCK_PIXMAP_MIME_TEXT_PATCH,
120         STOCK_PIXMAP_MIME_APPLICATION,
121         STOCK_PIXMAP_MIME_IMAGE,
122         STOCK_PIXMAP_MIME_AUDIO,
123         STOCK_PIXMAP_MIME_TEXT_ENRICHED,
124         STOCK_PIXMAP_MIME_UNKNOWN,
125         STOCK_PIXMAP_MIME_PDF,
126         STOCK_PIXMAP_MIME_PS,
127         STOCK_PIXMAP_MIME_TEXT_CALENDAR,
128         STOCK_PIXMAP_MIME_PGP_SIG,
129         STOCK_PIXMAP_PRINTER,
130         STOCK_PIXMAP_PRIVACY_SIGNED,
131         STOCK_PIXMAP_PRIVACY_PASSED,
132         STOCK_PIXMAP_PRIVACY_FAILED,
133         STOCK_PIXMAP_PRIVACY_UNKNOWN,
134         STOCK_PIXMAP_PRIVACY_EXPIRED,
135         STOCK_PIXMAP_PRIVACY_WARN,
136         STOCK_PIXMAP_PRIVACY_EMBLEM_SIGNED,
137         STOCK_PIXMAP_PRIVACY_EMBLEM_PASSED,
138         STOCK_PIXMAP_PRIVACY_EMBLEM_FAILED,
139         STOCK_PIXMAP_PRIVACY_EMBLEM_WARN,
140         STOCK_PIXMAP_MIME_MESSAGE,
141         STOCK_PIXMAP_SPAM_BTN,
142         STOCK_PIXMAP_HAM_BTN,
143         STOCK_PIXMAP_TRASH,
144         STOCK_PIXMAP_DELETE,
145         STOCK_PIXMAP_CANCEL,
146         STOCK_PIXMAP_EMPTY,              /* last entry */
147 };
148
149 typedef struct _ToolbarPage
150 {
151         PrefsPage  page;
152
153         GtkWidget *window;              /* do not modify */
154
155         ToolbarType source;
156         GList     *combo_action_list;   /* list of internal functions    */
157
158         GtkWidget *list_view_set;       /* toolbar items treeview        */
159         GtkWidget *item_text_entry;     /* item name                     */
160         GtkWidget *item_type_combo;     /* item type selection widget    */
161         GtkWidget *item_func_combo;     /* item internal function widget */
162         GtkWidget *item_action_combo;   /* item user action widget       */
163         GtkWidget *item_plugin_combo;   /* items registered by plugins */
164         GtkWidget *icon_button;         /* item icon chooser widget      */
165         
166         GtkWidget *icon_chooser_win;
167         GtkWidget *icon_chooser_view;
168         
169         gchar *item_icon_file;          /* item icon file                */
170
171 } ToolbarPage;
172
173 #define ERROR_MSG _("Selected Action already set.\nPlease choose another Action from List")
174 #define ERROR_MSG_NO_ICON _("Item has no icon defined.")
175 #define ERROR_MSG_NO_TEXT _("Item has no text defined.")
176
177 typedef struct _ToolbarPluginItem ToolbarPluginItem;
178 struct _ToolbarPluginItem {
179         gchar *plugin;
180         gchar *item_name;
181         ToolbarPluginCallback cb;
182         gpointer cb_data;
183 };
184
185 /* items registered by plugins */
186 static GHashTable *plugin_items = NULL;
187
188 static void prefs_toolbar_populate               (ToolbarPage *prefs_toolbar);
189
190 static void get_action_name                      (const gchar *entry, 
191                                                   gchar **menu);
192                                                   
193 static gboolean is_duplicate                     (ToolbarPage *prefs_toolbar,
194                                                   gchar            *chosen_action);
195 static void prefs_toolbar_save                   (PrefsPage        *_page);
196
197 static void prefs_toolbar_register               (GtkButton        *button,
198                                                   ToolbarPage *prefs_toolbar);
199 static void prefs_toolbar_substitute             (GtkButton        *button,
200                                                   ToolbarPage *prefs_toolbar);
201 static void prefs_toolbar_delete                 (GtkButton        *button,
202                                                   ToolbarPage *prefs_toolbar);
203
204 static void prefs_toolbar_up                     (GtkButton        *button,
205                                                   ToolbarPage *prefs_toolbar);
206
207 static void prefs_toolbar_down                   (GtkButton        *button,
208                                                   ToolbarPage *prefs_toolbar);
209
210 static void action_selection_changed             (GtkComboBox *action_combo,
211                                                   ToolbarPage *prefs_toolbar);
212 static void plugin_selection_changed         (GtkComboBox *action_combo,
213                           ToolbarPage *prefs_toolbar);
214
215 static void func_selection_changed               (GtkComboBox *action_combo,
216                                                   ToolbarPage *prefs_toolbar);
217
218 static void prefs_toolbar_create                 (ToolbarPage *prefs_toolbar);
219
220 static GtkWidget *create_set_list_view           (ToolbarPage *prefs_toolbar);
221
222 static gboolean set_list_selected                (GtkTreeSelection *selector,
223                                                   GtkTreeModel *model, 
224                                                   GtkTreePath *path,
225                                                   gboolean currently_selected,
226                                                   ToolbarPage *prefs_toolbar);
227
228 static void icon_chooser_create                  (GtkButton *button,
229                                                   ToolbarPage *prefs_toolbar);
230
231 static void prefs_toolbar_create_widget(PrefsPage *_page, GtkWindow *window, gpointer data)
232 {
233         ToolbarPage *prefs_toolbar = (ToolbarPage *) _page;
234         gchar *win_titles[3];
235         win_titles[TOOLBAR_MAIN]    = _("Main toolbar configuration");
236         win_titles[TOOLBAR_COMPOSE] = _("Compose toolbar configuration");  
237         win_titles[TOOLBAR_MSGVIEW] = _("Message view toolbar configuration");  
238
239         prefs_toolbar->window = GTK_WIDGET(window);
240
241         toolbar_read_config_file(prefs_toolbar->source);
242
243         prefs_toolbar_create(prefs_toolbar);
244         prefs_toolbar_populate(prefs_toolbar);
245 }
246
247 static void prefs_toolbar_save(PrefsPage *_page)
248 {
249         ToolbarPage *prefs_toolbar = (ToolbarPage *) _page;
250         GtkTreeView *list_view = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
251         GtkTreeModel *model = gtk_tree_view_get_model(list_view);
252         GtkTreeIter iter;
253         
254         toolbar_clear_list(prefs_toolbar->source);
255
256         if (!gtk_tree_model_iter_n_children(model, NULL)
257         ||  !gtk_tree_model_get_iter_first(model, &iter))
258                 toolbar_set_default(prefs_toolbar->source);
259         else {
260                 do {
261                         ToolbarItem *item;
262                         gchar *fname, *text, *event; 
263                         
264                         item = g_new0(ToolbarItem, 1);
265
266                         gtk_tree_model_get(model, &iter,
267                                            SET_FILENAME, &fname,
268                                            SET_TEXT, &text,
269                                            SET_EVENT, &event,
270                                            -1);
271
272                         /* XXX: remember that G_TYPE_STRING returned by model
273                          * is owned by caller of gtk_tree_model_get() */
274                         item->file  = fname;
275                         item->text  = text;
276                         item->index = toolbar_ret_val_from_descr(event);
277                         g_free(event);
278
279                         /* TODO: save A_CLAWS_ACTIONS only if they are still active */
280                         toolbar_set_list_item(item, prefs_toolbar->source);
281
282                         g_free(item->file);
283                         g_free(item->text);
284                         g_free(item);
285                 } while (gtk_tree_model_iter_next(model, &iter));
286         }
287
288         toolbar_save_config_file(prefs_toolbar->source);
289
290         if (prefs_toolbar->source == TOOLBAR_MAIN) 
291                 toolbar_update(TOOLBAR_MAIN, mainwindow_get_mainwindow());
292         else if (prefs_toolbar->source == TOOLBAR_COMPOSE)
293                 compose_reflect_prefs_pixmap_theme();
294         else if (prefs_toolbar->source == TOOLBAR_MSGVIEW)
295                 messageview_reflect_prefs_pixmap_theme();
296 }
297
298 static void prefs_toolbar_destroy_widget(PrefsPage *_page)
299 {
300         ToolbarPage *prefs_toolbar = (ToolbarPage *) _page;
301
302         g_list_free(prefs_toolbar->combo_action_list);
303         prefs_toolbar->combo_action_list = NULL;
304 }
305
306 static void prefs_toolbar_set_displayed(ToolbarPage *prefs_toolbar)
307 {
308         GSList *cur;
309         GtkTreeView *list_view_set = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
310         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model
311                                                 (list_view_set));
312         GSList *toolbar_list = toolbar_get_list(prefs_toolbar->source);
313         GtkTreeIter iter;
314
315         gtk_list_store_clear(store);
316
317         /* set currently active toolbar entries */
318         for (cur = toolbar_list; cur != NULL; cur = cur->next) {
319                 ToolbarItem *item = (ToolbarItem*) cur->data;
320
321                 gtk_list_store_append(store, &iter);
322         
323                 if (item->index != A_SEPARATOR) {
324                         GdkPixbuf *pix;
325                         StockPixmap icon = stock_pixmap_get_icon(item->file);
326                         
327                         stock_pixbuf_gdk(prefs_toolbar->window, icon, &pix);
328
329                         gtk_list_store_set(store, &iter, 
330                                            SET_ICON, pix,
331                                            SET_FILENAME, item->file,
332                                            SET_TEXT, item->text,
333                                            SET_EVENT, toolbar_ret_descr_from_val(item->index),
334                                            SET_ICON_TEXT, NULL, 
335                                            SET_ICON_IS_TEXT, FALSE,
336                                            -1);
337                 } else {
338                         gtk_list_store_set(store, &iter,
339                                            SET_ICON, NULL,
340                                            SET_FILENAME, toolbar_ret_descr_from_val(A_SEPARATOR),
341                                            SET_TEXT, (const gchar *) "", 
342                                            SET_EVENT, toolbar_ret_descr_from_val(A_SEPARATOR),
343                                            SET_ICON_TEXT, (const gchar *) SEPARATOR_PIXMAP,
344                                            SET_ICON_IS_TEXT, TRUE,
345                                            -1);
346                 }
347         }
348
349         /* select first */
350         gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
351         gtk_tree_selection_select_iter(gtk_tree_view_get_selection
352                                                 (list_view_set),
353                                        &iter);  
354 }
355
356 static void add_item_to_plugin_combo(gpointer key, gpointer data, gpointer combo_box)
357 {
358     gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), (const gchar*)key);
359 }
360
361 static void prefs_toolbar_populate(ToolbarPage *prefs_toolbar)
362 {
363         GSList *cur;
364         gchar *act, *act_name;
365
366         prefs_toolbar->combo_action_list = toolbar_get_action_items(prefs_toolbar->source);
367         combobox_set_popdown_strings(GTK_COMBO_BOX(prefs_toolbar->item_func_combo),
368                                      prefs_toolbar->combo_action_list);
369         
370         /* get currently defined sylpheed actions */
371         if (prefs_common.actions_list != NULL) {
372                 for (cur = prefs_common.actions_list; cur != NULL; cur = cur->next) {
373                         act = (gchar *)cur->data;
374                         get_action_name(act, &act_name);
375                         
376                         gtk_combo_box_append_text(
377                                 GTK_COMBO_BOX(prefs_toolbar->item_action_combo),
378                                 act_name);
379
380                         g_free(act_name);
381                 } 
382
383         }
384         
385         /* items registered by plugins */
386         if(plugin_items)
387           g_hash_table_foreach(plugin_items, add_item_to_plugin_combo, prefs_toolbar->item_plugin_combo);
388
389         gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_func_combo), 0);
390         gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_action_combo), 0);
391         gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), 0);
392         
393         prefs_toolbar_set_displayed(prefs_toolbar);
394
395         toolbar_clear_list(prefs_toolbar->source);
396 }
397
398 static gboolean is_duplicate(ToolbarPage *prefs_toolbar, gchar *chosen_action)
399 {
400         GtkTreeView *list_view_set = GTK_TREE_VIEW
401                                         (prefs_toolbar->list_view_set);
402         GtkTreeModel *model_set = gtk_tree_view_get_model(list_view_set);                                       
403         gchar *entry;
404         GtkTreeIter iter;
405         gboolean result;
406
407         cm_return_val_if_fail(chosen_action != NULL, TRUE);
408
409         if (!gtk_tree_model_iter_n_children(model_set, NULL))
410                 return FALSE;
411         
412         if (!gtk_tree_model_get_iter_first(model_set, &iter))
413                 return FALSE;
414
415         result = FALSE;
416         do {
417                 gtk_tree_model_get(model_set, &iter,
418                                    SET_EVENT, &entry, 
419                                    -1);
420                 if (g_utf8_collate(chosen_action, entry) == 0) 
421                         result = TRUE;
422                 g_free(entry);                  
423         } while (!result && gtk_tree_model_iter_next(model_set, &iter));
424
425         return result;
426 }
427
428 static void prefs_toolbar_default(GtkButton *button, ToolbarPage *prefs_toolbar)
429 {
430         toolbar_clear_list(prefs_toolbar->source);
431         toolbar_set_default(prefs_toolbar->source);
432         prefs_toolbar_set_displayed(prefs_toolbar);
433 }
434
435 /*!
436  *\return       String that should be freed by caller.
437  */
438 static void get_action_name(const gchar *entry, gchar **menu)
439 {
440         gchar *act, *act_p;
441         
442         *menu = NULL;
443
444         if (prefs_common.actions_list != NULL) {
445                 
446                 act = g_strdup(entry);
447                 act_p = strstr(act, ": ");
448                 if (act_p != NULL)
449                         act_p[0] = 0x00;
450                 /* freed by calling func */
451                 *menu = act;
452         }
453 }
454
455 static void prefs_toolbar_register(GtkButton *button, ToolbarPage *prefs_toolbar)
456 {
457         GtkTreeView *list_view_set   = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
458         gint item_type = gtk_combo_box_get_active(GTK_COMBO_BOX(prefs_toolbar->item_type_combo));
459         GtkListStore *store_set;
460         GtkTreeIter iter;
461
462         store_set = GTK_LIST_STORE(gtk_tree_view_get_model(list_view_set));
463
464         /* SEPARATOR or other ? */
465         if (item_type == ITEM_SEPARATOR) {
466                 gtk_list_store_append(store_set, &iter);
467                 gtk_list_store_set(store_set, &iter,
468                                    SET_ICON, NULL,
469                                    SET_FILENAME, prefs_toolbar->item_icon_file,
470                                    SET_TEXT, NULL,
471                                    SET_EVENT, toolbar_ret_descr_from_val(A_SEPARATOR),
472                                    SET_ICON_TEXT, (const gchar *) SEPARATOR_PIXMAP,
473                                    SET_ICON_IS_TEXT, TRUE,
474                                    -1);
475         } else {
476                 GdkPixbuf *pixbuf;
477                 gchar *event, *text;
478
479                 if (prefs_toolbar->item_icon_file == NULL) {
480                         alertpanel_error(ERROR_MSG_NO_ICON);
481                         return;
482                 }
483                 stock_pixbuf_gdk(prefs_toolbar->window, 
484                                  stock_pixmap_get_icon(prefs_toolbar->item_icon_file),
485                                  &pixbuf);
486                 if(pixbuf == NULL) {
487                         alertpanel_error(ERROR_MSG_NO_ICON);
488                         return;
489                 }
490                                 
491                 if (item_type == ITEM_FUNCTION) {
492                         event = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
493                                                 prefs_toolbar->item_func_combo));
494                                                 
495                         if (is_duplicate(prefs_toolbar, event)) {
496                                 alertpanel_error(ERROR_MSG);
497                                 g_free(event);
498                                 return;
499                         }
500                 } else if(item_type == ITEM_PLUGIN)
501                   event = toolbar_ret_descr_from_val(A_CLAWS_PLUGINS);
502                 else
503                         event = toolbar_ret_descr_from_val(A_CLAWS_ACTIONS);
504                 
505                 text = gtk_editable_get_chars(
506                         GTK_EDITABLE(prefs_toolbar->item_text_entry), 0 , -1);
507
508                 if (text != NULL) {
509                         gtk_list_store_append(store_set, &iter);
510                         gtk_list_store_set(store_set, &iter,
511                                            SET_ICON, pixbuf,
512                                            SET_FILENAME, prefs_toolbar->item_icon_file,
513                                            SET_TEXT, text,
514                                            SET_EVENT, event,
515                                            SET_ICON_TEXT, NULL,
516                                            SET_ICON_IS_TEXT, FALSE,
517                                            -1);
518                 } else {
519                         alertpanel_error(ERROR_MSG_NO_TEXT);
520                         return;
521                 }
522                 
523                 g_free(text);
524                 if((item_type != ITEM_USER_ACTION) && (item_type != ITEM_PLUGIN))
525                         g_free(event);
526         }
527         
528         gtk_tree_selection_select_iter(gtk_tree_view_get_selection
529                                                 (list_view_set),
530                                        &iter);
531 }
532
533 static void prefs_toolbar_substitute(GtkButton *button, ToolbarPage *prefs_toolbar)
534 {
535         GtkTreeView *list_view_set   = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
536         GtkListStore *store_set   = GTK_LIST_STORE(gtk_tree_view_get_model(list_view_set));
537         gint item_type = gtk_combo_box_get_active(GTK_COMBO_BOX(prefs_toolbar->item_type_combo));
538         GtkTreeSelection *sel_set;
539         GtkTreeIter iter_set;
540
541         if (!gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store_set), NULL))
542                 return;
543                 
544         sel_set = gtk_tree_view_get_selection(list_view_set);           
545         if (!gtk_tree_selection_get_selected(sel_set, NULL, &iter_set))
546                 return;
547
548         if (item_type == ITEM_SEPARATOR) {
549                 gtk_list_store_set(store_set, &iter_set, 
550                                    SET_ICON, NULL,
551                                    SET_TEXT, NULL,
552                                    SET_EVENT, toolbar_ret_descr_from_val(A_SEPARATOR),
553                                    SET_FILENAME, prefs_toolbar->item_icon_file,
554                                    SET_ICON_TEXT, (const gchar *) SEPARATOR_PIXMAP,
555                                    SET_ICON_IS_TEXT, TRUE,
556                                    -1);
557         } else {
558                 GdkPixbuf *pixbuf;
559                 gchar *icon_event, *set_event, *text;
560
561                 if (prefs_toolbar->item_icon_file == NULL) {
562                         alertpanel_error(ERROR_MSG_NO_ICON);
563                         return;
564                 }
565                 stock_pixbuf_gdk(prefs_toolbar->window, 
566                                  stock_pixmap_get_icon(prefs_toolbar->item_icon_file),
567                                  &pixbuf);
568                 if(pixbuf == NULL) {
569                         alertpanel_error(ERROR_MSG_NO_ICON);
570                         return;
571                 }
572
573                 gtk_tree_model_get(GTK_TREE_MODEL(store_set), &iter_set, 
574                                                   SET_EVENT, &set_event,
575                                                   -1);
576                 
577                 if (item_type == ITEM_FUNCTION) {
578                         icon_event = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
579                                                 prefs_toolbar->item_func_combo));
580                                                 
581                         if (is_duplicate(prefs_toolbar, icon_event)
582                         && g_utf8_collate(icon_event, set_event) != 0){
583                                 alertpanel_error(ERROR_MSG);
584                                 g_free(icon_event);
585                                 g_free(set_event);
586                                 return;
587                         }
588                 } else if(item_type == ITEM_PLUGIN)
589                         icon_event = toolbar_ret_descr_from_val(A_CLAWS_PLUGINS);
590                 else
591                         icon_event = toolbar_ret_descr_from_val(A_CLAWS_ACTIONS);
592                 
593                 text = gtk_editable_get_chars(
594                         GTK_EDITABLE(prefs_toolbar->item_text_entry), 0 , -1);
595
596                 /* change the row */
597                 if (text != NULL) {
598                         gtk_list_store_set(store_set, &iter_set,
599                                            SET_ICON, pixbuf,
600                                            SET_FILENAME, prefs_toolbar->item_icon_file,
601                                            SET_TEXT, text,
602                                            SET_EVENT, icon_event,
603                                            SET_ICON_TEXT, NULL,
604                                            SET_ICON_IS_TEXT, FALSE,
605                                            -1);
606                 } else 
607                         alertpanel_error(ERROR_MSG_NO_TEXT);
608                                 
609                 g_free(text);
610                 g_free(set_event);
611                 if((item_type != ITEM_USER_ACTION) && (item_type != ITEM_PLUGIN))
612                         g_free(icon_event);
613         }
614 }
615
616 static void prefs_toolbar_delete(GtkButton *button, ToolbarPage *prefs_toolbar)
617 {
618         GtkTreeView *list_view_set = GTK_TREE_VIEW(prefs_toolbar->list_view_set);
619         GtkTreeModel *store_set = gtk_tree_view_get_model(list_view_set);
620         GtkTreeIter iter_set;
621         GtkTreePath *path;                                                      
622
623         if (!gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store_set), NULL))
624                 return;
625         
626         if (!gtk_tree_selection_get_selected(gtk_tree_view_get_selection
627                                                         (list_view_set),
628                                              NULL,
629                                              &iter_set))
630                 return;                                      
631
632         /* select prev list item, if deleted was first select next */
633         path = gtk_tree_model_get_path(store_set, &iter_set);
634         gtk_tree_path_prev(path);
635         
636         gtk_list_store_remove(GTK_LIST_STORE(store_set), &iter_set);
637
638         gtk_tree_selection_select_path(
639                         gtk_tree_view_get_selection(list_view_set),
640                         path);
641
642         gtk_tree_path_free(path);
643 }
644
645 static void prefs_toolbar_up(GtkButton *button, ToolbarPage *prefs_toolbar)
646 {
647         GtkTreePath *prev, *sel;
648         GtkTreeIter isel;
649         GtkListStore *store = NULL;
650         GtkTreeModel *model = NULL;
651         GtkTreeIter iprev;
652         
653         if (!gtk_tree_selection_get_selected
654                 (gtk_tree_view_get_selection
655                         (GTK_TREE_VIEW(prefs_toolbar->list_view_set)),
656                  &model,        
657                  &isel))
658                 return;
659         store = (GtkListStore *)model;
660
661         sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
662         if (!sel)
663                 return;
664         
665         /* no move if we're at row 0... */
666         prev = gtk_tree_path_copy(sel);
667         if (!gtk_tree_path_prev(prev)) {
668                 gtk_tree_path_free(prev);
669                 gtk_tree_path_free(sel);
670                 return;
671         }
672
673         gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
674                                 &iprev, prev);
675         gtk_tree_path_free(sel);
676         gtk_tree_path_free(prev);
677
678         gtk_list_store_swap(store, &iprev, &isel);
679 }
680
681 static void prefs_toolbar_down(GtkButton *button, ToolbarPage *prefs_toolbar)
682 {
683         GtkListStore *store = NULL;
684         GtkTreeModel *model = NULL;
685         GtkTreeIter next, sel;
686         
687         if (!gtk_tree_selection_get_selected
688                 (gtk_tree_view_get_selection
689                         (GTK_TREE_VIEW(prefs_toolbar->list_view_set)),
690                  &model,
691                  &sel))
692                 return;
693
694         store = (GtkListStore *)model;
695         next = sel;
696         if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next)) 
697                 return;
698
699         gtk_list_store_swap(store, &next, &sel);
700 }
701
702 static void item_type_changed(GtkComboBox *item_type_combo,
703                                 ToolbarPage *prefs_toolbar)
704 {
705         gint active = gtk_combo_box_get_active(item_type_combo);
706
707         switch(active) {
708         case ITEM_FUNCTION:
709                 gtk_widget_show(prefs_toolbar->item_func_combo);
710                 gtk_widget_hide(prefs_toolbar->item_action_combo);
711                 gtk_widget_hide(prefs_toolbar->item_plugin_combo);
712                 gtk_combo_box_set_active(
713                         GTK_COMBO_BOX(prefs_toolbar->item_func_combo), 0);
714                 gtk_button_set_label(GTK_BUTTON(prefs_toolbar->icon_button), "");
715                 gtk_widget_set_sensitive(prefs_toolbar->item_text_entry, TRUE);
716                 gtk_widget_set_sensitive(prefs_toolbar->item_func_combo, TRUE);
717                 gtk_widget_set_sensitive(prefs_toolbar->icon_button, TRUE);
718
719                 func_selection_changed(GTK_COMBO_BOX(prefs_toolbar->item_func_combo),
720                                         prefs_toolbar);
721                 break;
722         case ITEM_USER_ACTION:
723                 gtk_widget_show(prefs_toolbar->item_action_combo);
724                 gtk_widget_hide(prefs_toolbar->item_func_combo);
725                 gtk_widget_hide(prefs_toolbar->item_plugin_combo);
726                 gtk_combo_box_set_active(
727                         GTK_COMBO_BOX(prefs_toolbar->item_action_combo), 0);
728                 gtk_button_set_label(GTK_BUTTON(prefs_toolbar->icon_button), "");
729                 gtk_widget_set_sensitive(prefs_toolbar->item_text_entry, FALSE);
730                 gtk_widget_set_sensitive(prefs_toolbar->item_action_combo, TRUE);
731                 gtk_widget_set_sensitive(prefs_toolbar->icon_button, TRUE);
732                 
733                 action_selection_changed(GTK_COMBO_BOX(prefs_toolbar->item_action_combo),
734                                         prefs_toolbar);         
735                 break;
736         case ITEM_SEPARATOR:
737                 gtk_button_set_label(GTK_BUTTON(prefs_toolbar->icon_button), _("None"));
738                 gtk_button_set_image(GTK_BUTTON(prefs_toolbar->icon_button), NULL);
739                 g_free(prefs_toolbar->item_icon_file);
740                 prefs_toolbar->item_icon_file = NULL;
741                 gtk_combo_box_set_active(
742                         GTK_COMBO_BOX(prefs_toolbar->item_func_combo), -1);
743                 gtk_combo_box_set_active(
744                         GTK_COMBO_BOX(prefs_toolbar->item_action_combo), -1);
745         gtk_combo_box_set_active(
746             GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), -1);
747                 gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->item_text_entry), "");
748                 gtk_widget_set_sensitive(prefs_toolbar->item_action_combo, FALSE);
749                 gtk_widget_set_sensitive(prefs_toolbar->item_text_entry, FALSE);
750                 gtk_widget_set_sensitive(prefs_toolbar->item_plugin_combo, FALSE);
751                 gtk_widget_set_sensitive(prefs_toolbar->item_func_combo, FALSE);
752                 gtk_widget_set_sensitive(prefs_toolbar->icon_button, FALSE);
753                 break;
754           case ITEM_PLUGIN:
755         gtk_widget_show(prefs_toolbar->item_plugin_combo);
756         gtk_widget_hide(prefs_toolbar->item_func_combo);
757         gtk_widget_hide(prefs_toolbar->item_action_combo);
758         gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), 0);
759         gtk_button_set_label(GTK_BUTTON(prefs_toolbar->icon_button), "");
760         gtk_widget_set_sensitive(prefs_toolbar->item_text_entry, TRUE);
761         gtk_widget_set_sensitive(prefs_toolbar->item_plugin_combo, TRUE);
762         gtk_widget_set_sensitive(prefs_toolbar->icon_button, TRUE);
763         plugin_selection_changed(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), prefs_toolbar);
764             break;
765         }
766
767 }
768
769 static void action_selection_changed(GtkComboBox *action_combo,
770                                 ToolbarPage *prefs_toolbar)
771 {
772         gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
773                            prefs_toolbar->item_action_combo));
774
775         if(text != NULL) { /* action */
776                 gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->item_text_entry), text);
777                 g_free(text);
778         } 
779 }
780
781 static void plugin_selection_changed(GtkComboBox *action_combo,
782                 ToolbarPage *prefs_toolbar)
783 {
784         gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo));
785
786     if(text != NULL) { /* action */
787         gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->item_text_entry), text);
788         g_free(text);
789     }
790 }
791
792 static void func_selection_changed(GtkComboBox *action_combo,
793                                 ToolbarPage *prefs_toolbar)
794 {
795         gchar *text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(
796                            prefs_toolbar->item_func_combo));
797
798         if(text != NULL) { /* action */
799                 int action = -1;
800                 action = toolbar_ret_val_from_descr(text);
801                 if (action >= 0)
802                         gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->item_text_entry), 
803                                         toolbar_get_short_text(action));
804                 g_free(text);
805                 if (action >= 0) {
806                         StockPixmap stockp = toolbar_get_icon(action);
807                         if (stockp >= 0)  {
808                                 g_free(prefs_toolbar->item_icon_file);
809                                 prefs_toolbar->item_icon_file = g_strdup(stock_pixmap_get_name(stockp));
810
811                                 gtk_button_set_image(GTK_BUTTON(prefs_toolbar->icon_button),
812                                      stock_pixmap_widget(prefs_toolbar->window, stockp));
813                         }
814                 }
815         } 
816 }
817
818 static void prefs_toolbar_create(ToolbarPage *prefs_toolbar)
819 {
820         GtkWidget *main_vbox;
821         GtkWidget *toolbar_item_hbox;
822         GtkWidget *icon_vbox;
823         GtkWidget *icon_label;
824         GtkWidget *icon_button;
825         GtkWidget *icon_hbox;
826         GtkWidget *item_type_combo;
827         GtkWidget *item_action_combo;
828         GtkWidget *item_plugin_combo;
829         GtkWidget *item_func_combo;
830         GtkWidget *reg_hbox;
831         GtkWidget *arrow;
832         GtkWidget *btn_hbox;
833 #ifdef GENERIC_UMPC
834         GtkWidget *hbox;
835 #endif
836         GtkWidget *reg_btn;
837         GtkWidget *subst_btn;
838         GtkWidget *del_btn;
839         GtkWidget *default_btn;
840         GtkWidget *vbox_frame;
841         GtkWidget *table;
842         GtkWidget *label_icon_text;
843         GtkWidget *item_text_entry;
844         GtkWidget *vbox_toolbar_items;
845         GtkWidget *hbox_bottom;
846         GtkWidget *scrolledwindow_list_view_set;
847         GtkWidget *list_view_set;
848         GtkWidget *label;
849
850         GtkWidget *btn_vbox;
851         GtkWidget *up_btn;
852         GtkWidget *down_btn;
853
854         debug_print("Creating custom toolbar window...\n");
855
856         main_vbox = gtk_vbox_new(FALSE, 0);
857         gtk_widget_show(main_vbox);
858
859         vbox_frame = gtk_frame_new(_("Toolbar item"));
860         gtk_widget_show(vbox_frame);
861         gtk_box_pack_start(GTK_BOX(main_vbox), vbox_frame, FALSE, TRUE, 0);
862
863         toolbar_item_hbox = gtk_hbox_new (FALSE, 4);
864         gtk_widget_show(toolbar_item_hbox);
865         gtk_container_add(GTK_CONTAINER (vbox_frame), toolbar_item_hbox);
866         
867         table = gtk_table_new (3, 3, FALSE);
868         gtk_box_pack_start(GTK_BOX(toolbar_item_hbox), table,
869                            TRUE, TRUE, 0);
870         gtk_container_set_border_width (GTK_CONTAINER (table), 8);
871         gtk_table_set_row_spacings (GTK_TABLE (table), 8);
872         gtk_table_set_col_spacings (GTK_TABLE (table), 8);
873
874         /* toolbar item type */
875         label = gtk_label_new(_("Item type"));
876         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
877         gtk_widget_show(label);
878         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
879                          (GtkAttachOptions) (GTK_FILL),
880                          (GtkAttachOptions) (0), 0, 0); 
881         
882         item_type_combo = combobox_text_new(FALSE, _("Internal Function"),
883                                 _("User Action"), _("Separator"), _("Plugins"), NULL);
884         gtk_widget_set_size_request(item_type_combo, 200, -1);
885         gtk_table_attach(GTK_TABLE(table), item_type_combo, 1, 3, 0, 1,
886                          (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
887                          (GtkAttachOptions) (0), 0, 0);
888
889         /* available actions */
890         label = gtk_label_new(_("Event executed on click"));
891         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
892         gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
893                           (GtkAttachOptions) (GTK_FILL),
894                           (GtkAttachOptions) (0), 0, 0);
895
896         item_action_combo = gtk_combo_box_new_text();
897         gtk_widget_set_size_request(item_action_combo, 200, -1);
898         gtk_table_attach (GTK_TABLE (table), item_action_combo, 1, 3, 1, 2,
899                           (GtkAttachOptions) (GTK_FILL),
900                           (GtkAttachOptions) (0), 0, 0);
901                           
902         /* available internal functions */
903         item_func_combo = gtk_combo_box_new_text();
904         gtk_widget_set_size_request(item_func_combo, 200, -1);
905         gtk_table_attach (GTK_TABLE (table), item_func_combo, 1, 3, 1, 2,
906                           (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
907                           (GtkAttachOptions) (0), 0, 0);
908         
909         /* plugin-registered items */
910         item_plugin_combo = gtk_combo_box_new_text();
911         gtk_widget_set_size_request(item_plugin_combo, 200, -1);
912     gtk_table_attach(GTK_TABLE(table), item_plugin_combo, 1, 3, 1, 2,
913               (GtkAttachOptions) (GTK_FILL),
914               (GtkAttachOptions) (0), 0, 0);
915
916         /* toolbar item description */
917         label_icon_text = gtk_label_new(_("Toolbar text"));
918         gtk_misc_set_alignment(GTK_MISC(label_icon_text), 0, 0.5);
919         gtk_widget_show (label_icon_text);
920         gtk_table_attach (GTK_TABLE (table), label_icon_text, 0, 1, 2, 3,
921                           (GtkAttachOptions) (GTK_FILL),
922                           (GtkAttachOptions) (0), 0, 0);
923
924         item_text_entry = gtk_entry_new();
925         gtk_table_attach (GTK_TABLE (table), item_text_entry, 1, 3, 2, 3,
926                           (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
927                           (GtkAttachOptions) (0), 0, 0);
928
929         icon_vbox = gtk_vbox_new(FALSE, VBOX_BORDER);
930         gtk_widget_show(icon_vbox);
931         
932         icon_label = gtk_label_new(_("Icon"));
933         gtk_widget_set_size_request(icon_label, 100, -1);
934         gtk_box_pack_start(GTK_BOX(icon_vbox), icon_label, FALSE, FALSE, 0);
935         
936         icon_hbox = gtk_hbox_new(FALSE, 0);
937         gtk_widget_show(icon_hbox);
938         
939         label = gtk_label_new("");
940         gtk_box_pack_start(GTK_BOX(icon_hbox), label, TRUE, TRUE, 0);
941         
942         icon_button = gtk_button_new();
943         gtk_widget_show(icon_button);
944         gtk_widget_set_size_request(icon_button, 50, 50);
945         g_signal_connect(G_OBJECT(icon_button), "clicked",
946                          G_CALLBACK(icon_chooser_create), prefs_toolbar);
947         gtk_box_pack_start(GTK_BOX(icon_hbox), icon_button, FALSE, FALSE, 8);
948
949         label = gtk_label_new("");
950         gtk_box_pack_start(GTK_BOX(icon_hbox), label, TRUE, TRUE, 0);   
951         
952         gtk_box_pack_start(GTK_BOX(icon_vbox), icon_hbox, FALSE, FALSE, 0);
953         
954         gtk_box_pack_start(GTK_BOX(toolbar_item_hbox), icon_vbox, FALSE, FALSE, 0);
955                 
956         /* register / substitute / delete */
957         reg_hbox = gtk_hbox_new(FALSE, 4);
958         gtk_box_pack_start(GTK_BOX(main_vbox), reg_hbox, FALSE, FALSE, 0);
959         gtk_container_set_border_width(GTK_CONTAINER(reg_hbox), 10);
960
961         arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
962         gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
963         gtk_widget_set_size_request(arrow, -1, 16);
964
965         btn_hbox = gtk_hbox_new(TRUE, 4);
966         gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
967
968         reg_btn = gtk_button_new_from_stock(GTK_STOCK_ADD);
969         gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
970         g_signal_connect(G_OBJECT(reg_btn), "clicked",
971                          G_CALLBACK(prefs_toolbar_register), 
972                          prefs_toolbar);
973
974         subst_btn = gtkut_get_replace_btn(_("Replace"));
975         gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
976         g_signal_connect(G_OBJECT(subst_btn), "clicked",
977                          G_CALLBACK(prefs_toolbar_substitute),
978                          prefs_toolbar);
979
980         del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
981         gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
982         g_signal_connect(G_OBJECT(del_btn), "clicked",
983                          G_CALLBACK(prefs_toolbar_delete), 
984                           prefs_toolbar);
985
986         default_btn = gtk_button_new_with_label(_(" Use default "));
987 #ifndef GENERIC_UMPC
988         gtk_box_pack_end(GTK_BOX(reg_hbox), default_btn, FALSE, TRUE, 0);
989 #else
990         hbox = gtk_hbox_new(FALSE, 0);
991         gtk_box_pack_start(GTK_BOX(main_vbox), hbox, FALSE, FALSE, 0);
992         gtk_box_pack_start(GTK_BOX(hbox), default_btn, FALSE, FALSE, 0);
993 #endif
994         g_signal_connect(G_OBJECT(default_btn), "clicked",
995                          G_CALLBACK(prefs_toolbar_default), 
996                          prefs_toolbar);
997
998         /* currently active toolbar items */
999         vbox_toolbar_items = gtk_vbox_new(FALSE, VBOX_BORDER);
1000         gtk_box_pack_start(GTK_BOX(main_vbox), vbox_toolbar_items, TRUE, TRUE, 0);
1001         
1002         hbox_bottom = gtk_hbox_new(FALSE, 0);
1003         gtk_container_add(GTK_CONTAINER(vbox_toolbar_items), hbox_bottom);
1004         
1005         scrolledwindow_list_view_set = gtk_scrolled_window_new(NULL, NULL);
1006         gtk_box_pack_start(GTK_BOX(hbox_bottom), scrolledwindow_list_view_set, TRUE, TRUE, 0);
1007         gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow_list_view_set), 1);
1008         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow_list_view_set), 
1009                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1010         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwindow_list_view_set),
1011                                             GTK_SHADOW_IN);
1012
1013         list_view_set = create_set_list_view(prefs_toolbar); 
1014         gtk_widget_show(list_view_set);
1015         gtk_container_add(GTK_CONTAINER(scrolledwindow_list_view_set), list_view_set);
1016         gtk_widget_set_size_request(list_view_set, 225, 120);
1017
1018         btn_vbox = gtk_vbox_new(FALSE, 8);
1019         gtk_widget_show(btn_vbox);
1020         gtk_box_pack_start(GTK_BOX(hbox_bottom), btn_vbox, FALSE, FALSE, 5);
1021
1022         up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
1023         gtk_widget_show(up_btn);
1024         gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 2);
1025
1026         down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
1027         gtk_widget_show(down_btn);
1028         gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
1029
1030         g_signal_connect(G_OBJECT(item_type_combo), "changed",
1031                          G_CALLBACK(item_type_changed), prefs_toolbar);
1032         g_signal_connect(G_OBJECT(item_action_combo), "changed",
1033                          G_CALLBACK(action_selection_changed), prefs_toolbar);
1034     g_signal_connect(G_OBJECT(item_plugin_combo), "changed",
1035              G_CALLBACK(plugin_selection_changed), prefs_toolbar);
1036         g_signal_connect(G_OBJECT(item_func_combo), "changed",
1037                          G_CALLBACK(func_selection_changed), prefs_toolbar);
1038         g_signal_connect(G_OBJECT(up_btn), "clicked",
1039                          G_CALLBACK(prefs_toolbar_up), prefs_toolbar);
1040         g_signal_connect(G_OBJECT(down_btn), "clicked",
1041                          G_CALLBACK(prefs_toolbar_down), prefs_toolbar);
1042         
1043         gtk_widget_show_all(main_vbox);
1044
1045         prefs_toolbar->list_view_set    = list_view_set;
1046         prefs_toolbar->item_text_entry  = item_text_entry;
1047         prefs_toolbar->item_type_combo  = item_type_combo;
1048         prefs_toolbar->item_func_combo  = item_func_combo;
1049         prefs_toolbar->item_action_combo= item_action_combo;
1050         prefs_toolbar->item_plugin_combo= item_plugin_combo;
1051         prefs_toolbar->icon_button      = icon_button;
1052         prefs_toolbar->item_icon_file   = NULL;
1053         
1054         prefs_toolbar->page.widget = main_vbox;
1055 }
1056
1057 ToolbarPage *prefs_toolbar_mainwindow;
1058 ToolbarPage *prefs_toolbar_composewindow;
1059 ToolbarPage *prefs_toolbar_messageview;
1060
1061 void prefs_toolbar_unregister_plugin_item(const gchar *plugin_name, const gchar *item_name)
1062 {
1063   gchar *key;
1064
1065   if(!plugin_items)
1066     return;
1067
1068   key = g_strdup_printf(plugin_name, "/", item_name, NULL);
1069   g_hash_table_remove(plugin_items, key);
1070   g_free(key);
1071 }
1072
1073 void prefs_toolbar_execute_plugin_item(const gchar *id)
1074 {
1075         ToolbarPluginItem *value;
1076         GSList *walk;
1077         gboolean found;
1078
1079         if(!plugin_items) {
1080         debug_print("No plugin registered toolbar items yet\n");
1081         return;
1082         }
1083
1084         value = g_hash_table_lookup(plugin_items, id);
1085         if(!value) {
1086                 debug_print("Could not find plugin toolbar item with id %s\n", id);
1087                 return;
1088         }
1089
1090         /* check if corresponding plugin is currently loaded */
1091         found = FALSE;
1092         for(walk = plugin_get_list(); walk; walk = walk->next) {
1093                 const gchar *plugin_name;
1094                 Plugin *plugin = walk->data;
1095                 plugin_name = plugin_get_name(plugin);
1096                 if(!strcmp(plugin_name, value->plugin)) {
1097                         found = TRUE;
1098                         break;
1099                 }
1100         }
1101         if(!found) {
1102         debug_print("Plugin '%s' is currently not loaded, cannot execute toolbar action\n", value->plugin);
1103         return;
1104         }
1105
1106         value->cb(value->item_name, value->cb_data);
1107 }
1108
1109 static void destroy_plugin_item_hash_value(ToolbarPluginItem *item)
1110 {
1111         g_free(item->plugin);
1112         g_free(item->item_name);
1113         g_free(item);
1114 }
1115
1116 void prefs_toolbar_register_plugin_item(const gchar *plugin_name, const gchar *item_name, ToolbarPluginCallback cb, gpointer cb_data)
1117 {
1118         gchar *key;
1119         ToolbarPluginItem *value;
1120
1121         cm_return_if_fail(plugin_name && item_name);
1122
1123         if(!plugin_items) {
1124                 plugin_items = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)destroy_plugin_item_hash_value);
1125                 if(!plugin_items)
1126                         return;
1127         }
1128
1129         key = g_strconcat(plugin_name, "/", item_name, NULL);
1130         value = g_new0(ToolbarPluginItem, 1);
1131         value->plugin = g_strdup(plugin_name);
1132         value->item_name = g_strdup(item_name);
1133         value->cb = cb;
1134         value->cb_data = cb_data;
1135         g_hash_table_insert(plugin_items, key, value);
1136 }
1137
1138 void prefs_toolbar_init(void)
1139 {
1140         ToolbarPage *page;
1141         static gchar *mainpath[3], *messagepath[3], *composepath[3];
1142
1143         mainpath[0] = _("Toolbars");
1144         mainpath[1] = _("Main Window");
1145         mainpath[2] = NULL;
1146
1147         page = g_new0(ToolbarPage, 1);
1148         page->page.path = mainpath;
1149         page->page.create_widget = prefs_toolbar_create_widget;
1150         page->page.destroy_widget = prefs_toolbar_destroy_widget;
1151         page->page.save_page = prefs_toolbar_save;
1152         page->source = TOOLBAR_MAIN;
1153         page->page.weight = 50.0;
1154         prefs_gtk_register_page((PrefsPage *) page);
1155         prefs_toolbar_mainwindow = page;
1156
1157         messagepath[0] = _("Toolbars");
1158         messagepath[1] = _("Message Window");
1159         messagepath[2] = NULL;
1160
1161         page = g_new0(ToolbarPage, 1);
1162         page->page.path = messagepath;
1163         page->page.create_widget = prefs_toolbar_create_widget;
1164         page->page.destroy_widget = prefs_toolbar_destroy_widget;
1165         page->page.save_page = prefs_toolbar_save;
1166         page->source = TOOLBAR_MSGVIEW;
1167         page->page.weight = 45.0;
1168         prefs_gtk_register_page((PrefsPage *) page);
1169         prefs_toolbar_messageview = page;
1170
1171         composepath[0] = _("Toolbars");
1172         composepath[1] = _("Compose Window");
1173         composepath[2] = NULL;
1174
1175         page = g_new0(ToolbarPage, 1);
1176         page->page.path = composepath;
1177         page->page.create_widget = prefs_toolbar_create_widget;
1178         page->page.destroy_widget = prefs_toolbar_destroy_widget;
1179         page->page.save_page = prefs_toolbar_save;
1180         page->source = TOOLBAR_COMPOSE;
1181         page->page.weight = 40.0;
1182         prefs_gtk_register_page((PrefsPage *) page);
1183         prefs_toolbar_composewindow = page;
1184 }
1185
1186 void prefs_toolbar_done(void)
1187 {
1188         prefs_gtk_unregister_page((PrefsPage *) prefs_toolbar_mainwindow);
1189         g_free(prefs_toolbar_mainwindow->item_icon_file);
1190         g_free(prefs_toolbar_mainwindow);
1191         prefs_gtk_unregister_page((PrefsPage *) prefs_toolbar_composewindow);
1192         g_free(prefs_toolbar_composewindow->item_icon_file);
1193         g_free(prefs_toolbar_composewindow);
1194         prefs_gtk_unregister_page((PrefsPage *) prefs_toolbar_messageview);
1195         g_free(prefs_toolbar_messageview->item_icon_file);
1196         g_free(prefs_toolbar_messageview);
1197 }
1198
1199 static void set_visible_if_not_text(GtkTreeViewColumn *col,
1200                                     GtkCellRenderer   *renderer,
1201                                     GtkTreeModel      *model,
1202                                     GtkTreeIter       *iter,
1203                                     gpointer           user_data)
1204 {
1205         gboolean is_text;
1206         GdkPixbuf *pixbuf;
1207
1208         gtk_tree_model_get(model, iter, SET_ICON_IS_TEXT, &is_text, -1);
1209         if (is_text) {
1210                 g_object_set(renderer, "visible", FALSE, NULL); 
1211         } else {
1212                 pixbuf = NULL;
1213                 gtk_tree_model_get(model, iter, 
1214                                    SET_ICON, &pixbuf,
1215                                    -1);
1216                 /* note getting a pixbuf from a tree model increases
1217                  * its refcount ... */
1218                 g_object_unref(pixbuf);
1219                 
1220                 g_object_set(renderer, "visible", TRUE, NULL);
1221                 g_object_set(renderer, "pixbuf",  pixbuf, NULL);
1222         }
1223 }
1224
1225 static GtkWidget *create_set_list_view(ToolbarPage *prefs_toolbar)
1226 {
1227         GtkTreeView *list_view;
1228         GtkListStore *store;
1229         GtkCellRenderer *renderer;
1230         GtkTreeViewColumn *column;
1231         GtkTreeSelection *selector;
1232
1233         store = gtk_list_store_new(N_SET_COLUMNS, 
1234                                    GDK_TYPE_PIXBUF,
1235                                    G_TYPE_STRING,
1236                                    G_TYPE_STRING,
1237                                    G_TYPE_STRING,
1238                                    G_TYPE_STRING,
1239                                    G_TYPE_BOOLEAN,
1240                                    -1);
1241         list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
1242         g_object_unref(G_OBJECT(store));
1243
1244         column = gtk_tree_view_column_new();
1245         gtk_tree_view_column_set_title(column, _("Icon"));
1246         renderer = gtk_cell_renderer_pixbuf_new();
1247         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1248         gtk_tree_view_set_reorderable(list_view, TRUE);
1249         /* tell pixbuf renderer it is only visible if 
1250          * the icon is not represented by text */
1251         gtk_tree_view_column_set_cell_data_func(column, renderer,
1252                                                 set_visible_if_not_text,
1253                                                 NULL, NULL);
1254         
1255         renderer = gtk_cell_renderer_text_new();
1256         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1257         
1258         /* tell the text renderer it is only visible if the icon
1259          * is represented by an image */
1260         gtk_tree_view_column_set_attributes(column, renderer,
1261                                             "visible", SET_ICON_IS_TEXT,
1262                                             "text", SET_ICON_TEXT,
1263                                             NULL);
1264
1265         gtk_tree_view_append_column(list_view, column);
1266
1267         column = gtk_tree_view_column_new();
1268         gtk_tree_view_column_set_title(column, _("Icon text"));
1269         renderer = gtk_cell_renderer_text_new();
1270         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1271         gtk_tree_view_column_set_attributes(column, renderer,
1272                                             "text", SET_TEXT,
1273                                             NULL);
1274         gtk_tree_view_append_column(list_view, column);
1275
1276         column = gtk_tree_view_column_new();
1277         gtk_tree_view_column_set_title(column, _("Mapped event"));
1278         renderer = gtk_cell_renderer_text_new();
1279         gtk_tree_view_column_pack_start(column, renderer, FALSE);
1280         gtk_tree_view_column_set_attributes(column, renderer,
1281                                             "text", SET_EVENT,
1282                                             NULL);
1283         gtk_tree_view_append_column(list_view, column);
1284
1285         /* various other tree view attributes */
1286         gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1287         
1288         selector = gtk_tree_view_get_selection(list_view);
1289         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1290         gtk_tree_selection_set_select_function
1291                 (selector, (GtkTreeSelectionFunc) set_list_selected,
1292                  prefs_toolbar, NULL);
1293
1294         return GTK_WIDGET(list_view);   
1295
1296 }
1297
1298 static gboolean set_list_selected(GtkTreeSelection *selector,
1299                                   GtkTreeModel *model, 
1300                                   GtkTreePath *path,
1301                                   gboolean currently_selected,
1302                                   ToolbarPage *prefs_toolbar)
1303 {
1304
1305         GtkTreeIter iter;
1306         gchar *icon_text, *icon_file, *descr;
1307         GList *cur;
1308         GSList *cur2;
1309         gint item_num;
1310         GdkPixbuf *pix;
1311         
1312         if (currently_selected || !gtk_tree_model_get_iter(model, &iter, path))
1313                 return TRUE;
1314         
1315         gtk_tree_model_get(model, &iter,
1316                            SET_ICON, &pix,
1317                            SET_TEXT, &icon_text,
1318                            SET_EVENT, &descr,
1319                            SET_FILENAME, &icon_file,
1320                            -1);
1321         
1322         g_free(prefs_toolbar->item_icon_file);
1323         prefs_toolbar->item_icon_file = icon_file;
1324         gtk_button_set_image(GTK_BUTTON(prefs_toolbar->icon_button),
1325                              gtk_image_new_from_pixbuf(pix));
1326         
1327         if (g_utf8_collate(toolbar_ret_descr_from_val(A_SEPARATOR), descr) == 0) {
1328                 gtk_button_set_label(GTK_BUTTON(prefs_toolbar->icon_button),
1329                                     _("None"));
1330                 g_free(prefs_toolbar->item_icon_file);
1331                 prefs_toolbar->item_icon_file = NULL;
1332                 gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_type_combo),
1333                                         ITEM_SEPARATOR);
1334                 g_free(icon_text);
1335                 g_free(descr);
1336
1337                 return TRUE;
1338         }
1339         
1340         gtk_button_set_label(GTK_BUTTON(prefs_toolbar->icon_button), "");
1341         gtk_entry_set_text(GTK_ENTRY(prefs_toolbar->item_text_entry), 
1342                            icon_text);
1343
1344         if (g_utf8_collate(toolbar_ret_descr_from_val(A_CLAWS_ACTIONS), descr) == 0) {
1345                 gtk_combo_box_set_active(GTK_COMBO_BOX(
1346                         prefs_toolbar->item_type_combo), ITEM_USER_ACTION);
1347
1348                 for(cur2 = prefs_common.actions_list, item_num = 0; cur2 != NULL;
1349                     cur2 = cur2->next) {
1350                         gchar *item_string;
1351                         get_action_name((gchar *)cur2->data, &item_string);
1352                         
1353                         if(g_utf8_collate(item_string, icon_text) == 0) {
1354                                 gtk_combo_box_set_active(
1355                                         GTK_COMBO_BOX(prefs_toolbar->item_action_combo),
1356                                         item_num);
1357                                 g_free(item_string);
1358                                 break;
1359                         }
1360                         else {
1361                                 item_num++;
1362                                 g_free(item_string);
1363                         }
1364                 }
1365
1366                 gtk_widget_show(prefs_toolbar->item_action_combo);
1367                 gtk_widget_hide(prefs_toolbar->item_func_combo);
1368                 gtk_widget_hide(prefs_toolbar->item_plugin_combo);
1369                 
1370                 g_free(icon_text);
1371                 g_free(descr);
1372
1373                 return TRUE;
1374         }
1375
1376   if (g_utf8_collate(toolbar_ret_descr_from_val(A_CLAWS_PLUGINS), descr) == 0) {
1377           gint num_items, ii;
1378           gchar *txt;
1379
1380       gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_type_combo), ITEM_PLUGIN);
1381
1382       /* set combo box correctly */
1383       num_items = g_hash_table_size(plugin_items);
1384       for(ii = 0; ii < num_items; ii++) {
1385           gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), ii);
1386           txt = gtk_combo_box_get_active_text(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo));
1387           if(!g_utf8_collate(txt, icon_text)) {
1388                   break;
1389           }
1390       }
1391       if(ii == num_items)
1392           gtk_combo_box_set_active(GTK_COMBO_BOX(prefs_toolbar->item_plugin_combo), -1);
1393
1394       gtk_widget_show(prefs_toolbar->item_plugin_combo);
1395       gtk_widget_hide(prefs_toolbar->item_func_combo);
1396       gtk_widget_hide(prefs_toolbar->item_action_combo);
1397
1398       g_free(descr);
1399       g_free(icon_text);
1400       return TRUE;
1401   }
1402
1403         
1404         /* scan combo list for selected description an set combo item accordingly */
1405         for (cur = prefs_toolbar->combo_action_list, item_num = 0; cur != NULL; 
1406              cur = cur->next) {
1407                 gchar *item_str = (gchar*)cur->data;
1408                 if (g_utf8_collate(item_str, descr) == 0) {
1409                         gtk_combo_box_set_active(
1410                                 GTK_COMBO_BOX(prefs_toolbar->item_func_combo),
1411                                 item_num);
1412                         
1413                         break;
1414                 }
1415                 else
1416                         item_num++;
1417         }
1418
1419         gtk_combo_box_set_active(GTK_COMBO_BOX(
1420                         prefs_toolbar->item_type_combo),ITEM_FUNCTION);
1421         gtk_widget_hide(prefs_toolbar->item_action_combo);
1422         gtk_widget_show(prefs_toolbar->item_func_combo);
1423
1424         g_free(icon_text);
1425         g_free(descr);
1426
1427         return TRUE;
1428 }
1429
1430 static void icon_chooser_ok_clicked(GtkButton *button,
1431                                         ToolbarPage *prefs_toolbar)
1432 {
1433         GtkTreeModel *model;
1434         GtkTreeIter iter;
1435         GList *list;
1436         GdkPixbuf *pix;
1437         gchar *icon_file;
1438         
1439         cm_return_if_fail(prefs_toolbar != NULL);
1440
1441         model = gtk_icon_view_get_model(GTK_ICON_VIEW(prefs_toolbar->icon_chooser_view));
1442         list = gtk_icon_view_get_selected_items(GTK_ICON_VIEW(prefs_toolbar->icon_chooser_view));
1443         if(list == NULL)
1444                 return;
1445         
1446         if(!gtk_tree_model_get_iter(model, &iter, (GtkTreePath *)list->data)) {
1447                 gtk_tree_path_free(list->data);
1448                 g_list_free(list);
1449                 return;
1450         }
1451         
1452         gtk_tree_model_get(model, &iter,
1453                            SET_ICON, &pix,
1454                            SET_FILENAME, &icon_file,
1455                            -1);
1456
1457         g_free(prefs_toolbar->item_icon_file);
1458         prefs_toolbar->item_icon_file = icon_file;
1459         gtk_button_set_image(GTK_BUTTON(prefs_toolbar->icon_button),
1460                              gtk_image_new_from_pixbuf(pix));
1461         
1462         gtk_widget_destroy(prefs_toolbar->icon_chooser_win);
1463         prefs_toolbar->icon_chooser_win = NULL;
1464         prefs_toolbar->icon_chooser_view = NULL;
1465         
1466         gtk_tree_path_free(list->data);
1467         g_list_free(list);
1468 }
1469
1470 static void icon_chooser_cancel_clicked(GtkButton *button,
1471                                         ToolbarPage *prefs_toolbar)
1472 {
1473         cm_return_if_fail(prefs_toolbar != NULL);
1474
1475         gtk_widget_destroy(prefs_toolbar->icon_chooser_win);
1476         prefs_toolbar->icon_chooser_win = NULL;
1477         prefs_toolbar->icon_chooser_view = NULL;
1478 }
1479
1480 static gboolean icon_chooser_key_pressed(GtkWidget *widget, GdkEventKey *event,
1481                         ToolbarPage *prefs_toolbar)
1482 {
1483         if (event && event->keyval == GDK_Escape) {
1484                 icon_chooser_cancel_clicked(NULL, prefs_toolbar);
1485                 return TRUE;
1486         }
1487
1488         return FALSE;
1489 }
1490
1491 static gboolean icon_list_key_pressed(GtkWidget *widget, GdkEventKey *event,
1492                         ToolbarPage *prefs_toolbar)
1493 {
1494         if (event) {
1495                 if (event->keyval == GDK_KP_Enter ||
1496                     event->keyval == GDK_Return ||
1497                     event->keyval == GDK_space) {
1498                         icon_chooser_ok_clicked(NULL, prefs_toolbar);
1499                         return TRUE;
1500                 }
1501         }
1502         return FALSE;
1503 }
1504
1505 static gboolean ok_cb(gpointer data)
1506 {
1507         ToolbarPage *prefs_toolbar = (ToolbarPage *)data;
1508         icon_chooser_ok_clicked(NULL, prefs_toolbar);
1509         return FALSE;
1510 }
1511
1512 static gboolean icon_list_button_release(GtkWidget *widget,
1513                                                GdkEventButton *event,
1514                                                ToolbarPage *prefs_toolbar )
1515 {
1516         static guint id = -1;
1517         if (id >= 0) {
1518                 g_source_remove(id);
1519                 id = -1;
1520         }
1521         id = g_timeout_add(100, ok_cb, prefs_toolbar);
1522         return FALSE;
1523 }
1524
1525 static gboolean icon_window_button_press(GtkWidget *widget,
1526                                                GdkEventButton *event,
1527                                                ToolbarPage *prefs_toolbar )
1528 {
1529         GtkWidget *event_widget, *button;
1530         gboolean restore = TRUE;
1531
1532         button = prefs_toolbar->icon_button;
1533
1534         /* Test where mouse was clicked */
1535         event_widget = gtk_get_event_widget((GdkEvent *)event);
1536         if (event_widget != widget) {
1537                 while (event_widget) {
1538                         if (event_widget == widget)
1539                                 return FALSE;
1540                         else if (event_widget == prefs_toolbar->icon_chooser_win) {
1541                                 restore = FALSE;
1542                                 break;
1543                         }
1544                         event_widget = event_widget->parent;
1545                 }
1546         }
1547
1548         if (restore) {
1549                 icon_chooser_cancel_clicked(NULL, prefs_toolbar);
1550                 return TRUE;
1551         }
1552         return FALSE;
1553 }
1554
1555 static void icon_chooser_activated(GtkTreeView *treeview, GtkTreePath *path,
1556                                 ToolbarPage *prefs_toolbar)
1557 {
1558         icon_chooser_ok_clicked(NULL, prefs_toolbar);
1559 }
1560
1561 static void icon_chooser_create(GtkButton *button, ToolbarPage *prefs_toolbar)
1562 {
1563         GtkWidget *icon_chooser_win;
1564         GtkWidget *scrollwin;
1565         GtkWidget *icon_view;
1566         GtkListStore *store;
1567         GtkTreeIter iter;
1568         gint i, x, y;
1569         
1570         store = gtk_list_store_new(2, 
1571                                    GDK_TYPE_PIXBUF,
1572                                    G_TYPE_STRING,
1573                                    -1);
1574                                    
1575         gtk_list_store_clear(store);
1576
1577         for (i = 0; ToolbarIcons[i] != STOCK_PIXMAP_EMPTY; i++) {
1578                 GdkPixbuf *pixbuf;
1579                 stock_pixbuf_gdk(prefs_toolbar->window, ToolbarIcons[i], &pixbuf);
1580                 
1581                 gtk_list_store_append(store, &iter);
1582                 gtk_list_store_set(store, &iter,
1583                                    SET_ICON, pixbuf,
1584                                    SET_FILENAME, stock_pixmap_get_name((StockPixmap) ToolbarIcons[i]),
1585                                    -1);
1586         }
1587         
1588         icon_chooser_win = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_toolbar");
1589         gtk_window_set_title(GTK_WINDOW(icon_chooser_win), _("Toolbar item icon"));
1590 #ifndef MAEMO
1591         gtk_window_set_decorated(GTK_WINDOW(icon_chooser_win), FALSE);
1592 #endif
1593         gdk_window_get_origin(GTK_WIDGET(prefs_toolbar->icon_button)->window, 
1594                         &x, &y);
1595         x += GTK_WIDGET(prefs_toolbar->icon_button)->allocation.x;
1596         y += GTK_WIDGET(prefs_toolbar->icon_button)->allocation.y;
1597         y += 50;
1598         x -= 300-50;
1599         gtk_window_move(GTK_WINDOW(icon_chooser_win), x, y);
1600         gtk_window_set_resizable(GTK_WINDOW(icon_chooser_win), FALSE);
1601         gtk_widget_set_size_request(icon_chooser_win, 300, 320);
1602         
1603         scrollwin = gtk_scrolled_window_new(NULL, NULL);
1604         gtk_container_add(GTK_CONTAINER(icon_chooser_win), scrollwin);
1605         gtk_widget_show(scrollwin);
1606         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
1607                                 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1608         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrollwin),
1609                                 GTK_SHADOW_OUT);
1610
1611         icon_view = gtk_icon_view_new_with_model(GTK_TREE_MODEL(store));
1612         gtk_icon_view_set_selection_mode(GTK_ICON_VIEW(icon_view), GTK_SELECTION_SINGLE);
1613         gtk_icon_view_set_pixbuf_column(GTK_ICON_VIEW(icon_view), SET_ICON);
1614         gtk_container_add(GTK_CONTAINER(scrollwin), GTK_WIDGET(icon_view));
1615
1616         g_signal_connect(G_OBJECT(icon_chooser_win), "key_press_event",
1617                          G_CALLBACK(icon_chooser_key_pressed), prefs_toolbar);
1618         g_signal_connect(G_OBJECT(icon_view), "item-activated",
1619                          G_CALLBACK(icon_chooser_activated), prefs_toolbar);
1620         g_signal_connect(G_OBJECT(icon_chooser_win),
1621                          "button-press-event",
1622                          G_CALLBACK(icon_window_button_press),
1623                          prefs_toolbar );
1624         g_signal_connect(G_OBJECT(icon_view),
1625                          "button-release-event",
1626                          G_CALLBACK(icon_list_button_release),
1627                          prefs_toolbar );
1628         g_signal_connect(G_OBJECT(icon_view), "key_press_event",
1629                          G_CALLBACK(icon_list_key_pressed), prefs_toolbar);
1630
1631         gtk_widget_show_all(icon_chooser_win);
1632         gtk_widget_grab_focus(GTK_WIDGET(icon_view));
1633         gtk_window_set_modal(GTK_WINDOW(icon_chooser_win), TRUE);
1634         
1635         prefs_toolbar->icon_chooser_win         = icon_chooser_win;
1636         prefs_toolbar->icon_chooser_view        = icon_view;
1637 }