aa4785214206f85d3b8dfeaac06ce6fd5405c249
[claws.git] / src / prefs_toolbar.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2001 Hiroyuki Yamamoto
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_PIXMAP      = 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         
302         toolbar_save_config_file ();
303         toolbar_clear_list ();
304         
305         main_window_reflect_prefs_all_real(TRUE);
306 }
307
308 static void prefs_toolbar_ok(void)
309 {
310         prefs_toolbar_save();
311         prefs_toolbar_close();
312 }
313
314 static void prefs_toolbar_cancel(void)
315 {
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 (shown below Pixmap)"));
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         GtkWidget *label_icon;
641         GtkWidget *label_file;
642         GtkWidget *label_text;
643         GtkWidget *label_action;
644         GtkWidget *toolbar;
645         GtkWidget *up_btn;
646         GtkWidget *down_btn;
647         GtkWidget *icon_wid;
648         gchar *titles[N_DISPLAYED_ITEMS_COLS];
649
650         GtkWidget *confirm_area;
651         GtkWidget *ok_btn;
652         GtkWidget *cancel_btn;
653
654         debug_print(_("Creating custom toolbar window...\n"));
655
656         window = gtk_window_new (GTK_WINDOW_DIALOG);
657         gtk_widget_set_usize (window, 450, -1); 
658         gtk_container_set_border_width(GTK_CONTAINER (window), 8);
659         gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
660         gtk_window_set_title (GTK_WINDOW (window), _("Customize toolbar"));
661         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
662         gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE);
663         gtk_signal_connect(GTK_OBJECT (window), "delete_event",
664                            GTK_SIGNAL_FUNC (prefs_toolbar_cancel),
665                            NULL);
666         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
667                            GTK_SIGNAL_FUNC(prefs_toolbar_key_pressed),
668                            NULL);
669         MANAGE_WINDOW_SIGNALS_CONNECT(window);  
670         gtk_widget_realize (window); 
671
672         main_vbox = gtk_vbox_new (FALSE, 0);
673         gtk_widget_show (main_vbox);
674         gtk_container_add (GTK_CONTAINER (window), main_vbox);
675         
676         top_hbox = gtk_hbox_new (FALSE, 0);
677         gtk_box_pack_start (GTK_BOX (main_vbox), top_hbox, TRUE, TRUE, 0);
678   
679         compose_frame = gtk_frame_new (_("Available toolbar items"));
680         gtk_box_pack_start (GTK_BOX (top_hbox), compose_frame, TRUE, TRUE, 0);
681         gtk_container_set_border_width (GTK_CONTAINER (compose_frame), 5);
682
683         vbox_frame = gtk_vbox_new (FALSE, 0);
684         gtk_container_add (GTK_CONTAINER (compose_frame), vbox_frame);
685         
686         /* available icons */
687         scrolledwindow_clist_icon = gtk_scrolled_window_new (NULL, NULL);
688         gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow_clist_icon), 5);
689         gtk_container_add (GTK_CONTAINER (vbox_frame), scrolledwindow_clist_icon);
690         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_clist_icon), 
691                                         GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
692         
693         clist_icons = gtk_clist_new (2);
694         gtk_container_add (GTK_CONTAINER (scrolledwindow_clist_icon), clist_icons);
695         gtk_container_set_border_width (GTK_CONTAINER (clist_icons), 1);
696         gtk_clist_set_column_width (GTK_CLIST (clist_icons), 0, 35);
697         gtk_clist_set_column_width (GTK_CLIST (clist_icons), 1, 200);
698         gtk_clist_column_titles_hide (GTK_CLIST (clist_icons));
699         gtk_widget_set_usize (clist_icons, 225, 108); 
700         
701         /* icon description */
702         hbox_icon_text = gtk_hbox_new (FALSE, 5);
703         gtk_container_add (GTK_CONTAINER (vbox_frame), hbox_icon_text);
704         
705         label_icon_text = gtk_label_new ("");
706         gtk_box_pack_start (GTK_BOX (hbox_icon_text), label_icon_text, FALSE, FALSE, 5);
707         
708         entry_icon_text = gtk_entry_new ();
709         gtk_box_pack_start (GTK_BOX (hbox_icon_text), entry_icon_text, FALSE, FALSE, 0);
710
711         /* Sylpheed Action Combo Box */ 
712         combo_syl_action = gtk_combo_new ();
713         gtk_box_pack_start (GTK_BOX (hbox_icon_text), combo_syl_action, FALSE, FALSE, 0);
714
715         combo_syl_list = GTK_COMBO (combo_syl_action)->list;
716         combo_syl_entry = GTK_COMBO (combo_syl_action)->entry;
717         gtk_entry_set_editable (GTK_ENTRY (combo_syl_entry), FALSE);
718
719         /* available actions */
720         hbox_action = gtk_hbox_new (FALSE, 5);
721         gtk_container_add (GTK_CONTAINER (vbox_frame), hbox_action);
722         gtk_container_set_border_width (GTK_CONTAINER (hbox_action), 5);
723         
724         label_action_sel = gtk_label_new (_("Event executed on click"));
725         gtk_box_pack_start (GTK_BOX (hbox_action), label_action_sel, FALSE, FALSE, 0);
726         
727         combo_action = gtk_combo_new ();
728         gtk_box_pack_start (GTK_BOX (hbox_action), combo_action, FALSE, FALSE, 0);
729         
730         combo_list = GTK_COMBO (combo_action)->list;
731         combo_entry = GTK_COMBO (combo_action)->entry;
732         gtk_entry_set_editable (GTK_ENTRY (combo_entry), FALSE);
733         
734         /* register / substitute / delete */
735         reg_hbox = gtk_hbox_new (FALSE, 4);
736         gtk_box_pack_start (GTK_BOX (main_vbox), reg_hbox, FALSE, FALSE, 0);
737         gtk_container_set_border_width (GTK_CONTAINER (reg_hbox), 10);
738
739         arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
740         gtk_box_pack_start (GTK_BOX (reg_hbox), arrow, FALSE, FALSE, 0);
741         gtk_widget_set_usize (arrow, -1, 16);
742
743         btn_hbox = gtk_hbox_new (TRUE, 4);
744         gtk_box_pack_start (GTK_BOX (reg_hbox), btn_hbox, FALSE, FALSE, 0);
745
746         reg_btn = gtk_button_new_with_label (_("Register"));
747         gtk_box_pack_start (GTK_BOX (btn_hbox), reg_btn, FALSE, TRUE, 0);
748         gtk_signal_connect (GTK_OBJECT (reg_btn), "clicked",
749                             GTK_SIGNAL_FUNC (prefs_toolbar_register), 
750                             NULL);
751
752         subst_btn = gtk_button_new_with_label (_(" Substitute "));
753         gtk_box_pack_start (GTK_BOX (btn_hbox), subst_btn, FALSE, TRUE, 0);
754         gtk_signal_connect (GTK_OBJECT (subst_btn), "clicked",
755                             GTK_SIGNAL_FUNC (prefs_toolbar_substitute),
756                             NULL);
757
758         del_btn = gtk_button_new_with_label (_("Delete"));
759         gtk_box_pack_start (GTK_BOX (btn_hbox), del_btn, FALSE, TRUE, 0);
760         gtk_signal_connect (GTK_OBJECT (del_btn), "clicked",
761                             GTK_SIGNAL_FUNC (prefs_toolbar_delete), 
762                             NULL);
763
764         /* currently active toolbar items */
765         frame_toolbar_items = gtk_frame_new (_("Displayed toolbar items"));
766         gtk_box_pack_start (GTK_BOX (main_vbox), frame_toolbar_items, TRUE, TRUE, 0);
767         gtk_container_set_border_width (GTK_CONTAINER (frame_toolbar_items), 5);
768         
769         hbox_bottom = gtk_hbox_new (FALSE, 0);
770         gtk_container_add (GTK_CONTAINER (frame_toolbar_items), hbox_bottom);
771         
772         scrolledwindow_clist_set = gtk_scrolled_window_new (NULL, NULL);
773         gtk_box_pack_start (GTK_BOX (hbox_bottom), scrolledwindow_clist_set, TRUE, TRUE, 0);
774         gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow_clist_set), 1);
775         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_clist_icon), 
776                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
777
778         titles[COL_PIXMAP]   = _("Pixmap");
779         titles[COL_FILENAME] = _("File name");
780         titles[COL_TEXT]     = _("Pixmap text");
781         titles[COL_EVENT]    = _("Mapped event");
782         
783         clist_set = gtk_clist_new_with_titles (N_DISPLAYED_ITEMS_COLS, titles);
784         gtk_widget_show (clist_set);
785         gtk_container_add (GTK_CONTAINER (scrolledwindow_clist_set), clist_set);
786         gtk_clist_set_column_width (GTK_CLIST(clist_set), COL_PIXMAP  , 80);
787         gtk_clist_set_column_width (GTK_CLIST(clist_set), COL_FILENAME, 80);
788         gtk_clist_set_column_width (GTK_CLIST(clist_set), COL_TEXT    , 80);
789         gtk_clist_set_column_width (GTK_CLIST(clist_set), COL_EVENT   , 80);
790         gtk_clist_column_titles_show (GTK_CLIST (clist_set));
791         gtk_widget_set_usize (clist_set, 225, 120);
792
793         toolbar = gtk_toolbar_new (GTK_ORIENTATION_VERTICAL, GTK_TOOLBAR_BOTH);
794         gtk_box_pack_start (GTK_BOX (hbox_bottom), toolbar, FALSE, FALSE, 0);
795         gtk_container_set_border_width (GTK_CONTAINER (toolbar), 5);
796
797         icon_wid = stock_pixmap_widget(hbox_bottom, STOCK_PIXMAP_UP_ARROW);
798         up_btn = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar),
799                                              GTK_TOOLBAR_CHILD_BUTTON,
800                                              NULL,
801                                              NULL,
802                                              _("Up"), NULL,
803                                              icon_wid, NULL, NULL);
804
805         icon_wid = stock_pixmap_widget(hbox_bottom, STOCK_PIXMAP_DOWN_ARROW);
806         down_btn = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar),
807                                                GTK_TOOLBAR_CHILD_BUTTON,
808                                                NULL,
809                                                NULL,
810                                                _("Down"), NULL,
811                                                icon_wid, NULL, NULL);
812
813         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
814                                 &cancel_btn, _("Cancel"), NULL, NULL);
815         gtk_box_pack_end (GTK_BOX(main_vbox), confirm_area, FALSE, FALSE, 0);
816         gtk_container_set_border_width (GTK_CONTAINER (confirm_area), 5);
817         gtk_widget_grab_default (ok_btn);
818
819         gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
820                            GTK_SIGNAL_FUNC(prefs_toolbar_ok), 
821                            NULL);
822         gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
823                            GTK_SIGNAL_FUNC(prefs_toolbar_cancel), 
824                            NULL);
825         gtk_signal_connect(GTK_OBJECT (clist_set), "select_row",
826                            GTK_SIGNAL_FUNC (prefs_toolbar_select_row_set),
827                            NULL);
828         gtk_signal_connect(GTK_OBJECT (clist_icons), "select_row",
829                            GTK_SIGNAL_FUNC (prefs_toolbar_select_row_icons),
830                            NULL);
831         gtk_signal_connect(GTK_OBJECT (down_btn), "clicked",
832                            GTK_SIGNAL_FUNC (prefs_toolbar_down),
833                            NULL);
834         gtk_signal_connect(GTK_OBJECT (up_btn), "clicked",
835                            GTK_SIGNAL_FUNC (prefs_toolbar_up),
836                            NULL);
837         gtk_signal_connect(GTK_OBJECT(combo_list), "selection-changed",
838                            GTK_SIGNAL_FUNC(prefs_toolbar_selection_changed),
839                            NULL);
840         
841         mtoolbar.window           = window;
842         mtoolbar.clist_icons      = clist_icons;
843         mtoolbar.clist_set        = clist_set;
844         mtoolbar.combo_action     = combo_action;
845         mtoolbar.combo_entry      = combo_entry;
846         mtoolbar.combo_list       = combo_list;
847         mtoolbar.entry_icon_text  = entry_icon_text;
848         mtoolbar.combo_syl_action = combo_syl_action;
849         mtoolbar.combo_syl_list   = combo_syl_list;
850         mtoolbar.combo_syl_entry  = combo_syl_entry;
851
852         mtoolbar.label_icon_text  = label_icon_text;
853
854         gtk_widget_show_all (window);
855 }