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