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"
61 #define TOOLBAR_TAG_INDEX "toolbar"
62 #define TOOLBAR_TAG_ITEM "item"
63 #define TOOLBAR_TAG_SEPARATOR "separator"
65 #define TOOLBAR_ICON_FILE "file"
66 #define TOOLBAR_ICON_TEXT "text"
67 #define TOOLBAR_ICON_ACTION "action"
69 static gboolean toolbar_is_duplicate (gint action,
71 static void toolbar_parse_item (XMLFile *file,
74 static gint toolbar_ret_val_from_text (const gchar *text);
75 static gchar *toolbar_ret_text_from_val (gint val);
77 static void toolbar_set_default_main (void);
78 static void toolbar_set_default_compose (void);
79 static void toolbar_set_default_msgview (void);
81 static void toolbar_style (ToolbarType type,
85 static MainWindow *get_mainwin (gpointer data);
86 static void activate_compose_button (Toolbar *toolbar,
88 ComposeButtonType type);
90 /* toolbar callbacks */
91 static void toolbar_reply (gpointer data,
93 static void toolbar_learn (gpointer data,
95 static void toolbar_delete_cb (GtkWidget *widget,
97 static void toolbar_trash_cb (GtkWidget *widget,
100 static void toolbar_compose_cb (GtkWidget *widget,
103 static void toolbar_learn_cb (GtkWidget *widget,
106 static void toolbar_reply_cb (GtkWidget *widget,
109 static void toolbar_reply_to_all_cb (GtkWidget *widget,
112 static void toolbar_reply_to_list_cb (GtkWidget *widget,
115 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
118 static void toolbar_forward_cb (GtkWidget *widget,
121 static void toolbar_prev_unread_cb (GtkWidget *widget,
123 static void toolbar_next_unread_cb (GtkWidget *widget,
126 static void toolbar_ignore_thread_cb (GtkWidget *widget,
129 static void toolbar_print_cb (GtkWidget *widget,
132 static void toolbar_actions_execute_cb (GtkWidget *widget,
136 static void toolbar_send_cb (GtkWidget *widget,
138 static void toolbar_send_later_cb (GtkWidget *widget,
140 static void toolbar_draft_cb (GtkWidget *widget,
142 static void toolbar_close_cb (GtkWidget *widget,
144 static void toolbar_open_mail_cb (GtkWidget *widget,
146 static void toolbar_insert_cb (GtkWidget *widget,
148 static void toolbar_attach_cb (GtkWidget *widget,
150 static void toolbar_sig_cb (GtkWidget *widget,
152 static void toolbar_ext_editor_cb (GtkWidget *widget,
154 static void toolbar_linewrap_current_cb (GtkWidget *widget,
156 static void toolbar_linewrap_all_cb (GtkWidget *widget,
158 static void toolbar_addrbook_cb (GtkWidget *widget,
161 static void toolbar_check_spelling_cb (GtkWidget *widget,
164 static void toolbar_cancel_inc_cb (GtkWidget *widget,
170 } toolbar_text [] = {
171 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
172 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
173 { "A_SEND_QUEUED", N_("Send Queued Messages") },
174 { "A_COMPOSE_EMAIL", N_("Compose Email") },
175 { "A_COMPOSE_NEWS", N_("Compose News") },
176 { "A_REPLY_MESSAGE", N_("Reply to Message") },
177 { "A_REPLY_SENDER", N_("Reply to Sender") },
178 { "A_REPLY_ALL", N_("Reply to All") },
179 { "A_REPLY_ML", N_("Reply to Mailing-list") },
180 { "A_OPEN_MAIL", N_("Open email") },
181 { "A_FORWARD", N_("Forward Message") },
182 { "A_TRASH", N_("Trash Message") },
183 { "A_DELETE_REAL", N_("Delete Message") },
184 { "A_EXECUTE", N_("Execute") },
185 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
186 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
187 { "A_IGNORE_THREAD", N_("Ignore thread") },
188 { "A_PRINT", N_("Print") },
189 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
190 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
192 { "A_SEND", N_("Send Message") },
193 { "A_SENDL", N_("Put into queue folder and send later") },
194 { "A_DRAFT", N_("Save to draft folder") },
195 { "A_INSERT", N_("Insert file") },
196 { "A_ATTACH", N_("Attach file") },
197 { "A_SIG", N_("Insert signature") },
198 { "A_EXTEDITOR", N_("Edit with external editor") },
199 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
200 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
201 { "A_ADDRBOOK", N_("Address book") },
203 { "A_CHECK_SPELLING", N_("Check spelling") },
205 { "A_SYL_ACTIONS", N_("Claws Mail Actions Feature") },
206 { "A_CANCEL_INC", N_("Cancel receiving") },
207 { "A_CLOSE", N_("Close window") },
208 { "A_SEPARATOR", "Separator" }
211 /* struct holds configuration files and a list of
212 * currently active toolbar items
213 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
217 const gchar *conf_file;
219 } toolbar_config[3] = {
220 { "toolbar_main.xml", NULL},
221 { "toolbar_compose.xml", NULL},
222 { "toolbar_msgview.xml", NULL}
225 static GtkItemFactoryEntry reply_entries[] =
227 {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
228 {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
230 static GtkItemFactoryEntry replyall_entries[] =
232 {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
233 {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
235 static GtkItemFactoryEntry replylist_entries[] =
237 {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
238 {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
240 static GtkItemFactoryEntry replysender_entries[] =
242 {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
243 {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
245 static GtkItemFactoryEntry forward_entries[] =
247 {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
248 {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
249 {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, NULL}
251 static GtkItemFactoryEntry learn_entries[] =
253 {N_("/Learn as _Spam"), NULL, toolbar_learn, TRUE, NULL},
254 {N_("/Learn as _Ham"), NULL, toolbar_learn, FALSE, NULL}
258 gint toolbar_ret_val_from_descr(const gchar *descr)
262 for (i = 0; i < N_ACTION_VAL; i++) {
263 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
270 gchar *toolbar_ret_descr_from_val(gint val)
272 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
274 return gettext(toolbar_text[val].descr);
277 static gint toolbar_ret_val_from_text(const gchar *text)
281 for (i = 0; i < N_ACTION_VAL; i++) {
282 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
289 static gchar *toolbar_ret_text_from_val(gint val)
291 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
293 return toolbar_text[val].index_str;
296 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
300 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
303 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
304 ToolbarItem *item = (ToolbarItem*) cur->data;
306 if (item->index == action)
312 /* depending on toolbar type this function
313 returns a list of available toolbar events being
314 displayed by prefs_toolbar
316 GList *toolbar_get_action_items(ToolbarType source)
321 if (source == TOOLBAR_MAIN) {
322 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
323 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
324 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
325 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
326 A_GOTO_NEXT, A_IGNORE_THREAD, A_PRINT,
327 A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
328 A_SYL_ACTIONS, A_CANCEL_INC };
330 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
331 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
334 else if (source == TOOLBAR_COMPOSE) {
335 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
336 A_INSERT, A_ATTACH, A_SIG,
337 A_EXTEDITOR, A_LINEWRAP_CURRENT,
338 A_LINEWRAP_ALL, A_ADDRBOOK,
342 A_SYL_ACTIONS, A_CLOSE };
344 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
345 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
347 else if (source == TOOLBAR_MSGVIEW) {
348 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
349 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
350 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
351 A_ADDRBOOK, A_LEARN_SPAM, A_SYL_ACTIONS, A_CLOSE };
353 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
354 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
360 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
364 ToolbarItem *item = NULL;
365 gboolean rewrite = FALSE;
367 attr = xml_get_current_tag_attr(file);
368 item = g_new0(ToolbarItem, 1);
370 name = ((XMLAttr *)attr->data)->name;
371 value = ((XMLAttr *)attr->data)->value;
373 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
374 item->file = g_strdup (value);
375 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
376 item->text = g_strdup (gettext(value));
377 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
378 item->index = toolbar_ret_val_from_text(value);
379 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
381 item->index = A_TRASH;
383 item->file = g_strdup("trash_btn");
385 item->text = g_strdup(_("Trash"));
388 attr = g_list_next(attr);
390 if (item->index != -1) {
392 if (!toolbar_is_duplicate(item->index, source))
393 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
397 toolbar_save_config_file(source);
401 static void toolbar_set_default_main(void)
407 } default_toolbar[] = {
409 { A_GO_FOLDERS, STOCK_PIXMAP_DIR_OPEN, _("Folders") },
410 { A_SEPARATOR, 0, ("") },
412 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get Mail")},
413 { A_SEPARATOR, 0, ("") },
414 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
415 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE,
416 (gchar*)Q_("Toolbar|Compose") },
417 { A_SEPARATOR, 0, ("") },
419 { A_OPEN_MAIL, STOCK_PIXMAP_OPEN_MAIL, _("Open") },
421 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
423 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
424 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
426 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
427 { A_SEPARATOR, 0, ("") },
428 { A_TRASH, STOCK_PIXMAP_TRASH, _("Trash") },
429 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
430 { A_LEARN_SPAM, STOCK_PIXMAP_SPAM_BTN, _("Spam") },
432 { A_SEPARATOR, 0, ("") },
433 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
438 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
440 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
442 if (default_toolbar[i].action != A_SEPARATOR) {
444 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
446 toolbar_item->file = g_strdup(file);
447 toolbar_item->index = default_toolbar[i].action;
448 toolbar_item->text = g_strdup(default_toolbar[i].text);
451 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
452 toolbar_item->index = A_SEPARATOR;
455 if (toolbar_item->index != -1) {
456 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
457 toolbar_config[TOOLBAR_MAIN].item_list =
458 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
463 static void toolbar_set_default_compose(void)
469 } default_toolbar[] = {
470 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
471 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
472 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
473 { A_SEPARATOR, 0, ("") },
475 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
477 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
478 { A_SEPARATOR, 0, ("") },
479 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
482 { A_SEPARATOR, 0, ("") },
483 { A_CLOSE, STOCK_PIXMAP_CLOSE, _("Close") }
489 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
491 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
493 if (default_toolbar[i].action != A_SEPARATOR) {
495 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
497 toolbar_item->file = g_strdup(file);
498 toolbar_item->index = default_toolbar[i].action;
499 toolbar_item->text = g_strdup(default_toolbar[i].text);
502 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
503 toolbar_item->index = A_SEPARATOR;
506 if (toolbar_item->index != -1) {
507 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
508 toolbar_config[TOOLBAR_COMPOSE].item_list =
509 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
514 static void toolbar_set_default_msgview(void)
520 } default_toolbar[] = {
521 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
522 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
523 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
524 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
525 { A_SEPARATOR, 0, ("") },
526 { A_TRASH, STOCK_PIXMAP_TRASH, _("Trash") },
527 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
528 { A_LEARN_SPAM, STOCK_PIXMAP_SPAM_BTN, _("Spam") },
530 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
533 { A_SEPARATOR, 0, ("") },
534 { A_CLOSE, STOCK_PIXMAP_CLOSE, _("Close") }
540 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
542 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
544 if (default_toolbar[i].action != A_SEPARATOR) {
546 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
548 toolbar_item->file = g_strdup(file);
549 toolbar_item->index = default_toolbar[i].action;
550 toolbar_item->text = g_strdup(default_toolbar[i].text);
553 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
554 toolbar_item->index = A_SEPARATOR;
557 if (toolbar_item->index != -1) {
558 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
559 toolbar_config[TOOLBAR_MSGVIEW].item_list =
560 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
565 void toolbar_set_default(ToolbarType source)
567 if (source == TOOLBAR_MAIN)
568 toolbar_set_default_main();
569 else if (source == TOOLBAR_COMPOSE)
570 toolbar_set_default_compose();
571 else if (source == TOOLBAR_MSGVIEW)
572 toolbar_set_default_msgview();
575 void toolbar_save_config_file(ToolbarType source)
580 gchar *fileSpec = NULL;
582 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
584 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
585 pfile = prefs_write_open(fileSpec);
589 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL);
591 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
593 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
594 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
596 if (toolbar_item->index != A_SEPARATOR) {
597 fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
599 TOOLBAR_ICON_FILE, toolbar_item->file,
601 xml_file_put_escape_str(fp, toolbar_item->text);
602 fprintf(fp, "\" %s=\"%s\"/>\n",
604 toolbar_ret_text_from_val(toolbar_item->index));
606 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
610 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
612 if (prefs_file_close (pfile) < 0 )
613 g_warning("failed to write toolbar configuration to file\n");
615 g_warning("failed to open toolbar configuration file for writing\n");
618 void toolbar_read_config_file(ToolbarType source)
620 XMLFile *file = NULL;
621 gchar *fileSpec = NULL;
626 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
628 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
629 file = xml_open_file(fileSpec);
632 toolbar_clear_list(source);
636 || (xml_get_dtd(file))
637 || (xml_parse_next_tag(file))
638 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
639 xml_close_file(file);
643 attr = xml_get_current_tag_attr(file);
650 if (xml_parse_next_tag(file))
653 /* Get next tag (icon, icon_text or icon_action) */
654 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
655 toolbar_parse_item(file, source);
656 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
657 ToolbarItem *item = g_new0(ToolbarItem, 1);
659 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
660 item->index = A_SEPARATOR;
661 toolbar_config[source].item_list =
662 g_slist_append(toolbar_config[source].item_list, item);
666 xml_close_file(file);
669 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
671 if (source == TOOLBAR_MAIN)
672 toolbar_set_default(TOOLBAR_MAIN);
673 else if (source == TOOLBAR_COMPOSE)
674 toolbar_set_default(TOOLBAR_COMPOSE);
675 else if (source == TOOLBAR_MSGVIEW)
676 toolbar_set_default(TOOLBAR_MSGVIEW);
678 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
682 toolbar_save_config_file(source);
687 * clears list of toolbar items read from configuration files
689 void toolbar_clear_list(ToolbarType source)
691 while (toolbar_config[source].item_list != NULL) {
692 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
694 toolbar_config[source].item_list =
695 g_slist_remove(toolbar_config[source].item_list, item);
701 g_slist_free(toolbar_config[source].item_list);
706 * return list of Toolbar items
708 GSList *toolbar_get_list(ToolbarType source)
712 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
713 list = toolbar_config[source].item_list;
718 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
720 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
722 toolbar_item->file = g_strdup(t_item->file);
723 toolbar_item->text = g_strdup(t_item->text);
724 toolbar_item->index = t_item->index;
726 toolbar_config[source].item_list =
727 g_slist_append(toolbar_config[source].item_list,
731 void toolbar_action_execute(GtkWidget *widget,
737 gchar *action, *action_p;
738 gboolean found = FALSE;
741 for (cur = action_list; cur != NULL; cur = cur->next) {
742 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
744 if (widget == act->widget) {
746 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
747 action = g_strdup((gchar*)lop->data);
749 action_p = strstr(action, ": ");
751 if (g_utf8_collate(act->name, action) == 0) {
765 actions_execute(data, i, widget, source);
767 g_warning ("Error: did not find Claws Action to execute");
770 static void activate_compose_button (Toolbar *toolbar,
772 ComposeButtonType type)
774 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
777 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
778 : toolbar->compose_news_btn);
779 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
780 : toolbar->compose_mail_btn);
781 toolbar->compose_btn_type = type;
784 void toolbar_set_compose_button(Toolbar *toolbar,
785 ComposeButtonType compose_btn_type)
787 if (toolbar->compose_btn_type != compose_btn_type)
788 activate_compose_button(toolbar,
789 prefs_common.toolbar_style,
793 static void activate_learn_button (Toolbar *toolbar,
795 LearnButtonType type)
797 if ((!toolbar->learn_spam_btn) || (!toolbar->learn_ham_btn))
800 gtk_widget_hide(type == LEARN_SPAM ? toolbar->learn_ham_btn
801 : toolbar->learn_spam_btn);
802 gtk_widget_show(type == LEARN_SPAM ? toolbar->learn_spam_btn
803 : toolbar->learn_ham_btn);
804 toolbar->learn_btn_type = type;
807 void toolbar_set_learn_button(Toolbar *toolbar,
808 LearnButtonType learn_btn_type)
810 if (toolbar->learn_btn_type != learn_btn_type)
811 activate_learn_button(toolbar,
812 prefs_common.toolbar_style,
816 void toolbar_toggle(guint action, gpointer data)
818 MainWindow *mainwin = (MainWindow*)data;
822 g_return_if_fail(mainwin != NULL);
824 toolbar_style(TOOLBAR_MAIN, action, mainwin);
826 list = compose_get_compose_list();
827 for (cur = list; cur != NULL; cur = cur->next) {
828 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
830 list = messageview_get_msgview_list();
831 for (cur = list; cur != NULL; cur = cur->next) {
832 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
837 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
839 switch ((ToolbarStyle)action) {
841 gtk_widget_hide(handlebox_wid);
844 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
848 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
852 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
855 case TOOLBAR_BOTH_HORIZ:
856 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
857 GTK_TOOLBAR_BOTH_HORIZ);
863 prefs_common.toolbar_style = (ToolbarStyle)action;
864 gtk_widget_set_size_request(handlebox_wid, 1, -1);
866 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
867 gtk_widget_show(handlebox_wid);
868 gtk_widget_queue_resize(handlebox_wid);
872 * Change the style of toolbar
874 static void toolbar_style(ToolbarType type, guint action, gpointer data)
876 GtkWidget *handlebox_wid;
877 GtkWidget *toolbar_wid;
878 MainWindow *mainwin = (MainWindow*)data;
879 Compose *compose = (Compose*)data;
880 MessageView *msgview = (MessageView*)data;
882 g_return_if_fail(data != NULL);
886 handlebox_wid = mainwin->handlebox;
887 toolbar_wid = mainwin->toolbar->toolbar;
889 case TOOLBAR_COMPOSE:
890 handlebox_wid = compose->handlebox;
891 toolbar_wid = compose->toolbar->toolbar;
893 case TOOLBAR_MSGVIEW:
894 handlebox_wid = msgview->handlebox;
895 toolbar_wid = msgview->toolbar->toolbar;
901 toolbar_set_style(toolbar_wid, handlebox_wid, action);
904 /* Toolbar handling */
905 static void toolbar_inc_cb(GtkWidget *widget,
908 ToolbarItem *toolbar_item = (ToolbarItem*)data;
911 g_return_if_fail(toolbar_item != NULL);
913 switch (toolbar_item->type) {
915 mainwin = (MainWindow*)toolbar_item->parent;
916 inc_mail_cb(mainwin, 0, NULL);
923 static void toolbar_inc_all_cb(GtkWidget *widget,
926 ToolbarItem *toolbar_item = (ToolbarItem*)data;
929 g_return_if_fail(toolbar_item != NULL);
931 switch (toolbar_item->type) {
933 mainwin = (MainWindow*)toolbar_item->parent;
934 inc_all_account_mail_cb(mainwin, 0, NULL);
941 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
943 ToolbarItem *toolbar_item = (ToolbarItem*)data;
946 g_return_if_fail(toolbar_item != NULL);
948 switch (toolbar_item->type) {
950 mainwin = (MainWindow*)toolbar_item->parent;
951 send_queue_cb(mainwin, 0, NULL);
958 static void toolbar_exec_cb(GtkWidget *widget,
961 MainWindow *mainwin = get_mainwin(data);
963 g_return_if_fail(mainwin != NULL);
964 summary_execute(mainwin->summaryview);
968 * Delete current/selected(s) message(s)
970 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
972 ToolbarItem *toolbar_item = (ToolbarItem*)data;
975 g_return_if_fail(toolbar_item != NULL);
976 g_return_if_fail(toolbar_item->parent);
978 switch (toolbar_item->type) {
979 case TOOLBAR_MSGVIEW:
980 messageview_delete((MessageView *)toolbar_item->parent);
983 mainwin = (MainWindow *)toolbar_item->parent;
984 summary_delete_trash(mainwin->summaryview);
987 debug_print("toolbar event not supported\n");
993 * Delete current/selected(s) message(s)
995 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
997 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1000 g_return_if_fail(toolbar_item != NULL);
1001 g_return_if_fail(toolbar_item->parent);
1003 switch (toolbar_item->type) {
1004 case TOOLBAR_MSGVIEW:
1005 messageview_delete((MessageView *)toolbar_item->parent);
1008 mainwin = (MainWindow *)toolbar_item->parent;
1009 summary_delete(mainwin->summaryview);
1012 debug_print("toolbar event not supported\n");
1019 * Compose new message
1021 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1023 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1024 MainWindow *mainwin;
1025 MessageView *msgview;
1027 g_return_if_fail(toolbar_item != NULL);
1029 switch (toolbar_item->type) {
1031 mainwin = (MainWindow*)toolbar_item->parent;
1032 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1033 compose_news_cb(mainwin, 0, NULL);
1035 compose_mail_cb(mainwin, 0, NULL);
1037 case TOOLBAR_MSGVIEW:
1038 msgview = (MessageView*)toolbar_item->parent;
1039 compose_new_with_folderitem(NULL,
1040 msgview->msginfo->folder, NULL);
1043 debug_print("toolbar event not supported\n");
1047 static void toolbar_learn(gpointer data, guint as_spam)
1049 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1050 MainWindow *mainwin;
1051 MessageView *msgview;
1053 g_return_if_fail(toolbar_item != NULL);
1055 switch (toolbar_item->type) {
1057 mainwin = (MainWindow*)toolbar_item->parent;
1059 mainwindow_learn(mainwin, TRUE);
1061 mainwindow_learn(mainwin, FALSE);
1063 case TOOLBAR_MSGVIEW:
1064 msgview = (MessageView*)toolbar_item->parent;
1066 messageview_learn(msgview, TRUE);
1068 messageview_learn(msgview, FALSE);
1071 debug_print("toolbar event not supported\n");
1075 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1077 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1078 MainWindow *mainwin;
1079 MessageView *msgview;
1081 g_return_if_fail(toolbar_item != NULL);
1083 switch (toolbar_item->type) {
1085 mainwin = (MainWindow*)toolbar_item->parent;
1086 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1087 mainwindow_learn(mainwin, TRUE);
1089 mainwindow_learn(mainwin, FALSE);
1091 case TOOLBAR_MSGVIEW:
1092 msgview = (MessageView*)toolbar_item->parent;
1093 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1094 messageview_learn(msgview, TRUE);
1096 messageview_learn(msgview, FALSE);
1099 debug_print("toolbar event not supported\n");
1107 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1109 toolbar_reply(data, prefs_common.reply_with_quote ?
1110 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1115 * Reply message to Sender and All recipients
1117 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1120 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1121 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1126 * Reply to Mailing List
1128 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1131 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1132 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1137 * Reply to sender of message
1139 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1142 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1143 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1149 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1151 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1154 g_return_if_fail(toolbar_item != NULL);
1156 switch (toolbar_item->type) {
1158 case TOOLBAR_MSGVIEW:
1161 case TOOLBAR_COMPOSE:
1162 compose = (Compose *)toolbar_item->parent;
1167 addressbook_open(compose);
1172 * Forward current/selected(s) message(s)
1174 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1176 toolbar_reply(data, COMPOSE_FORWARD);
1180 * Goto Prev Unread Message
1182 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1184 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1185 MainWindow *mainwin;
1186 MessageView *msgview;
1188 g_return_if_fail(toolbar_item != NULL);
1190 switch (toolbar_item->type) {
1192 mainwin = (MainWindow*)toolbar_item->parent;
1193 summary_select_prev_unread(mainwin->summaryview);
1196 case TOOLBAR_MSGVIEW:
1197 msgview = (MessageView*)toolbar_item->parent;
1198 msgview->updating = TRUE;
1199 summary_select_prev_unread(msgview->mainwin->summaryview);
1200 msgview->updating = FALSE;
1202 if (msgview->deferred_destroy) {
1203 debug_print("messageview got away!\n");
1204 messageview_destroy(msgview);
1208 /* Now we need to update the messageview window */
1209 if (msgview->mainwin->summaryview->selected) {
1210 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1213 messageview_show(msgview, msginfo,
1214 msgview->all_headers);
1216 gtk_widget_destroy(msgview->window);
1220 debug_print("toolbar event not supported\n");
1225 * Goto Next Unread Message
1227 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1229 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1230 MainWindow *mainwin;
1231 MessageView *msgview;
1233 g_return_if_fail(toolbar_item != NULL);
1235 switch (toolbar_item->type) {
1237 mainwin = (MainWindow*)toolbar_item->parent;
1238 summary_select_next_unread(mainwin->summaryview);
1241 case TOOLBAR_MSGVIEW:
1242 msgview = (MessageView*)toolbar_item->parent;
1243 msgview->updating = TRUE;
1244 summary_select_next_unread(msgview->mainwin->summaryview);
1245 msgview->updating = FALSE;
1247 if (msgview->deferred_destroy) {
1248 debug_print("messageview got away!\n");
1249 messageview_destroy(msgview);
1253 /* Now we need to update the messageview window */
1254 if (msgview->mainwin->summaryview->selected) {
1255 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1258 messageview_show(msgview, msginfo,
1259 msgview->all_headers);
1261 gtk_widget_destroy(msgview->window);
1265 debug_print("toolbar event not supported\n");
1269 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1271 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1272 MainWindow *mainwin;
1274 g_return_if_fail(toolbar_item != NULL);
1276 switch (toolbar_item->type) {
1278 mainwin = (MainWindow *) toolbar_item->parent;
1279 summary_toggle_ignore_thread(mainwin->summaryview);
1281 case TOOLBAR_MSGVIEW:
1282 /* TODO: see toolbar_next_unread_cb() if you need
1283 * this in the message view */
1286 debug_print("toolbar event not supported\n");
1291 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1293 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1295 g_return_if_fail(toolbar_item != NULL);
1300 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1302 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1303 MainWindow *mainwin;
1305 g_return_if_fail(toolbar_item != NULL);
1307 switch (toolbar_item->type) {
1309 mainwin = (MainWindow *) toolbar_item->parent;
1310 summary_print(mainwin->summaryview);
1312 case TOOLBAR_MSGVIEW:
1313 /* TODO: see toolbar_next_unread_cb() if you need
1314 * this in the message view */
1317 debug_print("toolbar event not supported\n");
1322 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1324 compose_toolbar_cb(A_SEND, data);
1327 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1329 compose_toolbar_cb(A_SENDL, data);
1332 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1334 compose_toolbar_cb(A_DRAFT, data);
1337 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1339 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1340 MainWindow *mainwin;
1341 MessageView *messageview;
1344 g_return_if_fail(toolbar_item != NULL);
1346 switch (toolbar_item->type) {
1348 mainwin = (MainWindow *) toolbar_item->parent;
1349 app_will_exit(NULL, mainwin);
1351 case TOOLBAR_MSGVIEW:
1352 messageview = (MessageView *)toolbar_item->parent;
1353 messageview_destroy(messageview);
1355 case TOOLBAR_COMPOSE:
1356 compose = (Compose *)toolbar_item->parent;
1357 compose_close_toolbar(compose);
1362 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1364 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1365 MainWindow *mainwin;
1367 g_return_if_fail(toolbar_item != NULL);
1369 switch (toolbar_item->type) {
1371 mainwin = (MainWindow *) toolbar_item->parent;
1372 summary_open_row(NULL, mainwin->summaryview);
1374 case TOOLBAR_MSGVIEW:
1375 debug_print("toolbar event not supported\n");
1377 case TOOLBAR_COMPOSE:
1378 debug_print("toolbar event not supported\n");
1383 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1385 compose_toolbar_cb(A_INSERT, data);
1388 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1390 compose_toolbar_cb(A_ATTACH, data);
1393 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1395 compose_toolbar_cb(A_SIG, data);
1398 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1400 compose_toolbar_cb(A_EXTEDITOR, data);
1403 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1405 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1408 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1410 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1414 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1416 compose_toolbar_cb(A_CHECK_SPELLING, data);
1420 * Execute actions from toolbar
1422 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1424 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1425 GSList *action_list;
1426 MainWindow *mainwin;
1428 MessageView *msgview;
1429 gpointer parent = toolbar_item->parent;
1431 g_return_if_fail(toolbar_item != NULL);
1433 switch (toolbar_item->type) {
1435 mainwin = (MainWindow*)parent;
1436 action_list = mainwin->toolbar->action_list;
1438 case TOOLBAR_COMPOSE:
1439 compose = (Compose*)parent;
1440 action_list = compose->toolbar->action_list;
1442 case TOOLBAR_MSGVIEW:
1443 msgview = (MessageView*)parent;
1444 action_list = msgview->toolbar->action_list;
1447 debug_print("toolbar event not supported\n");
1450 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1453 static MainWindow *get_mainwin(gpointer data)
1455 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1456 MainWindow *mainwin = NULL;
1457 MessageView *msgview;
1459 g_return_val_if_fail(toolbar_item != NULL, NULL);
1461 switch(toolbar_item->type) {
1463 mainwin = (MainWindow*)toolbar_item->parent;
1465 case TOOLBAR_MSGVIEW:
1466 msgview = (MessageView*)toolbar_item->parent;
1467 mainwin = (MainWindow*)msgview->mainwin;
1476 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1478 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1479 MainWindow *mainwin = NULL;
1480 switch(toolbar_item->type) {
1482 mainwin = (MainWindow*)toolbar_item->parent;
1485 g_warning("wrong toolbar type\n");
1489 if (!mainwin->in_folder) {
1490 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1492 folderview_select(mainwin->folderview, item);
1495 gtk_widget_grab_focus(mainwin->folderview->ctree);
1496 mainwindow_exit_folder(mainwin);
1500 static void toolbar_buttons_cb(GtkWidget *widget,
1507 void (*func)(GtkWidget *widget, gpointer data);
1509 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1510 { A_RECEIVE_CUR, toolbar_inc_cb },
1511 { A_SEND_QUEUED, toolbar_send_queued_cb },
1512 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1513 { A_COMPOSE_NEWS, toolbar_compose_cb },
1514 { A_REPLY_MESSAGE, toolbar_reply_cb },
1515 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1516 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1517 { A_REPLY_ML, toolbar_reply_to_list_cb },
1518 { A_FORWARD, toolbar_forward_cb },
1519 { A_TRASH, toolbar_trash_cb },
1520 { A_DELETE_REAL, toolbar_delete_cb },
1521 { A_EXECUTE, toolbar_exec_cb },
1522 { A_GOTO_PREV, toolbar_prev_unread_cb },
1523 { A_GOTO_NEXT, toolbar_next_unread_cb },
1524 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1525 { A_PRINT, toolbar_print_cb },
1526 { A_LEARN_SPAM, toolbar_learn_cb },
1527 { A_GO_FOLDERS, toolbar_go_folders_cb },
1529 { A_SEND, toolbar_send_cb },
1530 { A_SENDL, toolbar_send_later_cb },
1531 { A_DRAFT, toolbar_draft_cb },
1532 { A_OPEN_MAIL, toolbar_open_mail_cb },
1533 { A_CLOSE, toolbar_close_cb },
1534 { A_INSERT, toolbar_insert_cb },
1535 { A_ATTACH, toolbar_attach_cb },
1536 { A_SIG, toolbar_sig_cb },
1537 { A_EXTEDITOR, toolbar_ext_editor_cb },
1538 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1539 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1540 { A_ADDRBOOK, toolbar_addrbook_cb },
1542 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1544 { A_SYL_ACTIONS, toolbar_actions_execute_cb },
1545 { A_CANCEL_INC, toolbar_cancel_inc_cb }
1548 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1550 for (i = 0; i < num_items; i++) {
1551 if (callbacks[i].index == item->index) {
1552 callbacks[i].func(widget, item);
1559 * Create a new toolbar with specified type
1560 * if a callback list is passed it will be used before the
1561 * common callback list
1563 Toolbar *toolbar_create(ToolbarType type,
1564 GtkWidget *container,
1567 ToolbarItem *toolbar_item;
1570 GtkWidget *icon_wid = NULL;
1571 GtkWidget *icon_news;
1572 GtkWidget *icon_ham;
1574 GtkWidget *item_news;
1575 GtkWidget *item_ham;
1576 guint n_menu_entries;
1577 ComboButton *getall_combo;
1578 ComboButton *reply_combo;
1579 ComboButton *replyall_combo;
1580 ComboButton *replylist_combo;
1581 ComboButton *replysender_combo;
1582 ComboButton *fwd_combo;
1583 ComboButton *compose_combo;
1584 ComboButton *ham_combo;
1586 GtkTooltips *toolbar_tips;
1587 ToolbarSylpheedActions *action_item;
1589 GSList *toolbar_list;
1590 Toolbar *toolbar_data;
1593 toolbar_tips = gtk_tooltips_new();
1595 toolbar_read_config_file(type);
1596 toolbar_list = toolbar_get_list(type);
1598 toolbar_data = g_new0(Toolbar, 1);
1600 toolbar = gtk_toolbar_new();
1601 gtk_container_add(GTK_CONTAINER(container), toolbar);
1602 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1603 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1604 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1606 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1608 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1609 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1613 toolbar_item = g_new0(ToolbarItem, 1);
1614 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1615 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1616 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1617 toolbar_item->parent = data;
1618 toolbar_item->type = type;
1620 /* collect toolbar items in list to keep track */
1621 toolbar_data->item_list =
1622 g_slist_append(toolbar_data->item_list,
1624 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1625 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1629 icon_wid, G_CALLBACK(toolbar_buttons_cb),
1632 switch (toolbar_item->index) {
1635 toolbar_data->folders_btn = item;
1636 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1637 toolbar_data->folders_btn,
1638 _("Go to folder list"), NULL);
1641 toolbar_data->getall_btn = item;
1642 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1643 toolbar_data->getall_btn,
1644 _("Receive Mail on all Accounts"), NULL);
1645 getall_combo = gtkut_combo_button_create(toolbar_data->getall_btn, NULL, 0,
1646 "<GetAll>", (gpointer)toolbar_item);
1647 gtk_button_set_relief(GTK_BUTTON(getall_combo->arrow),
1649 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1650 GTK_WIDGET_PTR(getall_combo),
1651 _("Receive Mail on selected Account"), "Reply");
1652 toolbar_data->getall_combo = getall_combo;
1655 toolbar_data->get_btn = item;
1656 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1657 toolbar_data->get_btn,
1658 _("Receive Mail on current Account"), NULL);
1661 toolbar_data->send_btn = item;
1662 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1663 toolbar_data->send_btn,
1664 _("Send Queued Messages"), NULL);
1667 toolbar_data->close_window_btn = item;
1668 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1669 toolbar_data->close_window_btn,
1670 _("Close window"), NULL);
1673 toolbar_data->open_mail_btn = item;
1674 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1675 toolbar_data->open_mail_btn,
1676 _("Open email"), NULL);
1678 case A_COMPOSE_EMAIL:
1679 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1680 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1684 icon_news, G_CALLBACK(toolbar_buttons_cb),
1686 toolbar_data->compose_mail_btn = item;
1687 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1688 toolbar_data->compose_mail_btn,
1689 _("Compose Email"), NULL);
1690 toolbar_data->compose_news_btn = item_news;
1691 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1692 toolbar_data->compose_news_btn,
1693 _("Compose News"), NULL);
1694 compose_combo = gtkut_combo_button_create(toolbar_data->compose_mail_btn, NULL, 0,
1695 "<Compose>", (gpointer)toolbar_item);
1696 gtk_button_set_relief(GTK_BUTTON(compose_combo->arrow),
1698 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1699 GTK_WIDGET_PTR(compose_combo),
1700 _("Compose with selected Account"), "Compose");
1701 toolbar_data->compose_combo = compose_combo;
1704 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1705 item_ham = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1709 icon_ham, G_CALLBACK(toolbar_buttons_cb),
1711 toolbar_data->learn_spam_btn = item;
1712 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1713 toolbar_data->learn_spam_btn,
1714 _("Learn Spam"), NULL);
1715 toolbar_data->learn_ham_btn = item_ham;
1716 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1717 toolbar_data->learn_ham_btn,
1718 _("Learn Ham"), NULL);
1719 n_menu_entries = sizeof(learn_entries) /
1720 sizeof(learn_entries[0]);
1721 ham_combo = gtkut_combo_button_create(toolbar_data->learn_spam_btn,
1722 learn_entries, n_menu_entries,
1723 "<LearnSpam>", (gpointer)toolbar_item);
1724 gtk_button_set_relief(GTK_BUTTON(ham_combo->arrow),
1726 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1727 GTK_WIDGET_PTR(ham_combo),
1728 _("Learn as..."), _("Learn"));
1729 toolbar_data->ham_combo = ham_combo;
1731 case A_REPLY_MESSAGE:
1732 toolbar_data->reply_btn = item;
1733 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1734 toolbar_data->reply_btn,
1735 _("Reply to Message"), NULL);
1736 n_menu_entries = sizeof(reply_entries) /
1737 sizeof(reply_entries[0]);
1738 reply_combo = gtkut_combo_button_create(toolbar_data->reply_btn,
1739 reply_entries, n_menu_entries,
1740 "<Reply>", (gpointer)toolbar_item);
1741 gtk_button_set_relief(GTK_BUTTON(reply_combo->arrow),
1743 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1744 GTK_WIDGET_PTR(reply_combo),
1745 _("Reply to Message"), "Reply");
1746 toolbar_data->reply_combo = reply_combo;
1748 case A_REPLY_SENDER:
1749 toolbar_data->replysender_btn = item;
1750 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1751 toolbar_data->replysender_btn,
1752 _("Reply to Sender"), NULL);
1753 n_menu_entries = sizeof(replysender_entries) /
1754 sizeof(replysender_entries[0]);
1755 replysender_combo = gtkut_combo_button_create(toolbar_data->replysender_btn,
1756 replysender_entries, n_menu_entries,
1757 "<ReplySender>", (gpointer)toolbar_item);
1758 gtk_button_set_relief(GTK_BUTTON(replysender_combo->arrow),
1760 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1761 GTK_WIDGET_PTR(replysender_combo),
1762 _("Reply to Sender"), "ReplySender");
1763 toolbar_data->replysender_combo = replysender_combo;
1766 toolbar_data->replyall_btn = item;
1767 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1768 toolbar_data->replyall_btn,
1769 _("Reply to All"), NULL);
1770 n_menu_entries = sizeof(replyall_entries) /
1771 sizeof(replyall_entries[0]);
1772 replyall_combo = gtkut_combo_button_create(toolbar_data->replyall_btn,
1773 replyall_entries, n_menu_entries,
1774 "<ReplyAll>", (gpointer)toolbar_item);
1775 gtk_button_set_relief(GTK_BUTTON(replyall_combo->arrow),
1777 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1778 GTK_WIDGET_PTR(replyall_combo),
1779 _("Reply to All"), "ReplyAll");
1780 toolbar_data->replyall_combo = replyall_combo;
1783 toolbar_data->replylist_btn = item;
1784 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1785 toolbar_data->replylist_btn,
1786 _("Reply to Mailing-list"), NULL);
1787 n_menu_entries = sizeof(replylist_entries) /
1788 sizeof(replylist_entries[0]);
1789 replylist_combo = gtkut_combo_button_create(toolbar_data->replylist_btn,
1790 replylist_entries, n_menu_entries,
1791 "<ReplyList>", (gpointer)toolbar_item);
1792 gtk_button_set_relief(GTK_BUTTON(replylist_combo->arrow),
1794 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1795 GTK_WIDGET_PTR(replylist_combo),
1796 _("Reply to Mailing-list"), "ReplyList");
1797 toolbar_data->replylist_combo = replylist_combo;
1800 toolbar_data->fwd_btn = item;
1801 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1802 toolbar_data->fwd_btn,
1803 _("Forward Message"), NULL);
1804 n_menu_entries = sizeof(forward_entries) /
1805 sizeof(forward_entries[0]);
1806 fwd_combo = gtkut_combo_button_create(toolbar_data->fwd_btn,
1807 forward_entries, n_menu_entries,
1808 "<Forward>", (gpointer)toolbar_item);
1809 gtk_button_set_relief(GTK_BUTTON(fwd_combo->arrow),
1811 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1812 GTK_WIDGET_PTR(fwd_combo),
1813 _("Forward Message"), "Fwd");
1814 toolbar_data->fwd_combo = fwd_combo;
1817 toolbar_data->trash_btn = item;
1818 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1819 toolbar_data->trash_btn,
1820 _("Trash Message"), NULL);
1823 toolbar_data->delete_btn = item;
1824 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1825 toolbar_data->delete_btn,
1826 _("Delete Message"), NULL);
1829 toolbar_data->exec_btn = item;
1830 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1831 toolbar_data->exec_btn,
1832 _("Execute"), NULL);
1835 toolbar_data->prev_btn = item;
1836 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1837 toolbar_data->prev_btn,
1838 _("Go to Previous Unread Message"),
1842 toolbar_data->next_btn = item;
1843 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1844 toolbar_data->next_btn,
1845 _("Go to Next Unread Message"),
1849 /* Compose Toolbar */
1851 toolbar_data->send_btn = item;
1852 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1853 toolbar_data->send_btn,
1854 _("Send Message"), NULL);
1857 toolbar_data->sendl_btn = item;
1858 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1859 toolbar_data->sendl_btn,
1860 _("Put into queue folder and send later"), NULL);
1863 toolbar_data->draft_btn = item;
1864 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1865 toolbar_data->draft_btn,
1866 _("Save to draft folder"), NULL);
1869 toolbar_data->insert_btn = item;
1870 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1871 toolbar_data->insert_btn,
1872 _("Insert file"), NULL);
1875 toolbar_data->attach_btn = item;
1876 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1877 toolbar_data->attach_btn,
1878 _("Attach file"), NULL);
1881 toolbar_data->sig_btn = item;
1882 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1883 toolbar_data->sig_btn,
1884 _("Insert signature"), NULL);
1887 toolbar_data->exteditor_btn = item;
1888 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1889 toolbar_data->exteditor_btn,
1890 _("Edit with external editor"), NULL);
1892 case A_LINEWRAP_CURRENT:
1893 toolbar_data->linewrap_current_btn = item;
1894 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1895 toolbar_data->linewrap_current_btn,
1896 _("Wrap long lines of current paragraph"), NULL);
1898 case A_LINEWRAP_ALL:
1899 toolbar_data->linewrap_all_btn = item;
1900 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1901 toolbar_data->linewrap_all_btn,
1902 _("Wrap all long lines"), NULL);
1905 toolbar_data->addrbook_btn = item;
1906 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1907 toolbar_data->addrbook_btn,
1908 _("Address book"), NULL);
1911 case A_CHECK_SPELLING:
1912 toolbar_data->spellcheck_btn = item;
1913 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1914 toolbar_data->spellcheck_btn,
1915 _("Check spelling"), NULL);
1920 action_item = g_new0(ToolbarSylpheedActions, 1);
1921 action_item->widget = item;
1922 action_item->name = g_strdup(toolbar_item->text);
1924 toolbar_data->action_list =
1925 g_slist_append(toolbar_data->action_list,
1928 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1930 action_item->name, NULL);
1932 gtk_widget_show(item);
1935 toolbar_data->cancel_inc_btn = item;
1936 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1937 toolbar_data->cancel_inc_btn,
1938 _("Cancel receiving"), NULL);
1941 /* find and set the tool tip text */
1942 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1944 toolbar_ret_descr_from_val
1945 (toolbar_item->index),
1951 toolbar_data->toolbar = toolbar;
1952 if (type == TOOLBAR_MAIN)
1953 activate_compose_button(toolbar_data,
1954 prefs_common.toolbar_style,
1955 toolbar_data->compose_btn_type);
1956 if (type != TOOLBAR_COMPOSE)
1957 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
1960 gtk_widget_show_all(toolbar);
1962 return toolbar_data;
1966 * Free toolbar structures
1968 void toolbar_destroy(Toolbar * toolbar) {
1970 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1971 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1974 void toolbar_update(ToolbarType type, gpointer data)
1976 Toolbar *toolbar_data;
1977 GtkWidget *handlebox;
1978 MainWindow *mainwin = (MainWindow*)data;
1979 Compose *compose = (Compose*)data;
1980 MessageView *msgview = (MessageView*)data;
1984 toolbar_data = mainwin->toolbar;
1985 handlebox = mainwin->handlebox;
1987 case TOOLBAR_COMPOSE:
1988 toolbar_data = compose->toolbar;
1989 handlebox = compose->handlebox;
1991 case TOOLBAR_MSGVIEW:
1992 toolbar_data = msgview->toolbar;
1993 handlebox = msgview->handlebox;
1999 gtk_container_remove(GTK_CONTAINER(handlebox),
2000 GTK_WIDGET(toolbar_data->toolbar));
2002 toolbar_init(toolbar_data);
2003 toolbar_data = toolbar_create(type, handlebox, data);
2006 mainwin->toolbar = toolbar_data;
2008 case TOOLBAR_COMPOSE:
2009 compose->toolbar = toolbar_data;
2011 case TOOLBAR_MSGVIEW:
2012 msgview->toolbar = toolbar_data;
2016 toolbar_style(type, prefs_common.toolbar_style, data);
2018 if (type == TOOLBAR_MAIN) {
2019 toolbar_main_set_sensitive((MainWindow*)data);
2020 account_set_menu_only_toolbar();
2024 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2025 gboolean in_btn = FALSE; \
2026 if (GTK_IS_BUTTON(widget)) \
2027 in_btn = GTK_BUTTON(widget)->in_button; \
2028 gtk_widget_set_sensitive(widget, sensitive); \
2029 if (GTK_IS_BUTTON(widget)) \
2030 GTK_BUTTON(widget)->in_button = in_btn; \
2033 void toolbar_main_set_sensitive(gpointer data)
2035 SensitiveCond state;
2037 MainWindow *mainwin = (MainWindow*)data;
2038 Toolbar *toolbar = mainwin->toolbar;
2040 GSList *entry_list = NULL;
2042 typedef struct _Entry Entry;
2049 #define SET_WIDGET_COND(w, c) \
2051 Entry *e = g_new0(Entry, 1); \
2054 entry_list = g_slist_append(entry_list, e); \
2058 if (toolbar->get_btn)
2059 SET_WIDGET_COND(toolbar->get_btn,
2060 M_HAVE_ACCOUNT|M_UNLOCKED);
2062 if (toolbar->getall_btn) {
2063 SET_WIDGET_COND(toolbar->getall_btn,
2064 M_HAVE_ACCOUNT|M_UNLOCKED);
2065 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->getall_combo),
2066 M_HAVE_ACCOUNT|M_UNLOCKED);
2068 if (toolbar->send_btn) {
2069 SET_WIDGET_COND(toolbar->send_btn,
2070 M_HAVE_QUEUED_MAILS);
2072 if (toolbar->compose_mail_btn) {
2073 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->compose_combo),
2075 SET_WIDGET_COND(toolbar->compose_news_btn,
2078 if (toolbar->close_window_btn) {
2079 SET_WIDGET_COND(toolbar->compose_news_btn,
2082 if (toolbar->open_mail_btn) {
2083 SET_WIDGET_COND(toolbar->open_mail_btn,
2086 if (toolbar->reply_btn) {
2087 SET_WIDGET_COND(toolbar->reply_btn,
2088 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2089 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->reply_combo),
2090 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2092 if (toolbar->replyall_btn) {
2093 SET_WIDGET_COND(toolbar->replyall_btn,
2094 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2095 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replyall_combo),
2096 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2098 if (toolbar->replylist_btn) {
2099 SET_WIDGET_COND(toolbar->replylist_btn,
2100 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2101 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replylist_combo),
2102 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2104 if (toolbar->replysender_btn) {
2105 SET_WIDGET_COND(toolbar->replysender_btn,
2106 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2107 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replysender_combo),
2108 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2110 if (toolbar->fwd_btn) {
2111 SET_WIDGET_COND(toolbar->fwd_btn,
2112 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2113 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->fwd_combo),
2114 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2116 if (toolbar->fwd_combo) {
2117 GtkWidget *submenu = gtk_item_factory_get_widget(toolbar->fwd_combo->factory, "/Redirect");
2118 SET_WIDGET_COND(submenu,
2119 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2122 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2123 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
2125 SET_WIDGET_COND(toolbar->next_btn, 0);
2128 if (toolbar->trash_btn)
2129 SET_WIDGET_COND(toolbar->trash_btn,
2130 M_TARGET_EXIST|M_ALLOW_DELETE);
2132 if (toolbar->delete_btn)
2133 SET_WIDGET_COND(toolbar->delete_btn,
2134 M_TARGET_EXIST|M_ALLOW_DELETE);
2136 if (toolbar->exec_btn)
2137 SET_WIDGET_COND(toolbar->exec_btn,
2140 if (toolbar->learn_ham_btn)
2141 SET_WIDGET_COND(toolbar->learn_ham_btn,
2142 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2144 if (toolbar->learn_spam_btn)
2145 SET_WIDGET_COND(toolbar->learn_spam_btn,
2146 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2148 if (toolbar->ham_combo)
2149 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->ham_combo),
2150 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2152 if (toolbar->cancel_inc_btn)
2153 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2156 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2157 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
2159 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2162 #undef SET_WIDGET_COND
2164 state = main_window_get_current_state(mainwin);
2166 for (cur = entry_list; cur != NULL; cur = cur->next) {
2167 Entry *e = (Entry*) cur->data;
2169 if (e->widget != NULL) {
2170 sensitive = ((e->cond & state) == e->cond);
2171 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2175 while (entry_list != NULL) {
2176 Entry *e = (Entry*) entry_list->data;
2179 entry_list = g_slist_remove(entry_list, e);
2182 g_slist_free(entry_list);
2184 activate_compose_button(toolbar,
2185 prefs_common.toolbar_style,
2186 toolbar->compose_btn_type);
2190 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2192 Compose *compose = (Compose*)data;
2193 GSList *items = compose->toolbar->action_list;
2195 if (compose->toolbar->send_btn)
2196 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2197 if (compose->toolbar->sendl_btn)
2198 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2199 if (compose->toolbar->draft_btn )
2200 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2201 if (compose->toolbar->insert_btn )
2202 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2203 if (compose->toolbar->attach_btn)
2204 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2205 if (compose->toolbar->sig_btn)
2206 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2207 if (compose->toolbar->exteditor_btn)
2208 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2209 if (compose->toolbar->linewrap_current_btn)
2210 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2211 if (compose->toolbar->linewrap_all_btn)
2212 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2213 if (compose->toolbar->addrbook_btn)
2214 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2216 if (compose->toolbar->spellcheck_btn)
2217 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2219 for (; items != NULL; items = g_slist_next(items)) {
2220 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
2221 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2226 * Initialize toolbar structure
2228 void toolbar_init(Toolbar * toolbar) {
2230 toolbar->toolbar = NULL;
2231 toolbar->folders_btn = NULL;
2232 toolbar->get_btn = NULL;
2233 toolbar->getall_btn = NULL;
2234 toolbar->getall_combo = NULL;
2235 toolbar->send_btn = NULL;
2236 toolbar->compose_mail_btn = NULL;
2237 toolbar->compose_news_btn = NULL;
2238 toolbar->compose_combo = NULL;
2239 toolbar->reply_btn = NULL;
2240 toolbar->replysender_btn = NULL;
2241 toolbar->replyall_btn = NULL;
2242 toolbar->replylist_btn = NULL;
2243 toolbar->fwd_btn = NULL;
2244 toolbar->trash_btn = NULL;
2245 toolbar->delete_btn = NULL;
2246 toolbar->prev_btn = NULL;
2247 toolbar->next_btn = NULL;
2248 toolbar->exec_btn = NULL;
2249 toolbar->open_mail_btn = NULL;
2250 toolbar->close_window_btn = NULL;
2251 /* compose buttons */
2252 toolbar->sendl_btn = NULL;
2253 toolbar->draft_btn = NULL;
2254 toolbar->insert_btn = NULL;
2255 toolbar->attach_btn = NULL;
2256 toolbar->sig_btn = NULL;
2257 toolbar->exteditor_btn = NULL;
2258 toolbar->linewrap_current_btn = NULL;
2259 toolbar->linewrap_all_btn = NULL;
2260 toolbar->addrbook_btn = NULL;
2262 toolbar->spellcheck_btn = NULL;
2265 toolbar_destroy(toolbar);
2270 static void toolbar_reply(gpointer data, guint action)
2272 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2273 MainWindow *mainwin;
2274 MessageView *msgview;
2275 GSList *msginfo_list = NULL;
2277 g_return_if_fail(toolbar_item != NULL);
2279 switch (toolbar_item->type) {
2281 mainwin = (MainWindow*)toolbar_item->parent;
2282 msginfo_list = summary_get_selection(mainwin->summaryview);
2283 msgview = (MessageView*)mainwin->messageview;
2285 case TOOLBAR_MSGVIEW:
2286 msgview = (MessageView*)toolbar_item->parent;
2287 g_return_if_fail(msgview != NULL);
2288 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2294 g_return_if_fail(msgview != NULL);
2295 g_return_if_fail(msginfo_list != NULL);
2296 compose_reply_from_messageview(msgview, msginfo_list, action);
2297 g_slist_free(msginfo_list);
2299 /* TODO: update reply state ion summaryview */
2303 /* exported functions */
2305 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2307 MainWindow *mainwin = (MainWindow*)data;
2309 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2312 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2314 MainWindow *mainwin = (MainWindow*)data;
2316 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2319 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2323 gboolean got_error = FALSE;
2324 gchar *errstr = NULL;
2326 if (prefs_common.work_offline)
2327 if (alertpanel(_("Offline warning"),
2328 _("You're working offline. Override?"),
2329 GTK_STOCK_NO, GTK_STOCK_YES,
2330 NULL) != G_ALERTALTERNATE)
2333 /* ask for confirmation before sending queued messages only
2334 in online mode and if there is at least one message queued
2335 in any of the folder queue
2337 if (prefs_common.confirm_send_queued_messages) {
2339 /* check if there's a queued message */
2340 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2341 Folder *folder = list->data;
2343 found = !procmsg_queue_is_empty(folder->queue);
2345 /* if necessary, ask for confirmation before sending */
2346 if (found && !prefs_common.work_offline) {
2347 if (alertpanel(_("Send queued messages"),
2348 _("Send all queued messages?"),
2349 GTK_STOCK_CANCEL, _("_Send"),
2350 NULL) != G_ALERTALTERNATE)
2355 for (list = folder_get_list(); list != NULL; list = list->next) {
2356 Folder *folder = list->data;
2358 if (folder->queue) {
2359 if (procmsg_send_queue(folder->queue,
2360 prefs_common.savemsg,
2367 alertpanel_error_log(_("Some errors occurred while "
2368 "sending queued messages."));
2370 gchar *tmp = g_strdup_printf(_("Some errors occurred "
2371 "while sending queued messages:\n%s"), errstr);
2373 alertpanel_error_log(tmp);
2379 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2381 MainWindow *mainwin = (MainWindow*)data;
2382 PrefsAccount *ac = NULL;
2383 FolderItem *item = mainwin->summaryview->folder_item;
2388 ac = account_find_from_item(item);
2389 if (ac && ac->protocol != A_NNTP) {
2390 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2396 * CLAWS - use current account
2398 if (cur_account && (cur_account->protocol != A_NNTP)) {
2399 compose_new_with_folderitem(cur_account, item, NULL);
2404 * CLAWS - just get the first one
2406 list = account_get_list();
2407 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2408 ac = (PrefsAccount *) cur->data;
2409 if (ac->protocol != A_NNTP) {
2410 compose_new_with_folderitem(ac, item, NULL);
2416 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2418 MainWindow *mainwin = (MainWindow*)data;
2419 PrefsAccount * ac = NULL;
2423 if (mainwin->summaryview->folder_item) {
2424 ac = mainwin->summaryview->folder_item->folder->account;
2425 if (ac && ac->protocol == A_NNTP) {
2426 compose_new_with_folderitem(ac,
2427 mainwin->summaryview->folder_item, NULL);
2432 list = account_get_list();
2433 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2434 ac = (PrefsAccount *) cur->data;
2435 if (ac->protocol == A_NNTP) {
2436 compose_new_with_folderitem(ac,
2437 mainwin->summaryview->folder_item, NULL);