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