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