dceb13e8389efe9d08d151aa0f7ceaa6f24fc774
[claws.git] / src / toolbar.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2001-2003 Hiroyuki Yamamoto and the Sylpheed-Claws 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 2 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, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * General functions for accessing address book files.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #  include "config.h"
26 #endif
27
28 #include "defs.h"
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <dirent.h>
35 #include <sys/stat.h>
36 #include <math.h>
37 #include <setjmp.h>
38
39 #include "mainwindow.h"
40 #include "summaryview.h"
41 #include "compose.h"
42 #include "utils.h"
43 #include "xml.h"
44 #include "mgutils.h"
45 #include "prefs_gtk.h"
46 #include "codeconv.h"
47 #include "stock_pixmap.h"
48 #include "manage_window.h"
49 #include "gtkutils.h"
50 #include "toolbar.h"
51 #include "menu.h"
52 #include "inc.h"
53 #include "action.h"
54 #include "prefs_actions.h"
55 #include "prefs_common.h"
56 #include "prefs_toolbar.h"
57 #include "alertpanel.h"
58
59 /* elements */
60 #define TOOLBAR_TAG_INDEX        "toolbar"
61 #define TOOLBAR_TAG_ITEM         "item"
62 #define TOOLBAR_TAG_SEPARATOR    "separator"
63
64 #define TOOLBAR_ICON_FILE   "file"    
65 #define TOOLBAR_ICON_TEXT   "text"     
66 #define TOOLBAR_ICON_ACTION "action"    
67
68 gboolean      toolbar_is_duplicate              (gint           action,
69                                                  ToolbarType    source);
70 static void   toolbar_parse_item                (XMLFile        *file,
71                                                  ToolbarType    source);
72
73 static gint   toolbar_ret_val_from_text         (const gchar    *text);
74 static gchar *toolbar_ret_text_from_val         (gint           val);
75
76 static void   toolbar_set_default_main          (void);
77 static void   toolbar_set_default_compose       (void);
78 static void   toolbar_set_default_msgview       (void);
79
80 static void     toolbar_style                   (ToolbarType     type, 
81                                                  guint           action, 
82                                                  gpointer        data);
83
84 static MainWindow *get_mainwin                  (gpointer data);
85 static void activate_compose_button             (Toolbar        *toolbar,
86                                                  ToolbarStyle    style,
87                                                  ComposeButtonType type);
88
89 /* toolbar callbacks */
90 static void toolbar_reply                       (gpointer        data, 
91                                                  guint           action);
92 static void toolbar_delete_cb                   (GtkWidget      *widget,
93                                                  gpointer        data);
94
95 static void toolbar_compose_cb                  (GtkWidget      *widget,
96                                                  gpointer        data);
97
98 static void toolbar_reply_cb                    (GtkWidget      *widget,
99                                                  gpointer        data);
100
101 static void toolbar_reply_to_all_cb             (GtkWidget      *widget,
102                                                  gpointer        data);
103
104 static void toolbar_reply_to_list_cb            (GtkWidget      *widget,
105                                                  gpointer        data);
106
107 static void toolbar_reply_to_sender_cb          (GtkWidget      *widget,
108                                                  gpointer        data);
109
110 static void toolbar_forward_cb                  (GtkWidget      *widget,
111                                                  gpointer        data);
112
113 static void toolbar_next_unread_cb              (GtkWidget      *widget,
114                                                  gpointer        data);
115
116 static void toolbar_ignore_thread_cb            (GtkWidget      *widget,
117                                                  gpointer        data);
118
119 static void toolbar_print_cb                    (GtkWidget      *widget,
120                                                  gpointer        data);
121
122 static void toolbar_actions_execute_cb          (GtkWidget      *widget,
123                                                  gpointer        data);
124
125
126 static void toolbar_send_cb                     (GtkWidget      *widget,
127                                                  gpointer        data);
128 static void toolbar_send_later_cb               (GtkWidget      *widget,
129                                                  gpointer        data);
130 static void toolbar_draft_cb                    (GtkWidget      *widget,
131                                                  gpointer        data);
132 static void toolbar_insert_cb                   (GtkWidget      *widget,
133                                                  gpointer        data);
134 static void toolbar_attach_cb                   (GtkWidget      *widget,
135                                                  gpointer        data);
136 static void toolbar_sig_cb                      (GtkWidget      *widget,
137                                                  gpointer        data);
138 static void toolbar_ext_editor_cb               (GtkWidget      *widget,
139                                                  gpointer        data);
140 static void toolbar_linewrap_current_cb         (GtkWidget      *widget,
141                                                  gpointer        data);
142 static void toolbar_linewrap_all_cb             (GtkWidget      *widget,
143                                                  gpointer        data);
144 static void toolbar_addrbook_cb                 (GtkWidget      *widget, 
145                                                  gpointer        data);
146 #ifdef USE_ASPELL
147 static void toolbar_check_spelling_cb           (GtkWidget      *widget, 
148                                                  gpointer        data);
149 #endif
150
151 struct {
152         gchar *index_str;
153         const gchar *descr;
154 } toolbar_text [] = {
155         { "A_RECEIVE_ALL",      N_("Receive Mail on all Accounts")         },
156         { "A_RECEIVE_CUR",      N_("Receive Mail on current Account")      },
157         { "A_SEND_QUEUED",      N_("Send Queued Messages")                 },
158         { "A_COMPOSE_EMAIL",    N_("Compose Email")                        },
159         { "A_COMPOSE_NEWS",     N_("Compose News")                         },
160         { "A_REPLY_MESSAGE",    N_("Reply to Message")                     },
161         { "A_REPLY_SENDER",     N_("Reply to Sender")                      },
162         { "A_REPLY_ALL",        N_("Reply to All")                         },
163         { "A_REPLY_ML",         N_("Reply to Mailing-list")                },
164         { "A_FORWARD",          N_("Forward Message")                      }, 
165         { "A_DELETE",           N_("Delete Message")                       },
166         { "A_EXECUTE",          N_("Execute")                              },
167         { "A_GOTO_NEXT",        N_("Goto Next Message")                    },
168         { "A_IGNORE_THREAD",    N_("Ignore thread")                     },
169         { "A_PRINT",            N_("Print")                             },
170
171         { "A_SEND",             N_("Send Message")                         },
172         { "A_SENDL",            N_("Put into queue folder and send later") },
173         { "A_DRAFT",            N_("Save to draft folder")                 },
174         { "A_INSERT",           N_("Insert file")                          },   
175         { "A_ATTACH",           N_("Attach file")                          },
176         { "A_SIG",              N_("Insert signature")                     },
177         { "A_EXTEDITOR",        N_("Edit with external editor")            },
178         { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") }, 
179         { "A_LINEWRAP_ALL",     N_("Wrap all long lines")                  }, 
180         { "A_ADDRBOOK",         N_("Address book")                         },
181 #ifdef USE_ASPELL
182         { "A_CHECK_SPELLING",   N_("Check spelling")                       },
183 #endif
184         { "A_SYL_ACTIONS",      N_("Sylpheed Actions Feature")             }, 
185         { "A_SEPARATOR",        "Separator"                             }
186 };
187
188 /* struct holds configuration files and a list of
189  * currently active toolbar items 
190  * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
191  * give us an index
192  */
193 struct {
194         const gchar  *conf_file;
195         GSList       *item_list;
196 } toolbar_config[3] = {
197         { "toolbar_main.xml",    NULL},
198         { "toolbar_compose.xml", NULL}, 
199         { "toolbar_msgview.xml", NULL}
200 };
201
202 static GtkItemFactoryEntry reply_entries[] =
203 {
204         {N_("/Reply with _quote"), NULL,    toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
205         {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
206 };
207 static GtkItemFactoryEntry replyall_entries[] =
208 {
209         {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
210         {N_("/_Reply to all without quote"), "a",     toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
211 };
212 static GtkItemFactoryEntry replylist_entries[] =
213 {
214         {N_("/Reply to list with _quote"),    NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
215         {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
216 };
217 static GtkItemFactoryEntry replysender_entries[] =
218 {
219         {N_("/Reply to sender with _quote"),    NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
220         {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
221 };
222 static GtkItemFactoryEntry forward_entries[] =
223 {
224         {N_("/_Forward"),               "f",        toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
225         {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
226         {N_("/Redirec_t"),              NULL,       toolbar_reply, COMPOSE_REDIRECT, NULL}
227 };
228
229
230 gint toolbar_ret_val_from_descr(const gchar *descr)
231 {
232         gint i;
233
234         for (i = 0; i < N_ACTION_VAL; i++) {
235                 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
236                                 return i;
237         }
238         
239         return -1;
240 }
241
242 gchar *toolbar_ret_descr_from_val(gint val)
243 {
244         g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
245
246         return gettext(toolbar_text[val].descr);
247 }
248
249 static gint toolbar_ret_val_from_text(const gchar *text)
250 {
251         gint i;
252         
253         for (i = 0; i < N_ACTION_VAL; i++) {
254                 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
255                                 return i;
256         }
257         
258         return -1;
259 }
260
261 static gchar *toolbar_ret_text_from_val(gint val)
262 {
263         g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
264
265         return toolbar_text[val].index_str;
266 }
267
268 gboolean toolbar_is_duplicate(gint action, ToolbarType source)
269 {
270         GSList *cur;
271
272         if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS)) 
273                 return FALSE;
274
275         for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
276                 ToolbarItem *item = (ToolbarItem*) cur->data;
277                 
278                 if (item->index == action)
279                         return TRUE;
280         }
281         return FALSE;
282 }
283
284 /* depending on toolbar type this function 
285    returns a list of available toolbar events being 
286    displayed by prefs_toolbar
287 */
288 GList *toolbar_get_action_items(ToolbarType source)
289 {
290         GList *items = NULL;
291         gint i = 0;
292         
293         if (source == TOOLBAR_MAIN) {
294                 gint main_items[]   = { A_RECEIVE_ALL,   A_RECEIVE_CUR,   A_SEND_QUEUED,
295                                         A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER, 
296                                         A_REPLY_ALL,     A_REPLY_ML,      A_FORWARD, 
297                                         A_DELETE,        A_EXECUTE,       A_GOTO_NEXT, 
298                                         A_IGNORE_THREAD, A_PRINT,  
299                                         A_ADDRBOOK,      A_SYL_ACTIONS };
300
301                 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++)  {
302                         items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
303                         if (main_items[i] == A_PRINT) {
304                                 g_print("$$$ descr %s, trans %s\n",
305                                         toolbar_text[main_items[i]].descr,
306                                         gettext(toolbar_text[main_items[i]].descr));
307                         }
308                 }       
309         }
310         else if (source == TOOLBAR_COMPOSE) {
311                 gint comp_items[] =   { A_SEND,          A_SENDL,        A_DRAFT,
312                                         A_INSERT,        A_ATTACH,       A_SIG,
313                                         A_EXTEDITOR,     A_LINEWRAP_CURRENT,     
314                                         A_LINEWRAP_ALL,  A_ADDRBOOK,
315 #ifdef USE_ASPELL
316                                         A_CHECK_SPELLING, 
317 #endif
318                                         A_SYL_ACTIONS };        
319
320                 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++) 
321                         items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
322         }
323         else if (source == TOOLBAR_MSGVIEW) {
324                 gint msgv_items[] =   { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
325                                         A_REPLY_ALL,     A_REPLY_ML,      A_FORWARD,
326                                         A_DELETE,        A_GOTO_NEXT,     A_ADDRBOOK,
327                                         A_SYL_ACTIONS };        
328
329                 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++) 
330                         items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
331         }
332
333         return items;
334 }
335
336 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
337 {
338         GList *attr;
339         gchar *name, *value;
340         ToolbarItem *item = NULL;
341
342         attr = xml_get_current_tag_attr(file);
343         item = g_new0(ToolbarItem, 1);
344         while( attr ) {
345                 name = ((XMLAttr *)attr->data)->name;
346                 value = ((XMLAttr *)attr->data)->value;
347                 
348                 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0) 
349                         item->file = g_strdup (value);
350                 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
351                         item->text = g_strdup (value);
352                 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
353                         item->index = toolbar_ret_val_from_text(value);
354
355                 attr = g_list_next(attr);
356         }
357         if (item->index != -1) {
358                 
359                 if (!toolbar_is_duplicate(item->index, source)) 
360                         toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
361                                                                          item);
362         }
363 }
364
365 static void toolbar_set_default_main(void) 
366 {
367         struct {
368                 gint action;
369                 gint icon;
370                 gchar *text;
371         } default_toolbar[] = {
372                 { A_RECEIVE_CUR,   STOCK_PIXMAP_MAIL_RECEIVE,         _("Get")     },
373                 { A_RECEIVE_ALL,   STOCK_PIXMAP_MAIL_RECEIVE_ALL,     _("Get All") },
374                 { A_SEPARATOR,     0,                                 ("")         }, 
375                 { A_SEND_QUEUED,   STOCK_PIXMAP_MAIL_SEND_QUEUE,      _("Send")    },
376                 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE,         _("Email")   },
377                 { A_SEPARATOR,     0,                                 ("")         },
378                 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY,           _("Reply")   }, 
379                 { A_REPLY_ALL,     STOCK_PIXMAP_MAIL_REPLY_TO_ALL,    _("All")     },
380                 { A_REPLY_SENDER,  STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender")  },
381                 { A_FORWARD,       STOCK_PIXMAP_MAIL_FORWARD,         _("Forward") },
382                 { A_SEPARATOR,     0,                                 ("")         },
383                 { A_DELETE,        STOCK_PIXMAP_CLOSE,                _("Delete")  },
384                 { A_EXECUTE,       STOCK_PIXMAP_EXEC,                 _("Execute") },
385                 { A_GOTO_NEXT,     STOCK_PIXMAP_DOWN_ARROW,           _("Next")    }
386         };
387         
388         gint i;
389         
390         for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
391                 
392                 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
393                 
394                 if (default_toolbar[i].action != A_SEPARATOR) {
395                         
396                         gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
397                         
398                         toolbar_item->file  = g_strdup(file);
399                         toolbar_item->index = default_toolbar[i].action;
400                         toolbar_item->text  = g_strdup(default_toolbar[i].text);
401                 } else {
402
403                         toolbar_item->file  = g_strdup(TOOLBAR_TAG_SEPARATOR);
404                         toolbar_item->index = A_SEPARATOR;
405                 }
406                 
407                 if (toolbar_item->index != -1) {
408                         if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN)) 
409                                 toolbar_config[TOOLBAR_MAIN].item_list = 
410                                         g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
411                 }       
412         }
413 }
414
415 static void toolbar_set_default_compose(void)
416 {
417         struct {
418                 gint action;
419                 gint icon;
420                 gchar *text;
421         } default_toolbar[] = {
422                 { A_SEND,               STOCK_PIXMAP_MAIL_SEND,         _("Send")               },
423                 { A_SENDL,              STOCK_PIXMAP_MAIL_SEND_QUEUE,   _("Send later")         },
424                 { A_DRAFT,              STOCK_PIXMAP_MAIL,              _("Draft")              },
425                 { A_SEPARATOR,          0,                               ("")                   }, 
426                 { A_INSERT,             STOCK_PIXMAP_INSERT_FILE,       _("Insert")             },
427                 { A_ATTACH,             STOCK_PIXMAP_MAIL_ATTACH,       _("Attach")             },
428                 { A_SIG,                STOCK_PIXMAP_MAIL_SIGN,         _("Signature")          },
429                 { A_SEPARATOR,          0,                               ("")                   },
430                 { A_EXTEDITOR,          STOCK_PIXMAP_EDIT_EXTERN,       _("Editor")             },
431                 { A_LINEWRAP_CURRENT,   STOCK_PIXMAP_LINEWRAP_CURRENT,  _("Wrap paragraph")     },
432                 { A_LINEWRAP_ALL,       STOCK_PIXMAP_LINEWRAP_ALL,      _("Wrap all")           },
433                 { A_SEPARATOR,          0,                               ("")                   },
434                 { A_ADDRBOOK,           STOCK_PIXMAP_ADDRESS_BOOK,      _("Address")            }
435         };
436         
437         gint i;
438
439         for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
440                 
441                 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
442                 
443                 if (default_toolbar[i].action != A_SEPARATOR) {
444                         
445                         gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
446                         
447                         toolbar_item->file  = g_strdup(file);
448                         toolbar_item->index = default_toolbar[i].action;
449                         toolbar_item->text  = g_strdup(default_toolbar[i].text);
450                 } else {
451
452                         toolbar_item->file  = g_strdup(TOOLBAR_TAG_SEPARATOR);
453                         toolbar_item->index = A_SEPARATOR;
454                 }
455                 
456                 if (toolbar_item->index != -1) {
457                         if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE)) 
458                                 toolbar_config[TOOLBAR_COMPOSE].item_list = 
459                                         g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
460                 }       
461         }
462 }
463
464 static void toolbar_set_default_msgview(void)
465 {
466         struct {
467                 gint action;
468                 gint icon;
469                 gchar *text;
470         } default_toolbar[] = {
471                 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY,           _("Reply")   }, 
472                 { A_REPLY_ALL,     STOCK_PIXMAP_MAIL_REPLY_TO_ALL,    _("All")     },
473                 { A_REPLY_SENDER,  STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender")  },
474                 { A_FORWARD,       STOCK_PIXMAP_MAIL_FORWARD,         _("Forward") },
475                 { A_SEPARATOR,     0,                                 ("")         },
476                 { A_DELETE,        STOCK_PIXMAP_CLOSE,                _("Delete")  },
477                 { A_GOTO_NEXT,     STOCK_PIXMAP_DOWN_ARROW,           _("Next")    }
478         };
479         
480         gint i;
481
482         for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
483                 
484                 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
485                 
486                 if (default_toolbar[i].action != A_SEPARATOR) {
487                         
488                         gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
489                         
490                         toolbar_item->file  = g_strdup(file);
491                         toolbar_item->index = default_toolbar[i].action;
492                         toolbar_item->text  = g_strdup(default_toolbar[i].text);
493                 } else {
494
495                         toolbar_item->file  = g_strdup(TOOLBAR_TAG_SEPARATOR);
496                         toolbar_item->index = A_SEPARATOR;
497                 }
498                 
499                 if (toolbar_item->index != -1) {
500                         if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW)) 
501                                 toolbar_config[TOOLBAR_MSGVIEW].item_list = 
502                                         g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
503                 }       
504         }
505 }
506
507 void toolbar_set_default(ToolbarType source)
508 {
509         if (source == TOOLBAR_MAIN)
510                 toolbar_set_default_main();
511         else if  (source == TOOLBAR_COMPOSE)
512                 toolbar_set_default_compose();
513         else if  (source == TOOLBAR_MSGVIEW)
514                 toolbar_set_default_msgview();
515 }
516
517 void toolbar_save_config_file(ToolbarType source)
518 {
519         GSList *cur;
520         FILE *fp;
521         PrefFile *pfile;
522         gchar *fileSpec = NULL;
523
524         debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
525
526         fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
527         pfile = prefs_write_open(fileSpec);
528         g_free( fileSpec );
529         if( pfile ) {
530                 fp = pfile->fp;
531                 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL);
532
533                 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
534
535                 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
536                         ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
537                         
538                         if (toolbar_item->index != A_SEPARATOR) {
539                                 fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
540                                         TOOLBAR_TAG_ITEM, 
541                                         TOOLBAR_ICON_FILE, toolbar_item->file,
542                                         TOOLBAR_ICON_TEXT);
543                                 xml_file_put_escape_str(fp, toolbar_item->text);
544                                 fprintf(fp, "\" %s=\"%s\"/>\n",
545                                         TOOLBAR_ICON_ACTION, 
546                                         toolbar_ret_text_from_val(toolbar_item->index));
547                         } else {
548                                 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR); 
549                         }
550                 }
551
552                 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);      
553         
554                 if (prefs_file_close (pfile) < 0 ) 
555                         g_warning("failed to write toolbar configuration to file\n");
556         } else
557                 g_warning("failed to open toolbar configuration file for writing\n");
558 }
559
560 void toolbar_read_config_file(ToolbarType source)
561 {
562         XMLFile *file   = NULL;
563         gchar *fileSpec = NULL;
564         GList *attr;
565         gboolean retVal;
566         jmp_buf    jumper;
567
568         debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
569
570         fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
571         file = xml_open_file(fileSpec);
572         g_free(fileSpec);
573
574         toolbar_clear_list(source);
575
576         if (file) {
577                 if ((setjmp(jumper))
578                 || (xml_get_dtd(file))
579                 || (xml_parse_next_tag(file))
580                 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
581                         xml_close_file(file);
582                         return;
583                 }
584
585                 attr = xml_get_current_tag_attr(file);
586                 
587                 retVal = TRUE;
588                 for (;;) {
589                         if (!file->level) 
590                                 break;
591                         /* Get item tag */
592                         if (xml_parse_next_tag(file)) 
593                                 longjmp(jumper, 1);
594
595                         /* Get next tag (icon, icon_text or icon_action) */
596                         if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
597                                 toolbar_parse_item(file, source);
598                         } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
599                                 ToolbarItem *item = g_new0(ToolbarItem, 1);
600                         
601                                 item->file   = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
602                                 item->index  = A_SEPARATOR;
603                                 toolbar_config[source].item_list = 
604                                         g_slist_append(toolbar_config[source].item_list, item);
605                         }
606
607                 }
608                 xml_close_file(file);
609         }
610
611         if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
612
613                 if (source == TOOLBAR_MAIN) 
614                         toolbar_set_default(TOOLBAR_MAIN);
615                 else if (source == TOOLBAR_COMPOSE) 
616                         toolbar_set_default(TOOLBAR_COMPOSE);
617                 else if (source == TOOLBAR_MSGVIEW) 
618                         toolbar_set_default(TOOLBAR_MSGVIEW);
619                 else {          
620                         g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
621                         return;
622                 }
623
624                 toolbar_save_config_file(source);
625         }
626 }
627
628 /*
629  * clears list of toolbar items read from configuration files
630  */
631 void toolbar_clear_list(ToolbarType source)
632 {
633         while (toolbar_config[source].item_list != NULL) {
634                 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
635                 
636                 toolbar_config[source].item_list = 
637                         g_slist_remove(toolbar_config[source].item_list, item);
638
639                 if (item->file)
640                         g_free(item->file);
641                 if (item->text)
642                         g_free(item->text);
643                 g_free(item);   
644         }
645         g_slist_free(toolbar_config[source].item_list);
646 }
647
648
649 /* 
650  * return list of Toolbar items
651  */
652 GSList *toolbar_get_list(ToolbarType source)
653 {
654         GSList *list = NULL;
655
656         if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
657                 list = toolbar_config[source].item_list;
658
659         return list;
660 }
661
662 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
663 {
664         ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
665
666         toolbar_item->file  = g_strdup(t_item->file);
667         toolbar_item->text  = g_strdup(t_item->text);
668         toolbar_item->index = t_item->index;
669         
670         toolbar_config[source].item_list = 
671                 g_slist_append(toolbar_config[source].item_list,
672                                toolbar_item);
673 }
674
675 void toolbar_action_execute(GtkWidget    *widget,
676                             GSList       *action_list, 
677                             gpointer     data,
678                             gint         source) 
679 {
680         GSList *cur, *lop;
681         gchar *action, *action_p;
682         gboolean found = FALSE;
683         gint i = 0;
684
685         for (cur = action_list; cur != NULL;  cur = cur->next) {
686                 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
687
688                 if (widget == act->widget) {
689                         
690                         for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
691                                 action = g_strdup((gchar*)lop->data);
692
693                                 action_p = strstr(action, ": ");
694                                 action_p[0] = 0x00;
695                                 if (g_utf8_collate(act->name, action) == 0) {
696                                         found = TRUE;
697                                         g_free(action);
698                                         break;
699                                 } else 
700                                         i++;
701                                 g_free(action);
702                         }
703                         if (found) 
704                                 break;
705                 }
706         }
707
708         if (found) 
709                 actions_execute(data, i, widget, source);
710         else
711                 g_warning ("Error: did not find Sylpheed Action to execute");
712 }
713
714 static void activate_compose_button (Toolbar           *toolbar,
715                                      ToolbarStyle      style,
716                                      ComposeButtonType type)
717 {
718         if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
719                 return;
720
721         gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn 
722                         : toolbar->compose_news_btn);
723         gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
724                         : toolbar->compose_mail_btn);
725         toolbar->compose_btn_type = type;       
726 }
727
728 void toolbar_set_compose_button(Toolbar            *toolbar, 
729                                 ComposeButtonType  compose_btn_type)
730 {
731         if (toolbar->compose_btn_type != compose_btn_type)
732                 activate_compose_button(toolbar, 
733                                         prefs_common.toolbar_style,
734                                         compose_btn_type);
735 }
736
737 void toolbar_toggle(guint action, gpointer data)
738 {
739         MainWindow *mainwin = (MainWindow*)data;
740         GList *list;
741         GList *cur;
742
743         g_return_if_fail(mainwin != NULL);
744
745         toolbar_style(TOOLBAR_MAIN, action, mainwin);
746
747         list = compose_get_compose_list();
748         for (cur = list; cur != NULL; cur = cur->next) {
749                 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
750         }
751         list = messageview_get_msgview_list();
752         for (cur = list; cur != NULL; cur = cur->next) {
753                 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
754         }
755         
756 }
757
758 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
759 {
760         switch ((ToolbarStyle)action) {
761         case TOOLBAR_NONE:
762                 gtk_widget_hide(handlebox_wid);
763                 break;
764         case TOOLBAR_ICON:
765                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
766                                       GTK_TOOLBAR_ICONS);
767                 break;
768         case TOOLBAR_TEXT:
769                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
770                                       GTK_TOOLBAR_TEXT);
771                 break;
772         case TOOLBAR_BOTH:
773                 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
774                                       GTK_TOOLBAR_BOTH);
775                 break;
776         default:
777                 return;
778         }
779
780         prefs_common.toolbar_style = (ToolbarStyle)action;
781         gtk_widget_set_size_request(handlebox_wid, 1, -1);
782         
783         if (prefs_common.toolbar_style != TOOLBAR_NONE) {
784                 gtk_widget_show(handlebox_wid);
785                 gtk_widget_queue_resize(handlebox_wid);
786         }
787 }
788 /*
789  * Change the style of toolbar
790  */
791 static void toolbar_style(ToolbarType type, guint action, gpointer data)
792 {
793         GtkWidget  *handlebox_wid;
794         GtkWidget  *toolbar_wid;
795         MainWindow *mainwin = (MainWindow*)data;
796         Compose    *compose = (Compose*)data;
797         MessageView *msgview = (MessageView*)data;
798         
799         g_return_if_fail(data != NULL);
800         
801         switch (type) {
802         case TOOLBAR_MAIN:
803                 handlebox_wid = mainwin->handlebox;
804                 toolbar_wid = mainwin->toolbar->toolbar;
805                 break;
806         case TOOLBAR_COMPOSE:
807                 handlebox_wid = compose->handlebox;
808                 toolbar_wid = compose->toolbar->toolbar;
809                 break;
810         case TOOLBAR_MSGVIEW: 
811                 handlebox_wid = msgview->handlebox;
812                 toolbar_wid = msgview->toolbar->toolbar;
813                 break;
814         default:
815
816                 return;
817         }
818         toolbar_set_style(toolbar_wid, handlebox_wid, action);
819 }
820
821 /* Toolbar handling */
822 static void toolbar_inc_cb(GtkWidget    *widget,
823                            gpointer      data)
824 {
825         ToolbarItem *toolbar_item = (ToolbarItem*)data;
826         MainWindow *mainwin;
827
828         g_return_if_fail(toolbar_item != NULL);
829
830         switch (toolbar_item->type) {
831         case TOOLBAR_MAIN:
832                 mainwin = (MainWindow*)toolbar_item->parent;    
833                 inc_mail_cb(mainwin, 0, NULL);
834                 break;
835         default:
836                 break;
837         }
838 }
839
840 static void toolbar_inc_all_cb(GtkWidget        *widget,
841                                gpointer          data)
842 {
843         ToolbarItem *toolbar_item = (ToolbarItem*)data;
844         MainWindow *mainwin;
845
846         g_return_if_fail(toolbar_item != NULL);
847
848         switch (toolbar_item->type) {
849         case TOOLBAR_MAIN:
850                 mainwin = (MainWindow*)toolbar_item->parent;
851                 inc_all_account_mail_cb(mainwin, 0, NULL);
852                 break;
853         default:
854                 break;
855         }
856 }
857
858 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
859 {
860         ToolbarItem *toolbar_item = (ToolbarItem*)data;
861         MainWindow *mainwin;
862
863         g_return_if_fail(toolbar_item != NULL);
864
865         switch (toolbar_item->type) {
866         case TOOLBAR_MAIN:
867                 mainwin = (MainWindow*)toolbar_item->parent;
868                 send_queue_cb(mainwin, 0, NULL);
869                 break;
870         default:
871                 break;
872         }
873 }
874
875 static void toolbar_exec_cb(GtkWidget   *widget,
876                             gpointer     data)
877 {
878         MainWindow *mainwin = get_mainwin(data);
879
880         g_return_if_fail(mainwin != NULL);
881         summary_execute(mainwin->summaryview);
882 }
883
884 /*
885  * Delete current/selected(s) message(s)
886  */
887 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
888 {
889         ToolbarItem *toolbar_item = (ToolbarItem*)data;
890         MainWindow *mainwin;
891
892         g_return_if_fail(toolbar_item != NULL);
893         g_return_if_fail(toolbar_item->parent);
894         
895         switch (toolbar_item->type) {
896         case TOOLBAR_MSGVIEW:
897                 messageview_delete((MessageView *)toolbar_item->parent);
898                 break;
899         case TOOLBAR_MAIN:
900                 mainwin = (MainWindow *)toolbar_item->parent;
901                 summary_delete(mainwin->summaryview);
902                 break;
903         default: 
904                 debug_print("toolbar event not supported\n");
905                 break;
906         }
907 }
908
909
910 /*
911  * Compose new message
912  */
913 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
914 {
915         ToolbarItem *toolbar_item = (ToolbarItem*)data;
916         MainWindow *mainwin;
917         MessageView *msgview;
918
919         g_return_if_fail(toolbar_item != NULL);
920
921         switch (toolbar_item->type) {
922         case TOOLBAR_MAIN:
923                 mainwin = (MainWindow*)toolbar_item->parent;
924                 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS) 
925                         compose_news_cb(mainwin, 0, NULL);
926                 else
927                         compose_mail_cb(mainwin, 0, NULL);
928                 break;
929         case TOOLBAR_MSGVIEW:
930                 msgview = (MessageView*)toolbar_item->parent;
931                 compose_new_with_folderitem(NULL, 
932                                             msgview->msginfo->folder);
933                 break;  
934         default:
935                 debug_print("toolbar event not supported\n");
936         }
937 }
938
939
940 /*
941  * Reply Message
942  */
943 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
944 {
945         toolbar_reply(data, prefs_common.reply_with_quote ? 
946                       COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
947 }
948
949
950 /*
951  * Reply message to Sender and All recipients
952  */
953 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
954 {
955         toolbar_reply(data,
956                       prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE 
957                       : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
958 }
959
960
961 /*
962  * Reply to Mailing List
963  */
964 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
965 {
966         toolbar_reply(data, 
967                       prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE 
968                       : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
969 }
970
971
972 /*
973  * Reply to sender of message
974  */ 
975 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
976 {
977         toolbar_reply(data, 
978                       prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE 
979                       : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
980 }
981
982 /*
983  * Open addressbook
984  */ 
985 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
986 {
987         ToolbarItem *toolbar_item = (ToolbarItem*)data;
988         Compose *compose;
989
990         g_return_if_fail(toolbar_item != NULL);
991
992         switch (toolbar_item->type) {
993         case TOOLBAR_MAIN:
994         case TOOLBAR_MSGVIEW:
995                 compose = NULL;
996                 break;
997         case TOOLBAR_COMPOSE:
998                 compose = (Compose *)toolbar_item->parent;
999                 break;
1000         default:
1001                 return;
1002         }
1003         addressbook_open(compose);
1004 }
1005
1006
1007 /*
1008  * Forward current/selected(s) message(s)
1009  */
1010 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1011 {
1012         toolbar_reply(data, COMPOSE_FORWARD);
1013 }
1014
1015
1016 /*
1017  * Goto Next Unread Message
1018  */
1019 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1020 {
1021         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1022         MainWindow *mainwin;
1023         MessageView *msgview;
1024
1025         g_return_if_fail(toolbar_item != NULL);
1026
1027         switch (toolbar_item->type) {
1028         case TOOLBAR_MAIN:
1029                 mainwin = (MainWindow*)toolbar_item->parent;
1030                 summary_select_next_unread(mainwin->summaryview);
1031                 break;
1032                 
1033         case TOOLBAR_MSGVIEW:
1034                 msgview = (MessageView*)toolbar_item->parent;
1035                 summary_select_next_unread(msgview->mainwin->summaryview);
1036                 
1037                 /* Now we need to update the messageview window */
1038                 if (msgview->mainwin->summaryview->selected) {
1039                         GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1040                         
1041                         MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree, 
1042                                                                         msgview->mainwin->summaryview->selected);
1043                        
1044                         messageview_show(msgview, msginfo, 
1045                                          msgview->all_headers);
1046                 } else {
1047                         gtk_widget_destroy(msgview->window);
1048                 }
1049                 break;
1050         default:
1051                 debug_print("toolbar event not supported\n");
1052         }
1053 }
1054
1055 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1056 {
1057         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1058         MainWindow *mainwin;
1059
1060         g_return_if_fail(toolbar_item != NULL);
1061
1062         switch (toolbar_item->type) {
1063         case TOOLBAR_MAIN:
1064                 mainwin = (MainWindow *) toolbar_item->parent;
1065                 summary_toggle_ignore_thread(mainwin->summaryview);
1066                 break;
1067         case TOOLBAR_MSGVIEW:
1068                 /* TODO: see toolbar_next_unread_cb() if you need
1069                  * this in the message view */
1070                 break;
1071         default:
1072                 debug_print("toolbar event not supported\n");
1073                 break;
1074         }
1075 }
1076
1077 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1078 {
1079         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1080         MainWindow *mainwin;
1081
1082         g_return_if_fail(toolbar_item != NULL);
1083
1084         switch (toolbar_item->type) {
1085         case TOOLBAR_MAIN:
1086                 mainwin = (MainWindow *) toolbar_item->parent;
1087                 summary_print(mainwin->summaryview);
1088                 break;
1089         case TOOLBAR_MSGVIEW:
1090                 /* TODO: see toolbar_next_unread_cb() if you need
1091                  * this in the message view */
1092                 break;
1093         default:
1094                 debug_print("toolbar event not supported\n");
1095                 break;
1096         }
1097 }
1098
1099 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1100 {
1101         compose_toolbar_cb(A_SEND, data);
1102 }
1103
1104 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1105 {
1106         compose_toolbar_cb(A_SENDL, data);
1107 }
1108
1109 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1110 {
1111         compose_toolbar_cb(A_DRAFT, data);
1112 }
1113
1114 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1115 {
1116         compose_toolbar_cb(A_INSERT, data);
1117 }
1118
1119 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1120 {
1121         compose_toolbar_cb(A_ATTACH, data);
1122 }
1123
1124 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1125 {
1126         compose_toolbar_cb(A_SIG, data);
1127 }
1128
1129 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1130 {
1131         compose_toolbar_cb(A_EXTEDITOR, data);
1132 }
1133
1134 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1135 {
1136         compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1137 }
1138
1139 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1140 {
1141         compose_toolbar_cb(A_LINEWRAP_ALL, data);
1142 }
1143
1144 #ifdef USE_ASPELL
1145 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1146 {
1147         compose_toolbar_cb(A_CHECK_SPELLING, data);
1148 }
1149 #endif
1150 /*
1151  * Execute actions from toolbar
1152  */
1153 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1154 {
1155         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1156         GSList *action_list;
1157         MainWindow *mainwin;
1158         Compose *compose;
1159         MessageView *msgview;
1160         gpointer parent = toolbar_item->parent;
1161
1162         g_return_if_fail(toolbar_item != NULL);
1163
1164         switch (toolbar_item->type) {
1165         case TOOLBAR_MAIN:
1166                 mainwin = (MainWindow*)parent;
1167                 action_list = mainwin->toolbar->action_list;
1168                 break;
1169         case TOOLBAR_COMPOSE:
1170                 compose = (Compose*)parent;
1171                 action_list = compose->toolbar->action_list;
1172                 break;
1173         case TOOLBAR_MSGVIEW:
1174                 msgview = (MessageView*)parent;
1175                 action_list = msgview->toolbar->action_list;
1176                 break;
1177         default:
1178                 debug_print("toolbar event not supported\n");
1179                 return;
1180         }
1181         toolbar_action_execute(widget, action_list, parent, toolbar_item->type);        
1182 }
1183
1184 static MainWindow *get_mainwin(gpointer data)
1185 {
1186         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1187         MainWindow *mainwin = NULL;
1188         MessageView *msgview;
1189
1190         g_return_val_if_fail(toolbar_item != NULL, NULL);
1191
1192         switch(toolbar_item->type) {
1193         case TOOLBAR_MAIN:
1194                 mainwin = (MainWindow*)toolbar_item->parent;
1195                 break;
1196         case TOOLBAR_MSGVIEW:
1197                 msgview = (MessageView*)toolbar_item->parent;
1198                 mainwin = (MainWindow*)msgview->mainwin;
1199                 break;
1200         default:
1201                 break;
1202         }
1203
1204         return mainwin;
1205 }
1206
1207 static void toolbar_buttons_cb(GtkWidget   *widget, 
1208                                ToolbarItem *item)
1209 {
1210         gint num_items;
1211         gint i;
1212         struct {
1213                 gint   index;
1214                 void (*func)(GtkWidget *widget, gpointer data);
1215         } callbacks[] = {
1216                 { A_RECEIVE_ALL,        toolbar_inc_all_cb              },
1217                 { A_RECEIVE_CUR,        toolbar_inc_cb                  },
1218                 { A_SEND_QUEUED,        toolbar_send_queued_cb          },
1219                 { A_COMPOSE_EMAIL,      toolbar_compose_cb              },
1220                 { A_COMPOSE_NEWS,       toolbar_compose_cb              },
1221                 { A_REPLY_MESSAGE,      toolbar_reply_cb                },
1222                 { A_REPLY_SENDER,       toolbar_reply_to_sender_cb      },
1223                 { A_REPLY_ALL,          toolbar_reply_to_all_cb         },
1224                 { A_REPLY_ML,           toolbar_reply_to_list_cb        },
1225                 { A_FORWARD,            toolbar_forward_cb              },
1226                 { A_DELETE,             toolbar_delete_cb               },
1227                 { A_EXECUTE,            toolbar_exec_cb                 },
1228                 { A_GOTO_NEXT,          toolbar_next_unread_cb          },
1229                 { A_IGNORE_THREAD,      toolbar_ignore_thread_cb        },
1230                 { A_PRINT,              toolbar_print_cb                },
1231
1232                 { A_SEND,               toolbar_send_cb                 },
1233                 { A_SENDL,              toolbar_send_later_cb           },
1234                 { A_DRAFT,              toolbar_draft_cb                },
1235                 { A_INSERT,             toolbar_insert_cb               },
1236                 { A_ATTACH,             toolbar_attach_cb               },
1237                 { A_SIG,                toolbar_sig_cb                  },
1238                 { A_EXTEDITOR,          toolbar_ext_editor_cb           },
1239                 { A_LINEWRAP_CURRENT,   toolbar_linewrap_current_cb     },
1240                 { A_LINEWRAP_ALL,       toolbar_linewrap_all_cb         },
1241                 { A_ADDRBOOK,           toolbar_addrbook_cb             },
1242 #ifdef USE_ASPELL
1243                 { A_CHECK_SPELLING,     toolbar_check_spelling_cb       },
1244 #endif
1245                 { A_SYL_ACTIONS,        toolbar_actions_execute_cb      }
1246         };
1247
1248         num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1249
1250         for (i = 0; i < num_items; i++) {
1251                 if (callbacks[i].index == item->index) {
1252                         callbacks[i].func(widget, item);
1253                         return;
1254                 }
1255         }
1256 }
1257
1258 /**
1259  * Create a new toolbar with specified type
1260  * if a callback list is passed it will be used before the 
1261  * common callback list
1262  **/
1263 Toolbar *toolbar_create(ToolbarType      type, 
1264                         GtkWidget       *container,
1265                         gpointer         data)
1266 {
1267         ToolbarItem *toolbar_item;
1268
1269         GtkWidget *toolbar;
1270         GtkWidget *icon_wid = NULL;
1271         GtkWidget *icon_news;
1272         GtkWidget *item;
1273         GtkWidget *item_news;
1274
1275         guint n_menu_entries;
1276         ComboButton *reply_combo;
1277         ComboButton *replyall_combo;
1278         ComboButton *replylist_combo;
1279         ComboButton *replysender_combo;
1280         ComboButton *fwd_combo;
1281
1282         GtkTooltips *toolbar_tips;
1283         ToolbarSylpheedActions *action_item;
1284         GSList *cur;
1285         GSList *toolbar_list;
1286         Toolbar *toolbar_data;
1287
1288         
1289         toolbar_tips = gtk_tooltips_new();
1290         
1291         toolbar_read_config_file(type);
1292         toolbar_list = toolbar_get_list(type);
1293
1294         toolbar_data = g_new0(Toolbar, 1); 
1295
1296         toolbar = gtk_toolbar_new();
1297         gtk_container_add(GTK_CONTAINER(container), toolbar);
1298         gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1299         gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1300         gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1301         
1302         for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1303
1304                 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1305                         gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1306                         continue;
1307                 }
1308                 
1309                 toolbar_item = g_new0(ToolbarItem, 1); 
1310                 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1311                 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1312                 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1313                 toolbar_item->parent = data;
1314                 toolbar_item->type = type;
1315
1316                 /* collect toolbar items in list to keep track */
1317                 toolbar_data->item_list = 
1318                         g_slist_append(toolbar_data->item_list, 
1319                                        toolbar_item);
1320
1321                 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1322                 item  = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1323                                                 toolbar_item->text,
1324                                                 (""),
1325                                                 (""),
1326                                                 icon_wid, G_CALLBACK(toolbar_buttons_cb), 
1327                                                 toolbar_item);
1328                 
1329                 switch (toolbar_item->index) {
1330
1331                 case A_RECEIVE_ALL:
1332                         toolbar_data->getall_btn = item;
1333                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1334                                              toolbar_data->getall_btn, 
1335                                            _("Receive Mail on all Accounts"), NULL);
1336                         break;
1337                 case A_RECEIVE_CUR:
1338                         toolbar_data->get_btn = item;
1339                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1340                                              toolbar_data->get_btn,
1341                                            _("Receive Mail on current Account"), NULL);
1342                         break;
1343                 case A_SEND_QUEUED:
1344                         toolbar_data->send_btn = item; 
1345                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1346                                              toolbar_data->send_btn,
1347                                            _("Send Queued Messages"), NULL);
1348                         break;
1349                 case A_COMPOSE_EMAIL:
1350                         icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1351                         item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1352                                                             _("News"),
1353                                                             (""),
1354                                                             (""),
1355                                                             icon_news, G_CALLBACK(toolbar_buttons_cb), 
1356                                                             toolbar_item);
1357                         toolbar_data->compose_mail_btn = item; 
1358                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1359                                              toolbar_data->compose_mail_btn,
1360                                            _("Compose Email"), NULL);
1361                         toolbar_data->compose_news_btn = item_news;
1362                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1363                                              toolbar_data->compose_news_btn,
1364                                            _("Compose News"), NULL);
1365                         break;
1366                 case A_REPLY_MESSAGE:
1367                         toolbar_data->reply_btn = item;
1368                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1369                                              toolbar_data->reply_btn,
1370                                            _("Reply to Message"), NULL);
1371                         n_menu_entries = sizeof(reply_entries) / 
1372                                 sizeof(reply_entries[0]);
1373                         reply_combo = gtkut_combo_button_create(toolbar_data->reply_btn,
1374                                               reply_entries, n_menu_entries,
1375                                               "<Reply>", (gpointer)toolbar_item);
1376                         gtk_button_set_relief(GTK_BUTTON(reply_combo->arrow),
1377                                               GTK_RELIEF_NONE);
1378                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1379                                                   GTK_WIDGET_PTR(reply_combo),
1380                                                   _("Reply to Message"), "Reply");
1381                         toolbar_data->reply_combo = reply_combo;
1382                         break;
1383                 case A_REPLY_SENDER:
1384                         toolbar_data->replysender_btn = item;
1385                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1386                                              toolbar_data->replysender_btn,
1387                                            _("Reply to Sender"), NULL);
1388                         n_menu_entries = sizeof(replysender_entries) / 
1389                                 sizeof(replysender_entries[0]);
1390                         replysender_combo = gtkut_combo_button_create(toolbar_data->replysender_btn,
1391                                               replysender_entries, n_menu_entries,
1392                                               "<ReplySender>", (gpointer)toolbar_item);
1393                         gtk_button_set_relief(GTK_BUTTON(replysender_combo->arrow),
1394                                               GTK_RELIEF_NONE);
1395                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1396                                                   GTK_WIDGET_PTR(replysender_combo),
1397                                                   _("Reply to Sender"), "ReplySender");
1398                         toolbar_data->replysender_combo = replysender_combo;
1399                         break;
1400                 case A_REPLY_ALL:
1401                         toolbar_data->replyall_btn = item;
1402                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1403                                              toolbar_data->replyall_btn,
1404                                            _("Reply to All"), NULL);
1405                         n_menu_entries = sizeof(replyall_entries) / 
1406                                 sizeof(replyall_entries[0]);
1407                         replyall_combo = gtkut_combo_button_create(toolbar_data->replyall_btn,
1408                                               replyall_entries, n_menu_entries,
1409                                               "<ReplyAll>", (gpointer)toolbar_item);
1410                         gtk_button_set_relief(GTK_BUTTON(replyall_combo->arrow),
1411                                               GTK_RELIEF_NONE);
1412                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1413                                                   GTK_WIDGET_PTR(replyall_combo),
1414                                                   _("Reply to All"), "ReplyAll");
1415                         toolbar_data->replyall_combo = replyall_combo;
1416                         break;
1417                 case A_REPLY_ML:
1418                         toolbar_data->replylist_btn = item;
1419                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1420                                              toolbar_data->replylist_btn,
1421                                            _("Reply to Mailing-list"), NULL);
1422                         n_menu_entries = sizeof(replylist_entries) / 
1423                                 sizeof(replylist_entries[0]);
1424                         replylist_combo = gtkut_combo_button_create(toolbar_data->replylist_btn,
1425                                               replylist_entries, n_menu_entries,
1426                                               "<ReplyList>", (gpointer)toolbar_item);
1427                         gtk_button_set_relief(GTK_BUTTON(replylist_combo->arrow),
1428                                               GTK_RELIEF_NONE);
1429                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1430                                                   GTK_WIDGET_PTR(replylist_combo),
1431                                                   _("Reply to Mailing-list"), "ReplyList");
1432                         toolbar_data->replylist_combo = replylist_combo;
1433                         break;
1434                 case A_FORWARD:
1435                         toolbar_data->fwd_btn = item;
1436                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1437                                              toolbar_data->fwd_btn,
1438                                              _("Forward Message"), NULL);
1439                         n_menu_entries = sizeof(forward_entries) / 
1440                                 sizeof(forward_entries[0]);
1441                         fwd_combo = gtkut_combo_button_create(toolbar_data->fwd_btn,
1442                                               forward_entries, n_menu_entries,
1443                                               "<Forward>", (gpointer)toolbar_item);
1444                         gtk_button_set_relief(GTK_BUTTON(fwd_combo->arrow),
1445                                               GTK_RELIEF_NONE);
1446                         gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1447                                                   GTK_WIDGET_PTR(fwd_combo),
1448                                                   _("Forward Message"), "Fwd");
1449                         toolbar_data->fwd_combo = fwd_combo;
1450                         break;
1451                 case A_DELETE:
1452                         toolbar_data->delete_btn = item;
1453                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1454                                              toolbar_data->delete_btn,
1455                                              _("Delete Message"), NULL);
1456                         break;
1457                 case A_EXECUTE:
1458                         toolbar_data->exec_btn = item;
1459                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1460                                              toolbar_data->exec_btn,
1461                                            _("Execute"), NULL);
1462                         break;
1463                 case A_GOTO_NEXT:
1464                         toolbar_data->next_btn = item;
1465                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1466                                              toolbar_data->next_btn,
1467                                              _("Goto Next Message"), NULL);
1468                         break;
1469                 
1470                 /* Compose Toolbar */
1471                 case A_SEND:
1472                         toolbar_data->send_btn = item;
1473                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1474                                              toolbar_data->send_btn, 
1475                                              _("Send Message"), NULL);
1476                         break;
1477                 case A_SENDL:
1478                         toolbar_data->sendl_btn = item;
1479                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1480                                              toolbar_data->sendl_btn,
1481                                              _("Put into queue folder and send later"), NULL);
1482                         break;
1483                 case A_DRAFT:
1484                         toolbar_data->draft_btn = item; 
1485                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1486                                              toolbar_data->draft_btn,
1487                                              _("Save to draft folder"), NULL);
1488                         break;
1489                 case A_INSERT:
1490                         toolbar_data->insert_btn = item; 
1491                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1492                                              toolbar_data->insert_btn,
1493                                              _("Insert file"), NULL);
1494                         break;
1495                 case A_ATTACH:
1496                         toolbar_data->attach_btn = item;
1497                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1498                                              toolbar_data->attach_btn,
1499                                              _("Attach file"), NULL);
1500                         break;
1501                 case A_SIG:
1502                         toolbar_data->sig_btn = item;
1503                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1504                                              toolbar_data->sig_btn,
1505                                              _("Insert signature"), NULL);
1506                         break;
1507                 case A_EXTEDITOR:
1508                         toolbar_data->exteditor_btn = item;
1509                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1510                                              toolbar_data->exteditor_btn,
1511                                              _("Edit with external editor"), NULL);
1512                         break;
1513                 case A_LINEWRAP_CURRENT:
1514                         toolbar_data->linewrap_current_btn = item;
1515                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1516                                              toolbar_data->linewrap_current_btn,
1517                                              _("Wrap long lines of current paragraph"), NULL);
1518                         break;
1519                 case A_LINEWRAP_ALL:
1520                         toolbar_data->linewrap_all_btn = item;
1521                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1522                                              toolbar_data->linewrap_all_btn,
1523                                              _("Wrap all long lines"), NULL);
1524                         break;
1525                 case A_ADDRBOOK:
1526                         toolbar_data->addrbook_btn = item;
1527                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1528                                              toolbar_data->addrbook_btn,
1529                                              _("Address book"), NULL);
1530                         break;
1531 #ifdef USE_ASPELL
1532                 case A_CHECK_SPELLING:
1533                         toolbar_data->spellcheck_btn = item;
1534                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1535                                              toolbar_data->spellcheck_btn,
1536                                              _("Check spelling"), NULL);
1537                         break;
1538 #endif
1539
1540                 case A_SYL_ACTIONS:
1541                         action_item = g_new0(ToolbarSylpheedActions, 1);
1542                         action_item->widget = item;
1543                         action_item->name   = g_strdup(toolbar_item->text);
1544
1545                         toolbar_data->action_list = 
1546                                 g_slist_append(toolbar_data->action_list,
1547                                                action_item);
1548
1549                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips), 
1550                                              item,
1551                                              action_item->name, NULL);
1552
1553                         gtk_widget_show(item);
1554                         break;
1555                 default:
1556                         /* find and set the tool tip text */
1557                         gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1558                                              item,
1559                                              toolbar_ret_descr_from_val
1560                                                 (toolbar_item->index),
1561                                              NULL);
1562                         break;
1563                 }
1564
1565         }
1566         toolbar_data->toolbar = toolbar;
1567         if (type == TOOLBAR_MAIN)
1568                 activate_compose_button(toolbar_data, 
1569                                         prefs_common.toolbar_style, 
1570                                         toolbar_data->compose_btn_type);
1571         
1572         gtk_widget_show_all(toolbar);
1573         
1574         return toolbar_data; 
1575 }
1576
1577 /**
1578  * Free toolbar structures
1579  */ 
1580 void toolbar_destroy(Toolbar * toolbar) {
1581
1582         TOOLBAR_DESTROY_ITEMS(toolbar->item_list);      
1583         TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1584 }
1585
1586 void toolbar_update(ToolbarType type, gpointer data)
1587 {
1588         Toolbar *toolbar_data;
1589         GtkWidget *handlebox;
1590         MainWindow *mainwin = (MainWindow*)data;
1591         Compose    *compose = (Compose*)data;
1592         MessageView *msgview = (MessageView*)data;
1593
1594         switch(type) {
1595         case TOOLBAR_MAIN:
1596                 toolbar_data = mainwin->toolbar;
1597                 handlebox    = mainwin->handlebox;
1598                 break;
1599         case TOOLBAR_COMPOSE:
1600                 toolbar_data = compose->toolbar;
1601                 handlebox    = compose->handlebox;
1602                 break;
1603         case TOOLBAR_MSGVIEW:
1604                 toolbar_data = msgview->toolbar;
1605                 handlebox    = msgview->handlebox;
1606                 break;
1607         default:
1608                 return;
1609         }
1610
1611         gtk_container_remove(GTK_CONTAINER(handlebox), 
1612                              GTK_WIDGET(toolbar_data->toolbar));
1613
1614         toolbar_init(toolbar_data);
1615         toolbar_data = toolbar_create(type, handlebox, data);
1616         switch(type) {
1617         case TOOLBAR_MAIN:
1618                 mainwin->toolbar = toolbar_data;
1619                 break;
1620         case TOOLBAR_COMPOSE:
1621                 compose->toolbar = toolbar_data;
1622                 break;
1623         case TOOLBAR_MSGVIEW:
1624                 msgview->toolbar = toolbar_data;
1625                 break;
1626         }
1627
1628         toolbar_style(type, prefs_common.toolbar_style, data);
1629
1630         if (type == TOOLBAR_MAIN)
1631                 toolbar_main_set_sensitive((MainWindow*)data);
1632 }
1633
1634 void toolbar_main_set_sensitive(gpointer data)
1635 {
1636         SensitiveCond state;
1637         gboolean sensitive;
1638         MainWindow *mainwin = (MainWindow*)data;
1639         Toolbar *toolbar = mainwin->toolbar;
1640         GSList *cur;
1641         GSList *entry_list = NULL;
1642         
1643         typedef struct _Entry Entry;
1644         struct _Entry {
1645                 GtkWidget *widget;
1646                 SensitiveCond cond;
1647                 gboolean empty;
1648         };
1649
1650 #define SET_WIDGET_COND(w, c)     \
1651 { \
1652         Entry *e = g_new0(Entry, 1); \
1653         e->widget = w; \
1654         e->cond   = c; \
1655         entry_list = g_slist_append(entry_list, e); \
1656 }
1657
1658         SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1659         SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1660         SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1661         SET_WIDGET_COND(toolbar->reply_btn,
1662                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1663         if (toolbar->reply_btn)
1664                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->reply_combo),
1665                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1666         SET_WIDGET_COND(toolbar->replyall_btn,
1667                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1668         if (toolbar->replyall_btn)
1669                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replyall_combo),
1670                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1671         SET_WIDGET_COND(toolbar->replylist_btn,
1672                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1673         if (toolbar->replylist_btn) 
1674                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replylist_combo),
1675                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1676         SET_WIDGET_COND(toolbar->replysender_btn,
1677                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1678         if (toolbar->replysender_btn)
1679                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replysender_combo),
1680                         M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1681         SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1682         if (toolbar->fwd_btn)
1683                 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->fwd_combo),
1684                         M_HAVE_ACCOUNT|M_TARGET_EXIST); 
1685         if (toolbar->fwd_combo) {
1686                 GtkWidget *submenu = gtk_item_factory_get_widget(toolbar->fwd_combo->factory, "/Redirect");
1687                 SET_WIDGET_COND(submenu, M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST); 
1688         }
1689
1690         if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
1691                 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1692         } else {
1693                 SET_WIDGET_COND(toolbar->next_btn, 0);
1694         }
1695
1696         SET_WIDGET_COND(toolbar->delete_btn,
1697                         M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1698         SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1699
1700         for (cur = toolbar->action_list; cur != NULL;  cur = cur->next) {
1701                 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1702                 
1703                 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1704         }
1705
1706 #undef SET_WIDGET_COND
1707
1708         state = main_window_get_current_state(mainwin);
1709
1710         for (cur = entry_list; cur != NULL; cur = cur->next) {
1711                 Entry *e = (Entry*) cur->data;
1712
1713                 if (e->widget != NULL) {
1714                         sensitive = ((e->cond & state) == e->cond);
1715                         gtk_widget_set_sensitive(e->widget, sensitive); 
1716                 }
1717         }
1718         
1719         while (entry_list != NULL) {
1720                 Entry *e = (Entry*) entry_list->data;
1721
1722                 if (e)
1723                         g_free(e);
1724                 entry_list = g_slist_remove(entry_list, e);
1725         }
1726
1727         g_slist_free(entry_list);
1728
1729         activate_compose_button(toolbar, 
1730                                 prefs_common.toolbar_style,
1731                                 toolbar->compose_btn_type);
1732 }
1733
1734 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1735 {
1736         Compose *compose = (Compose*)data;
1737         GSList *items = compose->toolbar->action_list;
1738
1739         if (compose->toolbar->send_btn)
1740                 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1741         if (compose->toolbar->sendl_btn)
1742                 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1743         if (compose->toolbar->draft_btn )
1744                 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1745         if (compose->toolbar->insert_btn )
1746                 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1747         if (compose->toolbar->attach_btn)
1748                 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1749         if (compose->toolbar->sig_btn)
1750                 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1751         if (compose->toolbar->exteditor_btn)
1752                 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1753         if (compose->toolbar->linewrap_current_btn)
1754                 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
1755         if (compose->toolbar->linewrap_all_btn)
1756                 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
1757         if (compose->toolbar->addrbook_btn)
1758                 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1759 #ifdef USE_ASPELL
1760         if (compose->toolbar->spellcheck_btn)
1761                 gtk_widget_set_sensitive(compose->toolbar->spellcheck_btn, sensitive);
1762 #endif
1763         for (; items != NULL; items = g_slist_next(items)) {
1764                 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1765                 gtk_widget_set_sensitive(item->widget, sensitive);
1766         }
1767 }
1768
1769 /**
1770  * Initialize toolbar structure
1771  **/
1772 void toolbar_init(Toolbar * toolbar) {
1773
1774         toolbar->toolbar                = NULL;
1775         toolbar->get_btn                = NULL;
1776         toolbar->getall_btn             = NULL;
1777         toolbar->send_btn               = NULL;
1778         toolbar->compose_mail_btn       = NULL;
1779         toolbar->compose_news_btn       = NULL;
1780         toolbar->reply_btn              = NULL;
1781         toolbar->replysender_btn        = NULL;
1782         toolbar->replyall_btn           = NULL;
1783         toolbar->replylist_btn          = NULL;
1784         toolbar->fwd_btn                = NULL;
1785         toolbar->delete_btn             = NULL;
1786         toolbar->next_btn               = NULL;
1787         toolbar->exec_btn               = NULL;
1788
1789         /* compose buttons */ 
1790         toolbar->sendl_btn              = NULL;
1791         toolbar->draft_btn              = NULL;
1792         toolbar->insert_btn             = NULL;
1793         toolbar->attach_btn             = NULL;
1794         toolbar->sig_btn                = NULL; 
1795         toolbar->exteditor_btn          = NULL; 
1796         toolbar->linewrap_current_btn   = NULL; 
1797         toolbar->linewrap_all_btn       = NULL; 
1798         toolbar->addrbook_btn           = NULL; 
1799 #ifdef USE_ASPELL
1800         toolbar->spellcheck_btn         = NULL;
1801 #endif
1802
1803         toolbar_destroy(toolbar);
1804 }
1805
1806 /*
1807  */
1808 static void toolbar_reply(gpointer data, guint action)
1809 {
1810         ToolbarItem *toolbar_item = (ToolbarItem*)data;
1811         MainWindow *mainwin;
1812         MessageView *msgview;
1813         GSList *msginfo_list = NULL;
1814
1815         g_return_if_fail(toolbar_item != NULL);
1816
1817         switch (toolbar_item->type) {
1818         case TOOLBAR_MAIN:
1819                 mainwin = (MainWindow*)toolbar_item->parent;
1820                 msginfo_list = summary_get_selection(mainwin->summaryview);
1821                 msgview = (MessageView*)mainwin->messageview;
1822                 break;
1823         case TOOLBAR_MSGVIEW:
1824                 msgview = (MessageView*)toolbar_item->parent;
1825                 g_return_if_fail(msgview != NULL);      
1826                 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
1827                 break;
1828         default:
1829                 return;
1830         }
1831
1832         g_return_if_fail(msgview != NULL);
1833         g_return_if_fail(msginfo_list != NULL);
1834         compose_reply_from_messageview(msgview, msginfo_list, action);
1835         g_slist_free(msginfo_list);
1836
1837         /* TODO: update reply state ion summaryview */
1838 }
1839
1840
1841 /* exported functions */
1842
1843 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
1844 {
1845         MainWindow *mainwin = (MainWindow*)data;
1846
1847         inc_mail(mainwin, prefs_common.newmail_notify_manu);
1848 }
1849
1850 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
1851 {
1852         MainWindow *mainwin = (MainWindow*)data;
1853
1854         inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
1855 }
1856
1857 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
1858 {
1859         GList *list;
1860
1861         if (prefs_common.work_offline)
1862                 if (alertpanel(_("Offline warning"), 
1863                                _("You're working offline. Override?"),
1864                                _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1865                 return;
1866
1867         for (list = folder_get_list(); list != NULL; list = list->next) {
1868                 Folder *folder = list->data;
1869
1870                 if (folder->queue) {
1871                         if (procmsg_send_queue(folder->queue, 
1872                                                prefs_common.savemsg) < 0)
1873                                 alertpanel_error(_("Some errors occurred while "
1874                                                    "sending queued messages."));
1875                         folder_item_scan(folder->queue);
1876                 }
1877         }
1878 }
1879
1880 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
1881 {
1882         MainWindow *mainwin = (MainWindow*)data;
1883         PrefsAccount *ac = NULL;
1884         FolderItem *item = mainwin->summaryview->folder_item;   
1885         GList * list;
1886         GList * cur;
1887
1888         if (item) {
1889                 ac = account_find_from_item(item);
1890                 if (ac && ac->protocol != A_NNTP) {
1891                         compose_new_with_folderitem(ac, item);          /* CLAWS */
1892                         return;
1893                 }
1894         }
1895
1896         /*
1897          * CLAWS - use current account
1898          */
1899         if (cur_account && (cur_account->protocol != A_NNTP)) {
1900                 compose_new_with_folderitem(cur_account, item);
1901                 return;
1902         }
1903
1904         /*
1905          * CLAWS - just get the first one
1906          */
1907         list = account_get_list();
1908         for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
1909                 ac = (PrefsAccount *) cur->data;
1910                 if (ac->protocol != A_NNTP) {
1911                         compose_new_with_folderitem(ac, item);
1912                         return;
1913                 }
1914         }
1915 }
1916
1917 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
1918 {
1919         MainWindow *mainwin = (MainWindow*)data;
1920         PrefsAccount * ac = NULL;
1921         GList * list;
1922         GList * cur;
1923
1924         if (mainwin->summaryview->folder_item) {
1925                 ac = mainwin->summaryview->folder_item->folder->account;
1926                 if (ac && ac->protocol == A_NNTP) {
1927                         compose_new(ac,
1928                                     mainwin->summaryview->folder_item->path,
1929                                     NULL);
1930                         return;
1931                 }
1932         }
1933
1934         list = account_get_list();
1935         for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
1936                 ac = (PrefsAccount *) cur->data;
1937                 if (ac->protocol == A_NNTP) {
1938                         compose_new(ac, NULL, NULL);
1939                         return;
1940                 }
1941         }
1942 }