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