6eee1e5564acc2de211609f25e1526d50c52663e
[claws.git] / src / toolbar.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2001-2007 Hiroyuki Yamamoto and the Claws Mail 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 <glib/gi18n.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <dirent.h>
35 #include <sys/stat.h>
36 #include <math.h>
37 #include <setjmp.h>
38
39 #include "main.h"
40 #include "mainwindow.h"
41 #include "summaryview.h"
42 #include "compose.h"
43 #include "utils.h"
44 #include "xml.h"
45 #include "mgutils.h"
46 #include "prefs_gtk.h"
47 #include "codeconv.h"
48 #include "stock_pixmap.h"
49 #include "manage_window.h"
50 #include "gtkutils.h"
51 #include "toolbar.h"
52 #include "menu.h"
53 #include "inc.h"
54 #include "action.h"
55 #include "prefs_actions.h"
56 #include "prefs_common.h"
57 #include "prefs_toolbar.h"
58 #include "alertpanel.h"
59
60 /* elements */
61 #define TOOLBAR_TAG_INDEX        "toolbar"
62 #define TOOLBAR_TAG_ITEM         "item"
63 #define TOOLBAR_TAG_SEPARATOR    "separator"
64
65 #define TOOLBAR_ICON_FILE   "file"    
66 #define TOOLBAR_ICON_TEXT   "text"     
67 #define TOOLBAR_ICON_ACTION "action"    
68
69 static gboolean      toolbar_is_duplicate               (gint           action,
70                                                  ToolbarType    source);
71 static void   toolbar_parse_item                (XMLFile        *file,
72                                                  ToolbarType    source);
73
74 static gint   toolbar_ret_val_from_text         (const gchar    *text);
75 static gchar *toolbar_ret_text_from_val         (gint           val);
76
77 static void   toolbar_set_default_main          (void);
78 static void   toolbar_set_default_compose       (void);
79 static void   toolbar_set_default_msgview       (void);
80
81 static void     toolbar_style                   (ToolbarType     type, 
82                                                  guint           action, 
83                                                  gpointer        data);
84
85 static MainWindow *get_mainwin                  (gpointer data);
86 static void activate_compose_button             (Toolbar        *toolbar,
87                                                  ToolbarStyle    style,
88                                                  ComposeButtonType type);
89
90 /* toolbar callbacks */
91 static void toolbar_reply                       (gpointer        data, 
92                                                  guint           action);
93 static void toolbar_learn                       (gpointer        data, 
94                                                  guint           action);
95 static void toolbar_delete_cb                   (GtkWidget      *widget,
96                                                  gpointer        data);
97 static void toolbar_trash_cb                    (GtkWidget      *widget,
98                                                  gpointer        data);
99
100 static void toolbar_compose_cb                  (GtkWidget      *widget,
101                                                  gpointer        data);
102
103 static void toolbar_learn_cb                    (GtkWidget      *widget,
104                                                  gpointer        data);
105
106 static void toolbar_reply_cb                    (GtkWidget      *widget,
107                                                  gpointer        data);
108
109 static void toolbar_reply_to_all_cb             (GtkWidget      *widget,
110                                                  gpointer        data);
111
112 static void toolbar_reply_to_list_cb            (GtkWidget      *widget,
113                                                  gpointer        data);
114
115 static void toolbar_reply_to_sender_cb          (GtkWidget      *widget,
116                                                  gpointer        data);
117
118 static void toolbar_forward_cb                  (GtkWidget      *widget,
119                                                  gpointer        data);
120
121 static void toolbar_prev_unread_cb              (GtkWidget      *widget,
122                                                  gpointer        data);
123 static void toolbar_next_unread_cb              (GtkWidget      *widget,
124                                                  gpointer        data);
125
126 static void toolbar_ignore_thread_cb            (GtkWidget      *widget,
127                                                  gpointer        data);
128
129 static void toolbar_print_cb                    (GtkWidget      *widget,
130                                                  gpointer        data);
131
132 static void toolbar_actions_execute_cb          (GtkWidget      *widget,
133                                                  gpointer        data);
134
135
136 static void toolbar_send_cb                     (GtkWidget      *widget,
137                                                  gpointer        data);
138 static void toolbar_send_later_cb               (GtkWidget      *widget,
139                                                  gpointer        data);
140 static void toolbar_draft_cb                    (GtkWidget      *widget,
141                                                  gpointer        data);
142 static void toolbar_close_cb                    (GtkWidget      *widget,
143                                                  gpointer        data);
144 static void toolbar_open_mail_cb                (GtkWidget      *widget,
145                                                  gpointer        data);
146 static void toolbar_insert_cb                   (GtkWidget      *widget,
147                                                  gpointer        data);
148 static void toolbar_attach_cb                   (GtkWidget      *widget,
149                                                  gpointer        data);
150 static void toolbar_sig_cb                      (GtkWidget      *widget,
151                                                  gpointer        data);
152 static void toolbar_ext_editor_cb               (GtkWidget      *widget,
153                                                  gpointer        data);
154 static void toolbar_linewrap_current_cb         (GtkWidget      *widget,
155                                                  gpointer        data);
156 static void toolbar_linewrap_all_cb             (GtkWidget      *widget,
157                                                  gpointer        data);
158 static void toolbar_addrbook_cb                 (GtkWidget      *widget, 
159                                                  gpointer        data);
160 #ifdef USE_ASPELL
161 static void toolbar_check_spelling_cb           (GtkWidget      *widget, 
162                                                  gpointer        data);
163 #endif
164 static void toolbar_cancel_inc_cb               (GtkWidget      *widget,
165                                                  gpointer        data);
166
167 struct {
168         gchar *index_str;
169         const gchar *descr;
170 } toolbar_text [] = {
171         { "A_RECEIVE_ALL",      N_("Receive Mail on all Accounts")         },
172         { "A_RECEIVE_CUR",      N_("Receive Mail on current Account")      },
173         { "A_SEND_QUEUED",      N_("Send Queued Messages")                 },
174         { "A_COMPOSE_EMAIL",    N_("Compose Email")                        },
175         { "A_COMPOSE_NEWS",     N_("Compose News")                         },
176         { "A_REPLY_MESSAGE",    N_("Reply to Message")                     },
177         { "A_REPLY_SENDER",     N_("Reply to Sender")                      },
178         { "A_REPLY_ALL",        N_("Reply to All")                         },
179         { "A_REPLY_ML",         N_("Reply to Mailing-list")                },
180         { "A_OPEN_MAIL",        N_("Open email")                           },
181         { "A_FORWARD",          N_("Forward Message")                      }, 
182         { "A_TRASH",            N_("Trash Message")                        },
183         { "A_DELETE_REAL",      N_("Delete Message")                       },
184         { "A_EXECUTE",          N_("Execute")                              },
185         { "A_GOTO_PREV",        N_("Go to Previous Unread Message")        },
186         { "A_GOTO_NEXT",        N_("Go to Next Unread Message")            },
187         { "A_IGNORE_THREAD",    N_("Ignore thread")                        },
188         { "A_PRINT",            N_("Print")                                },
189         { "A_LEARN_SPAM",       N_("Learn Spam or Ham")                    },
190         { "A_GO_FOLDERS",       N_("Open folder/Go to folder list")        },
191
192         { "A_SEND",             N_("Send Message")                         },
193         { "A_SENDL",            N_("Put into queue folder and send later") },
194         { "A_DRAFT",            N_("Save to draft folder")                 },
195         { "A_INSERT",           N_("Insert file")                          },   
196         { "A_ATTACH",           N_("Attach file")                          },
197         { "A_SIG",              N_("Insert signature")                     },
198         { "A_EXTEDITOR",        N_("Edit with external editor")            },
199         { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") }, 
200         { "A_LINEWRAP_ALL",     N_("Wrap all long lines")                  }, 
201         { "A_ADDRBOOK",         N_("Address book")                         },
202 #ifdef USE_ASPELL
203         { "A_CHECK_SPELLING",   N_("Check spelling")                       },
204 #endif
205         { "A_SYL_ACTIONS",      N_("Claws Mail Actions Feature")           }, 
206         { "A_CANCEL_INC",       N_("Cancel receiving")                     },
207         { "A_CLOSE",            N_("Close window")                         },
208         { "A_SEPARATOR",        "Separator"                             }
209 };
210
211 /* struct holds configuration files and a list of
212  * currently active toolbar items 
213  * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
214  * give us an index
215  */
216 struct {
217         const gchar  *conf_file;
218         GSList       *item_list;
219 } toolbar_config[3] = {
220         { "toolbar_main.xml",    NULL},
221         { "toolbar_compose.xml", NULL}, 
222         { "toolbar_msgview.xml", NULL}
223 };
224
225 static GtkItemFactoryEntry reply_entries[] =
226 {
227         {N_("/Reply with _quote"), NULL,    toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
228         {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
229 };
230 static GtkItemFactoryEntry replyall_entries[] =
231 {
232         {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
233         {N_("/_Reply to all without quote"), "a",     toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
234 };
235 static GtkItemFactoryEntry replylist_entries[] =
236 {
237         {N_("/Reply to list with _quote"),    NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
238         {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
239 };
240 static GtkItemFactoryEntry replysender_entries[] =
241 {
242         {N_("/Reply to sender with _quote"),    NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
243         {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
244 };
245 static GtkItemFactoryEntry forward_entries[] =
246 {
247         {N_("/_Forward"),               "f",        toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
248         {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
249         {N_("/Redirec_t"),              NULL,       toolbar_reply, COMPOSE_REDIRECT, NULL}
250 };
251 static GtkItemFactoryEntry learn_entries[] =
252 {
253         {N_("/Learn as _Spam"),         NULL,   toolbar_learn, TRUE, NULL},
254         {N_("/Learn as _Ham"),          NULL,   toolbar_learn, FALSE, NULL}
255 };
256
257
258 gint toolbar_ret_val_from_descr(const gchar *descr)
259 {
260         gint i;
261
262         for (i = 0; i < N_ACTION_VAL; i++) {
263                 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
264                                 return i;
265         }
266         
267         return -1;
268 }
269
270 gchar *toolbar_ret_descr_from_val(gint val)
271 {
272         g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
273
274         return gettext(toolbar_text[val].descr);
275 }
276
277 static gint toolbar_ret_val_from_text(const gchar *text)
278 {
279         gint i;
280         
281         for (i = 0; i < N_ACTION_VAL; i++) {
282                 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
283                                 return i;
284         }
285
286         return -1;
287 }
288
289 static gchar *toolbar_ret_text_from_val(gint val)
290 {
291         g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
292
293         return toolbar_text[val].index_str;
294 }
295
296 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
297 {
298         GSList *cur;
299
300         if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS)) 
301                 return FALSE;
302
303         for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
304                 ToolbarItem *item = (ToolbarItem*) cur->data;
305                 
306                 if (item->index == action)
307                         return TRUE;
308         }
309         return FALSE;
310 }
311
312 /* depending on toolbar type this function 
313    returns a list of available toolbar events being 
314    displayed by prefs_toolbar
315 */
316 GList *toolbar_get_action_items(ToolbarType source)
317 {
318         GList *items = NULL;
319         gint i = 0;
320         
321         if (source == TOOLBAR_MAIN) {
322                 gint main_items[]   = { A_RECEIVE_ALL,   A_RECEIVE_CUR,   A_SEND_QUEUED,
323                                         A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER, 
324                                         A_REPLY_ALL,     A_REPLY_ML,      A_OPEN_MAIL,  A_FORWARD, 
325                                         A_TRASH , A_DELETE_REAL,       A_EXECUTE,       A_GOTO_PREV, 
326                                         A_GOTO_NEXT,    A_IGNORE_THREAD,  A_PRINT,
327                                         A_ADDRBOOK,     A_LEARN_SPAM, A_GO_FOLDERS, 
328                                         A_SYL_ACTIONS, A_CANCEL_INC };
329
330                 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++)  {
331                         items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
332                 }       
333         }
334         else if (source == TOOLBAR_COMPOSE) {
335                 gint comp_items[] =   { A_SEND,          A_SENDL,        A_DRAFT,
336                                         A_INSERT,        A_ATTACH,       A_SIG,
337                                         A_EXTEDITOR,     A_LINEWRAP_CURRENT,     
338                                         A_LINEWRAP_ALL,  A_ADDRBOOK,
339 #ifdef USE_ASPELL
340                                         A_CHECK_SPELLING, 
341 #endif
342                                         A_SYL_ACTIONS, A_CLOSE };       
343
344                 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++) 
345                         items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
346         }
347         else if (source == TOOLBAR_MSGVIEW) {
348                 gint msgv_items[] =   { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
349                                         A_REPLY_ALL,     A_REPLY_ML,      A_FORWARD,
350                                         A_TRASH, A_DELETE_REAL,       A_GOTO_PREV,        A_GOTO_NEXT,
351                                         A_ADDRBOOK,      A_LEARN_SPAM, A_SYL_ACTIONS, A_CLOSE };        
352
353                 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++) 
354                         items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
355         }
356
357         return items;
358 }
359
360 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
361 {
362         GList *attr;
363         gchar *name, *value;
364         ToolbarItem *item = NULL;
365         gboolean rewrite = FALSE;
366
367         attr = xml_get_current_tag_attr(file);
368         item = g_new0(ToolbarItem, 1);
369         while( attr ) {
370                 name = ((XMLAttr *)attr->data)->name;
371                 value = ((XMLAttr *)attr->data)->value;
372                 
373                 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0) 
374                         item->file = g_strdup (value);
375                 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
376                         item->text = g_strdup (gettext(value));
377                 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
378                         item->index = toolbar_ret_val_from_text(value);
379                 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
380                         /* switch button */
381                         item->index = A_TRASH;
382                         g_free(item->file);
383                         item->file = g_strdup("trash_btn");
384                         g_free(item->text);
385                         item->text = g_strdup(_("Trash"));
386                         rewrite = TRUE;
387                 }
388                 attr = g_list_next(attr);
389         }
390         if (item->index != -1) {
391                 
392                 if (!toolbar_is_duplicate(item->index, source)) 
393                         toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
394                                                                          item);
395         }
396         if (rewrite) {
397                 toolbar_save_config_file(source);
398         }
399 }
400
401 static void toolbar_set_default_main(void) 
402 {
403         struct {
404                 gint action;
405                 gint icon;
406                 gchar *text;
407         } default_toolbar[] = {
408 #ifdef MAEMO
409                 { A_GO_FOLDERS,    STOCK_PIXMAP_DIR_OPEN,             _("Folders") },
410                 { A_SEPARATOR,     0,                                 ("")         }, 
411 #endif
412                 { A_RECEIVE_ALL,   STOCK_PIXMAP_MAIL_RECEIVE_ALL,     _("Get Mail")},
413                 { A_SEPARATOR,     0,                                 ("")         }, 
414                 { A_SEND_QUEUED,   STOCK_PIXMAP_MAIL_SEND_QUEUE,      _("Send")    },
415                 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE,
416                         (gchar*)Q_("Toolbar|Compose") },
417                 { A_SEPARATOR,     0,                                 ("")         },
418 #ifdef MAEMO
419                 { A_OPEN_MAIL,     STOCK_PIXMAP_OPEN_MAIL,            _("Open")    },
420 #endif
421                 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY,           _("Reply")   }, 
422 #ifndef MAEMO
423                 { A_REPLY_ALL,     STOCK_PIXMAP_MAIL_REPLY_TO_ALL,    _("All")     },
424                 { A_REPLY_SENDER,  STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender")  },
425 #endif
426                 { A_FORWARD,       STOCK_PIXMAP_MAIL_FORWARD,         _("Forward") },
427                 { A_SEPARATOR,     0,                                 ("")         },
428                 { A_TRASH,         STOCK_PIXMAP_TRASH,                _("Trash")   },
429 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
430                 { A_LEARN_SPAM,    STOCK_PIXMAP_SPAM_BTN,             _("Spam")    },
431 #endif
432                 { A_SEPARATOR,     0,                                 ("")         },
433                 { A_GOTO_NEXT,     STOCK_PIXMAP_DOWN_ARROW,           _("Next")    }
434         };
435         
436         gint i;
437         
438         for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
439                 
440                 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
441                 
442                 if (default_toolbar[i].action != A_SEPARATOR) {
443                         
444                         gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
445                         
446                         toolbar_item->file  = g_strdup(file);
447                         toolbar_item->index = default_toolbar[i].action;
448                         toolbar_item->text  = g_strdup(default_toolbar[i].text);
449                 } else {
450
451                         toolbar_item->file  = g_strdup(TOOLBAR_TAG_SEPARATOR);
452                         toolbar_item->index = A_SEPARATOR;
453                 }
454                 
455                 if (toolbar_item->index != -1) {
456                         if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN)) 
457                                 toolbar_config[TOOLBAR_MAIN].item_list = 
458                                         g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
459                 }       
460         }
461 }
462
463 static void toolbar_set_default_compose(void)
464 {
465         struct {
466                 gint action;
467                 gint icon;
468                 gchar *text;
469         } default_toolbar[] = {
470                 { A_SEND,               STOCK_PIXMAP_MAIL_SEND,         _("Send")               },
471                 { A_SENDL,              STOCK_PIXMAP_MAIL_SEND_QUEUE,   _("Send later")         },
472                 { A_DRAFT,              STOCK_PIXMAP_MAIL,              _("Draft")              },
473                 { A_SEPARATOR,          0,                               ("")                   }, 
474 #ifndef MAEMO
475                 { A_INSERT,             STOCK_PIXMAP_INSERT_FILE,       _("Insert")             },
476 #endif
477                 { A_ATTACH,             STOCK_PIXMAP_MAIL_ATTACH,       _("Attach")             },
478                 { A_SEPARATOR,          0,                               ("")                   },
479                 { A_ADDRBOOK,           STOCK_PIXMAP_ADDRESS_BOOK,      _("Address")            }
480 #ifdef MAEMO
481                 ,
482                 { A_SEPARATOR,          0,                               ("")                   }, 
483                 { A_CLOSE,              STOCK_PIXMAP_CLOSE,             _("Close")              }
484 #endif
485         };
486         
487         gint i;
488
489         for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
490                 
491                 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
492                 
493                 if (default_toolbar[i].action != A_SEPARATOR) {
494                         
495                         gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
496                         
497                         toolbar_item->file  = g_strdup(file);
498                         toolbar_item->index = default_toolbar[i].action;
499                         toolbar_item->text  = g_strdup(default_toolbar[i].text);
500                 } else {
501
502                         toolbar_item->file  = g_strdup(TOOLBAR_TAG_SEPARATOR);
503                         toolbar_item->index = A_SEPARATOR;
504                 }
505                 
506                 if (toolbar_item->index != -1) {
507                         if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE)) 
508                                 toolbar_config[TOOLBAR_COMPOSE].item_list = 
509                                         g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
510                 }       
511         }
512 }
513
514 static void toolbar_set_default_msgview(void)
515 {
516         struct {
517                 gint action;
518                 gint icon;
519                 gchar *text;
520         } default_toolbar[] = {
521                 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY,           _("Reply")   }, 
522                 { A_REPLY_ALL,     STOCK_PIXMAP_MAIL_REPLY_TO_ALL,    _("All")     },
523                 { A_REPLY_SENDER,  STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender")  },
524                 { A_FORWARD,       STOCK_PIXMAP_MAIL_FORWARD,         _("Forward") },
525                 { A_SEPARATOR,     0,                                 ("")         },
526                 { A_TRASH,         STOCK_PIXMAP_TRASH,                _("Trash")   },
527 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
528                 { A_LEARN_SPAM,    STOCK_PIXMAP_SPAM_BTN,             _("Spam")    },
529 #endif
530                 { A_GOTO_NEXT,     STOCK_PIXMAP_DOWN_ARROW,           _("Next")    }
531 #ifdef MAEMO
532                 ,
533                 { A_SEPARATOR,          0,                               ("")      }, 
534                 { A_CLOSE,              STOCK_PIXMAP_CLOSE,             _("Close") }
535 #endif
536         };
537         
538         gint i;
539
540         for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
541                 
542                 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
543                 
544                 if (default_toolbar[i].action != A_SEPARATOR) {
545                         
546                         gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
547                         
548                         toolbar_item->file  = g_strdup(file);
549                         toolbar_item->index = default_toolbar[i].action;
550                         toolbar_item->text  = g_strdup(default_toolbar[i].text);
551                 } else {
552
553                         toolbar_item->file  = g_strdup(TOOLBAR_TAG_SEPARATOR);
554                         toolbar_item->index = A_SEPARATOR;
555                 }
556                 
557                 if (toolbar_item->index != -1) {
558                         if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW)) 
559                                 toolbar_config[TOOLBAR_MSGVIEW].item_list = 
560                                         g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
561                 }       
562         }
563 }
564
565 void toolbar_set_default(ToolbarType source)
566 {
567         if (source == TOOLBAR_MAIN)
568                 toolbar_set_default_main();
569         else if  (source == TOOLBAR_COMPOSE)
570                 toolbar_set_default_compose();
571         else if  (source == TOOLBAR_MSGVIEW)
572                 toolbar_set_default_msgview();
573 }
574
575 void toolbar_save_config_file(ToolbarType source)
576 {
577         GSList *cur;
578         FILE *fp;
579         PrefFile *pfile;
580         gchar *fileSpec = NULL;
581
582         debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
583
584         fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
585         pfile = prefs_write_open(fileSpec);
586         g_free( fileSpec );
587         if( pfile ) {
588                 fp = pfile->fp;
589                 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL);
590
591                 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
592
593                 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
594                         ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
595                         
596                         if (toolbar_item->index != A_SEPARATOR) {
597                                 fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
598                                         TOOLBAR_TAG_ITEM, 
599                                         TOOLBAR_ICON_FILE, toolbar_item->file,
600                                         TOOLBAR_ICON_TEXT);
601                                 xml_file_put_escape_str(fp, toolbar_item->text);
602                                 fprintf(fp, "\" %s=\"%s\"/>\n",
603                                         TOOLBAR_ICON_ACTION, 
604                                         toolbar_ret_text_from_val(toolbar_item->index));
605                         } else {
606                                 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR); 
607                         }
608                 }
609
610                 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);      
611         
612                 if (prefs_file_close (pfile) < 0 ) 
613                         g_warning("failed to write toolbar configuration to file\n");
614         } else
615                 g_warning("failed to open toolbar configuration file for writing\n");
616 }
617
618 void toolbar_read_config_file(ToolbarType source)
619 {
620         XMLFile *file   = NULL;
621         gchar *fileSpec = NULL;
622         GList *attr;
623         gboolean retVal;
624         jmp_buf    jumper;
625
626         debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
627
628         fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
629         file = xml_open_file(fileSpec);
630         g_free(fileSpec);
631
632         toolbar_clear_list(source);
633
634         if (file) {
635                 if ((setjmp(jumper))
636                 || (xml_get_dtd(file))
637                 || (xml_parse_next_tag(file))
638                 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
639                         xml_close_file(file);
640                         return;
641                 }
642
643                 attr = xml_get_current_tag_attr(file);
644                 
645                 retVal = TRUE;
646                 for (;;) {
647                         if (!file->level) 
648                                 break;
649                         /* Get item tag */
650                         if (xml_parse_next_tag(file)) 
651                                 longjmp(jumper, 1);
652
653                         /* Get next tag (icon, icon_text or icon_action) */
654                         if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
655                                 toolbar_parse_item(file, source);
656                         } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
657                                 ToolbarItem *item = g_new0(ToolbarItem, 1);
658                         
659                                 item->file   = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
660                                 item->index  = A_SEPARATOR;
661                                 toolbar_config[source].item_list = 
662                                         g_slist_append(toolbar_config[source].item_list, item);
663                         }
664
665                 }
666                 xml_close_file(file);
667         }
668
669         if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
670
671                 if (source == TOOLBAR_MAIN) 
672                         toolbar_set_default(TOOLBAR_MAIN);
673                 else if (source == TOOLBAR_COMPOSE) 
674                         toolbar_set_default(TOOLBAR_COMPOSE);
675                 else if (source == TOOLBAR_MSGVIEW) 
676                         toolbar_set_default(TOOLBAR_MSGVIEW);
677                 else {          
678                         g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
679                         return;
680                 }
681
682                 toolbar_save_config_file(source);
683         }
684 }
685
686 /*
687  * clears list of toolbar items read from configuration files
688  */
689 void toolbar_clear_list(ToolbarType source)
690 {
691         while (toolbar_config[source].item_list != NULL) {
692                 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
693                 
694                 toolbar_config[source].item_list = 
695                         g_slist_remove(toolbar_config[source].item_list, item);
696
697                 g_free(item->file);
698                 g_free(item->text);
699                 g_free(item);   
700         }
701         g_slist_free(toolbar_config[source].item_list);
702 }
703
704
705 /* 
706  * return list of Toolbar items
707  */
708 GSList *toolbar_get_list(ToolbarType source)
709 {
710         GSList *list = NULL;
711
712         if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
713                 list = toolbar_config[source].item_list;
714
715         return list;
716 }
717
718 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
719 {
720         ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
721
722         toolbar_item->file  = g_strdup(t_item->file);
723         toolbar_item->text  = g_strdup(t_item->text);
724         toolbar_item->index = t_item->index;
725         
726         toolbar_config[source].item_list = 
727                 g_slist_append(toolbar_config[source].item_list,
728                                toolbar_item);
729 }
730
731 void toolbar_action_execute(GtkWidget    *widget,
732                             GSList       *action_list, 
733                             gpointer     data,
734                             gint         source) 
735 {
736         GSList *cur, *lop;
737         gchar *action, *action_p;
738         gboolean found = FALSE;
739         gint i = 0;
740
741         for (cur = action_list; cur != NULL;  cur = cur->next) {
742                 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
743
744                 if (widget == act->widget) {
745                         
746                         for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
747                                 action = g_strdup((gchar*)lop->data);
748
749                                 action_p = strstr(action, ": ");
750                                 action_p[0] = 0x00;
751                                 if (g_utf8_collate(act->name, action) == 0) {
752                                         found = TRUE;
753                                         g_free(action);
754                                         break;
755                                 } else 
756                                         i++;
757                                 g_free(action);
758                         }
759                         if (found) 
760                                 break;
761                 }
762         }
763
764         if (found) 
765                 actions_execute(data, i, widget, source);
766         else
767                 g_warning ("Error: did not find Claws Action to execute");
768 }
769
770 static void activate_compose_button (Toolbar           *toolbar,
771                                      ToolbarStyle      style,
772                                      ComposeButtonType type)
773 {
774         if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
775                 return;
776
777         gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn 
778                         : toolbar->compose_news_btn);
779         gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
780                         : toolbar->compose_mail_btn);
781         toolbar->compose_btn_type = type;       
782 }
783
784 void toolbar_set_compose_button(Toolbar            *toolbar, 
785                                 ComposeButtonType  compose_btn_type)
786 {
787         if (toolbar->compose_btn_type != compose_btn_type)
788                 activate_compose_button(toolbar, 
789                                         prefs_common.toolbar_style,
790                                         compose_btn_type);
791 }
792
793 static void activate_learn_button (Toolbar           *toolbar,
794                                      ToolbarStyle      style,
795                                      LearnButtonType type)
796 {
797         if ((!toolbar->learn_spam_btn) || (!toolbar->learn_ham_btn))
798                 return;
799
800         gtk_widget_hide(type == LEARN_SPAM ? toolbar->learn_ham_btn 
801                         : toolbar->learn_spam_btn);
802         gtk_widget_show(type == LEARN_SPAM ? toolbar->learn_spam_btn
803                         : toolbar->learn_ham_btn);
804         toolbar->learn_btn_type = type; 
805 }
806
807 void toolbar_set_learn_button(Toolbar            *toolbar, 
808                                 LearnButtonType  learn_btn_type)
809 {
810         if (toolbar->learn_btn_type != learn_btn_type)
811                 activate_learn_button(toolbar, 
812                                         prefs_common.toolbar_style,
813                                         learn_btn_type);
814 }
815
816 void toolbar_toggle(guint action, gpointer data)
817 {
818         MainWindow *mainwin = (MainWindow*)data;
819         GList *list;
820         GList *cur;
821
822         g_return_if_fail(mainwin != NULL);
823
824         toolbar_style(TOOLBAR_MAIN, action, mainwin);
825
826         list = compose_get_compose_list();
827         for (cur = list; cur != NULL; cur = cur->next) {
828                 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
829         }
830         list = messageview_get_msgview_list();
831         for (cur = list; cur != NULL; cur = cur->next) {
832                 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
833         }
834         
835 }
836
837 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
838 {
839         switch ((ToolbarStyle)action) {
840         case TOOLBAR_NONE:
841                 gtk_widget_hide(handlebox_wid);
842                 break;
843         case TOOLBAR_ICON:
844                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
845                                       GTK_TOOLBAR_ICONS);
846                 break;
847         case TOOLBAR_TEXT:
848                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
849                                       GTK_TOOLBAR_TEXT);
850                 break;
851         case TOOLBAR_BOTH:
852                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
853                                       GTK_TOOLBAR_BOTH);
854                 break;
855         case TOOLBAR_BOTH_HORIZ:
856                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
857                                       GTK_TOOLBAR_BOTH_HORIZ);
858                 break;
859         default:
860                 return;
861         }
862
863         prefs_common.toolbar_style = (ToolbarStyle)action;
864         gtk_widget_set_size_request(handlebox_wid, 1, -1);
865         
866         if (prefs_common.toolbar_style != TOOLBAR_NONE) {
867                 gtk_widget_show(handlebox_wid);
868                 gtk_widget_queue_resize(handlebox_wid);
869         }
870 }
871 /*
872  * Change the style of toolbar
873  */
874 static void toolbar_style(ToolbarType type, guint action, gpointer data)
875 {
876         GtkWidget  *handlebox_wid;
877         GtkWidget  *toolbar_wid;
878         MainWindow *mainwin = (MainWindow*)data;
879         Compose    *compose = (Compose*)data;
880         MessageView *msgview = (MessageView*)data;
881         
882         g_return_if_fail(data != NULL);
883         
884         switch (type) {
885         case TOOLBAR_MAIN:
886                 handlebox_wid = mainwin->handlebox;
887                 toolbar_wid = mainwin->toolbar->toolbar;
888                 break;
889         case TOOLBAR_COMPOSE:
890                 handlebox_wid = compose->handlebox;
891                 toolbar_wid = compose->toolbar->toolbar;
892                 break;
893         case TOOLBAR_MSGVIEW: 
894                 handlebox_wid = msgview->handlebox;
895                 toolbar_wid = msgview->toolbar->toolbar;
896                 break;
897         default:
898
899                 return;
900         }
901         toolbar_set_style(toolbar_wid, handlebox_wid, action);
902 }
903
904 /* Toolbar handling */
905 static void toolbar_inc_cb(GtkWidget    *widget,
906                            gpointer      data)
907 {
908         ToolbarItem *toolbar_item = (ToolbarItem*)data;
909         MainWindow *mainwin;
910
911         g_return_if_fail(toolbar_item != NULL);
912
913         switch (toolbar_item->type) {
914         case TOOLBAR_MAIN:
915                 mainwin = (MainWindow*)toolbar_item->parent;    
916                 inc_mail_cb(mainwin, 0, NULL);
917                 break;
918         default:
919                 break;
920         }
921 }
922
923 static void toolbar_inc_all_cb(GtkWidget        *widget,
924                                gpointer          data)
925 {
926         ToolbarItem *toolbar_item = (ToolbarItem*)data;
927         MainWindow *mainwin;
928
929         g_return_if_fail(toolbar_item != NULL);
930
931         switch (toolbar_item->type) {
932         case TOOLBAR_MAIN:
933                 mainwin = (MainWindow*)toolbar_item->parent;
934                 inc_all_account_mail_cb(mainwin, 0, NULL);
935                 break;
936         default:
937                 break;
938         }
939 }
940
941 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
942 {
943         ToolbarItem *toolbar_item = (ToolbarItem*)data;
944         MainWindow *mainwin;
945
946         g_return_if_fail(toolbar_item != NULL);
947
948         switch (toolbar_item->type) {
949         case TOOLBAR_MAIN:
950                 mainwin = (MainWindow*)toolbar_item->parent;
951                 send_queue_cb(mainwin, 0, NULL);
952                 break;
953         default:
954                 break;
955         }
956 }
957
958 static void toolbar_exec_cb(GtkWidget   *widget,
959                             gpointer     data)
960 {
961         MainWindow *mainwin = get_mainwin(data);
962
963         g_return_if_fail(mainwin != NULL);
964         summary_execute(mainwin->summaryview);
965 }
966
967 /*
968  * Delete current/selected(s) message(s)
969  */
970 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
971 {
972         ToolbarItem *toolbar_item = (ToolbarItem*)data;
973         MainWindow *mainwin;
974
975         g_return_if_fail(toolbar_item != NULL);
976         g_return_if_fail(toolbar_item->parent);
977         
978         switch (toolbar_item->type) {
979         case TOOLBAR_MSGVIEW:
980                 messageview_delete((MessageView *)toolbar_item->parent);
981                 break;
982         case TOOLBAR_MAIN:
983                 mainwin = (MainWindow *)toolbar_item->parent;
984                 summary_delete_trash(mainwin->summaryview);
985                 break;
986         default: 
987                 debug_print("toolbar event not supported\n");
988                 break;
989         }
990 }
991
992 /*
993  * Delete current/selected(s) message(s)
994  */
995 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
996 {
997         ToolbarItem *toolbar_item = (ToolbarItem*)data;
998         MainWindow *mainwin;
999
1000         g_return_if_fail(toolbar_item != NULL);
1001         g_return_if_fail(toolbar_item->parent);
1002         
1003         switch (toolbar_item->type) {
1004         case TOOLBAR_MSGVIEW:
1005                 messageview_delete((MessageView *)toolbar_item->parent);
1006                 break;
1007         case TOOLBAR_MAIN:
1008                 mainwin = (MainWindow *)toolbar_item->parent;
1009                 summary_delete(mainwin->summaryview);
1010                 break;
1011         default: 
1012                 debug_print("toolbar event not supported\n");
1013                 break;
1014         }
1015 }
1016
1017
1018 /*
1019  * Compose new message
1020  */
1021 static void toolbar_compose_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                 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS) 
1033                         compose_news_cb(mainwin, 0, NULL);
1034                 else
1035                         compose_mail_cb(mainwin, 0, NULL);
1036                 break;
1037         case TOOLBAR_MSGVIEW:
1038                 msgview = (MessageView*)toolbar_item->parent;
1039                 compose_new_with_folderitem(NULL, 
1040                                             msgview->msginfo->folder, NULL);
1041                 break;  
1042         default:
1043                 debug_print("toolbar event not supported\n");
1044         }
1045 }
1046
1047 static void toolbar_learn(gpointer data, guint as_spam)
1048 {
1049         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1050         MainWindow *mainwin;
1051         MessageView *msgview;
1052
1053         g_return_if_fail(toolbar_item != NULL);
1054
1055         switch (toolbar_item->type) {
1056         case TOOLBAR_MAIN:
1057                 mainwin = (MainWindow*)toolbar_item->parent;
1058                 if (as_spam) 
1059                         mainwindow_learn(mainwin, TRUE);
1060                 else
1061                         mainwindow_learn(mainwin, FALSE);
1062                 break;
1063         case TOOLBAR_MSGVIEW:
1064                 msgview = (MessageView*)toolbar_item->parent;
1065                 if (as_spam) 
1066                         messageview_learn(msgview, TRUE);
1067                 else
1068                         messageview_learn(msgview, FALSE);
1069                 break;
1070         default:
1071                 debug_print("toolbar event not supported\n");
1072         }
1073 }
1074
1075 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1076 {
1077         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1078         MainWindow *mainwin;
1079         MessageView *msgview;
1080
1081         g_return_if_fail(toolbar_item != NULL);
1082
1083         switch (toolbar_item->type) {
1084         case TOOLBAR_MAIN:
1085                 mainwin = (MainWindow*)toolbar_item->parent;
1086                 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM) 
1087                         mainwindow_learn(mainwin, TRUE);
1088                 else
1089                         mainwindow_learn(mainwin, FALSE);
1090                 break;
1091         case TOOLBAR_MSGVIEW:
1092                 msgview = (MessageView*)toolbar_item->parent;
1093                 if (msgview->toolbar->learn_btn_type == LEARN_SPAM) 
1094                         messageview_learn(msgview, TRUE);
1095                 else
1096                         messageview_learn(msgview, FALSE);
1097                 break;
1098         default:
1099                 debug_print("toolbar event not supported\n");
1100         }
1101 }
1102
1103
1104 /*
1105  * Reply Message
1106  */
1107 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1108 {
1109         toolbar_reply(data, prefs_common.reply_with_quote ? 
1110                       COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1111 }
1112
1113
1114 /*
1115  * Reply message to Sender and All recipients
1116  */
1117 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1118 {
1119         toolbar_reply(data,
1120                       prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
1121                       : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1122 }
1123
1124
1125 /*
1126  * Reply to Mailing List
1127  */
1128 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1129 {
1130         toolbar_reply(data, 
1131                       prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE 
1132                       : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1133 }
1134
1135
1136 /*
1137  * Reply to sender of message
1138  */ 
1139 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1140 {
1141         toolbar_reply(data, 
1142                       prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
1143                       : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1144 }
1145
1146 /*
1147  * Open addressbook
1148  */ 
1149 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1150 {
1151         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1152         Compose *compose;
1153
1154         g_return_if_fail(toolbar_item != NULL);
1155
1156         switch (toolbar_item->type) {
1157         case TOOLBAR_MAIN:
1158         case TOOLBAR_MSGVIEW:
1159                 compose = NULL;
1160                 break;
1161         case TOOLBAR_COMPOSE:
1162                 compose = (Compose *)toolbar_item->parent;
1163                 break;
1164         default:
1165                 return;
1166         }
1167         addressbook_open(compose);
1168 }
1169
1170
1171 /*
1172  * Forward current/selected(s) message(s)
1173  */
1174 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1175 {
1176         toolbar_reply(data, COMPOSE_FORWARD);
1177 }
1178
1179 /*
1180  * Goto Prev Unread Message
1181  */
1182 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1183 {
1184         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1185         MainWindow *mainwin;
1186         MessageView *msgview;
1187
1188         g_return_if_fail(toolbar_item != NULL);
1189
1190         switch (toolbar_item->type) {
1191         case TOOLBAR_MAIN:
1192                 mainwin = (MainWindow*)toolbar_item->parent;
1193                 summary_select_prev_unread(mainwin->summaryview);
1194                 break;
1195                 
1196         case TOOLBAR_MSGVIEW:
1197                 msgview = (MessageView*)toolbar_item->parent;
1198                 msgview->updating = TRUE;
1199                 summary_select_prev_unread(msgview->mainwin->summaryview);
1200                 msgview->updating = FALSE;
1201
1202                 if (msgview->deferred_destroy) {
1203                         debug_print("messageview got away!\n");
1204                         messageview_destroy(msgview);
1205                         return;
1206                 }
1207                 
1208                 /* Now we need to update the messageview window */
1209                 if (msgview->mainwin->summaryview->selected) {
1210                         MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1211                        
1212                         if (msginfo)
1213                                 messageview_show(msgview, msginfo, 
1214                                          msgview->all_headers);
1215                 } else {
1216                         gtk_widget_destroy(msgview->window);
1217                 }
1218                 break;
1219         default:
1220                 debug_print("toolbar event not supported\n");
1221         }
1222 }
1223
1224 /*
1225  * Goto Next Unread Message
1226  */
1227 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1228 {
1229         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1230         MainWindow *mainwin;
1231         MessageView *msgview;
1232
1233         g_return_if_fail(toolbar_item != NULL);
1234
1235         switch (toolbar_item->type) {
1236         case TOOLBAR_MAIN:
1237                 mainwin = (MainWindow*)toolbar_item->parent;
1238                 summary_select_next_unread(mainwin->summaryview);
1239                 break;
1240                 
1241         case TOOLBAR_MSGVIEW:
1242                 msgview = (MessageView*)toolbar_item->parent;
1243                 msgview->updating = TRUE;
1244                 summary_select_next_unread(msgview->mainwin->summaryview);
1245                 msgview->updating = FALSE;
1246
1247                 if (msgview->deferred_destroy) {
1248                         debug_print("messageview got away!\n");
1249                         messageview_destroy(msgview);
1250                         return;
1251                 }
1252
1253                 /* Now we need to update the messageview window */
1254                 if (msgview->mainwin->summaryview->selected) {
1255                         MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1256                         
1257                         if (msginfo)
1258                                 messageview_show(msgview, msginfo, 
1259                                          msgview->all_headers);
1260                 } else {
1261                         gtk_widget_destroy(msgview->window);
1262                 }
1263                 break;
1264         default:
1265                 debug_print("toolbar event not supported\n");
1266         }
1267 }
1268
1269 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1270 {
1271         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1272         MainWindow *mainwin;
1273
1274         g_return_if_fail(toolbar_item != NULL);
1275
1276         switch (toolbar_item->type) {
1277         case TOOLBAR_MAIN:
1278                 mainwin = (MainWindow *) toolbar_item->parent;
1279                 summary_toggle_ignore_thread(mainwin->summaryview);
1280                 break;
1281         case TOOLBAR_MSGVIEW:
1282                 /* TODO: see toolbar_next_unread_cb() if you need
1283                  * this in the message view */
1284                 break;
1285         default:
1286                 debug_print("toolbar event not supported\n");
1287                 break;
1288         }
1289 }
1290
1291 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1292 {
1293         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1294
1295         g_return_if_fail(toolbar_item != NULL);
1296         inc_cancel_all();
1297 }
1298
1299
1300 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1301 {
1302         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1303         MainWindow *mainwin;
1304
1305         g_return_if_fail(toolbar_item != NULL);
1306
1307         switch (toolbar_item->type) {
1308         case TOOLBAR_MAIN:
1309                 mainwin = (MainWindow *) toolbar_item->parent;
1310                 summary_print(mainwin->summaryview);
1311                 break;
1312         case TOOLBAR_MSGVIEW:
1313                 /* TODO: see toolbar_next_unread_cb() if you need
1314                  * this in the message view */
1315                 break;
1316         default:
1317                 debug_print("toolbar event not supported\n");
1318                 break;
1319         }
1320 }
1321
1322 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1323 {
1324         compose_toolbar_cb(A_SEND, data);
1325 }
1326
1327 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1328 {
1329         compose_toolbar_cb(A_SENDL, data);
1330 }
1331
1332 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1333 {
1334         compose_toolbar_cb(A_DRAFT, data);
1335 }
1336
1337 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1338 {
1339         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1340         MainWindow *mainwin;
1341         MessageView *messageview;
1342         Compose *compose;
1343
1344         g_return_if_fail(toolbar_item != NULL);
1345
1346         switch (toolbar_item->type) {
1347         case TOOLBAR_MAIN:
1348                 mainwin = (MainWindow *) toolbar_item->parent;
1349                 app_will_exit(NULL, mainwin);
1350                 break;
1351         case TOOLBAR_MSGVIEW:
1352                 messageview = (MessageView *)toolbar_item->parent;
1353                 messageview_destroy(messageview);
1354                 break;
1355         case TOOLBAR_COMPOSE:
1356                 compose = (Compose *)toolbar_item->parent;
1357                 compose_close_toolbar(compose);
1358                 break;
1359         }
1360 }
1361
1362 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1363 {
1364         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1365         MainWindow *mainwin;
1366
1367         g_return_if_fail(toolbar_item != NULL);
1368
1369         switch (toolbar_item->type) {
1370         case TOOLBAR_MAIN:
1371                 mainwin = (MainWindow *) toolbar_item->parent;
1372                 summary_open_row(NULL, mainwin->summaryview);
1373                 break;
1374         case TOOLBAR_MSGVIEW:
1375                 debug_print("toolbar event not supported\n");
1376                 break;
1377         case TOOLBAR_COMPOSE:
1378                 debug_print("toolbar event not supported\n");
1379                 break;
1380         }
1381 }
1382
1383 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1384 {
1385         compose_toolbar_cb(A_INSERT, data);
1386 }
1387
1388 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1389 {
1390         compose_toolbar_cb(A_ATTACH, data);
1391 }
1392
1393 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1394 {
1395         compose_toolbar_cb(A_SIG, data);
1396 }
1397
1398 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1399 {
1400         compose_toolbar_cb(A_EXTEDITOR, data);
1401 }
1402
1403 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1404 {
1405         compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1406 }
1407
1408 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1409 {
1410         compose_toolbar_cb(A_LINEWRAP_ALL, data);
1411 }
1412
1413 #ifdef USE_ASPELL
1414 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1415 {
1416         compose_toolbar_cb(A_CHECK_SPELLING, data);
1417 }
1418 #endif
1419 /*
1420  * Execute actions from toolbar
1421  */
1422 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1423 {
1424         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1425         GSList *action_list;
1426         MainWindow *mainwin;
1427         Compose *compose;
1428         MessageView *msgview;
1429         gpointer parent = toolbar_item->parent;
1430
1431         g_return_if_fail(toolbar_item != NULL);
1432
1433         switch (toolbar_item->type) {
1434         case TOOLBAR_MAIN:
1435                 mainwin = (MainWindow*)parent;
1436                 action_list = mainwin->toolbar->action_list;
1437                 break;
1438         case TOOLBAR_COMPOSE:
1439                 compose = (Compose*)parent;
1440                 action_list = compose->toolbar->action_list;
1441                 break;
1442         case TOOLBAR_MSGVIEW:
1443                 msgview = (MessageView*)parent;
1444                 action_list = msgview->toolbar->action_list;
1445                 break;
1446         default:
1447                 debug_print("toolbar event not supported\n");
1448                 return;
1449         }
1450         toolbar_action_execute(widget, action_list, parent, toolbar_item->type);        
1451 }
1452
1453 static MainWindow *get_mainwin(gpointer data)
1454 {
1455         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1456         MainWindow *mainwin = NULL;
1457         MessageView *msgview;
1458
1459         g_return_val_if_fail(toolbar_item != NULL, NULL);
1460
1461         switch(toolbar_item->type) {
1462         case TOOLBAR_MAIN:
1463                 mainwin = (MainWindow*)toolbar_item->parent;
1464                 break;
1465         case TOOLBAR_MSGVIEW:
1466                 msgview = (MessageView*)toolbar_item->parent;
1467                 mainwin = (MainWindow*)msgview->mainwin;
1468                 break;
1469         default:
1470                 break;
1471         }
1472
1473         return mainwin;
1474 }
1475
1476 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1477 {
1478         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1479         MainWindow *mainwin = NULL;
1480         switch(toolbar_item->type) {
1481         case TOOLBAR_MAIN:
1482                 mainwin = (MainWindow*)toolbar_item->parent;
1483                 break;
1484         default:
1485                 g_warning("wrong toolbar type\n");
1486                 return;
1487         }
1488
1489         if (!mainwin->in_folder) {
1490                 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1491                 if (item) {
1492                         folderview_select(mainwin->folderview, item);
1493                 }
1494         } else {
1495                 gtk_widget_grab_focus(mainwin->folderview->ctree);
1496                 mainwindow_exit_folder(mainwin);
1497         }
1498 }
1499
1500 static void toolbar_buttons_cb(GtkWidget   *widget, 
1501                                ToolbarItem *item)
1502 {
1503         gint num_items;
1504         gint i;
1505         struct {
1506                 gint   index;
1507                 void (*func)(GtkWidget *widget, gpointer data);
1508         } callbacks[] = {
1509                 { A_RECEIVE_ALL,        toolbar_inc_all_cb              },
1510                 { A_RECEIVE_CUR,        toolbar_inc_cb                  },
1511                 { A_SEND_QUEUED,        toolbar_send_queued_cb          },
1512                 { A_COMPOSE_EMAIL,      toolbar_compose_cb              },
1513                 { A_COMPOSE_NEWS,       toolbar_compose_cb              },
1514                 { A_REPLY_MESSAGE,      toolbar_reply_cb                },
1515                 { A_REPLY_SENDER,       toolbar_reply_to_sender_cb      },
1516                 { A_REPLY_ALL,          toolbar_reply_to_all_cb         },
1517                 { A_REPLY_ML,           toolbar_reply_to_list_cb        },
1518                 { A_FORWARD,            toolbar_forward_cb              },
1519                 { A_TRASH,              toolbar_trash_cb                },
1520                 { A_DELETE_REAL,        toolbar_delete_cb               },
1521                 { A_EXECUTE,            toolbar_exec_cb                 },
1522                 { A_GOTO_PREV,          toolbar_prev_unread_cb          },
1523                 { A_GOTO_NEXT,          toolbar_next_unread_cb          },
1524                 { A_IGNORE_THREAD,      toolbar_ignore_thread_cb        },
1525                 { A_PRINT,              toolbar_print_cb                },
1526                 { A_LEARN_SPAM,         toolbar_learn_cb                },
1527                 { A_GO_FOLDERS,         toolbar_go_folders_cb           },
1528
1529                 { A_SEND,               toolbar_send_cb                 },
1530                 { A_SENDL,              toolbar_send_later_cb           },
1531                 { A_DRAFT,              toolbar_draft_cb                },
1532                 { A_OPEN_MAIL,          toolbar_open_mail_cb            },
1533                 { A_CLOSE,              toolbar_close_cb                },
1534                 { A_INSERT,             toolbar_insert_cb               },
1535                 { A_ATTACH,             toolbar_attach_cb               },
1536                 { A_SIG,                toolbar_sig_cb                  },
1537                 { A_EXTEDITOR,          toolbar_ext_editor_cb           },
1538                 { A_LINEWRAP_CURRENT,   toolbar_linewrap_current_cb     },
1539                 { A_LINEWRAP_ALL,       toolbar_linewrap_all_cb         },
1540                 { A_ADDRBOOK,           toolbar_addrbook_cb             },
1541 #ifdef USE_ASPELL
1542                 { A_CHECK_SPELLING,     toolbar_check_spelling_cb       },
1543 #endif
1544                 { A_SYL_ACTIONS,        toolbar_actions_execute_cb      },
1545                 { A_CANCEL_INC,         toolbar_cancel_inc_cb           }
1546         };
1547
1548         num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1549
1550         for (i = 0; i < num_items; i++) {
1551                 if (callbacks[i].index == item->index) {
1552                         callbacks[i].func(widget, item);
1553                         return;
1554                 }
1555         }
1556 }
1557
1558 /**
1559  * Create a new toolbar with specified type
1560  * if a callback list is passed it will be used before the 
1561  * common callback list
1562  **/
1563 Toolbar *toolbar_create(ToolbarType      type, 
1564                         GtkWidget       *container,
1565                         gpointer         data)
1566 {
1567         ToolbarItem *toolbar_item;
1568
1569         GtkWidget *toolbar;
1570         GtkWidget *icon_wid = NULL;
1571         GtkWidget *icon_news;
1572         GtkWidget *icon_ham;
1573         GtkWidget *item;
1574         GtkWidget *item_news;
1575         GtkWidget *item_ham;
1576         guint n_menu_entries;
1577         ComboButton *getall_combo;
1578         ComboButton *reply_combo;
1579         ComboButton *replyall_combo;
1580         ComboButton *replylist_combo;
1581         ComboButton *replysender_combo;
1582         ComboButton *fwd_combo;
1583         ComboButton *compose_combo;
1584         ComboButton *ham_combo;
1585
1586         GtkTooltips *toolbar_tips;
1587         ToolbarSylpheedActions *action_item;
1588         GSList *cur;
1589         GSList *toolbar_list;
1590         Toolbar *toolbar_data;
1591
1592         
1593         toolbar_tips = gtk_tooltips_new();
1594         
1595         toolbar_read_config_file(type);
1596         toolbar_list = toolbar_get_list(type);
1597
1598         toolbar_data = g_new0(Toolbar, 1); 
1599
1600         toolbar = gtk_toolbar_new();
1601         gtk_container_add(GTK_CONTAINER(container), toolbar);
1602         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1603         gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1604         gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1605         
1606         for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1607
1608                 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1609                         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1610                         continue;
1611                 }
1612                 
1613                 toolbar_item = g_new0(ToolbarItem, 1); 
1614                 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1615                 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1616                 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1617                 toolbar_item->parent = data;
1618                 toolbar_item->type = type;
1619
1620                 /* collect toolbar items in list to keep track */
1621                 toolbar_data->item_list = 
1622                         g_slist_append(toolbar_data->item_list, 
1623                                        toolbar_item);
1624                 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1625                 item  = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1626                                                 toolbar_item->text,
1627                                                 (""),
1628                                                 (""),
1629                                                 icon_wid, G_CALLBACK(toolbar_buttons_cb), 
1630                                                 toolbar_item);
1631                 
1632                 switch (toolbar_item->index) {
1633
1634                 case A_GO_FOLDERS:
1635                         toolbar_data->folders_btn = item;
1636                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1637                                              toolbar_data->folders_btn,
1638                                            _("Go to folder list"), NULL);
1639                         break;
1640                 case A_RECEIVE_ALL:
1641                         toolbar_data->getall_btn = item;
1642                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1643                                              toolbar_data->getall_btn, 
1644                                            _("Receive Mail on all Accounts"), NULL);
1645                         getall_combo = gtkut_combo_button_create(toolbar_data->getall_btn, NULL, 0,
1646                                         "<GetAll>", (gpointer)toolbar_item);
1647                         gtk_button_set_relief(GTK_BUTTON(getall_combo->arrow),
1648                                               GTK_RELIEF_NONE);
1649                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1650                                                   GTK_WIDGET_PTR(getall_combo),
1651                                                   _("Receive Mail on selected Account"), "Reply");
1652                         toolbar_data->getall_combo = getall_combo;
1653                         break;
1654                 case A_RECEIVE_CUR:
1655                         toolbar_data->get_btn = item;
1656                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1657                                              toolbar_data->get_btn,
1658                                            _("Receive Mail on current Account"), NULL);
1659                         break;
1660                 case A_SEND_QUEUED:
1661                         toolbar_data->send_btn = item; 
1662                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1663                                              toolbar_data->send_btn,
1664                                            _("Send Queued Messages"), NULL);
1665                         break;
1666                 case A_CLOSE:
1667                         toolbar_data->close_window_btn = item; 
1668                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1669                                              toolbar_data->close_window_btn,
1670                                            _("Close window"), NULL);
1671                         break;
1672                 case A_OPEN_MAIL:
1673                         toolbar_data->open_mail_btn = item; 
1674                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1675                                              toolbar_data->open_mail_btn,
1676                                            _("Open email"), NULL);
1677                         break;
1678                 case A_COMPOSE_EMAIL:
1679                         icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1680                         item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1681                                                             _("Compose"),
1682                                                             (""),
1683                                                             (""),
1684                                                             icon_news, G_CALLBACK(toolbar_buttons_cb), 
1685                                                             toolbar_item);
1686                         toolbar_data->compose_mail_btn = item; 
1687                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1688                                              toolbar_data->compose_mail_btn,
1689                                            _("Compose Email"), NULL);
1690                         toolbar_data->compose_news_btn = item_news;
1691                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1692                                              toolbar_data->compose_news_btn,
1693                                            _("Compose News"), NULL);
1694                         compose_combo = gtkut_combo_button_create(toolbar_data->compose_mail_btn, NULL, 0,
1695                                         "<Compose>", (gpointer)toolbar_item);
1696                         gtk_button_set_relief(GTK_BUTTON(compose_combo->arrow),
1697                                               GTK_RELIEF_NONE);
1698                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1699                                                   GTK_WIDGET_PTR(compose_combo),
1700                                                   _("Compose with selected Account"), "Compose");
1701                         toolbar_data->compose_combo = compose_combo;
1702                         break;
1703                 case A_LEARN_SPAM:
1704                         icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1705                         item_ham = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1706                                                             _("Ham"),
1707                                                             (""),
1708                                                             (""),
1709                                                             icon_ham, G_CALLBACK(toolbar_buttons_cb), 
1710                                                             toolbar_item);
1711                         toolbar_data->learn_spam_btn = item; 
1712                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1713                                              toolbar_data->learn_spam_btn,
1714                                            _("Learn Spam"), NULL);
1715                         toolbar_data->learn_ham_btn = item_ham;
1716                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1717                                              toolbar_data->learn_ham_btn,
1718                                            _("Learn Ham"), NULL);                       
1719                         n_menu_entries = sizeof(learn_entries) / 
1720                                 sizeof(learn_entries[0]);
1721                         ham_combo = gtkut_combo_button_create(toolbar_data->learn_spam_btn,
1722                                               learn_entries, n_menu_entries,
1723                                               "<LearnSpam>", (gpointer)toolbar_item);
1724                         gtk_button_set_relief(GTK_BUTTON(ham_combo->arrow),
1725                                               GTK_RELIEF_NONE);
1726                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1727                                                   GTK_WIDGET_PTR(ham_combo),
1728                                                   _("Learn as..."), _("Learn"));
1729                         toolbar_data->ham_combo = ham_combo;
1730                         break;
1731                 case A_REPLY_MESSAGE:
1732                         toolbar_data->reply_btn = item;
1733                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1734                                              toolbar_data->reply_btn,
1735                                            _("Reply to Message"), NULL);
1736                         n_menu_entries = sizeof(reply_entries) / 
1737                                 sizeof(reply_entries[0]);
1738                         reply_combo = gtkut_combo_button_create(toolbar_data->reply_btn,
1739                                               reply_entries, n_menu_entries,
1740                                               "<Reply>", (gpointer)toolbar_item);
1741                         gtk_button_set_relief(GTK_BUTTON(reply_combo->arrow),
1742                                               GTK_RELIEF_NONE);
1743                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1744                                                   GTK_WIDGET_PTR(reply_combo),
1745                                                   _("Reply to Message"), "Reply");
1746                         toolbar_data->reply_combo = reply_combo;
1747                         break;
1748                 case A_REPLY_SENDER:
1749                         toolbar_data->replysender_btn = item;
1750                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1751                                              toolbar_data->replysender_btn,
1752                                            _("Reply to Sender"), NULL);
1753                         n_menu_entries = sizeof(replysender_entries) / 
1754                                 sizeof(replysender_entries[0]);
1755                         replysender_combo = gtkut_combo_button_create(toolbar_data->replysender_btn,
1756                                               replysender_entries, n_menu_entries,
1757                                               "<ReplySender>", (gpointer)toolbar_item);
1758                         gtk_button_set_relief(GTK_BUTTON(replysender_combo->arrow),
1759                                               GTK_RELIEF_NONE);
1760                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1761                                                   GTK_WIDGET_PTR(replysender_combo),
1762                                                   _("Reply to Sender"), "ReplySender");
1763                         toolbar_data->replysender_combo = replysender_combo;
1764                         break;
1765                 case A_REPLY_ALL:
1766                         toolbar_data->replyall_btn = item;
1767                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1768                                              toolbar_data->replyall_btn,
1769                                            _("Reply to All"), NULL);
1770                         n_menu_entries = sizeof(replyall_entries) / 
1771                                 sizeof(replyall_entries[0]);
1772                         replyall_combo = gtkut_combo_button_create(toolbar_data->replyall_btn,
1773                                               replyall_entries, n_menu_entries,
1774                                               "<ReplyAll>", (gpointer)toolbar_item);
1775                         gtk_button_set_relief(GTK_BUTTON(replyall_combo->arrow),
1776                                               GTK_RELIEF_NONE);
1777                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1778                                                   GTK_WIDGET_PTR(replyall_combo),
1779                                                   _("Reply to All"), "ReplyAll");
1780                         toolbar_data->replyall_combo = replyall_combo;
1781                         break;
1782                 case A_REPLY_ML:
1783                         toolbar_data->replylist_btn = item;
1784                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1785                                              toolbar_data->replylist_btn,
1786                                            _("Reply to Mailing-list"), NULL);
1787                         n_menu_entries = sizeof(replylist_entries) / 
1788                                 sizeof(replylist_entries[0]);
1789                         replylist_combo = gtkut_combo_button_create(toolbar_data->replylist_btn,
1790                                               replylist_entries, n_menu_entries,
1791                                               "<ReplyList>", (gpointer)toolbar_item);
1792                         gtk_button_set_relief(GTK_BUTTON(replylist_combo->arrow),
1793                                               GTK_RELIEF_NONE);
1794                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1795                                                   GTK_WIDGET_PTR(replylist_combo),
1796                                                   _("Reply to Mailing-list"), "ReplyList");
1797                         toolbar_data->replylist_combo = replylist_combo;
1798                         break;
1799                 case A_FORWARD:
1800                         toolbar_data->fwd_btn = item;
1801                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1802                                              toolbar_data->fwd_btn,
1803                                              _("Forward Message"), NULL);
1804                         n_menu_entries = sizeof(forward_entries) / 
1805                                 sizeof(forward_entries[0]);
1806                         fwd_combo = gtkut_combo_button_create(toolbar_data->fwd_btn,
1807                                               forward_entries, n_menu_entries,
1808                                               "<Forward>", (gpointer)toolbar_item);
1809                         gtk_button_set_relief(GTK_BUTTON(fwd_combo->arrow),
1810                                               GTK_RELIEF_NONE);
1811                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1812                                                   GTK_WIDGET_PTR(fwd_combo),
1813                                                   _("Forward Message"), "Fwd");
1814                         toolbar_data->fwd_combo = fwd_combo;
1815                         break;
1816                 case A_TRASH:
1817                         toolbar_data->trash_btn = item;
1818                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1819                                              toolbar_data->trash_btn,
1820                                              _("Trash Message"), NULL);
1821                         break;
1822                 case A_DELETE_REAL:
1823                         toolbar_data->delete_btn = item;
1824                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1825                                              toolbar_data->delete_btn,
1826                                              _("Delete Message"), NULL);
1827                         break;
1828                 case A_EXECUTE:
1829                         toolbar_data->exec_btn = item;
1830                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1831                                              toolbar_data->exec_btn,
1832                                            _("Execute"), NULL);
1833                         break;
1834                 case A_GOTO_PREV:
1835                         toolbar_data->prev_btn = item;
1836                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1837                                              toolbar_data->prev_btn,
1838                                              _("Go to Previous Unread Message"),
1839                                              NULL);
1840                         break;
1841                 case A_GOTO_NEXT:
1842                         toolbar_data->next_btn = item;
1843                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1844                                              toolbar_data->next_btn,
1845                                              _("Go to Next Unread Message"),
1846                                              NULL);
1847                         break;
1848                 
1849                 /* Compose Toolbar */
1850                 case A_SEND:
1851                         toolbar_data->send_btn = item;
1852                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1853                                              toolbar_data->send_btn, 
1854                                              _("Send Message"), NULL);
1855                         break;
1856                 case A_SENDL:
1857                         toolbar_data->sendl_btn = item;
1858                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1859                                              toolbar_data->sendl_btn,
1860                                              _("Put into queue folder and send later"), NULL);
1861                         break;
1862                 case A_DRAFT:
1863                         toolbar_data->draft_btn = item; 
1864                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1865                                              toolbar_data->draft_btn,
1866                                              _("Save to draft folder"), NULL);
1867                         break;
1868                 case A_INSERT:
1869                         toolbar_data->insert_btn = item; 
1870                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1871                                              toolbar_data->insert_btn,
1872                                              _("Insert file"), NULL);
1873                         break;
1874                 case A_ATTACH:
1875                         toolbar_data->attach_btn = item;
1876                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1877                                              toolbar_data->attach_btn,
1878                                              _("Attach file"), NULL);
1879                         break;
1880                 case A_SIG:
1881                         toolbar_data->sig_btn = item;
1882                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1883                                              toolbar_data->sig_btn,
1884                                              _("Insert signature"), NULL);
1885                         break;
1886                 case A_EXTEDITOR:
1887                         toolbar_data->exteditor_btn = item;
1888                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1889                                              toolbar_data->exteditor_btn,
1890                                              _("Edit with external editor"), NULL);
1891                         break;
1892                 case A_LINEWRAP_CURRENT:
1893                         toolbar_data->linewrap_current_btn = item;
1894                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1895                                              toolbar_data->linewrap_current_btn,
1896                                              _("Wrap long lines of current paragraph"), NULL);
1897                         break;
1898                 case A_LINEWRAP_ALL:
1899                         toolbar_data->linewrap_all_btn = item;
1900                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1901                                              toolbar_data->linewrap_all_btn,
1902                                              _("Wrap all long lines"), NULL);
1903                         break;
1904                 case A_ADDRBOOK:
1905                         toolbar_data->addrbook_btn = item;
1906                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1907                                              toolbar_data->addrbook_btn,
1908                                              _("Address book"), NULL);
1909                         break;
1910 #ifdef USE_ASPELL
1911                 case A_CHECK_SPELLING:
1912                         toolbar_data->spellcheck_btn = item;
1913                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1914                                              toolbar_data->spellcheck_btn,
1915                                              _("Check spelling"), NULL);
1916                         break;
1917 #endif
1918
1919                 case A_SYL_ACTIONS:
1920                         action_item = g_new0(ToolbarSylpheedActions, 1);
1921                         action_item->widget = item;
1922                         action_item->name   = g_strdup(toolbar_item->text);
1923
1924                         toolbar_data->action_list = 
1925                                 g_slist_append(toolbar_data->action_list,
1926                                                action_item);
1927
1928                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1929                                              item,
1930                                              action_item->name, NULL);
1931
1932                         gtk_widget_show(item);
1933                         break;
1934                 case A_CANCEL_INC:
1935                         toolbar_data->cancel_inc_btn = item;
1936                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1937                                              toolbar_data->cancel_inc_btn,
1938                                              _("Cancel receiving"), NULL);
1939                         break;
1940                 default:
1941                         /* find and set the tool tip text */
1942                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1943                                              item,
1944                                              toolbar_ret_descr_from_val
1945                                                 (toolbar_item->index),
1946                                              NULL);
1947                         break;
1948                 }
1949
1950         }
1951         toolbar_data->toolbar = toolbar;
1952         if (type == TOOLBAR_MAIN)
1953                 activate_compose_button(toolbar_data, 
1954                                         prefs_common.toolbar_style, 
1955                                         toolbar_data->compose_btn_type);
1956         if (type != TOOLBAR_COMPOSE)
1957                 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
1958                                 LEARN_SPAM);
1959         
1960         gtk_widget_show_all(toolbar);
1961         
1962         return toolbar_data; 
1963 }
1964
1965 /**
1966  * Free toolbar structures
1967  */ 
1968 void toolbar_destroy(Toolbar * toolbar) {
1969
1970         TOOLBAR_DESTROY_ITEMS(toolbar->item_list);      
1971         TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1972 }
1973
1974 void toolbar_update(ToolbarType type, gpointer data)
1975 {
1976         Toolbar *toolbar_data;
1977         GtkWidget *handlebox;
1978         MainWindow *mainwin = (MainWindow*)data;
1979         Compose    *compose = (Compose*)data;
1980         MessageView *msgview = (MessageView*)data;
1981
1982         switch(type) {
1983         case TOOLBAR_MAIN:
1984                 toolbar_data = mainwin->toolbar;
1985                 handlebox    = mainwin->handlebox;
1986                 break;
1987         case TOOLBAR_COMPOSE:
1988                 toolbar_data = compose->toolbar;
1989                 handlebox    = compose->handlebox;
1990                 break;
1991         case TOOLBAR_MSGVIEW:
1992                 toolbar_data = msgview->toolbar;
1993                 handlebox    = msgview->handlebox;
1994                 break;
1995         default:
1996                 return;
1997         }
1998
1999         gtk_container_remove(GTK_CONTAINER(handlebox), 
2000                              GTK_WIDGET(toolbar_data->toolbar));
2001
2002         toolbar_init(toolbar_data);
2003         toolbar_data = toolbar_create(type, handlebox, data);
2004         switch(type) {
2005         case TOOLBAR_MAIN:
2006                 mainwin->toolbar = toolbar_data;
2007                 break;
2008         case TOOLBAR_COMPOSE:
2009                 compose->toolbar = toolbar_data;
2010                 break;
2011         case TOOLBAR_MSGVIEW:
2012                 msgview->toolbar = toolbar_data;
2013                 break;
2014         }
2015
2016         toolbar_style(type, prefs_common.toolbar_style, data);
2017
2018         if (type == TOOLBAR_MAIN) {
2019                 toolbar_main_set_sensitive((MainWindow*)data);
2020                 account_set_menu_only_toolbar();
2021         }
2022 }
2023
2024 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) {            \
2025         gboolean in_btn = FALSE;                                \
2026         if (GTK_IS_BUTTON(widget))                              \
2027                 in_btn = GTK_BUTTON(widget)->in_button;         \
2028         gtk_widget_set_sensitive(widget, sensitive);            \
2029         if (GTK_IS_BUTTON(widget))                              \
2030                 GTK_BUTTON(widget)->in_button = in_btn;         \
2031 }
2032
2033 void toolbar_main_set_sensitive(gpointer data)
2034 {
2035         SensitiveCond state;
2036         gboolean sensitive;
2037         MainWindow *mainwin = (MainWindow*)data;
2038         Toolbar *toolbar = mainwin->toolbar;
2039         GSList *cur;
2040         GSList *entry_list = NULL;
2041         
2042         typedef struct _Entry Entry;
2043         struct _Entry {
2044                 GtkWidget *widget;
2045                 SensitiveCond cond;
2046                 gboolean empty;
2047         };
2048
2049 #define SET_WIDGET_COND(w, c)     \
2050 { \
2051         Entry *e = g_new0(Entry, 1); \
2052         e->widget = w; \
2053         e->cond   = c; \
2054         entry_list = g_slist_append(entry_list, e); \
2055 }
2056
2057         
2058         if (toolbar->get_btn)
2059                 SET_WIDGET_COND(toolbar->get_btn, 
2060                         M_HAVE_ACCOUNT|M_UNLOCKED);
2061
2062         if (toolbar->getall_btn) {
2063                 SET_WIDGET_COND(toolbar->getall_btn, 
2064                         M_HAVE_ACCOUNT|M_UNLOCKED);
2065                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->getall_combo),
2066                         M_HAVE_ACCOUNT|M_UNLOCKED);
2067         }
2068         if (toolbar->send_btn) {
2069                 SET_WIDGET_COND(toolbar->send_btn,
2070                         M_HAVE_QUEUED_MAILS);
2071         }
2072         if (toolbar->compose_mail_btn) {
2073                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->compose_combo),
2074                         M_HAVE_ACCOUNT);
2075                 SET_WIDGET_COND(toolbar->compose_news_btn, 
2076                         M_HAVE_ACCOUNT);
2077         }
2078         if (toolbar->close_window_btn) {
2079                 SET_WIDGET_COND(toolbar->compose_news_btn, 
2080                         M_UNLOCKED);
2081         }
2082         if (toolbar->open_mail_btn) {
2083                 SET_WIDGET_COND(toolbar->open_mail_btn, 
2084                         M_TARGET_EXIST);
2085         }
2086         if (toolbar->reply_btn) {
2087                 SET_WIDGET_COND(toolbar->reply_btn,
2088                         M_HAVE_ACCOUNT|M_TARGET_EXIST);
2089                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->reply_combo),
2090                         M_HAVE_ACCOUNT|M_TARGET_EXIST);
2091         }
2092         if (toolbar->replyall_btn) {
2093                 SET_WIDGET_COND(toolbar->replyall_btn,
2094                         M_HAVE_ACCOUNT|M_TARGET_EXIST);
2095                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replyall_combo),
2096                         M_HAVE_ACCOUNT|M_TARGET_EXIST);
2097         }
2098         if (toolbar->replylist_btn) {
2099                 SET_WIDGET_COND(toolbar->replylist_btn,
2100                         M_HAVE_ACCOUNT|M_TARGET_EXIST);
2101                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replylist_combo),
2102                         M_HAVE_ACCOUNT|M_TARGET_EXIST);
2103         }
2104         if (toolbar->replysender_btn) {
2105                 SET_WIDGET_COND(toolbar->replysender_btn,
2106                         M_HAVE_ACCOUNT|M_TARGET_EXIST);
2107                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replysender_combo),
2108                         M_HAVE_ACCOUNT|M_TARGET_EXIST);
2109         }
2110         if (toolbar->fwd_btn) {
2111                 SET_WIDGET_COND(toolbar->fwd_btn, 
2112                         M_HAVE_ACCOUNT|M_TARGET_EXIST);
2113                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->fwd_combo),
2114                         M_HAVE_ACCOUNT|M_TARGET_EXIST); 
2115         }
2116         if (toolbar->fwd_combo) {
2117                 GtkWidget *submenu = gtk_item_factory_get_widget(toolbar->fwd_combo->factory, "/Redirect");
2118                 SET_WIDGET_COND(submenu, 
2119                         M_HAVE_ACCOUNT|M_TARGET_EXIST); 
2120         }
2121
2122         if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2123                 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
2124         } else {
2125                 SET_WIDGET_COND(toolbar->next_btn, 0);
2126         }
2127         
2128         if (toolbar->trash_btn)
2129                 SET_WIDGET_COND(toolbar->trash_btn,
2130                         M_TARGET_EXIST|M_ALLOW_DELETE);
2131
2132         if (toolbar->delete_btn)
2133                 SET_WIDGET_COND(toolbar->delete_btn,
2134                         M_TARGET_EXIST|M_ALLOW_DELETE);
2135
2136         if (toolbar->exec_btn)
2137                 SET_WIDGET_COND(toolbar->exec_btn, 
2138                         M_DELAY_EXEC);
2139         
2140         if (toolbar->learn_ham_btn)
2141                 SET_WIDGET_COND(toolbar->learn_ham_btn,
2142                         M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2143
2144         if (toolbar->learn_spam_btn)
2145                 SET_WIDGET_COND(toolbar->learn_spam_btn, 
2146                         M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2147
2148         if (toolbar->ham_combo)
2149                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->ham_combo),
2150                         M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2151
2152         if (toolbar->cancel_inc_btn)
2153                 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2154                                 M_INC_ACTIVE);
2155
2156         for (cur = toolbar->action_list; cur != NULL;  cur = cur->next) {
2157                 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
2158                 
2159                 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2160         }
2161
2162 #undef SET_WIDGET_COND
2163
2164         state = main_window_get_current_state(mainwin);
2165
2166         for (cur = entry_list; cur != NULL; cur = cur->next) {
2167                 Entry *e = (Entry*) cur->data;
2168
2169                 if (e->widget != NULL) {
2170                         sensitive = ((e->cond & state) == e->cond);
2171                         GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive); 
2172                 }
2173         }
2174         
2175         while (entry_list != NULL) {
2176                 Entry *e = (Entry*) entry_list->data;
2177
2178                 g_free(e);
2179                 entry_list = g_slist_remove(entry_list, e);
2180         }
2181
2182         g_slist_free(entry_list);
2183
2184         activate_compose_button(toolbar, 
2185                                 prefs_common.toolbar_style,
2186                                 toolbar->compose_btn_type);
2187         
2188 }
2189
2190 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2191 {
2192         Compose *compose = (Compose*)data;
2193         GSList *items = compose->toolbar->action_list;
2194
2195         if (compose->toolbar->send_btn)
2196                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2197         if (compose->toolbar->sendl_btn)
2198                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2199         if (compose->toolbar->draft_btn )
2200                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2201         if (compose->toolbar->insert_btn )
2202                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2203         if (compose->toolbar->attach_btn)
2204                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2205         if (compose->toolbar->sig_btn)
2206                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2207         if (compose->toolbar->exteditor_btn)
2208                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2209         if (compose->toolbar->linewrap_current_btn)
2210                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2211         if (compose->toolbar->linewrap_all_btn)
2212                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2213         if (compose->toolbar->addrbook_btn)
2214                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2215 #ifdef USE_ASPELL
2216         if (compose->toolbar->spellcheck_btn)
2217                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2218 #endif
2219         for (; items != NULL; items = g_slist_next(items)) {
2220                 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
2221                 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2222         }
2223 }
2224
2225 /**
2226  * Initialize toolbar structure
2227  **/
2228 void toolbar_init(Toolbar * toolbar) {
2229
2230         toolbar->toolbar                = NULL;
2231         toolbar->folders_btn            = NULL;
2232         toolbar->get_btn                = NULL;
2233         toolbar->getall_btn             = NULL;
2234         toolbar->getall_combo           = NULL;
2235         toolbar->send_btn               = NULL;
2236         toolbar->compose_mail_btn       = NULL;
2237         toolbar->compose_news_btn       = NULL;
2238         toolbar->compose_combo          = NULL;
2239         toolbar->reply_btn              = NULL;
2240         toolbar->replysender_btn        = NULL;
2241         toolbar->replyall_btn           = NULL;
2242         toolbar->replylist_btn          = NULL;
2243         toolbar->fwd_btn                = NULL;
2244         toolbar->trash_btn              = NULL;
2245         toolbar->delete_btn             = NULL;
2246         toolbar->prev_btn               = NULL;
2247         toolbar->next_btn               = NULL;
2248         toolbar->exec_btn               = NULL;
2249         toolbar->open_mail_btn          = NULL;
2250         toolbar->close_window_btn       = NULL;
2251         /* compose buttons */ 
2252         toolbar->sendl_btn              = NULL;
2253         toolbar->draft_btn              = NULL;
2254         toolbar->insert_btn             = NULL;
2255         toolbar->attach_btn             = NULL;
2256         toolbar->sig_btn                = NULL; 
2257         toolbar->exteditor_btn          = NULL; 
2258         toolbar->linewrap_current_btn   = NULL; 
2259         toolbar->linewrap_all_btn       = NULL; 
2260         toolbar->addrbook_btn           = NULL; 
2261 #ifdef USE_ASPELL
2262         toolbar->spellcheck_btn         = NULL;
2263 #endif
2264
2265         toolbar_destroy(toolbar);
2266 }
2267
2268 /*
2269  */
2270 static void toolbar_reply(gpointer data, guint action)
2271 {
2272         ToolbarItem *toolbar_item = (ToolbarItem*)data;
2273         MainWindow *mainwin;
2274         MessageView *msgview;
2275         GSList *msginfo_list = NULL;
2276
2277         g_return_if_fail(toolbar_item != NULL);
2278
2279         switch (toolbar_item->type) {
2280         case TOOLBAR_MAIN:
2281                 mainwin = (MainWindow*)toolbar_item->parent;
2282                 msginfo_list = summary_get_selection(mainwin->summaryview);
2283                 msgview = (MessageView*)mainwin->messageview;
2284                 break;
2285         case TOOLBAR_MSGVIEW:
2286                 msgview = (MessageView*)toolbar_item->parent;
2287                 g_return_if_fail(msgview != NULL);      
2288                 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2289                 break;
2290         default:
2291                 return;
2292         }
2293
2294         g_return_if_fail(msgview != NULL);
2295         g_return_if_fail(msginfo_list != NULL);
2296         compose_reply_from_messageview(msgview, msginfo_list, action);
2297         g_slist_free(msginfo_list);
2298
2299         /* TODO: update reply state ion summaryview */
2300 }
2301
2302
2303 /* exported functions */
2304
2305 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2306 {
2307         MainWindow *mainwin = (MainWindow*)data;
2308
2309         inc_mail(mainwin, prefs_common.newmail_notify_manu);
2310 }
2311
2312 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2313 {
2314         MainWindow *mainwin = (MainWindow*)data;
2315
2316         inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2317 }
2318
2319 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2320 {
2321         GList *list;
2322         gboolean found;
2323         gboolean got_error = FALSE;
2324         gchar *errstr = NULL;
2325
2326         if (prefs_common.work_offline)
2327                 if (alertpanel(_("Offline warning"), 
2328                                _("You're working offline. Override?"),
2329                                GTK_STOCK_NO, GTK_STOCK_YES,
2330                                NULL) != G_ALERTALTERNATE)
2331                 return;
2332
2333         /* ask for confirmation before sending queued messages only
2334            in online mode and if there is at least one message queued
2335            in any of the folder queue
2336         */
2337         if (prefs_common.confirm_send_queued_messages) {
2338                 found = FALSE;
2339                 /* check if there's a queued message */
2340                 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2341                         Folder *folder = list->data;
2342
2343                         found = !procmsg_queue_is_empty(folder->queue);
2344                 }
2345                 /* if necessary, ask for confirmation before sending */
2346                 if (found && !prefs_common.work_offline) {
2347                         if (alertpanel(_("Send queued messages"), 
2348                                    _("Send all queued messages?"),
2349                                    GTK_STOCK_CANCEL, _("_Send"),
2350                                    NULL) != G_ALERTALTERNATE)
2351                                 return;
2352                 }
2353         }
2354
2355         for (list = folder_get_list(); list != NULL; list = list->next) {
2356                 Folder *folder = list->data;
2357
2358                 if (folder->queue) {
2359                         if (procmsg_send_queue(folder->queue, 
2360                                                prefs_common.savemsg,
2361                                                &errstr) < 0)
2362                                 got_error = TRUE;
2363                 }
2364         }
2365         if (got_error) {
2366                 if (!errstr)
2367                         alertpanel_error_log(_("Some errors occurred while "
2368                                            "sending queued messages."));
2369                 else {
2370                         gchar *tmp = g_strdup_printf(_("Some errors occurred "
2371                                         "while sending queued messages:\n%s"), errstr);
2372                         g_free(errstr);
2373                         alertpanel_error_log(tmp);
2374                         g_free(tmp);
2375                 }
2376         }
2377 }
2378
2379 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2380 {
2381         MainWindow *mainwin = (MainWindow*)data;
2382         PrefsAccount *ac = NULL;
2383         FolderItem *item = mainwin->summaryview->folder_item;   
2384         GList * list;
2385         GList * cur;
2386         
2387         if (item) {
2388                 ac = account_find_from_item(item);
2389                 if (ac && ac->protocol != A_NNTP) {
2390                         compose_new_with_folderitem(ac, item, NULL);            /* CLAWS */
2391                         return;
2392                 }
2393         }
2394
2395         /*
2396          * CLAWS - use current account
2397          */
2398         if (cur_account && (cur_account->protocol != A_NNTP)) {
2399                 compose_new_with_folderitem(cur_account, item, NULL);
2400                 return;
2401         }
2402
2403         /*
2404          * CLAWS - just get the first one
2405          */
2406         list = account_get_list();
2407         for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2408                 ac = (PrefsAccount *) cur->data;
2409                 if (ac->protocol != A_NNTP) {
2410                         compose_new_with_folderitem(ac, item, NULL);
2411                         return;
2412                 }
2413         }
2414 }
2415
2416 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2417 {
2418         MainWindow *mainwin = (MainWindow*)data;
2419         PrefsAccount * ac = NULL;
2420         GList * list;
2421         GList * cur;
2422
2423         if (mainwin->summaryview->folder_item) {
2424                 ac = mainwin->summaryview->folder_item->folder->account;
2425                 if (ac && ac->protocol == A_NNTP) {
2426                         compose_new_with_folderitem(ac,
2427                                     mainwin->summaryview->folder_item, NULL);
2428                         return;
2429                 }
2430         }
2431
2432         list = account_get_list();
2433         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2434                 ac = (PrefsAccount *) cur->data;
2435                 if (ac->protocol == A_NNTP) {
2436                         compose_new_with_folderitem(ac,
2437                                     mainwin->summaryview->folder_item, NULL);
2438                         return;
2439                 }
2440         }
2441 }