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