2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2007 Hiroyuki Yamamoto and the Claws Mail team
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * General functions for accessing address book files.
31 #include <glib/gi18n.h>
40 #include "mainwindow.h"
41 #include "summaryview.h"
46 #include "prefs_gtk.h"
48 #include "stock_pixmap.h"
49 #include "manage_window.h"
55 #include "prefs_actions.h"
56 #include "prefs_common.h"
57 #include "prefs_toolbar.h"
58 #include "alertpanel.h"
62 #define TOOLBAR_TAG_INDEX "toolbar"
63 #define TOOLBAR_TAG_ITEM "item"
64 #define TOOLBAR_TAG_SEPARATOR "separator"
66 #define TOOLBAR_ICON_FILE "file"
67 #define TOOLBAR_ICON_TEXT "text"
68 #define TOOLBAR_ICON_ACTION "action"
70 static gboolean toolbar_is_duplicate (gint action,
72 static void toolbar_parse_item (XMLFile *file,
75 static gint toolbar_ret_val_from_text (const gchar *text);
76 static gchar *toolbar_ret_text_from_val (gint val);
78 static void toolbar_set_default_main (void);
79 static void toolbar_set_default_compose (void);
80 static void toolbar_set_default_msgview (void);
82 static void toolbar_style (ToolbarType type,
86 static MainWindow *get_mainwin (gpointer data);
87 static void activate_compose_button (Toolbar *toolbar,
89 ComposeButtonType type);
91 /* toolbar callbacks */
92 static void toolbar_reply (gpointer data,
94 static void toolbar_learn (gpointer data,
96 static void toolbar_delete_cb (GtkWidget *widget,
98 static void toolbar_trash_cb (GtkWidget *widget,
101 static void toolbar_compose_cb (GtkWidget *widget,
104 static void toolbar_learn_cb (GtkWidget *widget,
107 static void toolbar_reply_cb (GtkWidget *widget,
110 static void toolbar_reply_to_all_cb (GtkWidget *widget,
113 static void toolbar_reply_to_list_cb (GtkWidget *widget,
116 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
119 static void toolbar_forward_cb (GtkWidget *widget,
122 static void toolbar_prev_unread_cb (GtkWidget *widget,
124 static void toolbar_next_unread_cb (GtkWidget *widget,
127 static void toolbar_ignore_thread_cb (GtkWidget *widget,
130 static void toolbar_print_cb (GtkWidget *widget,
133 static void toolbar_actions_execute_cb (GtkWidget *widget,
137 static void toolbar_send_cb (GtkWidget *widget,
139 static void toolbar_send_later_cb (GtkWidget *widget,
141 static void toolbar_draft_cb (GtkWidget *widget,
143 static void toolbar_close_cb (GtkWidget *widget,
145 static void toolbar_open_mail_cb (GtkWidget *widget,
147 static void toolbar_insert_cb (GtkWidget *widget,
149 static void toolbar_attach_cb (GtkWidget *widget,
151 static void toolbar_sig_cb (GtkWidget *widget,
153 static void toolbar_ext_editor_cb (GtkWidget *widget,
155 static void toolbar_linewrap_current_cb (GtkWidget *widget,
157 static void toolbar_linewrap_all_cb (GtkWidget *widget,
159 static void toolbar_addrbook_cb (GtkWidget *widget,
162 static void toolbar_check_spelling_cb (GtkWidget *widget,
165 static void toolbar_cancel_inc_cb (GtkWidget *widget,
171 } toolbar_text [] = {
172 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
173 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
174 { "A_SEND_QUEUED", N_("Send Queued Messages") },
175 { "A_COMPOSE_EMAIL", N_("Compose Email") },
176 { "A_COMPOSE_NEWS", N_("Compose News") },
177 { "A_REPLY_MESSAGE", N_("Reply to Message") },
178 { "A_REPLY_SENDER", N_("Reply to Sender") },
179 { "A_REPLY_ALL", N_("Reply to All") },
180 { "A_REPLY_ML", N_("Reply to Mailing-list") },
181 { "A_OPEN_MAIL", N_("Open email") },
182 { "A_FORWARD", N_("Forward Message") },
183 { "A_TRASH", N_("Trash Message") },
184 { "A_DELETE_REAL", N_("Delete Message") },
185 { "A_EXECUTE", N_("Execute") },
186 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
187 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
188 { "A_IGNORE_THREAD", N_("Ignore thread") },
189 { "A_PRINT", N_("Print") },
190 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
191 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
193 { "A_SEND", N_("Send Message") },
194 { "A_SENDL", N_("Put into queue folder and send later") },
195 { "A_DRAFT", N_("Save to draft folder") },
196 { "A_INSERT", N_("Insert file") },
197 { "A_ATTACH", N_("Attach file") },
198 { "A_SIG", N_("Insert signature") },
199 { "A_EXTEDITOR", N_("Edit with external editor") },
200 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
201 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
202 { "A_ADDRBOOK", N_("Address book") },
204 { "A_CHECK_SPELLING", N_("Check spelling") },
206 { "A_SYL_ACTIONS", N_("Claws Mail Actions Feature") },
207 { "A_CANCEL_INC", N_("Cancel receiving") },
208 { "A_CLOSE", N_("Close window") },
209 { "A_SEPARATOR", "Separator" }
212 /* struct holds configuration files and a list of
213 * currently active toolbar items
214 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
218 const gchar *conf_file;
220 } toolbar_config[3] = {
221 { "toolbar_main.xml", NULL},
222 { "toolbar_compose.xml", NULL},
223 { "toolbar_msgview.xml", NULL}
226 static GtkItemFactoryEntry reply_entries[] =
228 {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
229 {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
231 static GtkItemFactoryEntry replyall_entries[] =
233 {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
234 {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
236 static GtkItemFactoryEntry replylist_entries[] =
238 {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
239 {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
241 static GtkItemFactoryEntry replysender_entries[] =
243 {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
244 {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
246 static GtkItemFactoryEntry forward_entries[] =
248 {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
249 {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
250 {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, NULL}
252 static GtkItemFactoryEntry learn_entries[] =
254 {N_("/Learn as _Spam"), NULL, toolbar_learn, TRUE, NULL},
255 {N_("/Learn as _Ham"), NULL, toolbar_learn, FALSE, NULL}
259 gint toolbar_ret_val_from_descr(const gchar *descr)
263 for (i = 0; i < N_ACTION_VAL; i++) {
264 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
271 gchar *toolbar_ret_descr_from_val(gint val)
273 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
275 return gettext(toolbar_text[val].descr);
278 static gint toolbar_ret_val_from_text(const gchar *text)
282 for (i = 0; i < N_ACTION_VAL; i++) {
283 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
290 static gchar *toolbar_ret_text_from_val(gint val)
292 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
294 return toolbar_text[val].index_str;
297 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
301 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
304 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
305 ToolbarItem *item = (ToolbarItem*) cur->data;
307 if (item->index == action)
313 /* depending on toolbar type this function
314 returns a list of available toolbar events being
315 displayed by prefs_toolbar
317 GList *toolbar_get_action_items(ToolbarType source)
322 if (source == TOOLBAR_MAIN) {
323 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
324 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
325 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
326 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
327 A_GOTO_NEXT, A_IGNORE_THREAD, A_PRINT,
328 A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
329 A_SYL_ACTIONS, A_CANCEL_INC };
331 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
332 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
335 else if (source == TOOLBAR_COMPOSE) {
336 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
337 A_INSERT, A_ATTACH, A_SIG,
338 A_EXTEDITOR, A_LINEWRAP_CURRENT,
339 A_LINEWRAP_ALL, A_ADDRBOOK,
343 A_SYL_ACTIONS, A_CLOSE };
345 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
346 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
348 else if (source == TOOLBAR_MSGVIEW) {
349 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
350 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
351 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
352 A_ADDRBOOK, A_LEARN_SPAM, A_SYL_ACTIONS, A_CLOSE };
354 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
355 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
361 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
365 ToolbarItem *item = NULL;
366 gboolean rewrite = FALSE;
368 attr = xml_get_current_tag_attr(file);
369 item = g_new0(ToolbarItem, 1);
371 name = ((XMLAttr *)attr->data)->name;
372 value = ((XMLAttr *)attr->data)->value;
374 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
375 item->file = g_strdup (value);
376 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
377 item->text = g_strdup (gettext(value));
378 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
379 item->index = toolbar_ret_val_from_text(value);
380 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
382 item->index = A_TRASH;
384 item->file = g_strdup("trash_btn");
386 item->text = g_strdup(_("Trash"));
389 attr = g_list_next(attr);
391 if (item->index != -1) {
393 if (!toolbar_is_duplicate(item->index, source))
394 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
398 toolbar_save_config_file(source);
402 static void toolbar_set_default_main(void)
408 } default_toolbar[] = {
410 { A_GO_FOLDERS, STOCK_PIXMAP_DIR_OPEN, _("Folders") },
411 { A_SEPARATOR, 0, ("") },
413 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get Mail")},
414 { A_SEPARATOR, 0, ("") },
415 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
416 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE,
417 (gchar*)Q_("Toolbar|Compose") },
418 { A_SEPARATOR, 0, ("") },
420 { A_OPEN_MAIL, STOCK_PIXMAP_OPEN_MAIL, _("Open") },
422 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
424 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
425 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
427 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
428 { A_SEPARATOR, 0, ("") },
429 { A_TRASH, STOCK_PIXMAP_TRASH, _("Trash") },
430 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
431 { A_LEARN_SPAM, STOCK_PIXMAP_SPAM_BTN, _("Spam") },
433 { A_SEPARATOR, 0, ("") },
434 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
439 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
441 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
443 if (default_toolbar[i].action != A_SEPARATOR) {
445 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
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);
452 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
453 toolbar_item->index = A_SEPARATOR;
456 if (toolbar_item->index != -1) {
457 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
458 toolbar_config[TOOLBAR_MAIN].item_list =
459 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
464 static void toolbar_set_default_compose(void)
470 } default_toolbar[] = {
471 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
472 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
473 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
474 { A_SEPARATOR, 0, ("") },
476 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
478 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
479 { A_SEPARATOR, 0, ("") },
480 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
483 { A_SEPARATOR, 0, ("") },
484 { A_CLOSE, STOCK_PIXMAP_CLOSE, _("Close") }
490 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
492 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
494 if (default_toolbar[i].action != A_SEPARATOR) {
496 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
498 toolbar_item->file = g_strdup(file);
499 toolbar_item->index = default_toolbar[i].action;
500 toolbar_item->text = g_strdup(default_toolbar[i].text);
503 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
504 toolbar_item->index = A_SEPARATOR;
507 if (toolbar_item->index != -1) {
508 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
509 toolbar_config[TOOLBAR_COMPOSE].item_list =
510 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
515 static void toolbar_set_default_msgview(void)
521 } default_toolbar[] = {
522 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
523 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
524 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
525 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
526 { A_SEPARATOR, 0, ("") },
527 { A_TRASH, STOCK_PIXMAP_TRASH, _("Trash") },
528 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
529 { A_LEARN_SPAM, STOCK_PIXMAP_SPAM_BTN, _("Spam") },
531 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
534 { A_SEPARATOR, 0, ("") },
535 { A_CLOSE, STOCK_PIXMAP_CLOSE, _("Close") }
541 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
543 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
545 if (default_toolbar[i].action != A_SEPARATOR) {
547 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
549 toolbar_item->file = g_strdup(file);
550 toolbar_item->index = default_toolbar[i].action;
551 toolbar_item->text = g_strdup(default_toolbar[i].text);
554 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
555 toolbar_item->index = A_SEPARATOR;
558 if (toolbar_item->index != -1) {
559 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
560 toolbar_config[TOOLBAR_MSGVIEW].item_list =
561 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
566 void toolbar_set_default(ToolbarType source)
568 if (source == TOOLBAR_MAIN)
569 toolbar_set_default_main();
570 else if (source == TOOLBAR_COMPOSE)
571 toolbar_set_default_compose();
572 else if (source == TOOLBAR_MSGVIEW)
573 toolbar_set_default_msgview();
576 void toolbar_save_config_file(ToolbarType source)
581 gchar *fileSpec = NULL;
583 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
585 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
586 pfile = prefs_write_open(fileSpec);
590 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL);
592 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
594 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
595 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
597 if (toolbar_item->index != A_SEPARATOR) {
598 fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
600 TOOLBAR_ICON_FILE, toolbar_item->file,
602 xml_file_put_escape_str(fp, toolbar_item->text);
603 fprintf(fp, "\" %s=\"%s\"/>\n",
605 toolbar_ret_text_from_val(toolbar_item->index));
607 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
611 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
613 if (prefs_file_close (pfile) < 0 )
614 g_warning("failed to write toolbar configuration to file\n");
616 g_warning("failed to open toolbar configuration file for writing\n");
619 void toolbar_read_config_file(ToolbarType source)
621 XMLFile *file = NULL;
622 gchar *fileSpec = NULL;
627 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
629 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
630 file = xml_open_file(fileSpec);
633 toolbar_clear_list(source);
637 || (xml_get_dtd(file))
638 || (xml_parse_next_tag(file))
639 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
640 xml_close_file(file);
644 attr = xml_get_current_tag_attr(file);
651 if (xml_parse_next_tag(file))
654 /* Get next tag (icon, icon_text or icon_action) */
655 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
656 toolbar_parse_item(file, source);
657 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
658 ToolbarItem *item = g_new0(ToolbarItem, 1);
660 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
661 item->index = A_SEPARATOR;
662 toolbar_config[source].item_list =
663 g_slist_append(toolbar_config[source].item_list, item);
667 xml_close_file(file);
670 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
672 if (source == TOOLBAR_MAIN)
673 toolbar_set_default(TOOLBAR_MAIN);
674 else if (source == TOOLBAR_COMPOSE)
675 toolbar_set_default(TOOLBAR_COMPOSE);
676 else if (source == TOOLBAR_MSGVIEW)
677 toolbar_set_default(TOOLBAR_MSGVIEW);
679 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
683 toolbar_save_config_file(source);
688 * clears list of toolbar items read from configuration files
690 void toolbar_clear_list(ToolbarType source)
692 while (toolbar_config[source].item_list != NULL) {
693 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
695 toolbar_config[source].item_list =
696 g_slist_remove(toolbar_config[source].item_list, item);
702 g_slist_free(toolbar_config[source].item_list);
707 * return list of Toolbar items
709 GSList *toolbar_get_list(ToolbarType source)
713 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
714 list = toolbar_config[source].item_list;
719 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
721 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
723 toolbar_item->file = g_strdup(t_item->file);
724 toolbar_item->text = g_strdup(t_item->text);
725 toolbar_item->index = t_item->index;
727 toolbar_config[source].item_list =
728 g_slist_append(toolbar_config[source].item_list,
732 void toolbar_action_execute(GtkWidget *widget,
738 gchar *action, *action_p;
739 gboolean found = FALSE;
742 for (cur = action_list; cur != NULL; cur = cur->next) {
743 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
745 if (widget == act->widget) {
747 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
748 action = g_strdup((gchar*)lop->data);
750 action_p = strstr(action, ": ");
752 if (g_utf8_collate(act->name, action) == 0) {
766 actions_execute(data, i, widget, source);
768 g_warning ("Error: did not find Claws Action to execute");
771 static void activate_compose_button (Toolbar *toolbar,
773 ComposeButtonType type)
775 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
778 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
779 : toolbar->compose_news_btn);
780 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
781 : toolbar->compose_mail_btn);
782 toolbar->compose_btn_type = type;
785 void toolbar_set_compose_button(Toolbar *toolbar,
786 ComposeButtonType compose_btn_type)
788 if (toolbar->compose_btn_type != compose_btn_type)
789 activate_compose_button(toolbar,
790 prefs_common.toolbar_style,
794 static void activate_learn_button (Toolbar *toolbar,
796 LearnButtonType type)
798 if ((!toolbar->learn_spam_btn) || (!toolbar->learn_ham_btn))
801 gtk_widget_hide(type == LEARN_SPAM ? toolbar->learn_ham_btn
802 : toolbar->learn_spam_btn);
803 gtk_widget_show(type == LEARN_SPAM ? toolbar->learn_spam_btn
804 : toolbar->learn_ham_btn);
805 toolbar->learn_btn_type = type;
808 void toolbar_set_learn_button(Toolbar *toolbar,
809 LearnButtonType learn_btn_type)
811 if (toolbar->learn_btn_type != learn_btn_type)
812 activate_learn_button(toolbar,
813 prefs_common.toolbar_style,
817 void toolbar_toggle(guint action, gpointer data)
819 MainWindow *mainwin = (MainWindow*)data;
823 g_return_if_fail(mainwin != NULL);
825 toolbar_style(TOOLBAR_MAIN, action, mainwin);
827 list = compose_get_compose_list();
828 for (cur = list; cur != NULL; cur = cur->next) {
829 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
831 list = messageview_get_msgview_list();
832 for (cur = list; cur != NULL; cur = cur->next) {
833 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
838 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
840 switch ((ToolbarStyle)action) {
842 gtk_widget_hide(handlebox_wid);
845 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
849 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
853 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
856 case TOOLBAR_BOTH_HORIZ:
857 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
858 GTK_TOOLBAR_BOTH_HORIZ);
864 prefs_common.toolbar_style = (ToolbarStyle)action;
865 gtk_widget_set_size_request(handlebox_wid, 1, -1);
867 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
868 gtk_widget_show(handlebox_wid);
869 gtk_widget_queue_resize(handlebox_wid);
873 * Change the style of toolbar
875 static void toolbar_style(ToolbarType type, guint action, gpointer data)
877 GtkWidget *handlebox_wid;
878 GtkWidget *toolbar_wid;
879 MainWindow *mainwin = (MainWindow*)data;
880 Compose *compose = (Compose*)data;
881 MessageView *msgview = (MessageView*)data;
883 g_return_if_fail(data != NULL);
887 handlebox_wid = mainwin->handlebox;
888 toolbar_wid = mainwin->toolbar->toolbar;
890 case TOOLBAR_COMPOSE:
891 handlebox_wid = compose->handlebox;
892 toolbar_wid = compose->toolbar->toolbar;
894 case TOOLBAR_MSGVIEW:
895 handlebox_wid = msgview->handlebox;
896 toolbar_wid = msgview->toolbar->toolbar;
902 toolbar_set_style(toolbar_wid, handlebox_wid, action);
905 /* Toolbar handling */
906 static void toolbar_inc_cb(GtkWidget *widget,
909 ToolbarItem *toolbar_item = (ToolbarItem*)data;
912 g_return_if_fail(toolbar_item != NULL);
914 switch (toolbar_item->type) {
916 mainwin = (MainWindow*)toolbar_item->parent;
917 inc_mail_cb(mainwin, 0, NULL);
924 static void toolbar_inc_all_cb(GtkWidget *widget,
927 ToolbarItem *toolbar_item = (ToolbarItem*)data;
930 g_return_if_fail(toolbar_item != NULL);
932 switch (toolbar_item->type) {
934 mainwin = (MainWindow*)toolbar_item->parent;
935 inc_all_account_mail_cb(mainwin, 0, NULL);
942 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
944 ToolbarItem *toolbar_item = (ToolbarItem*)data;
947 g_return_if_fail(toolbar_item != NULL);
949 switch (toolbar_item->type) {
951 mainwin = (MainWindow*)toolbar_item->parent;
952 send_queue_cb(mainwin, 0, NULL);
959 static void toolbar_exec_cb(GtkWidget *widget,
962 MainWindow *mainwin = get_mainwin(data);
964 g_return_if_fail(mainwin != NULL);
965 summary_execute(mainwin->summaryview);
969 * Delete current/selected(s) message(s)
971 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
973 ToolbarItem *toolbar_item = (ToolbarItem*)data;
976 g_return_if_fail(toolbar_item != NULL);
977 g_return_if_fail(toolbar_item->parent);
979 switch (toolbar_item->type) {
980 case TOOLBAR_MSGVIEW:
981 messageview_delete((MessageView *)toolbar_item->parent);
984 mainwin = (MainWindow *)toolbar_item->parent;
985 summary_delete_trash(mainwin->summaryview);
988 debug_print("toolbar event not supported\n");
994 * Delete current/selected(s) message(s)
996 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
998 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1001 g_return_if_fail(toolbar_item != NULL);
1002 g_return_if_fail(toolbar_item->parent);
1004 switch (toolbar_item->type) {
1005 case TOOLBAR_MSGVIEW:
1006 messageview_delete((MessageView *)toolbar_item->parent);
1009 mainwin = (MainWindow *)toolbar_item->parent;
1010 summary_delete(mainwin->summaryview);
1013 debug_print("toolbar event not supported\n");
1020 * Compose new message
1022 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1024 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1025 MainWindow *mainwin;
1026 MessageView *msgview;
1028 g_return_if_fail(toolbar_item != NULL);
1030 switch (toolbar_item->type) {
1032 mainwin = (MainWindow*)toolbar_item->parent;
1033 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1034 compose_news_cb(mainwin, 0, NULL);
1036 compose_mail_cb(mainwin, 0, NULL);
1038 case TOOLBAR_MSGVIEW:
1039 msgview = (MessageView*)toolbar_item->parent;
1040 compose_new_with_folderitem(NULL,
1041 msgview->msginfo->folder, NULL);
1044 debug_print("toolbar event not supported\n");
1048 static void toolbar_learn(gpointer data, guint as_spam)
1050 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1051 MainWindow *mainwin;
1052 MessageView *msgview;
1054 g_return_if_fail(toolbar_item != NULL);
1056 switch (toolbar_item->type) {
1058 mainwin = (MainWindow*)toolbar_item->parent;
1060 mainwindow_learn(mainwin, TRUE);
1062 mainwindow_learn(mainwin, FALSE);
1064 case TOOLBAR_MSGVIEW:
1065 msgview = (MessageView*)toolbar_item->parent;
1067 messageview_learn(msgview, TRUE);
1069 messageview_learn(msgview, FALSE);
1072 debug_print("toolbar event not supported\n");
1076 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1078 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1079 MainWindow *mainwin;
1080 MessageView *msgview;
1082 g_return_if_fail(toolbar_item != NULL);
1084 switch (toolbar_item->type) {
1086 mainwin = (MainWindow*)toolbar_item->parent;
1087 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1088 mainwindow_learn(mainwin, TRUE);
1090 mainwindow_learn(mainwin, FALSE);
1092 case TOOLBAR_MSGVIEW:
1093 msgview = (MessageView*)toolbar_item->parent;
1094 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1095 messageview_learn(msgview, TRUE);
1097 messageview_learn(msgview, FALSE);
1100 debug_print("toolbar event not supported\n");
1108 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1110 toolbar_reply(data, prefs_common.reply_with_quote ?
1111 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1116 * Reply message to Sender and All recipients
1118 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1121 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1122 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1127 * Reply to Mailing List
1129 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1132 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1133 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1138 * Reply to sender of message
1140 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1143 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1144 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1150 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1152 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1155 g_return_if_fail(toolbar_item != NULL);
1157 switch (toolbar_item->type) {
1159 case TOOLBAR_MSGVIEW:
1162 case TOOLBAR_COMPOSE:
1163 compose = (Compose *)toolbar_item->parent;
1168 addressbook_open(compose);
1173 * Forward current/selected(s) message(s)
1175 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1177 toolbar_reply(data, COMPOSE_FORWARD);
1181 * Goto Prev Unread Message
1183 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1185 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1186 MainWindow *mainwin;
1187 MessageView *msgview;
1189 g_return_if_fail(toolbar_item != NULL);
1191 switch (toolbar_item->type) {
1193 mainwin = (MainWindow*)toolbar_item->parent;
1194 summary_select_prev_unread(mainwin->summaryview);
1197 case TOOLBAR_MSGVIEW:
1198 msgview = (MessageView*)toolbar_item->parent;
1199 msgview->updating = TRUE;
1200 summary_select_prev_unread(msgview->mainwin->summaryview);
1201 msgview->updating = FALSE;
1203 if (msgview->deferred_destroy) {
1204 debug_print("messageview got away!\n");
1205 messageview_destroy(msgview);
1209 /* Now we need to update the messageview window */
1210 if (msgview->mainwin->summaryview->selected) {
1211 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1214 messageview_show(msgview, msginfo,
1215 msgview->all_headers);
1217 gtk_widget_destroy(msgview->window);
1221 debug_print("toolbar event not supported\n");
1226 * Goto Next Unread Message
1228 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1230 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1231 MainWindow *mainwin;
1232 MessageView *msgview;
1234 g_return_if_fail(toolbar_item != NULL);
1236 switch (toolbar_item->type) {
1238 mainwin = (MainWindow*)toolbar_item->parent;
1239 summary_select_next_unread(mainwin->summaryview);
1242 case TOOLBAR_MSGVIEW:
1243 msgview = (MessageView*)toolbar_item->parent;
1244 msgview->updating = TRUE;
1245 summary_select_next_unread(msgview->mainwin->summaryview);
1246 msgview->updating = FALSE;
1248 if (msgview->deferred_destroy) {
1249 debug_print("messageview got away!\n");
1250 messageview_destroy(msgview);
1254 /* Now we need to update the messageview window */
1255 if (msgview->mainwin->summaryview->selected) {
1256 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1259 messageview_show(msgview, msginfo,
1260 msgview->all_headers);
1262 gtk_widget_destroy(msgview->window);
1266 debug_print("toolbar event not supported\n");
1270 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1272 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1273 MainWindow *mainwin;
1275 g_return_if_fail(toolbar_item != NULL);
1277 switch (toolbar_item->type) {
1279 mainwin = (MainWindow *) toolbar_item->parent;
1280 summary_toggle_ignore_thread(mainwin->summaryview);
1282 case TOOLBAR_MSGVIEW:
1283 /* TODO: see toolbar_next_unread_cb() if you need
1284 * this in the message view */
1287 debug_print("toolbar event not supported\n");
1292 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1294 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1296 g_return_if_fail(toolbar_item != NULL);
1302 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1304 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1305 MainWindow *mainwin;
1307 g_return_if_fail(toolbar_item != NULL);
1309 switch (toolbar_item->type) {
1311 mainwin = (MainWindow *) toolbar_item->parent;
1312 summary_print(mainwin->summaryview);
1314 case TOOLBAR_MSGVIEW:
1315 /* TODO: see toolbar_next_unread_cb() if you need
1316 * this in the message view */
1319 debug_print("toolbar event not supported\n");
1324 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1326 compose_toolbar_cb(A_SEND, data);
1329 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1331 compose_toolbar_cb(A_SENDL, data);
1334 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1336 compose_toolbar_cb(A_DRAFT, data);
1339 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1341 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1342 MainWindow *mainwin;
1343 MessageView *messageview;
1346 g_return_if_fail(toolbar_item != NULL);
1348 switch (toolbar_item->type) {
1350 mainwin = (MainWindow *) toolbar_item->parent;
1351 app_will_exit(NULL, mainwin);
1353 case TOOLBAR_MSGVIEW:
1354 messageview = (MessageView *)toolbar_item->parent;
1355 messageview_destroy(messageview);
1357 case TOOLBAR_COMPOSE:
1358 compose = (Compose *)toolbar_item->parent;
1359 compose_close_toolbar(compose);
1364 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1366 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1367 MainWindow *mainwin;
1369 g_return_if_fail(toolbar_item != NULL);
1371 switch (toolbar_item->type) {
1373 mainwin = (MainWindow *) toolbar_item->parent;
1374 summary_open_row(NULL, mainwin->summaryview);
1376 case TOOLBAR_MSGVIEW:
1377 debug_print("toolbar event not supported\n");
1379 case TOOLBAR_COMPOSE:
1380 debug_print("toolbar event not supported\n");
1385 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1387 compose_toolbar_cb(A_INSERT, data);
1390 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1392 compose_toolbar_cb(A_ATTACH, data);
1395 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1397 compose_toolbar_cb(A_SIG, data);
1400 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1402 compose_toolbar_cb(A_EXTEDITOR, data);
1405 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1407 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1410 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1412 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1416 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1418 compose_toolbar_cb(A_CHECK_SPELLING, data);
1422 * Execute actions from toolbar
1424 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1426 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1427 GSList *action_list;
1428 MainWindow *mainwin;
1430 MessageView *msgview;
1431 gpointer parent = toolbar_item->parent;
1433 g_return_if_fail(toolbar_item != NULL);
1435 switch (toolbar_item->type) {
1437 mainwin = (MainWindow*)parent;
1438 action_list = mainwin->toolbar->action_list;
1440 case TOOLBAR_COMPOSE:
1441 compose = (Compose*)parent;
1442 action_list = compose->toolbar->action_list;
1444 case TOOLBAR_MSGVIEW:
1445 msgview = (MessageView*)parent;
1446 action_list = msgview->toolbar->action_list;
1449 debug_print("toolbar event not supported\n");
1452 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1455 static MainWindow *get_mainwin(gpointer data)
1457 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1458 MainWindow *mainwin = NULL;
1459 MessageView *msgview;
1461 g_return_val_if_fail(toolbar_item != NULL, NULL);
1463 switch(toolbar_item->type) {
1465 mainwin = (MainWindow*)toolbar_item->parent;
1467 case TOOLBAR_MSGVIEW:
1468 msgview = (MessageView*)toolbar_item->parent;
1469 mainwin = (MainWindow*)msgview->mainwin;
1478 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1480 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1481 MainWindow *mainwin = NULL;
1482 switch(toolbar_item->type) {
1484 mainwin = (MainWindow*)toolbar_item->parent;
1487 g_warning("wrong toolbar type\n");
1491 if (!mainwin->in_folder) {
1492 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1494 folderview_select(mainwin->folderview, item);
1497 gtk_widget_grab_focus(mainwin->folderview->ctree);
1498 mainwindow_exit_folder(mainwin);
1502 static void toolbar_buttons_cb(GtkWidget *widget,
1509 void (*func)(GtkWidget *widget, gpointer data);
1511 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1512 { A_RECEIVE_CUR, toolbar_inc_cb },
1513 { A_SEND_QUEUED, toolbar_send_queued_cb },
1514 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1515 { A_COMPOSE_NEWS, toolbar_compose_cb },
1516 { A_REPLY_MESSAGE, toolbar_reply_cb },
1517 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1518 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1519 { A_REPLY_ML, toolbar_reply_to_list_cb },
1520 { A_FORWARD, toolbar_forward_cb },
1521 { A_TRASH, toolbar_trash_cb },
1522 { A_DELETE_REAL, toolbar_delete_cb },
1523 { A_EXECUTE, toolbar_exec_cb },
1524 { A_GOTO_PREV, toolbar_prev_unread_cb },
1525 { A_GOTO_NEXT, toolbar_next_unread_cb },
1526 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1527 { A_PRINT, toolbar_print_cb },
1528 { A_LEARN_SPAM, toolbar_learn_cb },
1529 { A_GO_FOLDERS, toolbar_go_folders_cb },
1531 { A_SEND, toolbar_send_cb },
1532 { A_SENDL, toolbar_send_later_cb },
1533 { A_DRAFT, toolbar_draft_cb },
1534 { A_OPEN_MAIL, toolbar_open_mail_cb },
1535 { A_CLOSE, toolbar_close_cb },
1536 { A_INSERT, toolbar_insert_cb },
1537 { A_ATTACH, toolbar_attach_cb },
1538 { A_SIG, toolbar_sig_cb },
1539 { A_EXTEDITOR, toolbar_ext_editor_cb },
1540 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1541 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1542 { A_ADDRBOOK, toolbar_addrbook_cb },
1544 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1546 { A_SYL_ACTIONS, toolbar_actions_execute_cb },
1547 { A_CANCEL_INC, toolbar_cancel_inc_cb }
1550 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1552 for (i = 0; i < num_items; i++) {
1553 if (callbacks[i].index == item->index) {
1554 callbacks[i].func(widget, item);
1561 * Create a new toolbar with specified type
1562 * if a callback list is passed it will be used before the
1563 * common callback list
1565 Toolbar *toolbar_create(ToolbarType type,
1566 GtkWidget *container,
1569 ToolbarItem *toolbar_item;
1572 GtkWidget *icon_wid = NULL;
1573 GtkWidget *icon_news;
1574 GtkWidget *icon_ham;
1576 GtkWidget *item_news;
1577 GtkWidget *item_ham;
1578 guint n_menu_entries;
1579 ComboButton *getall_combo;
1580 ComboButton *reply_combo;
1581 ComboButton *replyall_combo;
1582 ComboButton *replylist_combo;
1583 ComboButton *replysender_combo;
1584 ComboButton *fwd_combo;
1585 ComboButton *compose_combo;
1586 ComboButton *ham_combo;
1588 GtkTooltips *toolbar_tips;
1589 ToolbarSylpheedActions *action_item;
1591 GSList *toolbar_list;
1592 Toolbar *toolbar_data;
1595 toolbar_tips = gtk_tooltips_new();
1597 toolbar_read_config_file(type);
1598 toolbar_list = toolbar_get_list(type);
1600 toolbar_data = g_new0(Toolbar, 1);
1602 toolbar = gtk_toolbar_new();
1603 gtk_container_add(GTK_CONTAINER(container), toolbar);
1604 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1605 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1606 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1608 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1610 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1611 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1615 toolbar_item = g_new0(ToolbarItem, 1);
1616 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1617 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1618 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1619 toolbar_item->parent = data;
1620 toolbar_item->type = type;
1622 /* collect toolbar items in list to keep track */
1623 toolbar_data->item_list =
1624 g_slist_append(toolbar_data->item_list,
1626 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1627 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1631 icon_wid, G_CALLBACK(toolbar_buttons_cb),
1634 switch (toolbar_item->index) {
1637 toolbar_data->folders_btn = item;
1638 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1639 toolbar_data->folders_btn,
1640 _("Go to folder list"), NULL);
1643 toolbar_data->getall_btn = item;
1644 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1645 toolbar_data->getall_btn,
1646 _("Receive Mail on all Accounts"), NULL);
1647 getall_combo = gtkut_combo_button_create(toolbar_data->getall_btn, NULL, 0,
1648 "<GetAll>", (gpointer)toolbar_item);
1649 gtk_button_set_relief(GTK_BUTTON(getall_combo->arrow),
1651 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1652 GTK_WIDGET_PTR(getall_combo),
1653 _("Receive Mail on selected Account"), "Reply");
1654 toolbar_data->getall_combo = getall_combo;
1657 toolbar_data->get_btn = item;
1658 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1659 toolbar_data->get_btn,
1660 _("Receive Mail on current Account"), NULL);
1663 toolbar_data->send_btn = item;
1664 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1665 toolbar_data->send_btn,
1666 _("Send Queued Messages"), NULL);
1669 toolbar_data->close_window_btn = item;
1670 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1671 toolbar_data->close_window_btn,
1672 _("Close window"), NULL);
1675 toolbar_data->open_mail_btn = item;
1676 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1677 toolbar_data->open_mail_btn,
1678 _("Open email"), NULL);
1680 case A_COMPOSE_EMAIL:
1681 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1682 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1686 icon_news, G_CALLBACK(toolbar_buttons_cb),
1688 toolbar_data->compose_mail_btn = item;
1689 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1690 toolbar_data->compose_mail_btn,
1691 _("Compose Email"), NULL);
1692 toolbar_data->compose_news_btn = item_news;
1693 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1694 toolbar_data->compose_news_btn,
1695 _("Compose News"), NULL);
1696 compose_combo = gtkut_combo_button_create(toolbar_data->compose_mail_btn, NULL, 0,
1697 "<Compose>", (gpointer)toolbar_item);
1698 gtk_button_set_relief(GTK_BUTTON(compose_combo->arrow),
1700 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1701 GTK_WIDGET_PTR(compose_combo),
1702 _("Compose with selected Account"), "Compose");
1703 toolbar_data->compose_combo = compose_combo;
1706 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1707 item_ham = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1711 icon_ham, G_CALLBACK(toolbar_buttons_cb),
1713 toolbar_data->learn_spam_btn = item;
1714 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1715 toolbar_data->learn_spam_btn,
1716 _("Learn Spam"), NULL);
1717 toolbar_data->learn_ham_btn = item_ham;
1718 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1719 toolbar_data->learn_ham_btn,
1720 _("Learn Ham"), NULL);
1721 n_menu_entries = sizeof(learn_entries) /
1722 sizeof(learn_entries[0]);
1723 ham_combo = gtkut_combo_button_create(toolbar_data->learn_spam_btn,
1724 learn_entries, n_menu_entries,
1725 "<LearnSpam>", (gpointer)toolbar_item);
1726 gtk_button_set_relief(GTK_BUTTON(ham_combo->arrow),
1728 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1729 GTK_WIDGET_PTR(ham_combo),
1730 _("Learn as..."), _("Learn"));
1731 toolbar_data->ham_combo = ham_combo;
1733 case A_REPLY_MESSAGE:
1734 toolbar_data->reply_btn = item;
1735 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1736 toolbar_data->reply_btn,
1737 _("Reply to Message"), NULL);
1738 n_menu_entries = sizeof(reply_entries) /
1739 sizeof(reply_entries[0]);
1740 reply_combo = gtkut_combo_button_create(toolbar_data->reply_btn,
1741 reply_entries, n_menu_entries,
1742 "<Reply>", (gpointer)toolbar_item);
1743 gtk_button_set_relief(GTK_BUTTON(reply_combo->arrow),
1745 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1746 GTK_WIDGET_PTR(reply_combo),
1747 _("Reply to Message"), "Reply");
1748 toolbar_data->reply_combo = reply_combo;
1750 case A_REPLY_SENDER:
1751 toolbar_data->replysender_btn = item;
1752 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1753 toolbar_data->replysender_btn,
1754 _("Reply to Sender"), NULL);
1755 n_menu_entries = sizeof(replysender_entries) /
1756 sizeof(replysender_entries[0]);
1757 replysender_combo = gtkut_combo_button_create(toolbar_data->replysender_btn,
1758 replysender_entries, n_menu_entries,
1759 "<ReplySender>", (gpointer)toolbar_item);
1760 gtk_button_set_relief(GTK_BUTTON(replysender_combo->arrow),
1762 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1763 GTK_WIDGET_PTR(replysender_combo),
1764 _("Reply to Sender"), "ReplySender");
1765 toolbar_data->replysender_combo = replysender_combo;
1768 toolbar_data->replyall_btn = item;
1769 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1770 toolbar_data->replyall_btn,
1771 _("Reply to All"), NULL);
1772 n_menu_entries = sizeof(replyall_entries) /
1773 sizeof(replyall_entries[0]);
1774 replyall_combo = gtkut_combo_button_create(toolbar_data->replyall_btn,
1775 replyall_entries, n_menu_entries,
1776 "<ReplyAll>", (gpointer)toolbar_item);
1777 gtk_button_set_relief(GTK_BUTTON(replyall_combo->arrow),
1779 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1780 GTK_WIDGET_PTR(replyall_combo),
1781 _("Reply to All"), "ReplyAll");
1782 toolbar_data->replyall_combo = replyall_combo;
1785 toolbar_data->replylist_btn = item;
1786 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1787 toolbar_data->replylist_btn,
1788 _("Reply to Mailing-list"), NULL);
1789 n_menu_entries = sizeof(replylist_entries) /
1790 sizeof(replylist_entries[0]);
1791 replylist_combo = gtkut_combo_button_create(toolbar_data->replylist_btn,
1792 replylist_entries, n_menu_entries,
1793 "<ReplyList>", (gpointer)toolbar_item);
1794 gtk_button_set_relief(GTK_BUTTON(replylist_combo->arrow),
1796 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1797 GTK_WIDGET_PTR(replylist_combo),
1798 _("Reply to Mailing-list"), "ReplyList");
1799 toolbar_data->replylist_combo = replylist_combo;
1802 toolbar_data->fwd_btn = item;
1803 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1804 toolbar_data->fwd_btn,
1805 _("Forward Message"), NULL);
1806 n_menu_entries = sizeof(forward_entries) /
1807 sizeof(forward_entries[0]);
1808 fwd_combo = gtkut_combo_button_create(toolbar_data->fwd_btn,
1809 forward_entries, n_menu_entries,
1810 "<Forward>", (gpointer)toolbar_item);
1811 gtk_button_set_relief(GTK_BUTTON(fwd_combo->arrow),
1813 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1814 GTK_WIDGET_PTR(fwd_combo),
1815 _("Forward Message"), "Fwd");
1816 toolbar_data->fwd_combo = fwd_combo;
1819 toolbar_data->trash_btn = item;
1820 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1821 toolbar_data->trash_btn,
1822 _("Trash Message"), NULL);
1825 toolbar_data->delete_btn = item;
1826 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1827 toolbar_data->delete_btn,
1828 _("Delete Message"), NULL);
1831 toolbar_data->exec_btn = item;
1832 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1833 toolbar_data->exec_btn,
1834 _("Execute"), NULL);
1837 toolbar_data->prev_btn = item;
1838 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1839 toolbar_data->prev_btn,
1840 _("Go to Previous Unread Message"),
1844 toolbar_data->next_btn = item;
1845 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1846 toolbar_data->next_btn,
1847 _("Go to Next Unread Message"),
1851 /* Compose Toolbar */
1853 toolbar_data->send_btn = item;
1854 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1855 toolbar_data->send_btn,
1856 _("Send Message"), NULL);
1859 toolbar_data->sendl_btn = item;
1860 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1861 toolbar_data->sendl_btn,
1862 _("Put into queue folder and send later"), NULL);
1865 toolbar_data->draft_btn = item;
1866 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1867 toolbar_data->draft_btn,
1868 _("Save to draft folder"), NULL);
1871 toolbar_data->insert_btn = item;
1872 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1873 toolbar_data->insert_btn,
1874 _("Insert file"), NULL);
1877 toolbar_data->attach_btn = item;
1878 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1879 toolbar_data->attach_btn,
1880 _("Attach file"), NULL);
1883 toolbar_data->sig_btn = item;
1884 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1885 toolbar_data->sig_btn,
1886 _("Insert signature"), NULL);
1889 toolbar_data->exteditor_btn = item;
1890 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1891 toolbar_data->exteditor_btn,
1892 _("Edit with external editor"), NULL);
1894 case A_LINEWRAP_CURRENT:
1895 toolbar_data->linewrap_current_btn = item;
1896 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1897 toolbar_data->linewrap_current_btn,
1898 _("Wrap long lines of current paragraph"), NULL);
1900 case A_LINEWRAP_ALL:
1901 toolbar_data->linewrap_all_btn = item;
1902 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1903 toolbar_data->linewrap_all_btn,
1904 _("Wrap all long lines"), NULL);
1907 toolbar_data->addrbook_btn = item;
1908 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1909 toolbar_data->addrbook_btn,
1910 _("Address book"), NULL);
1913 case A_CHECK_SPELLING:
1914 toolbar_data->spellcheck_btn = item;
1915 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1916 toolbar_data->spellcheck_btn,
1917 _("Check spelling"), NULL);
1922 action_item = g_new0(ToolbarSylpheedActions, 1);
1923 action_item->widget = item;
1924 action_item->name = g_strdup(toolbar_item->text);
1926 toolbar_data->action_list =
1927 g_slist_append(toolbar_data->action_list,
1930 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1932 action_item->name, NULL);
1934 gtk_widget_show(item);
1937 toolbar_data->cancel_inc_btn = item;
1938 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1939 toolbar_data->cancel_inc_btn,
1940 _("Cancel receiving"), NULL);
1943 /* find and set the tool tip text */
1944 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1946 toolbar_ret_descr_from_val
1947 (toolbar_item->index),
1953 toolbar_data->toolbar = toolbar;
1954 if (type == TOOLBAR_MAIN)
1955 activate_compose_button(toolbar_data,
1956 prefs_common.toolbar_style,
1957 toolbar_data->compose_btn_type);
1958 if (type != TOOLBAR_COMPOSE)
1959 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
1962 gtk_widget_show_all(toolbar);
1964 return toolbar_data;
1968 * Free toolbar structures
1970 void toolbar_destroy(Toolbar * toolbar) {
1972 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1973 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1976 void toolbar_update(ToolbarType type, gpointer data)
1978 Toolbar *toolbar_data;
1979 GtkWidget *handlebox;
1980 MainWindow *mainwin = (MainWindow*)data;
1981 Compose *compose = (Compose*)data;
1982 MessageView *msgview = (MessageView*)data;
1986 toolbar_data = mainwin->toolbar;
1987 handlebox = mainwin->handlebox;
1989 case TOOLBAR_COMPOSE:
1990 toolbar_data = compose->toolbar;
1991 handlebox = compose->handlebox;
1993 case TOOLBAR_MSGVIEW:
1994 toolbar_data = msgview->toolbar;
1995 handlebox = msgview->handlebox;
2001 gtk_container_remove(GTK_CONTAINER(handlebox),
2002 GTK_WIDGET(toolbar_data->toolbar));
2004 toolbar_init(toolbar_data);
2005 toolbar_data = toolbar_create(type, handlebox, data);
2008 mainwin->toolbar = toolbar_data;
2010 case TOOLBAR_COMPOSE:
2011 compose->toolbar = toolbar_data;
2013 case TOOLBAR_MSGVIEW:
2014 msgview->toolbar = toolbar_data;
2018 toolbar_style(type, prefs_common.toolbar_style, data);
2020 if (type == TOOLBAR_MAIN) {
2021 toolbar_main_set_sensitive((MainWindow*)data);
2022 account_set_menu_only_toolbar();
2026 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2027 gboolean in_btn = FALSE; \
2028 if (GTK_IS_BUTTON(widget)) \
2029 in_btn = GTK_BUTTON(widget)->in_button; \
2030 gtk_widget_set_sensitive(widget, sensitive); \
2031 if (GTK_IS_BUTTON(widget)) \
2032 GTK_BUTTON(widget)->in_button = in_btn; \
2035 void toolbar_main_set_sensitive(gpointer data)
2037 SensitiveCond state;
2039 MainWindow *mainwin = (MainWindow*)data;
2040 Toolbar *toolbar = mainwin->toolbar;
2042 GSList *entry_list = NULL;
2044 typedef struct _Entry Entry;
2051 #define SET_WIDGET_COND(w, c) \
2053 Entry *e = g_new0(Entry, 1); \
2056 entry_list = g_slist_append(entry_list, e); \
2060 if (toolbar->get_btn)
2061 SET_WIDGET_COND(toolbar->get_btn,
2062 M_HAVE_ACCOUNT|M_UNLOCKED);
2064 if (toolbar->getall_btn) {
2065 SET_WIDGET_COND(toolbar->getall_btn,
2066 M_HAVE_ACCOUNT|M_UNLOCKED);
2067 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->getall_combo),
2068 M_HAVE_ACCOUNT|M_UNLOCKED);
2070 if (toolbar->send_btn) {
2071 SET_WIDGET_COND(toolbar->send_btn,
2072 M_HAVE_QUEUED_MAILS);
2074 if (toolbar->compose_mail_btn) {
2075 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->compose_combo),
2077 SET_WIDGET_COND(toolbar->compose_news_btn,
2080 if (toolbar->close_window_btn) {
2081 SET_WIDGET_COND(toolbar->compose_news_btn,
2084 if (toolbar->open_mail_btn) {
2085 SET_WIDGET_COND(toolbar->open_mail_btn,
2088 if (toolbar->reply_btn) {
2089 SET_WIDGET_COND(toolbar->reply_btn,
2090 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2091 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->reply_combo),
2092 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2094 if (toolbar->replyall_btn) {
2095 SET_WIDGET_COND(toolbar->replyall_btn,
2096 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2097 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replyall_combo),
2098 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2100 if (toolbar->replylist_btn) {
2101 SET_WIDGET_COND(toolbar->replylist_btn,
2102 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2103 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replylist_combo),
2104 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2106 if (toolbar->replysender_btn) {
2107 SET_WIDGET_COND(toolbar->replysender_btn,
2108 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2109 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replysender_combo),
2110 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2112 if (toolbar->fwd_btn) {
2113 SET_WIDGET_COND(toolbar->fwd_btn,
2114 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2115 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->fwd_combo),
2116 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2118 if (toolbar->fwd_combo) {
2119 GtkWidget *submenu = gtk_item_factory_get_widget(toolbar->fwd_combo->factory, "/Redirect");
2120 SET_WIDGET_COND(submenu,
2121 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2124 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2125 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
2127 SET_WIDGET_COND(toolbar->next_btn, 0);
2130 if (toolbar->trash_btn)
2131 SET_WIDGET_COND(toolbar->trash_btn,
2132 M_TARGET_EXIST|M_ALLOW_DELETE);
2134 if (toolbar->delete_btn)
2135 SET_WIDGET_COND(toolbar->delete_btn,
2136 M_TARGET_EXIST|M_ALLOW_DELETE);
2138 if (toolbar->exec_btn)
2139 SET_WIDGET_COND(toolbar->exec_btn,
2142 if (toolbar->learn_ham_btn)
2143 SET_WIDGET_COND(toolbar->learn_ham_btn,
2144 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2146 if (toolbar->learn_spam_btn)
2147 SET_WIDGET_COND(toolbar->learn_spam_btn,
2148 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2150 if (toolbar->ham_combo)
2151 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->ham_combo),
2152 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2154 if (toolbar->cancel_inc_btn)
2155 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2158 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2159 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
2161 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2164 #undef SET_WIDGET_COND
2166 state = main_window_get_current_state(mainwin);
2168 for (cur = entry_list; cur != NULL; cur = cur->next) {
2169 Entry *e = (Entry*) cur->data;
2171 if (e->widget != NULL) {
2172 sensitive = ((e->cond & state) == e->cond);
2173 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2177 while (entry_list != NULL) {
2178 Entry *e = (Entry*) entry_list->data;
2181 entry_list = g_slist_remove(entry_list, e);
2184 g_slist_free(entry_list);
2186 activate_compose_button(toolbar,
2187 prefs_common.toolbar_style,
2188 toolbar->compose_btn_type);
2192 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2194 Compose *compose = (Compose*)data;
2195 GSList *items = compose->toolbar->action_list;
2197 if (compose->toolbar->send_btn)
2198 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2199 if (compose->toolbar->sendl_btn)
2200 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2201 if (compose->toolbar->draft_btn )
2202 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2203 if (compose->toolbar->insert_btn )
2204 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2205 if (compose->toolbar->attach_btn)
2206 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2207 if (compose->toolbar->sig_btn)
2208 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2209 if (compose->toolbar->exteditor_btn)
2210 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2211 if (compose->toolbar->linewrap_current_btn)
2212 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2213 if (compose->toolbar->linewrap_all_btn)
2214 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2215 if (compose->toolbar->addrbook_btn)
2216 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2218 if (compose->toolbar->spellcheck_btn)
2219 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2221 for (; items != NULL; items = g_slist_next(items)) {
2222 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
2223 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2228 * Initialize toolbar structure
2230 void toolbar_init(Toolbar * toolbar) {
2232 toolbar->toolbar = NULL;
2233 toolbar->folders_btn = NULL;
2234 toolbar->get_btn = NULL;
2235 toolbar->getall_btn = NULL;
2236 toolbar->getall_combo = NULL;
2237 toolbar->send_btn = NULL;
2238 toolbar->compose_mail_btn = NULL;
2239 toolbar->compose_news_btn = NULL;
2240 toolbar->compose_combo = NULL;
2241 toolbar->reply_btn = NULL;
2242 toolbar->replysender_btn = NULL;
2243 toolbar->replyall_btn = NULL;
2244 toolbar->replylist_btn = NULL;
2245 toolbar->fwd_btn = NULL;
2246 toolbar->trash_btn = NULL;
2247 toolbar->delete_btn = NULL;
2248 toolbar->prev_btn = NULL;
2249 toolbar->next_btn = NULL;
2250 toolbar->exec_btn = NULL;
2251 toolbar->open_mail_btn = NULL;
2252 toolbar->close_window_btn = NULL;
2253 /* compose buttons */
2254 toolbar->sendl_btn = NULL;
2255 toolbar->draft_btn = NULL;
2256 toolbar->insert_btn = NULL;
2257 toolbar->attach_btn = NULL;
2258 toolbar->sig_btn = NULL;
2259 toolbar->exteditor_btn = NULL;
2260 toolbar->linewrap_current_btn = NULL;
2261 toolbar->linewrap_all_btn = NULL;
2262 toolbar->addrbook_btn = NULL;
2264 toolbar->spellcheck_btn = NULL;
2267 toolbar_destroy(toolbar);
2272 static void toolbar_reply(gpointer data, guint action)
2274 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2275 MainWindow *mainwin;
2276 MessageView *msgview;
2277 GSList *msginfo_list = NULL;
2279 g_return_if_fail(toolbar_item != NULL);
2281 switch (toolbar_item->type) {
2283 mainwin = (MainWindow*)toolbar_item->parent;
2284 msginfo_list = summary_get_selection(mainwin->summaryview);
2285 msgview = (MessageView*)mainwin->messageview;
2287 case TOOLBAR_MSGVIEW:
2288 msgview = (MessageView*)toolbar_item->parent;
2289 g_return_if_fail(msgview != NULL);
2290 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2296 g_return_if_fail(msgview != NULL);
2297 g_return_if_fail(msginfo_list != NULL);
2298 compose_reply_from_messageview(msgview, msginfo_list, action);
2299 g_slist_free(msginfo_list);
2301 /* TODO: update reply state ion summaryview */
2305 /* exported functions */
2307 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2309 MainWindow *mainwin = (MainWindow*)data;
2311 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2314 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2316 MainWindow *mainwin = (MainWindow*)data;
2318 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2321 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2325 gboolean got_error = FALSE;
2326 gchar *errstr = NULL;
2328 if (prefs_common.work_offline)
2329 if (alertpanel(_("Offline warning"),
2330 _("You're working offline. Override?"),
2331 GTK_STOCK_NO, GTK_STOCK_YES,
2332 NULL) != G_ALERTALTERNATE)
2335 /* ask for confirmation before sending queued messages only
2336 in online mode and if there is at least one message queued
2337 in any of the folder queue
2339 if (prefs_common.confirm_send_queued_messages) {
2341 /* check if there's a queued message */
2342 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2343 Folder *folder = list->data;
2345 found = !procmsg_queue_is_empty(folder->queue);
2347 /* if necessary, ask for confirmation before sending */
2348 if (found && !prefs_common.work_offline) {
2349 if (alertpanel(_("Send queued messages"),
2350 _("Send all queued messages?"),
2351 GTK_STOCK_CANCEL, _("_Send"),
2352 NULL) != G_ALERTALTERNATE)
2357 for (list = folder_get_list(); list != NULL; list = list->next) {
2358 Folder *folder = list->data;
2360 if (folder->queue) {
2361 if (procmsg_send_queue(folder->queue,
2362 prefs_common.savemsg,
2369 alertpanel_error_log(_("Some errors occurred while "
2370 "sending queued messages."));
2372 gchar *tmp = g_strdup_printf(_("Some errors occurred "
2373 "while sending queued messages:\n%s"), errstr);
2375 alertpanel_error_log(tmp);
2381 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2383 MainWindow *mainwin = (MainWindow*)data;
2384 PrefsAccount *ac = NULL;
2385 FolderItem *item = mainwin->summaryview->folder_item;
2390 ac = account_find_from_item(item);
2391 if (ac && ac->protocol != A_NNTP) {
2392 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2398 * CLAWS - use current account
2400 if (cur_account && (cur_account->protocol != A_NNTP)) {
2401 compose_new_with_folderitem(cur_account, item, NULL);
2406 * CLAWS - just get the first one
2408 list = account_get_list();
2409 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2410 ac = (PrefsAccount *) cur->data;
2411 if (ac->protocol != A_NNTP) {
2412 compose_new_with_folderitem(ac, item, NULL);
2418 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2420 MainWindow *mainwin = (MainWindow*)data;
2421 PrefsAccount * ac = NULL;
2425 if (mainwin->summaryview->folder_item) {
2426 ac = mainwin->summaryview->folder_item->folder->account;
2427 if (ac && ac->protocol == A_NNTP) {
2428 compose_new_with_folderitem(ac,
2429 mainwin->summaryview->folder_item, NULL);
2434 list = account_get_list();
2435 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2436 ac = (PrefsAccount *) cur->data;
2437 if (ac->protocol == A_NNTP) {
2438 compose_new_with_folderitem(ac,
2439 mainwin->summaryview->folder_item, NULL);