fix substitute pixmap bug
[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), _("select 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), _("enter 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         gtk_window_set_title (GTK_WINDOW (window), _("Customize Toolbar"));
645         //gtk_widget_set_usize (window, 400, 500);
646         gtk_widget_realize (window);
647
648         main_vbox = gtk_vbox_new (FALSE, 0);
649
650         gtk_container_add (GTK_CONTAINER (window), main_vbox);
651         
652         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
653                                 &cancel_btn, _("Cancel"), NULL, NULL);
654         gtk_box_pack_end (GTK_BOX(main_vbox), confirm_area, FALSE, FALSE, 0);
655         gtk_container_set_border_width (GTK_CONTAINER (confirm_area), 5);
656         gtk_widget_grab_default (ok_btn);
657
658         top_hbox = gtk_hbox_new (FALSE, 0);
659         gtk_box_pack_start (GTK_BOX (main_vbox), top_hbox, TRUE, TRUE, 0);
660   
661         compose_frame = gtk_frame_new (_("compose Toolbar Item"));
662         gtk_box_pack_start (GTK_BOX (top_hbox), compose_frame, TRUE, TRUE, 0);
663         gtk_container_set_border_width (GTK_CONTAINER (compose_frame), 5);
664
665         vbox_frame = gtk_vbox_new (FALSE, 0);
666         gtk_container_add (GTK_CONTAINER (compose_frame), vbox_frame);
667         
668         /* available icons */
669         scrolledwindow_clist_icon = gtk_scrolled_window_new (NULL, NULL);
670         gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow_clist_icon), 5);
671         gtk_container_add (GTK_CONTAINER (vbox_frame), scrolledwindow_clist_icon);
672         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_clist_icon), 
673                                         GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
674         
675         clist_icons = gtk_clist_new (2);
676         gtk_container_add (GTK_CONTAINER (scrolledwindow_clist_icon), clist_icons);
677         gtk_container_set_border_width (GTK_CONTAINER (clist_icons), 1);
678         gtk_clist_set_column_width (GTK_CLIST (clist_icons), 0, 35);
679         gtk_clist_set_column_width (GTK_CLIST (clist_icons), 1, 200);
680         gtk_clist_column_titles_hide (GTK_CLIST (clist_icons));
681         gtk_widget_set_usize (clist_icons, 300, 150);
682         
683         /* icon description */
684         hbox_icon_text = gtk_hbox_new (TRUE, 5);
685         gtk_container_add (GTK_CONTAINER (vbox_frame), hbox_icon_text);
686         gtk_container_set_border_width (GTK_CONTAINER (hbox_icon_text), 5);
687         
688         label_icon_text = gtk_label_new ("");
689         gtk_box_pack_start (GTK_BOX (hbox_icon_text), label_icon_text, FALSE, FALSE, 5);
690         
691         entry_icon_text = gtk_entry_new ();
692         gtk_box_pack_start (GTK_BOX (hbox_icon_text), entry_icon_text, FALSE, FALSE, 0);
693
694         /* Sylpheed Action Combo Box */ 
695         combo_syl_action = gtk_combo_new ();
696         gtk_box_pack_start (GTK_BOX (hbox_icon_text), combo_syl_action, TRUE, TRUE, 0);
697
698         combo_syl_list = GTK_COMBO (combo_syl_action)->list;
699         combo_syl_entry = GTK_COMBO (combo_syl_action)->entry;
700         gtk_entry_set_editable (GTK_ENTRY (combo_syl_entry), FALSE);
701
702         /* available actions */
703         hbox_action = gtk_hbox_new (TRUE, 5);
704         gtk_container_add (GTK_CONTAINER (vbox_frame), hbox_action);
705         gtk_container_set_border_width (GTK_CONTAINER (hbox_action), 5);
706         
707         label_action_sel = gtk_label_new (_("select Action executed on click"));
708         gtk_box_pack_start (GTK_BOX (hbox_action), label_action_sel, FALSE, FALSE, 0);
709         gtk_label_set_justify (GTK_LABEL (label_action_sel), GTK_JUSTIFY_RIGHT);
710         
711         combo_action = gtk_combo_new ();
712         gtk_box_pack_start (GTK_BOX (hbox_action), combo_action, TRUE, TRUE, 0);
713         
714         combo_list = GTK_COMBO (combo_action)->list;
715         combo_entry = GTK_COMBO (combo_action)->entry;
716         gtk_entry_set_editable (GTK_ENTRY (combo_entry), FALSE);
717         
718         /* register / substitute / delete */
719         reg_hbox = gtk_hbox_new (FALSE, 4);
720         gtk_box_pack_start (GTK_BOX (main_vbox), reg_hbox, FALSE, FALSE, 0);
721         gtk_container_set_border_width (GTK_CONTAINER (reg_hbox), 10);
722
723         arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
724         gtk_box_pack_start (GTK_BOX (reg_hbox), arrow, FALSE, FALSE, 0);
725         gtk_widget_set_usize (arrow, -1, 16);
726
727         btn_hbox = gtk_hbox_new (TRUE, 4);
728         gtk_box_pack_start (GTK_BOX (reg_hbox), btn_hbox, FALSE, FALSE, 0);
729
730         reg_btn = gtk_button_new_with_label (_("Register"));
731         gtk_box_pack_start (GTK_BOX (btn_hbox), reg_btn, FALSE, TRUE, 0);
732         gtk_signal_connect (GTK_OBJECT (reg_btn), "clicked",
733                             GTK_SIGNAL_FUNC (prefs_toolbar_register), 
734                             NULL);
735
736         subst_btn = gtk_button_new_with_label (_(" Substitute "));
737         gtk_box_pack_start (GTK_BOX (btn_hbox), subst_btn, FALSE, TRUE, 0);
738         gtk_signal_connect (GTK_OBJECT (subst_btn), "clicked",
739                             GTK_SIGNAL_FUNC (prefs_toolbar_substitute),
740                             NULL);
741
742         del_btn = gtk_button_new_with_label (_("Delete"));
743         gtk_box_pack_start (GTK_BOX (btn_hbox), del_btn, FALSE, TRUE, 0);
744         gtk_signal_connect (GTK_OBJECT (del_btn), "clicked",
745                             GTK_SIGNAL_FUNC (prefs_toolbar_delete), 
746                             NULL);
747
748         /* currently active toolbar items */
749         frame_toolbar_items = gtk_frame_new (_("set ToolbarItems"));
750         gtk_box_pack_start (GTK_BOX (main_vbox), frame_toolbar_items, TRUE, TRUE, 0);
751         gtk_container_set_border_width (GTK_CONTAINER (frame_toolbar_items), 5);
752         
753         hbox_bottom = gtk_hbox_new (FALSE, 0);
754         gtk_container_add (GTK_CONTAINER (frame_toolbar_items), hbox_bottom);
755         
756         scrolledwindow_clist_set = gtk_scrolled_window_new (NULL, NULL);
757         gtk_box_pack_start (GTK_BOX (hbox_bottom), scrolledwindow_clist_set, TRUE, TRUE, 0);
758         gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow_clist_set), 5);
759         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_clist_icon), 
760                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
761         
762         clist_set = gtk_clist_new (4);
763         gtk_container_add (GTK_CONTAINER (scrolledwindow_clist_set), clist_set);
764         gtk_clist_set_column_width (GTK_CLIST (clist_set), 0, 80);
765         gtk_clist_set_column_width (GTK_CLIST (clist_set), 1, 80);
766         gtk_clist_set_column_width (GTK_CLIST (clist_set), 2, 80);
767         gtk_clist_set_column_width (GTK_CLIST (clist_set), 3, 80);
768         gtk_clist_column_titles_show (GTK_CLIST (clist_set));
769         gtk_widget_set_usize (clist_set, 300, 200);
770
771         label_icon = gtk_label_new (_("Toolbar Icon"));
772         gtk_clist_set_column_widget (GTK_CLIST (clist_set), 0, label_icon);
773         
774         label_file = gtk_label_new (_("File Name"));
775         gtk_clist_set_column_widget (GTK_CLIST (clist_set), 1, label_file);
776
777         label_text = gtk_label_new (_("Icon Text"));
778         gtk_clist_set_column_widget (GTK_CLIST (clist_set), 2, label_text);
779
780         label_action = gtk_label_new (_("Mapped Action"));
781         gtk_clist_set_column_widget (GTK_CLIST (clist_set), 3, label_action);
782         
783         toolbar = gtk_toolbar_new (GTK_ORIENTATION_VERTICAL, GTK_TOOLBAR_BOTH);
784         gtk_box_pack_start (GTK_BOX (hbox_bottom), toolbar, FALSE, FALSE, 0);
785         gtk_container_set_border_width (GTK_CONTAINER (toolbar), 5);
786
787         icon_wid = stock_pixmap_widget(hbox_bottom, STOCK_PIXMAP_UP_ARROW);
788         up_btn = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar),
789                                              GTK_TOOLBAR_CHILD_BUTTON,
790                                              NULL,
791                                              NULL,
792                                              _("Up"), NULL,
793                                              icon_wid, NULL, NULL);
794
795         icon_wid = stock_pixmap_widget(hbox_bottom, STOCK_PIXMAP_DOWN_ARROW);
796         down_btn = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar),
797                                                GTK_TOOLBAR_CHILD_BUTTON,
798                                                NULL,
799                                                NULL,
800                                                _("Down"), NULL,
801                                                icon_wid, NULL, NULL);
802
803         gtk_signal_connect(GTK_OBJECT (window), "delete_event",
804                            GTK_SIGNAL_FUNC (prefs_toolbar_cancel),
805                            NULL);
806         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
807                            GTK_SIGNAL_FUNC(prefs_toolbar_key_pressed),
808                            NULL);
809         MANAGE_WINDOW_SIGNALS_CONNECT(window);  
810
811         gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
812                            GTK_SIGNAL_FUNC(prefs_toolbar_ok), 
813                            NULL);
814         gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
815                            GTK_SIGNAL_FUNC(prefs_toolbar_cancel), 
816                            NULL);
817         gtk_signal_connect(GTK_OBJECT (clist_set), "select_row",
818                            GTK_SIGNAL_FUNC (prefs_toolbar_select_row_set),
819                            NULL);
820         gtk_signal_connect(GTK_OBJECT (clist_icons), "select_row",
821                            GTK_SIGNAL_FUNC (prefs_toolbar_select_row_icons),
822                            NULL);
823         gtk_signal_connect(GTK_OBJECT (down_btn), "clicked",
824                            GTK_SIGNAL_FUNC (prefs_toolbar_down),
825                            NULL);
826         gtk_signal_connect(GTK_OBJECT (up_btn), "clicked",
827                            GTK_SIGNAL_FUNC (prefs_toolbar_up),
828                            NULL);
829         gtk_signal_connect(GTK_OBJECT(combo_list), "selection-changed",
830                            GTK_SIGNAL_FUNC(prefs_toolbar_selection_changed),
831                            NULL);
832         
833         mtoolbar.window           = window;
834         mtoolbar.clist_icons      = clist_icons;
835         mtoolbar.clist_set        = clist_set;
836         mtoolbar.combo_action     = combo_action;
837         mtoolbar.combo_entry      = combo_entry;
838         mtoolbar.combo_list       = combo_list;
839         mtoolbar.entry_icon_text  = entry_icon_text;
840         mtoolbar.combo_syl_action = combo_syl_action;
841         mtoolbar.combo_syl_list   = combo_syl_list;
842         mtoolbar.combo_syl_entry  = combo_syl_entry;
843
844         mtoolbar.label_icon_text  = label_icon_text;
845
846         gtk_widget_show_all (window);
847 }