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