custom toolbar: compose win 3
[claws.git] / src / prefs_toolbar.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2002 Hiroyuki Yamamoto & the Sylpheed-Claws team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * General functions for accessing address book files.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include "defs.h"
29
30 #include <glib.h>
31 #include <gtk/gtk.h>
32 #include <gtk/gtkoptionmenu.h>
33 #include <gdk/gdkkeysyms.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36
37 #include "intl.h"
38 #include "stock_pixmap.h"
39 #include "manage_window.h"
40 #include "gtkutils.h"
41 #include "mainwindow.h"
42 #include "alertpanel.h"
43 #include "prefs_common.h"
44
45 #include "utils.h"
46
47 #include "toolbar.h"
48 #include "prefs_toolbar.h"
49
50 typedef enum
51 {
52         COL_ICON        = 0,
53         COL_FILENAME    = 1,
54         COL_TEXT        = 2,
55         COL_EVENT       = 3
56 } DisplayedItemsColumnPos;
57
58 # define N_DISPLAYED_ITEMS_COLS 4
59
60 static struct _Toolbar {
61         GtkWidget *window;
62
63         GtkWidget *clist_icons;
64         GtkWidget *clist_set;
65         GtkWidget *combo_action;
66         GtkWidget *combo_entry;
67         GtkWidget *combo_list;
68         GtkWidget *label_icon_text;
69         GtkWidget *label_action_sel;
70         GtkWidget *entry_icon_text;
71         GtkWidget *combo_syl_action;
72         GtkWidget *combo_syl_list;
73         GtkWidget *combo_syl_entry;
74
75         Toolbar    source;
76         GList     *combo_action_list;
77
78 }toolbar;
79
80 #define CELL_SPACING 24
81 #define ERROR_MSG _("Selected Action already set.\nPlease choose another Action from List")
82
83 static void prefs_toolbar_populate               (void);
84 static gboolean is_duplicate                     (gchar *chosen_action);
85 static void prefs_toolbar_save                   (void);
86
87 static void prefs_toolbar_ok                     (GtkButton       *button,
88                                                   gpointer         data);
89 static void prefs_toolbar_cancel                 (GtkButton       *button,
90                                                   gpointer         data);
91 static void prefs_toolbar_default                (GtkButton       *button, 
92                                                   gpointer         data);
93
94 static void prefs_toolbar_register               (GtkButton       *button,
95                                                   gpointer         data);
96 static void prefs_toolbar_substitute             (GtkButton       *button,
97                                                   gpointer         data);
98 static void prefs_toolbar_delete                 (GtkButton       *button,
99                                                   gpointer         data);
100
101 static void prefs_toolbar_up                     (GtkButton       *button,
102                                                   gpointer         data);
103
104 static void prefs_toolbar_down                   (GtkButton       *button,
105                                                   gpointer         data);
106
107 static void prefs_toolbar_select_row_set         (GtkCList *clist, 
108                                                   gint row, 
109                                                   gint column,
110                                                   GdkEvent *event, 
111                                                   gpointer user_data);
112
113 static void prefs_toolbar_select_row_icons       (GtkCList *clist, 
114                                                   gint row, 
115                                                   gint column,
116                                                   GdkEvent *event, 
117                                                   gpointer user_data);
118
119 static void prefs_toolbar_create                 (void);
120
121 static void prefs_toolbar_selection_changed      (GtkList *list, 
122                                                   gpointer user_data);
123
124 static gint prefs_toolbar_key_pressed            (GtkWidget *widget,
125                                                   GdkEventKey *event,
126                                                   gpointer data);
127
128 void prefs_toolbar(Toolbar source)
129 {
130         gchar *win_titles[2];
131         win_titles[TOOLBAR_MAIN]    = _("set Main toolbar items");
132         win_titles[TOOLBAR_COMPOSE] = _("set Compose toolbar items");  
133
134         toolbar.source = source;
135
136         toolbar_read_config_file(toolbar.source);
137
138         if (!toolbar.window)
139                 prefs_toolbar_create();
140
141         manage_window_set_transient(GTK_WINDOW(toolbar.window));
142         prefs_toolbar_populate();
143         gtk_window_set_title(GTK_WINDOW(toolbar.window), win_titles[toolbar.source]);
144         gtk_widget_show(toolbar.window);
145 }
146
147 void prefs_toolbar_close(void)
148 {
149         gtk_widget_hide(toolbar.window);
150         if (toolbar.source == TOOLBAR_MAIN) 
151                 main_window_reflect_prefs_all_real(TRUE);
152         else if (toolbar.source == TOOLBAR_COMPOSE)
153                 compose_reflect_prefs_pixmap_theme();
154         
155         g_list_free(toolbar.combo_action_list);
156         
157 }
158
159 static void prefs_toolbar_set_displayed(void)
160 {
161         GdkPixmap *xpm;
162         GdkBitmap *xpmmask;
163         gchar *activ[4];
164         GSList *cur;
165         GtkCList *clist_set = GTK_CLIST(toolbar.clist_set);
166         GSList *toolbar_list = toolbar_get_list(toolbar.source);
167
168         gtk_clist_clear(clist_set);
169         gtk_clist_freeze(clist_set);
170
171         /* set currently active toolbar entries */
172         for (cur = toolbar_list; cur != NULL; cur = cur->next) {
173                 ToolbarItem *item = (ToolbarItem*) cur->data;
174         
175                 if (g_strcasecmp(item->file, SEPARATOR) != 0) {
176                         gint row_num;
177                         StockPixmap icon = stock_pixmap_get_icon(item->file);
178                         
179                         stock_pixmap_gdk(toolbar.clist_set, icon,
180                                           &xpm, &xpmmask);
181                         activ[0] = g_strdup("");
182                         activ[1] = g_strdup(item->file);
183                         activ[2] = g_strdup(item->text);
184                         activ[3] = g_strdup(toolbar_ret_descr_from_val(item->index));
185                         row_num  = gtk_clist_append(clist_set, activ);
186                         gtk_clist_set_pixmap(clist_set, 
187                                               row_num, 0, xpm, xpmmask);
188
189                 } else {
190                         activ[0] = g_strdup(SEPARATOR_PIXMAP);
191                         activ[1] = g_strdup(item->file);
192                         activ[2] = g_strdup("");
193                         activ[3] = g_strdup("");
194                         gtk_clist_append(clist_set, activ);
195                 }
196
197                 g_free(activ[0]);
198                 g_free(activ[1]);
199                 g_free(activ[2]);
200                 g_free(activ[3]);
201         }
202
203         gtk_clist_thaw(clist_set);
204         gtk_clist_columns_autosize(clist_set);
205         gtk_clist_set_row_height(clist_set, CELL_SPACING);
206         gtk_clist_select_row(clist_set, 0, 0);
207 }
208
209 static void prefs_toolbar_populate(void)
210 {
211         gint i;
212         GSList *cur;
213         GList *syl_actions = NULL;
214         GtkCList *clist_icons = GTK_CLIST(toolbar.clist_icons);
215         GdkPixmap *xpm;
216         GdkBitmap *xpmmask;
217         gchar *avail[2];
218         gchar *act;
219         
220         gtk_clist_clear(clist_icons);
221         gtk_clist_freeze(clist_icons);
222
223         /* set available icons */
224         avail[0] = g_strdup(SEPARATOR_PIXMAP);
225         avail[1] = g_strdup(SEPARATOR);
226         gtk_clist_append(clist_icons, avail);
227         g_free(avail[0]);
228         g_free(avail[1]);
229
230         toolbar.combo_action_list = toolbar_get_action_items(toolbar.source);
231         gtk_combo_set_popdown_strings(GTK_COMBO(toolbar.combo_action), toolbar.combo_action_list);
232         gtk_combo_set_value_in_list(GTK_COMBO(toolbar.combo_action), 0, FALSE);
233         gtk_entry_set_text(GTK_ENTRY(toolbar.combo_entry), toolbar.combo_action_list->data);
234         //g_list_free(combo_action_list);
235
236         /* get currently defined sylpheed actions */
237         if (prefs_common.actions_list != NULL) {
238
239                 for (cur = prefs_common.actions_list; cur != NULL; cur = cur->next) {
240                         act = (gchar *)cur->data;
241                         syl_actions = g_list_append(syl_actions, act);
242                 } 
243
244                 gtk_combo_set_popdown_strings(GTK_COMBO(toolbar.combo_syl_action), syl_actions);
245                 gtk_combo_set_value_in_list(GTK_COMBO(toolbar.combo_syl_action), 0, FALSE);
246                 gtk_entry_set_text(GTK_ENTRY(toolbar.combo_syl_entry), syl_actions->data);
247                 prefs_toolbar_selection_changed(GTK_LIST(toolbar.combo_syl_list), NULL);
248                 g_list_free(syl_actions);
249         }
250
251         for (i = 0; i < N_STOCK_PIXMAPS; i++) {
252                 avail[0] = g_strdup("");
253                 avail[1] = g_strdup(stock_pixmap_get_name((StockPixmap)i));
254
255                 stock_pixmap_gdk(toolbar.clist_icons, i,
256                                   &xpm, &xpmmask);
257                 gtk_clist_append(clist_icons, avail);
258                 gtk_clist_set_pixmap(clist_icons, 
259                                        i + 1, 0, xpm, xpmmask);
260                 
261                 g_free(avail[0]);
262                 g_free(avail[1]);
263         }
264
265         gtk_clist_thaw(clist_icons);
266         gtk_clist_columns_autosize(clist_icons);
267         gtk_clist_set_row_height(clist_icons, CELL_SPACING);
268         gtk_clist_select_row(clist_icons, 0, 0);
269
270         prefs_toolbar_set_displayed();
271
272         toolbar_clear_list(toolbar.source);
273 }
274
275 static gboolean is_duplicate(gchar *chosen_action)
276 {
277         GtkCList *clist = GTK_CLIST(toolbar.clist_set);
278         gchar *entry;
279         gint row = 0;
280         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
281
282         g_return_val_if_fail(chosen_action != NULL, TRUE);
283         if (clist->rows == 0) 
284                 return FALSE;
285         
286         /* allow duplicate entries (A_SYL_ACTIONS) */
287         if (g_strcasecmp(syl_act, chosen_action) == 0)
288                 return FALSE;
289
290         do {
291                 gtk_clist_get_text(clist, row, 3, &entry);
292                 if ( g_strcasecmp(chosen_action, entry) == 0)
293                         return TRUE;
294                 row++;
295         } while ((gtk_clist_get_text(clist, row, 3, &entry)) && (row <= clist->rows));
296         
297         return FALSE;
298 }
299
300 static void prefs_toolbar_save(void)
301 {
302         gint row = 0;
303         GtkCList *clist = GTK_CLIST(toolbar.clist_set);
304         gchar *entry = NULL;
305         GSList *toolbar_list = NULL;
306         
307         toolbar_clear_list(toolbar.source);
308
309         if (clist->rows == 0) {
310                 toolbar_set_default(toolbar.source);
311         }
312         else {
313                 do {
314                         ToolbarItem *t_item = g_new0(ToolbarItem, 1);
315                         
316                         gtk_clist_get_text(clist, row, 1, &entry);
317                         t_item->file = g_strdup(entry);
318                         
319                         gtk_clist_get_text(clist, row, 2, &entry);
320                         t_item->text = g_strdup(entry);
321                         
322                         gtk_clist_get_text(clist, row, 3, &entry);      
323                         t_item->index = toolbar_ret_val_from_descr(entry);
324                         
325                         /* TODO: save A_SYL_ACTIONS only if they are still active */
326                         toolbar_set_list_item(t_item, toolbar.source);
327
328                         g_free(t_item->file);
329                         g_free(t_item->text);
330                         g_free(t_item);
331                         row++;
332                         
333                 } while(gtk_clist_get_text(clist, row, 3, &entry));
334         }
335
336         toolbar_save_config_file(toolbar.source);
337 }
338
339 static void prefs_toolbar_ok(GtkButton *button, gpointer data)
340 {
341         prefs_toolbar_save();
342         prefs_toolbar_close();
343 }
344
345 static void prefs_toolbar_cancel(GtkButton *button, gpointer data)
346 {
347         prefs_toolbar_close();
348 }
349
350 static void prefs_toolbar_default(GtkButton *button, gpointer data)
351 {
352         toolbar_clear_list(toolbar.source);
353         toolbar_set_default(toolbar.source);
354         prefs_toolbar_set_displayed();
355 }
356
357 static void get_action_name(gchar *entry, gchar **menu)
358 {
359         gchar *act, *act_p;
360
361         if (prefs_common.actions_list != NULL) {
362                 
363                 act = g_strdup(entry);
364                 act_p = strstr(act, ": ");
365                 if (act_p != NULL)
366                         act_p[0] = 0x00;
367                 /* freed by calling func */
368                 *menu = act;
369         }
370 }
371
372 static void prefs_toolbar_register(GtkButton *button, gpointer data)
373 {
374         GtkCList *clist_set   = GTK_CLIST(toolbar.clist_set);
375         GtkCList *clist_icons = GTK_CLIST(toolbar.clist_icons);
376         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
377         gint row_icons = 0;
378         gint row_set = 0;
379         GdkPixmap *xpm;
380         GdkBitmap *xpmmask;
381         gchar *item[4] = {NULL, NULL, NULL, NULL};
382
383         if (clist_icons->rows == 0) return; 
384
385         if (clist_icons->selection) {
386                 if (clist_icons->selection->data) 
387                         row_icons = GPOINTER_TO_INT(clist_icons->selection->data);
388         } else
389                 return;
390
391         gtk_clist_get_text(clist_icons, row_icons, 1, &item[1]);
392         item[3] = g_strdup(gtk_entry_get_text(GTK_ENTRY(toolbar.combo_entry)));
393         
394         /* SEPARATOR or other ? */
395         if (g_strcasecmp(item[1], SEPARATOR) == 0) {
396                 item[0] = g_strdup(SEPARATOR_PIXMAP);
397                 item[2] = g_strdup("");
398                 item[3] = g_strdup("");
399                 
400                 row_set = gtk_clist_append(GTK_CLIST(toolbar.clist_set), item);
401
402                 g_free(item[0]);
403         } else {
404
405                 if (is_duplicate(item[3])) {
406                         alertpanel_error(ERROR_MSG);
407                         g_free(item[3]);
408                         return;
409                 }
410
411                 stock_pixmap_gdk(toolbar.clist_set, stock_pixmap_get_icon(item[1]),
412                                   &xpm, &xpmmask);
413
414                 if (g_strcasecmp(item[3], syl_act) == 0) {
415
416                         gchar *entry = gtk_entry_get_text(GTK_ENTRY(toolbar.combo_syl_entry));
417                         get_action_name(entry, &item[2]);
418                 }
419                 else {
420                         item[2] = g_strdup(gtk_entry_get_text(GTK_ENTRY(toolbar.entry_icon_text)));
421                 }
422
423                 row_set = gtk_clist_append(GTK_CLIST(toolbar.clist_set), item);
424                 gtk_clist_set_pixmap(clist_set, row_set, 0, xpm, xpmmask);
425         }
426
427         gtk_clist_moveto(clist_set, row_set, 0, row_set/clist_set->rows, 0);
428         gtk_clist_select_row(clist_set, row_set, 0);
429
430         g_free(item[2]);
431         g_free(item[3]);
432 }
433
434 static void prefs_toolbar_substitute(GtkButton *button, gpointer data)
435 {
436         GtkCList *clist_set   = GTK_CLIST(toolbar.clist_set);
437         GtkCList *clist_icons = GTK_CLIST(toolbar.clist_icons);
438         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
439         gint row_icons = 0;
440         gint row_set = 0;
441         GdkPixmap *xpm;
442         GdkBitmap *xpmmask;
443         gchar *item[4] = {NULL, NULL, NULL, NULL};
444         gchar *ac_set;
445
446         /* no rows or nothing selected */
447         if ((clist_set->rows == 0) || (clist_set->selection == 0)) return; 
448
449         if (clist_icons->selection) {
450                 if (clist_icons->selection->data) 
451                         row_icons = GPOINTER_TO_INT(clist_icons->selection->data);
452         } else
453                 return;
454         
455         if (clist_set->selection) {
456                 if (clist_set->selection->data) 
457                         row_set = GPOINTER_TO_INT(clist_set->selection->data);
458         } else
459                 return;
460         
461         gtk_clist_get_text(clist_icons, row_icons, 1, &item[1]);
462         gtk_clist_get_text(clist_set, row_set, 3, &ac_set);
463         item[3] = g_strdup(gtk_entry_get_text(GTK_ENTRY(toolbar.combo_entry)));
464
465         if (g_strcasecmp(item[1], SEPARATOR) == 0) {
466                 item[0] = g_strdup(SEPARATOR_PIXMAP);
467                 item[2] = g_strdup("");
468                 item[3] = g_strdup("");
469
470                 gtk_clist_remove(clist_set, row_set);
471                 row_set = gtk_clist_insert(clist_set, row_set, item);
472
473                 g_free(item[0]);
474         } else {
475
476                 if ((is_duplicate(item[3])) && (g_strcasecmp(item[3], ac_set) != 0)){
477                         alertpanel_error(ERROR_MSG);
478                         g_free(item[3]);
479                         return;
480                 }
481
482                 stock_pixmap_gdk(toolbar.clist_set, stock_pixmap_get_icon(item[1]),
483                                   &xpm, &xpmmask);
484
485                 if (g_strcasecmp(item[3], syl_act) == 0) {
486
487                         gchar *entry = gtk_entry_get_text(GTK_ENTRY(toolbar.combo_syl_entry));
488                         get_action_name(entry, &item[2]);
489                 } else {
490                         item[2] = g_strdup(gtk_entry_get_text(GTK_ENTRY(toolbar.entry_icon_text)));
491                 }
492
493                 gtk_clist_remove(clist_set, row_set);
494                 row_set = gtk_clist_insert(clist_set, row_set, item);
495                 gtk_clist_set_pixmap(clist_set, row_set, 0, xpm, xpmmask);
496         }
497         
498         gtk_clist_moveto(clist_set, row_set, 0, row_set/clist_set->rows, 0);
499         gtk_clist_select_row(clist_set, row_set, 0);
500
501         g_free(item[2]);
502         g_free(item[3]);
503 }
504
505 static void prefs_toolbar_delete(GtkButton *button, gpointer data)
506 {
507         GtkCList *clist_set = GTK_CLIST(toolbar.clist_set);
508         gint row_set = 0;
509
510         if (clist_set->rows == 0) return; 
511         if (clist_set->selection) {
512                 if (clist_set->selection->data) 
513                         row_set = GPOINTER_TO_INT(clist_set->selection->data);
514         } else
515                 return;
516         
517         if (clist_set->row_list != NULL) {
518                         
519                 row_set = GPOINTER_TO_INT(clist_set->selection->data);
520                 gtk_clist_remove(clist_set, row_set);
521                 gtk_clist_columns_autosize(clist_set);
522                 
523                 if (clist_set->rows > 0)
524                         gtk_clist_select_row(clist_set,(row_set == 0) ? 0:row_set - 1, 0);
525         }
526 }
527
528 static void prefs_toolbar_up(GtkButton *button, gpointer data)
529 {
530         GtkCList *clist = GTK_CLIST(toolbar.clist_set);
531         gint row = 0;
532
533         if (!clist->selection) return;
534         if (clist->selection->data)
535                 row = GPOINTER_TO_INT(clist->selection->data);
536
537         if (row >= 0) {
538                 gtk_clist_row_move(clist, row, row - 1);
539                 if(gtk_clist_row_is_visible(clist, row - 1) != GTK_VISIBILITY_FULL) {
540                         gtk_clist_moveto(clist, row - 1, 0, 0, 0);
541                 } 
542         }
543 }
544
545 static void prefs_toolbar_down(GtkButton *button, gpointer data)
546 {
547         GtkCList *clist = GTK_CLIST(toolbar.clist_set);
548         gint row = 0;
549
550         if (!clist->selection) return;
551         if (clist->selection->data)
552                 row = GPOINTER_TO_INT(clist->selection->data);
553
554         if (row >= 0 && row < clist->rows - 1) {
555                 gtk_clist_row_move(clist, row, row + 1);
556                 if(gtk_clist_row_is_visible(clist, row + 1) != GTK_VISIBILITY_FULL) {
557                         gtk_clist_moveto(clist, row + 1, 0, 1, 0);
558                 } 
559         }
560 }
561
562 static void prefs_toolbar_select_row_set(GtkCList *clist, gint row, gint column,
563                                          GdkEvent *event, gpointer user_data)
564 {
565         GtkCList *clist_ico = GTK_CLIST(toolbar.clist_icons);
566         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
567         gint row_set = 0;
568         gint row_ico = 0;
569         gint item_num = 0;
570         gchar *file, *icon_text, *descr, *entry;
571         GList *cur;
572
573         if (clist->selection->data) 
574                 row_set = GPOINTER_TO_INT(clist->selection->data);      
575
576         gtk_clist_get_text(clist, row_set, 1, &file);
577         gtk_clist_get_text(clist, row_set, 2, &icon_text);
578         gtk_clist_get_text(clist, row_set, 3, &descr);
579
580         if (g_strcasecmp(descr, syl_act) != 0)
581                 gtk_entry_set_text(GTK_ENTRY(toolbar.entry_icon_text), icon_text);
582         
583         /* scan combo list for selected description an set combo item accordingly */
584         for (cur = toolbar.combo_action_list; cur != NULL; cur = cur->next) {
585                 gchar *item_str = (gchar*)cur->data;
586                 if (g_strcasecmp(item_str, descr) == 0) {
587                         gtk_list_select_item(GTK_LIST(toolbar.combo_list), item_num);
588                         break;
589                 }
590                 else
591                         item_num++;
592         }
593
594         do {
595                 gtk_clist_get_text(clist_ico, row_ico, 1, &entry);
596                 row_ico++;
597         } while(g_strcasecmp(entry, file) != 0);
598         
599         gtk_clist_select_row(clist_ico, row_ico - 1, 0);
600         gtk_clist_moveto(clist_ico, row_ico - 1, 0, row_ico/clist_ico->rows, 0);
601 }
602
603 static void prefs_toolbar_select_row_icons(GtkCList *clist, gint row, gint column,
604                                            GdkEvent *event, gpointer user_data)
605 {
606         GtkCList *clist_icons = GTK_CLIST(toolbar.clist_icons);
607         gchar *text;
608         
609         gtk_clist_get_text(clist_icons, row, 1, &text);
610
611         if (!text) return;
612
613         if (g_strcasecmp(SEPARATOR, text) == 0) {
614                 gtk_widget_set_sensitive(toolbar.combo_action,     FALSE);
615                 gtk_widget_set_sensitive(toolbar.entry_icon_text,  FALSE);
616                 gtk_widget_set_sensitive(toolbar.combo_syl_action, FALSE);
617         } else {
618                 gtk_widget_set_sensitive(toolbar.combo_action,     TRUE);
619                 gtk_widget_set_sensitive(toolbar.entry_icon_text,  TRUE);
620                 gtk_widget_set_sensitive(toolbar.combo_syl_action, TRUE);
621         }
622 }
623
624 static void prefs_toolbar_selection_changed(GtkList *list,
625                                             gpointer user_data)
626 {
627
628         gchar *cur_entry = g_strdup(gtk_entry_get_text(GTK_ENTRY(toolbar.combo_entry)));
629         gchar *actions_entry = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
630
631         gtk_widget_set_sensitive(toolbar.combo_syl_action, TRUE);
632
633         if (g_strcasecmp(cur_entry, actions_entry) == 0) {
634                 gtk_widget_hide(toolbar.entry_icon_text);
635                 gtk_widget_show(toolbar.combo_syl_action);
636                 gtk_label_set_text(GTK_LABEL(toolbar.label_icon_text), _("Sylpheed Action"));
637
638                 if (prefs_common.actions_list == NULL) {
639                     gtk_widget_set_sensitive(toolbar.combo_syl_action, FALSE);
640                 }
641
642         } else {
643                 gtk_widget_hide(toolbar.combo_syl_action);
644                 gtk_widget_show(toolbar.entry_icon_text);
645                 gtk_label_set_text(GTK_LABEL(toolbar.label_icon_text), _("Toolbar text"));
646         }
647
648         gtk_misc_set_alignment(GTK_MISC(toolbar.label_icon_text), 1, 0.5);
649         gtk_widget_show(toolbar.label_icon_text);
650         g_free(cur_entry);
651 }
652
653 static gint prefs_toolbar_key_pressed(GtkWidget *widget,
654                            GdkEventKey *event,
655                            gpointer data)
656 {
657         if (event && event->keyval == GDK_Escape) {
658                 prefs_toolbar_close();
659                 return TRUE;
660         }
661         return FALSE;
662 }
663
664 static void prefs_toolbar_create(void)
665 {
666         GtkWidget *window;
667         GtkWidget *main_vbox;
668         GtkWidget *top_hbox;
669         GtkWidget *compose_frame;
670         GtkWidget *reg_hbox;
671         GtkWidget *arrow;
672         GtkWidget *btn_hbox;
673         GtkWidget *reg_btn;
674         GtkWidget *subst_btn;
675         GtkWidget *del_btn;
676         GtkWidget *vbox_frame;
677         GtkWidget *table;
678         GtkWidget *scrolledwindow_clist_icon;
679         GtkWidget *clist_icons;
680         GtkWidget *label_icon_text;
681         GtkWidget *entry_icon_text;
682         GtkWidget *label_action_sel;
683         GtkWidget *empty_label;
684         GtkWidget *combo_action;
685         GtkWidget *combo_entry;
686         GtkWidget *combo_list;
687         GtkWidget *combo_syl_action;
688         GtkWidget *combo_syl_entry;
689         GtkWidget *combo_syl_list;
690         GtkWidget *frame_toolbar_items;
691         GtkWidget *hbox_bottom;
692         GtkWidget *scrolledwindow_clist_set;
693         GtkWidget *clist_set;
694
695         GtkWidget *btn_vbox;
696         GtkWidget *up_btn;
697         GtkWidget *down_btn;
698         
699         GtkWidget *confirm_area;
700         GtkWidget *ok_btn;
701         GtkWidget *cancel_btn;
702         GtkWidget *default_btn;
703
704         gchar *titles[N_DISPLAYED_ITEMS_COLS];
705  
706         debug_print("Creating custom toolbar window...\n");
707
708         window = gtk_window_new(GTK_WINDOW_DIALOG);
709         gtk_widget_set_usize(window, 450, -1); 
710         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
711         gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
712         
713         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
714         gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE);
715         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
716                            GTK_SIGNAL_FUNC(prefs_toolbar_cancel),
717                            NULL);
718         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
719                            GTK_SIGNAL_FUNC(prefs_toolbar_key_pressed),
720                            NULL);
721         MANAGE_WINDOW_SIGNALS_CONNECT(window);  
722         gtk_widget_realize(window); 
723
724         main_vbox = gtk_vbox_new(FALSE, 0);
725         gtk_widget_show(main_vbox);
726         gtk_container_add(GTK_CONTAINER(window), main_vbox);
727         
728         top_hbox = gtk_hbox_new(FALSE, 0);
729         gtk_box_pack_start(GTK_BOX(main_vbox), top_hbox, TRUE, TRUE, 0);
730   
731         compose_frame = gtk_frame_new(_("Available toolbar items"));
732         gtk_box_pack_start(GTK_BOX(top_hbox), compose_frame, TRUE, TRUE, 0);
733         gtk_container_set_border_width(GTK_CONTAINER(compose_frame), 5);
734
735         vbox_frame = gtk_vbox_new(FALSE, 0);
736         gtk_container_add(GTK_CONTAINER(compose_frame), vbox_frame);
737         
738         /* available icons */
739         scrolledwindow_clist_icon = gtk_scrolled_window_new(NULL, NULL);
740         gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow_clist_icon), 5);
741         gtk_container_add(GTK_CONTAINER(vbox_frame), scrolledwindow_clist_icon);
742         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow_clist_icon), 
743                                         GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
744         
745         clist_icons = gtk_clist_new(2);
746         gtk_container_add(GTK_CONTAINER(scrolledwindow_clist_icon), clist_icons);
747         gtk_container_set_border_width(GTK_CONTAINER(clist_icons), 1);
748         gtk_clist_set_column_width(GTK_CLIST(clist_icons), 0, 35);
749         gtk_clist_set_column_width(GTK_CLIST(clist_icons), 1, 200);
750         gtk_clist_column_titles_hide(GTK_CLIST(clist_icons));
751         gtk_widget_set_usize(clist_icons, 225, 108); 
752
753         table = gtk_table_new (2, 3, FALSE);
754         gtk_container_add (GTK_CONTAINER (vbox_frame), table);
755         gtk_container_set_border_width (GTK_CONTAINER (table), 8);
756         gtk_table_set_row_spacings (GTK_TABLE (table), 8);
757         gtk_table_set_col_spacings (GTK_TABLE (table), 8);
758         
759         /* icon description */
760         label_icon_text = gtk_label_new("");
761         gtk_misc_set_alignment(GTK_MISC(label_icon_text), 0, 0.5);
762         gtk_widget_show (label_icon_text);
763         gtk_table_attach (GTK_TABLE (table), label_icon_text, 0, 1, 0, 1,
764                           (GtkAttachOptions) (GTK_FILL),
765                           (GtkAttachOptions) (0), 0, 0);
766
767         entry_icon_text = gtk_entry_new();
768         gtk_table_attach (GTK_TABLE (table), entry_icon_text, 1, 2, 0, 1,
769                           (GtkAttachOptions) (/*GTK_EXPAND | */GTK_FILL),
770                           (GtkAttachOptions) (0), 0, 0);
771
772         /* Sylpheed Action Combo Box */
773         combo_syl_action = gtk_combo_new();
774         combo_syl_list = GTK_COMBO(combo_syl_action)->list;
775         combo_syl_entry = GTK_COMBO(combo_syl_action)->entry;
776         gtk_entry_set_editable(GTK_ENTRY(combo_syl_entry), FALSE);
777         gtk_table_attach (GTK_TABLE (table), combo_syl_action, 1, 2, 0, 1,
778                           (GtkAttachOptions) (/*GTK_EXPAND | */GTK_FILL),
779                           (GtkAttachOptions) (0), 0, 0);
780
781         empty_label = gtk_label_new("");
782         gtk_table_attach (GTK_TABLE (table), empty_label, 2, 3, 0, 1,
783                           (GtkAttachOptions) (GTK_EXPAND),
784                           (GtkAttachOptions) (0), 0, 0);
785         /* available actions */
786         label_action_sel = gtk_label_new(_("Event executed on click"));
787         gtk_misc_set_alignment(GTK_MISC(label_action_sel), 0, 0.5);
788         gtk_table_attach (GTK_TABLE (table), label_action_sel, 0, 1, 1, 2,
789                           (GtkAttachOptions) (GTK_FILL),
790                           (GtkAttachOptions) (0), 0, 0);
791
792         combo_action = gtk_combo_new();
793         gtk_table_attach (GTK_TABLE (table), combo_action, 1, 2, 1, 2,
794                           (GtkAttachOptions) (GTK_FILL),
795                           (GtkAttachOptions) (0), 0, 0);
796         
797         combo_list = GTK_COMBO(combo_action)->list;
798         combo_entry = GTK_COMBO(combo_action)->entry;
799         gtk_entry_set_editable(GTK_ENTRY(combo_entry), FALSE);
800         
801         empty_label = gtk_label_new("");
802         gtk_table_attach (GTK_TABLE (table), empty_label, 2, 3, 1, 2,
803                           (GtkAttachOptions) (GTK_EXPAND),
804                           (GtkAttachOptions) (0), 0, 0);
805
806         /* register / substitute / delete */
807         reg_hbox = gtk_hbox_new(FALSE, 4);
808         gtk_box_pack_start(GTK_BOX(main_vbox), reg_hbox, FALSE, FALSE, 0);
809         gtk_container_set_border_width(GTK_CONTAINER(reg_hbox), 10);
810
811         arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
812         gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
813         gtk_widget_set_usize(arrow, -1, 16);
814
815         btn_hbox = gtk_hbox_new(TRUE, 4);
816         gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
817
818         reg_btn = gtk_button_new_with_label(_("Register"));
819         gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
820         gtk_signal_connect(GTK_OBJECT(reg_btn), "clicked",
821                             GTK_SIGNAL_FUNC(prefs_toolbar_register), 
822                             NULL);
823
824         subst_btn = gtk_button_new_with_label(_(" Substitute "));
825         gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
826         gtk_signal_connect(GTK_OBJECT(subst_btn), "clicked",
827                             GTK_SIGNAL_FUNC(prefs_toolbar_substitute),
828                             NULL);
829
830         del_btn = gtk_button_new_with_label(_("Delete"));
831         gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
832         gtk_signal_connect(GTK_OBJECT(del_btn), "clicked",
833                             GTK_SIGNAL_FUNC(prefs_toolbar_delete), 
834                             NULL);
835
836         /* currently active toolbar items */
837         frame_toolbar_items = gtk_frame_new(_("Displayed toolbar items"));
838         gtk_box_pack_start(GTK_BOX(main_vbox), frame_toolbar_items, TRUE, TRUE, 0);
839         gtk_container_set_border_width(GTK_CONTAINER(frame_toolbar_items), 5);
840         
841         hbox_bottom = gtk_hbox_new(FALSE, 0);
842         gtk_container_add(GTK_CONTAINER(frame_toolbar_items), hbox_bottom);
843         
844         scrolledwindow_clist_set = gtk_scrolled_window_new(NULL, NULL);
845         gtk_box_pack_start(GTK_BOX(hbox_bottom), scrolledwindow_clist_set, TRUE, TRUE, 0);
846         gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow_clist_set), 1);
847         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow_clist_icon), 
848                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
849
850         titles[COL_ICON]     = _("Icon");
851         titles[COL_FILENAME] = _("File name");
852         titles[COL_TEXT]     = _("Icon text");
853         titles[COL_EVENT]    = _("Mapped event");
854         
855         clist_set = gtk_clist_new_with_titles(N_DISPLAYED_ITEMS_COLS, titles);
856         gtk_widget_show(clist_set);
857         gtk_container_add(GTK_CONTAINER(scrolledwindow_clist_set), clist_set);
858         gtk_clist_set_column_width(GTK_CLIST(clist_set), COL_ICON    , 80);
859         gtk_clist_set_column_width(GTK_CLIST(clist_set), COL_FILENAME, 80);
860         gtk_clist_set_column_width(GTK_CLIST(clist_set), COL_TEXT    , 80);
861         gtk_clist_set_column_width(GTK_CLIST(clist_set), COL_EVENT   , 80);
862         gtk_clist_column_titles_show(GTK_CLIST(clist_set));
863         gtk_widget_set_usize(clist_set, 225, 120);
864
865         btn_vbox = gtk_vbox_new(FALSE, 8);
866         gtk_widget_show(btn_vbox);
867         gtk_box_pack_start(GTK_BOX(hbox_bottom), btn_vbox, FALSE, FALSE, 5);
868
869         up_btn = gtk_button_new_with_label(_("Up"));
870         gtk_widget_show(up_btn);
871         gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 2);
872
873         down_btn = gtk_button_new_with_label(_("Down"));
874         gtk_widget_show(down_btn);
875         gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
876
877         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
878                                 &cancel_btn, _("Cancel"), &default_btn, _("Set default"));
879         gtk_box_pack_end(GTK_BOX(main_vbox), confirm_area, FALSE, FALSE, 0);
880         gtk_container_set_border_width(GTK_CONTAINER(confirm_area), 5);
881         gtk_widget_grab_default(ok_btn);
882
883         gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
884                            GTK_SIGNAL_FUNC(prefs_toolbar_ok), NULL);
885         gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
886                            GTK_SIGNAL_FUNC(prefs_toolbar_cancel), NULL);
887         gtk_signal_connect(GTK_OBJECT(default_btn), "clicked",
888                            GTK_SIGNAL_FUNC(prefs_toolbar_default), NULL);
889         gtk_signal_connect(GTK_OBJECT(clist_set), "select_row",
890                            GTK_SIGNAL_FUNC(prefs_toolbar_select_row_set),
891                            NULL);
892         gtk_signal_connect(GTK_OBJECT(clist_icons), "select_row",
893                            GTK_SIGNAL_FUNC(prefs_toolbar_select_row_icons),
894                            NULL);
895         gtk_signal_connect(GTK_OBJECT(combo_list), "selection-changed",
896                            GTK_SIGNAL_FUNC(prefs_toolbar_selection_changed),
897                            NULL);
898         gtk_signal_connect(GTK_OBJECT(up_btn), "clicked",
899                            GTK_SIGNAL_FUNC(prefs_toolbar_up), NULL);
900         gtk_signal_connect(GTK_OBJECT(down_btn), "clicked",
901                            GTK_SIGNAL_FUNC(prefs_toolbar_down), NULL);
902         
903         toolbar.window           = window;
904         toolbar.clist_icons      = clist_icons;
905         toolbar.clist_set        = clist_set;
906         toolbar.combo_action     = combo_action;
907         toolbar.combo_entry      = combo_entry;
908         toolbar.combo_list       = combo_list;
909         toolbar.entry_icon_text  = entry_icon_text;
910         toolbar.combo_syl_action = combo_syl_action;
911         toolbar.combo_syl_list   = combo_syl_list;
912         toolbar.combo_syl_entry  = combo_syl_entry;
913
914         toolbar.label_icon_text  = label_icon_text;
915         toolbar.label_action_sel = label_action_sel;
916
917         gtk_widget_show_all(window);
918 }