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