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