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