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