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");
441 case A_CHECK_SPELLING: return _("Check spelling");
447 static void toolbar_set_default_main(void)
452 } default_toolbar[] = {
454 { A_GO_FOLDERS, STOCK_PIXMAP_GO_FOLDERS },
455 { A_OPEN_MAIL, STOCK_PIXMAP_OPEN_MAIL },
458 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL },
460 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE},
461 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE },
463 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY},
465 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL},
466 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR},
468 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD},
470 { A_TRASH, STOCK_PIXMAP_TRASH},
472 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
473 { A_LEARN_SPAM, STOCK_PIXMAP_SPAM_BTN},
477 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW }
482 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
484 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
486 if (default_toolbar[i].action != A_SEPARATOR) {
488 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
490 toolbar_item->file = g_strdup(file);
491 toolbar_item->index = default_toolbar[i].action;
492 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
495 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
496 toolbar_item->index = A_SEPARATOR;
499 if (toolbar_item->index != -1) {
500 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
501 toolbar_config[TOOLBAR_MAIN].item_list =
502 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
507 static void toolbar_set_default_compose(void)
512 } default_toolbar[] = {
514 { A_CLOSE, STOCK_PIXMAP_CLOSE},
517 { A_SEND, STOCK_PIXMAP_MAIL_SEND},
518 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE},
519 { A_DRAFT, STOCK_PIXMAP_MAIL},
522 { A_INSERT, STOCK_PIXMAP_INSERT_FILE},
524 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH},
526 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK }
531 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
533 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
535 if (default_toolbar[i].action != A_SEPARATOR) {
537 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
539 toolbar_item->file = g_strdup(file);
540 toolbar_item->index = default_toolbar[i].action;
541 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
544 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
545 toolbar_item->index = A_SEPARATOR;
548 if (toolbar_item->index != -1) {
549 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
550 toolbar_config[TOOLBAR_COMPOSE].item_list =
551 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
556 static void toolbar_set_default_msgview(void)
561 } default_toolbar[] = {
563 { A_CLOSE, STOCK_PIXMAP_CLOSE},
566 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY},
567 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL},
568 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR},
569 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD},
571 { A_TRASH, STOCK_PIXMAP_TRASH},
573 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
574 { A_LEARN_SPAM, STOCK_PIXMAP_SPAM_BTN},
577 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW }
582 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
584 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
586 if (default_toolbar[i].action != A_SEPARATOR) {
588 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
590 toolbar_item->file = g_strdup(file);
591 toolbar_item->index = default_toolbar[i].action;
592 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
595 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
596 toolbar_item->index = A_SEPARATOR;
599 if (toolbar_item->index != -1) {
600 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
601 toolbar_config[TOOLBAR_MSGVIEW].item_list =
602 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
607 void toolbar_set_default(ToolbarType source)
609 if (source == TOOLBAR_MAIN)
610 toolbar_set_default_main();
611 else if (source == TOOLBAR_COMPOSE)
612 toolbar_set_default_compose();
613 else if (source == TOOLBAR_MSGVIEW)
614 toolbar_set_default_msgview();
617 void toolbar_save_config_file(ToolbarType source)
622 gchar *fileSpec = NULL;
624 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
626 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
627 pfile = prefs_write_open(fileSpec);
630 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
633 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
636 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
637 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
639 if (toolbar_item->index != A_SEPARATOR) {
640 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
642 TOOLBAR_ICON_FILE, toolbar_item->file,
643 TOOLBAR_ICON_TEXT) < 0)
645 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
647 if (fprintf(fp, "\" %s=\"%s\"/>\n",
649 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
652 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
657 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
661 if (prefs_file_close (pfile) < 0 )
662 g_warning("failed to write toolbar configuration to file\n");
666 FILE_OP_ERROR(fileSpec, "fprintf");
668 prefs_file_close_revert (pfile);
670 g_warning("failed to open toolbar configuration file for writing\n");
673 void toolbar_read_config_file(ToolbarType source)
675 XMLFile *file = NULL;
676 gchar *fileSpec = NULL;
681 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
683 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
684 file = xml_open_file(fileSpec);
687 toolbar_clear_list(source);
691 || (xml_get_dtd(file))
692 || (xml_parse_next_tag(file))
693 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
694 xml_close_file(file);
698 attr = xml_get_current_tag_attr(file);
705 if (xml_parse_next_tag(file))
708 /* Get next tag (icon, icon_text or icon_action) */
709 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
710 toolbar_parse_item(file, source);
711 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
712 ToolbarItem *item = g_new0(ToolbarItem, 1);
714 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
715 item->index = A_SEPARATOR;
716 toolbar_config[source].item_list =
717 g_slist_append(toolbar_config[source].item_list, item);
721 xml_close_file(file);
724 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
726 if (source == TOOLBAR_MAIN)
727 toolbar_set_default(TOOLBAR_MAIN);
728 else if (source == TOOLBAR_COMPOSE)
729 toolbar_set_default(TOOLBAR_COMPOSE);
730 else if (source == TOOLBAR_MSGVIEW)
731 toolbar_set_default(TOOLBAR_MSGVIEW);
733 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
737 toolbar_save_config_file(source);
742 * clears list of toolbar items read from configuration files
744 void toolbar_clear_list(ToolbarType source)
746 while (toolbar_config[source].item_list != NULL) {
747 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
749 toolbar_config[source].item_list =
750 g_slist_remove(toolbar_config[source].item_list, item);
756 g_slist_free(toolbar_config[source].item_list);
761 * return list of Toolbar items
763 GSList *toolbar_get_list(ToolbarType source)
767 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
768 list = toolbar_config[source].item_list;
773 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
775 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
777 toolbar_item->file = g_strdup(t_item->file);
778 toolbar_item->text = g_strdup(t_item->text);
779 toolbar_item->index = t_item->index;
781 toolbar_config[source].item_list =
782 g_slist_append(toolbar_config[source].item_list,
786 void toolbar_action_execute(GtkWidget *widget,
792 gchar *action, *action_p;
793 gboolean found = FALSE;
796 for (cur = action_list; cur != NULL; cur = cur->next) {
797 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
799 if (widget == act->widget) {
801 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
802 action = g_strdup((gchar*)lop->data);
804 action_p = strstr(action, ": ");
806 if (g_utf8_collate(act->name, action) == 0) {
820 actions_execute(data, i, widget, source);
822 g_warning ("Error: did not find Claws Action to execute");
825 static void activate_compose_button (Toolbar *toolbar,
827 ComposeButtonType type)
829 if ((!toolbar->compose_mail_btn))
832 if (type == COMPOSEBUTTON_NEWS) {
833 gtk_tool_button_set_icon_widget(
834 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
835 toolbar->compose_news_icon);
836 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->compose_mail_btn), GTK_TOOLTIPS(toolbar->tooltips),
837 _("Compose News message"), NULL);
838 gtk_widget_show(toolbar->compose_news_icon);
840 gtk_tool_button_set_icon_widget(
841 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
842 toolbar->compose_mail_icon);
843 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->compose_mail_btn), GTK_TOOLTIPS(toolbar->tooltips),
844 _("Compose Email"), NULL);
845 gtk_widget_show(toolbar->compose_mail_icon);
847 toolbar->compose_btn_type = type;
850 void toolbar_set_compose_button(Toolbar *toolbar,
851 ComposeButtonType compose_btn_type)
853 if (toolbar->compose_btn_type != compose_btn_type)
854 activate_compose_button(toolbar,
855 prefs_common.toolbar_style,
859 static void activate_learn_button (Toolbar *toolbar,
861 LearnButtonType type)
863 if ((!toolbar->learn_spam_btn))
866 if (type == LEARN_SPAM) {
867 gtk_tool_button_set_icon_widget(
868 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
869 toolbar->learn_spam_icon);
870 gtk_tool_button_set_label(
871 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
873 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->learn_spam_btn), GTK_TOOLTIPS(toolbar->tooltips),
874 _("Learn spam"), NULL);
875 gtk_widget_show(toolbar->learn_spam_icon);
877 gtk_tool_button_set_icon_widget(
878 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
879 toolbar->learn_ham_icon);
880 gtk_tool_button_set_label(
881 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
883 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->learn_spam_btn), GTK_TOOLTIPS(toolbar->tooltips),
884 _("Learn ham"), NULL);
885 gtk_widget_show(toolbar->learn_ham_icon);
887 toolbar->learn_btn_type = type;
890 void toolbar_set_learn_button(Toolbar *toolbar,
891 LearnButtonType learn_btn_type)
893 if (toolbar->learn_btn_type != learn_btn_type)
894 activate_learn_button(toolbar,
895 prefs_common.toolbar_style,
899 void toolbar_toggle(guint action, gpointer data)
901 MainWindow *mainwin = (MainWindow*)data;
905 g_return_if_fail(mainwin != NULL);
907 toolbar_style(TOOLBAR_MAIN, action, mainwin);
909 list = compose_get_compose_list();
910 for (cur = list; cur != NULL; cur = cur->next) {
911 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
913 list = messageview_get_msgview_list();
914 for (cur = list; cur != NULL; cur = cur->next) {
915 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
920 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
922 switch ((ToolbarStyle)action) {
924 gtk_widget_hide(handlebox_wid);
927 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
931 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
935 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
938 case TOOLBAR_BOTH_HORIZ:
939 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
940 GTK_TOOLBAR_BOTH_HORIZ);
946 prefs_common.toolbar_style = (ToolbarStyle)action;
947 gtk_widget_set_size_request(handlebox_wid, 1, -1);
949 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
950 gtk_widget_show(handlebox_wid);
951 gtk_widget_queue_resize(handlebox_wid);
955 * Change the style of toolbar
957 static void toolbar_style(ToolbarType type, guint action, gpointer data)
959 GtkWidget *handlebox_wid;
960 GtkWidget *toolbar_wid;
961 MainWindow *mainwin = (MainWindow*)data;
962 Compose *compose = (Compose*)data;
963 MessageView *msgview = (MessageView*)data;
965 g_return_if_fail(data != NULL);
969 handlebox_wid = mainwin->handlebox;
970 toolbar_wid = mainwin->toolbar->toolbar;
972 case TOOLBAR_COMPOSE:
973 handlebox_wid = compose->handlebox;
974 toolbar_wid = compose->toolbar->toolbar;
976 case TOOLBAR_MSGVIEW:
977 handlebox_wid = msgview->handlebox;
978 toolbar_wid = msgview->toolbar->toolbar;
984 toolbar_set_style(toolbar_wid, handlebox_wid, action);
987 /* Toolbar handling */
988 static void toolbar_inc_cb(GtkWidget *widget,
991 ToolbarItem *toolbar_item = (ToolbarItem*)data;
994 g_return_if_fail(toolbar_item != NULL);
996 switch (toolbar_item->type) {
998 mainwin = (MainWindow*)toolbar_item->parent;
999 inc_mail_cb(mainwin, 0, NULL);
1006 static void toolbar_inc_all_cb(GtkWidget *widget,
1009 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1010 MainWindow *mainwin;
1012 g_return_if_fail(toolbar_item != NULL);
1014 switch (toolbar_item->type) {
1016 mainwin = (MainWindow*)toolbar_item->parent;
1017 inc_all_account_mail_cb(mainwin, 0, NULL);
1024 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1026 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1027 MainWindow *mainwin;
1029 g_return_if_fail(toolbar_item != NULL);
1031 switch (toolbar_item->type) {
1033 mainwin = (MainWindow*)toolbar_item->parent;
1034 send_queue_cb(mainwin, 0, NULL);
1041 static void toolbar_exec_cb(GtkWidget *widget,
1044 MainWindow *mainwin = get_mainwin(data);
1046 g_return_if_fail(mainwin != NULL);
1047 summary_execute(mainwin->summaryview);
1051 * Delete current/selected(s) message(s)
1053 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1055 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1056 MainWindow *mainwin;
1058 g_return_if_fail(toolbar_item != NULL);
1059 g_return_if_fail(toolbar_item->parent);
1061 switch (toolbar_item->type) {
1062 case TOOLBAR_MSGVIEW:
1063 messageview_delete((MessageView *)toolbar_item->parent);
1066 mainwin = (MainWindow *)toolbar_item->parent;
1067 summary_delete_trash(mainwin->summaryview);
1070 debug_print("toolbar event not supported\n");
1076 * Delete current/selected(s) message(s)
1078 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1080 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1081 MainWindow *mainwin;
1083 g_return_if_fail(toolbar_item != NULL);
1084 g_return_if_fail(toolbar_item->parent);
1086 switch (toolbar_item->type) {
1087 case TOOLBAR_MSGVIEW:
1088 messageview_delete((MessageView *)toolbar_item->parent);
1091 mainwin = (MainWindow *)toolbar_item->parent;
1092 summary_delete(mainwin->summaryview);
1095 debug_print("toolbar event not supported\n");
1102 * Compose new message
1104 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1106 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1107 MainWindow *mainwin;
1108 MessageView *msgview;
1110 g_return_if_fail(toolbar_item != NULL);
1112 switch (toolbar_item->type) {
1114 mainwin = (MainWindow*)toolbar_item->parent;
1115 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1116 compose_news_cb(mainwin, 0, NULL);
1118 compose_mail_cb(mainwin, 0, NULL);
1120 case TOOLBAR_MSGVIEW:
1121 msgview = (MessageView*)toolbar_item->parent;
1122 compose_new_with_folderitem(NULL,
1123 msgview->msginfo->folder, NULL);
1126 debug_print("toolbar event not supported\n");
1130 static void toolbar_learn(gpointer data, guint as_spam)
1132 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1133 MainWindow *mainwin;
1134 MessageView *msgview;
1136 g_return_if_fail(toolbar_item != NULL);
1138 switch (toolbar_item->type) {
1140 mainwin = (MainWindow*)toolbar_item->parent;
1142 mainwindow_learn(mainwin, TRUE);
1144 mainwindow_learn(mainwin, FALSE);
1146 case TOOLBAR_MSGVIEW:
1147 msgview = (MessageView*)toolbar_item->parent;
1149 messageview_learn(msgview, TRUE);
1151 messageview_learn(msgview, FALSE);
1154 debug_print("toolbar event not supported\n");
1158 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1160 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1161 MainWindow *mainwin;
1162 MessageView *msgview;
1164 g_return_if_fail(toolbar_item != NULL);
1166 switch (toolbar_item->type) {
1168 mainwin = (MainWindow*)toolbar_item->parent;
1169 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1170 mainwindow_learn(mainwin, TRUE);
1172 mainwindow_learn(mainwin, FALSE);
1174 case TOOLBAR_MSGVIEW:
1175 msgview = (MessageView*)toolbar_item->parent;
1176 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1177 messageview_learn(msgview, TRUE);
1179 messageview_learn(msgview, FALSE);
1182 debug_print("toolbar event not supported\n");
1190 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1192 toolbar_reply(data, prefs_common.reply_with_quote ?
1193 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1198 * Reply message to Sender and All recipients
1200 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1203 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1204 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1209 * Reply to Mailing List
1211 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1214 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1215 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1220 * Reply to sender of message
1222 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1225 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1226 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1232 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1234 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1237 g_return_if_fail(toolbar_item != NULL);
1239 switch (toolbar_item->type) {
1241 case TOOLBAR_MSGVIEW:
1244 case TOOLBAR_COMPOSE:
1245 compose = (Compose *)toolbar_item->parent;
1250 addressbook_open(compose);
1255 * Forward current/selected(s) message(s)
1257 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1259 toolbar_reply(data, COMPOSE_FORWARD);
1263 * Goto Prev Unread Message
1265 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1267 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1268 MainWindow *mainwin;
1269 MessageView *msgview;
1271 g_return_if_fail(toolbar_item != NULL);
1273 switch (toolbar_item->type) {
1275 mainwin = (MainWindow*)toolbar_item->parent;
1276 summary_select_prev_unread(mainwin->summaryview);
1279 case TOOLBAR_MSGVIEW:
1280 msgview = (MessageView*)toolbar_item->parent;
1281 msgview->updating = TRUE;
1282 summary_select_prev_unread(msgview->mainwin->summaryview);
1283 msgview->updating = FALSE;
1285 if (msgview->deferred_destroy) {
1286 debug_print("messageview got away!\n");
1287 messageview_destroy(msgview);
1291 /* Now we need to update the messageview window */
1292 if (msgview->mainwin->summaryview->selected) {
1294 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1297 messageview_show(msgview, msginfo,
1298 msgview->all_headers);
1301 gtk_widget_destroy(msgview->window);
1305 debug_print("toolbar event not supported\n");
1310 * Goto Next Unread Message
1312 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1314 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1315 MainWindow *mainwin;
1316 MessageView *msgview;
1318 g_return_if_fail(toolbar_item != NULL);
1320 switch (toolbar_item->type) {
1322 mainwin = (MainWindow*)toolbar_item->parent;
1323 summary_select_next_unread(mainwin->summaryview);
1326 case TOOLBAR_MSGVIEW:
1327 msgview = (MessageView*)toolbar_item->parent;
1328 msgview->updating = TRUE;
1329 summary_select_next_unread(msgview->mainwin->summaryview);
1330 msgview->updating = FALSE;
1332 if (msgview->deferred_destroy) {
1333 debug_print("messageview got away!\n");
1334 messageview_destroy(msgview);
1338 /* Now we need to update the messageview window */
1339 if (msgview->mainwin->summaryview->selected) {
1341 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1344 messageview_show(msgview, msginfo,
1345 msgview->all_headers);
1348 gtk_widget_destroy(msgview->window);
1352 debug_print("toolbar event not supported\n");
1356 static void toolbar_ignore_thread_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_toggle_ignore_thread(mainwin->summaryview);
1368 case TOOLBAR_MSGVIEW:
1369 /* TODO: see toolbar_next_unread_cb() if you need
1370 * this in the message view */
1373 debug_print("toolbar event not supported\n");
1378 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1380 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1381 MainWindow *mainwin;
1383 g_return_if_fail(toolbar_item != NULL);
1385 switch (toolbar_item->type) {
1387 mainwin = (MainWindow *) toolbar_item->parent;
1388 summary_toggle_watch_thread(mainwin->summaryview);
1390 case TOOLBAR_MSGVIEW:
1391 /* TODO: see toolbar_next_unread_cb() if you need
1392 * this in the message view */
1395 debug_print("toolbar event not supported\n");
1400 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1402 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1404 g_return_if_fail(toolbar_item != NULL);
1410 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1412 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1413 MainWindow *mainwin;
1415 g_return_if_fail(toolbar_item != NULL);
1417 switch (toolbar_item->type) {
1419 mainwin = (MainWindow *) toolbar_item->parent;
1420 summary_print(mainwin->summaryview);
1422 case TOOLBAR_MSGVIEW:
1423 /* TODO: see toolbar_next_unread_cb() if you need
1424 * this in the message view */
1427 debug_print("toolbar event not supported\n");
1432 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1434 compose_toolbar_cb(A_SEND, data);
1437 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1439 compose_toolbar_cb(A_SENDL, data);
1442 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1444 compose_toolbar_cb(A_DRAFT, data);
1447 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1449 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1450 MainWindow *mainwin;
1451 MessageView *messageview;
1454 g_return_if_fail(toolbar_item != NULL);
1456 switch (toolbar_item->type) {
1458 mainwin = (MainWindow *) toolbar_item->parent;
1459 app_will_exit(NULL, mainwin);
1461 case TOOLBAR_MSGVIEW:
1462 messageview = (MessageView *)toolbar_item->parent;
1463 messageview_destroy(messageview);
1465 case TOOLBAR_COMPOSE:
1466 compose = (Compose *)toolbar_item->parent;
1467 compose_close_toolbar(compose);
1472 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1474 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1475 MainWindow *mainwin;
1477 g_return_if_fail(toolbar_item != NULL);
1479 switch (toolbar_item->type) {
1481 mainwin = (MainWindow *) toolbar_item->parent;
1482 summary_open_row(NULL, mainwin->summaryview);
1484 case TOOLBAR_MSGVIEW:
1485 debug_print("toolbar event not supported\n");
1487 case TOOLBAR_COMPOSE:
1488 debug_print("toolbar event not supported\n");
1493 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1495 compose_toolbar_cb(A_INSERT, data);
1498 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1500 compose_toolbar_cb(A_ATTACH, data);
1503 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1505 compose_toolbar_cb(A_SIG, data);
1508 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1510 compose_toolbar_cb(A_EXTEDITOR, data);
1513 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1515 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1518 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1520 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1524 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1526 compose_toolbar_cb(A_CHECK_SPELLING, data);
1530 * Execute actions from toolbar
1532 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1534 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1535 GSList *action_list;
1536 MainWindow *mainwin;
1538 MessageView *msgview;
1539 gpointer parent = toolbar_item->parent;
1541 g_return_if_fail(toolbar_item != NULL);
1543 switch (toolbar_item->type) {
1545 mainwin = (MainWindow*)parent;
1546 action_list = mainwin->toolbar->action_list;
1548 case TOOLBAR_COMPOSE:
1549 compose = (Compose*)parent;
1550 action_list = compose->toolbar->action_list;
1552 case TOOLBAR_MSGVIEW:
1553 msgview = (MessageView*)parent;
1554 action_list = msgview->toolbar->action_list;
1557 debug_print("toolbar event not supported\n");
1560 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1563 static MainWindow *get_mainwin(gpointer data)
1565 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1566 MainWindow *mainwin = NULL;
1567 MessageView *msgview;
1569 g_return_val_if_fail(toolbar_item != NULL, NULL);
1571 switch(toolbar_item->type) {
1573 mainwin = (MainWindow*)toolbar_item->parent;
1575 case TOOLBAR_MSGVIEW:
1576 msgview = (MessageView*)toolbar_item->parent;
1577 mainwin = (MainWindow*)msgview->mainwin;
1586 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1588 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1589 MainWindow *mainwin = NULL;
1590 switch(toolbar_item->type) {
1592 mainwin = (MainWindow*)toolbar_item->parent;
1595 g_warning("wrong toolbar type\n");
1599 if (!mainwin->in_folder) {
1600 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1602 folderview_select(mainwin->folderview, item);
1605 gtk_widget_grab_focus(mainwin->folderview->ctree);
1606 mainwindow_exit_folder(mainwin);
1610 static void toolbar_buttons_cb(GtkWidget *widget,
1617 void (*func)(GtkWidget *widget, gpointer data);
1619 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1620 { A_RECEIVE_CUR, toolbar_inc_cb },
1621 { A_SEND_QUEUED, toolbar_send_queued_cb },
1622 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1623 { A_COMPOSE_NEWS, toolbar_compose_cb },
1624 { A_REPLY_MESSAGE, toolbar_reply_cb },
1625 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1626 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1627 { A_REPLY_ML, toolbar_reply_to_list_cb },
1628 { A_FORWARD, toolbar_forward_cb },
1629 { A_TRASH, toolbar_trash_cb },
1630 { A_DELETE_REAL, toolbar_delete_cb },
1631 { A_EXECUTE, toolbar_exec_cb },
1632 { A_GOTO_PREV, toolbar_prev_unread_cb },
1633 { A_GOTO_NEXT, toolbar_next_unread_cb },
1634 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1635 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1636 { A_PRINT, toolbar_print_cb },
1637 { A_LEARN_SPAM, toolbar_learn_cb },
1638 { A_GO_FOLDERS, toolbar_go_folders_cb },
1640 { A_SEND, toolbar_send_cb },
1641 { A_SENDL, toolbar_send_later_cb },
1642 { A_DRAFT, toolbar_draft_cb },
1643 { A_OPEN_MAIL, toolbar_open_mail_cb },
1644 { A_CLOSE, toolbar_close_cb },
1645 { A_INSERT, toolbar_insert_cb },
1646 { A_ATTACH, toolbar_attach_cb },
1647 { A_SIG, toolbar_sig_cb },
1648 { A_EXTEDITOR, toolbar_ext_editor_cb },
1649 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1650 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1651 { A_ADDRBOOK, toolbar_addrbook_cb },
1653 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1655 { A_SYL_ACTIONS, toolbar_actions_execute_cb },
1656 { A_CANCEL_INC, toolbar_cancel_inc_cb }
1659 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1661 for (i = 0; i < num_items; i++) {
1662 if (callbacks[i].index == item->index) {
1663 callbacks[i].func(widget, item);
1669 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1670 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1671 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1672 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1673 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1674 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1675 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1679 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1680 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1681 GList *gchild = NULL; \
1682 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1683 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1684 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1685 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1686 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1687 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1689 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(item), \
1690 GTK_TOOLTIPS(toolbar_tips), menutip, NULL); \
1691 child = gtk_bin_get_child(GTK_BIN(item)); \
1692 gchild = gtk_container_get_children( \
1693 GTK_CONTAINER(child)); \
1694 btn = (GtkWidget *)gchild->data; \
1695 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1696 g_list_free(gchild); \
1697 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1698 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1699 g_list_free(gchild); \
1702 #define MAKE_MENU(entries,path,btn) { \
1703 n_menu_entries = sizeof(entries) / \
1704 sizeof(entries[0]); \
1705 menu = menu_create_items(entries, n_menu_entries, path, &factory, toolbar_item); \
1706 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(btn), menu); \
1710 * Create a new toolbar with specified type
1711 * if a callback list is passed it will be used before the
1712 * common callback list
1714 Toolbar *toolbar_create(ToolbarType type,
1715 GtkWidget *container,
1718 ToolbarItem *toolbar_item;
1721 GtkWidget *icon_wid = NULL;
1722 GtkWidget *icon_news;
1723 GtkWidget *icon_ham;
1726 guint n_menu_entries;
1727 GtkItemFactory *factory;
1728 GtkTooltips *toolbar_tips;
1729 ToolbarSylpheedActions *action_item;
1731 GSList *toolbar_list;
1732 Toolbar *toolbar_data;
1735 toolbar_tips = gtk_tooltips_new();
1737 toolbar_read_config_file(type);
1738 toolbar_list = toolbar_get_list(type);
1740 toolbar_data = g_new0(Toolbar, 1);
1742 toolbar = gtk_toolbar_new();
1744 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1745 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1746 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1748 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1750 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1751 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1755 toolbar_item = g_new0(ToolbarItem, 1);
1756 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1757 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1758 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1759 toolbar_item->parent = data;
1760 toolbar_item->type = type;
1762 /* collect toolbar items in list to keep track */
1763 toolbar_data->item_list =
1764 g_slist_append(toolbar_data->item_list,
1766 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1768 switch (toolbar_item->index) {
1771 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1772 toolbar_data->folders_btn = item;
1775 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1776 _("Receive Mail on all Accounts"),
1777 _("Receive Mail on selected Account"));
1778 toolbar_data->getall_btn = item;
1781 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail on current Account"));
1782 toolbar_data->get_btn = item;
1785 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1786 toolbar_data->send_btn = item;
1789 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1790 toolbar_data->close_window_btn = item;
1793 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1794 toolbar_data->open_mail_btn = item;
1796 case A_COMPOSE_EMAIL:
1798 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1800 _("Compose with selected Account"));
1801 toolbar_data->compose_mail_btn = item;
1802 toolbar_data->compose_mail_icon = icon_wid;
1803 g_object_ref(toolbar_data->compose_mail_icon);
1805 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1806 toolbar_data->compose_news_icon = icon_news;
1807 g_object_ref(toolbar_data->compose_news_icon);
1809 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1810 _("Compose Email"));
1811 toolbar_data->compose_mail_btn = item;
1812 toolbar_data->compose_mail_icon = icon_wid;
1814 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1815 toolbar_data->compose_news_icon = icon_news;
1819 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1822 toolbar_data->learn_spam_btn = item;
1823 toolbar_data->learn_spam_icon = icon_wid;
1824 g_object_ref(toolbar_data->learn_spam_icon);
1826 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1827 toolbar_data->learn_ham_icon = icon_ham;
1828 g_object_ref(toolbar_data->learn_ham_icon);
1830 MAKE_MENU(learn_entries,"<LearnSpam>",toolbar_data->learn_spam_btn);
1832 case A_REPLY_MESSAGE:
1834 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1835 _("Reply to Message"),
1836 _("Reply to Message options"));
1837 toolbar_data->reply_btn = item;
1839 MAKE_MENU(reply_entries,"<Reply>",toolbar_data->reply_btn);
1841 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1842 _("Reply to Message"));
1843 toolbar_data->reply_btn = item;
1846 case A_REPLY_SENDER:
1848 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1849 _("Reply to Sender"),
1850 _("Reply to Sender options"));
1851 toolbar_data->replysender_btn = item;
1853 MAKE_MENU(replysender_entries,"<ReplySender>",toolbar_data->replysender_btn);
1855 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1856 _("Reply to Sender"));
1857 toolbar_data->replysender_btn = item;
1862 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1864 _("Reply to All options"));
1865 toolbar_data->replyall_btn = item;
1867 MAKE_MENU(replyall_entries,"<ReplyAll>",toolbar_data->replyall_btn);
1869 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1871 toolbar_data->replyall_btn = item;
1876 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1877 _("Reply to Mailing-list"),
1878 _("Reply to Mailing-list options"));
1879 toolbar_data->replylist_btn = item;
1881 MAKE_MENU(replylist_entries,"<ReplyList>",toolbar_data->replylist_btn);
1883 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1884 _("Reply to Mailing-list"));
1885 toolbar_data->replylist_btn = item;
1890 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1891 _("Forward Message"),
1892 _("Forward Message options"));
1893 toolbar_data->fwd_btn = item;
1895 MAKE_MENU(forward_entries,"<Forward>",toolbar_data->fwd_btn);
1897 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1898 _("Forward Message"));
1899 toolbar_data->fwd_btn = item;
1903 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
1904 toolbar_data->trash_btn = item;
1907 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
1908 toolbar_data->delete_btn = item;
1911 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
1912 toolbar_data->exec_btn = item;
1915 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
1916 toolbar_data->prev_btn = item;
1919 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
1920 toolbar_data->next_btn = item;
1923 /* Compose Toolbar */
1925 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
1926 toolbar_data->send_btn = item;
1929 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
1930 toolbar_data->sendl_btn = item;
1933 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
1934 toolbar_data->draft_btn = item;
1937 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
1938 toolbar_data->insert_btn = item;
1941 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
1942 toolbar_data->attach_btn = item;
1945 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
1946 toolbar_data->sig_btn = item;
1949 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
1950 toolbar_data->exteditor_btn = item;
1952 case A_LINEWRAP_CURRENT:
1953 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
1954 toolbar_data->linewrap_current_btn = item;
1956 case A_LINEWRAP_ALL:
1957 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
1958 toolbar_data->linewrap_all_btn = item;
1961 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
1962 toolbar_data->addrbook_btn = item;
1965 case A_CHECK_SPELLING:
1966 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
1967 toolbar_data->spellcheck_btn = item;
1972 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
1973 action_item = g_new0(ToolbarSylpheedActions, 1);
1974 action_item->widget = item;
1975 action_item->name = g_strdup(toolbar_item->text);
1977 toolbar_data->action_list =
1978 g_slist_append(toolbar_data->action_list,
1982 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
1983 toolbar_data->cancel_inc_btn = item;
1986 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1987 toolbar_ret_descr_from_val(toolbar_item->index));
1988 /* find and set the tool tip text */
1993 toolbar_data->toolbar = toolbar;
1994 toolbar_data->tooltips = toolbar_tips;
1995 gtk_widget_show_all(toolbar);
1997 if (type == TOOLBAR_MAIN) {
1999 MainWindow *mainwin = mainwindow_get_mainwindow();
2000 GtkWidget *progressbar = gtk_progress_bar_new();
2001 item = gtk_tool_item_new();
2002 gtk_container_add (GTK_CONTAINER (item), progressbar);
2003 gtk_widget_show(item);
2004 gtk_widget_show(progressbar);
2005 gtk_widget_set_size_request(progressbar, 70, -1);
2006 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2007 mainwin->progressbar = progressbar;
2009 activate_compose_button(toolbar_data,
2010 prefs_common.toolbar_style,
2011 toolbar_data->compose_btn_type);
2013 if (type != TOOLBAR_COMPOSE)
2014 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2018 gtk_container_add(GTK_CONTAINER(container), toolbar);
2019 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2021 if ( GTK_IS_WINDOW(container) ) {
2022 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
2023 gtk_widget_show_all (container);
2025 gtk_container_add(GTK_CONTAINER(container), toolbar);
2026 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2029 return toolbar_data;
2033 * Free toolbar structures
2035 void toolbar_destroy(Toolbar * toolbar) {
2037 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2038 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2041 void toolbar_update(ToolbarType type, gpointer data)
2043 Toolbar *toolbar_data;
2044 GtkWidget *handlebox;
2045 MainWindow *mainwin = (MainWindow*)data;
2046 Compose *compose = (Compose*)data;
2047 MessageView *msgview = (MessageView*)data;
2052 toolbar_data = mainwin->toolbar;
2053 handlebox = mainwin->handlebox;
2055 case TOOLBAR_COMPOSE:
2056 toolbar_data = compose->toolbar;
2057 handlebox = compose->handlebox;
2059 case TOOLBAR_MSGVIEW:
2060 toolbar_data = msgview->toolbar;
2061 handlebox = msgview->handlebox;
2067 gtk_container_remove(GTK_CONTAINER(handlebox),
2068 GTK_WIDGET(toolbar_data->toolbar));
2070 toolbar_init(toolbar_data);
2071 toolbar_data = toolbar_create(type, handlebox, data);
2075 toolbar_data = mainwin->toolbar;
2076 handlebox = mainwin->window;
2078 case TOOLBAR_COMPOSE:
2079 toolbar_data = compose->toolbar;
2080 handlebox = compose->window;
2082 case TOOLBAR_MSGVIEW:
2083 toolbar_data = msgview->toolbar;
2084 handlebox = msgview->window;
2090 hildon_window_remove_toolbar(HILDON_WINDOW(handlebox), GTK_WIDGET(toolbar_data->toolbar));
2092 toolbar_init(toolbar_data);
2093 toolbar_data = toolbar_create(type, handlebox, data);
2098 mainwin->toolbar = toolbar_data;
2100 case TOOLBAR_COMPOSE:
2101 compose->toolbar = toolbar_data;
2103 case TOOLBAR_MSGVIEW:
2104 msgview->toolbar = toolbar_data;
2108 toolbar_style(type, prefs_common.toolbar_style, data);
2110 if (type == TOOLBAR_MAIN) {
2111 toolbar_main_set_sensitive((MainWindow*)data);
2112 account_set_menu_only_toolbar();
2116 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2117 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2118 if (GTK_IS_BUTTON(widget)) \
2119 in_btn1 = GTK_BUTTON(widget)->in_button; \
2120 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2121 GtkWidget *child = gtk_bin_get_child( \
2123 GList *gchild = gtk_container_get_children( \
2124 GTK_CONTAINER(child)); \
2125 GtkWidget *btn = (GtkWidget *)gchild->data; \
2126 GtkWidget *arr = (GtkWidget *) \
2127 (gchild->next?gchild->next->data:NULL); \
2128 g_list_free(gchild); \
2129 if (GTK_IS_BUTTON(btn)) \
2130 in_btn1 = GTK_BUTTON(btn)->in_button; \
2131 if (GTK_IS_BUTTON(arr)) \
2132 in_btn2 = GTK_BUTTON(arr)->in_button; \
2134 else if (GTK_IS_TOOL_ITEM(widget)) { \
2135 GtkWidget *child = gtk_bin_get_child( \
2137 if (GTK_IS_BUTTON(child)) \
2138 in_btn1 = GTK_BUTTON(child)->in_button; \
2140 gtk_widget_set_sensitive(widget, sensitive); \
2141 if (GTK_IS_BUTTON(widget)) \
2142 GTK_BUTTON(widget)->in_button = in_btn1; \
2143 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2144 GtkWidget *child = gtk_bin_get_child( \
2146 GList *gchild = gtk_container_get_children( \
2147 GTK_CONTAINER(child)); \
2148 GtkWidget *btn = (GtkWidget *)gchild->data; \
2149 GtkWidget *arr = (GtkWidget *) \
2150 (gchild->next?gchild->next->data:NULL); \
2151 g_list_free(gchild); \
2152 if (GTK_IS_BUTTON(btn)) \
2153 GTK_BUTTON(btn)->in_button = in_btn1; \
2154 if (GTK_IS_BUTTON(arr)) \
2155 GTK_BUTTON(arr)->in_button = in_btn2; \
2157 else if (GTK_IS_TOOL_ITEM(widget)) { \
2158 GtkWidget *child = gtk_bin_get_child( \
2160 if (GTK_IS_BUTTON(child)) \
2161 GTK_BUTTON(child)->in_button = in_btn1; \
2165 void toolbar_main_set_sensitive(gpointer data)
2167 SensitiveCond state;
2169 MainWindow *mainwin = (MainWindow*)data;
2170 Toolbar *toolbar = mainwin->toolbar;
2172 GSList *entry_list = NULL;
2174 typedef struct _Entry Entry;
2181 #define SET_WIDGET_COND(w, c) \
2183 Entry *e = g_new0(Entry, 1); \
2186 entry_list = g_slist_append(entry_list, e); \
2190 if (toolbar->get_btn)
2191 SET_WIDGET_COND(toolbar->get_btn,
2192 M_HAVE_ACCOUNT|M_UNLOCKED);
2194 if (toolbar->getall_btn) {
2195 SET_WIDGET_COND(toolbar->getall_btn,
2196 M_HAVE_ACCOUNT|M_UNLOCKED);
2198 if (toolbar->send_btn) {
2199 SET_WIDGET_COND(toolbar->send_btn,
2200 M_HAVE_QUEUED_MAILS);
2202 if (toolbar->compose_mail_btn) {
2203 SET_WIDGET_COND(toolbar->compose_mail_btn,
2206 if (toolbar->close_window_btn) {
2207 SET_WIDGET_COND(toolbar->close_window_btn,
2210 if (toolbar->open_mail_btn) {
2211 SET_WIDGET_COND(toolbar->open_mail_btn,
2214 if (toolbar->reply_btn) {
2215 SET_WIDGET_COND(toolbar->reply_btn,
2216 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2218 if (toolbar->replyall_btn) {
2219 SET_WIDGET_COND(toolbar->replyall_btn,
2220 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2222 if (toolbar->replylist_btn) {
2223 SET_WIDGET_COND(toolbar->replylist_btn,
2224 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2226 if (toolbar->replysender_btn) {
2227 SET_WIDGET_COND(toolbar->replysender_btn,
2228 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2230 if (toolbar->fwd_btn) {
2231 SET_WIDGET_COND(toolbar->fwd_btn,
2232 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2235 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2236 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
2238 SET_WIDGET_COND(toolbar->next_btn, 0);
2241 if (toolbar->trash_btn)
2242 SET_WIDGET_COND(toolbar->trash_btn,
2243 M_TARGET_EXIST|M_ALLOW_DELETE);
2245 if (toolbar->delete_btn)
2246 SET_WIDGET_COND(toolbar->delete_btn,
2247 M_TARGET_EXIST|M_ALLOW_DELETE);
2249 if (toolbar->exec_btn)
2250 SET_WIDGET_COND(toolbar->exec_btn,
2253 /* if (toolbar->learn_ham_btn)
2254 SET_WIDGET_COND(toolbar->learn_ham_btn,
2255 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2257 if (toolbar->learn_spam_btn)
2258 SET_WIDGET_COND(toolbar->learn_spam_btn,
2259 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2261 if (toolbar->cancel_inc_btn)
2262 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2265 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2266 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
2268 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2271 #undef SET_WIDGET_COND
2273 state = main_window_get_current_state(mainwin);
2275 for (cur = entry_list; cur != NULL; cur = cur->next) {
2276 Entry *e = (Entry*) cur->data;
2278 if (e->widget != NULL) {
2279 sensitive = ((e->cond & state) == e->cond);
2280 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2284 while (entry_list != NULL) {
2285 Entry *e = (Entry*) entry_list->data;
2288 entry_list = g_slist_remove(entry_list, e);
2291 g_slist_free(entry_list);
2293 activate_compose_button(toolbar,
2294 prefs_common.toolbar_style,
2295 toolbar->compose_btn_type);
2299 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2301 Compose *compose = (Compose*)data;
2302 GSList *items = compose->toolbar->action_list;
2304 if (compose->toolbar->send_btn)
2305 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2306 if (compose->toolbar->sendl_btn)
2307 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2308 if (compose->toolbar->draft_btn )
2309 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2310 if (compose->toolbar->insert_btn )
2311 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2312 if (compose->toolbar->attach_btn)
2313 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2314 if (compose->toolbar->sig_btn)
2315 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2316 if (compose->toolbar->exteditor_btn)
2317 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2318 if (compose->toolbar->linewrap_current_btn)
2319 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2320 if (compose->toolbar->linewrap_all_btn)
2321 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2322 if (compose->toolbar->addrbook_btn)
2323 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2325 if (compose->toolbar->spellcheck_btn)
2326 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2328 for (; items != NULL; items = g_slist_next(items)) {
2329 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
2330 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2335 * Initialize toolbar structure
2337 void toolbar_init(Toolbar * toolbar) {
2339 toolbar->toolbar = NULL;
2340 toolbar->folders_btn = NULL;
2341 toolbar->get_btn = NULL;
2342 toolbar->getall_btn = NULL;
2343 toolbar->send_btn = NULL;
2344 toolbar->compose_mail_btn = NULL;
2345 toolbar->compose_mail_icon = NULL;
2346 toolbar->compose_news_icon = NULL;
2347 toolbar->reply_btn = NULL;
2348 toolbar->replysender_btn = NULL;
2349 toolbar->replyall_btn = NULL;
2350 toolbar->replylist_btn = NULL;
2351 toolbar->fwd_btn = NULL;
2352 toolbar->trash_btn = NULL;
2353 toolbar->delete_btn = NULL;
2354 toolbar->prev_btn = NULL;
2355 toolbar->next_btn = NULL;
2356 toolbar->exec_btn = NULL;
2357 toolbar->open_mail_btn = NULL;
2358 toolbar->close_window_btn = NULL;
2359 /* compose buttons */
2360 toolbar->sendl_btn = NULL;
2361 toolbar->draft_btn = NULL;
2362 toolbar->insert_btn = NULL;
2363 toolbar->attach_btn = NULL;
2364 toolbar->sig_btn = NULL;
2365 toolbar->exteditor_btn = NULL;
2366 toolbar->linewrap_current_btn = NULL;
2367 toolbar->linewrap_all_btn = NULL;
2368 toolbar->addrbook_btn = NULL;
2370 toolbar->spellcheck_btn = NULL;
2373 toolbar_destroy(toolbar);
2378 static void toolbar_reply(gpointer data, guint action)
2380 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2381 MainWindow *mainwin;
2382 MessageView *msgview;
2383 GSList *msginfo_list = NULL;
2385 g_return_if_fail(toolbar_item != NULL);
2387 switch (toolbar_item->type) {
2389 mainwin = (MainWindow*)toolbar_item->parent;
2390 msginfo_list = summary_get_selection(mainwin->summaryview);
2391 msgview = (MessageView*)mainwin->messageview;
2393 case TOOLBAR_MSGVIEW:
2394 msgview = (MessageView*)toolbar_item->parent;
2395 g_return_if_fail(msgview != NULL);
2396 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2402 g_return_if_fail(msgview != NULL);
2403 g_return_if_fail(msginfo_list != NULL);
2404 compose_reply_from_messageview(msgview, msginfo_list, action);
2405 g_slist_free(msginfo_list);
2407 /* TODO: update reply state ion summaryview */
2411 /* exported functions */
2413 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2415 MainWindow *mainwin = (MainWindow*)data;
2417 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2420 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2422 MainWindow *mainwin = (MainWindow*)data;
2424 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2427 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2431 gboolean got_error = FALSE;
2432 gchar *errstr = NULL;
2434 if (prefs_common.work_offline)
2435 if (alertpanel(_("Offline warning"),
2436 _("You're working offline. Override?"),
2437 GTK_STOCK_NO, GTK_STOCK_YES,
2438 NULL) != G_ALERTALTERNATE)
2441 /* ask for confirmation before sending queued messages only
2442 in online mode and if there is at least one message queued
2443 in any of the folder queue
2445 if (prefs_common.confirm_send_queued_messages) {
2447 /* check if there's a queued message */
2448 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2449 Folder *folder = list->data;
2451 found = !procmsg_queue_is_empty(folder->queue);
2453 /* if necessary, ask for confirmation before sending */
2454 if (found && !prefs_common.work_offline) {
2455 if (alertpanel(_("Send queued messages"),
2456 _("Send all queued messages?"),
2457 GTK_STOCK_CANCEL, _("_Send"),
2458 NULL) != G_ALERTALTERNATE)
2463 for (list = folder_get_list(); list != NULL; list = list->next) {
2464 Folder *folder = list->data;
2466 if (folder->queue) {
2467 if (procmsg_send_queue(folder->queue,
2468 prefs_common.savemsg,
2475 alertpanel_error_log(_("Some errors occurred while "
2476 "sending queued messages."));
2478 alertpanel_error_log(_("Some errors occurred "
2479 "while sending queued messages:\n%s"), errstr);
2485 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2487 MainWindow *mainwin = (MainWindow*)data;
2488 PrefsAccount *ac = NULL;
2489 FolderItem *item = mainwin->summaryview->folder_item;
2494 ac = account_find_from_item(item);
2495 if (ac && ac->protocol != A_NNTP) {
2496 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2502 * CLAWS - use current account
2504 if (cur_account && (cur_account->protocol != A_NNTP)) {
2505 compose_new_with_folderitem(cur_account, item, NULL);
2510 * CLAWS - just get the first one
2512 list = account_get_list();
2513 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2514 ac = (PrefsAccount *) cur->data;
2515 if (ac->protocol != A_NNTP) {
2516 compose_new_with_folderitem(ac, item, NULL);
2522 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2524 MainWindow *mainwin = (MainWindow*)data;
2525 PrefsAccount * ac = NULL;
2529 if (mainwin->summaryview->folder_item) {
2530 ac = mainwin->summaryview->folder_item->folder->account;
2531 if (ac && ac->protocol == A_NNTP) {
2532 compose_new_with_folderitem(ac,
2533 mainwin->summaryview->folder_item, NULL);
2538 list = account_get_list();
2539 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2540 ac = (PrefsAccount *) cur->data;
2541 if (ac->protocol == A_NNTP) {
2542 compose_new_with_folderitem(ac,
2543 mainwin->summaryview->folder_item, NULL);