Custom Toolbar 3
authorOliver Haertel <o.h.a@gmx.net>
Tue, 6 Aug 2002 14:06:40 +0000 (14:06 +0000)
committerOliver Haertel <o.h.a@gmx.net>
Tue, 6 Aug 2002 14:06:40 +0000 (14:06 +0000)
src/Makefile.am
src/prefs_toolbar.c [new file with mode: 0644]
src/prefs_toolbar.h [new file with mode: 0644]
src/toolbar.c [new file with mode: 0644]
src/toolbar.h [new file with mode: 0644]

index b66fb15..77d1877 100644 (file)
@@ -136,7 +136,9 @@ sylpheed_SOURCES = \
        string_match.h string_match.c \
        selective_download.c selective_download.h \
        msgcache.h msgcache.c \
-       noticeview.h noticeview.c
+       noticeview.h noticeview.c \
+       toolbar.c toolbar.h \
+       prefs_toolbar.c prefs_toolbar.h
 
 BUILT_SOURCES = \
        quote_fmt_lex.c \
diff --git a/src/prefs_toolbar.c b/src/prefs_toolbar.c
new file mode 100644 (file)
index 0000000..6e98690
--- /dev/null
@@ -0,0 +1,847 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2001 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * General functions for accessing address book files.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "defs.h"
+
+#include <glib.h>
+#include <gtk/gtk.h>
+#include <gtk/gtkoptionmenu.h>
+#include <gdk/gdkkeysyms.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "intl.h"
+#include "stock_pixmap.h"
+#include "manage_window.h"
+#include "gtkutils.h"
+#include "mainwindow.h"
+#include "alertpanel.h"
+#include "prefs_common.h"
+
+#include "utils.h"
+
+#include "toolbar.h"
+#include "prefs_toolbar.h"
+
+static struct _Toolbar {
+       GtkWidget *window;
+
+       GtkWidget *clist_icons;
+       GtkWidget *clist_set;
+       GtkWidget *combo_action;
+       GtkWidget *combo_entry;
+       GtkWidget *combo_list;
+       GtkWidget *label_icon_text;
+       GtkWidget *entry_icon_text;
+       GtkWidget *combo_syl_action;
+       GtkWidget *combo_syl_list;
+       GtkWidget *combo_syl_entry;
+
+}mtoolbar;
+
+#define CELL_SPACING 30
+#define ERROR_MSG _("Selected Action already set.\nPlease choose another Action from List")
+
+static void prefs_toolbar_open                   (void);
+static void prefs_toolbar_populate               (void);
+static gboolean is_duplicate                     (gchar *chosen_action);
+static void prefs_toolbar_save                   (void);
+static void prefs_toolbar_ok                     (void);
+static void prefs_toolbar_cancel                 (void);
+
+static gint prefs_toolbar_register               (void);
+static gint prefs_toolbar_substitute             (void);
+static gint prefs_toolbar_delete                 (void);
+
+static void prefs_toolbar_up                     (void);
+
+static void prefs_toolbar_down                   (void);
+
+static void prefs_toolbar_select_row_set         (GtkCList *clist, 
+                                                 gint row, 
+                                                 gint column,
+                                                 GdkEvent *event, 
+                                                 gpointer user_data);
+
+static void prefs_toolbar_select_row_icons       (GtkCList *clist, 
+                                                 gint row, 
+                                                 gint column,
+                                                 GdkEvent *event, 
+                                                 gpointer user_data);
+
+static void prefs_toolbar_create                 (void);
+
+static void prefs_toolbar_selection_changed      (GtkList *list, 
+                                                 gpointer user_data);
+
+static gint prefs_toolbar_key_pressed            (GtkWidget *widget,
+                                                 GdkEventKey *event,
+                                                 gpointer data);
+
+void prefs_toolbar(void)
+{
+       toolbar_read_config_file();
+       prefs_toolbar_open ();
+}
+
+static void prefs_toolbar_open(void)
+{
+       if (!mtoolbar.window)
+               prefs_toolbar_create ();
+
+       manage_window_set_transient (GTK_WINDOW (mtoolbar.window));
+       prefs_toolbar_populate ();
+       gtk_widget_show(mtoolbar.window);
+}
+
+void prefs_toolbar_close(void)
+{
+       gtk_widget_hide (mtoolbar.window);
+}
+
+static void prefs_toolbar_populate(void)
+{
+       gint i;
+       GSList *cur;
+       GList *combo_action_items;
+       GList *syl_actions = NULL;
+       GtkCList *clist_icons = GTK_CLIST(mtoolbar.clist_icons);
+       GtkCList *clist_set   = GTK_CLIST(mtoolbar.clist_set);
+       GdkPixmap *xpm;
+       GdkBitmap *xpmmask;
+       gchar *avail[2];
+       gchar *activ[5];
+       gchar *act;
+       
+       gtk_clist_clear (clist_icons);
+       gtk_clist_clear (clist_set);
+
+       gtk_clist_freeze (clist_icons);
+       gtk_clist_freeze (clist_set);
+
+       /* set available icons */
+       avail[0] = g_strdup (SEPARATOR_PIXMAP);
+       avail[1] = g_strdup (SEPARATOR);
+       gtk_clist_append (clist_icons, avail);
+       g_free (avail[0]);
+       g_free (avail[1]);
+
+       combo_action_items = toolbar_get_action_items ();
+       gtk_combo_set_popdown_strings (GTK_COMBO (mtoolbar.combo_action), combo_action_items);
+       gtk_combo_set_value_in_list (GTK_COMBO (mtoolbar.combo_action), 0, FALSE);
+       gtk_entry_set_text (GTK_ENTRY (mtoolbar.combo_entry), combo_action_items->data);
+       g_list_free (combo_action_items);
+
+       /* get currently defined sylpheed actions */
+       if (prefs_common.actions_list != NULL) {
+
+               for (cur = prefs_common.actions_list; cur != NULL; cur = cur->next) {
+                       act = (gchar *)cur->data;
+                       syl_actions = g_list_append (syl_actions, act);
+               } 
+
+               gtk_combo_set_popdown_strings (GTK_COMBO (mtoolbar.combo_syl_action), syl_actions);
+               gtk_combo_set_value_in_list (GTK_COMBO (mtoolbar.combo_syl_action), 0, FALSE);
+               gtk_entry_set_text (GTK_ENTRY (mtoolbar.combo_syl_entry), syl_actions->data);
+               prefs_toolbar_selection_changed(GTK_LIST(mtoolbar.combo_syl_list), NULL);
+               g_list_free (syl_actions);
+       }
+
+       for (i = 0; i < N_STOCK_PIXMAPS; i++) {
+               avail[0] = g_strdup ("");
+               avail[1] = g_strdup (stock_pixmap_get_name ((StockPixmap)i));
+
+               stock_pixmap_gdk (mtoolbar.clist_icons, i,
+                                 &xpm, &xpmmask);
+               gtk_clist_append (clist_icons, avail);
+               gtk_clist_set_pixmap (clist_icons, 
+                                      i + 1, 0, xpm, xpmmask);
+               
+               g_free (avail[0]);
+               g_free (avail[1]);
+       }
+
+       /* set currently active toolbar entries */
+       for (cur = toolbar_list; cur != NULL; cur = cur->next) {
+               ToolbarItem *item = (ToolbarItem*) cur->data;
+       
+               if (g_strcasecmp (item->file, SEPARATOR) != 0) {
+                       gint row_num;
+                       StockPixmap icon = stock_pixmap_get_icon (item->file);
+                       
+                       stock_pixmap_gdk (mtoolbar.clist_set, icon,
+                                         &xpm, &xpmmask);
+                       activ[0] = g_strdup ("");
+                       activ[1] = g_strdup (item->file);
+                       activ[2] = g_strdup (item->text);
+                       activ[3] = g_strdup (toolbar_ret_descr_from_val (item->action));
+                       row_num  = gtk_clist_append (clist_set, activ);
+                       gtk_clist_set_pixmap (clist_set, 
+                                             row_num, 0, xpm, xpmmask);
+
+               } else {
+                       activ[0] = g_strdup (SEPARATOR_PIXMAP);
+                       activ[1] = g_strdup (item->file);
+                       activ[2] = g_strdup ("");
+                       activ[3] = g_strdup ("");
+                       gtk_clist_append (clist_set, activ);
+               }
+
+               g_free (activ[0]);
+               g_free (activ[1]);
+               g_free (activ[2]);
+               g_free (activ[3]);
+       }
+
+       gtk_clist_thaw(clist_icons);
+       gtk_clist_thaw(clist_set);
+
+       gtk_clist_columns_autosize(clist_icons);
+       gtk_clist_columns_autosize(clist_set);
+
+       gtk_clist_set_row_height(clist_icons, CELL_SPACING);
+       gtk_clist_set_row_height(clist_set, CELL_SPACING);
+
+       gtk_clist_select_row(clist_icons, 0, 0);
+       gtk_clist_select_row(clist_set, 0, 0);
+
+       toolbar_clear_list();
+}
+
+static gboolean is_duplicate(gchar *chosen_action)
+{
+       GtkCList *clist = GTK_CLIST(mtoolbar.clist_set);
+       gchar *entry;
+       gint row = 0;
+       gchar *syl_act = toolbar_ret_descr_from_val (A_SYL_ACTIONS);
+
+       g_return_val_if_fail (chosen_action != NULL, TRUE);
+       if (clist->rows == 0) 
+               return FALSE;
+       
+       /* allow duplicate entries (A_SYL_ACTIONS) */
+       if (g_strcasecmp(syl_act, chosen_action) == 0)
+               return FALSE;
+
+       do {
+               gtk_clist_get_text (clist, row, 3, &entry);
+               if ( g_strcasecmp (chosen_action, entry) == 0)
+                       return TRUE;
+               row++;
+       } while ((gtk_clist_get_text(clist, row, 3, &entry)) && (row <= clist->rows));
+       
+       return FALSE;
+}
+
+static void prefs_toolbar_save(void)
+{
+       gint row = 0;
+       GtkCList *clist = GTK_CLIST(mtoolbar.clist_set);
+       gchar *entry = NULL;
+       
+       toolbar_clear_list();
+
+       if (clist->rows == 0) {
+               toolbar_set_default_toolbar();
+       }
+       else {
+               do {
+                       ToolbarItem *toolbar_item = g_new0 (ToolbarItem, 1);
+                       
+                       gtk_clist_get_text (clist, row, 1, &entry);
+                       toolbar_item->file = g_strdup (entry);
+                       
+                       gtk_clist_get_text (clist, row, 2, &entry);
+                       toolbar_item->text = g_strdup (entry);
+                       
+                       gtk_clist_get_text (clist, row, 3, &entry);     
+                       toolbar_item->action = toolbar_ret_val_from_descr (entry);
+                       
+                       /* TODO: save A_SYL_ACTIONS only if they are still active */
+
+                       toolbar_list = g_slist_append (toolbar_list, toolbar_item);
+                       row++;
+                       
+               } while (gtk_clist_get_text (clist, row, 3, &entry));
+       }
+       
+       toolbar_save_config_file ();
+       
+       main_window_reflect_prefs_all_real(TRUE);
+}
+
+static void prefs_toolbar_ok(void)
+{
+       prefs_toolbar_save();
+       prefs_toolbar_close();
+}
+
+static void prefs_toolbar_cancel(void)
+{
+       prefs_toolbar_close();
+}
+
+static void get_action_name(gchar *entry, gchar **menu)
+{
+       gchar *act, *act_p;
+
+       if (prefs_common.actions_list != NULL) {
+               
+               act = g_strdup (entry);
+               act_p = strstr(act, ": ");
+               if (act_p != NULL)
+                       act_p[0] = 0x00;
+               /* freed by calling func */
+               *menu = act;
+       }
+}
+
+static gint prefs_toolbar_register(void)
+{
+       GtkCList *clist_set   = GTK_CLIST(mtoolbar.clist_set);
+       GtkCList *clist_icons = GTK_CLIST(mtoolbar.clist_icons);
+       gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
+       gint row_icons = 0;
+       gint row_set = 0;
+       GdkPixmap *xpm;
+       GdkBitmap *xpmmask;
+       gchar *item[5];
+
+       if (clist_icons->rows == 0) return -1; 
+
+       if (clist_icons->selection)
+               if (clist_icons->selection->data) 
+                       row_icons = GPOINTER_TO_INT(clist_icons->selection->data);
+       
+       gtk_clist_get_text (clist_icons, row_icons, 1, &item[1]);
+       item[3] = g_strdup (gtk_entry_get_text (GTK_ENTRY (mtoolbar.combo_entry)));
+       
+       /* SEPARATOR or other ? */
+       if (g_strcasecmp (item[1], SEPARATOR) == 0) {
+               item[0] = g_strdup (SEPARATOR_PIXMAP);
+               item[2] = g_strdup ("");
+               item[3] = g_strdup ("");
+               
+               row_set = gtk_clist_append (GTK_CLIST (mtoolbar.clist_set), item);
+       
+       } else {
+
+               if (is_duplicate (item[3])) {
+                       alertpanel_error(ERROR_MSG);
+                       g_free (item[3]);
+                       return -1;
+               }
+
+               stock_pixmap_gdk (mtoolbar.clist_set, stock_pixmap_get_icon (item[1]),
+                                 &xpm, &xpmmask);
+
+               if (g_strcasecmp (item[3], syl_act) == 0) {
+
+                       gchar *entry = gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_syl_entry));
+                       get_action_name(entry, &item[2]);
+               }
+               else {
+                       item[2] = g_strdup (gtk_entry_get_text (GTK_ENTRY (mtoolbar.entry_icon_text)));
+               }
+
+               row_set = gtk_clist_append (GTK_CLIST (mtoolbar.clist_set), item);
+               gtk_clist_set_pixmap (clist_set, row_set, 0, xpm, xpmmask);
+       }
+
+       gtk_clist_moveto(clist_set, row_set, 0, row_set/clist_set->rows, 0);
+       gtk_clist_select_row (clist_set, row_set, 0);
+
+       g_free (item[0]);
+       g_free (item[2]);
+       g_free (item[3]);
+
+       return 0;
+}
+
+static gint prefs_toolbar_substitute(void)
+{
+       GtkCList *clist_set   = GTK_CLIST(mtoolbar.clist_set);
+       GtkCList *clist_icons = GTK_CLIST(mtoolbar.clist_icons);
+       gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
+       gint row_icons = 0;
+       gint row_set = 0;
+       GdkPixmap *xpm;
+       GdkBitmap *xpmmask;
+       gchar *item[5];
+       gchar *ac_set;
+
+       /* no rows or nothing selected */
+       if ((clist_set->rows == 0) || (clist_set->selection == 0)) return -1; 
+
+       if (clist_icons->selection)
+               if (clist_icons->selection->data) 
+                       row_icons = GPOINTER_TO_INT(clist_icons->selection->data);
+
+       if (clist_set->selection)
+               if (clist_set->selection->data) 
+                       row_set = GPOINTER_TO_INT(clist_set->selection->data);
+
+       gtk_clist_get_text (clist_icons, row_icons, 1, &item[1]);
+       gtk_clist_get_text (clist_set, row_set, 3, &ac_set);
+       item[3] = g_strdup (gtk_entry_get_text (GTK_ENTRY (mtoolbar.combo_entry)));
+
+       if (g_strcasecmp (item[1], SEPARATOR) == 0) {
+               item[0] = g_strdup (SEPARATOR_PIXMAP);
+               item[2] = g_strdup ("");
+               item[3] = g_strdup ("");
+
+               gtk_clist_remove (clist_set, row_set);
+               row_set = gtk_clist_insert (clist_set, row_set, item);
+       } else {
+
+               if ((is_duplicate(item[3])) && (g_strcasecmp(item[3], ac_set) != 0)){
+                       alertpanel_error(ERROR_MSG);
+                       g_free (item[3]);
+                       return -1;
+               }
+
+               stock_pixmap_gdk (mtoolbar.clist_set, stock_pixmap_get_icon (item[1]),
+                                 &xpm, &xpmmask);
+
+               if (g_strcasecmp (item[3], syl_act) == 0) {
+
+                       gchar *entry = gtk_entry_get_text(GTK_ENTRY(mtoolbar.combo_syl_entry));
+                       get_action_name(entry, &item[2]);
+               } else {
+                       item[2] = g_strdup (gtk_entry_get_text (GTK_ENTRY (mtoolbar.entry_icon_text)));
+               }
+
+               gtk_clist_remove (clist_set, row_set);
+               row_set = gtk_clist_insert (clist_set, row_set, item);
+               gtk_clist_set_pixmap (clist_set, row_set, 0, xpm, xpmmask);
+       }
+       
+
+       
+       gtk_clist_moveto(clist_set, row_set, 0, row_set/clist_set->rows, 0);
+       gtk_clist_select_row (clist_set, row_set, 0);
+
+       g_free (item[0]);
+       g_free (item[2]);
+       g_free (item[3]);
+       
+       return 0;
+}
+
+static gint prefs_toolbar_delete(void)
+{
+       GtkCList *clist_set   = GTK_CLIST(mtoolbar.clist_set);
+       gint row_set = 0;
+
+       if (clist_set->rows == 0) return -1; 
+       if (clist_set->selection)
+               if (clist_set->selection->data) 
+                       row_set = GPOINTER_TO_INT(clist_set->selection->data);
+
+       if (clist_set->row_list != NULL) {
+                       
+               row_set = GPOINTER_TO_INT(clist_set->selection->data);
+               gtk_clist_remove (clist_set, row_set);
+               gtk_clist_columns_autosize (clist_set);
+               
+               if (clist_set->rows > 0)
+                       gtk_clist_select_row (clist_set, (row_set == 0) ? 0:row_set - 1, 0);
+       }
+
+       return 0;
+}
+
+static void prefs_toolbar_up(void)
+{
+       GtkCList *clist = GTK_CLIST(mtoolbar.clist_set);
+       gint row = 0;
+
+       if (!clist->selection) return;
+       if (clist->selection->data)
+               row = GPOINTER_TO_INT(clist->selection->data);
+
+       if (row >= 0) {
+               gtk_clist_row_move(clist, row, row - 1);
+               if(gtk_clist_row_is_visible(clist, row - 1) != GTK_VISIBILITY_FULL) {
+                       gtk_clist_moveto(clist, row - 1, 0, 0, 0);
+               } 
+       }
+}
+
+static void prefs_toolbar_down(void)
+{
+       GtkCList *clist = GTK_CLIST(mtoolbar.clist_set);
+       gint row = 0;
+
+       if (!clist->selection) return;
+       if (clist->selection->data)
+               row = GPOINTER_TO_INT(clist->selection->data);
+
+       if (row >= 0 && row < clist->rows - 1) {
+               gtk_clist_row_move(clist, row, row + 1);
+               if(gtk_clist_row_is_visible(clist, row + 1) != GTK_VISIBILITY_FULL) {
+                       gtk_clist_moveto(clist, row + 1, 0, 1, 0);
+               } 
+       }
+}
+
+static void prefs_toolbar_select_row_set(GtkCList *clist, gint row, gint column,
+                                        GdkEvent *event, gpointer user_data)
+{
+       GtkCList *clist_ico = GTK_CLIST (mtoolbar.clist_icons);
+       gchar *syl_act = toolbar_ret_descr_from_val(A_SYL_ACTIONS);
+       gint row_set = 0;
+       gint row_ico = 0;
+       gchar *file, *icon_text, *descr, *entry;
+
+       if (clist->selection->data) 
+               row_set = GPOINTER_TO_INT(clist->selection->data);      
+
+       gtk_clist_get_text (clist, row_set, 1, &file);
+       gtk_clist_get_text (clist, row_set, 2, &icon_text);
+       gtk_clist_get_text (clist, row_set, 3, &descr);
+
+       if (g_strcasecmp (descr, syl_act) != 0)
+               gtk_entry_set_text (GTK_ENTRY (mtoolbar.entry_icon_text), icon_text);
+
+       gtk_list_select_item (GTK_LIST (mtoolbar.combo_list), 
+                             toolbar_ret_val_from_descr (descr));
+       do {
+               gtk_clist_get_text (clist_ico, row_ico, 1, &entry);
+               row_ico++;
+       } while (g_strcasecmp (entry, file) != 0);
+       
+       gtk_clist_select_row (clist_ico, row_ico - 1, 0);
+       gtk_clist_moveto(clist_ico, row_ico - 1, 0, row_ico/clist_ico->rows, 0);
+}
+
+static void prefs_toolbar_select_row_icons(GtkCList *clist, gint row, gint column,
+                                          GdkEvent *event, gpointer user_data)
+{
+       GtkCList *clist_icons = GTK_CLIST(mtoolbar.clist_icons);
+       gchar *text;
+       
+       gtk_clist_get_text (clist_icons, row, 1, &text);
+
+       if (!text) 
+               return;
+
+       if (g_strcasecmp (SEPARATOR, text) == 0) {
+               gtk_widget_set_sensitive (mtoolbar.combo_action,     FALSE);
+               gtk_widget_set_sensitive (mtoolbar.entry_icon_text,  FALSE);
+               gtk_widget_set_sensitive (mtoolbar.combo_syl_action, FALSE);
+       } else {
+               gtk_widget_set_sensitive (mtoolbar.combo_action,     TRUE);
+               gtk_widget_set_sensitive (mtoolbar.entry_icon_text,  TRUE);
+               gtk_widget_set_sensitive (mtoolbar.combo_syl_action, TRUE);
+       }
+}
+
+static void prefs_toolbar_selection_changed(GtkList *list,
+                                           gpointer user_data)
+{
+
+       gchar *cur_entry = g_strdup (gtk_entry_get_text (GTK_ENTRY (mtoolbar.combo_entry)));
+       gchar *actions_entry = toolbar_ret_descr_from_val (A_SYL_ACTIONS);
+
+       gtk_widget_set_sensitive (mtoolbar.combo_syl_action, TRUE);
+
+       if (g_strcasecmp (cur_entry, actions_entry) == 0) {
+               gtk_widget_hide (mtoolbar.entry_icon_text);
+               gtk_widget_show (mtoolbar.combo_syl_action);
+               gtk_label_set_text (GTK_LABEL(mtoolbar.label_icon_text), _("select Sylpheed Action"));
+
+               if (prefs_common.actions_list == NULL) {
+                   gtk_widget_set_sensitive (mtoolbar.combo_syl_action, FALSE);
+               }
+                   
+       } else {
+               gtk_widget_hide (mtoolbar.combo_syl_action);
+               gtk_widget_show (mtoolbar.entry_icon_text);
+               gtk_label_set_text (GTK_LABEL(mtoolbar.label_icon_text), _("enter Toolbar Text (shown below Pixmap)"));
+       }
+}
+
+static gint prefs_toolbar_key_pressed(GtkWidget *widget,
+                          GdkEventKey *event,
+                          gpointer data)
+{
+       if (event && event->keyval == GDK_Escape) {
+               prefs_toolbar_cancel();
+               return TRUE;
+       }
+       return FALSE;
+}
+
+static void prefs_toolbar_create(void)
+{
+       GtkWidget *window;
+       GtkWidget *main_vbox;
+       GtkWidget *top_hbox;
+       GtkWidget *compose_frame;
+       GtkWidget *reg_hbox;
+       GtkWidget *arrow;
+       GtkWidget *btn_hbox;
+       GtkWidget *reg_btn;
+       GtkWidget *subst_btn;
+       GtkWidget *del_btn;
+       GtkWidget *vbox_frame;
+       GtkWidget *scrolledwindow_clist_icon;
+       GtkWidget *clist_icons;
+       GtkWidget *hbox_icon_text;
+       GtkWidget *label_icon_text;
+       GtkWidget *entry_icon_text;
+       GtkWidget *hbox_action;
+       GtkWidget *label_action_sel;
+       GtkWidget *combo_action;
+       GtkWidget *combo_entry;
+       GtkWidget *combo_list;
+       GtkWidget *combo_syl_action;
+       GtkWidget *combo_syl_entry;
+       GtkWidget *combo_syl_list;
+       GtkWidget *frame_toolbar_items;
+       GtkWidget *hbox_bottom;
+       GtkWidget *scrolledwindow_clist_set;
+       GtkWidget *clist_set;
+       GtkWidget *label_icon;
+       GtkWidget *label_file;
+       GtkWidget *label_text;
+       GtkWidget *label_action;
+       GtkWidget *toolbar;
+       GtkWidget *up_btn;
+       GtkWidget *down_btn;
+       GtkWidget *icon_wid;
+
+       GtkWidget *confirm_area;
+       GtkWidget *ok_btn;
+       GtkWidget *cancel_btn;
+
+       window = gtk_window_new (GTK_WINDOW_DIALOG);
+       gtk_window_set_title (GTK_WINDOW (window), _("Customize Toolbar"));
+       //gtk_widget_set_usize (window, 400, 500);
+       gtk_widget_realize (window);
+
+       main_vbox = gtk_vbox_new (FALSE, 0);
+
+       gtk_container_add (GTK_CONTAINER (window), main_vbox);
+       
+       gtkut_button_set_create(&confirm_area, &ok_btn, _("OK"),
+                               &cancel_btn, _("Cancel"), NULL, NULL);
+       gtk_box_pack_end (GTK_BOX(main_vbox), confirm_area, FALSE, FALSE, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (confirm_area), 5);
+       gtk_widget_grab_default (ok_btn);
+
+       top_hbox = gtk_hbox_new (FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (main_vbox), top_hbox, TRUE, TRUE, 0);
+  
+       compose_frame = gtk_frame_new (_("compose Toolbar Item"));
+       gtk_box_pack_start (GTK_BOX (top_hbox), compose_frame, TRUE, TRUE, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (compose_frame), 5);
+
+       vbox_frame = gtk_vbox_new (FALSE, 0);
+       gtk_container_add (GTK_CONTAINER (compose_frame), vbox_frame);
+       
+       /* available icons */
+       scrolledwindow_clist_icon = gtk_scrolled_window_new (NULL, NULL);
+       gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow_clist_icon), 5);
+       gtk_container_add (GTK_CONTAINER (vbox_frame), scrolledwindow_clist_icon);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_clist_icon), 
+                                       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+       
+       clist_icons = gtk_clist_new (2);
+       gtk_container_add (GTK_CONTAINER (scrolledwindow_clist_icon), clist_icons);
+       gtk_container_set_border_width (GTK_CONTAINER (clist_icons), 1);
+       gtk_clist_set_column_width (GTK_CLIST (clist_icons), 0, 35);
+       gtk_clist_set_column_width (GTK_CLIST (clist_icons), 1, 200);
+       gtk_clist_column_titles_hide (GTK_CLIST (clist_icons));
+       gtk_widget_set_usize (clist_icons, 300, 150);
+       
+       /* icon description */
+       hbox_icon_text = gtk_hbox_new (TRUE, 5);
+       gtk_container_add (GTK_CONTAINER (vbox_frame), hbox_icon_text);
+       gtk_container_set_border_width (GTK_CONTAINER (hbox_icon_text), 5);
+       
+       label_icon_text = gtk_label_new ("");
+       gtk_box_pack_start (GTK_BOX (hbox_icon_text), label_icon_text, FALSE, FALSE, 5);
+       
+       entry_icon_text = gtk_entry_new ();
+       gtk_box_pack_start (GTK_BOX (hbox_icon_text), entry_icon_text, FALSE, FALSE, 0);
+
+       /* Sylpheed Action Combo Box */ 
+       combo_syl_action = gtk_combo_new ();
+       gtk_box_pack_start (GTK_BOX (hbox_icon_text), combo_syl_action, TRUE, TRUE, 0);
+
+       combo_syl_list = GTK_COMBO (combo_syl_action)->list;
+       combo_syl_entry = GTK_COMBO (combo_syl_action)->entry;
+       gtk_entry_set_editable (GTK_ENTRY (combo_syl_entry), FALSE);
+
+       /* available actions */
+       hbox_action = gtk_hbox_new (TRUE, 5);
+       gtk_container_add (GTK_CONTAINER (vbox_frame), hbox_action);
+       gtk_container_set_border_width (GTK_CONTAINER (hbox_action), 5);
+       
+       label_action_sel = gtk_label_new (_("select Action executed on click"));
+       gtk_box_pack_start (GTK_BOX (hbox_action), label_action_sel, FALSE, FALSE, 0);
+       gtk_label_set_justify (GTK_LABEL (label_action_sel), GTK_JUSTIFY_RIGHT);
+       
+       combo_action = gtk_combo_new ();
+       gtk_box_pack_start (GTK_BOX (hbox_action), combo_action, TRUE, TRUE, 0);
+       
+       combo_list = GTK_COMBO (combo_action)->list;
+       combo_entry = GTK_COMBO (combo_action)->entry;
+       gtk_entry_set_editable (GTK_ENTRY (combo_entry), FALSE);
+       
+       /* register / substitute / delete */
+       reg_hbox = gtk_hbox_new (FALSE, 4);
+       gtk_box_pack_start (GTK_BOX (main_vbox), reg_hbox, FALSE, FALSE, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (reg_hbox), 10);
+
+       arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
+       gtk_box_pack_start (GTK_BOX (reg_hbox), arrow, FALSE, FALSE, 0);
+       gtk_widget_set_usize (arrow, -1, 16);
+
+       btn_hbox = gtk_hbox_new (TRUE, 4);
+       gtk_box_pack_start (GTK_BOX (reg_hbox), btn_hbox, FALSE, FALSE, 0);
+
+       reg_btn = gtk_button_new_with_label (_("Register"));
+       gtk_box_pack_start (GTK_BOX (btn_hbox), reg_btn, FALSE, TRUE, 0);
+       gtk_signal_connect (GTK_OBJECT (reg_btn), "clicked",
+                           GTK_SIGNAL_FUNC (prefs_toolbar_register), 
+                           NULL);
+
+       subst_btn = gtk_button_new_with_label (_(" Substitute "));
+       gtk_box_pack_start (GTK_BOX (btn_hbox), subst_btn, FALSE, TRUE, 0);
+       gtk_signal_connect (GTK_OBJECT (subst_btn), "clicked",
+                           GTK_SIGNAL_FUNC (prefs_toolbar_substitute),
+                           NULL);
+
+       del_btn = gtk_button_new_with_label (_("Delete"));
+       gtk_box_pack_start (GTK_BOX (btn_hbox), del_btn, FALSE, TRUE, 0);
+       gtk_signal_connect (GTK_OBJECT (del_btn), "clicked",
+                           GTK_SIGNAL_FUNC (prefs_toolbar_delete), 
+                           NULL);
+
+       /* currently active toolbar items */
+       frame_toolbar_items = gtk_frame_new (_("set ToolbarItems"));
+       gtk_box_pack_start (GTK_BOX (main_vbox), frame_toolbar_items, TRUE, TRUE, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (frame_toolbar_items), 5);
+       
+       hbox_bottom = gtk_hbox_new (FALSE, 0);
+       gtk_container_add (GTK_CONTAINER (frame_toolbar_items), hbox_bottom);
+       
+       scrolledwindow_clist_set = gtk_scrolled_window_new (NULL, NULL);
+       gtk_box_pack_start (GTK_BOX (hbox_bottom), scrolledwindow_clist_set, TRUE, TRUE, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (scrolledwindow_clist_set), 5);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow_clist_icon), 
+                                       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+       
+       clist_set = gtk_clist_new (4);
+       gtk_container_add (GTK_CONTAINER (scrolledwindow_clist_set), clist_set);
+       gtk_clist_set_column_width (GTK_CLIST (clist_set), 0, 80);
+       gtk_clist_set_column_width (GTK_CLIST (clist_set), 1, 80);
+       gtk_clist_set_column_width (GTK_CLIST (clist_set), 2, 80);
+       gtk_clist_set_column_width (GTK_CLIST (clist_set), 3, 80);
+       gtk_clist_column_titles_show (GTK_CLIST (clist_set));
+       gtk_widget_set_usize (clist_set, 300, 200);
+
+       label_icon = gtk_label_new (_("Toolbar Icon"));
+       gtk_clist_set_column_widget (GTK_CLIST (clist_set), 0, label_icon);
+       
+       label_file = gtk_label_new (_("File Name"));
+       gtk_clist_set_column_widget (GTK_CLIST (clist_set), 1, label_file);
+
+       label_text = gtk_label_new (_("Icon Text"));
+       gtk_clist_set_column_widget (GTK_CLIST (clist_set), 2, label_text);
+
+       label_action = gtk_label_new (_("Mapped Action"));
+       gtk_clist_set_column_widget (GTK_CLIST (clist_set), 3, label_action);
+       
+       toolbar = gtk_toolbar_new (GTK_ORIENTATION_VERTICAL, GTK_TOOLBAR_BOTH);
+       gtk_box_pack_start (GTK_BOX (hbox_bottom), toolbar, FALSE, FALSE, 0);
+       gtk_container_set_border_width (GTK_CONTAINER (toolbar), 5);
+
+       icon_wid = stock_pixmap_widget(hbox_bottom, STOCK_PIXMAP_UP_ARROW);
+       up_btn = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar),
+                                            GTK_TOOLBAR_CHILD_BUTTON,
+                                            NULL,
+                                            NULL,
+                                            _("Up"), NULL,
+                                            icon_wid, NULL, NULL);
+
+       icon_wid = stock_pixmap_widget(hbox_bottom, STOCK_PIXMAP_DOWN_ARROW);
+       down_btn = gtk_toolbar_append_element (GTK_TOOLBAR (toolbar),
+                                              GTK_TOOLBAR_CHILD_BUTTON,
+                                              NULL,
+                                              NULL,
+                                              _("Down"), NULL,
+                                              icon_wid, NULL, NULL);
+
+       gtk_signal_connect(GTK_OBJECT (window), "delete_event",
+                          GTK_SIGNAL_FUNC (prefs_toolbar_cancel),
+                          NULL);
+       gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
+                          GTK_SIGNAL_FUNC(prefs_toolbar_key_pressed),
+                          NULL);
+       MANAGE_WINDOW_SIGNALS_CONNECT(window);  
+
+       gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
+                          GTK_SIGNAL_FUNC(prefs_toolbar_ok), 
+                          NULL);
+       gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
+                          GTK_SIGNAL_FUNC(prefs_toolbar_cancel), 
+                          NULL);
+       gtk_signal_connect(GTK_OBJECT (clist_set), "select_row",
+                          GTK_SIGNAL_FUNC (prefs_toolbar_select_row_set),
+                          NULL);
+       gtk_signal_connect(GTK_OBJECT (clist_icons), "select_row",
+                          GTK_SIGNAL_FUNC (prefs_toolbar_select_row_icons),
+                          NULL);
+       gtk_signal_connect(GTK_OBJECT (down_btn), "clicked",
+                          GTK_SIGNAL_FUNC (prefs_toolbar_down),
+                          NULL);
+       gtk_signal_connect(GTK_OBJECT (up_btn), "clicked",
+                          GTK_SIGNAL_FUNC (prefs_toolbar_up),
+                          NULL);
+       gtk_signal_connect(GTK_OBJECT(combo_list), "selection-changed",
+                          GTK_SIGNAL_FUNC(prefs_toolbar_selection_changed),
+                          NULL);
+       
+       mtoolbar.window           = window;
+       mtoolbar.clist_icons      = clist_icons;
+       mtoolbar.clist_set        = clist_set;
+       mtoolbar.combo_action     = combo_action;
+       mtoolbar.combo_entry      = combo_entry;
+       mtoolbar.combo_list       = combo_list;
+       mtoolbar.entry_icon_text  = entry_icon_text;
+       mtoolbar.combo_syl_action = combo_syl_action;
+       mtoolbar.combo_syl_list   = combo_syl_list;
+       mtoolbar.combo_syl_entry  = combo_syl_entry;
+
+       mtoolbar.label_icon_text  = label_icon_text;
+
+       gtk_widget_show_all (window);
+}
diff --git a/src/prefs_toolbar.h b/src/prefs_toolbar.h
new file mode 100644 (file)
index 0000000..5de97cc
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PREFS_CUSTOM_TOOLBAR_H__
+#define __PREFS_CUSTOM_TOOLBAR_H__
+
+void prefs_toolbar(void);
+
+#endif /* __PREFS_CUSTOM_TOOLBAR_H__ */ 
diff --git a/src/toolbar.c b/src/toolbar.c
new file mode 100644 (file)
index 0000000..c1be622
--- /dev/null
@@ -0,0 +1,974 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2001 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * General functions for accessing address book files.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include "defs.h"
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <math.h>
+#include <setjmp.h>
+
+#include "intl.h"
+#include "utils.h"
+#include "xml.h"
+#include "mgutils.h"
+#include "prefs.h"
+#include "codeconv.h"
+#include "stock_pixmap.h"
+#include "mainwindow.h"
+#include "prefs_common.h"
+#include "menu.h"
+#include "prefs_actions.h"
+#include "manage_window.h"
+
+#include "toolbar.h"
+#include "prefs_toolbar.h"
+
+/* elements */
+#define TOOLBAR_TAG_INDEX        "toolbar"
+#define TOOLBAR_TAG_ITEM         "item"
+#define TOOLBAR_TAG_SEPARATOR    SEPARATOR
+
+jmp_buf    jumper;
+
+GSList *toolbar_list;
+
+MainWindow *mwin;
+
+#define TOOLBAR_ICON_FILE   "file"    
+#define TOOLBAR_ICON_TEXT   "text"     
+#define TOOLBAR_ICON_ACTION "action"    
+
+gboolean      toolbar_is_duplicate           (gint action);
+static void   toolbar_parse_item             (XMLFile *file);
+static gint   toolbar_ret_val_from_text      (gchar *text);
+
+
+/* callback functions */
+static void toolbar_inc_cb                     (GtkWidget      *widget,
+                                       gpointer                 data);
+
+static void toolbar_inc_all_cb         (GtkWidget      *widget,
+                                       gpointer                 data);
+
+static void toolbar_send_cb            (GtkWidget      *widget,
+                                       gpointer                 data);
+
+static void toolbar_compose_news_cb            (GtkWidget      *widget,
+                                       gpointer                 data);
+
+static void toolbar_compose_mail_cb            (GtkWidget      *widget,
+                                       gpointer                 data);
+
+static void toolbar_reply_cb           (GtkWidget      *widget,
+                                       gpointer                 data);
+
+static void toolbar_reply_to_all_cb            (GtkWidget      *widget,
+                                       gpointer                 data);
+
+static void toolbar_reply_to_sender_cb       (GtkWidget        *widget,
+                                       gpointer                 data);
+
+static void toolbar_forward_cb         (GtkWidget      *widget,
+                                       gpointer                  data);
+
+static void toolbar_delete_cb          (GtkWidget      *widget,
+                                       gpointer                 data);
+
+static void toolbar_exec_cb            (GtkWidget      *widget,
+                                       gpointer                 data);
+
+static void toolbar_next_unread_cb     (GtkWidget      *widget,
+                                gpointer        data);
+
+static void toolbar_actions_execute_cb       (GtkWidget        *widget,
+                                        gpointer        data);
+
+static void toolbar_reply_popup_cb     (GtkWidget      *widget,
+                                        GdkEventButton *event,
+                                        gpointer        data);
+static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell,
+                                        gpointer        data);
+
+static void toolbar_reply_to_all_popup_cb(GtkWidget    *widget,
+                                        GdkEventButton *event,
+                                        gpointer        data);
+
+static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell  *menu_shell,
+                                        gpointer        data);
+
+static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget,
+                                        GdkEventButton *event,
+                                        gpointer        data);
+static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell       *menu_shell,
+                                        gpointer        data);
+
+static void toolbar_forward_popup_cb    (GtkWidget      *widget,
+                                        GdkEventButton    *event,
+                                        gpointer        data);
+
+static void toolbar_forward_popup_closed_cb   (GtkMenuShell    *menu_shell,
+                                        gpointer        data);
+
+static ToolbarAction t_action[] = 
+{
+       { "A_RECEIVE_ALL",   N_("Receive Mail on all Accounts"),    toolbar_inc_all_cb               },
+       { "A_RECEIVE_CUR",   N_("Receive Mail on current Account"), toolbar_inc_cb                   },
+       { "A_SEND_QUEUD",    N_("Send Queud Message(s)"),           toolbar_send_cb                  },
+       { "A_COMPOSE_EMAIL", N_("Compose Email"),                   toolbar_compose_mail_cb          },
+       { "A_REPLY_MESSAGE", N_("Reply to Message"),                toolbar_reply_cb                 },
+       { "A_REPLY_SENDER",  N_("Reply to Sender"),                 toolbar_reply_to_sender_cb       },
+       { "A_REPLY_ALL",     N_("Reply to All"),                    toolbar_reply_to_all_cb          },
+       { "A_FORWARD",       N_("Forward Message"),                 toolbar_forward_cb               },
+       { "A_DELETE",        N_("Delete Message"),                  toolbar_delete_cb                },
+       { "A_EXECUTE",       N_("Execute"),                         toolbar_exec_cb                  },
+       { "A_GOTO_NEXT",     N_("Goto Next Message"),               toolbar_next_unread_cb           },
+       { "A_SYL_ACTIONS",   N_("Sylpheed Actions Feature"),        toolbar_actions_execute_cb       },
+
+       { "A_COMPOSE_NEWS",  N_("Compose News"),                    toolbar_compose_news_cb          },    
+       { "A_SEPARATOR",     SEPARATOR,                             NULL                             },
+};
+
+static GtkItemFactoryEntry reply_popup_entries[] =
+{
+       {N_("/Reply with _quote"), NULL, reply_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
+       {N_("/_Reply without quote"), NULL, reply_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
+};
+static GtkItemFactoryEntry replyall_popup_entries[] =
+{
+       {N_("/Reply to all with _quote"), "<shift>A", reply_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
+       {N_("/_Reply to all without quote"), "a", reply_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
+};
+static GtkItemFactoryEntry replysender_popup_entries[] =
+{
+       {N_("/Reply to sender with _quote"), NULL, reply_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
+       {N_("/_Reply to sender without quote"), NULL, reply_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
+};
+static GtkItemFactoryEntry fwd_popup_entries[] =
+{
+       {N_("/_Forward message (inline style)"), "f", reply_cb, COMPOSE_FORWARD_INLINE, NULL},
+       {N_("/Forward message as _attachment"), "<shift>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
+};
+
+
+void toolbar_actions_cb(GtkWidget *widget, ToolbarItem *toolbar_item)
+{
+       if (toolbar_item->action < sizeof (t_action) / sizeof (t_action[0]))
+               t_action[toolbar_item->action].func(widget, mwin);
+}
+
+gint toolbar_ret_val_from_descr(gchar *descr)
+{
+       gint i;
+       
+       for (i = 0; i < sizeof (t_action) / sizeof (t_action[0]); i++) {
+               if (g_strcasecmp (t_action[i].descr, descr) == 0)
+                               return i;
+       }
+       
+       return -1;
+}
+
+gchar *toolbar_ret_descr_from_val(gint val)
+{
+       g_return_val_if_fail (val >=0 && val <= sizeof(t_action) / sizeof(t_action[0]), NULL);
+
+       return t_action[val].descr;
+
+}
+
+static gint toolbar_ret_val_from_text(gchar *text)
+{
+       gint i;
+       
+       for (i = 0; i < sizeof (t_action) / sizeof (t_action[0]); i++) {
+               if (g_strcasecmp (t_action[i].action_text, text) == 0)
+                               return i;
+       }
+       
+       return -1;
+}
+
+gchar *toolbar_ret_text_from_val(gint val)
+{
+       g_return_val_if_fail (val >=0 && val <= sizeof(t_action) / sizeof(t_action[0]), NULL);
+
+       return t_action[val].action_text;
+}
+
+gboolean toolbar_is_duplicate(gint action)
+{
+       GSList *cur;
+
+       if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS)) 
+               return FALSE;
+
+       for (cur = toolbar_list; cur != NULL; cur = cur->next) {
+               ToolbarItem *item = (ToolbarItem*) cur->data;
+               
+               if (item->action == action)
+                       return TRUE;
+       }
+       return FALSE;
+}
+
+GList *toolbar_get_action_items(void)
+{
+       GList *items = NULL;
+       gint i;
+       
+       for (i = 0; i < N_ACTION_VAL; i++) {
+               items = g_list_append (items, t_action[i].descr);
+       }
+
+       return items;
+}
+
+static void toolbar_parse_item(XMLFile *file)
+{
+       GList *attr;
+       gchar *name, *value;
+       ToolbarItem *item = NULL;
+
+       attr = xml_get_current_tag_attr(file);
+       item = g_new0 (ToolbarItem, 1);
+       while( attr ) {
+               name = ((XMLAttr *)attr->data)->name;
+               value = ((XMLAttr *)attr->data)->value;
+               
+               if (strcmp (name, TOOLBAR_ICON_FILE) == 0) 
+                       item->file = g_strdup (value);
+               else if (strcmp (name, TOOLBAR_ICON_TEXT) == 0)
+                       item->text = g_strdup (value);
+               else if (strcmp (name, TOOLBAR_ICON_ACTION) == 0)
+                       item->action = toolbar_ret_val_from_text(value);
+
+               attr = g_list_next (attr);
+       }
+       if (item->action != -1) {
+               
+               if ( !toolbar_is_duplicate(item->action)) 
+                       toolbar_list = g_slist_append (toolbar_list, item);
+       }
+}
+
+void toolbar_set_default_toolbar(void)
+{
+       gint i;
+       /* create default toolbar */
+       struct _default_toolbar {
+               gint action;
+               gint icon;
+               gchar *text;
+       } default_toolbar[] = {
+               { A_RECEIVE_CUR,   STOCK_PIXMAP_MAIL_RECEIVE,         _("Get")     },
+               { A_RECEIVE_ALL,   STOCK_PIXMAP_MAIL_RECEIVE_ALL,     _("Get All") },
+               { A_SEPARATOR,     0,                                 ("")         }, 
+               { A_SEND_QUEUD,    STOCK_PIXMAP_MAIL_SEND_QUEUE,      _("Send")    },
+               { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE,         _("Email")   },
+               { A_SEPARATOR,     0,                                 ("")         },
+               { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY,           _("Reply")   }, 
+               { A_REPLY_ALL,     STOCK_PIXMAP_MAIL_REPLY_TO_ALL,    _("All")     },
+               { A_REPLY_SENDER,  STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender")  },
+               { A_FORWARD,       STOCK_PIXMAP_MAIL_FORWARD,         _("Forward") },
+               { A_SEPARATOR,     0,                                 ("")         },
+               { A_DELETE,        STOCK_PIXMAP_DELETED,              _("Delete")  },
+               { A_EXECUTE,       STOCK_PIXMAP_EXEC,                 _("Execute") },
+               { A_GOTO_NEXT,     STOCK_PIXMAP_DOWN_ARROW,           _("Next")    },
+       };
+               
+       for (i = 0; i < sizeof (default_toolbar) / sizeof (default_toolbar[0]); i++) {
+               
+               ToolbarItem *toolbar_item = g_new0 (ToolbarItem, 1);
+               
+               if (default_toolbar[i].action != A_SEPARATOR) {
+                       
+                       gchar *file = stock_pixmap_get_name ((StockPixmap)default_toolbar[i].icon);
+                       
+                       toolbar_item->file   = g_strdup (file);
+                       toolbar_item->action = default_toolbar[i].action;
+                       toolbar_item->text   = g_strdup (default_toolbar[i].text);
+               } else {
+
+                       toolbar_item->file   = g_strdup (SEPARATOR);
+                       toolbar_item->action = A_SEPARATOR;
+               }
+               
+               if (toolbar_item->action != -1) {
+                       
+                       if ( !toolbar_is_duplicate(toolbar_item->action)) 
+                               toolbar_list = g_slist_append (toolbar_list, toolbar_item);
+               }       
+       }
+}
+
+void toolbar_save_config_file ()
+{
+       GSList *cur;
+       FILE *fp;
+       PrefFile *pfile;
+       gchar *fileSpec = NULL;
+
+       debug_print("save Toolbar Configuration\n");
+
+       fileSpec = g_strconcat (get_rc_dir(), G_DIR_SEPARATOR_S, TOOLBAR_FILE, NULL );
+       pfile = prefs_write_open (fileSpec);
+       g_free( fileSpec );
+       if( pfile ) {
+               fp = pfile->fp;
+               fprintf (fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
+                               conv_get_current_charset_str());
+
+               fprintf (fp, "<%s>\n", TOOLBAR_TAG_INDEX);
+
+               for (cur = toolbar_list; cur != NULL; cur = cur->next) {
+                       ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
+                       
+                       if (g_strcasecmp (toolbar_item->file, SEPARATOR) != 0) 
+                               fprintf (fp, "\t<%s %s=\"%s\" %s=\"%s\" %s=\"%s\"/>\n",
+                                        TOOLBAR_TAG_ITEM, 
+                                        TOOLBAR_ICON_FILE, toolbar_item->file,
+                                        TOOLBAR_ICON_TEXT, toolbar_item->text,
+                                        TOOLBAR_ICON_ACTION, 
+                                        toolbar_ret_text_from_val (toolbar_item->action));
+                       else 
+                               fprintf (fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR); 
+               }
+
+               fprintf (fp, "</%s>\n", TOOLBAR_TAG_INDEX);     
+       
+               if( prefs_write_close (pfile) < 0 ) 
+                       g_warning(_("failed to write toolbar configuration to file\n"));
+       } else
+               g_warning(_("failed to open toolbar configuration file for writing\n"));
+       
+       toolbar_clear_list();
+}
+
+void toolbar_clear_list()
+{
+       while (toolbar_list != NULL) {
+               ToolbarItem *item = (ToolbarItem*) toolbar_list->data;
+               
+               toolbar_list = g_slist_remove (toolbar_list, item);
+               if (item->file)
+                       g_free (item->file);
+               if (item->text)
+                       g_free (item->text);
+       }
+       g_slist_free (toolbar_list);
+}
+
+void toolbar_read_config_file ()
+{
+       XMLFile *file   = NULL;
+       gchar *fileSpec = NULL;
+       GList *attr;
+       gboolean retVal;
+
+       debug_print("read Toolbar Configuration\n");
+
+       fileSpec = g_strconcat (get_rc_dir(), G_DIR_SEPARATOR_S, TOOLBAR_FILE, NULL );
+       file = xml_open_file (fileSpec);
+       g_free (fileSpec);
+
+       toolbar_clear_list();
+
+       if (file) {
+
+               if (setjmp (jumper)) {
+                       xml_close_file (file);
+                       return;
+               }
+
+               if (xml_get_dtd (file)) 
+                       return;
+               if (xml_parse_next_tag (file)) 
+                       return;
+               if (!xml_compare_tag (file, TOOLBAR_TAG_INDEX)) 
+                       return;
+                               
+               attr = xml_get_current_tag_attr (file);
+               
+               retVal = TRUE;
+               for (;;) {
+                       if (!file->level) 
+                               break;
+                       /* Get item tag */
+                       if (xml_parse_next_tag (file)) 
+                               longjmp (jumper, 1);
+
+                       /* Get next tag (icon, icon_text or icon_action) */
+                       if (xml_compare_tag (file, TOOLBAR_TAG_ITEM)) {
+                               toolbar_parse_item (file);
+                       } else if (xml_compare_tag (file, TOOLBAR_TAG_SEPARATOR)) {
+                               ToolbarItem *item = g_new0 (ToolbarItem, 1);
+                       
+                               item->file   = g_strdup (SEPARATOR);
+                               item->action = A_SEPARATOR;
+                               toolbar_list = g_slist_append (toolbar_list, item);
+                       }
+
+               }
+       }
+       else {  
+               /* save default toolbar */
+               toolbar_set_default_toolbar();
+               toolbar_save_config_file();
+       }
+}
+
+static void toolbar_actions_execute_cb (GtkWidget      *widget,
+                                gpointer        data)
+{
+       gint i = 0;
+       GSList *cur, *lop;
+       MainWindow *mainwin = (MainWindow*)data;
+       gchar *action, *action_p;
+       gboolean found = FALSE;
+
+       for (cur = mainwin->toolbar->syl_action; cur != NULL;  cur = cur->next) {
+               ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
+
+               if (widget == act->widget) {
+                       
+                       for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
+                               action = g_strdup((gchar*)lop->data);
+
+                               action_p = strstr(action, ": ");
+                               action_p[0] = 0x00;
+                               if (g_strcasecmp(act->name, action) == 0) {
+                                       found = TRUE;
+                                       g_free (action);
+                                       break;
+                               } else 
+                                       i++;
+                               g_free (action);
+                       }
+                       if (found) 
+                               break;
+               }
+       }
+
+       if (found)
+               actions_execute(mwin, i, widget);
+       else
+               g_warning (_("Error: did not find Sylpheed Action to execute"));
+}
+
+static void toolbar_inc_cb              (GtkWidget     *widget,
+                                gpointer        data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       inc_mail_cb(mainwin, 0, NULL);
+}
+
+static void toolbar_inc_all_cb (GtkWidget      *widget,
+                                gpointer        data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       inc_all_account_mail_cb(mainwin, 0, NULL);
+}
+
+static void toolbar_send_cb    (GtkWidget      *widget,
+                                gpointer        data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       send_queue_cb(mainwin, 0, NULL);
+}
+
+static void toolbar_compose_news_cb    (GtkWidget      *widget,
+                                gpointer        data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       compose_news_cb(mainwin, 0, NULL);
+}
+
+static void toolbar_compose_mail_cb    (GtkWidget      *widget,
+                                gpointer        data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       compose_mail_cb(mainwin, 0, NULL);
+}
+
+static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       reply_cb(mainwin, 
+                prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE 
+                : COMPOSE_REPLY_WITHOUT_QUOTE,
+                NULL);
+}
+
+static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       reply_cb(mainwin, 
+                prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
+                : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, 
+                NULL);
+}
+
+
+static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       reply_cb(mainwin, 
+                prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
+                : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, 
+                NULL);
+}
+
+static void toolbar_forward_cb (GtkWidget      *widget,
+                                gpointer        data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       if (prefs_common.forward_as_attachment)
+               reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
+       else
+               reply_cb(mainwin, COMPOSE_FORWARD, NULL);
+}
+
+static void toolbar_delete_cb  (GtkWidget      *widget,
+                                gpointer        data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       summary_delete(mainwin->summaryview);
+}
+
+static void toolbar_exec_cb    (GtkWidget      *widget,
+                                gpointer        data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       summary_execute(mainwin->summaryview);
+}
+
+static void toolbar_next_unread_cb     (GtkWidget      *widget,
+                                        gpointer        data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       next_unread_cb(mainwin, 0, NULL);
+}
+
+/* popup callback functions */
+static void toolbar_reply_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
+{
+       MainWindow *mainwindow = (MainWindow *) data;
+       
+       if (!event) return;
+
+       if (event->button == 3) {
+               gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
+               gtk_menu_popup(GTK_MENU(mainwindow->toolbar->reply_popup), NULL, NULL,
+                      menu_button_position, widget,
+                      event->button, event->time);
+       }
+}
+
+static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->reply_btn), GTK_RELIEF_NONE);
+       manage_window_focus_in(mainwin->window, NULL, NULL);
+}
+
+static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
+{
+       MainWindow *mainwindow = (MainWindow *) data;
+       
+       if (!event) return;
+
+       if (event->button == 3) {
+               gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
+               gtk_menu_popup(GTK_MENU(mainwindow->toolbar->replyall_popup), NULL, NULL,
+                      menu_button_position, widget,
+                      event->button, event->time);
+       }
+}
+
+static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->replyall_btn), GTK_RELIEF_NONE);
+       manage_window_focus_in(mainwin->window, NULL, NULL);
+}
+
+static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
+{
+       MainWindow *mainwindow = (MainWindow *) data;
+
+       if (!event) return;
+
+       if (event->button == 3) {
+               gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
+               gtk_menu_popup(GTK_MENU(mainwindow->toolbar->replysender_popup), NULL, NULL,
+                      menu_button_position, widget,
+                      event->button, event->time);
+       }
+}
+
+static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->replysender_btn), GTK_RELIEF_NONE);
+       manage_window_focus_in(mainwin->window, NULL, NULL);
+}
+
+static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
+{
+       MainWindow *mainwindow = (MainWindow *) data;
+       
+       if (!event) return;
+
+       if (event->button == 3) {
+               gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
+               gtk_menu_popup(GTK_MENU(mainwindow->toolbar->fwd_popup), NULL, NULL,
+                      menu_button_position, widget,
+                      event->button, event->time);
+       }
+}
+
+static void toolbar_forward_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
+{
+       MainWindow *mainwin = (MainWindow *)data;
+
+       gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->fwd_btn), GTK_RELIEF_NONE);
+       manage_window_focus_in(mainwin->window, NULL, NULL);
+}
+
+static void activate_compose_button (MainToolbar *toolbar,
+                               ToolbarStyle style,
+                               ComposeButtonType type)
+{
+       if (style == TOOLBAR_NONE) 
+               return;
+
+       if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
+               return;
+
+       gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn 
+                       : toolbar->compose_news_btn);
+       gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
+                       : toolbar->compose_mail_btn);
+       toolbar->compose_btn_type = type;       
+}
+
+void toolbar_reflect_prefs_pixmap_theme(MainWindow *mainwin)
+{
+       gtk_container_remove(GTK_CONTAINER(mainwin->handlebox), 
+                            GTK_WIDGET(mainwin->toolbar->toolbar));
+
+       mainwin->toolbar->toolbar = NULL;
+       toolbar_create(mainwin, mainwin->handlebox);
+
+}
+
+void toolbar_set_compose_button(MainToolbar *toolbar, ComposeButtonType compose_btn_type)
+{
+       if (toolbar->compose_btn_type != compose_btn_type)
+               activate_compose_button(toolbar, 
+                                       prefs_common.toolbar_style,
+                                       compose_btn_type);
+}
+
+void toolbar_set_sensitive(MainWindow *mainwin)
+{
+       SensitiveCond state;
+       gboolean sensitive;
+       MainToolbar *toolbar = mainwin->toolbar;
+       gint i = 0;
+       gint total = 0;
+
+       struct {
+               GtkWidget *widget;
+               SensitiveCond cond;
+               gboolean empty;
+       } entry[11];
+
+#define SET_WIDGET_COND(w, c)     \
+{                             \
+         entry[total].widget = w; \
+       entry[total].cond   = c; \
+       total++;                       \
+}
+
+       SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
+       SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
+       SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
+       SET_WIDGET_COND(toolbar->reply_btn,
+                       M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
+       SET_WIDGET_COND(toolbar->replyall_btn,
+                       M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
+       SET_WIDGET_COND(toolbar->replysender_btn,
+                       M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
+       SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
+
+       SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
+       SET_WIDGET_COND(toolbar->delete_btn,
+                       M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
+       SET_WIDGET_COND(toolbar->exec_btn, M_MSG_EXIST|M_EXEC|M_UNLOCKED);
+
+#undef SET_WIDGET_COND
+
+       state = main_window_get_current_state(mainwin);
+
+       for (i = 0; i < total; i++) {
+               
+               if (entry[i].widget == NULL) continue;
+               sensitive = ((entry[i].cond & state) == entry[i].cond);
+               gtk_widget_set_sensitive(entry[i].widget, sensitive);
+       }
+
+       activate_compose_button(toolbar, 
+                       prefs_common.toolbar_style,
+                       toolbar->compose_btn_type);
+}
+
+void toolbar_popups_create(MainWindow *mainwin, GtkWidget *window)
+{
+       guint n_menu_entries;
+       GtkWidget *reply_popup;
+       GtkWidget *replyall_popup;
+       GtkWidget *replysender_popup;
+       GtkWidget *fwd_popup;
+
+       if (mainwin->toolbar != NULL)
+               g_free (mainwin->toolbar);
+
+       mainwin->toolbar = g_new0(MainToolbar, 1); 
+       
+       /* store mainwin localy */
+       mwin = mainwin;
+
+       n_menu_entries = sizeof(reply_popup_entries) /
+                       sizeof(reply_popup_entries[0]);
+       reply_popup = popupmenu_create(window, reply_popup_entries, n_menu_entries,
+                                     "<ReplyPopup>", mainwin);
+       gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
+                          GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), mainwin);
+       n_menu_entries = sizeof(replyall_popup_entries) /
+                       sizeof(replyall_popup_entries[0]);
+       replyall_popup = popupmenu_create(window, replyall_popup_entries, n_menu_entries,
+                                     "<ReplyAllPopup>", mainwin);
+       gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
+                          GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), mainwin);
+       n_menu_entries = sizeof(replysender_popup_entries) /
+                       sizeof(replysender_popup_entries[0]);
+       replysender_popup = popupmenu_create(window, replysender_popup_entries, n_menu_entries,
+                                     "<ReplySenderPopup>", mainwin);
+       gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
+                          GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), mainwin);
+       /* create the popup menu for the forward button */
+       n_menu_entries = sizeof(fwd_popup_entries) /
+                       sizeof(fwd_popup_entries[0]);
+       fwd_popup = popupmenu_create(window, fwd_popup_entries, n_menu_entries,
+                                     "<ForwardPopup>", mainwin);
+       gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
+                          GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), mainwin);
+
+       mainwin->toolbar->reply_popup       = reply_popup;
+       mainwin->toolbar->replyall_popup    = replyall_popup;
+       mainwin->toolbar->replysender_popup = replysender_popup;
+       mainwin->toolbar->fwd_popup         = fwd_popup;
+}
+
+void toolbar_destroy(MainWindow *mainwin)
+{
+       ToolbarSylpheedActions *syl_action;
+
+       toolbar_clear_list();
+       
+       while (mainwin->toolbar->syl_action != NULL) {
+               syl_action = (ToolbarSylpheedActions*)mainwin->toolbar->syl_action->data;
+
+               if (syl_action->name)
+                       g_free (syl_action->name);
+               mainwin->toolbar->syl_action = g_slist_remove(mainwin->toolbar->syl_action, syl_action);
+       }
+
+       g_slist_free (mainwin->toolbar->syl_action);
+}
+
+void toolbar_create(MainWindow *mainwin,
+                   GtkWidget *container)
+{
+       ToolbarItem *toolbar_item;
+
+       GtkWidget *toolbar;
+       GtkWidget *icon_wid  = NULL;
+       GtkWidget *icon_news = NULL;
+       GtkWidget *item_news = NULL;
+       GtkWidget *item;
+       ToolbarSylpheedActions *syl_action;
+       GSList *cur;
+
+       toolbar_destroy(mainwin);
+       toolbar_read_config_file();
+
+       toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
+                                 GTK_TOOLBAR_BOTH);
+       gtk_container_add(GTK_CONTAINER(container), toolbar);
+       gtk_container_set_border_width(GTK_CONTAINER(container), 2);
+       gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
+       gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
+                                   GTK_TOOLBAR_SPACE_LINE);
+       
+       mainwin->toolbar->exec_btn = NULL;
+
+       for (cur = toolbar_list; cur != NULL; cur = cur->next) {
+               toolbar_item  = (ToolbarItem*) cur->data;
+               
+
+               if (g_strcasecmp (toolbar_item->file, SEPARATOR) == 0) {
+                       gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
+                       continue;
+               }
+
+               icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon (toolbar_item->file));
+               item  = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
+                                               toolbar_item->text,
+                                               toolbar_ret_descr_from_val (toolbar_item->action),
+                                               (""),
+                                               icon_wid, toolbar_actions_cb, 
+                                               toolbar_item);
+               
+               switch (toolbar_item->action) {
+               case A_RECEIVE_ALL:
+                       mainwin->toolbar->getall_btn = item;
+                       break;
+               case A_RECEIVE_CUR:
+                       mainwin->toolbar->get_btn = item;
+                       break;
+               case A_SEND_QUEUD:
+                       mainwin->toolbar->send_btn = item; 
+                       break;
+               case A_COMPOSE_EMAIL:
+                       icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
+                       item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
+                                                           _("News"),
+                                                           toolbar_ret_descr_from_val (A_COMPOSE_NEWS),
+                                                           (""),
+                                                           icon_news, toolbar_actions_cb, 
+                                                           toolbar_item);
+                       mainwin->toolbar->compose_mail_btn = item; 
+                       mainwin->toolbar->compose_news_btn = item_news;
+                       break;
+               case A_REPLY_MESSAGE:
+                       mainwin->toolbar->reply_btn = item;
+                       gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->reply_btn), 
+                                          "button_press_event",
+                                          GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
+                                          mainwin);
+                       break;
+               case A_REPLY_SENDER:
+                       mainwin->toolbar->replysender_btn = item;
+                       gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->replysender_btn), 
+                                          "button_press_event",
+                                          GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
+                                          mainwin);
+                       break;
+               case A_REPLY_ALL:
+                       mainwin->toolbar->replyall_btn = item;
+                       gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->replyall_btn), 
+                                          "button_press_event",
+                                          GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
+                                          mainwin);
+                       break;
+               case A_FORWARD:
+                       mainwin->toolbar->fwd_btn = item;
+                       gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->fwd_btn), 
+                                          "button_press_event",
+                                          GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
+                                          mainwin);
+                       break;
+               case A_DELETE:
+                       mainwin->toolbar->delete_btn = item;
+                       break;
+               case A_EXECUTE:
+                       mainwin->toolbar->exec_btn = item;
+                       break;
+               case A_GOTO_NEXT:
+                       mainwin->toolbar->next_btn = item;
+                       break;
+               case A_SYL_ACTIONS:
+                       syl_action = g_new0(ToolbarSylpheedActions, 1);
+                       syl_action->widget = item;
+                       syl_action->name   = g_strdup(toolbar_item->text);
+
+                       mainwin->toolbar->syl_action = g_slist_append(mainwin->toolbar->syl_action,
+                                                                     syl_action);
+                       gtk_widget_show (item);
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       /* we always create an exec button, if there isn't one yet */
+       if (!mainwin->toolbar->exec_btn) {
+               toolbar_item = g_new0(ToolbarItem, 1);
+               toolbar_item->action = A_EXECUTE;
+               toolbar_item->file   = stock_pixmap_get_name (STOCK_PIXMAP_EXEC);
+               toolbar_item->text   = toolbar_ret_text_from_val(A_EXECUTE);
+
+               icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EXEC);
+               item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
+                                              _("Execute"),
+                                              toolbar_ret_descr_from_val (A_EXECUTE),
+                                              (""),
+                                              icon_wid, toolbar_actions_cb,
+                                              toolbar_item);
+               mainwin->toolbar->exec_btn = item;
+               g_free (toolbar_item);
+       }
+       
+       mainwin->toolbar->toolbar = toolbar;
+       
+       activate_compose_button(mainwin->toolbar, 
+                               prefs_common.toolbar_style, 
+                               mainwin->toolbar->compose_btn_type);
+
+       gtk_widget_show_all(toolbar);
+}
diff --git a/src/toolbar.h b/src/toolbar.h
new file mode 100644 (file)
index 0000000..a7a09f6
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2002 Hiroyuki Yamamoto
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __CUSTOM_TOOLBAR_H__
+#define __CUSTOM_TOOLBAR_H__
+
+#define SEPARATOR        "separator"
+#define TOOLBAR_FILE     "toolbar.xml"
+
+#define SEPARATOR_PIXMAP "---"
+
+typedef enum 
+{
+       A_RECEIVE_ALL = 0,
+       A_RECEIVE_CUR,
+       A_SEND_QUEUD,
+       A_COMPOSE_EMAIL,
+       A_REPLY_MESSAGE,
+       A_REPLY_SENDER,
+       A_REPLY_ALL,
+       A_FORWARD,
+       A_DELETE,
+       A_EXECUTE,
+       A_GOTO_NEXT,
+       A_SYL_ACTIONS, 
+       
+       N_ACTION_VAL,
+} CTActionVal;
+
+#define A_COMPOSE_NEWS N_ACTION_VAL + 1
+#define A_SEPARATOR    N_ACTION_VAL + 2
+
+
+typedef struct _ToolbarAction ToolbarAction;
+struct _ToolbarAction
+{
+       gchar *action_text;
+       gchar *descr;
+       void (*func)(GtkWidget *widget, gpointer data);
+};
+
+typedef struct _ToolbarItem ToolbarItem;
+struct _ToolbarItem 
+{
+       gchar *file;
+       gchar *text;
+       gint  action;
+};
+
+typedef struct _ToolbarSylpheedActions ToolbarSylpheedActions;
+struct _ToolbarSylpheedActions
+{
+       GtkWidget *widget;
+       gchar     *name;
+};
+
+typedef enum 
+{
+       COMPOSEBUTTON_MAIL,
+       COMPOSEBUTTON_NEWS
+} ComposeButtonType;
+
+typedef struct _MainToolbar MainToolbar;
+
+struct _MainToolbar {
+
+       GtkWidget *toolbar;
+
+       GtkWidget *get_btn;
+       GtkWidget *getall_btn;
+       GtkWidget *sel_down;
+       GtkWidget *sel_down_all;
+       GtkWidget *sel_down_cur;
+       GtkWidget *send_btn;
+
+       GtkWidget *compose_mail_btn;
+       GtkWidget *compose_news_btn;
+
+       GtkWidget *reply_btn;
+       GtkWidget *replysender_btn;
+       GtkWidget *replyall_btn;
+
+       GtkWidget *fwd_btn;
+
+       GtkWidget *delete_btn;
+       GtkWidget *next_btn;
+
+       GSList    *syl_action;
+       GtkWidget *separator;
+
+       GtkWidget *exec_btn;
+
+       /* for the reply buttons */
+       GtkWidget *reply_popup;
+       GtkWidget *replyall_popup;
+       GtkWidget *replysender_popup;
+       
+       /* the forward button similar to the reply buttons*/
+       GtkWidget *fwd_popup;
+
+       ComposeButtonType compose_btn_type;
+};
+
+extern GSList *toolbar_list;
+
+void      toolbar_actions_cb               (GtkWidget          *widget, 
+                                           ToolbarItem        *toolbar_item);
+
+GList    *toolbar_get_action_items         (void);
+void      toolbar_save_config_file         (void);
+void      toolbar_read_config_file         (void);
+void      toolbar_set_default_toolbar      (void);
+void      toolbar_clear_list               (void);
+void      toolbar_destroy                  (MainWindow         *mainwin);
+
+gint      toolbar_ret_val_from_descr       (gchar              *descr);
+gchar    *toolbar_ret_descr_from_val       (gint               val);
+gchar    *toolbar_ret_text_from_val        (gint               val);
+void      toolbar_create                   (MainWindow         *mainwin,
+                                           GtkWidget          *container);
+
+void      toolbar_popups_create            (MainWindow         *mainwin, 
+                                           GtkWidget          *window);
+
+void      toolbar_set_sensitive            (MainWindow         *mainwin);
+void      toolbar_set_compose_button       (MainToolbar        *toolbar, 
+                                           ComposeButtonType  compose_btn_type);
+#endif /* __CUSTOM_TOOLBAR_H__ */