Silent up coverity scan.
[claws.git] / src / toolbar.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2001-2013 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 /*
21  * General functions for accessing address book files.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #include "claws-features.h"
27 #endif
28
29 #include "defs.h"
30
31 #include <glib.h>
32 #include <glib/gi18n.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <dirent.h>
36 #include <sys/stat.h>
37 #include <math.h>
38 #include <setjmp.h>
39
40 #include "main.h"
41 #include "mainwindow.h"
42 #include "summaryview.h"
43 #include "compose.h"
44 #include "utils.h"
45 #include "xml.h"
46 #include "mgutils.h"
47 #include "prefs_gtk.h"
48 #include "codeconv.h"
49 #include "stock_pixmap.h"
50 #include "manage_window.h"
51 #include "gtkutils.h"
52 #include "toolbar.h"
53 #include "menu.h"
54 #include "inc.h"
55 #include "action.h"
56 #include "prefs_actions.h"
57 #include "prefs_common.h"
58 #include "prefs_toolbar.h"
59 #include "alertpanel.h"
60 #include "imap.h"
61 #include "account.h"
62 #include "send_message.h"
63 #ifndef USE_ALT_ADDRBOOK
64         #include "addressbook.h"
65 #else
66         #include "addressbook-dbus.h"
67 #endif
68
69 /* elements */
70 #define TOOLBAR_TAG_INDEX        "toolbar"
71 #define TOOLBAR_TAG_ITEM         "item"
72 #define TOOLBAR_TAG_SEPARATOR    "separator"
73
74 #define TOOLBAR_ICON_FILE   "file"    
75 #define TOOLBAR_ICON_TEXT   "text"     
76 #define TOOLBAR_ICON_ACTION "action"    
77
78 static void toolbar_init(Toolbar * toolbar);
79 static gboolean      toolbar_is_duplicate               (gint           action,
80                                                  ToolbarType    source);
81 static void   toolbar_parse_item                (XMLFile        *file,
82                                                  ToolbarType    source, gboolean *rewrite);
83
84 static gint   toolbar_ret_val_from_text         (const gchar    *text);
85 static gchar *toolbar_ret_text_from_val         (gint           val);
86
87 static void   toolbar_set_default_main          (void);
88 static void   toolbar_set_default_compose       (void);
89 static void   toolbar_set_default_msgview       (void);
90
91 static void     toolbar_style                   (ToolbarType     type, 
92                                                  guint           action, 
93                                                  gpointer        data);
94
95 static MainWindow *get_mainwin                  (gpointer data);
96 static void activate_compose_button             (Toolbar        *toolbar,
97                                                  ToolbarStyle    style,
98                                                  ComposeButtonType type);
99
100 /* toolbar callbacks */
101 static void toolbar_reply                       (gpointer        data, 
102                                                  guint           action);
103 static void toolbar_learn                       (gpointer        data, 
104                                                  guint           action);
105 static void toolbar_delete_cb                   (GtkWidget      *widget,
106                                                  gpointer        data);
107 static void toolbar_trash_cb                    (GtkWidget      *widget,
108                                                  gpointer        data);
109
110 static void toolbar_compose_cb                  (GtkWidget      *widget,
111                                                  gpointer        data);
112
113 static void toolbar_learn_cb                    (GtkWidget      *widget,
114                                                  gpointer        data);
115
116 static void toolbar_reply_cb                    (GtkWidget      *widget,
117                                                  gpointer        data);
118
119 static void toolbar_reply_to_all_cb             (GtkWidget      *widget,
120                                                  gpointer        data);
121
122 static void toolbar_reply_to_list_cb            (GtkWidget      *widget,
123                                                  gpointer        data);
124
125 static void toolbar_reply_to_sender_cb          (GtkWidget      *widget,
126                                                  gpointer        data);
127
128 static void toolbar_forward_cb                  (GtkWidget      *widget,
129                                                  gpointer        data);
130
131 static void toolbar_prev_unread_cb              (GtkWidget      *widget,
132                                                  gpointer        data);
133 static void toolbar_next_unread_cb              (GtkWidget      *widget,
134                                                  gpointer        data);
135
136 static void toolbar_ignore_thread_cb            (GtkWidget      *widget,
137                                                  gpointer        data);
138
139 static void toolbar_watch_thread_cb             (GtkWidget      *widget,
140                                                  gpointer        data);
141
142 static void toolbar_mark_cb             (GtkWidget      *widget,
143                                                  gpointer        data);
144
145 static void toolbar_unmark_cb           (GtkWidget      *widget,
146                                                  gpointer        data);
147
148 static void toolbar_lock_cb             (GtkWidget      *widget,
149                                                  gpointer        data);
150
151 static void toolbar_ulock_cb            (GtkWidget      *widget,
152                                                  gpointer        data);
153
154 static void toolbar_all_read_cb         (GtkWidget      *widget,
155                                                  gpointer        data);
156
157 static void toolbar_all_unread_cb               (GtkWidget      *widget,
158                                                  gpointer        data);
159
160 static void toolbar_read_cb             (GtkWidget      *widget,
161                                                  gpointer        data);
162
163 static void toolbar_unread_cb           (GtkWidget      *widget,
164                                                  gpointer        data);
165
166 static void toolbar_print_cb                    (GtkWidget      *widget,
167                                                  gpointer        data);
168
169 static void toolbar_actions_execute_cb          (GtkWidget      *widget,
170                                                  gpointer        data);
171 static void toolbar_plugins_execute_cb      (GtkWidget      *widget,
172                              gpointer        data);
173
174
175 static void toolbar_send_cb                     (GtkWidget      *widget,
176                                                  gpointer        data);
177 static void toolbar_send_later_cb               (GtkWidget      *widget,
178                                                  gpointer        data);
179 static void toolbar_draft_cb                    (GtkWidget      *widget,
180                                                  gpointer        data);
181 static void toolbar_close_cb                    (GtkWidget      *widget,
182                                                  gpointer        data);
183 static void toolbar_preferences_cb              (GtkWidget      *widget,
184                                                  gpointer        data);
185 static void toolbar_open_mail_cb                (GtkWidget      *widget,
186                                                  gpointer        data);
187 static void toolbar_insert_cb                   (GtkWidget      *widget,
188                                                  gpointer        data);
189 static void toolbar_attach_cb                   (GtkWidget      *widget,
190                                                  gpointer        data);
191 static void toolbar_sig_cb                      (GtkWidget      *widget,
192                                                  gpointer        data);
193 static void toolbar_ext_editor_cb               (GtkWidget      *widget,
194                                                  gpointer        data);
195 static void toolbar_linewrap_current_cb         (GtkWidget      *widget,
196                                                  gpointer        data);
197 static void toolbar_linewrap_all_cb             (GtkWidget      *widget,
198                                                  gpointer        data);
199 static void toolbar_addrbook_cb                 (GtkWidget      *widget, 
200                                                  gpointer        data);
201 #ifdef USE_ENCHANT
202 static void toolbar_check_spelling_cb           (GtkWidget      *widget, 
203                                                  gpointer        data);
204 #endif
205 static void toolbar_cancel_inc_cb               (GtkWidget      *widget,
206                                                  gpointer        data);
207 static void toolbar_cancel_send_cb              (GtkWidget      *widget,
208                                                  gpointer        data);
209 static void toolbar_cancel_all_cb               (GtkWidget      *widget,
210                                                  gpointer        data);
211
212 struct {
213         gchar *index_str;
214         const gchar *descr;
215 } toolbar_text [] = {
216         { "A_RECEIVE_ALL",      N_("Receive Mail from all Accounts")       },
217         { "A_RECEIVE_CUR",      N_("Receive Mail from current Account")    },
218         { "A_SEND_QUEUED",      N_("Send Queued Messages")                 },
219         { "A_COMPOSE_EMAIL",    N_("Compose Email")                        },
220         { "A_COMPOSE_NEWS",     N_("Compose News")                         },
221         { "A_REPLY_MESSAGE",    N_("Reply to Message")                     },
222         { "A_REPLY_SENDER",     N_("Reply to Sender")                      },
223         { "A_REPLY_ALL",        N_("Reply to All")                         },
224         { "A_REPLY_ML",         N_("Reply to Mailing-list")                },
225         { "A_OPEN_MAIL",        N_("Open email")                           },
226         { "A_FORWARD",          N_("Forward Message")                      }, 
227         { "A_TRASH",            N_("Trash Message")                        },
228         { "A_DELETE_REAL",      N_("Delete Message")                       },
229         { "A_EXECUTE",          N_("Execute")                              },
230         { "A_GOTO_PREV",        N_("Go to Previous Unread Message")        },
231         { "A_GOTO_NEXT",        N_("Go to Next Unread Message")            },
232
233         { "A_IGNORE_THREAD",    N_("Ignore thread")                        },
234         { "A_WATCH_THREAD",     N_("Watch thread")                         },
235         { "A_MARK",                     N_("Mark Message")                         },
236         { "A_UNMARK",                   N_("Unmark Message")                       },
237         { "A_LOCK",                     N_("Lock Message")                         },
238         { "A_UNLOCK",                   N_("Unlock Message")                       },
239         { "A_ALL_READ",                 N_("Mark all Messages as read")            },
240         { "A_ALL_UNREAD",               N_("Mark all Messages as unread")          },
241         { "A_READ",                     N_("Mark Message as read")                 },
242         { "A_UNREAD",                   N_("Mark Message as unread")               },
243
244         { "A_PRINT",            N_("Print")                                },
245         { "A_LEARN_SPAM",       N_("Learn Spam or Ham")                    },
246         { "A_GO_FOLDERS",       N_("Open folder/Go to folder list")        },
247         { "A_PREFERENCES",      N_("Preferences")                          },
248
249         { "A_SEND",             N_("Send Message")                         },
250         { "A_SEND_LATER",       N_("Put into queue folder and send later") },
251         { "A_DRAFT",            N_("Save to draft folder")                 },
252         { "A_INSERT",           N_("Insert file")                          },   
253         { "A_ATTACH",           N_("Attach file")                          },
254         { "A_SIG",              N_("Insert signature")                     },
255         { "A_REP_SIG",          N_("Replace signature")                    },
256         { "A_EXTEDITOR",        N_("Edit with external editor")            },
257         { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") }, 
258         { "A_LINEWRAP_ALL",     N_("Wrap all long lines")                  }, 
259         { "A_ADDRBOOK",         N_("Address book")                         },
260 #ifdef USE_ENCHANT
261         { "A_CHECK_SPELLING",   N_("Check spelling")                       },
262 #endif
263         { "A_CLAWS_ACTIONS",    N_("Claws Mail Actions Feature")           }, 
264         { "A_CANCEL_INC",       N_("Cancel receiving")                     },
265         { "A_CANCEL_SEND",      N_("Cancel sending")                       },
266         { "A_CANCEL_ALL",       N_("Cancel receiving/sending")             },
267         { "A_CLOSE",            N_("Close window")                         },
268         { "A_SEPARATOR",        N_("Separator")                            },
269         { "A_CLAWS_PLUGINS",    N_("Claws Mail Plugins")                   }
270 };
271
272 /* migration table: support reading toolbar configuration files with
273    old action names and converting them to current action names,
274    see toolbar_parse_item(), which makes uses of this alias table.
275 */
276 struct {
277         const gchar *old_name;
278         const gchar *current_name;
279 } toolbar_migration [] = {
280         { "A_SYL_ACTIONS",   "A_CLAWS_ACTIONS" },
281         { "A_SENDL",         "A_SEND_LATER" },
282         { NULL,              NULL }
283 };
284         
285 /* struct holds configuration files and a list of
286  * currently active toolbar items 
287  * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
288  * give us an index
289  */
290 struct {
291         const gchar  *conf_file;
292         GSList       *item_list;
293 } toolbar_config[NUM_TOOLBARS] = {
294         { "toolbar_main.xml",    NULL},
295         { "toolbar_compose.xml", NULL}, 
296         { "toolbar_msgview.xml", NULL}
297 };
298
299 gint toolbar_ret_val_from_descr(const gchar *descr)
300 {
301         gint i;
302
303         for (i = 0; i < N_ACTION_VAL; i++) {
304                 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
305                                 return i;
306         }
307         
308         return -1;
309 }
310
311 gchar *toolbar_ret_descr_from_val(gint val)
312 {
313         cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
314
315         return gettext(toolbar_text[val].descr);
316 }
317
318 static gint toolbar_ret_val_from_text(const gchar *text)
319 {
320         gint i;
321         
322         for (i = 0; i < N_ACTION_VAL; i++) {
323                 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
324                                 return i;
325         }
326
327         return -1;
328 }
329
330 static gchar *toolbar_ret_text_from_val(gint val)
331 {
332         cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
333
334         return toolbar_text[val].index_str;
335 }
336
337 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
338 {
339         GSList *cur;
340
341         if ((action == A_SEPARATOR) || (action == A_CLAWS_ACTIONS) || (action == A_CLAWS_PLUGINS))
342                 return FALSE;
343
344         for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
345                 ToolbarItem *item = (ToolbarItem*) cur->data;
346                 
347                 if (item->index == action)
348                         return TRUE;
349         }
350         return FALSE;
351 }
352
353 /* depending on toolbar type this function 
354    returns a list of available toolbar events being 
355    displayed by prefs_toolbar
356 */
357 GList *toolbar_get_action_items(ToolbarType source)
358 {
359         GList *items = NULL;
360         gint i = 0;
361         
362         if (source == TOOLBAR_MAIN) {
363                 gint main_items[] = {
364                                         A_RECEIVE_ALL,   A_RECEIVE_CUR,   A_SEND_QUEUED,
365                                         A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
366                                         A_REPLY_ALL,     A_REPLY_ML,      A_OPEN_MAIL,     A_FORWARD,
367                                         A_TRASH,         A_DELETE_REAL,   A_EXECUTE,       A_GOTO_PREV,
368                                         A_GOTO_NEXT,     A_IGNORE_THREAD, A_WATCH_THREAD,  A_MARK,
369                                         A_UNMARK,        A_LOCK,          A_UNLOCK,        A_ALL_READ,
370                                         A_ALL_UNREAD,    A_READ,          A_UNREAD,          A_PRINT,
371                                         A_ADDRBOOK,      A_LEARN_SPAM,    A_GO_FOLDERS, 
372                                         A_CANCEL_INC,    A_CANCEL_SEND,   A_CANCEL_ALL,    A_PREFERENCES };
373
374                 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++)  {
375                         items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
376                 }       
377         }
378         else if (source == TOOLBAR_COMPOSE) {
379                 gint comp_items[] =   {
380                                         A_SEND,          A_SEND_LATER,   A_DRAFT,
381                                         A_INSERT,        A_ATTACH,       A_SIG,
382                                         A_REP_SIG,       A_EXTEDITOR,    A_LINEWRAP_CURRENT,
383                                         A_LINEWRAP_ALL,  A_ADDRBOOK,
384 #ifdef USE_ENCHANT
385                                         A_CHECK_SPELLING,
386 #endif
387                                         A_CLOSE };
388
389                 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++) 
390                         items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
391         }
392         else if (source == TOOLBAR_MSGVIEW) {
393                 gint msgv_items[] =   {
394                                         A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
395                                         A_REPLY_ALL,     A_REPLY_ML,      A_FORWARD,
396                                         A_TRASH,         A_DELETE_REAL,   A_GOTO_PREV,      A_GOTO_NEXT,
397                                         A_ADDRBOOK,      A_LEARN_SPAM,    A_CLOSE };
398
399                 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++) 
400                         items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
401         }
402
403         return items;
404 }
405
406 static void toolbar_parse_item(XMLFile *file, ToolbarType source, gboolean *rewrite)
407 {
408         GList *attr;
409         gchar *name, *value;
410         ToolbarItem *item = NULL;
411
412         g_return_if_fail(rewrite != NULL);
413
414         attr = xml_get_current_tag_attr(file);
415         item = g_new0(ToolbarItem, 1);
416         while( attr ) {
417                 name = ((XMLAttr *)attr->data)->name;
418                 value = ((XMLAttr *)attr->data)->value;
419                 
420                 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0) 
421                         item->file = g_strdup (value);
422                 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
423                         item->text = g_strdup (*value ? gettext(value):"");
424                 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
425                         item->index = toolbar_ret_val_from_text(value);
426
427                 if ((item->index == -1) && !strcmp(value, "A_DELETE")) {
428                         /* switch button */
429                         item->index = A_TRASH;
430                         g_free(item->file);
431                         item->file = g_strdup("trash_btn");
432                         g_free(item->text);
433                         item->text = g_strdup(C_("Toolbar", "Trash"));
434                         *rewrite = TRUE;
435                 }
436                 if (item->index == -1) {
437                         /* item not found in table: try migrating old action names to current ones */
438                         gint i;
439
440                         /* replace action name */
441                         for (i = 0; toolbar_migration[i].old_name != NULL; i++) {
442                                 if (g_utf8_collate(value, toolbar_migration[i].old_name) == 0) {
443                                         item->index = toolbar_ret_val_from_text(toolbar_migration[i].current_name);
444                                         if (item->index != -1) {
445                                                 *rewrite = TRUE;
446                                                 debug_print("toolbar_parse_item: migrating action label from '%s' to '%s'\n",
447                                                         value, toolbar_migration[i].current_name);
448                                                 break;
449                                         }
450                                 }
451                         }
452                 }
453                 if ((item->index == -1) && !rewrite)
454                         g_warning("toolbar_parse_item: unrecognized action name '%s'\n", value);
455
456                 attr = g_list_next(attr);
457         }
458         if (item->index != -1) {
459                 if (!toolbar_is_duplicate(item->index, source)) 
460                         toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
461                                                                          item);
462         }
463 }
464
465 const gchar *toolbar_get_short_text(int action) {
466         switch(action) {
467         case A_RECEIVE_ALL:     return _("Get Mail");
468         case A_RECEIVE_CUR:     return _("Get");
469         case A_SEND_QUEUED:     return _("Send");
470         case A_COMPOSE_EMAIL:   return C_("Toolbar", "Compose");
471         case A_COMPOSE_NEWS:    return C_("Toolbar", "Compose");
472         case A_REPLY_MESSAGE:   return _("Reply");
473         case A_REPLY_SENDER:    return C_("Toolbar", "Sender");
474         case A_REPLY_ALL:       return _("All");
475         case A_REPLY_ML:        return _("List");
476         case A_OPEN_MAIL:       return _("Open");
477         case A_FORWARD:         return _("Forward");
478         case A_TRASH:           return C_("Toolbar", "Trash");
479         case A_DELETE_REAL:     return _("Delete");
480         case A_EXECUTE:         return _("Execute");
481         case A_GOTO_PREV:       return _("Prev");
482         case A_GOTO_NEXT:       return _("Next");
483
484         case A_IGNORE_THREAD:   return _("Ignore thread");
485         case A_WATCH_THREAD:    return _("Watch thread");
486         case A_MARK:            return _("Mark");
487         case A_UNMARK:          return _("Unmark");
488         case A_LOCK:            return _("Lock");
489         case A_UNLOCK:          return _("Unlock");
490         case A_ALL_READ:        return _("All read");
491         case A_ALL_UNREAD:      return _("All unread");
492         case A_READ:            return _("Read");
493         case A_UNREAD:          return _("Unread");
494
495         case A_PRINT:           return _("Print");
496         case A_LEARN_SPAM:      return _("Spam");
497         case A_GO_FOLDERS:      return _("Folders");
498         case A_PREFERENCES:     return _("Preferences");
499
500         case A_SEND:            return _("Send");
501         case A_SEND_LATER:      return _("Send later");
502         case A_DRAFT:           return _("Draft");
503         case A_INSERT:          return _("Insert");
504         case A_ATTACH:          return _("Attach");
505         case A_SIG:             return _("Insert sig.");
506         case A_REP_SIG:         return _("Replace sig.");
507         case A_EXTEDITOR:       return _("Edit");
508         case A_LINEWRAP_CURRENT:return _("Wrap para.");
509         case A_LINEWRAP_ALL:    return _("Wrap all");
510         case A_ADDRBOOK:        return _("Address");
511         #ifdef USE_ENCHANT
512         case A_CHECK_SPELLING:  return _("Check spelling");
513         #endif
514
515         case A_CANCEL_INC:      return _("Stop");
516         case A_CANCEL_SEND:     return _("Stop");
517         case A_CANCEL_ALL:      return _("Stop all");
518         case A_CLOSE:           return _("Close");
519         default:                return "";
520         }
521 }
522
523 gint toolbar_get_icon(int action) {
524         switch(action) {
525         case A_RECEIVE_ALL:     return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
526         case A_RECEIVE_CUR:     return STOCK_PIXMAP_MAIL_RECEIVE;
527         case A_SEND_QUEUED:     return STOCK_PIXMAP_MAIL_SEND_QUEUE;
528         case A_COMPOSE_EMAIL:   return STOCK_PIXMAP_MAIL_COMPOSE;
529         case A_COMPOSE_NEWS:    return STOCK_PIXMAP_NEWS_COMPOSE;
530         case A_REPLY_MESSAGE:   return STOCK_PIXMAP_MAIL_REPLY;
531         case A_REPLY_SENDER:    return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
532         case A_REPLY_ALL:       return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
533         case A_REPLY_ML:        return STOCK_PIXMAP_MAIL_REPLY_TO_LIST;
534         case A_OPEN_MAIL:       return STOCK_PIXMAP_OPEN_MAIL;
535         case A_FORWARD:         return STOCK_PIXMAP_MAIL_FORWARD;
536         case A_TRASH:           return STOCK_PIXMAP_TRASH;
537         case A_DELETE_REAL:     return STOCK_PIXMAP_DELETE;
538         case A_EXECUTE:         return STOCK_PIXMAP_EXEC;
539         case A_GOTO_PREV:       return STOCK_PIXMAP_UP_ARROW;
540         case A_GOTO_NEXT:       return STOCK_PIXMAP_DOWN_ARROW;
541
542         case A_IGNORE_THREAD:   return STOCK_PIXMAP_MARK_IGNORETHREAD;
543         case A_WATCH_THREAD:    return STOCK_PIXMAP_MARK_WATCHTHREAD;
544         case A_MARK:            return STOCK_PIXMAP_MARK_MARK;
545         case A_UNMARK:          return STOCK_PIXMAP_MARK_UNMARK;
546         case A_LOCK:            return STOCK_PIXMAP_MARK_LOCKED;
547         case A_UNLOCK:          return STOCK_PIXMAP_MARK_UNLOCKED;
548         case A_ALL_READ:        return STOCK_PIXMAP_MARK_ALLREAD;
549         case A_ALL_UNREAD:      return STOCK_PIXMAP_MARK_ALLUNREAD;
550         case A_READ:            return STOCK_PIXMAP_MARK_READ;
551         case A_UNREAD:          return STOCK_PIXMAP_MARK_UNREAD;
552
553         case A_PRINT:           return STOCK_PIXMAP_PRINTER;
554         case A_LEARN_SPAM:      return STOCK_PIXMAP_SPAM_BTN;
555         case A_GO_FOLDERS:      return STOCK_PIXMAP_GO_FOLDERS;
556         case A_PREFERENCES:     return STOCK_PIXMAP_PREFERENCES;
557
558         case A_SEND:            return STOCK_PIXMAP_MAIL_SEND;
559         case A_SEND_LATER:      return STOCK_PIXMAP_MAIL_SEND_QUEUE;
560         case A_DRAFT:           return STOCK_PIXMAP_MAIL;
561         case A_INSERT:          return STOCK_PIXMAP_INSERT_FILE;
562         case A_ATTACH:          return STOCK_PIXMAP_MAIL_ATTACH;
563         case A_SIG:             return STOCK_PIXMAP_MAIL_SIGN;
564         case A_REP_SIG:         return STOCK_PIXMAP_MAIL_SIGN;
565         case A_EXTEDITOR:       return STOCK_PIXMAP_EDIT_EXTERN;
566         case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
567         case A_LINEWRAP_ALL:    return STOCK_PIXMAP_LINEWRAP_ALL;
568         case A_ADDRBOOK:        return STOCK_PIXMAP_ADDRESS_BOOK;
569         #ifdef USE_ENCHANT
570         case A_CHECK_SPELLING:  return STOCK_PIXMAP_CHECK_SPELLING;
571         #endif
572
573         case A_CANCEL_INC:      return STOCK_PIXMAP_CANCEL;
574         case A_CANCEL_SEND:     return STOCK_PIXMAP_CANCEL;
575         case A_CANCEL_ALL:      return STOCK_PIXMAP_CANCEL;
576         case A_CLOSE:           return STOCK_PIXMAP_CLOSE;
577         default:                return -1;
578         }
579 }
580
581 static void toolbar_set_default_main(void) 
582 {
583         struct {
584                 gint action;
585         } default_toolbar[] = {
586 #ifdef GENERIC_UMPC
587                 { A_GO_FOLDERS},
588                 { A_OPEN_MAIL},         
589                 { A_SEPARATOR}, 
590 #endif
591                 { A_RECEIVE_ALL},
592                 { A_SEPARATOR}, 
593                 { A_SEND_QUEUED},
594                 { A_COMPOSE_EMAIL},
595                 { A_SEPARATOR},
596                 { A_REPLY_MESSAGE}, 
597 #ifndef GENERIC_UMPC
598                 { A_REPLY_ALL},
599                 { A_REPLY_SENDER},
600 #endif
601                 { A_FORWARD},
602                 { A_SEPARATOR},
603                 { A_TRASH},
604 #ifndef GENERIC_UMPC
605                 { A_LEARN_SPAM},
606 #endif
607                 { A_SEPARATOR},
608                 { A_GOTO_NEXT}
609         };
610         
611         gint i;
612         
613         for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
614                 
615                 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
616                 
617                 if (default_toolbar[i].action != A_SEPARATOR) {
618                         
619                         gchar *file = NULL;
620                         if (toolbar_get_icon(default_toolbar[i].action) > -1) {
621                                 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
622                         }
623                         
624                         toolbar_item->file  = g_strdup(file);
625                         toolbar_item->index = default_toolbar[i].action;
626                         toolbar_item->text  = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
627                 } else {
628
629                         toolbar_item->file  = g_strdup(TOOLBAR_TAG_SEPARATOR);
630                         toolbar_item->index = A_SEPARATOR;
631                 }
632                 
633                 if (toolbar_item->index != -1) {
634                         if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN)) 
635                                 toolbar_config[TOOLBAR_MAIN].item_list = 
636                                         g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
637                 }       
638         }
639 }
640
641 static void toolbar_set_default_compose(void)
642 {
643         struct {
644                 gint action;
645         } default_toolbar[] = {
646 #ifdef GENERIC_UMPC
647                 { A_CLOSE},
648                 { A_SEPARATOR}, 
649 #endif
650                 { A_SEND},
651                 { A_SEND_LATER},
652                 { A_DRAFT},
653                 { A_SEPARATOR}, 
654 #ifndef GENERIC_UMPC
655                 { A_INSERT},
656 #endif
657                 { A_ATTACH},
658                 { A_SEPARATOR},
659                 { A_ADDRBOOK}
660         };
661         
662         gint i;
663
664         for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
665                 
666                 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
667                 
668                 if (default_toolbar[i].action != A_SEPARATOR) {
669                         
670                         gchar *file = NULL;
671                         if (toolbar_get_icon(default_toolbar[i].action) > -1) {
672                                 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
673                         }
674                         toolbar_item->file  = g_strdup(file);
675                         toolbar_item->index = default_toolbar[i].action;
676                         toolbar_item->text  = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
677                 } else {
678
679                         toolbar_item->file  = g_strdup(TOOLBAR_TAG_SEPARATOR);
680                         toolbar_item->index = A_SEPARATOR;
681                 }
682                 
683                 if (toolbar_item->index != -1) {
684                         if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE)) 
685                                 toolbar_config[TOOLBAR_COMPOSE].item_list = 
686                                         g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
687                 }       
688         }
689 }
690
691 static void toolbar_set_default_msgview(void)
692 {
693         struct {
694                 gint action;
695         } default_toolbar[] = {
696 #ifdef GENERIC_UMPC
697                 { A_CLOSE},
698                 { A_SEPARATOR}, 
699 #endif
700                 { A_REPLY_MESSAGE}, 
701                 { A_REPLY_ALL},
702                 { A_REPLY_SENDER},
703                 { A_FORWARD},
704                 { A_SEPARATOR},
705                 { A_TRASH},
706 #ifndef GENERIC_UMPC
707                 { A_LEARN_SPAM},
708 #endif
709                 { A_GOTO_NEXT}
710         };
711         
712         gint i;
713
714         for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
715                 
716                 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
717                 
718                 if (default_toolbar[i].action != A_SEPARATOR) {
719                         gchar *file = NULL;
720                         if (toolbar_get_icon(default_toolbar[i].action) > -1) {
721                                 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
722                         }
723                         
724                         toolbar_item->file  = g_strdup(file);
725                         toolbar_item->index = default_toolbar[i].action;
726                         toolbar_item->text  = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
727                 } else {
728
729                         toolbar_item->file  = g_strdup(TOOLBAR_TAG_SEPARATOR);
730                         toolbar_item->index = A_SEPARATOR;
731                 }
732                 
733                 if (toolbar_item->index != -1) {
734                         if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW)) 
735                                 toolbar_config[TOOLBAR_MSGVIEW].item_list = 
736                                         g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
737                 }       
738         }
739 }
740
741 void toolbar_set_default(ToolbarType source)
742 {
743         if (source == TOOLBAR_MAIN)
744                 toolbar_set_default_main();
745         else if  (source == TOOLBAR_COMPOSE)
746                 toolbar_set_default_compose();
747         else if  (source == TOOLBAR_MSGVIEW)
748                 toolbar_set_default_msgview();
749 }
750
751 void toolbar_save_config_file(ToolbarType source)
752 {
753         GSList *cur;
754         FILE *fp;
755         PrefFile *pfile;
756         gchar *fileSpec = NULL;
757
758         debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
759
760         fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
761         pfile = prefs_write_open(fileSpec);
762         if( pfile ) {
763                 fp = pfile->fp;
764                 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
765                         goto fail;
766
767                 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
768                         goto fail;
769
770                 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
771                         ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
772                         
773                         if (toolbar_item->index != A_SEPARATOR) {
774                                 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
775                                         TOOLBAR_TAG_ITEM, 
776                                         TOOLBAR_ICON_FILE, toolbar_item->file,
777                                         TOOLBAR_ICON_TEXT) < 0)
778                                         goto fail;
779                                 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
780                                         goto fail;
781                                 if (fprintf(fp, "\" %s=\"%s\"/>\n",
782                                         TOOLBAR_ICON_ACTION, 
783                                         toolbar_ret_text_from_val(toolbar_item->index)) < 0)
784                                         goto fail;
785                         } else {
786                                 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
787                                         goto fail;
788                         }
789                 }
790
791                 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
792                         goto fail;
793         
794                 g_free( fileSpec );
795                 if (prefs_file_close (pfile) < 0 ) 
796                         g_warning("failed to write toolbar configuration to file");
797                 return;
798                 
799 fail:
800                 FILE_OP_ERROR(fileSpec, "fprintf");
801                 g_free( fileSpec );
802                 prefs_file_close_revert (pfile);
803         } else
804                 g_warning("failed to open toolbar configuration file for writing");
805 }
806
807 void toolbar_read_config_file(ToolbarType source)
808 {
809         XMLFile *file   = NULL;
810         gchar *fileSpec = NULL;
811         jmp_buf    jumper;
812         gboolean rewrite = FALSE;
813
814         debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
815
816         fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
817         file = xml_open_file(fileSpec);
818         g_free(fileSpec);
819
820         toolbar_clear_list(source);
821
822         if (file) {
823                 if ((setjmp(jumper))
824                 || (xml_get_dtd(file))
825                 || (xml_parse_next_tag(file))
826                 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
827                         xml_close_file(file);
828                         return;
829                 }
830
831                 for (;;) {
832                         if (!file->level) 
833                                 break;
834                         /* Get item tag */
835                         if (xml_parse_next_tag(file)) 
836                                 longjmp(jumper, 1);
837
838                         /* Get next tag (icon, icon_text or icon_action) */
839                         if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
840                                 toolbar_parse_item(file, source, &rewrite);
841                         } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
842                                 ToolbarItem *item = g_new0(ToolbarItem, 1);
843                         
844                                 item->file   = g_strdup(TOOLBAR_TAG_SEPARATOR);
845                                 item->index  = A_SEPARATOR;
846                                 toolbar_config[source].item_list = 
847                                         g_slist_append(toolbar_config[source].item_list, item);
848                         }
849
850                 }
851                 xml_close_file(file);
852                 if (rewrite) {
853                         debug_print("toolbar_read_config_file: rewriting toolbar\n");
854                         toolbar_save_config_file(source);
855                 }
856         }
857
858         if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
859
860                 if (source == TOOLBAR_MAIN) 
861                         toolbar_set_default(TOOLBAR_MAIN);
862                 else if (source == TOOLBAR_COMPOSE) 
863                         toolbar_set_default(TOOLBAR_COMPOSE);
864                 else if (source == TOOLBAR_MSGVIEW) 
865                         toolbar_set_default(TOOLBAR_MSGVIEW);
866                 else {          
867                         g_warning("refusing to write unknown Toolbar Configuration number %d", source);
868                         return;
869                 }
870
871                 toolbar_save_config_file(source);
872         }
873 }
874
875 /*
876  * clears list of toolbar items read from configuration files
877  */
878 void toolbar_clear_list(ToolbarType source)
879 {
880         while (toolbar_config[source].item_list != NULL) {
881                 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
882                 
883                 toolbar_config[source].item_list = 
884                         g_slist_remove(toolbar_config[source].item_list, item);
885
886                 g_free(item->file);
887                 g_free(item->text);
888                 g_free(item);   
889         }
890         g_slist_free(toolbar_config[source].item_list);
891 }
892
893
894 /* 
895  * return list of Toolbar items
896  */
897 GSList *toolbar_get_list(ToolbarType source)
898 {
899         GSList *list = NULL;
900
901         if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
902                 list = toolbar_config[source].item_list;
903
904         return list;
905 }
906
907 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
908 {
909         ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
910
911         toolbar_item->file  = g_strdup(t_item->file);
912         toolbar_item->text  = g_strdup(t_item->text);
913         toolbar_item->index = t_item->index;
914         
915         toolbar_config[source].item_list = 
916                 g_slist_append(toolbar_config[source].item_list,
917                                toolbar_item);
918 }
919
920 static void toolbar_action_execute(GtkWidget    *widget,
921                             GSList       *action_list, 
922                             gpointer     data,
923                             gint         source) 
924 {
925         GSList *cur;
926         gint i = 0;
927
928         for (cur = action_list; cur != NULL;  cur = cur->next) {
929                 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
930
931                 if (widget == act->widget) {
932                         i = prefs_actions_find_by_name(act->name);
933
934                         if (i != -1) 
935                                 break;
936                 }
937         }
938
939         if (i != -1) 
940                 actions_execute(data, i, widget, source);
941         else
942                 g_warning ("Error: did not find Claws Action to execute");
943 }
944
945 gboolean toolbar_check_action_btns(ToolbarType type)
946 {
947         GSList *temp, *curr, *list = toolbar_config[type].item_list;
948         gboolean modified = FALSE;
949         
950         curr = list;
951         while (curr != NULL) {
952                 ToolbarItem *toolbar_item = (ToolbarItem *) curr->data;
953                 temp = curr;
954                 curr = curr->next;
955                 
956                 if (toolbar_item->index != A_CLAWS_ACTIONS)
957                         continue;
958
959                 if (prefs_actions_find_by_name(toolbar_item->text) == -1) {
960                         list = g_slist_delete_link(list, temp);
961                         g_free(toolbar_item->file);
962                         g_free(toolbar_item->text);
963                         g_free(toolbar_item);
964                         modified = TRUE;
965                 }
966         }
967         
968         return modified;
969 }
970
971 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
972         gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), tip);                             \
973 }
974
975 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
976         gtk_menu_tool_button_set_arrow_tooltip_text(GTK_MENU_TOOL_BUTTON(widget), tip);                         \
977 }
978
979 static void activate_compose_button (Toolbar           *toolbar,
980                                      ToolbarStyle      style,
981                                      ComposeButtonType type)
982 {
983         if ((!toolbar->compose_mail_btn))
984                 return;
985
986         if (type == COMPOSEBUTTON_NEWS) {
987                 gtk_tool_button_set_icon_widget(
988                         GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
989                         toolbar->compose_news_icon);
990 #ifndef GENERIC_UMPC
991                 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose News message"));
992 #endif  
993                 gtk_widget_show(toolbar->compose_news_icon);
994         } else {
995                 gtk_tool_button_set_icon_widget(
996                         GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
997                         toolbar->compose_mail_icon);
998 #ifndef GENERIC_UMPC
999                 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose Email"));
1000 #endif  
1001                 gtk_widget_show(toolbar->compose_mail_icon);
1002         }
1003         toolbar->compose_btn_type = type;
1004 }
1005
1006 void toolbar_set_compose_button(Toolbar            *toolbar, 
1007                                 ComposeButtonType  compose_btn_type)
1008 {
1009         if (toolbar->compose_btn_type != compose_btn_type)
1010                 activate_compose_button(toolbar, 
1011                                         prefs_common.toolbar_style,
1012                                         compose_btn_type);
1013 }
1014
1015 static void activate_learn_button (Toolbar           *toolbar,
1016                                      ToolbarStyle      style,
1017                                      LearnButtonType type)
1018 {
1019         if ((!toolbar->learn_spam_btn))
1020                 return;
1021
1022         if (type == LEARN_SPAM) {
1023                 gtk_tool_button_set_icon_widget(
1024                         GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
1025                         toolbar->learn_spam_icon);
1026                 gtk_tool_button_set_label(
1027                         GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
1028                         _("Spam"));
1029 #ifndef GENERIC_UMPC
1030                 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn spam"));       
1031 #endif
1032                 gtk_widget_show(toolbar->learn_spam_icon);
1033         } else {
1034                 gtk_tool_button_set_icon_widget(
1035                         GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
1036                         toolbar->learn_ham_icon);
1037                 gtk_tool_button_set_label(
1038                         GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
1039                         _("Ham"));
1040 #ifndef GENERIC_UMPC
1041                 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn ham"));
1042 #endif  
1043                 gtk_widget_show(toolbar->learn_ham_icon);
1044         }
1045         toolbar->learn_btn_type = type; 
1046 }
1047
1048 void toolbar_set_learn_button(Toolbar            *toolbar, 
1049                                 LearnButtonType  learn_btn_type)
1050 {
1051         if (toolbar->learn_btn_type != learn_btn_type)
1052                 activate_learn_button(toolbar, 
1053                                         prefs_common.toolbar_style,
1054                                         learn_btn_type);
1055 }
1056
1057 void toolbar_toggle(guint action, gpointer data)
1058 {
1059         MainWindow *mainwin = (MainWindow*)data;
1060         const GList *list;
1061         const GList *cur;
1062
1063         cm_return_if_fail(mainwin != NULL);
1064
1065         toolbar_style(TOOLBAR_MAIN, action, mainwin);
1066
1067         list = compose_get_compose_list();
1068         for (cur = list; cur != NULL; cur = cur->next) {
1069                 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
1070         }
1071         list = messageview_get_msgview_list();
1072         for (cur = list; cur != NULL; cur = cur->next) {
1073                 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
1074         }
1075         
1076 }
1077
1078 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
1079 {
1080         switch ((ToolbarStyle)action) {
1081         case TOOLBAR_NONE:
1082                 gtk_widget_hide(handlebox_wid);
1083                 break;
1084         case TOOLBAR_ICON:
1085                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1086                                       GTK_TOOLBAR_ICONS);
1087                 break;
1088         case TOOLBAR_TEXT:
1089                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1090                                       GTK_TOOLBAR_TEXT);
1091                 break;
1092         case TOOLBAR_BOTH:
1093                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1094                                       GTK_TOOLBAR_BOTH);
1095                 break;
1096         case TOOLBAR_BOTH_HORIZ:
1097                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1098                                       GTK_TOOLBAR_BOTH_HORIZ);
1099                 break;
1100         default:
1101                 return;
1102         }
1103
1104         prefs_common.toolbar_style = (ToolbarStyle)action;
1105         gtk_widget_set_size_request(handlebox_wid, 1, -1);
1106         
1107         if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1108                 gtk_widget_show(handlebox_wid);
1109                 gtk_widget_queue_resize(handlebox_wid);
1110         }
1111 }
1112 /*
1113  * Change the style of toolbar
1114  */
1115 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1116 {
1117         GtkWidget  *handlebox_wid;
1118         GtkWidget  *toolbar_wid;
1119         MainWindow *mainwin = (MainWindow*)data;
1120         Compose    *compose = (Compose*)data;
1121         MessageView *msgview = (MessageView*)data;
1122         
1123         cm_return_if_fail(data != NULL);
1124         
1125         switch (type) {
1126         case TOOLBAR_MAIN:
1127                 handlebox_wid = mainwin->handlebox;
1128                 toolbar_wid = mainwin->toolbar->toolbar;
1129                 break;
1130         case TOOLBAR_COMPOSE:
1131                 handlebox_wid = compose->handlebox;
1132                 toolbar_wid = compose->toolbar->toolbar;
1133                 break;
1134         case TOOLBAR_MSGVIEW: 
1135                 handlebox_wid = msgview->handlebox;
1136                 toolbar_wid = msgview->toolbar->toolbar;
1137                 break;
1138         default:
1139
1140                 return;
1141         }
1142         toolbar_set_style(toolbar_wid, handlebox_wid, action);
1143 }
1144
1145 /* Toolbar handling */
1146 static void toolbar_inc_cb(GtkWidget    *widget,
1147                            gpointer      data)
1148 {
1149         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1150         MainWindow *mainwin;
1151
1152         cm_return_if_fail(toolbar_item != NULL);
1153
1154         switch (toolbar_item->type) {
1155         case TOOLBAR_MAIN:
1156                 mainwin = (MainWindow*)toolbar_item->parent;    
1157                 inc_mail_cb(mainwin, 0, NULL);
1158                 break;
1159         default:
1160                 break;
1161         }
1162 }
1163
1164 static void toolbar_inc_all_cb(GtkWidget        *widget,
1165                                gpointer          data)
1166 {
1167         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1168         MainWindow *mainwin;
1169
1170         cm_return_if_fail(toolbar_item != NULL);
1171
1172         switch (toolbar_item->type) {
1173         case TOOLBAR_MAIN:
1174                 mainwin = (MainWindow*)toolbar_item->parent;
1175                 inc_all_account_mail_cb(mainwin, 0, NULL);
1176                 break;
1177         default:
1178                 break;
1179         }
1180 }
1181
1182 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1183 {
1184         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1185         MainWindow *mainwin;
1186
1187         cm_return_if_fail(toolbar_item != NULL);
1188
1189         switch (toolbar_item->type) {
1190         case TOOLBAR_MAIN:
1191                 mainwin = (MainWindow*)toolbar_item->parent;
1192                 send_queue_cb(mainwin, 0, NULL);
1193                 break;
1194         default:
1195                 break;
1196         }
1197 }
1198
1199 static void toolbar_exec_cb(GtkWidget   *widget,
1200                             gpointer     data)
1201 {
1202         MainWindow *mainwin = get_mainwin(data);
1203
1204         cm_return_if_fail(mainwin != NULL);
1205         summary_execute(mainwin->summaryview);
1206 }
1207
1208 /*
1209  * Delete current/selected(s) message(s)
1210  */
1211 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1212 {
1213         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1214         MainWindow *mainwin;
1215
1216         cm_return_if_fail(toolbar_item != NULL);
1217         cm_return_if_fail(toolbar_item->parent);
1218         
1219         switch (toolbar_item->type) {
1220         case TOOLBAR_MSGVIEW:
1221                 messageview_delete((MessageView *)toolbar_item->parent);
1222                 break;
1223         case TOOLBAR_MAIN:
1224                 mainwin = (MainWindow *)toolbar_item->parent;
1225                 summary_delete_trash(mainwin->summaryview);
1226                 break;
1227         default: 
1228                 debug_print("toolbar event not supported\n");
1229                 break;
1230         }
1231 }
1232
1233 /*
1234  * Delete current/selected(s) message(s)
1235  */
1236 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1237 {
1238         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1239         MainWindow *mainwin;
1240
1241         cm_return_if_fail(toolbar_item != NULL);
1242         cm_return_if_fail(toolbar_item->parent);
1243         
1244         switch (toolbar_item->type) {
1245         case TOOLBAR_MSGVIEW:
1246                 messageview_delete((MessageView *)toolbar_item->parent);
1247                 break;
1248         case TOOLBAR_MAIN:
1249                 mainwin = (MainWindow *)toolbar_item->parent;
1250                 summary_delete(mainwin->summaryview);
1251                 break;
1252         default: 
1253                 debug_print("toolbar event not supported\n");
1254                 break;
1255         }
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);
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);
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_GO_FOLDERS,         toolbar_go_folders_cb           },
2020
2021                 { A_SEND,               toolbar_send_cb                 },
2022                 { A_SEND_LATER, toolbar_send_later_cb           },
2023                 { A_DRAFT,              toolbar_draft_cb                },
2024                 { A_OPEN_MAIL,          toolbar_open_mail_cb            },
2025                 { A_CLOSE,              toolbar_close_cb                },
2026                 { A_PREFERENCES,        toolbar_preferences_cb          },
2027                 { A_INSERT,             toolbar_insert_cb               },
2028                 { A_ATTACH,             toolbar_attach_cb               },
2029                 { A_SIG,                toolbar_sig_cb                  },
2030                 { A_REP_SIG,            toolbar_replace_sig_cb          },
2031                 { A_EXTEDITOR,          toolbar_ext_editor_cb           },
2032                 { A_LINEWRAP_CURRENT,   toolbar_linewrap_current_cb     },
2033                 { A_LINEWRAP_ALL,       toolbar_linewrap_all_cb         },
2034                 { A_ADDRBOOK,           toolbar_addrbook_cb             },
2035 #ifdef USE_ENCHANT
2036                 { A_CHECK_SPELLING,     toolbar_check_spelling_cb       },
2037 #endif
2038                 { A_CLAWS_ACTIONS,      toolbar_actions_execute_cb      },
2039                 { A_CANCEL_INC,         toolbar_cancel_inc_cb           },
2040                 { A_CANCEL_SEND,        toolbar_cancel_send_cb          },
2041                 { A_CANCEL_ALL,         toolbar_cancel_all_cb           },
2042                 { A_CLAWS_PLUGINS,  toolbar_plugins_execute_cb  },
2043         };
2044
2045         num_items = sizeof(callbacks)/sizeof(callbacks[0]);
2046
2047         for (i = 0; i < num_items; i++) {
2048                 if (callbacks[i].index == item->index) {
2049                         callbacks[i].func(widget, item);
2050                         return;
2051                 }
2052         }
2053 }
2054 #ifndef GENERIC_UMPC
2055 #define TOOLBAR_ITEM(item,icon,text,tooltip) {                                                          \
2056         item = GTK_WIDGET(gtk_tool_button_new(icon, text));                                             \
2057         gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE);                            \
2058         gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE);                                      \
2059         gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE);                                      \
2060         g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item);     \
2061         gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);                              \
2062         CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item),                                                    \
2063                         tooltip);                                                                       \
2064 }
2065
2066 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) {                                              \
2067         GtkWidget *child = NULL, *btn = NULL, *arr = NULL;                                              \
2068         GList *gchild = NULL;                                                                           \
2069         item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text));                                        \
2070         gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE);                              \
2071         gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE);                                      \
2072         g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item);     \
2073         gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);                              \
2074         CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item),                                                    \
2075                         tooltip);                                                                       \
2076         CLAWS_SET_ARROW_TIP(GTK_MENU_TOOL_BUTTON(item), menutip);                                       \
2077         child = gtk_bin_get_child(GTK_BIN(item));                                                       \
2078         gchild = gtk_container_get_children(                                                            \
2079                         GTK_CONTAINER(child));                                                          \
2080         btn = (GtkWidget *)gchild->data;                                                                \
2081         gtkut_widget_set_can_focus(btn, FALSE);                                                         \
2082         arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL);                                      \
2083         gtkut_widget_set_can_focus(arr, FALSE);                                                         \
2084         g_list_free(gchild);                                                                            \
2085         gchild = gtk_container_get_children(GTK_CONTAINER(arr));                                        \
2086         gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1);                                   \
2087         g_list_free(gchild);                                                                            \
2088 }
2089 #else
2090 #define TOOLBAR_ITEM(item,icon,text,tooltip) {                                                          \
2091         item = GTK_WIDGET(gtk_tool_button_new(icon, text));                                             \
2092         gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE);                            \
2093         gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE);                                      \
2094         gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE);                                      \
2095         g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item);     \
2096         gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);                              \
2097 }
2098
2099 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) {                                              \
2100         GtkWidget *child = NULL, *btn = NULL, *arr = NULL;                                              \
2101         GList *gchild = NULL;                                                                           \
2102         item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text));                                        \
2103         gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE);                              \
2104         gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE);                                      \
2105         g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item);     \
2106         gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);                              \
2107         child = gtk_bin_get_child(GTK_BIN(item));                                                       \
2108         gchild = gtk_container_get_children(                                                            \
2109                         GTK_CONTAINER(child));                                                          \
2110         btn = (GtkWidget *)gchild->data;                                                                \
2111         gtkut_widget_set_can_focus(btn, FALSE);                                                         \
2112         arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL);                                      \
2113         gtkut_widget_set_can_focus(arr, FALSE);                                                         \
2114         g_list_free(gchild);                                                                            \
2115         gchild = gtk_container_get_children(GTK_CONTAINER(arr));                                        \
2116         gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1);                                   \
2117         g_list_free(gchild);                                                                            \
2118 }
2119 #endif
2120
2121 #define ADD_MENU_ITEM(name,cb,data) {                                                   \
2122         item = gtk_menu_item_new_with_mnemonic(name);                                   \
2123         gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);                              \
2124         g_signal_connect(G_OBJECT(item), "activate",                                    \
2125                          G_CALLBACK(cb),                                                \
2126                            toolbar_item);                                               \
2127         g_object_set_data(G_OBJECT(item), "int-value", GINT_TO_POINTER(data));          \
2128         gtk_widget_show(item);                                                          \
2129 }
2130
2131 static void toolbar_reply_menu_cb(GtkWidget *widget, gpointer data)
2132 {
2133         gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
2134         ToolbarItem *toolbar_item = (ToolbarItem *)data;
2135         
2136         toolbar_reply(toolbar_item, GPOINTER_TO_INT(int_value));
2137 }
2138
2139 static void toolbar_learn_menu_cb(GtkWidget *widget, gpointer data)
2140 {
2141         gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
2142         ToolbarItem *toolbar_item = (ToolbarItem *)data;
2143         
2144         toolbar_learn(toolbar_item, GPOINTER_TO_INT(int_value));
2145 }
2146
2147 /**
2148  * Create a new toolbar with specified type
2149  * if a callback list is passed it will be used before the 
2150  * common callback list
2151  **/
2152 Toolbar *toolbar_create(ToolbarType      type, 
2153                         GtkWidget       *container,
2154                         gpointer         data)
2155 {
2156         ToolbarItem *toolbar_item;
2157
2158         GtkWidget *toolbar;
2159         GtkWidget *icon_wid = NULL;
2160         GtkWidget *icon_news;
2161         GtkWidget *icon_ham;
2162         GtkWidget *item;
2163         ToolbarClawsActions *action_item;
2164         GSList *cur;
2165         GSList *toolbar_list;
2166         Toolbar *toolbar_data;
2167         GtkWidget *menu;
2168         toolbar_read_config_file(type);
2169         toolbar_list = toolbar_get_list(type);
2170
2171         toolbar_data = g_new0(Toolbar, 1); 
2172
2173         toolbar = gtk_toolbar_new();
2174
2175         gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL);
2176
2177         gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
2178         gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
2179         
2180         for (cur = toolbar_list; cur != NULL; cur = cur->next) {
2181
2182                 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
2183                         gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
2184                         continue;
2185                 }
2186                 
2187                 toolbar_item = g_new0(ToolbarItem, 1); 
2188                 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
2189                 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
2190                 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
2191                 toolbar_item->parent = data;
2192                 toolbar_item->type = type;
2193
2194                 /* collect toolbar items in list to keep track */
2195                 toolbar_data->item_list = 
2196                         g_slist_append(toolbar_data->item_list, 
2197                                        toolbar_item);
2198                 icon_wid = stock_pixmap_widget(stock_pixmap_get_icon(toolbar_item->file));
2199                         
2200                 switch (toolbar_item->index) {
2201
2202                 case A_GO_FOLDERS:
2203                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
2204                         toolbar_data->folders_btn = item;
2205                         break;
2206                 case A_RECEIVE_ALL:
2207                         TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2208                                 _("Receive Mail from all Accounts"),
2209                                 _("Receive Mail from selected Account"));
2210                         toolbar_data->getall_btn = item;
2211                         break;
2212                 case A_RECEIVE_CUR:
2213                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail from current Account"));
2214                         toolbar_data->get_btn = item;
2215                         break;
2216                 case A_SEND_QUEUED:
2217                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
2218                         toolbar_data->send_btn = item; 
2219                         break;
2220                 case A_CLOSE:
2221                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
2222                         toolbar_data->close_window_btn = item; 
2223                         break;
2224                 case A_PREFERENCES:
2225                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open preferences"));
2226                         toolbar_data->preferences_btn = item; 
2227                         break;
2228                 case A_OPEN_MAIL:
2229                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
2230                         toolbar_data->open_mail_btn = item; 
2231                         break;
2232                 case A_COMPOSE_EMAIL:
2233 #ifndef GENERIC_UMPC
2234                         TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2235                                 _("Compose Email"),
2236                                 _("Compose with selected Account"));
2237                         toolbar_data->compose_mail_btn = item; 
2238                         toolbar_data->compose_mail_icon = icon_wid; 
2239                         g_object_ref(toolbar_data->compose_mail_icon);
2240
2241                         icon_news = stock_pixmap_widget(STOCK_PIXMAP_NEWS_COMPOSE);
2242                         toolbar_data->compose_news_icon = icon_news; 
2243                         g_object_ref(toolbar_data->compose_news_icon);
2244 #else
2245                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2246                                 _("Compose Email"));
2247                         toolbar_data->compose_mail_btn = item; 
2248                         toolbar_data->compose_mail_icon = icon_wid; 
2249
2250                         icon_news = stock_pixmap_widget(STOCK_PIXMAP_NEWS_COMPOSE);
2251                         toolbar_data->compose_news_icon = icon_news; 
2252 #endif
2253                         break;
2254                 case A_LEARN_SPAM:
2255                         TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2256                                 _("Spam"),
2257                                 _("Learn as..."));
2258                         toolbar_data->learn_spam_btn = item; 
2259                         toolbar_data->learn_spam_icon = icon_wid; 
2260                         g_object_ref(toolbar_data->learn_spam_icon);
2261
2262                         icon_ham = stock_pixmap_widget(STOCK_PIXMAP_HAM_BTN);
2263                         toolbar_data->learn_ham_icon = icon_ham; 
2264                         g_object_ref(toolbar_data->learn_ham_icon);
2265
2266                         menu = gtk_menu_new();
2267                         ADD_MENU_ITEM(_("Learn as _Spam"), toolbar_learn_menu_cb, TRUE);
2268                         ADD_MENU_ITEM(_("Learn as _Ham"), toolbar_learn_menu_cb, FALSE);
2269                         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->learn_spam_btn), menu);
2270                         break;
2271                 case A_REPLY_MESSAGE:
2272 #ifndef GENERIC_UMPC
2273                         TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2274                                 _("Reply to Message"),
2275                                 _("Reply to Message options"));
2276                         toolbar_data->reply_btn = item;
2277
2278                         menu = gtk_menu_new();
2279                         ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITH_QUOTE);
2280                         ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITHOUT_QUOTE);
2281                         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->reply_btn), menu);
2282 #else
2283                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2284                                 _("Reply to Message"));
2285                         toolbar_data->reply_btn = item;
2286 #endif
2287                         break;
2288                 case A_REPLY_SENDER:
2289 #ifndef GENERIC_UMPC
2290                         TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2291                                 _("Reply to Sender"),
2292                                 _("Reply to Sender options"));
2293                         toolbar_data->replysender_btn = item;
2294
2295                         menu = gtk_menu_new();
2296                         ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE);
2297                         ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
2298                         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replysender_btn), menu);
2299 #else
2300                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2301                                 _("Reply to Sender"));
2302                         toolbar_data->replysender_btn = item;
2303 #endif
2304                         break;
2305                 case A_REPLY_ALL:
2306 #ifndef GENERIC_UMPC
2307                         TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2308                                 _("Reply to All"),
2309                                 _("Reply to All options"));
2310                         toolbar_data->replyall_btn = item;
2311
2312                         menu = gtk_menu_new();
2313                         ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE);
2314                         ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
2315                         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replyall_btn), menu);
2316 #else
2317                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2318                                 _("Reply to All"));
2319                         toolbar_data->replyall_btn = item;
2320 #endif
2321                         break;
2322                 case A_REPLY_ML:
2323 #ifndef GENERIC_UMPC
2324                         TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2325                                 _("Reply to Mailing-list"),
2326                                 _("Reply to Mailing-list options"));
2327                         toolbar_data->replylist_btn = item;
2328
2329                         menu = gtk_menu_new();
2330                         ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE);
2331                         ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
2332                         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replylist_btn), menu);
2333 #else
2334                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2335                                 _("Reply to Mailing-list"));
2336                         toolbar_data->replylist_btn = item;
2337 #endif
2338                         break;
2339                 case A_FORWARD:
2340 #ifndef GENERIC_UMPC
2341                         TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2342                                 _("Forward Message"),
2343                                 _("Forward Message options"));
2344                         toolbar_data->fwd_btn = item;
2345
2346                         menu = gtk_menu_new();
2347                         ADD_MENU_ITEM(_("_Forward"), toolbar_reply_menu_cb, COMPOSE_FORWARD_INLINE);
2348                         ADD_MENU_ITEM(_("For_ward as attachment"), toolbar_reply_menu_cb, COMPOSE_FORWARD_AS_ATTACH);
2349                         ADD_MENU_ITEM(_("Redirec_t"), toolbar_reply_menu_cb, COMPOSE_REDIRECT);
2350                         gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->fwd_btn), menu);
2351 #else
2352                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2353                                 _("Forward Message"));
2354                         toolbar_data->fwd_btn = item;
2355 #endif
2356                         break;
2357                 case A_TRASH:
2358                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
2359                         toolbar_data->trash_btn = item;
2360                         break;
2361                 case A_DELETE_REAL:
2362                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
2363                         toolbar_data->delete_btn = item;
2364                         break;
2365                 case A_EXECUTE:
2366                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
2367                         toolbar_data->exec_btn = item;
2368                         break;
2369                 case A_GOTO_PREV:
2370                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
2371                         toolbar_data->prev_btn = item;
2372                         break;
2373                 case A_GOTO_NEXT:
2374                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
2375                         toolbar_data->next_btn = item;
2376                         break;
2377                 
2378                 /* Compose Toolbar */
2379                 case A_SEND:
2380                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2381                         toolbar_data->send_btn = item;
2382                         break;
2383                 case A_SEND_LATER:
2384                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2385                         toolbar_data->sendl_btn = item;
2386                         break;
2387                 case A_DRAFT:
2388                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2389                         toolbar_data->draft_btn = item; 
2390                         break;
2391                 case A_INSERT:
2392                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2393                         toolbar_data->insert_btn = item; 
2394                         break;
2395                 case A_ATTACH:
2396                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2397                         toolbar_data->attach_btn = item;
2398                         break;
2399                 case A_SIG:
2400                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2401                         toolbar_data->sig_btn = item;
2402                         break;
2403                 case A_REP_SIG:
2404                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Replace signature"));
2405                         toolbar_data->repsig_btn = item;
2406                         break;
2407                 case A_EXTEDITOR:
2408                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2409                         toolbar_data->exteditor_btn = item;
2410                         break;
2411                 case A_LINEWRAP_CURRENT:
2412                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2413                         toolbar_data->linewrap_current_btn = item;
2414                         break;
2415                 case A_LINEWRAP_ALL:
2416                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2417                         toolbar_data->linewrap_all_btn = item;
2418                         break;
2419                 case A_ADDRBOOK:
2420                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2421                         toolbar_data->addrbook_btn = item;
2422                         break;
2423 #ifdef USE_ENCHANT
2424                 case A_CHECK_SPELLING:
2425                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2426                         toolbar_data->spellcheck_btn = item;
2427                         break;
2428 #endif
2429
2430                 case A_CLAWS_ACTIONS:
2431                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2432                         action_item = g_new0(ToolbarClawsActions, 1);
2433                         action_item->widget = item;
2434                         action_item->name   = g_strdup(toolbar_item->text);
2435
2436                         toolbar_data->action_list = 
2437                                 g_slist_append(toolbar_data->action_list,
2438                                                action_item);
2439                         break;
2440                 case A_CANCEL_INC:
2441                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2442                         toolbar_data->cancel_inc_btn = item;
2443                         break;
2444                 case A_CANCEL_SEND:
2445                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel sending"));
2446                         toolbar_data->cancel_send_btn = item;
2447                         break;
2448                 case A_CANCEL_ALL:
2449                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving/sending"));
2450                         toolbar_data->cancel_all_btn = item;
2451                         break;
2452                 case A_CLAWS_PLUGINS:
2453                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, toolbar_item->text);
2454                         break;
2455                 default:
2456                         TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2457                                 toolbar_ret_descr_from_val(toolbar_item->index));
2458                         /* find and set the tool tip text */
2459                         break;
2460                 }
2461
2462         }
2463         toolbar_data->toolbar = toolbar;
2464
2465         gtk_widget_show_all(toolbar);
2466
2467         if (type == TOOLBAR_MAIN) {
2468 #ifdef GENERIC_UMPC
2469                 MainWindow *mainwin = mainwindow_get_mainwindow();
2470                 GtkWidget *progressbar = gtk_progress_bar_new();
2471                 item = GTK_WIDGET(gtk_tool_item_new());
2472                 gtk_container_add (GTK_CONTAINER (item), progressbar);
2473                 gtk_widget_show(item);
2474                 gtk_widget_set_size_request(progressbar, 84, -1);
2475                 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2476                 mainwin->progressbar = progressbar;
2477 #endif
2478                 activate_compose_button(toolbar_data, 
2479                                         prefs_common.toolbar_style, 
2480                                         toolbar_data->compose_btn_type);
2481         }
2482         if (type != TOOLBAR_COMPOSE)
2483                 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2484                                 LEARN_SPAM);
2485         
2486         gtk_container_add(GTK_CONTAINER(container), toolbar);
2487         gtk_container_set_border_width(GTK_CONTAINER(container), 0);
2488
2489         return toolbar_data; 
2490 }
2491
2492 /**
2493  * Free toolbar structures
2494  */ 
2495 void toolbar_destroy(Toolbar * toolbar) {
2496
2497         TOOLBAR_DESTROY_ITEMS(toolbar->item_list);      
2498         TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2499 }
2500
2501 void toolbar_update(ToolbarType type, gpointer data)
2502 {
2503         Toolbar *toolbar_data;
2504         GtkWidget *handlebox;
2505         MainWindow *mainwin = (MainWindow*)data;
2506         Compose    *compose = (Compose*)data;
2507         MessageView *msgview = (MessageView*)data;
2508
2509 #ifndef GENERIC_UMPC
2510         switch(type) {
2511         case TOOLBAR_MAIN:
2512                 toolbar_data = mainwin->toolbar;
2513                 handlebox    = mainwin->handlebox;
2514                 break;
2515         case TOOLBAR_COMPOSE:
2516                 toolbar_data = compose->toolbar;
2517                 handlebox    = compose->handlebox;
2518                 break;
2519         case TOOLBAR_MSGVIEW:
2520                 toolbar_data = msgview->toolbar;
2521                 handlebox    = msgview->handlebox;
2522                 break;
2523         default:
2524                 return;
2525         }
2526
2527         gtk_container_remove(GTK_CONTAINER(handlebox), 
2528                              GTK_WIDGET(toolbar_data->toolbar));
2529
2530         toolbar_init(toolbar_data);
2531         toolbar_data = toolbar_create(type, handlebox, data);
2532 #else
2533         switch(type) {
2534         case TOOLBAR_MAIN:
2535                 toolbar_data = mainwin->toolbar;
2536                 handlebox    = mainwin->window;
2537                 break;
2538         case TOOLBAR_COMPOSE:
2539                 toolbar_data = compose->toolbar;
2540                 handlebox    = compose->window;
2541                 break;
2542         case TOOLBAR_MSGVIEW:
2543                 toolbar_data = msgview->toolbar;
2544                 handlebox    = msgview->window;
2545                 break;
2546         default:
2547                 return;
2548         }
2549         toolbar_init(toolbar_data);
2550         toolbar_data = toolbar_create(type, handlebox, data);
2551 #endif
2552
2553         switch(type) {
2554         case TOOLBAR_MAIN:
2555                 mainwin->toolbar = toolbar_data;
2556                 break;
2557         case TOOLBAR_COMPOSE:
2558                 compose->toolbar = toolbar_data;
2559                 break;
2560         case TOOLBAR_MSGVIEW:
2561                 msgview->toolbar = toolbar_data;
2562                 break;
2563         }
2564
2565         toolbar_style(type, prefs_common.toolbar_style, data);
2566
2567         if (type == TOOLBAR_MAIN) {
2568                 toolbar_main_set_sensitive((MainWindow*)data);
2569                 account_set_menu_only_toolbar();
2570         }
2571 }
2572
2573 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) {            \
2574         gtk_widget_set_sensitive(widget, sensitive);            \
2575 }
2576
2577 void toolbar_main_set_sensitive(gpointer data)
2578 {
2579         SensitiveCondMask state;
2580         gboolean sensitive;
2581         MainWindow *mainwin = (MainWindow*)data;
2582         Toolbar *toolbar = mainwin->toolbar;
2583         GSList *cur;
2584         GSList *entry_list = NULL;
2585         
2586         typedef struct _Entry Entry;
2587         struct _Entry {
2588                 GtkWidget *widget;
2589                 SensitiveCondMask cond;
2590                 gboolean empty;
2591         };
2592
2593 #define SET_WIDGET_COND(w, ...)     \
2594 do { \
2595         Entry *e = g_new0(Entry, 1); \
2596         e->widget = w; \
2597         e->cond = main_window_get_mask(__VA_ARGS__, -1); \
2598         entry_list = g_slist_append(entry_list, e); \
2599 } while (0)
2600         
2601         /* match all bit flags */
2602
2603         if (toolbar->get_btn)
2604                 SET_WIDGET_COND(toolbar->get_btn, 
2605                         M_HAVE_ACCOUNT, M_UNLOCKED, M_HAVE_RETRIEVABLE_ACCOUNT);
2606
2607         if (toolbar->getall_btn) {
2608                 SET_WIDGET_COND(toolbar->getall_btn, 
2609                         M_HAVE_ACCOUNT, M_UNLOCKED, M_HAVE_ANY_RETRIEVABLE_ACCOUNT);
2610         }
2611         if (toolbar->send_btn) {
2612                 SET_WIDGET_COND(toolbar->send_btn,
2613                         M_HAVE_QUEUED_MAILS);
2614         }
2615         if (toolbar->compose_mail_btn) {
2616                 SET_WIDGET_COND(toolbar->compose_mail_btn, 
2617                         M_HAVE_ACCOUNT);
2618         }
2619         if (toolbar->close_window_btn) {
2620                 SET_WIDGET_COND(toolbar->close_window_btn, 
2621                         M_UNLOCKED);
2622         }
2623         if (toolbar->open_mail_btn) {
2624                 SET_WIDGET_COND(toolbar->open_mail_btn, 
2625                         M_TARGET_EXIST, M_SUMMARY_ISLIST);
2626         }
2627         if (toolbar->reply_btn) {
2628                 SET_WIDGET_COND(toolbar->reply_btn,
2629                         M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2630         }
2631         if (toolbar->replyall_btn) {
2632                 SET_WIDGET_COND(toolbar->replyall_btn,
2633                         M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2634         }
2635         if (toolbar->replylist_btn) {
2636                 SET_WIDGET_COND(toolbar->replylist_btn,
2637                         M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2638         }
2639         if (toolbar->replysender_btn) {
2640                 SET_WIDGET_COND(toolbar->replysender_btn,
2641                         M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2642         }
2643         if (toolbar->fwd_btn) {
2644                 SET_WIDGET_COND(toolbar->fwd_btn, 
2645                         M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2646         }
2647
2648         if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2649                 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST, M_SUMMARY_ISLIST);
2650         } else {
2651                 SET_WIDGET_COND(toolbar->next_btn, -1);
2652         }
2653         
2654         if (toolbar->trash_btn)
2655                 SET_WIDGET_COND(toolbar->trash_btn,
2656                         M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS);
2657
2658         if (toolbar->delete_btn)
2659                 SET_WIDGET_COND(toolbar->delete_btn,
2660                         M_TARGET_EXIST, M_ALLOW_DELETE);
2661
2662         if (toolbar->exec_btn)
2663                 SET_WIDGET_COND(toolbar->exec_btn, 
2664                         M_DELAY_EXEC);
2665         
2666         if (toolbar->learn_spam_btn)
2667                 SET_WIDGET_COND(toolbar->learn_spam_btn, 
2668                         M_TARGET_EXIST, M_CAN_LEARN_SPAM, M_SUMMARY_ISLIST);
2669
2670         if (toolbar->cancel_inc_btn)
2671                 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2672                                 M_INC_ACTIVE);
2673
2674         if (toolbar->cancel_send_btn)
2675                 SET_WIDGET_COND(toolbar->cancel_send_btn,
2676                                 M_SEND_ACTIVE);
2677
2678         for (cur = toolbar->action_list; cur != NULL;  cur = cur->next) {
2679                 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2680                 
2681                 SET_WIDGET_COND(act->widget, M_TARGET_EXIST, M_UNLOCKED);
2682         }
2683
2684         state = main_window_get_current_state(mainwin);
2685
2686         for (cur = entry_list; cur != NULL; cur = cur->next) {
2687                 Entry *e = (Entry*) cur->data;
2688
2689                 if (e->widget != NULL) {
2690                         sensitive = ((e->cond & state) == e->cond);
2691                         GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive); 
2692                 }
2693         }
2694         
2695         while (entry_list != NULL) {
2696                 Entry *e = (Entry*) entry_list->data;
2697
2698                 g_free(e);
2699                 entry_list = g_slist_remove(entry_list, e);
2700         }
2701
2702         /* match any bit flags */
2703
2704         if (toolbar->cancel_all_btn)
2705                 SET_WIDGET_COND(toolbar->cancel_all_btn,
2706                                 M_INC_ACTIVE, M_SEND_ACTIVE);
2707
2708         for (cur = entry_list; cur != NULL; cur = cur->next) {
2709                 Entry *e = (Entry*) cur->data;
2710
2711                 if (e->widget != NULL) {
2712                         sensitive = ((e->cond & state) != 0);
2713                         GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive); 
2714                 }
2715         }
2716
2717         while (entry_list != NULL) {
2718                 Entry *e = (Entry*) entry_list->data;
2719
2720                 g_free(e);
2721                 entry_list = g_slist_remove(entry_list, e);
2722         }
2723
2724         g_slist_free(entry_list);
2725
2726         activate_compose_button(toolbar, 
2727                                 prefs_common.toolbar_style,
2728                                 toolbar->compose_btn_type);
2729         
2730 #undef SET_WIDGET_COND
2731 }
2732
2733 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2734 {
2735         Compose *compose = (Compose*)data;
2736         GSList *items = compose->toolbar->action_list;
2737
2738         if (compose->toolbar->send_btn)
2739                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2740         if (compose->toolbar->sendl_btn)
2741                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2742         if (compose->toolbar->draft_btn )
2743                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2744         if (compose->toolbar->insert_btn )
2745                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2746         if (compose->toolbar->attach_btn)
2747                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2748         if (compose->toolbar->sig_btn)
2749                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2750         if (compose->toolbar->repsig_btn)
2751                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->repsig_btn, sensitive);
2752         if (compose->toolbar->exteditor_btn)
2753                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2754         if (compose->toolbar->linewrap_current_btn)
2755                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2756         if (compose->toolbar->linewrap_all_btn)
2757                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2758         if (compose->toolbar->addrbook_btn)
2759                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2760 #ifdef USE_ENCHANT
2761         if (compose->toolbar->spellcheck_btn)
2762                 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2763 #endif
2764         for (; items != NULL; items = g_slist_next(items)) {
2765                 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2766                 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2767         }
2768 }
2769
2770 /**
2771  * Initialize toolbar structure
2772  **/
2773 static void toolbar_init(Toolbar * toolbar)
2774 {
2775
2776         toolbar->toolbar           = NULL;
2777         toolbar->folders_btn       = NULL;
2778         toolbar->get_btn           = NULL;
2779         toolbar->getall_btn        = NULL;
2780         toolbar->send_btn          = NULL;
2781         toolbar->compose_mail_btn  = NULL;
2782         toolbar->compose_mail_icon = NULL;
2783         toolbar->compose_news_icon = NULL;
2784         toolbar->reply_btn         = NULL;
2785         toolbar->replysender_btn   = NULL;
2786         toolbar->replyall_btn      = NULL;
2787         toolbar->replylist_btn     = NULL;
2788         toolbar->fwd_btn           = NULL;
2789         toolbar->trash_btn         = NULL;
2790         toolbar->delete_btn        = NULL;
2791         toolbar->prev_btn          = NULL;
2792         toolbar->next_btn          = NULL;
2793         toolbar->exec_btn          = NULL;
2794         toolbar->separator         = NULL;
2795         toolbar->learn_spam_btn    = NULL;
2796         toolbar->learn_spam_icon   = NULL;
2797         toolbar->learn_ham_icon    = NULL;
2798         toolbar->cancel_inc_btn    = NULL;
2799         toolbar->cancel_send_btn   = NULL;
2800         toolbar->cancel_all_btn    = NULL;
2801
2802         /* compose buttons */ 
2803         toolbar->sendl_btn         = NULL;
2804         toolbar->draft_btn         = NULL;
2805         toolbar->insert_btn        = NULL;
2806         toolbar->attach_btn        = NULL;
2807         toolbar->sig_btn           = NULL; 
2808         toolbar->repsig_btn        = NULL; 
2809         toolbar->exteditor_btn     = NULL; 
2810         toolbar->linewrap_current_btn = NULL;   
2811         toolbar->linewrap_all_btn  = NULL;      
2812         toolbar->addrbook_btn      = NULL; 
2813
2814         toolbar->open_mail_btn     = NULL;
2815         toolbar->close_window_btn  = NULL;
2816         toolbar->preferences_btn   = NULL;
2817         toolbar->action_list       = NULL;
2818         toolbar->item_list         = NULL;
2819 #ifdef USE_ENCHANT
2820         toolbar->spellcheck_btn    = NULL;
2821 #endif
2822
2823         toolbar_destroy(toolbar);
2824 }
2825
2826 /*
2827  */
2828 static void toolbar_reply(gpointer data, guint action)
2829 {
2830         ToolbarItem *toolbar_item = (ToolbarItem*)data;
2831         MainWindow *mainwin;
2832         MessageView *msgview;
2833         GSList *msginfo_list = NULL;
2834
2835         cm_return_if_fail(toolbar_item != NULL);
2836
2837         switch (toolbar_item->type) {
2838         case TOOLBAR_MAIN:
2839                 mainwin = (MainWindow*)toolbar_item->parent;
2840                 msginfo_list = summary_get_selection(mainwin->summaryview);
2841                 msgview = (MessageView*)mainwin->messageview;
2842                 break;
2843         case TOOLBAR_MSGVIEW:
2844                 msgview = (MessageView*)toolbar_item->parent;
2845                 cm_return_if_fail(msgview != NULL);     
2846                 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2847                 break;
2848         default:
2849                 return;
2850         }
2851
2852         cm_return_if_fail(msgview != NULL);
2853         cm_return_if_fail(msginfo_list != NULL);
2854         compose_reply_from_messageview(msgview, msginfo_list, action);
2855         g_slist_free(msginfo_list);
2856
2857         /* TODO: update reply state ion summaryview */
2858 }
2859
2860
2861 /* exported functions */
2862
2863 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2864 {
2865         MainWindow *mainwin = (MainWindow*)data;
2866
2867         inc_mail(mainwin, prefs_common.newmail_notify_manu);
2868 }
2869
2870 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2871 {
2872         MainWindow *mainwin = (MainWindow*)data;
2873
2874         inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2875 }
2876
2877 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2878 {
2879         GList *list;
2880         gboolean found;
2881         gboolean got_error = FALSE;
2882         gchar *errstr = NULL;
2883
2884         if (prefs_common.work_offline)
2885                 if (alertpanel(_("Offline warning"), 
2886                                _("You're working offline. Override?"),
2887                                GTK_STOCK_NO, GTK_STOCK_YES,
2888                                NULL) != G_ALERTALTERNATE)
2889                 return;
2890
2891         /* ask for confirmation before sending queued messages only
2892            in online mode and if there is at least one message queued
2893            in any of the folder queue
2894         */
2895         if (prefs_common.confirm_send_queued_messages) {
2896                 found = FALSE;
2897                 /* check if there's a queued message */
2898                 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2899                         Folder *folder = list->data;
2900
2901                         found = !procmsg_queue_is_empty(folder->queue);
2902                 }
2903                 /* if necessary, ask for confirmation before sending */
2904                 if (found && !prefs_common.work_offline) {
2905                         if (alertpanel(_("Send queued messages"), 
2906                                    _("Send all queued messages?"),
2907                                    GTK_STOCK_CANCEL, _("_Send"),
2908                                    NULL) != G_ALERTALTERNATE)
2909                                 return;
2910                 }
2911         }
2912
2913         for (list = folder_get_list(); list != NULL; list = list->next) {
2914                 Folder *folder = list->data;
2915
2916                 if (folder->queue) {
2917                         if (procmsg_send_queue(folder->queue, 
2918                                                prefs_common.savemsg,
2919                                                &errstr) < 0)
2920                                 got_error = TRUE;
2921                 }
2922         }
2923         if (got_error) {
2924                 if (!errstr)
2925                         alertpanel_error_log(_("Some errors occurred while "
2926                                            "sending queued messages."));
2927                 else {
2928                         alertpanel_error_log(_("Some errors occurred "
2929                                         "while sending queued messages:\n%s"), errstr);
2930                         g_free(errstr);
2931                 }
2932         }
2933 }
2934
2935 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2936 {
2937         MainWindow *mainwin = (MainWindow*)data;
2938         PrefsAccount *ac = NULL;
2939         FolderItem *item = mainwin->summaryview->folder_item;   
2940         GList * list;
2941         GList * cur;
2942         
2943         if (item) {
2944                 ac = account_find_from_item(item);
2945                 if (ac && ac->protocol != A_NNTP && ac->protocol != A_IMAP4) {
2946                         compose_new_with_folderitem(ac, item, NULL);            /* CLAWS */
2947                         return;
2948                 }
2949         }
2950
2951         /*
2952          * CLAWS - use current account
2953          */
2954         if (cur_account && (cur_account->protocol != A_NNTP)) {
2955                 compose_new_with_folderitem(cur_account, item, NULL);
2956                 return;
2957         }
2958
2959         /*
2960          * CLAWS - just get the first one
2961          */
2962         list = account_get_list();
2963         for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2964                 ac = (PrefsAccount *) cur->data;
2965                 if (ac->protocol != A_NNTP) {
2966                         compose_new_with_folderitem(ac, item, NULL);
2967                         return;
2968                 }
2969         }
2970 }
2971
2972 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2973 {
2974         MainWindow *mainwin = (MainWindow*)data;
2975         PrefsAccount * ac = NULL;
2976         GList * list;
2977         GList * cur;
2978
2979         if (mainwin->summaryview->folder_item) {
2980                 ac = mainwin->summaryview->folder_item->folder->account;
2981                 if (ac && ac->protocol == A_NNTP) {
2982                         compose_new_with_folderitem(ac,
2983                                     mainwin->summaryview->folder_item, NULL);
2984                         return;
2985                 }
2986         }
2987
2988         list = account_get_list();
2989         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2990                 ac = (PrefsAccount *) cur->data;
2991                 if (ac->protocol == A_NNTP) {
2992                         compose_new_with_folderitem(ac,
2993                                     mainwin->summaryview->folder_item, NULL);
2994                         return;
2995                 }
2996         }
2997 }