fix #warnings in src/
[claws.git] / src / toolbar.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2001-2003 Hiroyuki Yamamoto and 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 <stdio.h>
32 #include <stdlib.h>
33 #include <dirent.h>
34 #include <sys/stat.h>
35 #include <math.h>
36 #include <setjmp.h>
37
38 #include "intl.h"
39 #include "mainwindow.h"
40 #include "summaryview.h"
41 #include "compose.h"
42 #include "utils.h"
43 #include "xml.h"
44 #include "mgutils.h"
45 #include "prefs_gtk.h"
46 #include "codeconv.h"
47 #include "stock_pixmap.h"
48 #include "manage_window.h"
49 #include "gtkutils.h"
50 #include "toolbar.h"
51 #include "menu.h"
52 #include "inc.h"
53 #include "action.h"
54 #include "prefs_actions.h"
55 #include "prefs_common.h"
56 #include "prefs_toolbar.h"
57 #include "alertpanel.h"
58
59 /* elements */
60 #define TOOLBAR_TAG_INDEX        "toolbar"
61 #define TOOLBAR_TAG_ITEM         "item"
62 #define TOOLBAR_TAG_SEPARATOR    "separator"
63
64 #define TOOLBAR_ICON_FILE   "file"    
65 #define TOOLBAR_ICON_TEXT   "text"     
66 #define TOOLBAR_ICON_ACTION "action"    
67
68 gboolean      toolbar_is_duplicate              (gint           action,
69                                                  ToolbarType    source);
70 static void   toolbar_parse_item                (XMLFile        *file,
71                                                  ToolbarType    source);
72
73 static gint   toolbar_ret_val_from_text         (const gchar    *text);
74 static gchar *toolbar_ret_text_from_val         (gint           val);
75
76 static void   toolbar_set_default_main          (void);
77 static void   toolbar_set_default_compose       (void);
78 static void   toolbar_set_default_msgview       (void);
79
80 static void     toolbar_style                   (ToolbarType     type, 
81                                                  guint           action, 
82                                                  gpointer        data);
83
84 static MainWindow *get_mainwin                  (gpointer data);
85 static void activate_compose_button             (Toolbar        *toolbar,
86                                                  ToolbarStyle    style,
87                                                  ComposeButtonType type);
88
89 /* toolbar callbacks */
90 static void toolbar_reply                       (gpointer        data, 
91                                                  guint           action);
92 static void toolbar_delete_cb                   (GtkWidget      *widget,
93                                                  gpointer        data);
94
95 static void toolbar_compose_cb                  (GtkWidget      *widget,
96                                                  gpointer        data);
97
98 static void toolbar_reply_cb                    (GtkWidget      *widget,
99                                                  gpointer        data);
100
101 static void toolbar_reply_to_all_cb             (GtkWidget      *widget,
102                                                  gpointer        data);
103
104 static void toolbar_reply_to_list_cb            (GtkWidget      *widget,
105                                                  gpointer        data);
106
107 static void toolbar_reply_to_sender_cb          (GtkWidget      *widget,
108                                                  gpointer        data);
109
110 static void toolbar_forward_cb                  (GtkWidget      *widget,
111                                                  gpointer        data);
112
113 static void toolbar_next_unread_cb              (GtkWidget      *widget,
114                                                  gpointer        data);
115
116 static void toolbar_ignore_thread_cb            (GtkWidget      *widget,
117                                                  gpointer        data);
118
119 static void toolbar_print_cb                    (GtkWidget      *widget,
120                                                  gpointer        data);
121
122 static void toolbar_actions_execute_cb          (GtkWidget      *widget,
123                                                  gpointer        data);
124
125
126 static void toolbar_send_cb                     (GtkWidget      *widget,
127                                                  gpointer        data);
128 static void toolbar_send_later_cb               (GtkWidget      *widget,
129                                                  gpointer        data);
130 static void toolbar_draft_cb                    (GtkWidget      *widget,
131                                                  gpointer        data);
132 static void toolbar_insert_cb                   (GtkWidget      *widget,
133                                                  gpointer        data);
134 static void toolbar_attach_cb                   (GtkWidget      *widget,
135                                                  gpointer        data);
136 static void toolbar_sig_cb                      (GtkWidget      *widget,
137                                                  gpointer        data);
138 static void toolbar_ext_editor_cb               (GtkWidget      *widget,
139                                                  gpointer        data);
140 static void toolbar_linewrap_current_cb         (GtkWidget      *widget,
141                                                  gpointer        data);
142 static void toolbar_linewrap_all_cb             (GtkWidget      *widget,
143                                                  gpointer        data);
144 static void toolbar_addrbook_cb                 (GtkWidget      *widget, 
145                                                  gpointer        data);
146 #ifdef USE_ASPELL
147 static void toolbar_check_spelling_cb           (GtkWidget      *widget, 
148                                                  gpointer        data);
149 #endif
150
151 struct {
152         gchar *index_str;
153         const gchar *descr;
154 } toolbar_text [] = {
155         { "A_RECEIVE_ALL",      N_("Receive Mail on all Accounts")         },
156         { "A_RECEIVE_CUR",      N_("Receive Mail on current Account")      },
157         { "A_SEND_QUEUED",      N_("Send Queued Message(s)")               },
158         { "A_COMPOSE_EMAIL",    N_("Compose Email")                        },
159         { "A_COMPOSE_NEWS",     N_("Compose News")                         },
160         { "A_REPLY_MESSAGE",    N_("Reply to Message")                     },
161         { "A_REPLY_SENDER",     N_("Reply to Sender")                      },
162         { "A_REPLY_ALL",        N_("Reply to All")                         },
163         { "A_REPLY_ML",         N_("Reply to Mailing-list")                },
164         { "A_FORWARD",          N_("Forward Message")                      }, 
165         { "A_DELETE",           N_("Delete Message")                       },
166         { "A_EXECUTE",          N_("Execute")                              },
167         { "A_GOTO_NEXT",        N_("Goto Next Message")                    },
168         { "A_IGNORE_THREAD",    N_("Ignore thread")                     },
169         { "A_PRINT",            N_("Print")                             },
170
171         { "A_SEND",             N_("Send Message")                         },
172         { "A_SENDL",            N_("Put into queue folder and send later") },
173         { "A_DRAFT",            N_("Save to draft folder")                 },
174         { "A_INSERT",           N_("Insert file")                          },   
175         { "A_ATTACH",           N_("Attach file")                          },
176         { "A_SIG",              N_("Insert signature")                     },
177         { "A_EXTEDITOR",        N_("Edit with external editor")            },
178         { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") }, 
179         { "A_LINEWRAP_ALL",     N_("Wrap all long lines")                  }, 
180         { "A_ADDRBOOK",         N_("Address book")                         },
181 #ifdef USE_ASPELL
182         { "A_CHECK_SPELLING",   N_("Check spelling")                       },
183 #endif
184         { "A_SYL_ACTIONS",      N_("Sylpheed Actions Feature")             }, 
185         { "A_SEPARATOR",        "Separator"                             }
186 };
187
188 /* struct holds configuration files and a list of
189  * currently active toolbar items 
190  * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
191  * give us an index
192  */
193 struct {
194         const gchar  *conf_file;
195         GSList       *item_list;
196 } toolbar_config[3] = {
197         { "toolbar_main.xml",    NULL},
198         { "toolbar_compose.xml", NULL}, 
199         { "toolbar_msgview.xml", NULL}
200 };
201
202 static GtkItemFactoryEntry reply_entries[] =
203 {
204         {N_("/Reply with _quote"), NULL,    toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
205         {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
206 };
207 static GtkItemFactoryEntry replyall_entries[] =
208 {
209         {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
210         {N_("/_Reply to all without quote"), "a",     toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
211 };
212 static GtkItemFactoryEntry replylist_entries[] =
213 {
214         {N_("/Reply to list with _quote"),    NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
215         {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
216 };
217 static GtkItemFactoryEntry replysender_entries[] =
218 {
219         {N_("/Reply to sender with _quote"),    NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
220         {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
221 };
222 static GtkItemFactoryEntry forward_entries[] =
223 {
224         {N_("/_Forward"),               "f",        toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
225         {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
226         {N_("/Redirec_t"),              NULL,       toolbar_reply, COMPOSE_REDIRECT, NULL}
227 };
228
229
230 gint toolbar_ret_val_from_descr(const gchar *descr)
231 {
232         gint i;
233
234         for (i = 0; i < N_ACTION_VAL; i++) {
235                 if (g_strcasecmp(gettext(toolbar_text[i].descr), descr) == 0)
236                                 return i;
237         }
238         
239         return -1;
240 }
241
242 gchar *toolbar_ret_descr_from_val(gint val)
243 {
244         g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
245
246         return gettext(toolbar_text[val].descr);
247 }
248
249 static gint toolbar_ret_val_from_text(const gchar *text)
250 {
251         gint i;
252         
253         for (i = 0; i < N_ACTION_VAL; i++) {
254                 if (g_strcasecmp(toolbar_text[i].index_str, text) == 0)
255                                 return i;
256         }
257         
258         return -1;
259 }
260
261 static gchar *toolbar_ret_text_from_val(gint val)
262 {
263         g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
264
265         return toolbar_text[val].index_str;
266 }
267
268 gboolean toolbar_is_duplicate(gint action, ToolbarType source)
269 {
270         GSList *cur;
271
272         if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS)) 
273                 return FALSE;
274
275         for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
276                 ToolbarItem *item = (ToolbarItem*) cur->data;
277                 
278                 if (item->index == action)
279                         return TRUE;
280         }
281         return FALSE;
282 }
283
284 /* depending on toolbar type this function 
285    returns a list of available toolbar events being 
286    displayed by prefs_toolbar
287 */
288 GList *toolbar_get_action_items(ToolbarType source)
289 {
290         GList *items = NULL;
291         gint i = 0;
292         
293         if (source == TOOLBAR_MAIN) {
294                 gint main_items[]   = { A_RECEIVE_ALL,   A_RECEIVE_CUR,   A_SEND_QUEUED,
295                                         A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER, 
296                                         A_REPLY_ALL,     A_REPLY_ML,      A_FORWARD, 
297                                         A_DELETE,        A_EXECUTE,       A_GOTO_NEXT, 
298                                         A_IGNORE_THREAD, A_PRINT,  
299                                         A_ADDRBOOK,      A_SYL_ACTIONS };
300
301                 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++)  {
302                         items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
303                         if (main_items[i] == A_PRINT) {
304                                 g_print("$$$ descr %s, trans %s\n",
305                                         toolbar_text[main_items[i]].descr,
306                                         gettext(toolbar_text[main_items[i]].descr));
307                         }
308                 }       
309         }
310         else if (source == TOOLBAR_COMPOSE) {
311                 gint comp_items[] =   { A_SEND,          A_SENDL,        A_DRAFT,
312                                         A_INSERT,        A_ATTACH,       A_SIG,
313                                         A_EXTEDITOR,     A_LINEWRAP_CURRENT,     
314                                         A_LINEWRAP_ALL,  A_ADDRBOOK,
315 #ifdef USE_ASPELL
316                                         A_CHECK_SPELLING, 
317 #endif
318                                         A_SYL_ACTIONS };        
319
320                 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++) 
321                         items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
322         }
323         else if (source == TOOLBAR_MSGVIEW) {
324                 gint msgv_items[] =   { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
325                                         A_REPLY_ALL,     A_REPLY_ML,      A_FORWARD,
326                                         A_DELETE,        A_GOTO_NEXT,     A_ADDRBOOK,
327                                         A_SYL_ACTIONS };        
328
329                 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++) 
330                         items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
331         }
332
333         return items;
334 }
335
336 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
337 {
338         GList *attr;
339         gchar *name, *value;
340         ToolbarItem *item = NULL;
341
342         attr = xml_get_current_tag_attr(file);
343         item = g_new0(ToolbarItem, 1);
344         while( attr ) {
345                 name = ((XMLAttr *)attr->data)->name;
346                 value = ((XMLAttr *)attr->data)->value;
347                 
348                 if (g_strcasecmp(name, TOOLBAR_ICON_FILE) == 0) 
349                         item->file = g_strdup (value);
350                 else if (g_strcasecmp(name, TOOLBAR_ICON_TEXT) == 0)
351                         item->text = g_strdup (value);
352                 else if (g_strcasecmp(name, TOOLBAR_ICON_ACTION) == 0)
353                         item->index = toolbar_ret_val_from_text(value);
354
355                 attr = g_list_next(attr);
356         }
357         if (item->index != -1) {
358                 
359                 if (!toolbar_is_duplicate(item->index, source)) 
360                         toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
361                                                                          item);
362         }
363 }
364
365 static void toolbar_set_default_main(void) 
366 {
367         struct {
368                 gint action;
369                 gint icon;
370                 gchar *text;
371         } default_toolbar[] = {
372                 { A_RECEIVE_CUR,   STOCK_PIXMAP_MAIL_RECEIVE,         _("Get")     },
373                 { A_RECEIVE_ALL,   STOCK_PIXMAP_MAIL_RECEIVE_ALL,     _("Get All") },
374                 { A_SEPARATOR,     0,                                 ("")         }, 
375                 { A_SEND_QUEUED,   STOCK_PIXMAP_MAIL_SEND_QUEUE,      _("Send")    },
376                 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE,         _("Email")   },
377                 { A_SEPARATOR,     0,                                 ("")         },
378                 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY,           _("Reply")   }, 
379                 { A_REPLY_ALL,     STOCK_PIXMAP_MAIL_REPLY_TO_ALL,    _("All")     },
380                 { A_REPLY_SENDER,  STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender")  },
381                 { A_FORWARD,       STOCK_PIXMAP_MAIL_FORWARD,         _("Forward") },
382                 { A_SEPARATOR,     0,                                 ("")         },
383                 { A_DELETE,        STOCK_PIXMAP_CLOSE,                _("Delete")  },
384                 { A_EXECUTE,       STOCK_PIXMAP_EXEC,                 _("Execute") },
385                 { A_GOTO_NEXT,     STOCK_PIXMAP_DOWN_ARROW,           _("Next")    }
386         };
387         
388         gint i;
389         
390         for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
391                 
392                 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
393                 
394                 if (default_toolbar[i].action != A_SEPARATOR) {
395                         
396                         gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
397                         
398                         toolbar_item->file  = g_strdup(file);
399                         toolbar_item->index = default_toolbar[i].action;
400                         toolbar_item->text  = g_strdup(default_toolbar[i].text);
401                 } else {
402
403                         toolbar_item->file  = g_strdup(TOOLBAR_TAG_SEPARATOR);
404                         toolbar_item->index = A_SEPARATOR;
405                 }
406                 
407                 if (toolbar_item->index != -1) {
408                         if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN)) 
409                                 toolbar_config[TOOLBAR_MAIN].item_list = 
410                                         g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
411                 }       
412         }
413 }
414
415 static void toolbar_set_default_compose(void)
416 {
417         struct {
418                 gint action;
419                 gint icon;
420                 gchar *text;
421         } default_toolbar[] = {
422                 { A_SEND,               STOCK_PIXMAP_MAIL_SEND,         _("Send")               },
423                 { A_SENDL,              STOCK_PIXMAP_MAIL_SEND_QUEUE,   _("Send later")         },
424                 { A_DRAFT,              STOCK_PIXMAP_MAIL,              _("Draft")              },
425                 { A_SEPARATOR,          0,                               ("")                   }, 
426                 { A_INSERT,             STOCK_PIXMAP_INSERT_FILE,       _("Insert")             },
427                 { A_ATTACH,             STOCK_PIXMAP_MAIL_ATTACH,       _("Attach")             },
428                 { A_SIG,                STOCK_PIXMAP_MAIL_SIGN,         _("Signature")          },
429                 { A_SEPARATOR,          0,                               ("")                   },
430                 { A_EXTEDITOR,          STOCK_PIXMAP_EDIT_EXTERN,       _("Editor")             },
431                 { A_LINEWRAP_CURRENT,   STOCK_PIXMAP_LINEWRAP_CURRENT,  _("Wrap paragraph")     },
432                 { A_LINEWRAP_ALL,       STOCK_PIXMAP_LINEWRAP_ALL,      _("Wrap all")           },
433                 { A_SEPARATOR,          0,                               ("")                   },
434                 { A_ADDRBOOK,           STOCK_PIXMAP_ADDRESS_BOOK,      _("Address")            }
435         };
436         
437         gint i;
438
439         for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
440                 
441                 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
442                 
443                 if (default_toolbar[i].action != A_SEPARATOR) {
444                         
445                         gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
446                         
447                         toolbar_item->file  = g_strdup(file);
448                         toolbar_item->index = default_toolbar[i].action;
449                         toolbar_item->text  = g_strdup(default_toolbar[i].text);
450                 } else {
451
452                         toolbar_item->file  = g_strdup(TOOLBAR_TAG_SEPARATOR);
453                         toolbar_item->index = A_SEPARATOR;
454                 }
455                 
456                 if (toolbar_item->index != -1) {
457                         if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE)) 
458                                 toolbar_config[TOOLBAR_COMPOSE].item_list = 
459                                         g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
460                 }       
461         }
462 }
463
464 static void toolbar_set_default_msgview(void)
465 {
466         struct {
467                 gint action;
468                 gint icon;
469                 gchar *text;
470         } default_toolbar[] = {
471                 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY,           _("Reply")   }, 
472                 { A_REPLY_ALL,     STOCK_PIXMAP_MAIL_REPLY_TO_ALL,    _("All")     },
473                 { A_REPLY_SENDER,  STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender")  },
474                 { A_FORWARD,       STOCK_PIXMAP_MAIL_FORWARD,         _("Forward") },
475                 { A_SEPARATOR,     0,                                 ("")         },
476                 { A_DELETE,        STOCK_PIXMAP_CLOSE,                _("Delete")  },
477                 { A_GOTO_NEXT,     STOCK_PIXMAP_DOWN_ARROW,           _("Next")    }
478         };
479         
480         gint i;
481
482         for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
483                 
484                 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
485                 
486                 if (default_toolbar[i].action != A_SEPARATOR) {
487                         
488                         gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
489                         
490                         toolbar_item->file  = g_strdup(file);
491                         toolbar_item->index = default_toolbar[i].action;
492                         toolbar_item->text  = g_strdup(default_toolbar[i].text);
493                 } else {
494
495                         toolbar_item->file  = g_strdup(TOOLBAR_TAG_SEPARATOR);
496                         toolbar_item->index = A_SEPARATOR;
497                 }
498                 
499                 if (toolbar_item->index != -1) {
500                         if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW)) 
501                                 toolbar_config[TOOLBAR_MSGVIEW].item_list = 
502                                         g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
503                 }       
504         }
505 }
506
507 void toolbar_set_default(ToolbarType source)
508 {
509         if (source == TOOLBAR_MAIN)
510                 toolbar_set_default_main();
511         else if  (source == TOOLBAR_COMPOSE)
512                 toolbar_set_default_compose();
513         else if  (source == TOOLBAR_MSGVIEW)
514                 toolbar_set_default_msgview();
515 }
516
517 void toolbar_save_config_file(ToolbarType source)
518 {
519         GSList *cur;
520         FILE *fp;
521         PrefFile *pfile;
522         gchar *fileSpec = NULL;
523
524         debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
525
526         fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
527         pfile = prefs_write_open(fileSpec);
528         g_free( fileSpec );
529         if( pfile ) {
530                 fp = pfile->fp;
531                 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
532                         conv_get_current_charset_str());
533
534                 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
535
536                 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
537                         ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
538                         
539                         if (toolbar_item->index != A_SEPARATOR) {
540                                 fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
541                                         TOOLBAR_TAG_ITEM, 
542                                         TOOLBAR_ICON_FILE, toolbar_item->file,
543                                         TOOLBAR_ICON_TEXT);
544                                 xml_file_put_escape_str(fp, toolbar_item->text);
545                                 fprintf(fp, "\" %s=\"%s\"/>\n",
546                                         TOOLBAR_ICON_ACTION, 
547                                         toolbar_ret_text_from_val(toolbar_item->index));
548                         } else {
549                                 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR); 
550                         }
551                 }
552
553                 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);      
554         
555                 if (prefs_file_close (pfile) < 0 ) 
556                         g_warning("failed to write toolbar configuration to file\n");
557         } else
558                 g_warning("failed to open toolbar configuration file for writing\n");
559 }
560
561 void toolbar_read_config_file(ToolbarType source)
562 {
563         XMLFile *file   = NULL;
564         gchar *fileSpec = NULL;
565         GList *attr;
566         gboolean retVal;
567         jmp_buf    jumper;
568
569         debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
570
571         fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
572         file = xml_open_file(fileSpec);
573         g_free(fileSpec);
574
575         toolbar_clear_list(source);
576
577         if (file) {
578                 if ((setjmp(jumper))
579                 || (xml_get_dtd(file))
580                 || (xml_parse_next_tag(file))
581                 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
582                         xml_close_file(file);
583                         return;
584                 }
585
586                 attr = xml_get_current_tag_attr(file);
587                 
588                 retVal = TRUE;
589                 for (;;) {
590                         if (!file->level) 
591                                 break;
592                         /* Get item tag */
593                         if (xml_parse_next_tag(file)) 
594                                 longjmp(jumper, 1);
595
596                         /* Get next tag (icon, icon_text or icon_action) */
597                         if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
598                                 toolbar_parse_item(file, source);
599                         } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
600                                 ToolbarItem *item = g_new0(ToolbarItem, 1);
601                         
602                                 item->file   = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
603                                 item->index  = A_SEPARATOR;
604                                 toolbar_config[source].item_list = 
605                                         g_slist_append(toolbar_config[source].item_list, item);
606                         }
607
608                 }
609                 xml_close_file(file);
610         }
611
612         if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
613
614                 if (source == TOOLBAR_MAIN) 
615                         toolbar_set_default(TOOLBAR_MAIN);
616                 else if (source == TOOLBAR_COMPOSE) 
617                         toolbar_set_default(TOOLBAR_COMPOSE);
618                 else if (source == TOOLBAR_MSGVIEW) 
619                         toolbar_set_default(TOOLBAR_MSGVIEW);
620                 else {          
621                         g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
622                         return;
623                 }
624
625                 toolbar_save_config_file(source);
626         }
627 }
628
629 /*
630  * clears list of toolbar items read from configuration files
631  */
632 void toolbar_clear_list(ToolbarType source)
633 {
634         while (toolbar_config[source].item_list != NULL) {
635                 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
636                 
637                 toolbar_config[source].item_list = 
638                         g_slist_remove(toolbar_config[source].item_list, item);
639
640                 if (item->file)
641                         g_free(item->file);
642                 if (item->text)
643                         g_free(item->text);
644                 g_free(item);   
645         }
646         g_slist_free(toolbar_config[source].item_list);
647 }
648
649
650 /* 
651  * return list of Toolbar items
652  */
653 GSList *toolbar_get_list(ToolbarType source)
654 {
655         GSList *list = NULL;
656
657         if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
658                 list = toolbar_config[source].item_list;
659
660         return list;
661 }
662
663 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
664 {
665         ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
666
667         toolbar_item->file  = g_strdup(t_item->file);
668         toolbar_item->text  = g_strdup(t_item->text);
669         toolbar_item->index = t_item->index;
670         
671         toolbar_config[source].item_list = 
672                 g_slist_append(toolbar_config[source].item_list,
673                                toolbar_item);
674 }
675
676 void toolbar_action_execute(GtkWidget    *widget,
677                             GSList       *action_list, 
678                             gpointer     data,
679                             gint         source) 
680 {
681         GSList *cur, *lop;
682         gchar *action, *action_p;
683         gboolean found = FALSE;
684         gint i = 0;
685
686         for (cur = action_list; cur != NULL;  cur = cur->next) {
687                 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
688
689                 if (widget == act->widget) {
690                         
691                         for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
692                                 action = g_strdup((gchar*)lop->data);
693
694                                 action_p = strstr(action, ": ");
695                                 action_p[0] = 0x00;
696                                 if (g_strcasecmp(act->name, action) == 0) {
697                                         found = TRUE;
698                                         g_free(action);
699                                         break;
700                                 } else 
701                                         i++;
702                                 g_free(action);
703                         }
704                         if (found) 
705                                 break;
706                 }
707         }
708
709         if (found) 
710                 actions_execute(data, i, widget, source);
711         else
712                 g_warning ("Error: did not find Sylpheed Action to execute");
713 }
714
715 static void activate_compose_button (Toolbar           *toolbar,
716                                      ToolbarStyle      style,
717                                      ComposeButtonType type)
718 {
719         if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
720                 return;
721
722         gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn 
723                         : toolbar->compose_news_btn);
724         gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
725                         : toolbar->compose_mail_btn);
726         toolbar->compose_btn_type = type;       
727 }
728
729 void toolbar_set_compose_button(Toolbar            *toolbar, 
730                                 ComposeButtonType  compose_btn_type)
731 {
732         if (toolbar->compose_btn_type != compose_btn_type)
733                 activate_compose_button(toolbar, 
734                                         prefs_common.toolbar_style,
735                                         compose_btn_type);
736 }
737
738 void toolbar_toggle(guint action, gpointer data)
739 {
740         MainWindow *mainwin = (MainWindow*)data;
741         GList *list;
742         GList *cur;
743
744         g_return_if_fail(mainwin != NULL);
745
746         toolbar_style(TOOLBAR_MAIN, action, mainwin);
747
748         list = compose_get_compose_list();
749         for (cur = list; cur != NULL; cur = cur->next) {
750                 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
751         }
752         list = messageview_get_msgview_list();
753         for (cur = list; cur != NULL; cur = cur->next) {
754                 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
755         }
756         
757 }
758
759 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
760 {
761         switch ((ToolbarStyle)action) {
762         case TOOLBAR_NONE:
763                 gtk_widget_hide(handlebox_wid);
764                 break;
765         case TOOLBAR_ICON:
766                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
767                                       GTK_TOOLBAR_ICONS);
768                 break;
769         case TOOLBAR_TEXT:
770                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
771                                       GTK_TOOLBAR_TEXT);
772                 break;
773         case TOOLBAR_BOTH:
774                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
775                                       GTK_TOOLBAR_BOTH);
776                 break;
777         default:
778                 return;
779         }
780
781         prefs_common.toolbar_style = (ToolbarStyle)action;
782         gtk_widget_set_usize(handlebox_wid, 1, -1);
783         
784         if (prefs_common.toolbar_style != TOOLBAR_NONE) {
785                 gtk_widget_show(handlebox_wid);
786                 gtk_widget_queue_resize(handlebox_wid);
787         }
788 }
789 /*
790  * Change the style of toolbar
791  */
792 static void toolbar_style(ToolbarType type, guint action, gpointer data)
793 {
794         GtkWidget  *handlebox_wid;
795         GtkWidget  *toolbar_wid;
796         MainWindow *mainwin = (MainWindow*)data;
797         Compose    *compose = (Compose*)data;
798         MessageView *msgview = (MessageView*)data;
799         
800         g_return_if_fail(data != NULL);
801         
802         switch (type) {
803         case TOOLBAR_MAIN:
804                 handlebox_wid = mainwin->handlebox;
805                 toolbar_wid = mainwin->toolbar->toolbar;
806                 break;
807         case TOOLBAR_COMPOSE:
808                 handlebox_wid = compose->handlebox;
809                 toolbar_wid = compose->toolbar->toolbar;
810                 break;
811         case TOOLBAR_MSGVIEW: 
812                 handlebox_wid = msgview->handlebox;
813                 toolbar_wid = msgview->toolbar->toolbar;
814                 break;
815         default:
816
817                 return;
818         }
819         toolbar_set_style(toolbar_wid, handlebox_wid, action);
820 }
821
822 /* Toolbar handling */
823 static void toolbar_inc_cb(GtkWidget    *widget,
824                            gpointer      data)
825 {
826         ToolbarItem *toolbar_item = (ToolbarItem*)data;
827         MainWindow *mainwin;
828
829         g_return_if_fail(toolbar_item != NULL);
830
831         switch (toolbar_item->type) {
832         case TOOLBAR_MAIN:
833                 mainwin = (MainWindow*)toolbar_item->parent;    
834                 inc_mail_cb(mainwin, 0, NULL);
835                 break;
836         default:
837                 break;
838         }
839 }
840
841 static void toolbar_inc_all_cb(GtkWidget        *widget,
842                                gpointer          data)
843 {
844         ToolbarItem *toolbar_item = (ToolbarItem*)data;
845         MainWindow *mainwin;
846
847         g_return_if_fail(toolbar_item != NULL);
848
849         switch (toolbar_item->type) {
850         case TOOLBAR_MAIN:
851                 mainwin = (MainWindow*)toolbar_item->parent;
852                 inc_all_account_mail_cb(mainwin, 0, NULL);
853                 break;
854         default:
855                 break;
856         }
857 }
858
859 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
860 {
861         ToolbarItem *toolbar_item = (ToolbarItem*)data;
862         MainWindow *mainwin;
863
864         g_return_if_fail(toolbar_item != NULL);
865
866         switch (toolbar_item->type) {
867         case TOOLBAR_MAIN:
868                 mainwin = (MainWindow*)toolbar_item->parent;
869                 send_queue_cb(mainwin, 0, NULL);
870                 break;
871         default:
872                 break;
873         }
874 }
875
876 static void toolbar_exec_cb(GtkWidget   *widget,
877                             gpointer     data)
878 {
879         MainWindow *mainwin = get_mainwin(data);
880
881         g_return_if_fail(mainwin != NULL);
882         summary_execute(mainwin->summaryview);
883 }
884
885 /*
886  * Delete current/selected(s) message(s)
887  */
888 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
889 {
890         ToolbarItem *toolbar_item = (ToolbarItem*)data;
891         MainWindow *mainwin;
892
893         g_return_if_fail(toolbar_item != NULL);
894         g_return_if_fail(toolbar_item->parent);
895         
896         switch (toolbar_item->type) {
897         case TOOLBAR_MSGVIEW:
898                 messageview_delete((MessageView *)toolbar_item->parent);
899                 break;
900         case TOOLBAR_MAIN:
901                 mainwin = (MainWindow *)toolbar_item->parent;
902                 summary_delete(mainwin->summaryview);
903                 break;
904         default: 
905                 debug_print("toolbar event not supported\n");
906                 break;
907         }
908 }
909
910
911 /*
912  * Compose new message
913  */
914 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
915 {
916         ToolbarItem *toolbar_item = (ToolbarItem*)data;
917         MainWindow *mainwin;
918         MessageView *msgview;
919
920         g_return_if_fail(toolbar_item != NULL);
921
922         switch (toolbar_item->type) {
923         case TOOLBAR_MAIN:
924                 mainwin = (MainWindow*)toolbar_item->parent;
925                 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS) 
926                         compose_news_cb(mainwin, 0, NULL);
927                 else
928                         compose_mail_cb(mainwin, 0, NULL);
929                 break;
930         case TOOLBAR_MSGVIEW:
931                 msgview = (MessageView*)toolbar_item->parent;
932                 compose_new_with_folderitem(NULL, 
933                                             msgview->msginfo->folder);
934                 break;  
935         default:
936                 debug_print("toolbar event not supported\n");
937         }
938 }
939
940
941 /*
942  * Reply Message
943  */
944 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
945 {
946         toolbar_reply(data, prefs_common.reply_with_quote ? 
947                       COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
948 }
949
950
951 /*
952  * Reply message to Sender and All recipients
953  */
954 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
955 {
956         toolbar_reply(data,
957                       prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
958                       : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
959 }
960
961
962 /*
963  * Reply to Mailing List
964  */
965 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
966 {
967         toolbar_reply(data, 
968                       prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE 
969                       : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
970 }
971
972
973 /*
974  * Reply to sender of message
975  */ 
976 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
977 {
978         toolbar_reply(data, 
979                       prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
980                       : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
981 }
982
983 /*
984  * Open addressbook
985  */ 
986 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
987 {
988         ToolbarItem *toolbar_item = (ToolbarItem*)data;
989         Compose *compose;
990
991         g_return_if_fail(toolbar_item != NULL);
992
993         switch (toolbar_item->type) {
994         case TOOLBAR_MAIN:
995         case TOOLBAR_MSGVIEW:
996                 compose = NULL;
997                 break;
998         case TOOLBAR_COMPOSE:
999                 compose = (Compose *)toolbar_item->parent;
1000                 break;
1001         default:
1002                 return;
1003         }
1004         addressbook_open(compose);
1005 }
1006
1007
1008 /*
1009  * Forward current/selected(s) message(s)
1010  */
1011 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1012 {
1013         toolbar_reply(data, COMPOSE_FORWARD);
1014 }
1015
1016
1017 /*
1018  * Goto Next Unread Message
1019  */
1020 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1021 {
1022         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1023         MainWindow *mainwin;
1024         MessageView *msgview;
1025
1026         g_return_if_fail(toolbar_item != NULL);
1027
1028         switch (toolbar_item->type) {
1029         case TOOLBAR_MAIN:
1030                 mainwin = (MainWindow*)toolbar_item->parent;
1031                 summary_select_next_unread(mainwin->summaryview);
1032                 break;
1033                 
1034         case TOOLBAR_MSGVIEW:
1035                 msgview = (MessageView*)toolbar_item->parent;
1036                 summary_select_next_unread(msgview->mainwin->summaryview);
1037                 
1038                 /* Now we need to update the messageview window */
1039                 if (msgview->mainwin->summaryview->selected) {
1040                         GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1041                         
1042                         MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree, 
1043                                                                         msgview->mainwin->summaryview->selected);
1044                        
1045                         messageview_show(msgview, msginfo, 
1046                                          msgview->all_headers);
1047                 } else {
1048                         gtk_widget_destroy(msgview->window);
1049                 }
1050                 break;
1051         default:
1052                 debug_print("toolbar event not supported\n");
1053         }
1054 }
1055
1056 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1057 {
1058         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1059         MainWindow *mainwin;
1060
1061         g_return_if_fail(toolbar_item != NULL);
1062
1063         switch (toolbar_item->type) {
1064         case TOOLBAR_MAIN:
1065                 mainwin = (MainWindow *) toolbar_item->parent;
1066                 summary_toggle_ignore_thread(mainwin->summaryview);
1067                 break;
1068         case TOOLBAR_MSGVIEW:
1069                 /* TODO: see toolbar_next_unread_cb() if you need
1070                  * this in the message view */
1071                 break;
1072         default:
1073                 debug_print("toolbar event not supported\n");
1074                 break;
1075         }
1076 }
1077
1078 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1079 {
1080         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1081         MainWindow *mainwin;
1082
1083         g_return_if_fail(toolbar_item != NULL);
1084
1085         switch (toolbar_item->type) {
1086         case TOOLBAR_MAIN:
1087                 mainwin = (MainWindow *) toolbar_item->parent;
1088                 summary_print(mainwin->summaryview);
1089                 break;
1090         case TOOLBAR_MSGVIEW:
1091                 /* TODO: see toolbar_next_unread_cb() if you need
1092                  * this in the message view */
1093                 break;
1094         default:
1095                 debug_print("toolbar event not supported\n");
1096                 break;
1097         }
1098 }
1099
1100 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1101 {
1102         compose_toolbar_cb(A_SEND, data);
1103 }
1104
1105 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1106 {
1107         compose_toolbar_cb(A_SENDL, data);
1108 }
1109
1110 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1111 {
1112         compose_toolbar_cb(A_DRAFT, data);
1113 }
1114
1115 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1116 {
1117         compose_toolbar_cb(A_INSERT, data);
1118 }
1119
1120 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1121 {
1122         compose_toolbar_cb(A_ATTACH, data);
1123 }
1124
1125 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1126 {
1127         compose_toolbar_cb(A_SIG, data);
1128 }
1129
1130 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1131 {
1132         compose_toolbar_cb(A_EXTEDITOR, data);
1133 }
1134
1135 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1136 {
1137         compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1138 }
1139
1140 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1141 {
1142         compose_toolbar_cb(A_LINEWRAP_ALL, data);
1143 }
1144
1145 #ifdef USE_ASPELL
1146 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1147 {
1148         compose_toolbar_cb(A_CHECK_SPELLING, data);
1149 }
1150 #endif
1151 /*
1152  * Execute actions from toolbar
1153  */
1154 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1155 {
1156         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1157         GSList *action_list;
1158         MainWindow *mainwin;
1159         Compose *compose;
1160         MessageView *msgview;
1161         gpointer parent = toolbar_item->parent;
1162
1163         g_return_if_fail(toolbar_item != NULL);
1164
1165         switch (toolbar_item->type) {
1166         case TOOLBAR_MAIN:
1167                 mainwin = (MainWindow*)parent;
1168                 action_list = mainwin->toolbar->action_list;
1169                 break;
1170         case TOOLBAR_COMPOSE:
1171                 compose = (Compose*)parent;
1172                 action_list = compose->toolbar->action_list;
1173                 break;
1174         case TOOLBAR_MSGVIEW:
1175                 msgview = (MessageView*)parent;
1176                 action_list = msgview->toolbar->action_list;
1177                 break;
1178         default:
1179                 debug_print("toolbar event not supported\n");
1180                 return;
1181         }
1182         toolbar_action_execute(widget, action_list, parent, toolbar_item->type);        
1183 }
1184
1185 static MainWindow *get_mainwin(gpointer data)
1186 {
1187         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1188         MainWindow *mainwin = NULL;
1189         MessageView *msgview;
1190
1191         g_return_val_if_fail(toolbar_item != NULL, NULL);
1192
1193         switch(toolbar_item->type) {
1194         case TOOLBAR_MAIN:
1195                 mainwin = (MainWindow*)toolbar_item->parent;
1196                 break;
1197         case TOOLBAR_MSGVIEW:
1198                 msgview = (MessageView*)toolbar_item->parent;
1199                 mainwin = (MainWindow*)msgview->mainwin;
1200                 break;
1201         default:
1202                 break;
1203         }
1204
1205         return mainwin;
1206 }
1207
1208 static void toolbar_buttons_cb(GtkWidget   *widget, 
1209                                ToolbarItem *item)
1210 {
1211         gint num_items;
1212         gint i;
1213         struct {
1214                 gint   index;
1215                 void (*func)(GtkWidget *widget, gpointer data);
1216         } callbacks[] = {
1217                 { A_RECEIVE_ALL,        toolbar_inc_all_cb              },
1218                 { A_RECEIVE_CUR,        toolbar_inc_cb                  },
1219                 { A_SEND_QUEUED,        toolbar_send_queued_cb          },
1220                 { A_COMPOSE_EMAIL,      toolbar_compose_cb              },
1221                 { A_COMPOSE_NEWS,       toolbar_compose_cb              },
1222                 { A_REPLY_MESSAGE,      toolbar_reply_cb                },
1223                 { A_REPLY_SENDER,       toolbar_reply_to_sender_cb      },
1224                 { A_REPLY_ALL,          toolbar_reply_to_all_cb         },
1225                 { A_REPLY_ML,           toolbar_reply_to_list_cb        },
1226                 { A_FORWARD,            toolbar_forward_cb              },
1227                 { A_DELETE,             toolbar_delete_cb               },
1228                 { A_EXECUTE,            toolbar_exec_cb                 },
1229                 { A_GOTO_NEXT,          toolbar_next_unread_cb          },
1230                 { A_IGNORE_THREAD,      toolbar_ignore_thread_cb        },
1231                 { A_PRINT,              toolbar_print_cb                },
1232
1233                 { A_SEND,               toolbar_send_cb                 },
1234                 { A_SENDL,              toolbar_send_later_cb           },
1235                 { A_DRAFT,              toolbar_draft_cb                },
1236                 { A_INSERT,             toolbar_insert_cb               },
1237                 { A_ATTACH,             toolbar_attach_cb               },
1238                 { A_SIG,                toolbar_sig_cb                  },
1239                 { A_EXTEDITOR,          toolbar_ext_editor_cb           },
1240                 { A_LINEWRAP_CURRENT,   toolbar_linewrap_current_cb     },
1241                 { A_LINEWRAP_ALL,       toolbar_linewrap_all_cb         },
1242                 { A_ADDRBOOK,           toolbar_addrbook_cb             },
1243 #ifdef USE_ASPELL
1244                 { A_CHECK_SPELLING,     toolbar_check_spelling_cb       },
1245 #endif
1246                 { A_SYL_ACTIONS,        toolbar_actions_execute_cb      }
1247         };
1248
1249         num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1250
1251         for (i = 0; i < num_items; i++) {
1252                 if (callbacks[i].index == item->index) {
1253                         callbacks[i].func(widget, item);
1254                         return;
1255                 }
1256         }
1257 }
1258
1259 /**
1260  * Create a new toolbar with specified type
1261  * if a callback list is passed it will be used before the 
1262  * common callback list
1263  **/
1264 Toolbar *toolbar_create(ToolbarType      type, 
1265                         GtkWidget       *container,
1266                         gpointer         data)
1267 {
1268         ToolbarItem *toolbar_item;
1269
1270         GtkWidget *toolbar;
1271         GtkWidget *icon_wid = NULL;
1272         GtkWidget *icon_news;
1273         GtkWidget *item;
1274         GtkWidget *item_news;
1275
1276         guint n_menu_entries;
1277         ComboButton *reply_combo;
1278         ComboButton *replyall_combo;
1279         ComboButton *replylist_combo;
1280         ComboButton *replysender_combo;
1281         ComboButton *fwd_combo;
1282
1283         GtkTooltips *toolbar_tips;
1284         ToolbarSylpheedActions *action_item;
1285         GSList *cur;
1286         GSList *toolbar_list;
1287         Toolbar *toolbar_data;
1288
1289         
1290         toolbar_tips = gtk_tooltips_new();
1291         
1292         toolbar_read_config_file(type);
1293         toolbar_list = toolbar_get_list(type);
1294
1295         toolbar_data = g_new0(Toolbar, 1); 
1296
1297         toolbar = gtk_toolbar_new();
1298         gtk_container_add(GTK_CONTAINER(container), toolbar);
1299         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1300         gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1301         gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1302         
1303         for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1304
1305                 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1306                         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1307                         continue;
1308                 }
1309                 
1310                 toolbar_item = g_new0(ToolbarItem, 1); 
1311                 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1312                 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1313                 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1314                 toolbar_item->parent = data;
1315                 toolbar_item->type = type;
1316
1317                 /* collect toolbar items in list to keep track */
1318                 toolbar_data->item_list = 
1319                         g_slist_append(toolbar_data->item_list, 
1320                                        toolbar_item);
1321
1322                 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1323                 item  = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1324                                                 toolbar_item->text,
1325                                                 (""),
1326                                                 (""),
1327                                                 icon_wid, G_CALLBACK(toolbar_buttons_cb), 
1328                                                 toolbar_item);
1329                 
1330                 switch (toolbar_item->index) {
1331
1332                 case A_RECEIVE_ALL:
1333                         toolbar_data->getall_btn = item;
1334                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1335                                              toolbar_data->getall_btn, 
1336                                            _("Receive Mail on all Accounts"), NULL);
1337                         break;
1338                 case A_RECEIVE_CUR:
1339                         toolbar_data->get_btn = item;
1340                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1341                                              toolbar_data->get_btn,
1342                                            _("Receive Mail on current Account"), NULL);
1343                         break;
1344                 case A_SEND_QUEUED:
1345                         toolbar_data->send_btn = item; 
1346                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1347                                              toolbar_data->send_btn,
1348                                            _("Send Queued Message(s)"), NULL);
1349                         break;
1350                 case A_COMPOSE_EMAIL:
1351                         icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1352                         item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1353                                                             _("News"),
1354                                                             (""),
1355                                                             (""),
1356                                                             icon_news, G_CALLBACK(toolbar_buttons_cb), 
1357                                                             toolbar_item);
1358                         toolbar_data->compose_mail_btn = item; 
1359                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1360                                              toolbar_data->compose_mail_btn,
1361                                            _("Compose Email"), NULL);
1362                         toolbar_data->compose_news_btn = item_news;
1363                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1364                                              toolbar_data->compose_news_btn,
1365                                            _("Compose News"), NULL);
1366                         break;
1367                 case A_REPLY_MESSAGE:
1368                         toolbar_data->reply_btn = item;
1369                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1370                                              toolbar_data->reply_btn,
1371                                            _("Reply to Message"), NULL);
1372                         n_menu_entries = sizeof(reply_entries) / 
1373                                 sizeof(replysender_entries[0]);
1374                         reply_combo = gtkut_combo_button_create(toolbar_data->reply_btn,
1375                                               reply_entries, n_menu_entries,
1376                                               "<Reply>", (gpointer)toolbar_item);
1377                         gtk_button_set_relief(GTK_BUTTON(reply_combo->arrow),
1378                                               GTK_RELIEF_NONE);
1379                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1380                                                   GTK_WIDGET_PTR(reply_combo),
1381                                                   _("Reply to Message"), "Reply");
1382                         toolbar_data->reply_combo = reply_combo;
1383                         break;
1384                 case A_REPLY_SENDER:
1385                         toolbar_data->replysender_btn = item;
1386                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1387                                              toolbar_data->replysender_btn,
1388                                            _("Reply to Sender"), NULL);
1389                         n_menu_entries = sizeof(replysender_entries) / 
1390                                 sizeof(replysender_entries[0]);
1391                         replysender_combo = gtkut_combo_button_create(toolbar_data->replysender_btn,
1392                                               replysender_entries, n_menu_entries,
1393                                               "<ReplySender>", (gpointer)toolbar_item);
1394                         gtk_button_set_relief(GTK_BUTTON(replysender_combo->arrow),
1395                                               GTK_RELIEF_NONE);
1396                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1397                                                   GTK_WIDGET_PTR(replysender_combo),
1398                                                   _("Reply to Sender"), "ReplySender");
1399                         toolbar_data->replysender_combo = replysender_combo;
1400                         break;
1401                 case A_REPLY_ALL:
1402                         toolbar_data->replyall_btn = item;
1403                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1404                                              toolbar_data->replyall_btn,
1405                                            _("Reply to All"), NULL);
1406                         n_menu_entries = sizeof(replyall_entries) / 
1407                                 sizeof(replyall_entries[0]);
1408                         replyall_combo = gtkut_combo_button_create(toolbar_data->replyall_btn,
1409                                               replyall_entries, n_menu_entries,
1410                                               "<ReplyAll>", (gpointer)toolbar_item);
1411                         gtk_button_set_relief(GTK_BUTTON(replyall_combo->arrow),
1412                                               GTK_RELIEF_NONE);
1413                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1414                                                   GTK_WIDGET_PTR(replyall_combo),
1415                                                   _("Reply to All"), "ReplyAll");
1416                         toolbar_data->replyall_combo = replyall_combo;
1417                         break;
1418                 case A_REPLY_ML:
1419                         toolbar_data->replylist_btn = item;
1420                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1421                                              toolbar_data->replylist_btn,
1422                                            _("Reply to Mailing-list"), NULL);
1423                         n_menu_entries = sizeof(replylist_entries) / 
1424                                 sizeof(replylist_entries[0]);
1425                         replylist_combo = gtkut_combo_button_create(toolbar_data->replylist_btn,
1426                                               replylist_entries, n_menu_entries,
1427                                               "<ReplyList>", (gpointer)toolbar_item);
1428                         gtk_button_set_relief(GTK_BUTTON(replylist_combo->arrow),
1429                                               GTK_RELIEF_NONE);
1430                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1431                                                   GTK_WIDGET_PTR(replylist_combo),
1432                                                   _("Reply to Mailing-list"), "ReplyList");
1433                         toolbar_data->replylist_combo = replylist_combo;
1434                         break;
1435                 case A_FORWARD:
1436                         toolbar_data->fwd_btn = item;
1437                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1438                                              toolbar_data->fwd_btn,
1439                                              _("Forward Message"), NULL);
1440                         n_menu_entries = sizeof(forward_entries) / 
1441                                 sizeof(forward_entries[0]);
1442                         fwd_combo = gtkut_combo_button_create(toolbar_data->fwd_btn,
1443                                               forward_entries, n_menu_entries,
1444                                               "<Forward>", (gpointer)toolbar_item);
1445                         gtk_button_set_relief(GTK_BUTTON(fwd_combo->arrow),
1446                                               GTK_RELIEF_NONE);
1447                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1448                                                   GTK_WIDGET_PTR(fwd_combo),
1449                                                   _("Forward Message"), "Fwd");
1450                         toolbar_data->fwd_combo = fwd_combo;
1451                         break;
1452                 case A_DELETE:
1453                         toolbar_data->delete_btn = item;
1454                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1455                                              toolbar_data->delete_btn,
1456                                              _("Delete Message"), NULL);
1457                         break;
1458                 case A_EXECUTE:
1459                         toolbar_data->exec_btn = item;
1460                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1461                                              toolbar_data->exec_btn,
1462                                            _("Execute"), NULL);
1463                         break;
1464                 case A_GOTO_NEXT:
1465                         toolbar_data->next_btn = item;
1466                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1467                                              toolbar_data->next_btn,
1468                                              _("Goto Next Message"), NULL);
1469                         break;
1470                 
1471                 /* Compose Toolbar */
1472                 case A_SEND:
1473                         toolbar_data->send_btn = item;
1474                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1475                                              toolbar_data->send_btn, 
1476                                              _("Send Message"), NULL);
1477                         break;
1478                 case A_SENDL:
1479                         toolbar_data->sendl_btn = item;
1480                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1481                                              toolbar_data->sendl_btn,
1482                                              _("Put into queue folder and send later"), NULL);
1483                         break;
1484                 case A_DRAFT:
1485                         toolbar_data->draft_btn = item; 
1486                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1487                                              toolbar_data->draft_btn,
1488                                              _("Save to draft folder"), NULL);
1489                         break;
1490                 case A_INSERT:
1491                         toolbar_data->insert_btn = item; 
1492                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1493                                              toolbar_data->insert_btn,
1494                                              _("Insert file"), NULL);
1495                         break;
1496                 case A_ATTACH:
1497                         toolbar_data->attach_btn = item;
1498                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1499                                              toolbar_data->attach_btn,
1500                                              _("Attach file"), NULL);
1501                         break;
1502                 case A_SIG:
1503                         toolbar_data->sig_btn = item;
1504                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1505                                              toolbar_data->sig_btn,
1506                                              _("Insert signature"), NULL);
1507                         break;
1508                 case A_EXTEDITOR:
1509                         toolbar_data->exteditor_btn = item;
1510                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1511                                              toolbar_data->exteditor_btn,
1512                                              _("Edit with external editor"), NULL);
1513                         break;
1514                 case A_LINEWRAP_CURRENT:
1515                         toolbar_data->linewrap_current_btn = item;
1516                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1517                                              toolbar_data->linewrap_current_btn,
1518                                              _("Wrap long lines of current paragraph"), NULL);
1519                         break;
1520                 case A_LINEWRAP_ALL:
1521                         toolbar_data->linewrap_all_btn = item;
1522                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1523                                              toolbar_data->linewrap_all_btn,
1524                                              _("Wrap all long lines"), NULL);
1525                         break;
1526                 case A_ADDRBOOK:
1527                         toolbar_data->addrbook_btn = item;
1528                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1529                                              toolbar_data->addrbook_btn,
1530                                              _("Address book"), NULL);
1531                         break;
1532 #ifdef USE_ASPELL
1533                 case A_CHECK_SPELLING:
1534                         toolbar_data->spellcheck_btn = item;
1535                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1536                                              toolbar_data->spellcheck_btn,
1537                                              _("Check spelling"), NULL);
1538                         break;
1539 #endif
1540
1541                 case A_SYL_ACTIONS:
1542                         action_item = g_new0(ToolbarSylpheedActions, 1);
1543                         action_item->widget = item;
1544                         action_item->name   = g_strdup(toolbar_item->text);
1545
1546                         toolbar_data->action_list = 
1547                                 g_slist_append(toolbar_data->action_list,
1548                                                action_item);
1549
1550                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1551                                              item,
1552                                              action_item->name, NULL);
1553
1554                         gtk_widget_show(item);
1555                         break;
1556                 default:
1557                         /* find and set the tool tip text */
1558                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1559                                              item,
1560                                              toolbar_ret_descr_from_val
1561                                                 (toolbar_item->index),
1562                                              NULL);
1563                         break;
1564                 }
1565
1566         }
1567         toolbar_data->toolbar = toolbar;
1568         if (type == TOOLBAR_MAIN)
1569                 activate_compose_button(toolbar_data, 
1570                                         prefs_common.toolbar_style, 
1571                                         toolbar_data->compose_btn_type);
1572         
1573         gtk_widget_show_all(toolbar);
1574         
1575         return toolbar_data; 
1576 }
1577
1578 /**
1579  * Free toolbar structures
1580  */ 
1581 void toolbar_destroy(Toolbar * toolbar) {
1582
1583         TOOLBAR_DESTROY_ITEMS(toolbar->item_list);      
1584         TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1585 }
1586
1587 void toolbar_update(ToolbarType type, gpointer data)
1588 {
1589         Toolbar *toolbar_data;
1590         GtkWidget *handlebox;
1591         MainWindow *mainwin = (MainWindow*)data;
1592         Compose    *compose = (Compose*)data;
1593         MessageView *msgview = (MessageView*)data;
1594
1595         switch(type) {
1596         case TOOLBAR_MAIN:
1597                 toolbar_data = mainwin->toolbar;
1598                 handlebox    = mainwin->handlebox;
1599                 break;
1600         case TOOLBAR_COMPOSE:
1601                 toolbar_data = compose->toolbar;
1602                 handlebox    = compose->handlebox;
1603                 break;
1604         case TOOLBAR_MSGVIEW:
1605                 toolbar_data = msgview->toolbar;
1606                 handlebox    = msgview->handlebox;
1607                 break;
1608         default:
1609                 return;
1610         }
1611
1612         gtk_container_remove(GTK_CONTAINER(handlebox), 
1613                              GTK_WIDGET(toolbar_data->toolbar));
1614
1615         toolbar_init(toolbar_data);
1616         toolbar_data = toolbar_create(type, handlebox, data);
1617         switch(type) {
1618         case TOOLBAR_MAIN:
1619                 mainwin->toolbar = toolbar_data;
1620                 break;
1621         case TOOLBAR_COMPOSE:
1622                 compose->toolbar = toolbar_data;
1623                 break;
1624         case TOOLBAR_MSGVIEW:
1625                 msgview->toolbar = toolbar_data;
1626                 break;
1627         }
1628
1629         toolbar_style(type, prefs_common.toolbar_style, data);
1630
1631         if (type == TOOLBAR_MAIN)
1632                 toolbar_main_set_sensitive((MainWindow*)data);
1633 }
1634
1635 void toolbar_main_set_sensitive(gpointer data)
1636 {
1637         SensitiveCond state;
1638         gboolean sensitive;
1639         MainWindow *mainwin = (MainWindow*)data;
1640         Toolbar *toolbar = mainwin->toolbar;
1641         GSList *cur;
1642         GSList *entry_list = NULL;
1643         
1644         typedef struct _Entry Entry;
1645         struct _Entry {
1646                 GtkWidget *widget;
1647                 SensitiveCond cond;
1648                 gboolean empty;
1649         };
1650
1651 #define SET_WIDGET_COND(w, c)     \
1652 { \
1653         Entry *e = g_new0(Entry, 1); \
1654         e->widget = w; \
1655         e->cond   = c; \
1656         entry_list = g_slist_append(entry_list, e); \
1657 }
1658
1659         SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1660         SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1661         SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1662         SET_WIDGET_COND(toolbar->reply_btn,
1663                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1664         if (toolbar->reply_btn)
1665                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->reply_combo),
1666                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1667         SET_WIDGET_COND(toolbar->replyall_btn,
1668                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1669         if (toolbar->replyall_btn)
1670                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replyall_combo),
1671                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1672         SET_WIDGET_COND(toolbar->replylist_btn,
1673                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1674         if (toolbar->replylist_btn) 
1675                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replylist_combo),
1676                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1677         SET_WIDGET_COND(toolbar->replysender_btn,
1678                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1679         if (toolbar->replysender_btn)
1680                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replysender_combo),
1681                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1682         SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1683         if (toolbar->fwd_btn)
1684                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->fwd_combo),
1685                         M_HAVE_ACCOUNT|M_TARGET_EXIST); 
1686
1687         SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1688         SET_WIDGET_COND(toolbar->delete_btn,
1689                         M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1690         SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1691
1692         for (cur = toolbar->action_list; cur != NULL;  cur = cur->next) {
1693                 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1694                 
1695                 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1696         }
1697
1698 #undef SET_WIDGET_COND
1699
1700         state = main_window_get_current_state(mainwin);
1701
1702         for (cur = entry_list; cur != NULL; cur = cur->next) {
1703                 Entry *e = (Entry*) cur->data;
1704
1705                 if (e->widget != NULL) {
1706                         sensitive = ((e->cond & state) == e->cond);
1707                         gtk_widget_set_sensitive(e->widget, sensitive); 
1708                 }
1709         }
1710         
1711         while (entry_list != NULL) {
1712                 Entry *e = (Entry*) entry_list->data;
1713
1714                 if (e)
1715                         g_free(e);
1716                 entry_list = g_slist_remove(entry_list, e);
1717         }
1718
1719         g_slist_free(entry_list);
1720
1721         activate_compose_button(toolbar, 
1722                                 prefs_common.toolbar_style,
1723                                 toolbar->compose_btn_type);
1724 }
1725
1726 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1727 {
1728         Compose *compose = (Compose*)data;
1729         GSList *items = compose->toolbar->action_list;
1730
1731         if (compose->toolbar->send_btn)
1732                 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1733         if (compose->toolbar->sendl_btn)
1734                 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1735         if (compose->toolbar->draft_btn )
1736                 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1737         if (compose->toolbar->insert_btn )
1738                 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1739         if (compose->toolbar->attach_btn)
1740                 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1741         if (compose->toolbar->sig_btn)
1742                 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1743         if (compose->toolbar->exteditor_btn)
1744                 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1745         if (compose->toolbar->linewrap_current_btn)
1746                 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
1747         if (compose->toolbar->linewrap_all_btn)
1748                 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
1749         if (compose->toolbar->addrbook_btn)
1750                 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1751 #ifdef USE_ASPELL
1752         if (compose->toolbar->spellcheck_btn)
1753                 gtk_widget_set_sensitive(compose->toolbar->spellcheck_btn, sensitive);
1754 #endif
1755         for (; items != NULL; items = g_slist_next(items)) {
1756                 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1757                 gtk_widget_set_sensitive(item->widget, sensitive);
1758         }
1759 }
1760
1761 /**
1762  * Initialize toolbar structure
1763  **/
1764 void toolbar_init(Toolbar * toolbar) {
1765
1766         toolbar->toolbar                = NULL;
1767         toolbar->get_btn                = NULL;
1768         toolbar->getall_btn             = NULL;
1769         toolbar->send_btn               = NULL;
1770         toolbar->compose_mail_btn       = NULL;
1771         toolbar->compose_news_btn       = NULL;
1772         toolbar->reply_btn              = NULL;
1773         toolbar->replysender_btn        = NULL;
1774         toolbar->replyall_btn           = NULL;
1775         toolbar->replylist_btn          = NULL;
1776         toolbar->fwd_btn                = NULL;
1777         toolbar->delete_btn             = NULL;
1778         toolbar->next_btn               = NULL;
1779         toolbar->exec_btn               = NULL;
1780
1781         /* compose buttons */ 
1782         toolbar->sendl_btn              = NULL;
1783         toolbar->draft_btn              = NULL;
1784         toolbar->insert_btn             = NULL;
1785         toolbar->attach_btn             = NULL;
1786         toolbar->sig_btn                = NULL; 
1787         toolbar->exteditor_btn          = NULL; 
1788         toolbar->linewrap_current_btn   = NULL; 
1789         toolbar->linewrap_all_btn       = NULL; 
1790         toolbar->addrbook_btn           = NULL; 
1791 #ifdef USE_ASPELL
1792         toolbar->spellcheck_btn         = NULL;
1793 #endif
1794
1795         toolbar_destroy(toolbar);
1796 }
1797
1798 /*
1799  */
1800 static void toolbar_reply(gpointer data, guint action)
1801 {
1802         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1803         MainWindow *mainwin;
1804         MessageView *msgview;
1805         GSList *msginfo_list = NULL;
1806         gchar *body;
1807
1808         g_return_if_fail(toolbar_item != NULL);
1809
1810         switch (toolbar_item->type) {
1811         case TOOLBAR_MAIN:
1812                 mainwin = (MainWindow*)toolbar_item->parent;
1813                 msginfo_list = summary_get_selection(mainwin->summaryview);
1814                 msgview = (MessageView*)mainwin->messageview;
1815                 break;
1816         case TOOLBAR_MSGVIEW:
1817                 msgview = (MessageView*)toolbar_item->parent;
1818                 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
1819                 break;
1820         default:
1821                 return;
1822         }
1823
1824         g_return_if_fail(msgview != NULL);
1825         body = messageview_get_selection(msgview);
1826
1827         g_return_if_fail(msginfo_list != NULL);
1828         compose_reply_mode((ComposeMode)action, msginfo_list, body);
1829
1830         g_free(body);
1831         g_slist_free(msginfo_list);
1832
1833         /* TODO: update reply state ion summaryview */
1834 }
1835
1836
1837 /* exported functions */
1838
1839 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
1840 {
1841         MainWindow *mainwin = (MainWindow*)data;
1842
1843         inc_mail(mainwin, prefs_common.newmail_notify_manu);
1844 }
1845
1846 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
1847 {
1848         MainWindow *mainwin = (MainWindow*)data;
1849
1850         inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
1851 }
1852
1853 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
1854 {
1855         GList *list;
1856
1857         if (prefs_common.work_offline)
1858                 if (alertpanel(_("Offline warning"), 
1859                                _("You're working offline. Override?"),
1860                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1861                 return;
1862
1863         for (list = folder_get_list(); list != NULL; list = list->next) {
1864                 Folder *folder = list->data;
1865
1866                 if (folder->queue) {
1867                         procmsg_send_queue(folder->queue, prefs_common.savemsg);
1868                         folder_item_scan(folder->queue);
1869                 }
1870         }
1871 }
1872
1873 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
1874 {
1875         MainWindow *mainwin = (MainWindow*)data;
1876         PrefsAccount *ac = NULL;
1877         FolderItem *item = mainwin->summaryview->folder_item;   
1878         GList * list;
1879         GList * cur;
1880
1881         if (item) {
1882                 ac = account_find_from_item(item);
1883                 if (ac && ac->protocol != A_NNTP) {
1884                         compose_new_with_folderitem(ac, item);          /* CLAWS */
1885                         return;
1886                 }
1887         }
1888
1889         /*
1890          * CLAWS - use current account
1891          */
1892         if (cur_account && (cur_account->protocol != A_NNTP)) {
1893                 compose_new_with_folderitem(cur_account, item);
1894                 return;
1895         }
1896
1897         /*
1898          * CLAWS - just get the first one
1899          */
1900         list = account_get_list();
1901         for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
1902                 ac = (PrefsAccount *) cur->data;
1903                 if (ac->protocol != A_NNTP) {
1904                         compose_new_with_folderitem(ac, item);
1905                         return;
1906                 }
1907         }
1908 }
1909
1910 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
1911 {
1912         MainWindow *mainwin = (MainWindow*)data;
1913         PrefsAccount * ac = NULL;
1914         GList * list;
1915         GList * cur;
1916
1917         if (mainwin->summaryview->folder_item) {
1918                 ac = mainwin->summaryview->folder_item->folder->account;
1919                 if (ac && ac->protocol == A_NNTP) {
1920                         compose_new(ac,
1921                                     mainwin->summaryview->folder_item->path,
1922                                     NULL);
1923                         return;
1924                 }
1925         }
1926
1927         list = account_get_list();
1928         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
1929                 ac = (PrefsAccount *) cur->data;
1930                 if (ac->protocol == A_NNTP) {
1931                         compose_new(ac, NULL, NULL);
1932                         return;
1933                 }
1934         }
1935 }