re-order prefs_toolbar_cancel()
[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 *entry_icon_text;
70         GtkWidget *combo_syl_action;
71         GtkWidget *combo_syl_list;
72         GtkWidget *combo_syl_entry;
73
74 }mtoolbar;
75
76 #define CELL_SPACING 24
77 #define ERROR_MSG _("Selected Action already set.\nPlease choose another Action from List")
78
79 static void prefs_toolbar_open                   (void);
80 static void prefs_toolbar_populate               (void);
81 static gboolean is_duplicate                     (gchar *chosen_action);
82 static void prefs_toolbar_save                   (void);
83 static void prefs_toolbar_ok                     (void);
84 static void prefs_toolbar_cancel                 (void);
85
86 static gint prefs_toolbar_register               (void);
87 static gint prefs_toolbar_substitute             (void);
88 static gint prefs_toolbar_delete                 (void);
89
90 static void prefs_toolbar_up                     (void);
91
92 static void prefs_toolbar_down                   (void);
93
94 static void prefs_toolbar_select_row_set         (GtkCList *clist, 
95                                                   gint row, 
96                                                   gint column,
97                                                   GdkEvent *event, 
98                                                   gpointer user_data);
99
100 static void prefs_toolbar_select_row_icons       (GtkCList *clist, 
101                                                   gint row, 
102                                                   gint column,
103                                                   GdkEvent *event, 
104                                                   gpointer user_data);
105
106 static void prefs_toolbar_create                 (void);
107
108 static void prefs_toolbar_selection_changed      (GtkList *list, 
109                                                   gpointer user_data);
110
111 static gint prefs_toolbar_key_pressed            (GtkWidget *widget,
112                                                   GdkEventKey *event,
113                                                   gpointer data);
114
115 void prefs_toolbar(void)
116 {
117         toolbar_read_config_file();
118         prefs_toolbar_open();
119 }
120
121 static void prefs_toolbar_open(void)
122 {
123         if (!mtoolbar.window)
124                 prefs_toolbar_create();
125
126         manage_window_set_transient(GTK_WINDOW(mtoolbar.window));
127         prefs_toolbar_populate();
128         gtk_widget_show(mtoolbar.window);
129 }
130
131 void prefs_toolbar_close(void)
132 {
133         gtk_widget_hide(mtoolbar.window);
134 }
135
136 static void prefs_toolbar_populate(void)
137 {
138         gint i;
139         GSList *cur;
140         GList *combo_action_items;
141         GList *syl_actions = NULL;
142         GtkCList *clist_icons = GTK_CLIST(mtoolbar.clist_icons);
143         GtkCList *clist_set   = GTK_CLIST(mtoolbar.clist_set);
144         GdkPixmap *xpm;
145         GdkBitmap *xpmmask;
146         gchar *avail[2];
147         gchar *activ[5] = {0};
148         gchar *act;
149         
150         gtk_clist_clear(clist_icons);
151         gtk_clist_clear(clist_set);
152
153         gtk_clist_freeze(clist_icons);
154         gtk_clist_freeze(clist_set);
155
156         /* set available icons */
157         avail[0] = g_strdup(SEPARATOR_PIXMAP);
158         avail[1] = g_strdup(SEPARATOR);
159         gtk_clist_append(clist_icons, avail);
160         g_free(avail[0]);
161         g_free(avail[1]);
162
163         combo_action_items = toolbar_get_action_items();
164         gtk_combo_set_popdown_strings(GTK_COMBO(mtoolbar.combo_action), combo_action_items);
165         gtk_combo_set_value_in_list(GTK_COMBO(mtoolbar.combo_action), 0, FALSE);
166         gtk_entry_set_text(GTK_ENTRY(mtoolbar.combo_entry), combo_action_items->data);
167         g_list_free(combo_action_items);
168
169         /* get currently defined sylpheed actions */
170         if (prefs_common.actions_list != NULL) {
171
172                 for (cur = prefs_common.actions_list; cur != NULL; cur = cur->next) {
173                         act = (gchar *)cur->data;
174                         syl_actions = g_list_append(syl_actions, act);
175                 } 
176
177                 gtk_combo_set_popdown_strings(GTK_COMBO(mtoolbar.combo_syl_action), syl_actions);
178                 gtk_combo_set_value_in_list(GTK_COMBO(mtoolbar.combo_syl_action), 0, FALSE);
179                 gtk_entry_set_text(GTK_ENTRY(mtoolbar.combo_syl_entry), syl_actions->data);
180                 prefs_toolbar_selection_changed(GTK_LIST(mtoolbar.combo_syl_list), NULL);
181                 g_list_free(syl_actions);
182         }
183
184         for (i = 0; i < N_STOCK_PIXMAPS; i++) {
185                 avail[0] = g_strdup("");
186                 avail[1] = g_strdup(stock_pixmap_get_name((StockPixmap)i));
187
188                 stock_pixmap_gdk(mtoolbar.clist_icons, i,
189                                   &xpm, &xpmmask);
190                 gtk_clist_append(clist_icons, avail);
191                 gtk_clist_set_pixmap(clist_icons, 
192                                        i + 1, 0, xpm, xpmmask);
193                 
194                 g_free(avail[0]);
195                 g_free(avail[1]);
196         }
197
198         /* set currently active toolbar entries */
199         for (cur = toolbar_list; cur != NULL; cur = cur->next) {
200                 ToolbarItem *item = (ToolbarItem*) cur->data;
201         
202                 if (g_strcasecmp(item->file, SEPARATOR) != 0) {
203                         gint row_num;
204                         StockPixmap icon = stock_pixmap_get_icon(item->file);
205                         
206                         stock_pixmap_gdk(mtoolbar.clist_set, icon,
207                                           &xpm, &xpmmask);
208                         activ[0] = g_strdup("");
209                         activ[1] = g_strdup(item->file);
210                         activ[2] = g_strdup(item->text);
211                         activ[3] = g_strdup(toolbar_ret_descr_from_val(item->action));
212                         row_num  = gtk_clist_append(clist_set, activ);
213                         gtk_clist_set_pixmap(clist_set, 
214                                               row_num, 0, xpm, xpmmask);
215
216                 } else {
217                         activ[0] = g_strdup(SEPARATOR_PIXMAP);
218                         activ[1] = g_strdup(item->file);
219                         activ[2] = g_strdup("");
220                         activ[3] = g_strdup("");
221                         gtk_clist_append(clist_set, activ);
222                 }
223
224                 g_free(activ[0]);
225                 g_free(activ[1]);
226                 g_free(activ[2]);
227                 g_free(activ[3]);
228         }
229
230         gtk_clist_thaw(clist_icons);
231         gtk_clist_thaw(clist_set);
232
233         gtk_clist_columns_autosize(clist_icons);
234         gtk_clist_columns_autosize(clist_set);
235
236         gtk_clist_set_row_height(clist_icons, CELL_SPACING);
237         gtk_clist_set_row_height(clist_set, CELL_SPACING);
238
239         gtk_clist_select_row(clist_icons, 0, 0);
240         gtk_clist_select_row(clist_set, 0, 0);
241
242         toolbar_clear_list();
243 }
244
245 static gboolean is_duplicate(gchar *chosen_action)
246 {
247         GtkCList *clist = GTK_CLIST(mtoolbar.clist_set);
248         gchar *entry;
249         gint row = 0;
250         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
251
252         g_return_val_if_fail(chosen_action != NULL, TRUE);
253         if (clist->rows == 0) 
254                 return FALSE;
255         
256         /* allow duplicate entries (A_SYL_ACTIONS) */
257         if (g_strcasecmp(syl_act, chosen_action) == 0)
258                 return FALSE;
259
260         do {
261                 gtk_clist_get_text(clist, row, 3, &entry);
262                 if ( g_strcasecmp(chosen_action, entry) == 0)
263                         return TRUE;
264                 row++;
265         } while ((gtk_clist_get_text(clist, row, 3, &entry)) && (row <= clist->rows));
266         
267         return FALSE;
268 }
269
270 static void prefs_toolbar_save(void)
271 {
272         gint row = 0;
273         GtkCList *clist = GTK_CLIST(mtoolbar.clist_set);
274         gchar *entry = NULL;
275         
276         toolbar_clear_list();
277
278         if (clist->rows == 0) {
279                 toolbar_set_default_toolbar();
280         }
281         else {
282                 do {
283                         ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
284                         
285                         gtk_clist_get_text(clist, row, 1, &entry);
286                         toolbar_item->file = g_strdup(entry);
287                         
288                         gtk_clist_get_text(clist, row, 2, &entry);
289                         toolbar_item->text = g_strdup(entry);
290                         
291                         gtk_clist_get_text(clist, row, 3, &entry);      
292                         toolbar_item->action = toolbar_ret_val_from_descr(entry);
293                         
294                         /* TODO: save A_SYL_ACTIONS only if they are still active */
295
296                         toolbar_list = g_slist_append(toolbar_list, toolbar_item);
297                         row++;
298                         
299                 } while(gtk_clist_get_text(clist, row, 3, &entry));
300         }
301         toolbar_save_config_file();
302         toolbar_update();
303         main_window_reflect_prefs_all_real(TRUE);
304 }
305
306 static void prefs_toolbar_ok(void)
307 {
308         prefs_toolbar_save();
309         prefs_toolbar_close();
310 }
311
312 static void prefs_toolbar_cancel(void)
313 {
314         toolbar_update();
315         main_window_reflect_prefs_all_real(TRUE);
316         prefs_toolbar_close();
317 }
318
319 static void get_action_name(gchar *entry, gchar **menu)
320 {
321         gchar *act, *act_p;
322
323         if (prefs_common.actions_list != NULL) {
324                 
325                 act = g_strdup(entry);
326                 act_p = strstr(act, ": ");
327                 if (act_p != NULL)
328                         act_p[0] = 0x00;
329                 /* freed by calling func */
330                 *menu = act;
331         }
332 }
333
334 static gint prefs_toolbar_register(void)
335 {
336         GtkCList *clist_set   = GTK_CLIST(mtoolbar.clist_set);
337         GtkCList *clist_icons = GTK_CLIST(mtoolbar.clist_icons);
338         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
339         gint row_icons = 0;
340         gint row_set = 0;
341         GdkPixmap *xpm;
342         GdkBitmap *xpmmask;
343         gchar *item[4];
344
345         if (clist_icons->rows == 0) return -1; 
346
347         if (clist_icons->selection)
348                 if (clist_icons->selection->data) 
349                         row_icons = GPOINTER_TO_INT(clist_icons->selection->data);
350         
351         gtk_clist_get_text(clist_icons, row_icons, 1, &item[1]);
352         item[3] = g_strdup(gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_entry)));
353         
354         /* SEPARATOR or other ? */
355         if (g_strcasecmp(item[1], SEPARATOR) == 0) {
356                 item[0] = g_strdup(SEPARATOR_PIXMAP);
357                 item[2] = g_strdup("");
358                 item[3] = g_strdup("");
359                 
360                 row_set = gtk_clist_append(GTK_CLIST(mtoolbar.clist_set), item);
361
362                 g_free(item[0]);
363         } else {
364
365                 if (is_duplicate(item[3])) {
366                         alertpanel_error(ERROR_MSG);
367                         g_free(item[3]);
368                         return -1;
369                 }
370
371                 stock_pixmap_gdk(mtoolbar.clist_set, stock_pixmap_get_icon(item[1]),
372                                   &xpm, &xpmmask);
373
374                 if (g_strcasecmp(item[3], syl_act) == 0) {
375
376                         gchar *entry = gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_syl_entry));
377                         get_action_name(entry, &item[2]);
378                 }
379                 else {
380                         item[2] = g_strdup(gtk_entry_get_text(GTK_ENTRY(mtoolbar.entry_icon_text)));
381                 }
382
383                 row_set = gtk_clist_append(GTK_CLIST(mtoolbar.clist_set), item);
384                 gtk_clist_set_pixmap(clist_set, row_set, 0, xpm, xpmmask);
385         }
386
387         gtk_clist_moveto(clist_set, row_set, 0, row_set/clist_set->rows, 0);
388         gtk_clist_select_row(clist_set, row_set, 0);
389
390         g_free(item[2]);
391         g_free(item[3]);
392
393         return 0;
394 }
395
396 static gint prefs_toolbar_substitute(void)
397 {
398         GtkCList *clist_set   = GTK_CLIST(mtoolbar.clist_set);
399         GtkCList *clist_icons = GTK_CLIST(mtoolbar.clist_icons);
400         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
401         gint row_icons = 0;
402         gint row_set = 0;
403         GdkPixmap *xpm;
404         GdkBitmap *xpmmask;
405         gchar *item[4];
406         gchar *ac_set;
407
408         /* no rows or nothing selected */
409         if ((clist_set->rows == 0) || (clist_set->selection == 0)) return -1; 
410
411         if (clist_icons->selection)
412                 if (clist_icons->selection->data) 
413                         row_icons = GPOINTER_TO_INT(clist_icons->selection->data);
414
415         if (clist_set->selection)
416                 if (clist_set->selection->data) 
417                         row_set = GPOINTER_TO_INT(clist_set->selection->data);
418
419         gtk_clist_get_text(clist_icons, row_icons, 1, &item[1]);
420         gtk_clist_get_text(clist_set, row_set, 3, &ac_set);
421         item[3] = g_strdup(gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_entry)));
422
423         if (g_strcasecmp(item[1], SEPARATOR) == 0) {
424                 item[0] = g_strdup(SEPARATOR_PIXMAP);
425                 item[2] = g_strdup("");
426                 item[3] = g_strdup("");
427
428                 gtk_clist_remove(clist_set, row_set);
429                 row_set = gtk_clist_insert(clist_set, row_set, item);
430
431                 g_free(item[0]);
432         } else {
433
434                 if ((is_duplicate(item[3])) && (g_strcasecmp(item[3], ac_set) != 0)){
435                         alertpanel_error(ERROR_MSG);
436                         g_free(item[3]);
437                         return -1;
438                 }
439
440                 stock_pixmap_gdk(mtoolbar.clist_set, stock_pixmap_get_icon(item[1]),
441                                   &xpm, &xpmmask);
442
443                 if (g_strcasecmp(item[3], syl_act) == 0) {
444
445                         gchar *entry = gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_syl_entry));
446                         get_action_name(entry, &item[2]);
447                 } else {
448                         item[2] = g_strdup(gtk_entry_get_text(GTK_ENTRY(mtoolbar.entry_icon_text)));
449                 }
450
451                 gtk_clist_remove(clist_set, row_set);
452                 row_set = gtk_clist_insert(clist_set, row_set, item);
453                 gtk_clist_set_pixmap(clist_set, row_set, 0, xpm, xpmmask);
454         }
455         
456         gtk_clist_moveto(clist_set, row_set, 0, row_set/clist_set->rows, 0);
457         gtk_clist_select_row(clist_set, row_set, 0);
458
459         g_free(item[2]);
460         g_free(item[3]);
461         
462         return 0;
463 }
464
465 static gint prefs_toolbar_delete(void)
466 {
467         GtkCList *clist_set = GTK_CLIST(mtoolbar.clist_set);
468         gint row_set = 0;
469
470         if (clist_set->rows == 0) return -1; 
471         if (clist_set->selection)
472                 if (clist_set->selection->data) 
473                         row_set = GPOINTER_TO_INT(clist_set->selection->data);
474
475         if (clist_set->row_list != NULL) {
476                         
477                 row_set = GPOINTER_TO_INT(clist_set->selection->data);
478                 gtk_clist_remove(clist_set, row_set);
479                 gtk_clist_columns_autosize(clist_set);
480                 
481                 if (clist_set->rows > 0)
482                         gtk_clist_select_row(clist_set,(row_set == 0) ? 0:row_set - 1, 0);
483         }
484
485         return 0;
486 }
487
488 static void prefs_toolbar_up(void)
489 {
490         GtkCList *clist = GTK_CLIST(mtoolbar.clist_set);
491         gint row = 0;
492
493         if (!clist->selection) return;
494         if (clist->selection->data)
495                 row = GPOINTER_TO_INT(clist->selection->data);
496
497         if (row >= 0) {
498                 gtk_clist_row_move(clist, row, row - 1);
499                 if(gtk_clist_row_is_visible(clist, row - 1) != GTK_VISIBILITY_FULL) {
500                         gtk_clist_moveto(clist, row - 1, 0, 0, 0);
501                 } 
502         }
503 }
504
505 static void prefs_toolbar_down(void)
506 {
507         GtkCList *clist = GTK_CLIST(mtoolbar.clist_set);
508         gint row = 0;
509
510         if (!clist->selection) return;
511         if (clist->selection->data)
512                 row = GPOINTER_TO_INT(clist->selection->data);
513
514         if (row >= 0 && row < clist->rows - 1) {
515                 gtk_clist_row_move(clist, row, row + 1);
516                 if(gtk_clist_row_is_visible(clist, row + 1) != GTK_VISIBILITY_FULL) {
517                         gtk_clist_moveto(clist, row + 1, 0, 1, 0);
518                 } 
519         }
520 }
521
522 static void prefs_toolbar_select_row_set(GtkCList *clist, gint row, gint column,
523                                          GdkEvent *event, gpointer user_data)
524 {
525         GtkCList *clist_ico = GTK_CLIST(mtoolbar.clist_icons);
526         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
527         gint row_set = 0;
528         gint row_ico = 0;
529         gchar *file, *icon_text, *descr, *entry;
530
531         if (clist->selection->data) 
532                 row_set = GPOINTER_TO_INT(clist->selection->data);      
533
534         gtk_clist_get_text(clist, row_set, 1, &file);
535         gtk_clist_get_text(clist, row_set, 2, &icon_text);
536         gtk_clist_get_text(clist, row_set, 3, &descr);
537
538         if (g_strcasecmp(descr, syl_act) != 0)
539                 gtk_entry_set_text(GTK_ENTRY(mtoolbar.entry_icon_text), icon_text);
540
541         gtk_list_select_item(GTK_LIST(mtoolbar.combo_list), 
542                               toolbar_ret_val_from_descr(descr));
543         do {
544                 gtk_clist_get_text(clist_ico, row_ico, 1, &entry);
545                 row_ico++;
546         } while(g_strcasecmp(entry, file) != 0);
547         
548         gtk_clist_select_row(clist_ico, row_ico - 1, 0);
549         gtk_clist_moveto(clist_ico, row_ico - 1, 0, row_ico/clist_ico->rows, 0);
550 }
551
552 static void prefs_toolbar_select_row_icons(GtkCList *clist, gint row, gint column,
553                                            GdkEvent *event, gpointer user_data)
554 {
555         GtkCList *clist_icons = GTK_CLIST(mtoolbar.clist_icons);
556         gchar *text;
557         
558         gtk_clist_get_text(clist_icons, row, 1, &text);
559
560         if (!text) 
561                 return;
562
563         if (g_strcasecmp(SEPARATOR, text) == 0) {
564                 gtk_widget_set_sensitive(mtoolbar.combo_action,     FALSE);
565                 gtk_widget_set_sensitive(mtoolbar.entry_icon_text,  FALSE);
566                 gtk_widget_set_sensitive(mtoolbar.combo_syl_action, FALSE);
567         } else {
568                 gtk_widget_set_sensitive(mtoolbar.combo_action,     TRUE);
569                 gtk_widget_set_sensitive(mtoolbar.entry_icon_text,  TRUE);
570                 gtk_widget_set_sensitive(mtoolbar.combo_syl_action, TRUE);
571         }
572 }
573
574 static void prefs_toolbar_selection_changed(GtkList *list,
575                                             gpointer user_data)
576 {
577
578         gchar *cur_entry = g_strdup(gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_entry)));
579         gchar *actions_entry = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
580
581         gtk_widget_set_sensitive(mtoolbar.combo_syl_action, TRUE);
582
583         if (g_strcasecmp(cur_entry, actions_entry) == 0) {
584                 gtk_widget_hide(mtoolbar.entry_icon_text);
585                 gtk_widget_show(mtoolbar.combo_syl_action);
586                 gtk_label_set_text(GTK_LABEL(mtoolbar.label_icon_text), _("Sylpheed Action"));
587
588                 if (prefs_common.actions_list == NULL) {
589                     gtk_widget_set_sensitive(mtoolbar.combo_syl_action, FALSE);
590                 }
591                     
592         } else {
593                 gtk_widget_hide(mtoolbar.combo_syl_action);
594                 gtk_widget_show(mtoolbar.entry_icon_text);
595                 gtk_label_set_text(GTK_LABEL(mtoolbar.label_icon_text), _("Toolbar text"));
596         }
597 }
598
599 static gint prefs_toolbar_key_pressed(GtkWidget *widget,
600                            GdkEventKey *event,
601                            gpointer data)
602 {
603         if (event && event->keyval == GDK_Escape) {
604                 prefs_toolbar_cancel();
605                 return TRUE;
606         }
607         return FALSE;
608 }
609
610 static void prefs_toolbar_create(void)
611 {
612         GtkWidget *window;
613         GtkWidget *main_vbox;
614         GtkWidget *top_hbox;
615         GtkWidget *compose_frame;
616         GtkWidget *reg_hbox;
617         GtkWidget *arrow;
618         GtkWidget *btn_hbox;
619         GtkWidget *reg_btn;
620         GtkWidget *subst_btn;
621         GtkWidget *del_btn;
622         GtkWidget *vbox_frame;
623         GtkWidget *scrolledwindow_clist_icon;
624         GtkWidget *clist_icons;
625         GtkWidget *hbox_icon_text;
626         GtkWidget *label_icon_text;
627         GtkWidget *entry_icon_text;
628         GtkWidget *hbox_action;
629         GtkWidget *label_action_sel;
630         GtkWidget *combo_action;
631         GtkWidget *combo_entry;
632         GtkWidget *combo_list;
633         GtkWidget *combo_syl_action;
634         GtkWidget *combo_syl_entry;
635         GtkWidget *combo_syl_list;
636         GtkWidget *frame_toolbar_items;
637         GtkWidget *hbox_bottom;
638         GtkWidget *scrolledwindow_clist_set;
639         GtkWidget *clist_set;
640
641         GtkWidget *btn_vbox;
642         GtkWidget *up_btn;
643         GtkWidget *down_btn;
644
645         GtkWidget *confirm_area;
646         GtkWidget *ok_btn;
647         GtkWidget *cancel_btn;
648
649         gchar *titles[N_DISPLAYED_ITEMS_COLS];
650
651         debug_print("Creating custom toolbar window...\n");
652
653         window = gtk_window_new(GTK_WINDOW_DIALOG);
654         gtk_widget_set_usize(window, 450, -1); 
655         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
656         gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
657         gtk_window_set_title(GTK_WINDOW(window), _("Customize toolbar"));
658         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
659         gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE);
660         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
661                            GTK_SIGNAL_FUNC(prefs_toolbar_cancel),
662                            NULL);
663         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
664                            GTK_SIGNAL_FUNC(prefs_toolbar_key_pressed),
665                            NULL);
666         MANAGE_WINDOW_SIGNALS_CONNECT(window);  
667         gtk_widget_realize(window); 
668
669         main_vbox = gtk_vbox_new(FALSE, 0);
670         gtk_widget_show(main_vbox);
671         gtk_container_add(GTK_CONTAINER(window), main_vbox);
672         
673         top_hbox = gtk_hbox_new(FALSE, 0);
674         gtk_box_pack_start(GTK_BOX(main_vbox), top_hbox, TRUE, TRUE, 0);
675   
676         compose_frame = gtk_frame_new(_("Available toolbar items"));
677         gtk_box_pack_start(GTK_BOX(top_hbox), compose_frame, TRUE, TRUE, 0);
678         gtk_container_set_border_width(GTK_CONTAINER(compose_frame), 5);
679
680         vbox_frame = gtk_vbox_new(FALSE, 0);
681         gtk_container_add(GTK_CONTAINER(compose_frame), vbox_frame);
682         
683         /* available icons */
684         scrolledwindow_clist_icon = gtk_scrolled_window_new(NULL, NULL);
685         gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow_clist_icon), 5);
686         gtk_container_add(GTK_CONTAINER(vbox_frame), scrolledwindow_clist_icon);
687         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow_clist_icon), 
688                                         GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
689         
690         clist_icons = gtk_clist_new(2);
691         gtk_container_add(GTK_CONTAINER(scrolledwindow_clist_icon), clist_icons);
692         gtk_container_set_border_width(GTK_CONTAINER(clist_icons), 1);
693         gtk_clist_set_column_width(GTK_CLIST(clist_icons), 0, 35);
694         gtk_clist_set_column_width(GTK_CLIST(clist_icons), 1, 200);
695         gtk_clist_column_titles_hide(GTK_CLIST(clist_icons));
696         gtk_widget_set_usize(clist_icons, 225, 108); 
697         
698         /* icon description */
699         hbox_icon_text = gtk_hbox_new(FALSE, 5);
700         gtk_container_add(GTK_CONTAINER(vbox_frame), hbox_icon_text);
701         
702         label_icon_text = gtk_label_new("");
703         gtk_box_pack_start(GTK_BOX(hbox_icon_text), label_icon_text, FALSE, FALSE, 5);
704         
705         entry_icon_text = gtk_entry_new();
706         gtk_box_pack_start(GTK_BOX(hbox_icon_text), entry_icon_text, FALSE, FALSE, 0);
707
708         /* Sylpheed Action Combo Box */ 
709         combo_syl_action = gtk_combo_new();
710         gtk_box_pack_start(GTK_BOX(hbox_icon_text), combo_syl_action, FALSE, FALSE, 0);
711
712         combo_syl_list = GTK_COMBO(combo_syl_action)->list;
713         combo_syl_entry = GTK_COMBO(combo_syl_action)->entry;
714         gtk_entry_set_editable(GTK_ENTRY(combo_syl_entry), FALSE);
715
716         /* available actions */
717         hbox_action = gtk_hbox_new(FALSE, 5);
718         gtk_container_add(GTK_CONTAINER(vbox_frame), hbox_action);
719         gtk_container_set_border_width(GTK_CONTAINER(hbox_action), 5);
720         
721         label_action_sel = gtk_label_new(_("Event executed on click"));
722         gtk_box_pack_start(GTK_BOX(hbox_action), label_action_sel, FALSE, FALSE, 0);
723         
724         combo_action = gtk_combo_new();
725         gtk_box_pack_start(GTK_BOX(hbox_action), combo_action, FALSE, FALSE, 0);
726         
727         combo_list = GTK_COMBO(combo_action)->list;
728         combo_entry = GTK_COMBO(combo_action)->entry;
729         gtk_entry_set_editable(GTK_ENTRY(combo_entry), FALSE);
730         
731         /* register / substitute / delete */
732         reg_hbox = gtk_hbox_new(FALSE, 4);
733         gtk_box_pack_start(GTK_BOX(main_vbox), reg_hbox, FALSE, FALSE, 0);
734         gtk_container_set_border_width(GTK_CONTAINER(reg_hbox), 10);
735
736         arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
737         gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
738         gtk_widget_set_usize(arrow, -1, 16);
739
740         btn_hbox = gtk_hbox_new(TRUE, 4);
741         gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
742
743         reg_btn = gtk_button_new_with_label(_("Register"));
744         gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
745         gtk_signal_connect(GTK_OBJECT(reg_btn), "clicked",
746                             GTK_SIGNAL_FUNC(prefs_toolbar_register), 
747                             NULL);
748
749         subst_btn = gtk_button_new_with_label(_(" Substitute "));
750         gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
751         gtk_signal_connect(GTK_OBJECT(subst_btn), "clicked",
752                             GTK_SIGNAL_FUNC(prefs_toolbar_substitute),
753                             NULL);
754
755         del_btn = gtk_button_new_with_label(_("Delete"));
756         gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
757         gtk_signal_connect(GTK_OBJECT(del_btn), "clicked",
758                             GTK_SIGNAL_FUNC(prefs_toolbar_delete), 
759                             NULL);
760
761         /* currently active toolbar items */
762         frame_toolbar_items = gtk_frame_new(_("Displayed toolbar items"));
763         gtk_box_pack_start(GTK_BOX(main_vbox), frame_toolbar_items, TRUE, TRUE, 0);
764         gtk_container_set_border_width(GTK_CONTAINER(frame_toolbar_items), 5);
765         
766         hbox_bottom = gtk_hbox_new(FALSE, 0);
767         gtk_container_add(GTK_CONTAINER(frame_toolbar_items), hbox_bottom);
768         
769         scrolledwindow_clist_set = gtk_scrolled_window_new(NULL, NULL);
770         gtk_box_pack_start(GTK_BOX(hbox_bottom), scrolledwindow_clist_set, TRUE, TRUE, 0);
771         gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow_clist_set), 1);
772         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow_clist_icon), 
773                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
774
775         titles[COL_ICON]     = _("Icon");
776         titles[COL_FILENAME] = _("File name");
777         titles[COL_TEXT]     = _("Icon text");
778         titles[COL_EVENT]    = _("Mapped event");
779         
780         clist_set = gtk_clist_new_with_titles(N_DISPLAYED_ITEMS_COLS, titles);
781         gtk_widget_show(clist_set);
782         gtk_container_add(GTK_CONTAINER(scrolledwindow_clist_set), clist_set);
783         gtk_clist_set_column_width(GTK_CLIST(clist_set), COL_ICON    , 80);
784         gtk_clist_set_column_width(GTK_CLIST(clist_set), COL_FILENAME, 80);
785         gtk_clist_set_column_width(GTK_CLIST(clist_set), COL_TEXT    , 80);
786         gtk_clist_set_column_width(GTK_CLIST(clist_set), COL_EVENT   , 80);
787         gtk_clist_column_titles_show(GTK_CLIST(clist_set));
788         gtk_widget_set_usize(clist_set, 225, 120);
789
790         btn_vbox = gtk_vbox_new(FALSE, 8);
791         gtk_widget_show(btn_vbox);
792         gtk_box_pack_start(GTK_BOX(hbox_bottom), btn_vbox, FALSE, FALSE, 5);
793
794         up_btn = gtk_button_new_with_label(_("Up"));
795         gtk_widget_show(up_btn);
796         gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 2);
797
798         down_btn = gtk_button_new_with_label(_("Down"));
799         gtk_widget_show(down_btn);
800         gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
801
802         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
803                                 &cancel_btn, _("Cancel"), NULL, NULL);
804         gtk_box_pack_end(GTK_BOX(main_vbox), confirm_area, FALSE, FALSE, 0);
805         gtk_container_set_border_width(GTK_CONTAINER(confirm_area), 5);
806         gtk_widget_grab_default(ok_btn);
807
808         gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
809                            GTK_SIGNAL_FUNC(prefs_toolbar_ok), NULL);
810         gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
811                            GTK_SIGNAL_FUNC(prefs_toolbar_cancel), NULL);
812         gtk_signal_connect(GTK_OBJECT(clist_set), "select_row",
813                            GTK_SIGNAL_FUNC(prefs_toolbar_select_row_set),
814                            NULL);
815         gtk_signal_connect(GTK_OBJECT(clist_icons), "select_row",
816                            GTK_SIGNAL_FUNC(prefs_toolbar_select_row_icons),
817                            NULL);
818         gtk_signal_connect(GTK_OBJECT(combo_list), "selection-changed",
819                            GTK_SIGNAL_FUNC(prefs_toolbar_selection_changed),
820                            NULL);
821         gtk_signal_connect(GTK_OBJECT(up_btn), "clicked",
822                            GTK_SIGNAL_FUNC(prefs_toolbar_up), NULL);
823         gtk_signal_connect(GTK_OBJECT(down_btn), "clicked",
824                            GTK_SIGNAL_FUNC(prefs_toolbar_down), NULL);
825         
826         mtoolbar.window           = window;
827         mtoolbar.clist_icons      = clist_icons;
828         mtoolbar.clist_set        = clist_set;
829         mtoolbar.combo_action     = combo_action;
830         mtoolbar.combo_entry      = combo_entry;
831         mtoolbar.combo_list       = combo_list;
832         mtoolbar.entry_icon_text  = entry_icon_text;
833         mtoolbar.combo_syl_action = combo_syl_action;
834         mtoolbar.combo_syl_list   = combo_syl_list;
835         mtoolbar.combo_syl_entry  = combo_syl_entry;
836
837         mtoolbar.label_icon_text  = label_icon_text;
838
839         gtk_widget_show_all(window);
840 }