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