fix bug where clicking 'OK' creates an icon & text toolbar regardless of prefs
[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         main_window_reflect_prefs_all_real(TRUE);
304 }
305
306 static void prefs_toolbar_ok(void)
307 {
308         prefs_toolbar_save();
309         prefs_toolbar_close();
310 }
311
312 static void prefs_toolbar_cancel(void)
313 {
314         prefs_toolbar_close();
315 }
316
317 static void get_action_name(gchar *entry, gchar **menu)
318 {
319         gchar *act, *act_p;
320
321         if (prefs_common.actions_list != NULL) {
322                 
323                 act = g_strdup(entry);
324                 act_p = strstr(act, ": ");
325                 if (act_p != NULL)
326                         act_p[0] = 0x00;
327                 /* freed by calling func */
328                 *menu = act;
329         }
330 }
331
332 static gint prefs_toolbar_register(void)
333 {
334         GtkCList *clist_set   = GTK_CLIST(mtoolbar.clist_set);
335         GtkCList *clist_icons = GTK_CLIST(mtoolbar.clist_icons);
336         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
337         gint row_icons = 0;
338         gint row_set = 0;
339         GdkPixmap *xpm;
340         GdkBitmap *xpmmask;
341         gchar *item[4];
342
343         if (clist_icons->rows == 0) return -1; 
344
345         if (clist_icons->selection)
346                 if (clist_icons->selection->data) 
347                         row_icons = GPOINTER_TO_INT(clist_icons->selection->data);
348         
349         gtk_clist_get_text(clist_icons, row_icons, 1, &item[1]);
350         item[3] = g_strdup(gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_entry)));
351         
352         /* SEPARATOR or other ? */
353         if (g_strcasecmp(item[1], SEPARATOR) == 0) {
354                 item[0] = g_strdup(SEPARATOR_PIXMAP);
355                 item[2] = g_strdup("");
356                 item[3] = g_strdup("");
357                 
358                 row_set = gtk_clist_append(GTK_CLIST(mtoolbar.clist_set), item);
359
360                 g_free(item[0]);
361         } else {
362
363                 if (is_duplicate(item[3])) {
364                         alertpanel_error(ERROR_MSG);
365                         g_free(item[3]);
366                         return -1;
367                 }
368
369                 stock_pixmap_gdk(mtoolbar.clist_set, stock_pixmap_get_icon(item[1]),
370                                   &xpm, &xpmmask);
371
372                 if (g_strcasecmp(item[3], syl_act) == 0) {
373
374                         gchar *entry = gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_syl_entry));
375                         get_action_name(entry, &item[2]);
376                 }
377                 else {
378                         item[2] = g_strdup(gtk_entry_get_text(GTK_ENTRY(mtoolbar.entry_icon_text)));
379                 }
380
381                 row_set = gtk_clist_append(GTK_CLIST(mtoolbar.clist_set), item);
382                 gtk_clist_set_pixmap(clist_set, row_set, 0, xpm, xpmmask);
383         }
384
385         gtk_clist_moveto(clist_set, row_set, 0, row_set/clist_set->rows, 0);
386         gtk_clist_select_row(clist_set, row_set, 0);
387
388         g_free(item[2]);
389         g_free(item[3]);
390
391         return 0;
392 }
393
394 static gint prefs_toolbar_substitute(void)
395 {
396         GtkCList *clist_set   = GTK_CLIST(mtoolbar.clist_set);
397         GtkCList *clist_icons = GTK_CLIST(mtoolbar.clist_icons);
398         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
399         gint row_icons = 0;
400         gint row_set = 0;
401         GdkPixmap *xpm;
402         GdkBitmap *xpmmask;
403         gchar *item[4];
404         gchar *ac_set;
405
406         /* no rows or nothing selected */
407         if ((clist_set->rows == 0) || (clist_set->selection == 0)) return -1; 
408
409         if (clist_icons->selection)
410                 if (clist_icons->selection->data) 
411                         row_icons = GPOINTER_TO_INT(clist_icons->selection->data);
412
413         if (clist_set->selection)
414                 if (clist_set->selection->data) 
415                         row_set = GPOINTER_TO_INT(clist_set->selection->data);
416
417         gtk_clist_get_text(clist_icons, row_icons, 1, &item[1]);
418         gtk_clist_get_text(clist_set, row_set, 3, &ac_set);
419         item[3] = g_strdup(gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_entry)));
420
421         if (g_strcasecmp(item[1], SEPARATOR) == 0) {
422                 item[0] = g_strdup(SEPARATOR_PIXMAP);
423                 item[2] = g_strdup("");
424                 item[3] = g_strdup("");
425
426                 gtk_clist_remove(clist_set, row_set);
427                 row_set = gtk_clist_insert(clist_set, row_set, item);
428
429                 g_free(item[0]);
430         } else {
431
432                 if ((is_duplicate(item[3])) && (g_strcasecmp(item[3], ac_set) != 0)){
433                         alertpanel_error(ERROR_MSG);
434                         g_free(item[3]);
435                         return -1;
436                 }
437
438                 stock_pixmap_gdk(mtoolbar.clist_set, stock_pixmap_get_icon(item[1]),
439                                   &xpm, &xpmmask);
440
441                 if (g_strcasecmp(item[3], syl_act) == 0) {
442
443                         gchar *entry = gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_syl_entry));
444                         get_action_name(entry, &item[2]);
445                 } else {
446                         item[2] = g_strdup(gtk_entry_get_text(GTK_ENTRY(mtoolbar.entry_icon_text)));
447                 }
448
449                 gtk_clist_remove(clist_set, row_set);
450                 row_set = gtk_clist_insert(clist_set, row_set, item);
451                 gtk_clist_set_pixmap(clist_set, row_set, 0, xpm, xpmmask);
452         }
453         
454         gtk_clist_moveto(clist_set, row_set, 0, row_set/clist_set->rows, 0);
455         gtk_clist_select_row(clist_set, row_set, 0);
456
457         g_free(item[2]);
458         g_free(item[3]);
459         
460         return 0;
461 }
462
463 static gint prefs_toolbar_delete(void)
464 {
465         GtkCList *clist_set = GTK_CLIST(mtoolbar.clist_set);
466         gint row_set = 0;
467
468         if (clist_set->rows == 0) return -1; 
469         if (clist_set->selection)
470                 if (clist_set->selection->data) 
471                         row_set = GPOINTER_TO_INT(clist_set->selection->data);
472
473         if (clist_set->row_list != NULL) {
474                         
475                 row_set = GPOINTER_TO_INT(clist_set->selection->data);
476                 gtk_clist_remove(clist_set, row_set);
477                 gtk_clist_columns_autosize(clist_set);
478                 
479                 if (clist_set->rows > 0)
480                         gtk_clist_select_row(clist_set,(row_set == 0) ? 0:row_set - 1, 0);
481         }
482
483         return 0;
484 }
485
486 static void prefs_toolbar_up(void)
487 {
488         GtkCList *clist = GTK_CLIST(mtoolbar.clist_set);
489         gint row = 0;
490
491         if (!clist->selection) return;
492         if (clist->selection->data)
493                 row = GPOINTER_TO_INT(clist->selection->data);
494
495         if (row >= 0) {
496                 gtk_clist_row_move(clist, row, row - 1);
497                 if(gtk_clist_row_is_visible(clist, row - 1) != GTK_VISIBILITY_FULL) {
498                         gtk_clist_moveto(clist, row - 1, 0, 0, 0);
499                 } 
500         }
501 }
502
503 static void prefs_toolbar_down(void)
504 {
505         GtkCList *clist = GTK_CLIST(mtoolbar.clist_set);
506         gint row = 0;
507
508         if (!clist->selection) return;
509         if (clist->selection->data)
510                 row = GPOINTER_TO_INT(clist->selection->data);
511
512         if (row >= 0 && row < clist->rows - 1) {
513                 gtk_clist_row_move(clist, row, row + 1);
514                 if(gtk_clist_row_is_visible(clist, row + 1) != GTK_VISIBILITY_FULL) {
515                         gtk_clist_moveto(clist, row + 1, 0, 1, 0);
516                 } 
517         }
518 }
519
520 static void prefs_toolbar_select_row_set(GtkCList *clist, gint row, gint column,
521                                          GdkEvent *event, gpointer user_data)
522 {
523         GtkCList *clist_ico = GTK_CLIST(mtoolbar.clist_icons);
524         gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
525         gint row_set = 0;
526         gint row_ico = 0;
527         gchar *file, *icon_text, *descr, *entry;
528
529         if (clist->selection->data) 
530                 row_set = GPOINTER_TO_INT(clist->selection->data);      
531
532         gtk_clist_get_text(clist, row_set, 1, &file);
533         gtk_clist_get_text(clist, row_set, 2, &icon_text);
534         gtk_clist_get_text(clist, row_set, 3, &descr);
535
536         if (g_strcasecmp(descr, syl_act) != 0)
537                 gtk_entry_set_text(GTK_ENTRY(mtoolbar.entry_icon_text), icon_text);
538
539         gtk_list_select_item(GTK_LIST(mtoolbar.combo_list), 
540                               toolbar_ret_val_from_descr(descr));
541         do {
542                 gtk_clist_get_text(clist_ico, row_ico, 1, &entry);
543                 row_ico++;
544         } while(g_strcasecmp(entry, file) != 0);
545         
546         gtk_clist_select_row(clist_ico, row_ico - 1, 0);
547         gtk_clist_moveto(clist_ico, row_ico - 1, 0, row_ico/clist_ico->rows, 0);
548 }
549
550 static void prefs_toolbar_select_row_icons(GtkCList *clist, gint row, gint column,
551                                            GdkEvent *event, gpointer user_data)
552 {
553         GtkCList *clist_icons = GTK_CLIST(mtoolbar.clist_icons);
554         gchar *text;
555         
556         gtk_clist_get_text(clist_icons, row, 1, &text);
557
558         if (!text) 
559                 return;
560
561         if (g_strcasecmp(SEPARATOR, text) == 0) {
562                 gtk_widget_set_sensitive(mtoolbar.combo_action,     FALSE);
563                 gtk_widget_set_sensitive(mtoolbar.entry_icon_text,  FALSE);
564                 gtk_widget_set_sensitive(mtoolbar.combo_syl_action, FALSE);
565         } else {
566                 gtk_widget_set_sensitive(mtoolbar.combo_action,     TRUE);
567                 gtk_widget_set_sensitive(mtoolbar.entry_icon_text,  TRUE);
568                 gtk_widget_set_sensitive(mtoolbar.combo_syl_action, TRUE);
569         }
570 }
571
572 static void prefs_toolbar_selection_changed(GtkList *list,
573                                             gpointer user_data)
574 {
575
576         gchar *cur_entry = g_strdup(gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_entry)));
577         gchar *actions_entry = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
578
579         gtk_widget_set_sensitive(mtoolbar.combo_syl_action, TRUE);
580
581         if (g_strcasecmp(cur_entry, actions_entry) == 0) {
582                 gtk_widget_hide(mtoolbar.entry_icon_text);
583                 gtk_widget_show(mtoolbar.combo_syl_action);
584                 gtk_label_set_text(GTK_LABEL(mtoolbar.label_icon_text), _("Sylpheed Action"));
585
586                 if (prefs_common.actions_list == NULL) {
587                     gtk_widget_set_sensitive(mtoolbar.combo_syl_action, FALSE);
588                 }
589                     
590         } else {
591                 gtk_widget_hide(mtoolbar.combo_syl_action);
592                 gtk_widget_show(mtoolbar.entry_icon_text);
593                 gtk_label_set_text(GTK_LABEL(mtoolbar.label_icon_text), _("Toolbar text"));
594         }
595 }
596
597 static gint prefs_toolbar_key_pressed(GtkWidget *widget,
598                            GdkEventKey *event,
599                            gpointer data)
600 {
601         if (event && event->keyval == GDK_Escape) {
602                 prefs_toolbar_cancel();
603                 return TRUE;
604         }
605         return FALSE;
606 }
607
608 static void prefs_toolbar_create(void)
609 {
610         GtkWidget *window;
611         GtkWidget *main_vbox;
612         GtkWidget *top_hbox;
613         GtkWidget *compose_frame;
614         GtkWidget *reg_hbox;
615         GtkWidget *arrow;
616         GtkWidget *btn_hbox;
617         GtkWidget *reg_btn;
618         GtkWidget *subst_btn;
619         GtkWidget *del_btn;
620         GtkWidget *vbox_frame;
621         GtkWidget *scrolledwindow_clist_icon;
622         GtkWidget *clist_icons;
623         GtkWidget *hbox_icon_text;
624         GtkWidget *label_icon_text;
625         GtkWidget *entry_icon_text;
626         GtkWidget *hbox_action;
627         GtkWidget *label_action_sel;
628         GtkWidget *combo_action;
629         GtkWidget *combo_entry;
630         GtkWidget *combo_list;
631         GtkWidget *combo_syl_action;
632         GtkWidget *combo_syl_entry;
633         GtkWidget *combo_syl_list;
634         GtkWidget *frame_toolbar_items;
635         GtkWidget *hbox_bottom;
636         GtkWidget *scrolledwindow_clist_set;
637         GtkWidget *clist_set;
638
639         GtkWidget *btn_vbox;
640         GtkWidget *up_btn;
641         GtkWidget *down_btn;
642
643         GtkWidget *confirm_area;
644         GtkWidget *ok_btn;
645         GtkWidget *cancel_btn;
646
647         gchar *titles[N_DISPLAYED_ITEMS_COLS];
648
649         debug_print("Creating custom toolbar window...\n");
650
651         window = gtk_window_new(GTK_WINDOW_DIALOG);
652         gtk_widget_set_usize(window, 450, -1); 
653         gtk_container_set_border_width(GTK_CONTAINER(window), 8);
654         gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
655         gtk_window_set_title(GTK_WINDOW(window), _("Customize toolbar"));
656         gtk_window_set_modal(GTK_WINDOW(window), TRUE);
657         gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, TRUE);
658         gtk_signal_connect(GTK_OBJECT(window), "delete_event",
659                            GTK_SIGNAL_FUNC(prefs_toolbar_cancel),
660                            NULL);
661         gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
662                            GTK_SIGNAL_FUNC(prefs_toolbar_key_pressed),
663                            NULL);
664         MANAGE_WINDOW_SIGNALS_CONNECT(window);  
665         gtk_widget_realize(window); 
666
667         main_vbox = gtk_vbox_new(FALSE, 0);
668         gtk_widget_show(main_vbox);
669         gtk_container_add(GTK_CONTAINER(window), main_vbox);
670         
671         top_hbox = gtk_hbox_new(FALSE, 0);
672         gtk_box_pack_start(GTK_BOX(main_vbox), top_hbox, TRUE, TRUE, 0);
673   
674         compose_frame = gtk_frame_new(_("Available toolbar items"));
675         gtk_box_pack_start(GTK_BOX(top_hbox), compose_frame, TRUE, TRUE, 0);
676         gtk_container_set_border_width(GTK_CONTAINER(compose_frame), 5);
677
678         vbox_frame = gtk_vbox_new(FALSE, 0);
679         gtk_container_add(GTK_CONTAINER(compose_frame), vbox_frame);
680         
681         /* available icons */
682         scrolledwindow_clist_icon = gtk_scrolled_window_new(NULL, NULL);
683         gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow_clist_icon), 5);
684         gtk_container_add(GTK_CONTAINER(vbox_frame), scrolledwindow_clist_icon);
685         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow_clist_icon), 
686                                         GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
687         
688         clist_icons = gtk_clist_new(2);
689         gtk_container_add(GTK_CONTAINER(scrolledwindow_clist_icon), clist_icons);
690         gtk_container_set_border_width(GTK_CONTAINER(clist_icons), 1);
691         gtk_clist_set_column_width(GTK_CLIST(clist_icons), 0, 35);
692         gtk_clist_set_column_width(GTK_CLIST(clist_icons), 1, 200);
693         gtk_clist_column_titles_hide(GTK_CLIST(clist_icons));
694         gtk_widget_set_usize(clist_icons, 225, 108); 
695         
696         /* icon description */
697         hbox_icon_text = gtk_hbox_new(FALSE, 5);
698         gtk_container_add(GTK_CONTAINER(vbox_frame), hbox_icon_text);
699         
700         label_icon_text = gtk_label_new("");
701         gtk_box_pack_start(GTK_BOX(hbox_icon_text), label_icon_text, FALSE, FALSE, 5);
702         
703         entry_icon_text = gtk_entry_new();
704         gtk_box_pack_start(GTK_BOX(hbox_icon_text), entry_icon_text, FALSE, FALSE, 0);
705
706         /* Sylpheed Action Combo Box */ 
707         combo_syl_action = gtk_combo_new();
708         gtk_box_pack_start(GTK_BOX(hbox_icon_text), combo_syl_action, FALSE, FALSE, 0);
709
710         combo_syl_list = GTK_COMBO(combo_syl_action)->list;
711         combo_syl_entry = GTK_COMBO(combo_syl_action)->entry;
712         gtk_entry_set_editable(GTK_ENTRY(combo_syl_entry), FALSE);
713
714         /* available actions */
715         hbox_action = gtk_hbox_new(FALSE, 5);
716         gtk_container_add(GTK_CONTAINER(vbox_frame), hbox_action);
717         gtk_container_set_border_width(GTK_CONTAINER(hbox_action), 5);
718         
719         label_action_sel = gtk_label_new(_("Event executed on click"));
720         gtk_box_pack_start(GTK_BOX(hbox_action), label_action_sel, FALSE, FALSE, 0);
721         
722         combo_action = gtk_combo_new();
723         gtk_box_pack_start(GTK_BOX(hbox_action), combo_action, FALSE, FALSE, 0);
724         
725         combo_list = GTK_COMBO(combo_action)->list;
726         combo_entry = GTK_COMBO(combo_action)->entry;
727         gtk_entry_set_editable(GTK_ENTRY(combo_entry), FALSE);
728         
729         /* register / substitute / delete */
730         reg_hbox = gtk_hbox_new(FALSE, 4);
731         gtk_box_pack_start(GTK_BOX(main_vbox), reg_hbox, FALSE, FALSE, 0);
732         gtk_container_set_border_width(GTK_CONTAINER(reg_hbox), 10);
733
734         arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_OUT);
735         gtk_box_pack_start(GTK_BOX(reg_hbox), arrow, FALSE, FALSE, 0);
736         gtk_widget_set_usize(arrow, -1, 16);
737
738         btn_hbox = gtk_hbox_new(TRUE, 4);
739         gtk_box_pack_start(GTK_BOX(reg_hbox), btn_hbox, FALSE, FALSE, 0);
740
741         reg_btn = gtk_button_new_with_label(_("Register"));
742         gtk_box_pack_start(GTK_BOX(btn_hbox), reg_btn, FALSE, TRUE, 0);
743         gtk_signal_connect(GTK_OBJECT(reg_btn), "clicked",
744                             GTK_SIGNAL_FUNC(prefs_toolbar_register), 
745                             NULL);
746
747         subst_btn = gtk_button_new_with_label(_(" Substitute "));
748         gtk_box_pack_start(GTK_BOX(btn_hbox), subst_btn, FALSE, TRUE, 0);
749         gtk_signal_connect(GTK_OBJECT(subst_btn), "clicked",
750                             GTK_SIGNAL_FUNC(prefs_toolbar_substitute),
751                             NULL);
752
753         del_btn = gtk_button_new_with_label(_("Delete"));
754         gtk_box_pack_start(GTK_BOX(btn_hbox), del_btn, FALSE, TRUE, 0);
755         gtk_signal_connect(GTK_OBJECT(del_btn), "clicked",
756                             GTK_SIGNAL_FUNC(prefs_toolbar_delete), 
757                             NULL);
758
759         /* currently active toolbar items */
760         frame_toolbar_items = gtk_frame_new(_("Displayed toolbar items"));
761         gtk_box_pack_start(GTK_BOX(main_vbox), frame_toolbar_items, TRUE, TRUE, 0);
762         gtk_container_set_border_width(GTK_CONTAINER(frame_toolbar_items), 5);
763         
764         hbox_bottom = gtk_hbox_new(FALSE, 0);
765         gtk_container_add(GTK_CONTAINER(frame_toolbar_items), hbox_bottom);
766         
767         scrolledwindow_clist_set = gtk_scrolled_window_new(NULL, NULL);
768         gtk_box_pack_start(GTK_BOX(hbox_bottom), scrolledwindow_clist_set, TRUE, TRUE, 0);
769         gtk_container_set_border_width(GTK_CONTAINER(scrolledwindow_clist_set), 1);
770         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow_clist_icon), 
771                                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
772
773         titles[COL_ICON]     = _("Icon");
774         titles[COL_FILENAME] = _("File name");
775         titles[COL_TEXT]     = _("Icon text");
776         titles[COL_EVENT]    = _("Mapped event");
777         
778         clist_set = gtk_clist_new_with_titles(N_DISPLAYED_ITEMS_COLS, titles);
779         gtk_widget_show(clist_set);
780         gtk_container_add(GTK_CONTAINER(scrolledwindow_clist_set), clist_set);
781         gtk_clist_set_column_width(GTK_CLIST(clist_set), COL_ICON    , 80);
782         gtk_clist_set_column_width(GTK_CLIST(clist_set), COL_FILENAME, 80);
783         gtk_clist_set_column_width(GTK_CLIST(clist_set), COL_TEXT    , 80);
784         gtk_clist_set_column_width(GTK_CLIST(clist_set), COL_EVENT   , 80);
785         gtk_clist_column_titles_show(GTK_CLIST(clist_set));
786         gtk_widget_set_usize(clist_set, 225, 120);
787
788         btn_vbox = gtk_vbox_new(FALSE, 8);
789         gtk_widget_show(btn_vbox);
790         gtk_box_pack_start(GTK_BOX(hbox_bottom), btn_vbox, FALSE, FALSE, 5);
791
792         up_btn = gtk_button_new_with_label(_("Up"));
793         gtk_widget_show(up_btn);
794         gtk_box_pack_start(GTK_BOX(btn_vbox), up_btn, FALSE, FALSE, 2);
795
796         down_btn = gtk_button_new_with_label(_("Down"));
797         gtk_widget_show(down_btn);
798         gtk_box_pack_start(GTK_BOX(btn_vbox), down_btn, FALSE, FALSE, 0);
799
800         gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
801                                 &cancel_btn, _("Cancel"), NULL, NULL);
802         gtk_box_pack_end(GTK_BOX(main_vbox), confirm_area, FALSE, FALSE, 0);
803         gtk_container_set_border_width(GTK_CONTAINER(confirm_area), 5);
804         gtk_widget_grab_default(ok_btn);
805
806         gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
807                            GTK_SIGNAL_FUNC(prefs_toolbar_ok), NULL);
808         gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
809                            GTK_SIGNAL_FUNC(prefs_toolbar_cancel), NULL);
810         gtk_signal_connect(GTK_OBJECT(clist_set), "select_row",
811                            GTK_SIGNAL_FUNC(prefs_toolbar_select_row_set),
812                            NULL);
813         gtk_signal_connect(GTK_OBJECT(clist_icons), "select_row",
814                            GTK_SIGNAL_FUNC(prefs_toolbar_select_row_icons),
815                            NULL);
816         gtk_signal_connect(GTK_OBJECT(combo_list), "selection-changed",
817                            GTK_SIGNAL_FUNC(prefs_toolbar_selection_changed),
818                            NULL);
819         gtk_signal_connect(GTK_OBJECT(up_btn), "clicked",
820                            GTK_SIGNAL_FUNC(prefs_toolbar_up), NULL);
821         gtk_signal_connect(GTK_OBJECT(down_btn), "clicked",
822                            GTK_SIGNAL_FUNC(prefs_toolbar_down), NULL);
823         
824         mtoolbar.window           = window;
825         mtoolbar.clist_icons      = clist_icons;
826         mtoolbar.clist_set        = clist_set;
827         mtoolbar.combo_action     = combo_action;
828         mtoolbar.combo_entry      = combo_entry;
829         mtoolbar.combo_list       = combo_list;
830         mtoolbar.entry_icon_text  = entry_icon_text;
831         mtoolbar.combo_syl_action = combo_syl_action;
832         mtoolbar.combo_syl_list   = combo_syl_list;
833         mtoolbar.combo_syl_entry  = combo_syl_entry;
834
835         mtoolbar.label_icon_text  = label_icon_text;
836
837         gtk_widget_show_all(window);
838 }