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") },
191 { "A_SEND", N_("Send Message") },
192 { "A_SENDL", N_("Put into queue folder and send later") },
193 { "A_DRAFT", N_("Save to draft folder") },
194 { "A_INSERT", N_("Insert file") },
195 { "A_ATTACH", N_("Attach file") },
196 { "A_SIG", N_("Insert signature") },
197 { "A_EXTEDITOR", N_("Edit with external editor") },
198 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
199 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
200 { "A_ADDRBOOK", N_("Address book") },
202 { "A_CHECK_SPELLING", N_("Check spelling") },
204 { "A_SYL_ACTIONS", N_("Claws Mail Actions Feature") },
205 { "A_CANCEL_INC", N_("Cancel receiving") },
206 { "A_CLOSE", N_("Close window") },
207 { "A_SEPARATOR", "Separator" }
210 /* struct holds configuration files and a list of
211 * currently active toolbar items
212 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
216 const gchar *conf_file;
218 } toolbar_config[3] = {
219 { "toolbar_main.xml", NULL},
220 { "toolbar_compose.xml", NULL},
221 { "toolbar_msgview.xml", NULL}
224 static GtkItemFactoryEntry reply_entries[] =
226 {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
227 {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
229 static GtkItemFactoryEntry replyall_entries[] =
231 {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
232 {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
234 static GtkItemFactoryEntry replylist_entries[] =
236 {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
237 {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
239 static GtkItemFactoryEntry replysender_entries[] =
241 {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
242 {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
244 static GtkItemFactoryEntry forward_entries[] =
246 {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
247 {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
248 {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, NULL}
250 static GtkItemFactoryEntry learn_entries[] =
252 {N_("/Learn as _Spam"), NULL, toolbar_learn, TRUE, NULL},
253 {N_("/Learn as _Ham"), NULL, toolbar_learn, FALSE, NULL}
257 gint toolbar_ret_val_from_descr(const gchar *descr)
261 for (i = 0; i < N_ACTION_VAL; i++) {
262 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
269 gchar *toolbar_ret_descr_from_val(gint val)
271 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
273 return gettext(toolbar_text[val].descr);
276 static gint toolbar_ret_val_from_text(const gchar *text)
280 for (i = 0; i < N_ACTION_VAL; i++) {
281 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
288 static gchar *toolbar_ret_text_from_val(gint val)
290 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
292 return toolbar_text[val].index_str;
295 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
299 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
302 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
303 ToolbarItem *item = (ToolbarItem*) cur->data;
305 if (item->index == action)
311 /* depending on toolbar type this function
312 returns a list of available toolbar events being
313 displayed by prefs_toolbar
315 GList *toolbar_get_action_items(ToolbarType source)
320 if (source == TOOLBAR_MAIN) {
321 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
322 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
323 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
324 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
325 A_GOTO_NEXT, A_IGNORE_THREAD, A_PRINT,
326 A_ADDRBOOK, A_LEARN_SPAM, A_SYL_ACTIONS, A_CANCEL_INC };
328 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
329 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
332 else if (source == TOOLBAR_COMPOSE) {
333 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
334 A_INSERT, A_ATTACH, A_SIG,
335 A_EXTEDITOR, A_LINEWRAP_CURRENT,
336 A_LINEWRAP_ALL, A_ADDRBOOK,
340 A_SYL_ACTIONS, A_CLOSE };
342 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
343 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
345 else if (source == TOOLBAR_MSGVIEW) {
346 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
347 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
348 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
349 A_ADDRBOOK, A_LEARN_SPAM, A_SYL_ACTIONS, A_CLOSE };
351 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
352 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
358 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
362 ToolbarItem *item = NULL;
363 gboolean rewrite = FALSE;
365 attr = xml_get_current_tag_attr(file);
366 item = g_new0(ToolbarItem, 1);
368 name = ((XMLAttr *)attr->data)->name;
369 value = ((XMLAttr *)attr->data)->value;
371 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
372 item->file = g_strdup (value);
373 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
374 item->text = g_strdup (gettext(value));
375 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
376 item->index = toolbar_ret_val_from_text(value);
377 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
379 item->index = A_TRASH;
381 item->file = g_strdup("trash_btn");
383 item->text = g_strdup(_("Trash"));
386 attr = g_list_next(attr);
388 if (item->index != -1) {
390 if (!toolbar_is_duplicate(item->index, source))
391 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
395 toolbar_save_config_file(source);
399 static void toolbar_set_default_main(void)
405 } default_toolbar[] = {
406 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get Mail") },
407 { A_SEPARATOR, 0, ("") },
408 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
409 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE,
410 (gchar*)Q_("Toolbar|Compose") },
411 { A_SEPARATOR, 0, ("") },
413 { A_OPEN_MAIL, STOCK_PIXMAP_OPEN_MAIL, _("Open") },
415 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
417 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
418 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
420 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
421 { A_SEPARATOR, 0, ("") },
422 { A_TRASH, STOCK_PIXMAP_TRASH, _("Trash") },
423 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
424 { A_LEARN_SPAM, STOCK_PIXMAP_SPAM_BTN, _("Spam") },
426 { A_SEPARATOR, 0, ("") },
427 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
432 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
434 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
436 if (default_toolbar[i].action != A_SEPARATOR) {
438 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
440 toolbar_item->file = g_strdup(file);
441 toolbar_item->index = default_toolbar[i].action;
442 toolbar_item->text = g_strdup(default_toolbar[i].text);
445 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
446 toolbar_item->index = A_SEPARATOR;
449 if (toolbar_item->index != -1) {
450 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
451 toolbar_config[TOOLBAR_MAIN].item_list =
452 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
457 static void toolbar_set_default_compose(void)
463 } default_toolbar[] = {
464 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
465 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
466 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
467 { A_SEPARATOR, 0, ("") },
469 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
471 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
472 { A_SEPARATOR, 0, ("") },
473 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
476 { A_SEPARATOR, 0, ("") },
477 { A_CLOSE, STOCK_PIXMAP_CLOSE, _("Close") }
483 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
485 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
487 if (default_toolbar[i].action != A_SEPARATOR) {
489 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
491 toolbar_item->file = g_strdup(file);
492 toolbar_item->index = default_toolbar[i].action;
493 toolbar_item->text = g_strdup(default_toolbar[i].text);
496 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
497 toolbar_item->index = A_SEPARATOR;
500 if (toolbar_item->index != -1) {
501 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
502 toolbar_config[TOOLBAR_COMPOSE].item_list =
503 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
508 static void toolbar_set_default_msgview(void)
514 } default_toolbar[] = {
515 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
516 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
517 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
518 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
519 { A_SEPARATOR, 0, ("") },
520 { A_TRASH, STOCK_PIXMAP_TRASH, _("Trash") },
521 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
522 { A_LEARN_SPAM, STOCK_PIXMAP_SPAM_BTN, _("Spam") },
524 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
527 { A_SEPARATOR, 0, ("") },
528 { A_CLOSE, STOCK_PIXMAP_CLOSE, _("Close") }
534 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
536 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
538 if (default_toolbar[i].action != A_SEPARATOR) {
540 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
542 toolbar_item->file = g_strdup(file);
543 toolbar_item->index = default_toolbar[i].action;
544 toolbar_item->text = g_strdup(default_toolbar[i].text);
547 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
548 toolbar_item->index = A_SEPARATOR;
551 if (toolbar_item->index != -1) {
552 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
553 toolbar_config[TOOLBAR_MSGVIEW].item_list =
554 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
559 void toolbar_set_default(ToolbarType source)
561 if (source == TOOLBAR_MAIN)
562 toolbar_set_default_main();
563 else if (source == TOOLBAR_COMPOSE)
564 toolbar_set_default_compose();
565 else if (source == TOOLBAR_MSGVIEW)
566 toolbar_set_default_msgview();
569 void toolbar_save_config_file(ToolbarType source)
574 gchar *fileSpec = NULL;
576 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
578 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
579 pfile = prefs_write_open(fileSpec);
583 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL);
585 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
587 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
588 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
590 if (toolbar_item->index != A_SEPARATOR) {
591 fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
593 TOOLBAR_ICON_FILE, toolbar_item->file,
595 xml_file_put_escape_str(fp, toolbar_item->text);
596 fprintf(fp, "\" %s=\"%s\"/>\n",
598 toolbar_ret_text_from_val(toolbar_item->index));
600 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
604 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
606 if (prefs_file_close (pfile) < 0 )
607 g_warning("failed to write toolbar configuration to file\n");
609 g_warning("failed to open toolbar configuration file for writing\n");
612 void toolbar_read_config_file(ToolbarType source)
614 XMLFile *file = NULL;
615 gchar *fileSpec = NULL;
620 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
622 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
623 file = xml_open_file(fileSpec);
626 toolbar_clear_list(source);
630 || (xml_get_dtd(file))
631 || (xml_parse_next_tag(file))
632 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
633 xml_close_file(file);
637 attr = xml_get_current_tag_attr(file);
644 if (xml_parse_next_tag(file))
647 /* Get next tag (icon, icon_text or icon_action) */
648 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
649 toolbar_parse_item(file, source);
650 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
651 ToolbarItem *item = g_new0(ToolbarItem, 1);
653 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
654 item->index = A_SEPARATOR;
655 toolbar_config[source].item_list =
656 g_slist_append(toolbar_config[source].item_list, item);
660 xml_close_file(file);
663 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
665 if (source == TOOLBAR_MAIN)
666 toolbar_set_default(TOOLBAR_MAIN);
667 else if (source == TOOLBAR_COMPOSE)
668 toolbar_set_default(TOOLBAR_COMPOSE);
669 else if (source == TOOLBAR_MSGVIEW)
670 toolbar_set_default(TOOLBAR_MSGVIEW);
672 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
676 toolbar_save_config_file(source);
681 * clears list of toolbar items read from configuration files
683 void toolbar_clear_list(ToolbarType source)
685 while (toolbar_config[source].item_list != NULL) {
686 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
688 toolbar_config[source].item_list =
689 g_slist_remove(toolbar_config[source].item_list, item);
695 g_slist_free(toolbar_config[source].item_list);
700 * return list of Toolbar items
702 GSList *toolbar_get_list(ToolbarType source)
706 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
707 list = toolbar_config[source].item_list;
712 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
714 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
716 toolbar_item->file = g_strdup(t_item->file);
717 toolbar_item->text = g_strdup(t_item->text);
718 toolbar_item->index = t_item->index;
720 toolbar_config[source].item_list =
721 g_slist_append(toolbar_config[source].item_list,
725 void toolbar_action_execute(GtkWidget *widget,
731 gchar *action, *action_p;
732 gboolean found = FALSE;
735 for (cur = action_list; cur != NULL; cur = cur->next) {
736 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
738 if (widget == act->widget) {
740 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
741 action = g_strdup((gchar*)lop->data);
743 action_p = strstr(action, ": ");
745 if (g_utf8_collate(act->name, action) == 0) {
759 actions_execute(data, i, widget, source);
761 g_warning ("Error: did not find Claws Action to execute");
764 static void activate_compose_button (Toolbar *toolbar,
766 ComposeButtonType type)
768 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
771 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
772 : toolbar->compose_news_btn);
773 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
774 : toolbar->compose_mail_btn);
775 toolbar->compose_btn_type = type;
778 void toolbar_set_compose_button(Toolbar *toolbar,
779 ComposeButtonType compose_btn_type)
781 if (toolbar->compose_btn_type != compose_btn_type)
782 activate_compose_button(toolbar,
783 prefs_common.toolbar_style,
787 static void activate_learn_button (Toolbar *toolbar,
789 LearnButtonType type)
791 if ((!toolbar->learn_spam_btn) || (!toolbar->learn_ham_btn))
794 gtk_widget_hide(type == LEARN_SPAM ? toolbar->learn_ham_btn
795 : toolbar->learn_spam_btn);
796 gtk_widget_show(type == LEARN_SPAM ? toolbar->learn_spam_btn
797 : toolbar->learn_ham_btn);
798 toolbar->learn_btn_type = type;
801 void toolbar_set_learn_button(Toolbar *toolbar,
802 LearnButtonType learn_btn_type)
804 if (toolbar->learn_btn_type != learn_btn_type)
805 activate_learn_button(toolbar,
806 prefs_common.toolbar_style,
810 void toolbar_toggle(guint action, gpointer data)
812 MainWindow *mainwin = (MainWindow*)data;
816 g_return_if_fail(mainwin != NULL);
818 toolbar_style(TOOLBAR_MAIN, action, mainwin);
820 list = compose_get_compose_list();
821 for (cur = list; cur != NULL; cur = cur->next) {
822 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
824 list = messageview_get_msgview_list();
825 for (cur = list; cur != NULL; cur = cur->next) {
826 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
831 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
833 switch ((ToolbarStyle)action) {
835 gtk_widget_hide(handlebox_wid);
838 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
842 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
846 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
849 case TOOLBAR_BOTH_HORIZ:
850 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
851 GTK_TOOLBAR_BOTH_HORIZ);
857 prefs_common.toolbar_style = (ToolbarStyle)action;
858 gtk_widget_set_size_request(handlebox_wid, 1, -1);
860 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
861 gtk_widget_show(handlebox_wid);
862 gtk_widget_queue_resize(handlebox_wid);
866 * Change the style of toolbar
868 static void toolbar_style(ToolbarType type, guint action, gpointer data)
870 GtkWidget *handlebox_wid;
871 GtkWidget *toolbar_wid;
872 MainWindow *mainwin = (MainWindow*)data;
873 Compose *compose = (Compose*)data;
874 MessageView *msgview = (MessageView*)data;
876 g_return_if_fail(data != NULL);
880 handlebox_wid = mainwin->handlebox;
881 toolbar_wid = mainwin->toolbar->toolbar;
883 case TOOLBAR_COMPOSE:
884 handlebox_wid = compose->handlebox;
885 toolbar_wid = compose->toolbar->toolbar;
887 case TOOLBAR_MSGVIEW:
888 handlebox_wid = msgview->handlebox;
889 toolbar_wid = msgview->toolbar->toolbar;
895 toolbar_set_style(toolbar_wid, handlebox_wid, action);
898 /* Toolbar handling */
899 static void toolbar_inc_cb(GtkWidget *widget,
902 ToolbarItem *toolbar_item = (ToolbarItem*)data;
905 g_return_if_fail(toolbar_item != NULL);
907 switch (toolbar_item->type) {
909 mainwin = (MainWindow*)toolbar_item->parent;
910 inc_mail_cb(mainwin, 0, NULL);
917 static void toolbar_inc_all_cb(GtkWidget *widget,
920 ToolbarItem *toolbar_item = (ToolbarItem*)data;
923 g_return_if_fail(toolbar_item != NULL);
925 switch (toolbar_item->type) {
927 mainwin = (MainWindow*)toolbar_item->parent;
928 inc_all_account_mail_cb(mainwin, 0, NULL);
935 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
937 ToolbarItem *toolbar_item = (ToolbarItem*)data;
940 g_return_if_fail(toolbar_item != NULL);
942 switch (toolbar_item->type) {
944 mainwin = (MainWindow*)toolbar_item->parent;
945 send_queue_cb(mainwin, 0, NULL);
952 static void toolbar_exec_cb(GtkWidget *widget,
955 MainWindow *mainwin = get_mainwin(data);
957 g_return_if_fail(mainwin != NULL);
958 summary_execute(mainwin->summaryview);
962 * Delete current/selected(s) message(s)
964 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
966 ToolbarItem *toolbar_item = (ToolbarItem*)data;
969 g_return_if_fail(toolbar_item != NULL);
970 g_return_if_fail(toolbar_item->parent);
972 switch (toolbar_item->type) {
973 case TOOLBAR_MSGVIEW:
974 messageview_delete((MessageView *)toolbar_item->parent);
977 mainwin = (MainWindow *)toolbar_item->parent;
978 summary_delete_trash(mainwin->summaryview);
981 debug_print("toolbar event not supported\n");
987 * Delete current/selected(s) message(s)
989 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
991 ToolbarItem *toolbar_item = (ToolbarItem*)data;
994 g_return_if_fail(toolbar_item != NULL);
995 g_return_if_fail(toolbar_item->parent);
997 switch (toolbar_item->type) {
998 case TOOLBAR_MSGVIEW:
999 messageview_delete((MessageView *)toolbar_item->parent);
1002 mainwin = (MainWindow *)toolbar_item->parent;
1003 summary_delete(mainwin->summaryview);
1006 debug_print("toolbar event not supported\n");
1013 * Compose new message
1015 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1017 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1018 MainWindow *mainwin;
1019 MessageView *msgview;
1021 g_return_if_fail(toolbar_item != NULL);
1023 switch (toolbar_item->type) {
1025 mainwin = (MainWindow*)toolbar_item->parent;
1026 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1027 compose_news_cb(mainwin, 0, NULL);
1029 compose_mail_cb(mainwin, 0, NULL);
1031 case TOOLBAR_MSGVIEW:
1032 msgview = (MessageView*)toolbar_item->parent;
1033 compose_new_with_folderitem(NULL,
1034 msgview->msginfo->folder, NULL);
1037 debug_print("toolbar event not supported\n");
1041 static void toolbar_learn(gpointer data, guint as_spam)
1043 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1044 MainWindow *mainwin;
1045 MessageView *msgview;
1047 g_return_if_fail(toolbar_item != NULL);
1049 switch (toolbar_item->type) {
1051 mainwin = (MainWindow*)toolbar_item->parent;
1053 mainwindow_learn(mainwin, TRUE);
1055 mainwindow_learn(mainwin, FALSE);
1057 case TOOLBAR_MSGVIEW:
1058 msgview = (MessageView*)toolbar_item->parent;
1060 messageview_learn(msgview, TRUE);
1062 messageview_learn(msgview, FALSE);
1065 debug_print("toolbar event not supported\n");
1069 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1071 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1072 MainWindow *mainwin;
1073 MessageView *msgview;
1075 g_return_if_fail(toolbar_item != NULL);
1077 switch (toolbar_item->type) {
1079 mainwin = (MainWindow*)toolbar_item->parent;
1080 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1081 mainwindow_learn(mainwin, TRUE);
1083 mainwindow_learn(mainwin, FALSE);
1085 case TOOLBAR_MSGVIEW:
1086 msgview = (MessageView*)toolbar_item->parent;
1087 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1088 messageview_learn(msgview, TRUE);
1090 messageview_learn(msgview, FALSE);
1093 debug_print("toolbar event not supported\n");
1101 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1103 toolbar_reply(data, prefs_common.reply_with_quote ?
1104 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1109 * Reply message to Sender and All recipients
1111 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1114 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1115 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1120 * Reply to Mailing List
1122 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1125 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1126 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1131 * Reply to sender of message
1133 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1136 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1137 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1143 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1145 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1148 g_return_if_fail(toolbar_item != NULL);
1150 switch (toolbar_item->type) {
1152 case TOOLBAR_MSGVIEW:
1155 case TOOLBAR_COMPOSE:
1156 compose = (Compose *)toolbar_item->parent;
1161 addressbook_open(compose);
1166 * Forward current/selected(s) message(s)
1168 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1170 toolbar_reply(data, COMPOSE_FORWARD);
1174 * Goto Prev Unread Message
1176 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1178 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1179 MainWindow *mainwin;
1180 MessageView *msgview;
1182 g_return_if_fail(toolbar_item != NULL);
1184 switch (toolbar_item->type) {
1186 mainwin = (MainWindow*)toolbar_item->parent;
1187 summary_select_prev_unread(mainwin->summaryview);
1190 case TOOLBAR_MSGVIEW:
1191 msgview = (MessageView*)toolbar_item->parent;
1192 msgview->updating = TRUE;
1193 summary_select_prev_unread(msgview->mainwin->summaryview);
1194 msgview->updating = FALSE;
1196 if (msgview->deferred_destroy) {
1197 debug_print("messageview got away!\n");
1198 messageview_destroy(msgview);
1202 /* Now we need to update the messageview window */
1203 if (msgview->mainwin->summaryview->selected) {
1204 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1207 messageview_show(msgview, msginfo,
1208 msgview->all_headers);
1210 gtk_widget_destroy(msgview->window);
1214 debug_print("toolbar event not supported\n");
1219 * Goto Next Unread Message
1221 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1223 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1224 MainWindow *mainwin;
1225 MessageView *msgview;
1227 g_return_if_fail(toolbar_item != NULL);
1229 switch (toolbar_item->type) {
1231 mainwin = (MainWindow*)toolbar_item->parent;
1232 summary_select_next_unread(mainwin->summaryview);
1235 case TOOLBAR_MSGVIEW:
1236 msgview = (MessageView*)toolbar_item->parent;
1237 msgview->updating = TRUE;
1238 summary_select_next_unread(msgview->mainwin->summaryview);
1239 msgview->updating = FALSE;
1241 if (msgview->deferred_destroy) {
1242 debug_print("messageview got away!\n");
1243 messageview_destroy(msgview);
1247 /* Now we need to update the messageview window */
1248 if (msgview->mainwin->summaryview->selected) {
1249 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1252 messageview_show(msgview, msginfo,
1253 msgview->all_headers);
1255 gtk_widget_destroy(msgview->window);
1259 debug_print("toolbar event not supported\n");
1263 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1265 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1266 MainWindow *mainwin;
1268 g_return_if_fail(toolbar_item != NULL);
1270 switch (toolbar_item->type) {
1272 mainwin = (MainWindow *) toolbar_item->parent;
1273 summary_toggle_ignore_thread(mainwin->summaryview);
1275 case TOOLBAR_MSGVIEW:
1276 /* TODO: see toolbar_next_unread_cb() if you need
1277 * this in the message view */
1280 debug_print("toolbar event not supported\n");
1285 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1287 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1289 g_return_if_fail(toolbar_item != NULL);
1294 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1296 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1297 MainWindow *mainwin;
1299 g_return_if_fail(toolbar_item != NULL);
1301 switch (toolbar_item->type) {
1303 mainwin = (MainWindow *) toolbar_item->parent;
1304 summary_print(mainwin->summaryview);
1306 case TOOLBAR_MSGVIEW:
1307 /* TODO: see toolbar_next_unread_cb() if you need
1308 * this in the message view */
1311 debug_print("toolbar event not supported\n");
1316 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1318 compose_toolbar_cb(A_SEND, data);
1321 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1323 compose_toolbar_cb(A_SENDL, data);
1326 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1328 compose_toolbar_cb(A_DRAFT, data);
1331 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1333 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1334 MainWindow *mainwin;
1335 MessageView *messageview;
1338 g_return_if_fail(toolbar_item != NULL);
1340 switch (toolbar_item->type) {
1342 mainwin = (MainWindow *) toolbar_item->parent;
1343 app_will_exit(NULL, mainwin);
1345 case TOOLBAR_MSGVIEW:
1346 messageview = (MessageView *)toolbar_item->parent;
1347 messageview_destroy(messageview);
1349 case TOOLBAR_COMPOSE:
1350 compose = (Compose *)toolbar_item->parent;
1351 compose_close_toolbar(compose);
1356 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1358 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1359 MainWindow *mainwin;
1361 g_return_if_fail(toolbar_item != NULL);
1363 switch (toolbar_item->type) {
1365 mainwin = (MainWindow *) toolbar_item->parent;
1366 summary_open_row(NULL, mainwin->summaryview);
1368 case TOOLBAR_MSGVIEW:
1369 debug_print("toolbar event not supported\n");
1371 case TOOLBAR_COMPOSE:
1372 debug_print("toolbar event not supported\n");
1377 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1379 compose_toolbar_cb(A_INSERT, data);
1382 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1384 compose_toolbar_cb(A_ATTACH, data);
1387 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1389 compose_toolbar_cb(A_SIG, data);
1392 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1394 compose_toolbar_cb(A_EXTEDITOR, data);
1397 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1399 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1402 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1404 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1408 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1410 compose_toolbar_cb(A_CHECK_SPELLING, data);
1414 * Execute actions from toolbar
1416 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1418 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1419 GSList *action_list;
1420 MainWindow *mainwin;
1422 MessageView *msgview;
1423 gpointer parent = toolbar_item->parent;
1425 g_return_if_fail(toolbar_item != NULL);
1427 switch (toolbar_item->type) {
1429 mainwin = (MainWindow*)parent;
1430 action_list = mainwin->toolbar->action_list;
1432 case TOOLBAR_COMPOSE:
1433 compose = (Compose*)parent;
1434 action_list = compose->toolbar->action_list;
1436 case TOOLBAR_MSGVIEW:
1437 msgview = (MessageView*)parent;
1438 action_list = msgview->toolbar->action_list;
1441 debug_print("toolbar event not supported\n");
1444 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1447 static MainWindow *get_mainwin(gpointer data)
1449 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1450 MainWindow *mainwin = NULL;
1451 MessageView *msgview;
1453 g_return_val_if_fail(toolbar_item != NULL, NULL);
1455 switch(toolbar_item->type) {
1457 mainwin = (MainWindow*)toolbar_item->parent;
1459 case TOOLBAR_MSGVIEW:
1460 msgview = (MessageView*)toolbar_item->parent;
1461 mainwin = (MainWindow*)msgview->mainwin;
1470 static void toolbar_buttons_cb(GtkWidget *widget,
1477 void (*func)(GtkWidget *widget, gpointer data);
1479 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1480 { A_RECEIVE_CUR, toolbar_inc_cb },
1481 { A_SEND_QUEUED, toolbar_send_queued_cb },
1482 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1483 { A_COMPOSE_NEWS, toolbar_compose_cb },
1484 { A_REPLY_MESSAGE, toolbar_reply_cb },
1485 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1486 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1487 { A_REPLY_ML, toolbar_reply_to_list_cb },
1488 { A_FORWARD, toolbar_forward_cb },
1489 { A_TRASH, toolbar_trash_cb },
1490 { A_DELETE_REAL, toolbar_delete_cb },
1491 { A_EXECUTE, toolbar_exec_cb },
1492 { A_GOTO_PREV, toolbar_prev_unread_cb },
1493 { A_GOTO_NEXT, toolbar_next_unread_cb },
1494 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1495 { A_PRINT, toolbar_print_cb },
1496 { A_LEARN_SPAM, toolbar_learn_cb },
1498 { A_SEND, toolbar_send_cb },
1499 { A_SENDL, toolbar_send_later_cb },
1500 { A_DRAFT, toolbar_draft_cb },
1501 { A_OPEN_MAIL, toolbar_open_mail_cb },
1502 { A_CLOSE, toolbar_close_cb },
1503 { A_INSERT, toolbar_insert_cb },
1504 { A_ATTACH, toolbar_attach_cb },
1505 { A_SIG, toolbar_sig_cb },
1506 { A_EXTEDITOR, toolbar_ext_editor_cb },
1507 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1508 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1509 { A_ADDRBOOK, toolbar_addrbook_cb },
1511 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1513 { A_SYL_ACTIONS, toolbar_actions_execute_cb },
1514 { A_CANCEL_INC, toolbar_cancel_inc_cb }
1517 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1519 for (i = 0; i < num_items; i++) {
1520 if (callbacks[i].index == item->index) {
1521 callbacks[i].func(widget, item);
1528 * Create a new toolbar with specified type
1529 * if a callback list is passed it will be used before the
1530 * common callback list
1532 Toolbar *toolbar_create(ToolbarType type,
1533 GtkWidget *container,
1536 ToolbarItem *toolbar_item;
1539 GtkWidget *icon_wid = NULL;
1540 GtkWidget *icon_news;
1541 GtkWidget *icon_ham;
1543 GtkWidget *item_news;
1544 GtkWidget *item_ham;
1545 guint n_menu_entries;
1546 ComboButton *getall_combo;
1547 ComboButton *reply_combo;
1548 ComboButton *replyall_combo;
1549 ComboButton *replylist_combo;
1550 ComboButton *replysender_combo;
1551 ComboButton *fwd_combo;
1552 ComboButton *compose_combo;
1553 ComboButton *ham_combo;
1555 GtkTooltips *toolbar_tips;
1556 ToolbarSylpheedActions *action_item;
1558 GSList *toolbar_list;
1559 Toolbar *toolbar_data;
1562 toolbar_tips = gtk_tooltips_new();
1564 toolbar_read_config_file(type);
1565 toolbar_list = toolbar_get_list(type);
1567 toolbar_data = g_new0(Toolbar, 1);
1569 toolbar = gtk_toolbar_new();
1570 gtk_container_add(GTK_CONTAINER(container), toolbar);
1571 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1572 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1573 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1575 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1577 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1578 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1582 toolbar_item = g_new0(ToolbarItem, 1);
1583 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1584 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1585 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1586 toolbar_item->parent = data;
1587 toolbar_item->type = type;
1589 /* collect toolbar items in list to keep track */
1590 toolbar_data->item_list =
1591 g_slist_append(toolbar_data->item_list,
1593 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1594 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1598 icon_wid, G_CALLBACK(toolbar_buttons_cb),
1601 switch (toolbar_item->index) {
1604 toolbar_data->getall_btn = item;
1605 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1606 toolbar_data->getall_btn,
1607 _("Receive Mail on all Accounts"), NULL);
1608 getall_combo = gtkut_combo_button_create(toolbar_data->getall_btn, NULL, 0,
1609 "<GetAll>", (gpointer)toolbar_item);
1610 gtk_button_set_relief(GTK_BUTTON(getall_combo->arrow),
1612 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1613 GTK_WIDGET_PTR(getall_combo),
1614 _("Receive Mail on selected Account"), "Reply");
1615 toolbar_data->getall_combo = getall_combo;
1618 toolbar_data->get_btn = item;
1619 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1620 toolbar_data->get_btn,
1621 _("Receive Mail on current Account"), NULL);
1624 toolbar_data->send_btn = item;
1625 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1626 toolbar_data->send_btn,
1627 _("Send Queued Messages"), NULL);
1630 toolbar_data->close_window_btn = item;
1631 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1632 toolbar_data->close_window_btn,
1633 _("Close window"), NULL);
1636 toolbar_data->open_mail_btn = item;
1637 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1638 toolbar_data->open_mail_btn,
1639 _("Open email"), NULL);
1641 case A_COMPOSE_EMAIL:
1642 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1643 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1647 icon_news, G_CALLBACK(toolbar_buttons_cb),
1649 toolbar_data->compose_mail_btn = item;
1650 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1651 toolbar_data->compose_mail_btn,
1652 _("Compose Email"), NULL);
1653 toolbar_data->compose_news_btn = item_news;
1654 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1655 toolbar_data->compose_news_btn,
1656 _("Compose News"), NULL);
1657 compose_combo = gtkut_combo_button_create(toolbar_data->compose_mail_btn, NULL, 0,
1658 "<Compose>", (gpointer)toolbar_item);
1659 gtk_button_set_relief(GTK_BUTTON(compose_combo->arrow),
1661 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1662 GTK_WIDGET_PTR(compose_combo),
1663 _("Compose with selected Account"), "Compose");
1664 toolbar_data->compose_combo = compose_combo;
1667 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1668 item_ham = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1672 icon_ham, G_CALLBACK(toolbar_buttons_cb),
1674 toolbar_data->learn_spam_btn = item;
1675 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1676 toolbar_data->learn_spam_btn,
1677 _("Learn Spam"), NULL);
1678 toolbar_data->learn_ham_btn = item_ham;
1679 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1680 toolbar_data->learn_ham_btn,
1681 _("Learn Ham"), NULL);
1682 n_menu_entries = sizeof(learn_entries) /
1683 sizeof(learn_entries[0]);
1684 ham_combo = gtkut_combo_button_create(toolbar_data->learn_spam_btn,
1685 learn_entries, n_menu_entries,
1686 "<LearnSpam>", (gpointer)toolbar_item);
1687 gtk_button_set_relief(GTK_BUTTON(ham_combo->arrow),
1689 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1690 GTK_WIDGET_PTR(ham_combo),
1691 _("Learn as..."), _("Learn"));
1692 toolbar_data->ham_combo = ham_combo;
1694 case A_REPLY_MESSAGE:
1695 toolbar_data->reply_btn = item;
1696 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1697 toolbar_data->reply_btn,
1698 _("Reply to Message"), NULL);
1699 n_menu_entries = sizeof(reply_entries) /
1700 sizeof(reply_entries[0]);
1701 reply_combo = gtkut_combo_button_create(toolbar_data->reply_btn,
1702 reply_entries, n_menu_entries,
1703 "<Reply>", (gpointer)toolbar_item);
1704 gtk_button_set_relief(GTK_BUTTON(reply_combo->arrow),
1706 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1707 GTK_WIDGET_PTR(reply_combo),
1708 _("Reply to Message"), "Reply");
1709 toolbar_data->reply_combo = reply_combo;
1711 case A_REPLY_SENDER:
1712 toolbar_data->replysender_btn = item;
1713 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1714 toolbar_data->replysender_btn,
1715 _("Reply to Sender"), NULL);
1716 n_menu_entries = sizeof(replysender_entries) /
1717 sizeof(replysender_entries[0]);
1718 replysender_combo = gtkut_combo_button_create(toolbar_data->replysender_btn,
1719 replysender_entries, n_menu_entries,
1720 "<ReplySender>", (gpointer)toolbar_item);
1721 gtk_button_set_relief(GTK_BUTTON(replysender_combo->arrow),
1723 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1724 GTK_WIDGET_PTR(replysender_combo),
1725 _("Reply to Sender"), "ReplySender");
1726 toolbar_data->replysender_combo = replysender_combo;
1729 toolbar_data->replyall_btn = item;
1730 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1731 toolbar_data->replyall_btn,
1732 _("Reply to All"), NULL);
1733 n_menu_entries = sizeof(replyall_entries) /
1734 sizeof(replyall_entries[0]);
1735 replyall_combo = gtkut_combo_button_create(toolbar_data->replyall_btn,
1736 replyall_entries, n_menu_entries,
1737 "<ReplyAll>", (gpointer)toolbar_item);
1738 gtk_button_set_relief(GTK_BUTTON(replyall_combo->arrow),
1740 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1741 GTK_WIDGET_PTR(replyall_combo),
1742 _("Reply to All"), "ReplyAll");
1743 toolbar_data->replyall_combo = replyall_combo;
1746 toolbar_data->replylist_btn = item;
1747 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1748 toolbar_data->replylist_btn,
1749 _("Reply to Mailing-list"), NULL);
1750 n_menu_entries = sizeof(replylist_entries) /
1751 sizeof(replylist_entries[0]);
1752 replylist_combo = gtkut_combo_button_create(toolbar_data->replylist_btn,
1753 replylist_entries, n_menu_entries,
1754 "<ReplyList>", (gpointer)toolbar_item);
1755 gtk_button_set_relief(GTK_BUTTON(replylist_combo->arrow),
1757 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1758 GTK_WIDGET_PTR(replylist_combo),
1759 _("Reply to Mailing-list"), "ReplyList");
1760 toolbar_data->replylist_combo = replylist_combo;
1763 toolbar_data->fwd_btn = item;
1764 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1765 toolbar_data->fwd_btn,
1766 _("Forward Message"), NULL);
1767 n_menu_entries = sizeof(forward_entries) /
1768 sizeof(forward_entries[0]);
1769 fwd_combo = gtkut_combo_button_create(toolbar_data->fwd_btn,
1770 forward_entries, n_menu_entries,
1771 "<Forward>", (gpointer)toolbar_item);
1772 gtk_button_set_relief(GTK_BUTTON(fwd_combo->arrow),
1774 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1775 GTK_WIDGET_PTR(fwd_combo),
1776 _("Forward Message"), "Fwd");
1777 toolbar_data->fwd_combo = fwd_combo;
1780 toolbar_data->trash_btn = item;
1781 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1782 toolbar_data->trash_btn,
1783 _("Trash Message"), NULL);
1786 toolbar_data->delete_btn = item;
1787 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1788 toolbar_data->delete_btn,
1789 _("Delete Message"), NULL);
1792 toolbar_data->exec_btn = item;
1793 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1794 toolbar_data->exec_btn,
1795 _("Execute"), NULL);
1798 toolbar_data->prev_btn = item;
1799 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1800 toolbar_data->prev_btn,
1801 _("Go to Previous Unread Message"),
1805 toolbar_data->next_btn = item;
1806 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1807 toolbar_data->next_btn,
1808 _("Go to Next Unread Message"),
1812 /* Compose Toolbar */
1814 toolbar_data->send_btn = item;
1815 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1816 toolbar_data->send_btn,
1817 _("Send Message"), NULL);
1820 toolbar_data->sendl_btn = item;
1821 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1822 toolbar_data->sendl_btn,
1823 _("Put into queue folder and send later"), NULL);
1826 toolbar_data->draft_btn = item;
1827 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1828 toolbar_data->draft_btn,
1829 _("Save to draft folder"), NULL);
1832 toolbar_data->insert_btn = item;
1833 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1834 toolbar_data->insert_btn,
1835 _("Insert file"), NULL);
1838 toolbar_data->attach_btn = item;
1839 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1840 toolbar_data->attach_btn,
1841 _("Attach file"), NULL);
1844 toolbar_data->sig_btn = item;
1845 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1846 toolbar_data->sig_btn,
1847 _("Insert signature"), NULL);
1850 toolbar_data->exteditor_btn = item;
1851 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1852 toolbar_data->exteditor_btn,
1853 _("Edit with external editor"), NULL);
1855 case A_LINEWRAP_CURRENT:
1856 toolbar_data->linewrap_current_btn = item;
1857 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1858 toolbar_data->linewrap_current_btn,
1859 _("Wrap long lines of current paragraph"), NULL);
1861 case A_LINEWRAP_ALL:
1862 toolbar_data->linewrap_all_btn = item;
1863 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1864 toolbar_data->linewrap_all_btn,
1865 _("Wrap all long lines"), NULL);
1868 toolbar_data->addrbook_btn = item;
1869 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1870 toolbar_data->addrbook_btn,
1871 _("Address book"), NULL);
1874 case A_CHECK_SPELLING:
1875 toolbar_data->spellcheck_btn = item;
1876 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1877 toolbar_data->spellcheck_btn,
1878 _("Check spelling"), NULL);
1883 action_item = g_new0(ToolbarSylpheedActions, 1);
1884 action_item->widget = item;
1885 action_item->name = g_strdup(toolbar_item->text);
1887 toolbar_data->action_list =
1888 g_slist_append(toolbar_data->action_list,
1891 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1893 action_item->name, NULL);
1895 gtk_widget_show(item);
1898 toolbar_data->cancel_inc_btn = item;
1899 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1900 toolbar_data->cancel_inc_btn,
1901 _("Cancel receiving"), NULL);
1904 /* find and set the tool tip text */
1905 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1907 toolbar_ret_descr_from_val
1908 (toolbar_item->index),
1914 toolbar_data->toolbar = toolbar;
1915 if (type == TOOLBAR_MAIN)
1916 activate_compose_button(toolbar_data,
1917 prefs_common.toolbar_style,
1918 toolbar_data->compose_btn_type);
1919 if (type != TOOLBAR_COMPOSE)
1920 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
1923 gtk_widget_show_all(toolbar);
1925 return toolbar_data;
1929 * Free toolbar structures
1931 void toolbar_destroy(Toolbar * toolbar) {
1933 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1934 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1937 void toolbar_update(ToolbarType type, gpointer data)
1939 Toolbar *toolbar_data;
1940 GtkWidget *handlebox;
1941 MainWindow *mainwin = (MainWindow*)data;
1942 Compose *compose = (Compose*)data;
1943 MessageView *msgview = (MessageView*)data;
1947 toolbar_data = mainwin->toolbar;
1948 handlebox = mainwin->handlebox;
1950 case TOOLBAR_COMPOSE:
1951 toolbar_data = compose->toolbar;
1952 handlebox = compose->handlebox;
1954 case TOOLBAR_MSGVIEW:
1955 toolbar_data = msgview->toolbar;
1956 handlebox = msgview->handlebox;
1962 gtk_container_remove(GTK_CONTAINER(handlebox),
1963 GTK_WIDGET(toolbar_data->toolbar));
1965 toolbar_init(toolbar_data);
1966 toolbar_data = toolbar_create(type, handlebox, data);
1969 mainwin->toolbar = toolbar_data;
1971 case TOOLBAR_COMPOSE:
1972 compose->toolbar = toolbar_data;
1974 case TOOLBAR_MSGVIEW:
1975 msgview->toolbar = toolbar_data;
1979 toolbar_style(type, prefs_common.toolbar_style, data);
1981 if (type == TOOLBAR_MAIN) {
1982 toolbar_main_set_sensitive((MainWindow*)data);
1983 account_set_menu_only_toolbar();
1987 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
1988 gboolean in_btn = FALSE; \
1989 if (GTK_IS_BUTTON(widget)) \
1990 in_btn = GTK_BUTTON(widget)->in_button; \
1991 gtk_widget_set_sensitive(widget, sensitive); \
1992 if (GTK_IS_BUTTON(widget)) \
1993 GTK_BUTTON(widget)->in_button = in_btn; \
1996 void toolbar_main_set_sensitive(gpointer data)
1998 SensitiveCond state;
2000 MainWindow *mainwin = (MainWindow*)data;
2001 Toolbar *toolbar = mainwin->toolbar;
2003 GSList *entry_list = NULL;
2005 typedef struct _Entry Entry;
2012 #define SET_WIDGET_COND(w, c) \
2014 Entry *e = g_new0(Entry, 1); \
2017 entry_list = g_slist_append(entry_list, e); \
2021 if (toolbar->get_btn)
2022 SET_WIDGET_COND(toolbar->get_btn,
2023 M_HAVE_ACCOUNT|M_UNLOCKED);
2025 if (toolbar->getall_btn) {
2026 SET_WIDGET_COND(toolbar->getall_btn,
2027 M_HAVE_ACCOUNT|M_UNLOCKED);
2028 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->getall_combo),
2029 M_HAVE_ACCOUNT|M_UNLOCKED);
2031 if (toolbar->send_btn) {
2032 SET_WIDGET_COND(toolbar->send_btn,
2033 M_HAVE_QUEUED_MAILS);
2035 if (toolbar->compose_mail_btn) {
2036 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->compose_combo),
2038 SET_WIDGET_COND(toolbar->compose_news_btn,
2041 if (toolbar->close_window_btn) {
2042 SET_WIDGET_COND(toolbar->compose_news_btn,
2045 if (toolbar->open_mail_btn) {
2046 SET_WIDGET_COND(toolbar->open_mail_btn,
2049 if (toolbar->reply_btn) {
2050 SET_WIDGET_COND(toolbar->reply_btn,
2051 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2052 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->reply_combo),
2053 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2055 if (toolbar->replyall_btn) {
2056 SET_WIDGET_COND(toolbar->replyall_btn,
2057 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2058 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replyall_combo),
2059 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2061 if (toolbar->replylist_btn) {
2062 SET_WIDGET_COND(toolbar->replylist_btn,
2063 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2064 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replylist_combo),
2065 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2067 if (toolbar->replysender_btn) {
2068 SET_WIDGET_COND(toolbar->replysender_btn,
2069 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2070 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replysender_combo),
2071 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2073 if (toolbar->fwd_btn) {
2074 SET_WIDGET_COND(toolbar->fwd_btn,
2075 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2076 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->fwd_combo),
2077 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2079 if (toolbar->fwd_combo) {
2080 GtkWidget *submenu = gtk_item_factory_get_widget(toolbar->fwd_combo->factory, "/Redirect");
2081 SET_WIDGET_COND(submenu,
2082 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2085 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2086 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
2088 SET_WIDGET_COND(toolbar->next_btn, 0);
2091 if (toolbar->trash_btn)
2092 SET_WIDGET_COND(toolbar->trash_btn,
2093 M_TARGET_EXIST|M_ALLOW_DELETE);
2095 if (toolbar->delete_btn)
2096 SET_WIDGET_COND(toolbar->delete_btn,
2097 M_TARGET_EXIST|M_ALLOW_DELETE);
2099 if (toolbar->exec_btn)
2100 SET_WIDGET_COND(toolbar->exec_btn,
2103 if (toolbar->learn_ham_btn)
2104 SET_WIDGET_COND(toolbar->learn_ham_btn,
2105 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2107 if (toolbar->learn_spam_btn)
2108 SET_WIDGET_COND(toolbar->learn_spam_btn,
2109 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2111 if (toolbar->ham_combo)
2112 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->ham_combo),
2113 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2115 if (toolbar->cancel_inc_btn)
2116 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2119 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2120 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
2122 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2125 #undef SET_WIDGET_COND
2127 state = main_window_get_current_state(mainwin);
2129 for (cur = entry_list; cur != NULL; cur = cur->next) {
2130 Entry *e = (Entry*) cur->data;
2132 if (e->widget != NULL) {
2133 sensitive = ((e->cond & state) == e->cond);
2134 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2138 while (entry_list != NULL) {
2139 Entry *e = (Entry*) entry_list->data;
2142 entry_list = g_slist_remove(entry_list, e);
2145 g_slist_free(entry_list);
2147 activate_compose_button(toolbar,
2148 prefs_common.toolbar_style,
2149 toolbar->compose_btn_type);
2153 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2155 Compose *compose = (Compose*)data;
2156 GSList *items = compose->toolbar->action_list;
2158 if (compose->toolbar->send_btn)
2159 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2160 if (compose->toolbar->sendl_btn)
2161 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2162 if (compose->toolbar->draft_btn )
2163 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2164 if (compose->toolbar->insert_btn )
2165 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2166 if (compose->toolbar->attach_btn)
2167 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2168 if (compose->toolbar->sig_btn)
2169 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2170 if (compose->toolbar->exteditor_btn)
2171 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2172 if (compose->toolbar->linewrap_current_btn)
2173 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2174 if (compose->toolbar->linewrap_all_btn)
2175 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2176 if (compose->toolbar->addrbook_btn)
2177 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2179 if (compose->toolbar->spellcheck_btn)
2180 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2182 for (; items != NULL; items = g_slist_next(items)) {
2183 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
2184 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2189 * Initialize toolbar structure
2191 void toolbar_init(Toolbar * toolbar) {
2193 toolbar->toolbar = NULL;
2194 toolbar->get_btn = NULL;
2195 toolbar->getall_btn = NULL;
2196 toolbar->getall_combo = NULL;
2197 toolbar->send_btn = NULL;
2198 toolbar->compose_mail_btn = NULL;
2199 toolbar->compose_news_btn = NULL;
2200 toolbar->compose_combo = NULL;
2201 toolbar->reply_btn = NULL;
2202 toolbar->replysender_btn = NULL;
2203 toolbar->replyall_btn = NULL;
2204 toolbar->replylist_btn = NULL;
2205 toolbar->fwd_btn = NULL;
2206 toolbar->trash_btn = NULL;
2207 toolbar->delete_btn = NULL;
2208 toolbar->prev_btn = NULL;
2209 toolbar->next_btn = NULL;
2210 toolbar->exec_btn = NULL;
2211 toolbar->open_mail_btn = NULL;
2212 toolbar->close_window_btn = NULL;
2213 /* compose buttons */
2214 toolbar->sendl_btn = NULL;
2215 toolbar->draft_btn = NULL;
2216 toolbar->insert_btn = NULL;
2217 toolbar->attach_btn = NULL;
2218 toolbar->sig_btn = NULL;
2219 toolbar->exteditor_btn = NULL;
2220 toolbar->linewrap_current_btn = NULL;
2221 toolbar->linewrap_all_btn = NULL;
2222 toolbar->addrbook_btn = NULL;
2224 toolbar->spellcheck_btn = NULL;
2227 toolbar_destroy(toolbar);
2232 static void toolbar_reply(gpointer data, guint action)
2234 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2235 MainWindow *mainwin;
2236 MessageView *msgview;
2237 GSList *msginfo_list = NULL;
2239 g_return_if_fail(toolbar_item != NULL);
2241 switch (toolbar_item->type) {
2243 mainwin = (MainWindow*)toolbar_item->parent;
2244 msginfo_list = summary_get_selection(mainwin->summaryview);
2245 msgview = (MessageView*)mainwin->messageview;
2247 case TOOLBAR_MSGVIEW:
2248 msgview = (MessageView*)toolbar_item->parent;
2249 g_return_if_fail(msgview != NULL);
2250 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2256 g_return_if_fail(msgview != NULL);
2257 g_return_if_fail(msginfo_list != NULL);
2258 compose_reply_from_messageview(msgview, msginfo_list, action);
2259 g_slist_free(msginfo_list);
2261 /* TODO: update reply state ion summaryview */
2265 /* exported functions */
2267 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2269 MainWindow *mainwin = (MainWindow*)data;
2271 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2274 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2276 MainWindow *mainwin = (MainWindow*)data;
2278 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2281 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2285 gboolean got_error = FALSE;
2286 gchar *errstr = NULL;
2288 if (prefs_common.work_offline)
2289 if (alertpanel(_("Offline warning"),
2290 _("You're working offline. Override?"),
2291 GTK_STOCK_NO, GTK_STOCK_YES,
2292 NULL) != G_ALERTALTERNATE)
2295 /* ask for confirmation before sending queued messages only
2296 in online mode and if there is at least one message queued
2297 in any of the folder queue
2299 if (prefs_common.confirm_send_queued_messages) {
2301 /* check if there's a queued message */
2302 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2303 Folder *folder = list->data;
2305 found = !procmsg_queue_is_empty(folder->queue);
2307 /* if necessary, ask for confirmation before sending */
2308 if (found && !prefs_common.work_offline) {
2309 if (alertpanel(_("Send queued messages"),
2310 _("Send all queued messages?"),
2311 GTK_STOCK_CANCEL, _("_Send"),
2312 NULL) != G_ALERTALTERNATE)
2317 for (list = folder_get_list(); list != NULL; list = list->next) {
2318 Folder *folder = list->data;
2320 if (folder->queue) {
2321 if (procmsg_send_queue(folder->queue,
2322 prefs_common.savemsg,
2329 alertpanel_error_log(_("Some errors occurred while "
2330 "sending queued messages."));
2332 gchar *tmp = g_strdup_printf(_("Some errors occurred "
2333 "while sending queued messages:\n%s"), errstr);
2335 alertpanel_error_log(tmp);
2341 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2343 MainWindow *mainwin = (MainWindow*)data;
2344 PrefsAccount *ac = NULL;
2345 FolderItem *item = mainwin->summaryview->folder_item;
2350 ac = account_find_from_item(item);
2351 if (ac && ac->protocol != A_NNTP) {
2352 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2358 * CLAWS - use current account
2360 if (cur_account && (cur_account->protocol != A_NNTP)) {
2361 compose_new_with_folderitem(cur_account, item, NULL);
2366 * CLAWS - just get the first one
2368 list = account_get_list();
2369 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2370 ac = (PrefsAccount *) cur->data;
2371 if (ac->protocol != A_NNTP) {
2372 compose_new_with_folderitem(ac, item, NULL);
2378 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2380 MainWindow *mainwin = (MainWindow*)data;
2381 PrefsAccount * ac = NULL;
2385 if (mainwin->summaryview->folder_item) {
2386 ac = mainwin->summaryview->folder_item->folder->account;
2387 if (ac && ac->protocol == A_NNTP) {
2388 compose_new_with_folderitem(ac,
2389 mainwin->summaryview->folder_item, NULL);
2394 list = account_get_list();
2395 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2396 ac = (PrefsAccount *) cur->data;
2397 if (ac->protocol == A_NNTP) {
2398 compose_new_with_folderitem(ac,
2399 mainwin->summaryview->folder_item, NULL);