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