1005806812fb5f0f4fabcc5d87b8f169ed0ebf5f
[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];
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[5];
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         } else {
353
354                 if (is_duplicate (item[3])) {
355                         alertpanel_error(ERROR_MSG);
356                         g_free (item[3]);
357                         return -1;
358                 }
359
360                 stock_pixmap_gdk (mtoolbar.clist_set, stock_pixmap_get_icon (item[1]),
361                                   &xpm, &xpmmask);
362
363                 if (g_strcasecmp (item[3], syl_act) == 0) {
364
365                         gchar *entry = gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_syl_entry));
366                         get_action_name(entry, &item[2]);
367                 }
368                 else {
369                         item[2] = g_strdup (gtk_entry_get_text (GTK_ENTRY (mtoolbar.entry_icon_text)));
370                 }
371
372                 row_set = gtk_clist_append (GTK_CLIST (mtoolbar.clist_set), item);
373                 gtk_clist_set_pixmap (clist_set, row_set, 0, xpm, xpmmask);
374         }
375
376         gtk_clist_moveto(clist_set, row_set, 0, row_set/clist_set->rows, 0);
377         gtk_clist_select_row (clist_set, row_set, 0);
378
379         g_free (item[0]);
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[5];
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         } else {
421
422                 if ((is_duplicate(item[3])) && (g_strcasecmp(item[3], ac_set) != 0)){
423                         alertpanel_error(ERROR_MSG);
424                         g_free (item[3]);
425                         return -1;
426                 }
427
428                 stock_pixmap_gdk (mtoolbar.clist_set, stock_pixmap_get_icon (item[1]),
429                                   &xpm, &xpmmask);
430
431                 if (g_strcasecmp (item[3], syl_act) == 0) {
432
433                         gchar *entry = gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_syl_entry));
434                         get_action_name(entry, &item[2]);
435                 } else {
436                         item[2] = g_strdup (gtk_entry_get_text (GTK_ENTRY (mtoolbar.entry_icon_text)));
437                 }
438
439                 gtk_clist_remove (clist_set, row_set);
440                 row_set = gtk_clist_insert (clist_set, row_set, item);
441                 gtk_clist_set_pixmap (clist_set, row_set, 0, xpm, xpmmask);
442         }
443         
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[0]);
450         g_free (item[2]);
451         g_free (item[3]);
452         
453         return 0;
454 }
455
456 static gint prefs_toolbar_delete(void)
457 {
458         GtkCList *clist_set   = GTK_CLIST(mtoolbar.clist_set);
459         gint row_set = 0;
460
461         if (clist_set->rows == 0) return -1; 
462         if (clist_set->selection)
463                 if (clist_set->selection->data) 
464                         row_set = GPOINTER_TO_INT(clist_set->selection->data);
465
466         if (clist_set->row_list != NULL) {
467                         
468                 row_set = GPOINTER_TO_INT(clist_set->selection->data);
469                 gtk_clist_remove (clist_set, row_set);
470                 gtk_clist_columns_autosize (clist_set);
471                 
472                 if (clist_set->rows > 0)
473                         gtk_clist_select_row (clist_set, (row_set == 0) ? 0:row_set - 1, 0);
474         }
475
476         return 0;
477 }
478
479 static void prefs_toolbar_up(void)
480 {
481         GtkCList *clist = GTK_CLIST(mtoolbar.clist_set);
482         gint row = 0;
483
484         if (!clist->selection) return;
485         if (clist->selection->data)
486                 row = GPOINTER_TO_INT(clist->selection->data);
487
488         if (row >= 0) {
489                 gtk_clist_row_move(clist, row, row - 1);
490                 if(gtk_clist_row_is_visible(clist, row - 1) != GTK_VISIBILITY_FULL) {
491                         gtk_clist_moveto(clist, row - 1, 0, 0, 0);
492                 } 
493         }
494 }
495
496 static void prefs_toolbar_down(void)
497 {
498         GtkCList *clist = GTK_CLIST(mtoolbar.clist_set);
499         gint row = 0;
500
501         if (!clist->selection) return;
502         if (clist->selection->data)
503                 row = GPOINTER_TO_INT(clist->selection->data);
504
505         if (row >= 0 && row < clist->rows - 1) {
506                 gtk_clist_row_move(clist, row, row + 1);
507                 if(gtk_clist_row_is_visible(clist, row + 1) != GTK_VISIBILITY_FULL) {
508                         gtk_clist_moveto(clist, row + 1, 0, 1, 0);
509                 } 
510         }
511 }
512
513 static void prefs_toolbar_select_row_set(GtkCList *clist, gint row, gint column,
514                                          GdkEvent *event, gpointer user_data)
515 {
516         GtkCList *clist_ico = GTK_CLIST (mtoolbar.clist_icons);
517         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
518         gint row_set = 0;
519         gint row_ico = 0;
520         gchar *file, *icon_text, *descr, *entry;
521
522         if (clist->selection->data) 
523                 row_set = GPOINTER_TO_INT(clist->selection->data);      
524
525         gtk_clist_get_text (clist, row_set, 1, &file);
526         gtk_clist_get_text (clist, row_set, 2, &icon_text);
527         gtk_clist_get_text (clist, row_set, 3, &descr);
528
529         if (g_strcasecmp (descr, syl_act) != 0)
530                 gtk_entry_set_text (GTK_ENTRY (mtoolbar.entry_icon_text), icon_text);
531
532         gtk_list_select_item (GTK_LIST (mtoolbar.combo_list), 
533                               toolbar_ret_val_from_descr (descr));
534         do {
535                 gtk_clist_get_text (clist_ico, row_ico, 1, &entry);
536                 row_ico++;
537         } while (g_strcasecmp (entry, file) != 0);
538         
539         gtk_clist_select_row (clist_ico, row_ico - 1, 0);
540         gtk_clist_moveto(clist_ico, row_ico - 1, 0, row_ico/clist_ico->rows, 0);
541 }
542
543 static void prefs_toolbar_select_row_icons(GtkCList *clist, gint row, gint column,
544                                            GdkEvent *event, gpointer user_data)
545 {
546         GtkCList *clist_icons = GTK_CLIST(mtoolbar.clist_icons);
547         gchar *text;
548         
549         gtk_clist_get_text (clist_icons, row, 1, &text);
550
551         if (!text) 
552                 return;
553
554         if (g_strcasecmp (SEPARATOR, text) == 0) {
555                 gtk_widget_set_sensitive (mtoolbar.combo_action,     FALSE);
556                 gtk_widget_set_sensitive (mtoolbar.entry_icon_text,  FALSE);
557                 gtk_widget_set_sensitive (mtoolbar.combo_syl_action, FALSE);
558         } else {
559                 gtk_widget_set_sensitive (mtoolbar.combo_action,     TRUE);
560                 gtk_widget_set_sensitive (mtoolbar.entry_icon_text,  TRUE);
561                 gtk_widget_set_sensitive (mtoolbar.combo_syl_action, TRUE);
562         }
563 }
564
565 static void prefs_toolbar_selection_changed(GtkList *list,
566                                             gpointer user_data)
567 {
568
569         gchar *cur_entry = g_strdup (gtk_entry_get_text (GTK_ENTRY (mtoolbar.combo_entry)));
570         gchar *actions_entry = toolbar_ret_descr_from_val (A_SYL_ACTIONS);
571
572         gtk_widget_set_sensitive (mtoolbar.combo_syl_action, TRUE);
573
574         if (g_strcasecmp (cur_entry, actions_entry) == 0) {
575                 gtk_widget_hide (mtoolbar.entry_icon_text);
576                 gtk_widget_show (mtoolbar.combo_syl_action);
577                 gtk_label_set_text (GTK_LABEL(mtoolbar.label_icon_text), _("select Sylpheed Action"));
578
579                 if (prefs_common.actions_list == NULL) {
580                     gtk_widget_set_sensitive (mtoolbar.combo_syl_action, FALSE);
581                 }
582                     
583         } else {
584                 gtk_widget_hide (mtoolbar.combo_syl_action);
585                 gtk_widget_show (mtoolbar.entry_icon_text);
586                 gtk_label_set_text (GTK_LABEL(mtoolbar.label_icon_text), _("enter Toolbar Text (shown below Pixmap)"));
587         }
588 }
589
590 static gint prefs_toolbar_key_pressed(GtkWidget *widget,
591                            GdkEventKey *event,
592                            gpointer data)
593 {
594         if (event && event->keyval == GDK_Escape) {
595                 prefs_toolbar_cancel();
596                 return TRUE;
597         }
598         return FALSE;
599 }
600
601 static void prefs_toolbar_create(void)
602 {
603         GtkWidget *window;
604         GtkWidget *main_vbox;
605         GtkWidget *top_hbox;
606         GtkWidget *compose_frame;
607         GtkWidget *reg_hbox;
608         GtkWidget *arrow;
609         GtkWidget *btn_hbox;
610         GtkWidget *reg_btn;
611         GtkWidget *subst_btn;
612         GtkWidget *del_btn;
613         GtkWidget *vbox_frame;
614         GtkWidget *scrolledwindow_clist_icon;
615         GtkWidget *clist_icons;
616         GtkWidget *hbox_icon_text;
617         GtkWidget *label_icon_text;
618         GtkWidget *entry_icon_text;
619         GtkWidget *hbox_action;
620         GtkWidget *label_action_sel;
621         GtkWidget *combo_action;
622         GtkWidget *combo_entry;
623         GtkWidget *combo_list;
624         GtkWidget *combo_syl_action;
625         GtkWidget *combo_syl_entry;
626         GtkWidget *combo_syl_list;
627         GtkWidget *frame_toolbar_items;
628         GtkWidget *hbox_bottom;
629         GtkWidget *scrolledwindow_clist_set;
630         GtkWidget *clist_set;
631         GtkWidget *label_icon;
632         GtkWidget *label_file;
633         GtkWidget *label_text;
634         GtkWidget *label_action;
635         GtkWidget *toolbar;
636         GtkWidget *up_btn;
637         GtkWidget *down_btn;
638         GtkWidget *icon_wid;
639
640         GtkWidget *confirm_area;
641         GtkWidget *ok_btn;
642         GtkWidget *cancel_btn;
643
644         window = gtk_window_new (GTK_WINDOW_DIALOG);
645         gtk_window_set_title (GTK_WINDOW (window), _("Customize Toolbar"));
646         //gtk_widget_set_usize (window, 400, 500);
647         gtk_widget_realize (window);
648
649         main_vbox = gtk_vbox_new (FALSE, 0);
650
651         gtk_container_add (GTK_CONTAINER (window), main_vbox);
652         
653         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
654                                 &cancel_btn, _("Cancel"), NULL, NULL);
655         gtk_box_pack_end (GTK_BOX(main_vbox), confirm_area, FALSE, FALSE, 0);
656         gtk_container_set_border_width (GTK_CONTAINER (confirm_area), 5);
657         gtk_widget_grab_default (ok_btn);
658
659         top_hbox = gtk_hbox_new (FALSE, 0);
660         gtk_box_pack_start (GTK_BOX (main_vbox), top_hbox, TRUE, TRUE, 0);
661   
662         compose_frame = gtk_frame_new (_("compose Toolbar Item"));
663         gtk_box_pack_start (GTK_BOX (top_hbox), compose_frame, TRUE, TRUE, 0);
664         gtk_container_set_border_width (GTK_CONTAINER (compose_frame), 5);
665
666         vbox_frame = gtk_vbox_new (FALSE, 0);
667         gtk_container_add (GTK_CONTAINER (compose_frame), vbox_frame);
668         
669         /* available icons */
670         scrolledwindow_clist_icon = gtk_scrolled_window_new (NULL, NULL);
671         gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow_clist_icon), 5);
672         gtk_container_add (GTK_CONTAINER (vbox_frame), scrolledwindow_clist_icon);
673         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_clist_icon), 
674                                         GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
675         
676         clist_icons = gtk_clist_new (2);
677         gtk_container_add (GTK_CONTAINER (scrolledwindow_clist_icon), clist_icons);
678         gtk_container_set_border_width (GTK_CONTAINER (clist_icons), 1);
679         gtk_clist_set_column_width (GTK_CLIST (clist_icons), 0, 35);
680         gtk_clist_set_column_width (GTK_CLIST (clist_icons), 1, 200);
681         gtk_clist_column_titles_hide (GTK_CLIST (clist_icons));
682         gtk_widget_set_usize (clist_icons, 300, 150);
683         
684         /* icon description */
685         hbox_icon_text = gtk_hbox_new (TRUE, 5);
686         gtk_container_add (GTK_CONTAINER (vbox_frame), hbox_icon_text);
687         gtk_container_set_border_width (GTK_CONTAINER (hbox_icon_text), 5);
688         
689         label_icon_text = gtk_label_new ("");
690         gtk_box_pack_start (GTK_BOX (hbox_icon_text), label_icon_text, FALSE, FALSE, 5);
691         
692         entry_icon_text = gtk_entry_new ();
693         gtk_box_pack_start (GTK_BOX (hbox_icon_text), entry_icon_text, FALSE, FALSE, 0);
694
695         /* Sylpheed Action Combo Box */ 
696         combo_syl_action = gtk_combo_new ();
697         gtk_box_pack_start (GTK_BOX (hbox_icon_text), combo_syl_action, TRUE, TRUE, 0);
698
699         combo_syl_list = GTK_COMBO (combo_syl_action)->list;
700         combo_syl_entry = GTK_COMBO (combo_syl_action)->entry;
701         gtk_entry_set_editable (GTK_ENTRY (combo_syl_entry), FALSE);
702
703         /* available actions */
704         hbox_action = gtk_hbox_new (TRUE, 5);
705         gtk_container_add (GTK_CONTAINER (vbox_frame), hbox_action);
706         gtk_container_set_border_width (GTK_CONTAINER (hbox_action), 5);
707         
708         label_action_sel = gtk_label_new (_("select Action executed on click"));
709         gtk_box_pack_start (GTK_BOX (hbox_action), label_action_sel, FALSE, FALSE, 0);
710         gtk_label_set_justify (GTK_LABEL (label_action_sel), GTK_JUSTIFY_RIGHT);
711         
712         combo_action = gtk_combo_new ();
713         gtk_box_pack_start (GTK_BOX (hbox_action), combo_action, TRUE, TRUE, 0);
714         
715         combo_list = GTK_COMBO (combo_action)->list;
716         combo_entry = GTK_COMBO (combo_action)->entry;
717         gtk_entry_set_editable (GTK_ENTRY (combo_entry), FALSE);
718         
719         /* register / substitute / delete */
720         reg_hbox = gtk_hbox_new (FALSE, 4);
721         gtk_box_pack_start (GTK_BOX (main_vbox), reg_hbox, FALSE, FALSE, 0);
722         gtk_container_set_border_width (GTK_CONTAINER (reg_hbox), 10);
723
724         arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
725         gtk_box_pack_start (GTK_BOX (reg_hbox), arrow, FALSE, FALSE, 0);
726         gtk_widget_set_usize (arrow, -1, 16);
727
728         btn_hbox = gtk_hbox_new (TRUE, 4);
729         gtk_box_pack_start (GTK_BOX (reg_hbox), btn_hbox, FALSE, FALSE, 0);
730
731         reg_btn = gtk_button_new_with_label (_("Register"));
732         gtk_box_pack_start (GTK_BOX (btn_hbox), reg_btn, FALSE, TRUE, 0);
733         gtk_signal_connect (GTK_OBJECT (reg_btn), "clicked",
734                             GTK_SIGNAL_FUNC (prefs_toolbar_register), 
735                             NULL);
736
737         subst_btn = gtk_button_new_with_label (_(" Substitute "));
738         gtk_box_pack_start (GTK_BOX (btn_hbox), subst_btn, FALSE, TRUE, 0);
739         gtk_signal_connect (GTK_OBJECT (subst_btn), "clicked",
740                             GTK_SIGNAL_FUNC (prefs_toolbar_substitute),
741                             NULL);
742
743         del_btn = gtk_button_new_with_label (_("Delete"));
744         gtk_box_pack_start (GTK_BOX (btn_hbox), del_btn, FALSE, TRUE, 0);
745         gtk_signal_connect (GTK_OBJECT (del_btn), "clicked",
746                             GTK_SIGNAL_FUNC (prefs_toolbar_delete), 
747                             NULL);
748
749         /* currently active toolbar items */
750         frame_toolbar_items = gtk_frame_new (_("set ToolbarItems"));
751         gtk_box_pack_start (GTK_BOX (main_vbox), frame_toolbar_items, TRUE, TRUE, 0);
752         gtk_container_set_border_width (GTK_CONTAINER (frame_toolbar_items), 5);
753         
754         hbox_bottom = gtk_hbox_new (FALSE, 0);
755         gtk_container_add (GTK_CONTAINER (frame_toolbar_items), hbox_bottom);
756         
757         scrolledwindow_clist_set = gtk_scrolled_window_new (NULL, NULL);
758         gtk_box_pack_start (GTK_BOX (hbox_bottom), scrolledwindow_clist_set, TRUE, TRUE, 0);
759         gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow_clist_set), 5);
760         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_clist_icon), 
761                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
762         
763         clist_set = gtk_clist_new (4);
764         gtk_container_add (GTK_CONTAINER (scrolledwindow_clist_set), clist_set);
765         gtk_clist_set_column_width (GTK_CLIST (clist_set), 0, 80);
766         gtk_clist_set_column_width (GTK_CLIST (clist_set), 1, 80);
767         gtk_clist_set_column_width (GTK_CLIST (clist_set), 2, 80);
768         gtk_clist_set_column_width (GTK_CLIST (clist_set), 3, 80);
769         gtk_clist_column_titles_show (GTK_CLIST (clist_set));
770         gtk_widget_set_usize (clist_set, 300, 200);
771
772         label_icon = gtk_label_new (_("Toolbar Icon"));
773         gtk_clist_set_column_widget (GTK_CLIST (clist_set), 0, label_icon);
774         
775         label_file = gtk_label_new (_("File Name"));
776         gtk_clist_set_column_widget (GTK_CLIST (clist_set), 1, label_file);
777
778         label_text = gtk_label_new (_("Icon Text"));
779         gtk_clist_set_column_widget (GTK_CLIST (clist_set), 2, label_text);
780
781         label_action = gtk_label_new (_("Mapped Action"));
782         gtk_clist_set_column_widget (GTK_CLIST (clist_set), 3, label_action);
783         
784         toolbar = gtk_toolbar_new (GTK_ORIENTATION_VERTICAL, GTK_TOOLBAR_BOTH);
785         gtk_box_pack_start (GTK_BOX (hbox_bottom), toolbar, FALSE, FALSE, 0);
786         gtk_container_set_border_width (GTK_CONTAINER (toolbar), 5);
787
788         icon_wid = stock_pixmap_widget(hbox_bottom, STOCK_PIXMAP_UP_ARROW);
789         up_btn = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar),
790                                              GTK_TOOLBAR_CHILD_BUTTON,
791                                              NULL,
792                                              NULL,
793                                              _("Up"), NULL,
794                                              icon_wid, NULL, NULL);
795
796         icon_wid = stock_pixmap_widget(hbox_bottom, STOCK_PIXMAP_DOWN_ARROW);
797         down_btn = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar),
798                                                GTK_TOOLBAR_CHILD_BUTTON,
799                                                NULL,
800                                                NULL,
801                                                _("Down"), NULL,
802                                                icon_wid, NULL, NULL);
803
804         gtk_signal_connect(GTK_OBJECT (window), "delete_event",
805                            GTK_SIGNAL_FUNC (prefs_toolbar_cancel),
806                            NULL);
807         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
808                            GTK_SIGNAL_FUNC(prefs_toolbar_key_pressed),
809                            NULL);
810         MANAGE_WINDOW_SIGNALS_CONNECT(window);  
811
812         gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
813                            GTK_SIGNAL_FUNC(prefs_toolbar_ok), 
814                            NULL);
815         gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
816                            GTK_SIGNAL_FUNC(prefs_toolbar_cancel), 
817                            NULL);
818         gtk_signal_connect(GTK_OBJECT (clist_set), "select_row",
819                            GTK_SIGNAL_FUNC (prefs_toolbar_select_row_set),
820                            NULL);
821         gtk_signal_connect(GTK_OBJECT (clist_icons), "select_row",
822                            GTK_SIGNAL_FUNC (prefs_toolbar_select_row_icons),
823                            NULL);
824         gtk_signal_connect(GTK_OBJECT (down_btn), "clicked",
825                            GTK_SIGNAL_FUNC (prefs_toolbar_down),
826                            NULL);
827         gtk_signal_connect(GTK_OBJECT (up_btn), "clicked",
828                            GTK_SIGNAL_FUNC (prefs_toolbar_up),
829                            NULL);
830         gtk_signal_connect(GTK_OBJECT(combo_list), "selection-changed",
831                            GTK_SIGNAL_FUNC(prefs_toolbar_selection_changed),
832                            NULL);
833         
834         mtoolbar.window           = window;
835         mtoolbar.clist_icons      = clist_icons;
836         mtoolbar.clist_set        = clist_set;
837         mtoolbar.combo_action     = combo_action;
838         mtoolbar.combo_entry      = combo_entry;
839         mtoolbar.combo_list       = combo_list;
840         mtoolbar.entry_icon_text  = entry_icon_text;
841         mtoolbar.combo_syl_action = combo_syl_action;
842         mtoolbar.combo_syl_list   = combo_syl_list;
843         mtoolbar.combo_syl_entry  = combo_syl_entry;
844
845         mtoolbar.label_icon_text  = label_icon_text;
846
847         gtk_widget_show_all (window);
848 }