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