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