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