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