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