This commit was manufactured by cvs2svn to create branch 'gtk2'.
[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 #warning FIXME_GTK2
540                         if (toolbar_item->index != A_SEPARATOR) {
541                                 fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
542                                         TOOLBAR_TAG_ITEM, 
543                                         TOOLBAR_ICON_FILE, toolbar_item->file,
544                                         TOOLBAR_ICON_TEXT);
545                                 xml_file_put_escape_str(fp, toolbar_item->text);
546                                 fprintf(fp, "\" %s=\"%s\"/>\n",
547                                         TOOLBAR_ICON_ACTION, 
548                                         toolbar_ret_text_from_val(toolbar_item->index));
549                         } else {
550                                 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR); 
551                         }
552                 }
553
554                 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);      
555         
556                 if (prefs_file_close (pfile) < 0 ) 
557                         g_warning("failed to write toolbar configuration to file\n");
558         } else
559                 g_warning("failed to open toolbar configuration file for writing\n");
560 }
561
562 void toolbar_read_config_file(ToolbarType source)
563 {
564         XMLFile *file   = NULL;
565         gchar *fileSpec = NULL;
566         GList *attr;
567         gboolean retVal;
568         jmp_buf    jumper;
569
570         debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
571
572         fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
573         file = xml_open_file(fileSpec);
574         g_free(fileSpec);
575
576         toolbar_clear_list(source);
577
578         if (file) {
579                 if ((setjmp(jumper))
580                 || (xml_get_dtd(file))
581                 || (xml_parse_next_tag(file))
582                 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
583                         xml_close_file(file);
584                         return;
585                 }
586
587                 attr = xml_get_current_tag_attr(file);
588                 
589                 retVal = TRUE;
590                 for (;;) {
591                         if (!file->level) 
592                                 break;
593                         /* Get item tag */
594                         if (xml_parse_next_tag(file)) 
595                                 longjmp(jumper, 1);
596
597                         /* Get next tag (icon, icon_text or icon_action) */
598                         if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
599                                 toolbar_parse_item(file, source);
600                         } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
601                                 ToolbarItem *item = g_new0(ToolbarItem, 1);
602                         
603                                 item->file   = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
604                                 item->index  = A_SEPARATOR;
605                                 toolbar_config[source].item_list = 
606                                         g_slist_append(toolbar_config[source].item_list, item);
607                         }
608
609                 }
610                 xml_close_file(file);
611         }
612
613         if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
614
615                 if (source == TOOLBAR_MAIN) 
616                         toolbar_set_default(TOOLBAR_MAIN);
617                 else if (source == TOOLBAR_COMPOSE) 
618                         toolbar_set_default(TOOLBAR_COMPOSE);
619                 else if (source == TOOLBAR_MSGVIEW) 
620                         toolbar_set_default(TOOLBAR_MSGVIEW);
621                 else {          
622                         g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
623                         return;
624                 }
625
626                 toolbar_save_config_file(source);
627         }
628 }
629
630 /*
631  * clears list of toolbar items read from configuration files
632  */
633 void toolbar_clear_list(ToolbarType source)
634 {
635         while (toolbar_config[source].item_list != NULL) {
636                 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
637                 
638                 toolbar_config[source].item_list = 
639                         g_slist_remove(toolbar_config[source].item_list, item);
640
641                 if (item->file)
642                         g_free(item->file);
643                 if (item->text)
644                         g_free(item->text);
645                 g_free(item);   
646         }
647         g_slist_free(toolbar_config[source].item_list);
648 }
649
650
651 /* 
652  * return list of Toolbar items
653  */
654 GSList *toolbar_get_list(ToolbarType source)
655 {
656         GSList *list = NULL;
657
658         if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
659                 list = toolbar_config[source].item_list;
660
661         return list;
662 }
663
664 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
665 {
666         ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
667
668         toolbar_item->file  = g_strdup(t_item->file);
669         toolbar_item->text  = g_strdup(t_item->text);
670         toolbar_item->index = t_item->index;
671         
672         toolbar_config[source].item_list = 
673                 g_slist_append(toolbar_config[source].item_list,
674                                toolbar_item);
675 }
676
677 void toolbar_action_execute(GtkWidget    *widget,
678                             GSList       *action_list, 
679                             gpointer     data,
680                             gint         source) 
681 {
682         GSList *cur, *lop;
683         gchar *action, *action_p;
684         gboolean found = FALSE;
685         gint i = 0;
686
687         for (cur = action_list; cur != NULL;  cur = cur->next) {
688                 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
689
690                 if (widget == act->widget) {
691                         
692                         for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
693                                 action = g_strdup((gchar*)lop->data);
694
695                                 action_p = strstr(action, ": ");
696                                 action_p[0] = 0x00;
697                                 if (g_strcasecmp(act->name, action) == 0) {
698                                         found = TRUE;
699                                         g_free(action);
700                                         break;
701                                 } else 
702                                         i++;
703                                 g_free(action);
704                         }
705                         if (found) 
706                                 break;
707                 }
708         }
709
710         if (found) 
711                 actions_execute(data, i, widget, source);
712         else
713                 g_warning ("Error: did not find Sylpheed Action to execute");
714 }
715
716 static void activate_compose_button (Toolbar           *toolbar,
717                                      ToolbarStyle      style,
718                                      ComposeButtonType type)
719 {
720         if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
721                 return;
722
723         gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn 
724                         : toolbar->compose_news_btn);
725         gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
726                         : toolbar->compose_mail_btn);
727         toolbar->compose_btn_type = type;       
728 }
729
730 void toolbar_set_compose_button(Toolbar            *toolbar, 
731                                 ComposeButtonType  compose_btn_type)
732 {
733         if (toolbar->compose_btn_type != compose_btn_type)
734                 activate_compose_button(toolbar, 
735                                         prefs_common.toolbar_style,
736                                         compose_btn_type);
737 }
738
739 void toolbar_toggle(guint action, gpointer data)
740 {
741         MainWindow *mainwin = (MainWindow*)data;
742         GList *list;
743         GList *cur;
744
745         g_return_if_fail(mainwin != NULL);
746
747         toolbar_style(TOOLBAR_MAIN, action, mainwin);
748
749         list = compose_get_compose_list();
750         for (cur = list; cur != NULL; cur = cur->next) {
751                 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
752         }
753         list = messageview_get_msgview_list();
754         for (cur = list; cur != NULL; cur = cur->next) {
755                 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
756         }
757         
758 }
759
760 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
761 {
762         switch ((ToolbarStyle)action) {
763         case TOOLBAR_NONE:
764                 gtk_widget_hide(handlebox_wid);
765                 break;
766         case TOOLBAR_ICON:
767                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
768                                       GTK_TOOLBAR_ICONS);
769                 break;
770         case TOOLBAR_TEXT:
771                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
772                                       GTK_TOOLBAR_TEXT);
773                 break;
774         case TOOLBAR_BOTH:
775                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
776                                       GTK_TOOLBAR_BOTH);
777                 break;
778         default:
779                 return;
780         }
781
782         prefs_common.toolbar_style = (ToolbarStyle)action;
783         gtk_widget_set_usize(handlebox_wid, 1, -1);
784         
785         if (prefs_common.toolbar_style != TOOLBAR_NONE) {
786                 gtk_widget_show(handlebox_wid);
787                 gtk_widget_queue_resize(handlebox_wid);
788         }
789 }
790 /*
791  * Change the style of toolbar
792  */
793 static void toolbar_style(ToolbarType type, guint action, gpointer data)
794 {
795         GtkWidget  *handlebox_wid;
796         GtkWidget  *toolbar_wid;
797         MainWindow *mainwin = (MainWindow*)data;
798         Compose    *compose = (Compose*)data;
799         MessageView *msgview = (MessageView*)data;
800         
801         g_return_if_fail(data != NULL);
802         
803         switch (type) {
804         case TOOLBAR_MAIN:
805                 handlebox_wid = mainwin->handlebox;
806                 toolbar_wid = mainwin->toolbar->toolbar;
807                 break;
808         case TOOLBAR_COMPOSE:
809                 handlebox_wid = compose->handlebox;
810                 toolbar_wid = compose->toolbar->toolbar;
811                 break;
812         case TOOLBAR_MSGVIEW: 
813                 handlebox_wid = msgview->handlebox;
814                 toolbar_wid = msgview->toolbar->toolbar;
815                 break;
816         default:
817
818                 return;
819         }
820         toolbar_set_style(toolbar_wid, handlebox_wid, action);
821 }
822
823 /* Toolbar handling */
824 static void toolbar_inc_cb(GtkWidget    *widget,
825                            gpointer      data)
826 {
827         ToolbarItem *toolbar_item = (ToolbarItem*)data;
828         MainWindow *mainwin;
829
830         g_return_if_fail(toolbar_item != NULL);
831
832         switch (toolbar_item->type) {
833         case TOOLBAR_MAIN:
834                 mainwin = (MainWindow*)toolbar_item->parent;    
835                 inc_mail_cb(mainwin, 0, NULL);
836                 break;
837         default:
838                 break;
839         }
840 }
841
842 static void toolbar_inc_all_cb(GtkWidget        *widget,
843                                gpointer          data)
844 {
845         ToolbarItem *toolbar_item = (ToolbarItem*)data;
846         MainWindow *mainwin;
847
848         g_return_if_fail(toolbar_item != NULL);
849
850         switch (toolbar_item->type) {
851         case TOOLBAR_MAIN:
852                 mainwin = (MainWindow*)toolbar_item->parent;
853                 inc_all_account_mail_cb(mainwin, 0, NULL);
854                 break;
855         default:
856                 break;
857         }
858 }
859
860 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
861 {
862         ToolbarItem *toolbar_item = (ToolbarItem*)data;
863         MainWindow *mainwin;
864
865         g_return_if_fail(toolbar_item != NULL);
866
867         switch (toolbar_item->type) {
868         case TOOLBAR_MAIN:
869                 mainwin = (MainWindow*)toolbar_item->parent;
870                 send_queue_cb(mainwin, 0, NULL);
871                 break;
872         default:
873                 break;
874         }
875 }
876
877 static void toolbar_exec_cb(GtkWidget   *widget,
878                             gpointer     data)
879 {
880         MainWindow *mainwin = get_mainwin(data);
881
882         g_return_if_fail(mainwin != NULL);
883         summary_execute(mainwin->summaryview);
884 }
885
886 /*
887  * Delete current/selected(s) message(s)
888  */
889 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
890 {
891         ToolbarItem *toolbar_item = (ToolbarItem*)data;
892         MainWindow *mainwin;
893
894         g_return_if_fail(toolbar_item != NULL);
895         g_return_if_fail(toolbar_item->parent);
896         
897         switch (toolbar_item->type) {
898         case TOOLBAR_MSGVIEW:
899                 messageview_delete((MessageView *)toolbar_item->parent);
900                 break;
901         case TOOLBAR_MAIN:
902                 mainwin = (MainWindow *)toolbar_item->parent;
903                 summary_delete(mainwin->summaryview);
904                 break;
905         default: 
906                 debug_print("toolbar event not supported\n");
907                 break;
908         }
909 }
910
911
912 /*
913  * Compose new message
914  */
915 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
916 {
917         ToolbarItem *toolbar_item = (ToolbarItem*)data;
918         MainWindow *mainwin;
919         MessageView *msgview;
920
921         g_return_if_fail(toolbar_item != NULL);
922
923         switch (toolbar_item->type) {
924         case TOOLBAR_MAIN:
925                 mainwin = (MainWindow*)toolbar_item->parent;
926                 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS) 
927                         compose_news_cb(mainwin, 0, NULL);
928                 else
929                         compose_mail_cb(mainwin, 0, NULL);
930                 break;
931         case TOOLBAR_MSGVIEW:
932                 msgview = (MessageView*)toolbar_item->parent;
933                 compose_new_with_folderitem(NULL, 
934                                             msgview->msginfo->folder);
935                 break;  
936         default:
937                 debug_print("toolbar event not supported\n");
938         }
939 }
940
941
942 /*
943  * Reply Message
944  */
945 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
946 {
947         toolbar_reply(data, prefs_common.reply_with_quote ? 
948                       COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
949 }
950
951
952 /*
953  * Reply message to Sender and All recipients
954  */
955 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
956 {
957         toolbar_reply(data,
958                       prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
959                       : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
960 }
961
962
963 /*
964  * Reply to Mailing List
965  */
966 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
967 {
968         toolbar_reply(data, 
969                       prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE 
970                       : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
971 }
972
973
974 /*
975  * Reply to sender of message
976  */ 
977 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
978 {
979         toolbar_reply(data, 
980                       prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
981                       : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
982 }
983
984 /*
985  * Open addressbook
986  */ 
987 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
988 {
989         ToolbarItem *toolbar_item = (ToolbarItem*)data;
990         Compose *compose;
991
992         g_return_if_fail(toolbar_item != NULL);
993
994         switch (toolbar_item->type) {
995         case TOOLBAR_MAIN:
996         case TOOLBAR_MSGVIEW:
997                 compose = NULL;
998                 break;
999         case TOOLBAR_COMPOSE:
1000                 compose = (Compose *)toolbar_item->parent;
1001                 break;
1002         default:
1003                 return;
1004         }
1005         addressbook_open(compose);
1006 }
1007
1008
1009 /*
1010  * Forward current/selected(s) message(s)
1011  */
1012 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1013 {
1014         toolbar_reply(data, COMPOSE_FORWARD);
1015 }
1016
1017
1018 /*
1019  * Goto Next Unread Message
1020  */
1021 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1022 {
1023         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1024         MainWindow *mainwin;
1025         MessageView *msgview;
1026
1027         g_return_if_fail(toolbar_item != NULL);
1028
1029         switch (toolbar_item->type) {
1030         case TOOLBAR_MAIN:
1031                 mainwin = (MainWindow*)toolbar_item->parent;
1032                 summary_select_next_unread(mainwin->summaryview);
1033                 break;
1034                 
1035         case TOOLBAR_MSGVIEW:
1036                 msgview = (MessageView*)toolbar_item->parent;
1037                 summary_select_next_unread(msgview->mainwin->summaryview);
1038                 
1039                 /* Now we need to update the messageview window */
1040                 if (msgview->mainwin->summaryview->selected) {
1041                         GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1042                         
1043                         MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree, 
1044                                                                         msgview->mainwin->summaryview->selected);
1045                        
1046                         messageview_show(msgview, msginfo, 
1047                                          msgview->all_headers);
1048                 } else {
1049                         gtk_widget_destroy(msgview->window);
1050                 }
1051                 break;
1052         default:
1053                 debug_print("toolbar event not supported\n");
1054         }
1055 }
1056
1057 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1058 {
1059         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1060         MainWindow *mainwin;
1061
1062         g_return_if_fail(toolbar_item != NULL);
1063
1064         switch (toolbar_item->type) {
1065         case TOOLBAR_MAIN:
1066                 mainwin = (MainWindow *) toolbar_item->parent;
1067                 summary_toggle_ignore_thread(mainwin->summaryview);
1068                 break;
1069         case TOOLBAR_MSGVIEW:
1070                 /* TODO: see toolbar_next_unread_cb() if you need
1071                  * this in the message view */
1072                 break;
1073         default:
1074                 debug_print("toolbar event not supported\n");
1075                 break;
1076         }
1077 }
1078
1079 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1080 {
1081         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1082         MainWindow *mainwin;
1083
1084         g_return_if_fail(toolbar_item != NULL);
1085
1086         switch (toolbar_item->type) {
1087         case TOOLBAR_MAIN:
1088                 mainwin = (MainWindow *) toolbar_item->parent;
1089                 summary_print(mainwin->summaryview);
1090                 break;
1091         case TOOLBAR_MSGVIEW:
1092                 /* TODO: see toolbar_next_unread_cb() if you need
1093                  * this in the message view */
1094                 break;
1095         default:
1096                 debug_print("toolbar event not supported\n");
1097                 break;
1098         }
1099 }
1100
1101 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1102 {
1103         compose_toolbar_cb(A_SEND, data);
1104 }
1105
1106 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1107 {
1108         compose_toolbar_cb(A_SENDL, data);
1109 }
1110
1111 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1112 {
1113         compose_toolbar_cb(A_DRAFT, data);
1114 }
1115
1116 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1117 {
1118         compose_toolbar_cb(A_INSERT, data);
1119 }
1120
1121 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1122 {
1123         compose_toolbar_cb(A_ATTACH, data);
1124 }
1125
1126 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1127 {
1128         compose_toolbar_cb(A_SIG, data);
1129 }
1130
1131 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1132 {
1133         compose_toolbar_cb(A_EXTEDITOR, data);
1134 }
1135
1136 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1137 {
1138         compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1139 }
1140
1141 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1142 {
1143         compose_toolbar_cb(A_LINEWRAP_ALL, data);
1144 }
1145
1146 #ifdef USE_ASPELL
1147 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1148 {
1149         compose_toolbar_cb(A_CHECK_SPELLING, data);
1150 }
1151 #endif
1152 /*
1153  * Execute actions from toolbar
1154  */
1155 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1156 {
1157         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1158         GSList *action_list;
1159         MainWindow *mainwin;
1160         Compose *compose;
1161         MessageView *msgview;
1162         gpointer parent = toolbar_item->parent;
1163
1164         g_return_if_fail(toolbar_item != NULL);
1165
1166         switch (toolbar_item->type) {
1167         case TOOLBAR_MAIN:
1168                 mainwin = (MainWindow*)parent;
1169                 action_list = mainwin->toolbar->action_list;
1170                 break;
1171         case TOOLBAR_COMPOSE:
1172                 compose = (Compose*)parent;
1173                 action_list = compose->toolbar->action_list;
1174                 break;
1175         case TOOLBAR_MSGVIEW:
1176                 msgview = (MessageView*)parent;
1177                 action_list = msgview->toolbar->action_list;
1178                 break;
1179         default:
1180                 debug_print("toolbar event not supported\n");
1181                 return;
1182         }
1183         toolbar_action_execute(widget, action_list, parent, toolbar_item->type);        
1184 }
1185
1186 static MainWindow *get_mainwin(gpointer data)
1187 {
1188         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1189         MainWindow *mainwin = NULL;
1190         MessageView *msgview;
1191
1192         g_return_val_if_fail(toolbar_item != NULL, NULL);
1193
1194         switch(toolbar_item->type) {
1195         case TOOLBAR_MAIN:
1196                 mainwin = (MainWindow*)toolbar_item->parent;
1197                 break;
1198         case TOOLBAR_MSGVIEW:
1199                 msgview = (MessageView*)toolbar_item->parent;
1200                 mainwin = (MainWindow*)msgview->mainwin;
1201                 break;
1202         default:
1203                 break;
1204         }
1205
1206         return mainwin;
1207 }
1208
1209 static void toolbar_buttons_cb(GtkWidget   *widget, 
1210                                ToolbarItem *item)
1211 {
1212         gint num_items;
1213         gint i;
1214         struct {
1215                 gint   index;
1216                 void (*func)(GtkWidget *widget, gpointer data);
1217         } callbacks[] = {
1218                 { A_RECEIVE_ALL,        toolbar_inc_all_cb              },
1219                 { A_RECEIVE_CUR,        toolbar_inc_cb                  },
1220                 { A_SEND_QUEUED,        toolbar_send_queued_cb          },
1221                 { A_COMPOSE_EMAIL,      toolbar_compose_cb              },
1222                 { A_COMPOSE_NEWS,       toolbar_compose_cb              },
1223                 { A_REPLY_MESSAGE,      toolbar_reply_cb                },
1224                 { A_REPLY_SENDER,       toolbar_reply_to_sender_cb      },
1225                 { A_REPLY_ALL,          toolbar_reply_to_all_cb         },
1226                 { A_REPLY_ML,           toolbar_reply_to_list_cb        },
1227                 { A_FORWARD,            toolbar_forward_cb              },
1228                 { A_DELETE,             toolbar_delete_cb               },
1229                 { A_EXECUTE,            toolbar_exec_cb                 },
1230                 { A_GOTO_NEXT,          toolbar_next_unread_cb          },
1231                 { A_IGNORE_THREAD,      toolbar_ignore_thread_cb        },
1232                 { A_PRINT,              toolbar_print_cb                },
1233
1234                 { A_SEND,               toolbar_send_cb                 },
1235                 { A_SENDL,              toolbar_send_later_cb           },
1236                 { A_DRAFT,              toolbar_draft_cb                },
1237                 { A_INSERT,             toolbar_insert_cb               },
1238                 { A_ATTACH,             toolbar_attach_cb               },
1239                 { A_SIG,                toolbar_sig_cb                  },
1240                 { A_EXTEDITOR,          toolbar_ext_editor_cb           },
1241                 { A_LINEWRAP_CURRENT,   toolbar_linewrap_current_cb     },
1242                 { A_LINEWRAP_ALL,       toolbar_linewrap_all_cb         },
1243                 { A_ADDRBOOK,           toolbar_addrbook_cb             },
1244 #ifdef USE_ASPELL
1245                 { A_CHECK_SPELLING,     toolbar_check_spelling_cb       },
1246 #endif
1247                 { A_SYL_ACTIONS,        toolbar_actions_execute_cb      }
1248         };
1249
1250         num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1251
1252         for (i = 0; i < num_items; i++) {
1253                 if (callbacks[i].index == item->index) {
1254                         callbacks[i].func(widget, item);
1255                         return;
1256                 }
1257         }
1258 }
1259
1260 /**
1261  * Create a new toolbar with specified type
1262  * if a callback list is passed it will be used before the 
1263  * common callback list
1264  **/
1265 Toolbar *toolbar_create(ToolbarType      type, 
1266                         GtkWidget       *container,
1267                         gpointer         data)
1268 {
1269         ToolbarItem *toolbar_item;
1270
1271         GtkWidget *toolbar;
1272         GtkWidget *icon_wid = NULL;
1273         GtkWidget *icon_news;
1274         GtkWidget *item;
1275         GtkWidget *item_news;
1276
1277         guint n_menu_entries;
1278         ComboButton *reply_combo;
1279         ComboButton *replyall_combo;
1280         ComboButton *replylist_combo;
1281         ComboButton *replysender_combo;
1282         ComboButton *fwd_combo;
1283
1284         GtkTooltips *toolbar_tips;
1285         ToolbarSylpheedActions *action_item;
1286         GSList *cur;
1287         GSList *toolbar_list;
1288         Toolbar *toolbar_data;
1289
1290         
1291         toolbar_tips = gtk_tooltips_new();
1292         
1293         toolbar_read_config_file(type);
1294         toolbar_list = toolbar_get_list(type);
1295
1296         toolbar_data = g_new0(Toolbar, 1); 
1297
1298         toolbar = gtk_toolbar_new();
1299         gtk_container_add(GTK_CONTAINER(container), toolbar);
1300         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1301         gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1302         gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1303         
1304         for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1305
1306                 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1307                         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1308                         continue;
1309                 }
1310                 
1311                 toolbar_item = g_new0(ToolbarItem, 1); 
1312                 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1313                 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1314                 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1315                 toolbar_item->parent = data;
1316                 toolbar_item->type = type;
1317
1318                 /* collect toolbar items in list to keep track */
1319                 toolbar_data->item_list = 
1320                         g_slist_append(toolbar_data->item_list, 
1321                                        toolbar_item);
1322
1323                 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1324                 item  = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1325                                                 toolbar_item->text,
1326                                                 (""),
1327                                                 (""),
1328                                                 icon_wid, G_CALLBACK(toolbar_buttons_cb), 
1329                                                 toolbar_item);
1330                 
1331                 switch (toolbar_item->index) {
1332
1333                 case A_RECEIVE_ALL:
1334                         toolbar_data->getall_btn = item;
1335                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1336                                              toolbar_data->getall_btn, 
1337                                            _("Receive Mail on all Accounts"), NULL);
1338                         break;
1339                 case A_RECEIVE_CUR:
1340                         toolbar_data->get_btn = item;
1341                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1342                                              toolbar_data->get_btn,
1343                                            _("Receive Mail on current Account"), NULL);
1344                         break;
1345                 case A_SEND_QUEUED:
1346                         toolbar_data->send_btn = item; 
1347                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1348                                              toolbar_data->send_btn,
1349                                            _("Send Queued Message(s)"), NULL);
1350                         break;
1351                 case A_COMPOSE_EMAIL:
1352                         icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1353                         item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1354                                                             _("News"),
1355                                                             (""),
1356                                                             (""),
1357                                                             icon_news, G_CALLBACK(toolbar_buttons_cb), 
1358                                                             toolbar_item);
1359                         toolbar_data->compose_mail_btn = item; 
1360                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1361                                              toolbar_data->compose_mail_btn,
1362                                            _("Compose Email"), NULL);
1363                         toolbar_data->compose_news_btn = item_news;
1364                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1365                                              toolbar_data->compose_news_btn,
1366                                            _("Compose News"), NULL);
1367                         break;
1368                 case A_REPLY_MESSAGE:
1369                         toolbar_data->reply_btn = item;
1370                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1371                                              toolbar_data->reply_btn,
1372                                            _("Reply to Message"), NULL);
1373                         n_menu_entries = sizeof(reply_entries) / 
1374                                 sizeof(replysender_entries[0]);
1375                         reply_combo = gtkut_combo_button_create(toolbar_data->reply_btn,
1376                                               reply_entries, n_menu_entries,
1377                                               "<Reply>", (gpointer)toolbar_item);
1378                         gtk_button_set_relief(GTK_BUTTON(reply_combo->arrow),
1379                                               GTK_RELIEF_NONE);
1380                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1381                                                   GTK_WIDGET_PTR(reply_combo),
1382                                                   _("Reply to Message"), "Reply");
1383                         toolbar_data->reply_combo = reply_combo;
1384                         break;
1385                 case A_REPLY_SENDER:
1386                         toolbar_data->replysender_btn = item;
1387                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1388                                              toolbar_data->replysender_btn,
1389                                            _("Reply to Sender"), NULL);
1390                         n_menu_entries = sizeof(replysender_entries) / 
1391                                 sizeof(replysender_entries[0]);
1392                         replysender_combo = gtkut_combo_button_create(toolbar_data->replysender_btn,
1393                                               replysender_entries, n_menu_entries,
1394                                               "<ReplySender>", (gpointer)toolbar_item);
1395                         gtk_button_set_relief(GTK_BUTTON(replysender_combo->arrow),
1396                                               GTK_RELIEF_NONE);
1397                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1398                                                   GTK_WIDGET_PTR(replysender_combo),
1399                                                   _("Reply to Sender"), "ReplySender");
1400                         toolbar_data->replysender_combo = replysender_combo;
1401                         break;
1402                 case A_REPLY_ALL:
1403                         toolbar_data->replyall_btn = item;
1404                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1405                                              toolbar_data->replyall_btn,
1406                                            _("Reply to All"), NULL);
1407                         n_menu_entries = sizeof(replyall_entries) / 
1408                                 sizeof(replyall_entries[0]);
1409                         replyall_combo = gtkut_combo_button_create(toolbar_data->replyall_btn,
1410                                               replyall_entries, n_menu_entries,
1411                                               "<ReplyAll>", (gpointer)toolbar_item);
1412                         gtk_button_set_relief(GTK_BUTTON(replyall_combo->arrow),
1413                                               GTK_RELIEF_NONE);
1414                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1415                                                   GTK_WIDGET_PTR(replyall_combo),
1416                                                   _("Reply to All"), "ReplyAll");
1417                         toolbar_data->replyall_combo = replyall_combo;
1418                         break;
1419                 case A_REPLY_ML:
1420                         toolbar_data->replylist_btn = item;
1421                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1422                                              toolbar_data->replylist_btn,
1423                                            _("Reply to Mailing-list"), NULL);
1424                         n_menu_entries = sizeof(replylist_entries) / 
1425                                 sizeof(replylist_entries[0]);
1426                         replylist_combo = gtkut_combo_button_create(toolbar_data->replylist_btn,
1427                                               replylist_entries, n_menu_entries,
1428                                               "<ReplyList>", (gpointer)toolbar_item);
1429                         gtk_button_set_relief(GTK_BUTTON(replylist_combo->arrow),
1430                                               GTK_RELIEF_NONE);
1431                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1432                                                   GTK_WIDGET_PTR(replylist_combo),
1433                                                   _("Reply to Mailing-list"), "ReplyList");
1434                         toolbar_data->replylist_combo = replylist_combo;
1435                         break;
1436                 case A_FORWARD:
1437                         toolbar_data->fwd_btn = item;
1438                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1439                                              toolbar_data->fwd_btn,
1440                                              _("Forward Message"), NULL);
1441                         n_menu_entries = sizeof(forward_entries) / 
1442                                 sizeof(forward_entries[0]);
1443                         fwd_combo = gtkut_combo_button_create(toolbar_data->fwd_btn,
1444                                               forward_entries, n_menu_entries,
1445                                               "<Forward>", (gpointer)toolbar_item);
1446                         gtk_button_set_relief(GTK_BUTTON(fwd_combo->arrow),
1447                                               GTK_RELIEF_NONE);
1448                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1449                                                   GTK_WIDGET_PTR(fwd_combo),
1450                                                   _("Forward Message"), "Fwd");
1451                         toolbar_data->fwd_combo = fwd_combo;
1452                         break;
1453                 case A_DELETE:
1454                         toolbar_data->delete_btn = item;
1455                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1456                                              toolbar_data->delete_btn,
1457                                              _("Delete Message"), NULL);
1458                         break;
1459                 case A_EXECUTE:
1460                         toolbar_data->exec_btn = item;
1461                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1462                                              toolbar_data->exec_btn,
1463                                            _("Execute"), NULL);
1464                         break;
1465                 case A_GOTO_NEXT:
1466                         toolbar_data->next_btn = item;
1467                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1468                                              toolbar_data->next_btn,
1469                                              _("Goto Next Message"), NULL);
1470                         break;
1471                 
1472                 /* Compose Toolbar */
1473                 case A_SEND:
1474                         toolbar_data->send_btn = item;
1475                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1476                                              toolbar_data->send_btn, 
1477                                              _("Send Message"), NULL);
1478                         break;
1479                 case A_SENDL:
1480                         toolbar_data->sendl_btn = item;
1481                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1482                                              toolbar_data->sendl_btn,
1483                                              _("Put into queue folder and send later"), NULL);
1484                         break;
1485                 case A_DRAFT:
1486                         toolbar_data->draft_btn = item; 
1487                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1488                                              toolbar_data->draft_btn,
1489                                              _("Save to draft folder"), NULL);
1490                         break;
1491                 case A_INSERT:
1492                         toolbar_data->insert_btn = item; 
1493                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1494                                              toolbar_data->insert_btn,
1495                                              _("Insert file"), NULL);
1496                         break;
1497                 case A_ATTACH:
1498                         toolbar_data->attach_btn = item;
1499                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1500                                              toolbar_data->attach_btn,
1501                                              _("Attach file"), NULL);
1502                         break;
1503                 case A_SIG:
1504                         toolbar_data->sig_btn = item;
1505                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1506                                              toolbar_data->sig_btn,
1507                                              _("Insert signature"), NULL);
1508                         break;
1509                 case A_EXTEDITOR:
1510                         toolbar_data->exteditor_btn = item;
1511                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1512                                              toolbar_data->exteditor_btn,
1513                                              _("Edit with external editor"), NULL);
1514                         break;
1515                 case A_LINEWRAP_CURRENT:
1516                         toolbar_data->linewrap_current_btn = item;
1517                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1518                                              toolbar_data->linewrap_current_btn,
1519                                              _("Wrap long lines of current paragraph"), NULL);
1520                         break;
1521                 case A_LINEWRAP_ALL:
1522                         toolbar_data->linewrap_all_btn = item;
1523                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1524                                              toolbar_data->linewrap_all_btn,
1525                                              _("Wrap all long lines"), NULL);
1526                         break;
1527                 case A_ADDRBOOK:
1528                         toolbar_data->addrbook_btn = item;
1529                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1530                                              toolbar_data->addrbook_btn,
1531                                              _("Address book"), NULL);
1532                         break;
1533 #ifdef USE_ASPELL
1534                 case A_CHECK_SPELLING:
1535                         toolbar_data->spellcheck_btn = item;
1536                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1537                                              toolbar_data->spellcheck_btn,
1538                                              _("Check spelling"), NULL);
1539                         break;
1540 #endif
1541
1542                 case A_SYL_ACTIONS:
1543                         action_item = g_new0(ToolbarSylpheedActions, 1);
1544                         action_item->widget = item;
1545                         action_item->name   = g_strdup(toolbar_item->text);
1546
1547                         toolbar_data->action_list = 
1548                                 g_slist_append(toolbar_data->action_list,
1549                                                action_item);
1550
1551                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1552                                              item,
1553                                              action_item->name, NULL);
1554
1555                         gtk_widget_show(item);
1556                         break;
1557                 default:
1558                         /* find and set the tool tip text */
1559                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1560                                              item,
1561                                              toolbar_ret_descr_from_val
1562                                                 (toolbar_item->index),
1563                                              NULL);
1564                         break;
1565                 }
1566
1567         }
1568         toolbar_data->toolbar = toolbar;
1569         if (type == TOOLBAR_MAIN)
1570                 activate_compose_button(toolbar_data, 
1571                                         prefs_common.toolbar_style, 
1572                                         toolbar_data->compose_btn_type);
1573         
1574         gtk_widget_show_all(toolbar);
1575         
1576         return toolbar_data; 
1577 }
1578
1579 /**
1580  * Free toolbar structures
1581  */ 
1582 void toolbar_destroy(Toolbar * toolbar) {
1583
1584         TOOLBAR_DESTROY_ITEMS(toolbar->item_list);      
1585         TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1586 }
1587
1588 void toolbar_update(ToolbarType type, gpointer data)
1589 {
1590         Toolbar *toolbar_data;
1591         GtkWidget *handlebox;
1592         MainWindow *mainwin = (MainWindow*)data;
1593         Compose    *compose = (Compose*)data;
1594         MessageView *msgview = (MessageView*)data;
1595
1596         switch(type) {
1597         case TOOLBAR_MAIN:
1598                 toolbar_data = mainwin->toolbar;
1599                 handlebox    = mainwin->handlebox;
1600                 break;
1601         case TOOLBAR_COMPOSE:
1602                 toolbar_data = compose->toolbar;
1603                 handlebox    = compose->handlebox;
1604                 break;
1605         case TOOLBAR_MSGVIEW:
1606                 toolbar_data = msgview->toolbar;
1607                 handlebox    = msgview->handlebox;
1608                 break;
1609         default:
1610                 return;
1611         }
1612
1613         gtk_container_remove(GTK_CONTAINER(handlebox), 
1614                              GTK_WIDGET(toolbar_data->toolbar));
1615
1616         toolbar_init(toolbar_data);
1617         toolbar_data = toolbar_create(type, handlebox, data);
1618         switch(type) {
1619         case TOOLBAR_MAIN:
1620                 mainwin->toolbar = toolbar_data;
1621                 break;
1622         case TOOLBAR_COMPOSE:
1623                 compose->toolbar = toolbar_data;
1624                 break;
1625         case TOOLBAR_MSGVIEW:
1626                 msgview->toolbar = toolbar_data;
1627                 break;
1628         }
1629
1630         toolbar_style(type, prefs_common.toolbar_style, data);
1631
1632         if (type == TOOLBAR_MAIN)
1633                 toolbar_main_set_sensitive((MainWindow*)data);
1634 }
1635
1636 void toolbar_main_set_sensitive(gpointer data)
1637 {
1638         SensitiveCond state;
1639         gboolean sensitive;
1640         MainWindow *mainwin = (MainWindow*)data;
1641         Toolbar *toolbar = mainwin->toolbar;
1642         GSList *cur;
1643         GSList *entry_list = NULL;
1644         
1645         typedef struct _Entry Entry;
1646         struct _Entry {
1647                 GtkWidget *widget;
1648                 SensitiveCond cond;
1649                 gboolean empty;
1650         };
1651
1652 #define SET_WIDGET_COND(w, c)     \
1653 { \
1654         Entry *e = g_new0(Entry, 1); \
1655         e->widget = w; \
1656         e->cond   = c; \
1657         entry_list = g_slist_append(entry_list, e); \
1658 }
1659
1660         SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1661         SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1662         SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1663         SET_WIDGET_COND(toolbar->reply_btn,
1664                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1665         if (toolbar->reply_btn)
1666                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->reply_combo),
1667                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1668         SET_WIDGET_COND(toolbar->replyall_btn,
1669                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1670         if (toolbar->replyall_btn)
1671                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replyall_combo),
1672                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1673         SET_WIDGET_COND(toolbar->replylist_btn,
1674                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1675         if (toolbar->replylist_btn) 
1676                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replylist_combo),
1677                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1678         SET_WIDGET_COND(toolbar->replysender_btn,
1679                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1680         if (toolbar->replysender_btn)
1681                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replysender_combo),
1682                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1683         SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1684         if (toolbar->fwd_btn)
1685                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->fwd_combo),
1686                         M_HAVE_ACCOUNT|M_TARGET_EXIST); 
1687
1688         SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1689         SET_WIDGET_COND(toolbar->delete_btn,
1690                         M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1691         SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1692
1693         for (cur = toolbar->action_list; cur != NULL;  cur = cur->next) {
1694                 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1695                 
1696                 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1697         }
1698
1699 #undef SET_WIDGET_COND
1700
1701         state = main_window_get_current_state(mainwin);
1702
1703         for (cur = entry_list; cur != NULL; cur = cur->next) {
1704                 Entry *e = (Entry*) cur->data;
1705
1706                 if (e->widget != NULL) {
1707                         sensitive = ((e->cond & state) == e->cond);
1708                         gtk_widget_set_sensitive(e->widget, sensitive); 
1709                 }
1710         }
1711         
1712         while (entry_list != NULL) {
1713                 Entry *e = (Entry*) entry_list->data;
1714
1715                 if (e)
1716                         g_free(e);
1717                 entry_list = g_slist_remove(entry_list, e);
1718         }
1719
1720         g_slist_free(entry_list);
1721
1722         activate_compose_button(toolbar, 
1723                                 prefs_common.toolbar_style,
1724                                 toolbar->compose_btn_type);
1725 }
1726
1727 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1728 {
1729         Compose *compose = (Compose*)data;
1730         GSList *items = compose->toolbar->action_list;
1731
1732         if (compose->toolbar->send_btn)
1733                 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1734         if (compose->toolbar->sendl_btn)
1735                 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1736         if (compose->toolbar->draft_btn )
1737                 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1738         if (compose->toolbar->insert_btn )
1739                 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1740         if (compose->toolbar->attach_btn)
1741                 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1742         if (compose->toolbar->sig_btn)
1743                 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1744         if (compose->toolbar->exteditor_btn)
1745                 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1746         if (compose->toolbar->linewrap_current_btn)
1747                 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
1748         if (compose->toolbar->linewrap_all_btn)
1749                 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
1750         if (compose->toolbar->addrbook_btn)
1751                 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1752 #ifdef USE_ASPELL
1753         if (compose->toolbar->spellcheck_btn)
1754                 gtk_widget_set_sensitive(compose->toolbar->spellcheck_btn, sensitive);
1755 #endif
1756         for (; items != NULL; items = g_slist_next(items)) {
1757                 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1758                 gtk_widget_set_sensitive(item->widget, sensitive);
1759         }
1760 }
1761
1762 /**
1763  * Initialize toolbar structure
1764  **/
1765 void toolbar_init(Toolbar * toolbar) {
1766
1767         toolbar->toolbar                = NULL;
1768         toolbar->get_btn                = NULL;
1769         toolbar->getall_btn             = NULL;
1770         toolbar->send_btn               = NULL;
1771         toolbar->compose_mail_btn       = NULL;
1772         toolbar->compose_news_btn       = NULL;
1773         toolbar->reply_btn              = NULL;
1774         toolbar->replysender_btn        = NULL;
1775         toolbar->replyall_btn           = NULL;
1776         toolbar->replylist_btn          = NULL;
1777         toolbar->fwd_btn                = NULL;
1778         toolbar->delete_btn             = NULL;
1779         toolbar->next_btn               = NULL;
1780         toolbar->exec_btn               = NULL;
1781
1782         /* compose buttons */ 
1783         toolbar->sendl_btn              = NULL;
1784         toolbar->draft_btn              = NULL;
1785         toolbar->insert_btn             = NULL;
1786         toolbar->attach_btn             = NULL;
1787         toolbar->sig_btn                = NULL; 
1788         toolbar->exteditor_btn          = NULL; 
1789         toolbar->linewrap_current_btn   = NULL; 
1790         toolbar->linewrap_all_btn       = NULL; 
1791         toolbar->addrbook_btn           = NULL; 
1792 #ifdef USE_ASPELL
1793         toolbar->spellcheck_btn         = NULL;
1794 #endif
1795
1796         toolbar_destroy(toolbar);
1797 }
1798
1799 /*
1800  */
1801 static void toolbar_reply(gpointer data, guint action)
1802 {
1803         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1804         MainWindow *mainwin;
1805         MessageView *msgview;
1806         GSList *msginfo_list = NULL;
1807         gchar *body;
1808
1809         g_return_if_fail(toolbar_item != NULL);
1810
1811         switch (toolbar_item->type) {
1812         case TOOLBAR_MAIN:
1813                 mainwin = (MainWindow*)toolbar_item->parent;
1814                 msginfo_list = summary_get_selection(mainwin->summaryview);
1815                 msgview = (MessageView*)mainwin->messageview;
1816                 break;
1817         case TOOLBAR_MSGVIEW:
1818                 msgview = (MessageView*)toolbar_item->parent;
1819                 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
1820                 break;
1821         default:
1822                 return;
1823         }
1824
1825         g_return_if_fail(msgview != NULL);
1826         body = messageview_get_selection(msgview);
1827
1828         g_return_if_fail(msginfo_list != NULL);
1829         compose_reply_mode((ComposeMode)action, msginfo_list, body);
1830
1831         g_free(body);
1832         g_slist_free(msginfo_list);
1833
1834         /* TODO: update reply state ion summaryview */
1835 }
1836
1837
1838 /* exported functions */
1839
1840 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
1841 {
1842         MainWindow *mainwin = (MainWindow*)data;
1843
1844         inc_mail(mainwin, prefs_common.newmail_notify_manu);
1845 }
1846
1847 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
1848 {
1849         MainWindow *mainwin = (MainWindow*)data;
1850
1851         inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
1852 }
1853
1854 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
1855 {
1856         GList *list;
1857
1858         if (prefs_common.work_offline)
1859                 if (alertpanel(_("Offline warning"), 
1860                                _("You're working offline. Override?"),
1861                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1862                 return;
1863
1864         for (list = folder_get_list(); list != NULL; list = list->next) {
1865                 Folder *folder = list->data;
1866
1867                 if (folder->queue) {
1868                         procmsg_send_queue(folder->queue, prefs_common.savemsg);
1869                         folder_item_scan(folder->queue);
1870                 }
1871         }
1872 }
1873
1874 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
1875 {
1876         MainWindow *mainwin = (MainWindow*)data;
1877         PrefsAccount *ac = NULL;
1878         FolderItem *item = mainwin->summaryview->folder_item;   
1879         GList * list;
1880         GList * cur;
1881
1882         if (item) {
1883                 ac = account_find_from_item(item);
1884                 if (ac && ac->protocol != A_NNTP) {
1885                         compose_new_with_folderitem(ac, item);          /* CLAWS */
1886                         return;
1887                 }
1888         }
1889
1890         /*
1891          * CLAWS - use current account
1892          */
1893         if (cur_account && (cur_account->protocol != A_NNTP)) {
1894                 compose_new_with_folderitem(cur_account, item);
1895                 return;
1896         }
1897
1898         /*
1899          * CLAWS - just get the first one
1900          */
1901         list = account_get_list();
1902         for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
1903                 ac = (PrefsAccount *) cur->data;
1904                 if (ac->protocol != A_NNTP) {
1905                         compose_new_with_folderitem(ac, item);
1906                         return;
1907                 }
1908         }
1909 }
1910
1911 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
1912 {
1913         MainWindow *mainwin = (MainWindow*)data;
1914         PrefsAccount * ac = NULL;
1915         GList * list;
1916         GList * cur;
1917
1918         if (mainwin->summaryview->folder_item) {
1919                 ac = mainwin->summaryview->folder_item->folder->account;
1920                 if (ac && ac->protocol == A_NNTP) {
1921                         compose_new(ac,
1922                                     mainwin->summaryview->folder_item->path,
1923                                     NULL);
1924                         return;
1925                 }
1926         }
1927
1928         list = account_get_list();
1929         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
1930                 ac = (PrefsAccount *) cur->data;
1931                 if (ac->protocol == A_NNTP) {
1932                         compose_new(ac, NULL, NULL);
1933                         return;
1934                 }
1935         }
1936 }