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