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 3 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, see <http://www.gnu.org/licenses/>.
21 * General functions for accessing address book files.
31 #include <glib/gi18n.h>
40 #include "mainwindow.h"
41 #include "summaryview.h"
46 #include "prefs_gtk.h"
48 #include "stock_pixmap.h"
49 #include "manage_window.h"
55 #include "prefs_actions.h"
56 #include "prefs_common.h"
57 #include "prefs_toolbar.h"
58 #include "alertpanel.h"
62 #define TOOLBAR_TAG_INDEX "toolbar"
63 #define TOOLBAR_TAG_ITEM "item"
64 #define TOOLBAR_TAG_SEPARATOR "separator"
66 #define TOOLBAR_ICON_FILE "file"
67 #define TOOLBAR_ICON_TEXT "text"
68 #define TOOLBAR_ICON_ACTION "action"
70 static gboolean toolbar_is_duplicate (gint action,
72 static void toolbar_parse_item (XMLFile *file,
75 static gint toolbar_ret_val_from_text (const gchar *text);
76 static gchar *toolbar_ret_text_from_val (gint val);
78 static void toolbar_set_default_main (void);
79 static void toolbar_set_default_compose (void);
80 static void toolbar_set_default_msgview (void);
82 static void toolbar_style (ToolbarType type,
86 static MainWindow *get_mainwin (gpointer data);
87 static void activate_compose_button (Toolbar *toolbar,
89 ComposeButtonType type);
91 /* toolbar callbacks */
92 static void toolbar_reply (gpointer data,
94 static void toolbar_learn (gpointer data,
96 static void toolbar_delete_cb (GtkWidget *widget,
98 static void toolbar_trash_cb (GtkWidget *widget,
101 static void toolbar_compose_cb (GtkWidget *widget,
104 static void toolbar_learn_cb (GtkWidget *widget,
107 static void toolbar_reply_cb (GtkWidget *widget,
110 static void toolbar_reply_to_all_cb (GtkWidget *widget,
113 static void toolbar_reply_to_list_cb (GtkWidget *widget,
116 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
119 static void toolbar_forward_cb (GtkWidget *widget,
122 static void toolbar_prev_unread_cb (GtkWidget *widget,
124 static void toolbar_next_unread_cb (GtkWidget *widget,
127 static void toolbar_ignore_thread_cb (GtkWidget *widget,
130 static void toolbar_watch_thread_cb (GtkWidget *widget,
133 static void toolbar_print_cb (GtkWidget *widget,
136 static void toolbar_actions_execute_cb (GtkWidget *widget,
140 static void toolbar_send_cb (GtkWidget *widget,
142 static void toolbar_send_later_cb (GtkWidget *widget,
144 static void toolbar_draft_cb (GtkWidget *widget,
146 static void toolbar_close_cb (GtkWidget *widget,
148 static void toolbar_open_mail_cb (GtkWidget *widget,
150 static void toolbar_insert_cb (GtkWidget *widget,
152 static void toolbar_attach_cb (GtkWidget *widget,
154 static void toolbar_sig_cb (GtkWidget *widget,
156 static void toolbar_ext_editor_cb (GtkWidget *widget,
158 static void toolbar_linewrap_current_cb (GtkWidget *widget,
160 static void toolbar_linewrap_all_cb (GtkWidget *widget,
162 static void toolbar_addrbook_cb (GtkWidget *widget,
165 static void toolbar_check_spelling_cb (GtkWidget *widget,
168 static void toolbar_cancel_inc_cb (GtkWidget *widget,
174 } toolbar_text [] = {
175 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
176 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
177 { "A_SEND_QUEUED", N_("Send Queued Messages") },
178 { "A_COMPOSE_EMAIL", N_("Compose Email") },
179 { "A_COMPOSE_NEWS", N_("Compose News") },
180 { "A_REPLY_MESSAGE", N_("Reply to Message") },
181 { "A_REPLY_SENDER", N_("Reply to Sender") },
182 { "A_REPLY_ALL", N_("Reply to All") },
183 { "A_REPLY_ML", N_("Reply to Mailing-list") },
184 { "A_OPEN_MAIL", N_("Open email") },
185 { "A_FORWARD", N_("Forward Message") },
186 { "A_TRASH", N_("Trash Message") },
187 { "A_DELETE_REAL", N_("Delete Message") },
188 { "A_EXECUTE", N_("Execute") },
189 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
190 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
191 { "A_IGNORE_THREAD", N_("Ignore thread") },
192 { "A_WATCH_THREAD", N_("Watch thread") },
193 { "A_PRINT", N_("Print") },
194 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
195 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
197 { "A_SEND", N_("Send Message") },
198 { "A_SENDL", N_("Put into queue folder and send later") },
199 { "A_DRAFT", N_("Save to draft folder") },
200 { "A_INSERT", N_("Insert file") },
201 { "A_ATTACH", N_("Attach file") },
202 { "A_SIG", N_("Insert signature") },
203 { "A_EXTEDITOR", N_("Edit with external editor") },
204 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
205 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
206 { "A_ADDRBOOK", N_("Address book") },
208 { "A_CHECK_SPELLING", N_("Check spelling") },
210 { "A_SYL_ACTIONS", N_("Claws Mail Actions Feature") },
211 { "A_CANCEL_INC", N_("Cancel receiving") },
212 { "A_CLOSE", N_("Close window") },
213 { "A_SEPARATOR", "Separator" }
216 /* struct holds configuration files and a list of
217 * currently active toolbar items
218 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
222 const gchar *conf_file;
224 } toolbar_config[3] = {
225 { "toolbar_main.xml", NULL},
226 { "toolbar_compose.xml", NULL},
227 { "toolbar_msgview.xml", NULL}
230 static GtkItemFactoryEntry reply_entries[] =
232 {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
233 {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
235 static GtkItemFactoryEntry replyall_entries[] =
237 {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
238 {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
240 static GtkItemFactoryEntry replylist_entries[] =
242 {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
243 {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
245 static GtkItemFactoryEntry replysender_entries[] =
247 {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
248 {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
250 static GtkItemFactoryEntry forward_entries[] =
252 {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
253 {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
254 {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, NULL}
256 static GtkItemFactoryEntry learn_entries[] =
258 {N_("/Learn as _Spam"), NULL, toolbar_learn, TRUE, NULL},
259 {N_("/Learn as _Ham"), NULL, toolbar_learn, FALSE, NULL}
263 gint toolbar_ret_val_from_descr(const gchar *descr)
267 for (i = 0; i < N_ACTION_VAL; i++) {
268 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
275 gchar *toolbar_ret_descr_from_val(gint val)
277 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
279 return gettext(toolbar_text[val].descr);
282 static gint toolbar_ret_val_from_text(const gchar *text)
286 for (i = 0; i < N_ACTION_VAL; i++) {
287 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
294 static gchar *toolbar_ret_text_from_val(gint val)
296 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
298 return toolbar_text[val].index_str;
301 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
305 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
308 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
309 ToolbarItem *item = (ToolbarItem*) cur->data;
311 if (item->index == action)
317 /* depending on toolbar type this function
318 returns a list of available toolbar events being
319 displayed by prefs_toolbar
321 GList *toolbar_get_action_items(ToolbarType source)
326 if (source == TOOLBAR_MAIN) {
327 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
328 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
329 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
330 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
331 A_GOTO_NEXT, A_IGNORE_THREAD, A_WATCH_THREAD, A_PRINT,
332 A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
335 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
336 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
339 else if (source == TOOLBAR_COMPOSE) {
340 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
341 A_INSERT, A_ATTACH, A_SIG,
342 A_EXTEDITOR, A_LINEWRAP_CURRENT,
343 A_LINEWRAP_ALL, A_ADDRBOOK,
349 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
350 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
352 else if (source == TOOLBAR_MSGVIEW) {
353 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
354 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
355 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
356 A_ADDRBOOK, A_LEARN_SPAM, A_CLOSE };
358 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
359 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
365 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
369 ToolbarItem *item = NULL;
370 gboolean rewrite = FALSE;
372 attr = xml_get_current_tag_attr(file);
373 item = g_new0(ToolbarItem, 1);
375 name = ((XMLAttr *)attr->data)->name;
376 value = ((XMLAttr *)attr->data)->value;
378 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
379 item->file = g_strdup (value);
380 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
381 item->text = g_strdup (gettext(value));
382 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
383 item->index = toolbar_ret_val_from_text(value);
384 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
386 item->index = A_TRASH;
388 item->file = g_strdup("trash_btn");
390 item->text = g_strdup(_("Trash"));
393 attr = g_list_next(attr);
395 if (item->index != -1) {
397 if (!toolbar_is_duplicate(item->index, source))
398 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
402 toolbar_save_config_file(source);
406 const gchar *toolbar_get_short_text(int action) {
408 case A_GO_FOLDERS: return _("Folders");
409 case A_OPEN_MAIL: return _("Open");
410 case A_RECEIVE_ALL: return _("Get Mail");
411 case A_RECEIVE_CUR: return _("Get");
412 case A_SEND_QUEUED: return _("Send");
413 case A_COMPOSE_EMAIL: return Q_("Toolbar|Compose");
414 case A_COMPOSE_NEWS: return Q_("Toolbar|Compose");
415 case A_REPLY_MESSAGE: return _("Reply");
416 case A_REPLY_ALL: return _("All");
417 case A_REPLY_SENDER: return _("Sender");
418 case A_REPLY_ML: return _("List");
419 case A_FORWARD: return _("Forward");
420 case A_TRASH: return _("Trash");
421 case A_DELETE_REAL: return _("Delete");
422 case A_LEARN_SPAM: return _("Spam");
423 case A_GOTO_PREV: return _("Prev");
424 case A_GOTO_NEXT: return _("Next");
425 case A_IGNORE_THREAD: return _("Ignore thread");
426 case A_WATCH_THREAD: return _("Watch thread");
427 case A_PRINT: return _("Print");
428 case A_CLOSE: return _("Close");
429 case A_SEND: return _("Send");
430 case A_SENDL: return _("Send later");
431 case A_DRAFT: return _("Draft");
432 case A_INSERT: return _("Insert");
433 case A_ATTACH: return _("Attach");
434 case A_SIG: return _("Insert sig.");
435 case A_EXTEDITOR: return _("Edit");
436 case A_LINEWRAP_CURRENT:return _("Wrap para.");
437 case A_LINEWRAP_ALL: return _("Wrap all");
438 case A_ADDRBOOK: return _("Address");
439 case A_CANCEL_INC: return _("Stop");
440 case A_EXECUTE: return _("Execute");
442 case A_CHECK_SPELLING: return _("Check spelling");
448 gint toolbar_get_icon(int action) {
450 case A_GO_FOLDERS: return STOCK_PIXMAP_GO_FOLDERS;
451 case A_OPEN_MAIL: return STOCK_PIXMAP_OPEN_MAIL;
452 case A_RECEIVE_ALL: return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
453 case A_RECEIVE_CUR: return STOCK_PIXMAP_MAIL_RECEIVE;
454 case A_SEND_QUEUED: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
455 case A_COMPOSE_EMAIL: return STOCK_PIXMAP_MAIL_COMPOSE;
456 case A_COMPOSE_NEWS: return STOCK_PIXMAP_NEWS_COMPOSE;
457 case A_REPLY_MESSAGE: return STOCK_PIXMAP_MAIL_REPLY;
458 case A_REPLY_ALL: return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
459 case A_REPLY_SENDER: return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
460 case A_REPLY_ML: return STOCK_PIXMAP_MAIL_REPLY;
461 case A_FORWARD: return STOCK_PIXMAP_MAIL_FORWARD;
462 case A_TRASH: return STOCK_PIXMAP_TRASH;
463 case A_DELETE_REAL: return STOCK_PIXMAP_DELETED;
464 case A_LEARN_SPAM: return STOCK_PIXMAP_SPAM_BTN;
465 case A_GOTO_PREV: return STOCK_PIXMAP_UP_ARROW;
466 case A_GOTO_NEXT: return STOCK_PIXMAP_DOWN_ARROW;
467 case A_IGNORE_THREAD: return STOCK_PIXMAP_IGNORETHREAD;
468 case A_WATCH_THREAD: return STOCK_PIXMAP_WATCHTHREAD;
469 case A_PRINT: return STOCK_PIXMAP_PRINTER;
470 case A_CLOSE: return STOCK_PIXMAP_CLOSE;
471 case A_SEND: return STOCK_PIXMAP_MAIL_SEND;
472 case A_SENDL: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
473 case A_DRAFT: return STOCK_PIXMAP_MAIL;
474 case A_INSERT: return STOCK_PIXMAP_INSERT_FILE;
475 case A_ATTACH: return STOCK_PIXMAP_MAIL_ATTACH;
476 case A_SIG: return STOCK_PIXMAP_MAIL_SIGN;
477 case A_EXTEDITOR: return STOCK_PIXMAP_EDIT_EXTERN;
478 case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
479 case A_LINEWRAP_ALL: return STOCK_PIXMAP_LINEWRAP_ALL;
480 case A_ADDRBOOK: return STOCK_PIXMAP_ADDRESS_BOOK;
481 case A_CANCEL_INC: return STOCK_PIXMAP_NOTICE_ERROR;
482 case A_EXECUTE: return STOCK_PIXMAP_EXEC;
484 case A_CHECK_SPELLING: return STOCK_PIXMAP_CHECK_SPELLING;
490 static void toolbar_set_default_main(void)
494 } default_toolbar[] = {
514 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
524 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
526 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
528 if (default_toolbar[i].action != A_SEPARATOR) {
530 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_short_text(default_toolbar[i].action));
532 toolbar_item->file = g_strdup(file);
533 toolbar_item->index = default_toolbar[i].action;
534 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
537 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
538 toolbar_item->index = A_SEPARATOR;
541 if (toolbar_item->index != -1) {
542 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
543 toolbar_config[TOOLBAR_MAIN].item_list =
544 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
549 static void toolbar_set_default_compose(void)
553 } default_toolbar[] = {
572 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
574 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
576 if (default_toolbar[i].action != A_SEPARATOR) {
578 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_short_text(default_toolbar[i].action));
580 toolbar_item->file = g_strdup(file);
581 toolbar_item->index = default_toolbar[i].action;
582 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
585 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
586 toolbar_item->index = A_SEPARATOR;
589 if (toolbar_item->index != -1) {
590 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
591 toolbar_config[TOOLBAR_COMPOSE].item_list =
592 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
597 static void toolbar_set_default_msgview(void)
601 } default_toolbar[] = {
613 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
622 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
624 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
626 if (default_toolbar[i].action != A_SEPARATOR) {
628 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_short_text(default_toolbar[i].action));
630 toolbar_item->file = g_strdup(file);
631 toolbar_item->index = default_toolbar[i].action;
632 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
635 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
636 toolbar_item->index = A_SEPARATOR;
639 if (toolbar_item->index != -1) {
640 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
641 toolbar_config[TOOLBAR_MSGVIEW].item_list =
642 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
647 void toolbar_set_default(ToolbarType source)
649 if (source == TOOLBAR_MAIN)
650 toolbar_set_default_main();
651 else if (source == TOOLBAR_COMPOSE)
652 toolbar_set_default_compose();
653 else if (source == TOOLBAR_MSGVIEW)
654 toolbar_set_default_msgview();
657 void toolbar_save_config_file(ToolbarType source)
662 gchar *fileSpec = NULL;
664 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
666 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
667 pfile = prefs_write_open(fileSpec);
670 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
673 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
676 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
677 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
679 if (toolbar_item->index != A_SEPARATOR) {
680 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
682 TOOLBAR_ICON_FILE, toolbar_item->file,
683 TOOLBAR_ICON_TEXT) < 0)
685 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
687 if (fprintf(fp, "\" %s=\"%s\"/>\n",
689 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
692 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
697 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
701 if (prefs_file_close (pfile) < 0 )
702 g_warning("failed to write toolbar configuration to file\n");
706 FILE_OP_ERROR(fileSpec, "fprintf");
708 prefs_file_close_revert (pfile);
710 g_warning("failed to open toolbar configuration file for writing\n");
713 void toolbar_read_config_file(ToolbarType source)
715 XMLFile *file = NULL;
716 gchar *fileSpec = NULL;
721 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
723 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
724 file = xml_open_file(fileSpec);
727 toolbar_clear_list(source);
731 || (xml_get_dtd(file))
732 || (xml_parse_next_tag(file))
733 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
734 xml_close_file(file);
738 attr = xml_get_current_tag_attr(file);
745 if (xml_parse_next_tag(file))
748 /* Get next tag (icon, icon_text or icon_action) */
749 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
750 toolbar_parse_item(file, source);
751 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
752 ToolbarItem *item = g_new0(ToolbarItem, 1);
754 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
755 item->index = A_SEPARATOR;
756 toolbar_config[source].item_list =
757 g_slist_append(toolbar_config[source].item_list, item);
761 xml_close_file(file);
764 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
766 if (source == TOOLBAR_MAIN)
767 toolbar_set_default(TOOLBAR_MAIN);
768 else if (source == TOOLBAR_COMPOSE)
769 toolbar_set_default(TOOLBAR_COMPOSE);
770 else if (source == TOOLBAR_MSGVIEW)
771 toolbar_set_default(TOOLBAR_MSGVIEW);
773 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
777 toolbar_save_config_file(source);
782 * clears list of toolbar items read from configuration files
784 void toolbar_clear_list(ToolbarType source)
786 while (toolbar_config[source].item_list != NULL) {
787 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
789 toolbar_config[source].item_list =
790 g_slist_remove(toolbar_config[source].item_list, item);
796 g_slist_free(toolbar_config[source].item_list);
801 * return list of Toolbar items
803 GSList *toolbar_get_list(ToolbarType source)
807 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
808 list = toolbar_config[source].item_list;
813 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
815 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
817 toolbar_item->file = g_strdup(t_item->file);
818 toolbar_item->text = g_strdup(t_item->text);
819 toolbar_item->index = t_item->index;
821 toolbar_config[source].item_list =
822 g_slist_append(toolbar_config[source].item_list,
826 void toolbar_action_execute(GtkWidget *widget,
832 gchar *action, *action_p;
833 gboolean found = FALSE;
836 for (cur = action_list; cur != NULL; cur = cur->next) {
837 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
839 if (widget == act->widget) {
841 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
842 action = g_strdup((gchar*)lop->data);
844 action_p = strstr(action, ": ");
846 if (g_utf8_collate(act->name, action) == 0) {
860 actions_execute(data, i, widget, source);
862 g_warning ("Error: did not find Claws Action to execute");
865 static void activate_compose_button (Toolbar *toolbar,
867 ComposeButtonType type)
869 if ((!toolbar->compose_mail_btn))
872 if (type == COMPOSEBUTTON_NEWS) {
873 gtk_tool_button_set_icon_widget(
874 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
875 toolbar->compose_news_icon);
876 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->compose_mail_btn), GTK_TOOLTIPS(toolbar->tooltips),
877 _("Compose News message"), NULL);
878 gtk_widget_show(toolbar->compose_news_icon);
880 gtk_tool_button_set_icon_widget(
881 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
882 toolbar->compose_mail_icon);
883 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->compose_mail_btn), GTK_TOOLTIPS(toolbar->tooltips),
884 _("Compose Email"), NULL);
885 gtk_widget_show(toolbar->compose_mail_icon);
887 toolbar->compose_btn_type = type;
890 void toolbar_set_compose_button(Toolbar *toolbar,
891 ComposeButtonType compose_btn_type)
893 if (toolbar->compose_btn_type != compose_btn_type)
894 activate_compose_button(toolbar,
895 prefs_common.toolbar_style,
899 static void activate_learn_button (Toolbar *toolbar,
901 LearnButtonType type)
903 if ((!toolbar->learn_spam_btn))
906 if (type == LEARN_SPAM) {
907 gtk_tool_button_set_icon_widget(
908 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
909 toolbar->learn_spam_icon);
910 gtk_tool_button_set_label(
911 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
913 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->learn_spam_btn), GTK_TOOLTIPS(toolbar->tooltips),
914 _("Learn spam"), NULL);
915 gtk_widget_show(toolbar->learn_spam_icon);
917 gtk_tool_button_set_icon_widget(
918 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
919 toolbar->learn_ham_icon);
920 gtk_tool_button_set_label(
921 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
923 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->learn_spam_btn), GTK_TOOLTIPS(toolbar->tooltips),
924 _("Learn ham"), NULL);
925 gtk_widget_show(toolbar->learn_ham_icon);
927 toolbar->learn_btn_type = type;
930 void toolbar_set_learn_button(Toolbar *toolbar,
931 LearnButtonType learn_btn_type)
933 if (toolbar->learn_btn_type != learn_btn_type)
934 activate_learn_button(toolbar,
935 prefs_common.toolbar_style,
939 void toolbar_toggle(guint action, gpointer data)
941 MainWindow *mainwin = (MainWindow*)data;
945 g_return_if_fail(mainwin != NULL);
947 toolbar_style(TOOLBAR_MAIN, action, mainwin);
949 list = compose_get_compose_list();
950 for (cur = list; cur != NULL; cur = cur->next) {
951 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
953 list = messageview_get_msgview_list();
954 for (cur = list; cur != NULL; cur = cur->next) {
955 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
960 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
962 switch ((ToolbarStyle)action) {
964 gtk_widget_hide(handlebox_wid);
967 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
971 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
975 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
978 case TOOLBAR_BOTH_HORIZ:
979 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
980 GTK_TOOLBAR_BOTH_HORIZ);
986 prefs_common.toolbar_style = (ToolbarStyle)action;
987 gtk_widget_set_size_request(handlebox_wid, 1, -1);
989 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
990 gtk_widget_show(handlebox_wid);
991 gtk_widget_queue_resize(handlebox_wid);
995 * Change the style of toolbar
997 static void toolbar_style(ToolbarType type, guint action, gpointer data)
999 GtkWidget *handlebox_wid;
1000 GtkWidget *toolbar_wid;
1001 MainWindow *mainwin = (MainWindow*)data;
1002 Compose *compose = (Compose*)data;
1003 MessageView *msgview = (MessageView*)data;
1005 g_return_if_fail(data != NULL);
1009 handlebox_wid = mainwin->handlebox;
1010 toolbar_wid = mainwin->toolbar->toolbar;
1012 case TOOLBAR_COMPOSE:
1013 handlebox_wid = compose->handlebox;
1014 toolbar_wid = compose->toolbar->toolbar;
1016 case TOOLBAR_MSGVIEW:
1017 handlebox_wid = msgview->handlebox;
1018 toolbar_wid = msgview->toolbar->toolbar;
1024 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1027 /* Toolbar handling */
1028 static void toolbar_inc_cb(GtkWidget *widget,
1031 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1032 MainWindow *mainwin;
1034 g_return_if_fail(toolbar_item != NULL);
1036 switch (toolbar_item->type) {
1038 mainwin = (MainWindow*)toolbar_item->parent;
1039 inc_mail_cb(mainwin, 0, NULL);
1046 static void toolbar_inc_all_cb(GtkWidget *widget,
1049 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1050 MainWindow *mainwin;
1052 g_return_if_fail(toolbar_item != NULL);
1054 switch (toolbar_item->type) {
1056 mainwin = (MainWindow*)toolbar_item->parent;
1057 inc_all_account_mail_cb(mainwin, 0, NULL);
1064 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1066 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1067 MainWindow *mainwin;
1069 g_return_if_fail(toolbar_item != NULL);
1071 switch (toolbar_item->type) {
1073 mainwin = (MainWindow*)toolbar_item->parent;
1074 send_queue_cb(mainwin, 0, NULL);
1081 static void toolbar_exec_cb(GtkWidget *widget,
1084 MainWindow *mainwin = get_mainwin(data);
1086 g_return_if_fail(mainwin != NULL);
1087 summary_execute(mainwin->summaryview);
1091 * Delete current/selected(s) message(s)
1093 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1095 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1096 MainWindow *mainwin;
1098 g_return_if_fail(toolbar_item != NULL);
1099 g_return_if_fail(toolbar_item->parent);
1101 switch (toolbar_item->type) {
1102 case TOOLBAR_MSGVIEW:
1103 messageview_delete((MessageView *)toolbar_item->parent);
1106 mainwin = (MainWindow *)toolbar_item->parent;
1107 summary_delete_trash(mainwin->summaryview);
1110 debug_print("toolbar event not supported\n");
1116 * Delete current/selected(s) message(s)
1118 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1120 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1121 MainWindow *mainwin;
1123 g_return_if_fail(toolbar_item != NULL);
1124 g_return_if_fail(toolbar_item->parent);
1126 switch (toolbar_item->type) {
1127 case TOOLBAR_MSGVIEW:
1128 messageview_delete((MessageView *)toolbar_item->parent);
1131 mainwin = (MainWindow *)toolbar_item->parent;
1132 summary_delete(mainwin->summaryview);
1135 debug_print("toolbar event not supported\n");
1142 * Compose new message
1144 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1146 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1147 MainWindow *mainwin;
1148 MessageView *msgview;
1150 g_return_if_fail(toolbar_item != NULL);
1152 switch (toolbar_item->type) {
1154 mainwin = (MainWindow*)toolbar_item->parent;
1155 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1156 compose_news_cb(mainwin, 0, NULL);
1158 compose_mail_cb(mainwin, 0, NULL);
1160 case TOOLBAR_MSGVIEW:
1161 msgview = (MessageView*)toolbar_item->parent;
1162 compose_new_with_folderitem(NULL,
1163 msgview->msginfo->folder, NULL);
1166 debug_print("toolbar event not supported\n");
1170 static void toolbar_learn(gpointer data, guint as_spam)
1172 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1173 MainWindow *mainwin;
1174 MessageView *msgview;
1176 g_return_if_fail(toolbar_item != NULL);
1178 switch (toolbar_item->type) {
1180 mainwin = (MainWindow*)toolbar_item->parent;
1182 mainwindow_learn(mainwin, TRUE);
1184 mainwindow_learn(mainwin, FALSE);
1186 case TOOLBAR_MSGVIEW:
1187 msgview = (MessageView*)toolbar_item->parent;
1189 messageview_learn(msgview, TRUE);
1191 messageview_learn(msgview, FALSE);
1194 debug_print("toolbar event not supported\n");
1198 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1200 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1201 MainWindow *mainwin;
1202 MessageView *msgview;
1204 g_return_if_fail(toolbar_item != NULL);
1206 switch (toolbar_item->type) {
1208 mainwin = (MainWindow*)toolbar_item->parent;
1209 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1210 mainwindow_learn(mainwin, TRUE);
1212 mainwindow_learn(mainwin, FALSE);
1214 case TOOLBAR_MSGVIEW:
1215 msgview = (MessageView*)toolbar_item->parent;
1216 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1217 messageview_learn(msgview, TRUE);
1219 messageview_learn(msgview, FALSE);
1222 debug_print("toolbar event not supported\n");
1230 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1232 toolbar_reply(data, prefs_common.reply_with_quote ?
1233 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1238 * Reply message to Sender and All recipients
1240 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1243 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1244 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1249 * Reply to Mailing List
1251 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1254 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1255 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1260 * Reply to sender of message
1262 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1265 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1266 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1272 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1274 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1277 g_return_if_fail(toolbar_item != NULL);
1279 switch (toolbar_item->type) {
1281 case TOOLBAR_MSGVIEW:
1284 case TOOLBAR_COMPOSE:
1285 compose = (Compose *)toolbar_item->parent;
1290 addressbook_open(compose);
1295 * Forward current/selected(s) message(s)
1297 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1299 toolbar_reply(data, COMPOSE_FORWARD);
1303 * Goto Prev Unread Message
1305 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1307 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1308 MainWindow *mainwin;
1309 MessageView *msgview;
1311 g_return_if_fail(toolbar_item != NULL);
1313 switch (toolbar_item->type) {
1315 mainwin = (MainWindow*)toolbar_item->parent;
1316 summary_select_prev_unread(mainwin->summaryview);
1319 case TOOLBAR_MSGVIEW:
1320 msgview = (MessageView*)toolbar_item->parent;
1321 msgview->updating = TRUE;
1322 summary_select_prev_unread(msgview->mainwin->summaryview);
1323 msgview->updating = FALSE;
1325 if (msgview->deferred_destroy) {
1326 debug_print("messageview got away!\n");
1327 messageview_destroy(msgview);
1331 /* Now we need to update the messageview window */
1332 if (msgview->mainwin->summaryview->selected) {
1334 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1337 messageview_show(msgview, msginfo,
1338 msgview->all_headers);
1341 gtk_widget_destroy(msgview->window);
1345 debug_print("toolbar event not supported\n");
1350 * Goto Next Unread Message
1352 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1354 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1355 MainWindow *mainwin;
1356 MessageView *msgview;
1358 g_return_if_fail(toolbar_item != NULL);
1360 switch (toolbar_item->type) {
1362 mainwin = (MainWindow*)toolbar_item->parent;
1363 summary_select_next_unread(mainwin->summaryview);
1366 case TOOLBAR_MSGVIEW:
1367 msgview = (MessageView*)toolbar_item->parent;
1368 msgview->updating = TRUE;
1369 summary_select_next_unread(msgview->mainwin->summaryview);
1370 msgview->updating = FALSE;
1372 if (msgview->deferred_destroy) {
1373 debug_print("messageview got away!\n");
1374 messageview_destroy(msgview);
1378 /* Now we need to update the messageview window */
1379 if (msgview->mainwin->summaryview->selected) {
1381 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1384 messageview_show(msgview, msginfo,
1385 msgview->all_headers);
1388 gtk_widget_destroy(msgview->window);
1392 debug_print("toolbar event not supported\n");
1396 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1398 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1399 MainWindow *mainwin;
1401 g_return_if_fail(toolbar_item != NULL);
1403 switch (toolbar_item->type) {
1405 mainwin = (MainWindow *) toolbar_item->parent;
1406 summary_toggle_ignore_thread(mainwin->summaryview);
1408 case TOOLBAR_MSGVIEW:
1409 /* TODO: see toolbar_next_unread_cb() if you need
1410 * this in the message view */
1413 debug_print("toolbar event not supported\n");
1418 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1420 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1421 MainWindow *mainwin;
1423 g_return_if_fail(toolbar_item != NULL);
1425 switch (toolbar_item->type) {
1427 mainwin = (MainWindow *) toolbar_item->parent;
1428 summary_toggle_watch_thread(mainwin->summaryview);
1430 case TOOLBAR_MSGVIEW:
1431 /* TODO: see toolbar_next_unread_cb() if you need
1432 * this in the message view */
1435 debug_print("toolbar event not supported\n");
1440 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1442 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1444 g_return_if_fail(toolbar_item != NULL);
1450 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1452 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1453 MainWindow *mainwin;
1455 g_return_if_fail(toolbar_item != NULL);
1457 switch (toolbar_item->type) {
1459 mainwin = (MainWindow *) toolbar_item->parent;
1460 summary_print(mainwin->summaryview);
1462 case TOOLBAR_MSGVIEW:
1463 /* TODO: see toolbar_next_unread_cb() if you need
1464 * this in the message view */
1467 debug_print("toolbar event not supported\n");
1472 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1474 compose_toolbar_cb(A_SEND, data);
1477 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1479 compose_toolbar_cb(A_SENDL, data);
1482 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1484 compose_toolbar_cb(A_DRAFT, data);
1487 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1489 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1490 MainWindow *mainwin;
1491 MessageView *messageview;
1494 g_return_if_fail(toolbar_item != NULL);
1496 switch (toolbar_item->type) {
1498 mainwin = (MainWindow *) toolbar_item->parent;
1499 app_will_exit(NULL, mainwin);
1501 case TOOLBAR_MSGVIEW:
1502 messageview = (MessageView *)toolbar_item->parent;
1503 messageview_destroy(messageview);
1505 case TOOLBAR_COMPOSE:
1506 compose = (Compose *)toolbar_item->parent;
1507 compose_close_toolbar(compose);
1512 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1514 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1515 MainWindow *mainwin;
1517 g_return_if_fail(toolbar_item != NULL);
1519 switch (toolbar_item->type) {
1521 mainwin = (MainWindow *) toolbar_item->parent;
1522 summary_open_row(NULL, mainwin->summaryview);
1524 case TOOLBAR_MSGVIEW:
1525 debug_print("toolbar event not supported\n");
1527 case TOOLBAR_COMPOSE:
1528 debug_print("toolbar event not supported\n");
1533 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1535 compose_toolbar_cb(A_INSERT, data);
1538 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1540 compose_toolbar_cb(A_ATTACH, data);
1543 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1545 compose_toolbar_cb(A_SIG, data);
1548 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1550 compose_toolbar_cb(A_EXTEDITOR, data);
1553 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1555 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1558 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1560 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1564 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1566 compose_toolbar_cb(A_CHECK_SPELLING, data);
1570 * Execute actions from toolbar
1572 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1574 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1575 GSList *action_list;
1576 MainWindow *mainwin;
1578 MessageView *msgview;
1579 gpointer parent = toolbar_item->parent;
1581 g_return_if_fail(toolbar_item != NULL);
1583 switch (toolbar_item->type) {
1585 mainwin = (MainWindow*)parent;
1586 action_list = mainwin->toolbar->action_list;
1588 case TOOLBAR_COMPOSE:
1589 compose = (Compose*)parent;
1590 action_list = compose->toolbar->action_list;
1592 case TOOLBAR_MSGVIEW:
1593 msgview = (MessageView*)parent;
1594 action_list = msgview->toolbar->action_list;
1597 debug_print("toolbar event not supported\n");
1600 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1603 static MainWindow *get_mainwin(gpointer data)
1605 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1606 MainWindow *mainwin = NULL;
1607 MessageView *msgview;
1609 g_return_val_if_fail(toolbar_item != NULL, NULL);
1611 switch(toolbar_item->type) {
1613 mainwin = (MainWindow*)toolbar_item->parent;
1615 case TOOLBAR_MSGVIEW:
1616 msgview = (MessageView*)toolbar_item->parent;
1617 mainwin = (MainWindow*)msgview->mainwin;
1626 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1628 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1629 MainWindow *mainwin = NULL;
1630 switch(toolbar_item->type) {
1632 mainwin = (MainWindow*)toolbar_item->parent;
1635 g_warning("wrong toolbar type\n");
1639 if (!mainwin->in_folder) {
1640 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1642 folderview_select(mainwin->folderview, item);
1645 gtk_widget_grab_focus(mainwin->folderview->ctree);
1646 mainwindow_exit_folder(mainwin);
1650 static void toolbar_buttons_cb(GtkWidget *widget,
1657 void (*func)(GtkWidget *widget, gpointer data);
1659 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1660 { A_RECEIVE_CUR, toolbar_inc_cb },
1661 { A_SEND_QUEUED, toolbar_send_queued_cb },
1662 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1663 { A_COMPOSE_NEWS, toolbar_compose_cb },
1664 { A_REPLY_MESSAGE, toolbar_reply_cb },
1665 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1666 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1667 { A_REPLY_ML, toolbar_reply_to_list_cb },
1668 { A_FORWARD, toolbar_forward_cb },
1669 { A_TRASH, toolbar_trash_cb },
1670 { A_DELETE_REAL, toolbar_delete_cb },
1671 { A_EXECUTE, toolbar_exec_cb },
1672 { A_GOTO_PREV, toolbar_prev_unread_cb },
1673 { A_GOTO_NEXT, toolbar_next_unread_cb },
1674 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1675 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1676 { A_PRINT, toolbar_print_cb },
1677 { A_LEARN_SPAM, toolbar_learn_cb },
1678 { A_GO_FOLDERS, toolbar_go_folders_cb },
1680 { A_SEND, toolbar_send_cb },
1681 { A_SENDL, toolbar_send_later_cb },
1682 { A_DRAFT, toolbar_draft_cb },
1683 { A_OPEN_MAIL, toolbar_open_mail_cb },
1684 { A_CLOSE, toolbar_close_cb },
1685 { A_INSERT, toolbar_insert_cb },
1686 { A_ATTACH, toolbar_attach_cb },
1687 { A_SIG, toolbar_sig_cb },
1688 { A_EXTEDITOR, toolbar_ext_editor_cb },
1689 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1690 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1691 { A_ADDRBOOK, toolbar_addrbook_cb },
1693 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1695 { A_SYL_ACTIONS, toolbar_actions_execute_cb },
1696 { A_CANCEL_INC, toolbar_cancel_inc_cb }
1699 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1701 for (i = 0; i < num_items; i++) {
1702 if (callbacks[i].index == item->index) {
1703 callbacks[i].func(widget, item);
1709 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1710 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1711 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1712 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1713 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1714 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1715 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1719 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1720 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1721 GList *gchild = NULL; \
1722 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1723 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1724 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1725 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1726 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1727 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1729 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(item), \
1730 GTK_TOOLTIPS(toolbar_tips), menutip, NULL); \
1731 child = gtk_bin_get_child(GTK_BIN(item)); \
1732 gchild = gtk_container_get_children( \
1733 GTK_CONTAINER(child)); \
1734 btn = (GtkWidget *)gchild->data; \
1735 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1736 g_list_free(gchild); \
1737 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1738 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1739 g_list_free(gchild); \
1742 #define MAKE_MENU(entries,path,btn) { \
1743 n_menu_entries = sizeof(entries) / \
1744 sizeof(entries[0]); \
1745 menu = menu_create_items(entries, n_menu_entries, path, &factory, toolbar_item); \
1746 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(btn), menu); \
1750 * Create a new toolbar with specified type
1751 * if a callback list is passed it will be used before the
1752 * common callback list
1754 Toolbar *toolbar_create(ToolbarType type,
1755 GtkWidget *container,
1758 ToolbarItem *toolbar_item;
1761 GtkWidget *icon_wid = NULL;
1762 GtkWidget *icon_news;
1763 GtkWidget *icon_ham;
1766 guint n_menu_entries;
1767 GtkItemFactory *factory;
1768 GtkTooltips *toolbar_tips;
1769 ToolbarSylpheedActions *action_item;
1771 GSList *toolbar_list;
1772 Toolbar *toolbar_data;
1775 toolbar_tips = gtk_tooltips_new();
1777 toolbar_read_config_file(type);
1778 toolbar_list = toolbar_get_list(type);
1780 toolbar_data = g_new0(Toolbar, 1);
1782 toolbar = gtk_toolbar_new();
1784 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1785 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1786 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1788 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1790 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1791 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1795 toolbar_item = g_new0(ToolbarItem, 1);
1796 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1797 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1798 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1799 toolbar_item->parent = data;
1800 toolbar_item->type = type;
1802 /* collect toolbar items in list to keep track */
1803 toolbar_data->item_list =
1804 g_slist_append(toolbar_data->item_list,
1806 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1808 switch (toolbar_item->index) {
1811 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1812 toolbar_data->folders_btn = item;
1815 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1816 _("Receive Mail on all Accounts"),
1817 _("Receive Mail on selected Account"));
1818 toolbar_data->getall_btn = item;
1821 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail on current Account"));
1822 toolbar_data->get_btn = item;
1825 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1826 toolbar_data->send_btn = item;
1829 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1830 toolbar_data->close_window_btn = item;
1833 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1834 toolbar_data->open_mail_btn = item;
1836 case A_COMPOSE_EMAIL:
1838 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1840 _("Compose with selected Account"));
1841 toolbar_data->compose_mail_btn = item;
1842 toolbar_data->compose_mail_icon = icon_wid;
1843 g_object_ref(toolbar_data->compose_mail_icon);
1845 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1846 toolbar_data->compose_news_icon = icon_news;
1847 g_object_ref(toolbar_data->compose_news_icon);
1849 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1850 _("Compose Email"));
1851 toolbar_data->compose_mail_btn = item;
1852 toolbar_data->compose_mail_icon = icon_wid;
1854 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1855 toolbar_data->compose_news_icon = icon_news;
1859 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1862 toolbar_data->learn_spam_btn = item;
1863 toolbar_data->learn_spam_icon = icon_wid;
1864 g_object_ref(toolbar_data->learn_spam_icon);
1866 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1867 toolbar_data->learn_ham_icon = icon_ham;
1868 g_object_ref(toolbar_data->learn_ham_icon);
1870 MAKE_MENU(learn_entries,"<LearnSpam>",toolbar_data->learn_spam_btn);
1872 case A_REPLY_MESSAGE:
1874 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1875 _("Reply to Message"),
1876 _("Reply to Message options"));
1877 toolbar_data->reply_btn = item;
1879 MAKE_MENU(reply_entries,"<Reply>",toolbar_data->reply_btn);
1881 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1882 _("Reply to Message"));
1883 toolbar_data->reply_btn = item;
1886 case A_REPLY_SENDER:
1888 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1889 _("Reply to Sender"),
1890 _("Reply to Sender options"));
1891 toolbar_data->replysender_btn = item;
1893 MAKE_MENU(replysender_entries,"<ReplySender>",toolbar_data->replysender_btn);
1895 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1896 _("Reply to Sender"));
1897 toolbar_data->replysender_btn = item;
1902 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1904 _("Reply to All options"));
1905 toolbar_data->replyall_btn = item;
1907 MAKE_MENU(replyall_entries,"<ReplyAll>",toolbar_data->replyall_btn);
1909 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1911 toolbar_data->replyall_btn = item;
1916 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1917 _("Reply to Mailing-list"),
1918 _("Reply to Mailing-list options"));
1919 toolbar_data->replylist_btn = item;
1921 MAKE_MENU(replylist_entries,"<ReplyList>",toolbar_data->replylist_btn);
1923 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1924 _("Reply to Mailing-list"));
1925 toolbar_data->replylist_btn = item;
1930 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1931 _("Forward Message"),
1932 _("Forward Message options"));
1933 toolbar_data->fwd_btn = item;
1935 MAKE_MENU(forward_entries,"<Forward>",toolbar_data->fwd_btn);
1937 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1938 _("Forward Message"));
1939 toolbar_data->fwd_btn = item;
1943 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
1944 toolbar_data->trash_btn = item;
1947 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
1948 toolbar_data->delete_btn = item;
1951 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
1952 toolbar_data->exec_btn = item;
1955 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
1956 toolbar_data->prev_btn = item;
1959 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
1960 toolbar_data->next_btn = item;
1963 /* Compose Toolbar */
1965 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
1966 toolbar_data->send_btn = item;
1969 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
1970 toolbar_data->sendl_btn = item;
1973 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
1974 toolbar_data->draft_btn = item;
1977 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
1978 toolbar_data->insert_btn = item;
1981 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
1982 toolbar_data->attach_btn = item;
1985 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
1986 toolbar_data->sig_btn = item;
1989 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
1990 toolbar_data->exteditor_btn = item;
1992 case A_LINEWRAP_CURRENT:
1993 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
1994 toolbar_data->linewrap_current_btn = item;
1996 case A_LINEWRAP_ALL:
1997 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
1998 toolbar_data->linewrap_all_btn = item;
2001 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2002 toolbar_data->addrbook_btn = item;
2005 case A_CHECK_SPELLING:
2006 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2007 toolbar_data->spellcheck_btn = item;
2012 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2013 action_item = g_new0(ToolbarSylpheedActions, 1);
2014 action_item->widget = item;
2015 action_item->name = g_strdup(toolbar_item->text);
2017 toolbar_data->action_list =
2018 g_slist_append(toolbar_data->action_list,
2022 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2023 toolbar_data->cancel_inc_btn = item;
2026 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2027 toolbar_ret_descr_from_val(toolbar_item->index));
2028 /* find and set the tool tip text */
2033 toolbar_data->toolbar = toolbar;
2034 toolbar_data->tooltips = toolbar_tips;
2035 gtk_widget_show_all(toolbar);
2037 if (type == TOOLBAR_MAIN) {
2039 MainWindow *mainwin = mainwindow_get_mainwindow();
2040 GtkWidget *progressbar = gtk_progress_bar_new();
2041 item = gtk_tool_item_new();
2042 gtk_container_add (GTK_CONTAINER (item), progressbar);
2043 gtk_widget_show(item);
2044 gtk_widget_show(progressbar);
2045 gtk_widget_set_size_request(progressbar, 70, -1);
2046 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2047 mainwin->progressbar = progressbar;
2049 activate_compose_button(toolbar_data,
2050 prefs_common.toolbar_style,
2051 toolbar_data->compose_btn_type);
2053 if (type != TOOLBAR_COMPOSE)
2054 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2058 gtk_container_add(GTK_CONTAINER(container), toolbar);
2059 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2061 if ( GTK_IS_WINDOW(container) ) {
2062 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
2063 gtk_widget_show_all (container);
2065 gtk_container_add(GTK_CONTAINER(container), toolbar);
2066 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2069 return toolbar_data;
2073 * Free toolbar structures
2075 void toolbar_destroy(Toolbar * toolbar) {
2077 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2078 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2081 void toolbar_update(ToolbarType type, gpointer data)
2083 Toolbar *toolbar_data;
2084 GtkWidget *handlebox;
2085 MainWindow *mainwin = (MainWindow*)data;
2086 Compose *compose = (Compose*)data;
2087 MessageView *msgview = (MessageView*)data;
2092 toolbar_data = mainwin->toolbar;
2093 handlebox = mainwin->handlebox;
2095 case TOOLBAR_COMPOSE:
2096 toolbar_data = compose->toolbar;
2097 handlebox = compose->handlebox;
2099 case TOOLBAR_MSGVIEW:
2100 toolbar_data = msgview->toolbar;
2101 handlebox = msgview->handlebox;
2107 gtk_container_remove(GTK_CONTAINER(handlebox),
2108 GTK_WIDGET(toolbar_data->toolbar));
2110 toolbar_init(toolbar_data);
2111 toolbar_data = toolbar_create(type, handlebox, data);
2115 toolbar_data = mainwin->toolbar;
2116 handlebox = mainwin->window;
2118 case TOOLBAR_COMPOSE:
2119 toolbar_data = compose->toolbar;
2120 handlebox = compose->window;
2122 case TOOLBAR_MSGVIEW:
2123 toolbar_data = msgview->toolbar;
2124 handlebox = msgview->window;
2130 hildon_window_remove_toolbar(HILDON_WINDOW(handlebox), GTK_WIDGET(toolbar_data->toolbar));
2132 toolbar_init(toolbar_data);
2133 toolbar_data = toolbar_create(type, handlebox, data);
2138 mainwin->toolbar = toolbar_data;
2140 case TOOLBAR_COMPOSE:
2141 compose->toolbar = toolbar_data;
2143 case TOOLBAR_MSGVIEW:
2144 msgview->toolbar = toolbar_data;
2148 toolbar_style(type, prefs_common.toolbar_style, data);
2150 if (type == TOOLBAR_MAIN) {
2151 toolbar_main_set_sensitive((MainWindow*)data);
2152 account_set_menu_only_toolbar();
2156 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2157 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2158 if (GTK_IS_BUTTON(widget)) \
2159 in_btn1 = GTK_BUTTON(widget)->in_button; \
2160 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2161 GtkWidget *child = gtk_bin_get_child( \
2163 GList *gchild = gtk_container_get_children( \
2164 GTK_CONTAINER(child)); \
2165 GtkWidget *btn = (GtkWidget *)gchild->data; \
2166 GtkWidget *arr = (GtkWidget *) \
2167 (gchild->next?gchild->next->data:NULL); \
2168 g_list_free(gchild); \
2169 if (GTK_IS_BUTTON(btn)) \
2170 in_btn1 = GTK_BUTTON(btn)->in_button; \
2171 if (GTK_IS_BUTTON(arr)) \
2172 in_btn2 = GTK_BUTTON(arr)->in_button; \
2174 else if (GTK_IS_TOOL_ITEM(widget)) { \
2175 GtkWidget *child = gtk_bin_get_child( \
2177 if (GTK_IS_BUTTON(child)) \
2178 in_btn1 = GTK_BUTTON(child)->in_button; \
2180 gtk_widget_set_sensitive(widget, sensitive); \
2181 if (GTK_IS_BUTTON(widget)) \
2182 GTK_BUTTON(widget)->in_button = in_btn1; \
2183 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2184 GtkWidget *child = gtk_bin_get_child( \
2186 GList *gchild = gtk_container_get_children( \
2187 GTK_CONTAINER(child)); \
2188 GtkWidget *btn = (GtkWidget *)gchild->data; \
2189 GtkWidget *arr = (GtkWidget *) \
2190 (gchild->next?gchild->next->data:NULL); \
2191 g_list_free(gchild); \
2192 if (GTK_IS_BUTTON(btn)) \
2193 GTK_BUTTON(btn)->in_button = in_btn1; \
2194 if (GTK_IS_BUTTON(arr)) \
2195 GTK_BUTTON(arr)->in_button = in_btn2; \
2197 else if (GTK_IS_TOOL_ITEM(widget)) { \
2198 GtkWidget *child = gtk_bin_get_child( \
2200 if (GTK_IS_BUTTON(child)) \
2201 GTK_BUTTON(child)->in_button = in_btn1; \
2205 void toolbar_main_set_sensitive(gpointer data)
2207 SensitiveCond state;
2209 MainWindow *mainwin = (MainWindow*)data;
2210 Toolbar *toolbar = mainwin->toolbar;
2212 GSList *entry_list = NULL;
2214 typedef struct _Entry Entry;
2221 #define SET_WIDGET_COND(w, c) \
2223 Entry *e = g_new0(Entry, 1); \
2226 entry_list = g_slist_append(entry_list, e); \
2230 if (toolbar->get_btn)
2231 SET_WIDGET_COND(toolbar->get_btn,
2232 M_HAVE_ACCOUNT|M_UNLOCKED);
2234 if (toolbar->getall_btn) {
2235 SET_WIDGET_COND(toolbar->getall_btn,
2236 M_HAVE_ACCOUNT|M_UNLOCKED);
2238 if (toolbar->send_btn) {
2239 SET_WIDGET_COND(toolbar->send_btn,
2240 M_HAVE_QUEUED_MAILS);
2242 if (toolbar->compose_mail_btn) {
2243 SET_WIDGET_COND(toolbar->compose_mail_btn,
2246 if (toolbar->close_window_btn) {
2247 SET_WIDGET_COND(toolbar->close_window_btn,
2250 if (toolbar->open_mail_btn) {
2251 SET_WIDGET_COND(toolbar->open_mail_btn,
2254 if (toolbar->reply_btn) {
2255 SET_WIDGET_COND(toolbar->reply_btn,
2256 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2258 if (toolbar->replyall_btn) {
2259 SET_WIDGET_COND(toolbar->replyall_btn,
2260 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2262 if (toolbar->replylist_btn) {
2263 SET_WIDGET_COND(toolbar->replylist_btn,
2264 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2266 if (toolbar->replysender_btn) {
2267 SET_WIDGET_COND(toolbar->replysender_btn,
2268 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2270 if (toolbar->fwd_btn) {
2271 SET_WIDGET_COND(toolbar->fwd_btn,
2272 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2275 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2276 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
2278 SET_WIDGET_COND(toolbar->next_btn, 0);
2281 if (toolbar->trash_btn)
2282 SET_WIDGET_COND(toolbar->trash_btn,
2283 M_TARGET_EXIST|M_ALLOW_DELETE);
2285 if (toolbar->delete_btn)
2286 SET_WIDGET_COND(toolbar->delete_btn,
2287 M_TARGET_EXIST|M_ALLOW_DELETE);
2289 if (toolbar->exec_btn)
2290 SET_WIDGET_COND(toolbar->exec_btn,
2293 /* if (toolbar->learn_ham_btn)
2294 SET_WIDGET_COND(toolbar->learn_ham_btn,
2295 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2297 if (toolbar->learn_spam_btn)
2298 SET_WIDGET_COND(toolbar->learn_spam_btn,
2299 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2301 if (toolbar->cancel_inc_btn)
2302 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2305 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2306 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
2308 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2311 #undef SET_WIDGET_COND
2313 state = main_window_get_current_state(mainwin);
2315 for (cur = entry_list; cur != NULL; cur = cur->next) {
2316 Entry *e = (Entry*) cur->data;
2318 if (e->widget != NULL) {
2319 sensitive = ((e->cond & state) == e->cond);
2320 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2324 while (entry_list != NULL) {
2325 Entry *e = (Entry*) entry_list->data;
2328 entry_list = g_slist_remove(entry_list, e);
2331 g_slist_free(entry_list);
2333 activate_compose_button(toolbar,
2334 prefs_common.toolbar_style,
2335 toolbar->compose_btn_type);
2339 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2341 Compose *compose = (Compose*)data;
2342 GSList *items = compose->toolbar->action_list;
2344 if (compose->toolbar->send_btn)
2345 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2346 if (compose->toolbar->sendl_btn)
2347 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2348 if (compose->toolbar->draft_btn )
2349 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2350 if (compose->toolbar->insert_btn )
2351 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2352 if (compose->toolbar->attach_btn)
2353 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2354 if (compose->toolbar->sig_btn)
2355 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2356 if (compose->toolbar->exteditor_btn)
2357 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2358 if (compose->toolbar->linewrap_current_btn)
2359 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2360 if (compose->toolbar->linewrap_all_btn)
2361 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2362 if (compose->toolbar->addrbook_btn)
2363 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2365 if (compose->toolbar->spellcheck_btn)
2366 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2368 for (; items != NULL; items = g_slist_next(items)) {
2369 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
2370 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2375 * Initialize toolbar structure
2377 void toolbar_init(Toolbar * toolbar) {
2379 toolbar->toolbar = NULL;
2380 toolbar->folders_btn = NULL;
2381 toolbar->get_btn = NULL;
2382 toolbar->getall_btn = NULL;
2383 toolbar->send_btn = NULL;
2384 toolbar->compose_mail_btn = NULL;
2385 toolbar->compose_mail_icon = NULL;
2386 toolbar->compose_news_icon = NULL;
2387 toolbar->reply_btn = NULL;
2388 toolbar->replysender_btn = NULL;
2389 toolbar->replyall_btn = NULL;
2390 toolbar->replylist_btn = NULL;
2391 toolbar->fwd_btn = NULL;
2392 toolbar->trash_btn = NULL;
2393 toolbar->delete_btn = NULL;
2394 toolbar->prev_btn = NULL;
2395 toolbar->next_btn = NULL;
2396 toolbar->exec_btn = NULL;
2397 toolbar->open_mail_btn = NULL;
2398 toolbar->close_window_btn = NULL;
2399 /* compose buttons */
2400 toolbar->sendl_btn = NULL;
2401 toolbar->draft_btn = NULL;
2402 toolbar->insert_btn = NULL;
2403 toolbar->attach_btn = NULL;
2404 toolbar->sig_btn = NULL;
2405 toolbar->exteditor_btn = NULL;
2406 toolbar->linewrap_current_btn = NULL;
2407 toolbar->linewrap_all_btn = NULL;
2408 toolbar->addrbook_btn = NULL;
2410 toolbar->spellcheck_btn = NULL;
2413 toolbar_destroy(toolbar);
2418 static void toolbar_reply(gpointer data, guint action)
2420 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2421 MainWindow *mainwin;
2422 MessageView *msgview;
2423 GSList *msginfo_list = NULL;
2425 g_return_if_fail(toolbar_item != NULL);
2427 switch (toolbar_item->type) {
2429 mainwin = (MainWindow*)toolbar_item->parent;
2430 msginfo_list = summary_get_selection(mainwin->summaryview);
2431 msgview = (MessageView*)mainwin->messageview;
2433 case TOOLBAR_MSGVIEW:
2434 msgview = (MessageView*)toolbar_item->parent;
2435 g_return_if_fail(msgview != NULL);
2436 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2442 g_return_if_fail(msgview != NULL);
2443 g_return_if_fail(msginfo_list != NULL);
2444 compose_reply_from_messageview(msgview, msginfo_list, action);
2445 g_slist_free(msginfo_list);
2447 /* TODO: update reply state ion summaryview */
2451 /* exported functions */
2453 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2455 MainWindow *mainwin = (MainWindow*)data;
2457 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2460 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2462 MainWindow *mainwin = (MainWindow*)data;
2464 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2467 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2471 gboolean got_error = FALSE;
2472 gchar *errstr = NULL;
2474 if (prefs_common.work_offline)
2475 if (alertpanel(_("Offline warning"),
2476 _("You're working offline. Override?"),
2477 GTK_STOCK_NO, GTK_STOCK_YES,
2478 NULL) != G_ALERTALTERNATE)
2481 /* ask for confirmation before sending queued messages only
2482 in online mode and if there is at least one message queued
2483 in any of the folder queue
2485 if (prefs_common.confirm_send_queued_messages) {
2487 /* check if there's a queued message */
2488 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2489 Folder *folder = list->data;
2491 found = !procmsg_queue_is_empty(folder->queue);
2493 /* if necessary, ask for confirmation before sending */
2494 if (found && !prefs_common.work_offline) {
2495 if (alertpanel(_("Send queued messages"),
2496 _("Send all queued messages?"),
2497 GTK_STOCK_CANCEL, _("_Send"),
2498 NULL) != G_ALERTALTERNATE)
2503 for (list = folder_get_list(); list != NULL; list = list->next) {
2504 Folder *folder = list->data;
2506 if (folder->queue) {
2507 if (procmsg_send_queue(folder->queue,
2508 prefs_common.savemsg,
2515 alertpanel_error_log(_("Some errors occurred while "
2516 "sending queued messages."));
2518 alertpanel_error_log(_("Some errors occurred "
2519 "while sending queued messages:\n%s"), errstr);
2525 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2527 MainWindow *mainwin = (MainWindow*)data;
2528 PrefsAccount *ac = NULL;
2529 FolderItem *item = mainwin->summaryview->folder_item;
2534 ac = account_find_from_item(item);
2535 if (ac && ac->protocol != A_NNTP) {
2536 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2542 * CLAWS - use current account
2544 if (cur_account && (cur_account->protocol != A_NNTP)) {
2545 compose_new_with_folderitem(cur_account, item, NULL);
2550 * CLAWS - just get the first one
2552 list = account_get_list();
2553 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2554 ac = (PrefsAccount *) cur->data;
2555 if (ac->protocol != A_NNTP) {
2556 compose_new_with_folderitem(ac, item, NULL);
2562 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2564 MainWindow *mainwin = (MainWindow*)data;
2565 PrefsAccount * ac = NULL;
2569 if (mainwin->summaryview->folder_item) {
2570 ac = mainwin->summaryview->folder_item->folder->account;
2571 if (ac && ac->protocol == A_NNTP) {
2572 compose_new_with_folderitem(ac,
2573 mainwin->summaryview->folder_item, NULL);
2578 list = account_get_list();
2579 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2580 ac = (PrefsAccount *) cur->data;
2581 if (ac->protocol == A_NNTP) {
2582 compose_new_with_folderitem(ac,
2583 mainwin->summaryview->folder_item, NULL);