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_print_cb (GtkWidget *widget,
133 static void toolbar_actions_execute_cb (GtkWidget *widget,
137 static void toolbar_send_cb (GtkWidget *widget,
139 static void toolbar_send_later_cb (GtkWidget *widget,
141 static void toolbar_draft_cb (GtkWidget *widget,
143 static void toolbar_close_cb (GtkWidget *widget,
145 static void toolbar_open_mail_cb (GtkWidget *widget,
147 static void toolbar_insert_cb (GtkWidget *widget,
149 static void toolbar_attach_cb (GtkWidget *widget,
151 static void toolbar_sig_cb (GtkWidget *widget,
153 static void toolbar_ext_editor_cb (GtkWidget *widget,
155 static void toolbar_linewrap_current_cb (GtkWidget *widget,
157 static void toolbar_linewrap_all_cb (GtkWidget *widget,
159 static void toolbar_addrbook_cb (GtkWidget *widget,
162 static void toolbar_check_spelling_cb (GtkWidget *widget,
165 static void toolbar_cancel_inc_cb (GtkWidget *widget,
171 } toolbar_text [] = {
172 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
173 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
174 { "A_SEND_QUEUED", N_("Send Queued Messages") },
175 { "A_COMPOSE_EMAIL", N_("Compose Email") },
176 { "A_COMPOSE_NEWS", N_("Compose News") },
177 { "A_REPLY_MESSAGE", N_("Reply to Message") },
178 { "A_REPLY_SENDER", N_("Reply to Sender") },
179 { "A_REPLY_ALL", N_("Reply to All") },
180 { "A_REPLY_ML", N_("Reply to Mailing-list") },
181 { "A_OPEN_MAIL", N_("Open email") },
182 { "A_FORWARD", N_("Forward Message") },
183 { "A_TRASH", N_("Trash Message") },
184 { "A_DELETE_REAL", N_("Delete Message") },
185 { "A_EXECUTE", N_("Execute") },
186 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
187 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
188 { "A_IGNORE_THREAD", N_("Ignore thread") },
189 { "A_PRINT", N_("Print") },
190 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
191 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
193 { "A_SEND", N_("Send Message") },
194 { "A_SENDL", N_("Put into queue folder and send later") },
195 { "A_DRAFT", N_("Save to draft folder") },
196 { "A_INSERT", N_("Insert file") },
197 { "A_ATTACH", N_("Attach file") },
198 { "A_SIG", N_("Insert signature") },
199 { "A_EXTEDITOR", N_("Edit with external editor") },
200 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
201 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
202 { "A_ADDRBOOK", N_("Address book") },
204 { "A_CHECK_SPELLING", N_("Check spelling") },
206 { "A_SYL_ACTIONS", N_("Claws Mail Actions Feature") },
207 { "A_CANCEL_INC", N_("Cancel receiving") },
208 { "A_CLOSE", N_("Close window") },
209 { "A_SEPARATOR", "Separator" }
212 /* struct holds configuration files and a list of
213 * currently active toolbar items
214 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
218 const gchar *conf_file;
220 } toolbar_config[3] = {
221 { "toolbar_main.xml", NULL},
222 { "toolbar_compose.xml", NULL},
223 { "toolbar_msgview.xml", NULL}
226 static GtkItemFactoryEntry reply_entries[] =
228 {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
229 {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
231 static GtkItemFactoryEntry replyall_entries[] =
233 {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
234 {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
236 static GtkItemFactoryEntry replylist_entries[] =
238 {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
239 {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
241 static GtkItemFactoryEntry replysender_entries[] =
243 {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
244 {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
246 static GtkItemFactoryEntry forward_entries[] =
248 {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
249 {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
250 {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, NULL}
252 static GtkItemFactoryEntry learn_entries[] =
254 {N_("/Learn as _Spam"), NULL, toolbar_learn, TRUE, NULL},
255 {N_("/Learn as _Ham"), NULL, toolbar_learn, FALSE, NULL}
259 gint toolbar_ret_val_from_descr(const gchar *descr)
263 for (i = 0; i < N_ACTION_VAL; i++) {
264 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
271 gchar *toolbar_ret_descr_from_val(gint val)
273 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
275 return gettext(toolbar_text[val].descr);
278 static gint toolbar_ret_val_from_text(const gchar *text)
282 for (i = 0; i < N_ACTION_VAL; i++) {
283 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
290 static gchar *toolbar_ret_text_from_val(gint val)
292 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
294 return toolbar_text[val].index_str;
297 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
301 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
304 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
305 ToolbarItem *item = (ToolbarItem*) cur->data;
307 if (item->index == action)
313 /* depending on toolbar type this function
314 returns a list of available toolbar events being
315 displayed by prefs_toolbar
317 GList *toolbar_get_action_items(ToolbarType source)
322 if (source == TOOLBAR_MAIN) {
323 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
324 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
325 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
326 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
327 A_GOTO_NEXT, A_IGNORE_THREAD, A_PRINT,
328 A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
329 A_SYL_ACTIONS, A_CANCEL_INC };
331 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
332 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
335 else if (source == TOOLBAR_COMPOSE) {
336 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
337 A_INSERT, A_ATTACH, A_SIG,
338 A_EXTEDITOR, A_LINEWRAP_CURRENT,
339 A_LINEWRAP_ALL, A_ADDRBOOK,
343 A_SYL_ACTIONS, A_CLOSE };
345 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
346 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
348 else if (source == TOOLBAR_MSGVIEW) {
349 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
350 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
351 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
352 A_ADDRBOOK, A_LEARN_SPAM, A_SYL_ACTIONS, A_CLOSE };
354 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
355 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
361 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
365 ToolbarItem *item = NULL;
366 gboolean rewrite = FALSE;
368 attr = xml_get_current_tag_attr(file);
369 item = g_new0(ToolbarItem, 1);
371 name = ((XMLAttr *)attr->data)->name;
372 value = ((XMLAttr *)attr->data)->value;
374 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
375 item->file = g_strdup (value);
376 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
377 item->text = g_strdup (gettext(value));
378 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
379 item->index = toolbar_ret_val_from_text(value);
380 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
382 item->index = A_TRASH;
384 item->file = g_strdup("trash_btn");
386 item->text = g_strdup(_("Trash"));
389 attr = g_list_next(attr);
391 if (item->index != -1) {
393 if (!toolbar_is_duplicate(item->index, source))
394 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
398 toolbar_save_config_file(source);
402 static void toolbar_set_default_main(void)
408 } default_toolbar[] = {
410 { A_GO_FOLDERS, STOCK_PIXMAP_DIR_OPEN, _("Folders") },
411 { A_SEPARATOR, 0, ("") },
413 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get Mail")},
414 { A_SEPARATOR, 0, ("") },
415 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
416 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE,
417 (gchar*)Q_("Toolbar|Compose") },
418 { A_SEPARATOR, 0, ("") },
420 { A_OPEN_MAIL, STOCK_PIXMAP_OPEN_MAIL, _("Open") },
422 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
424 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
425 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
427 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
428 { A_SEPARATOR, 0, ("") },
429 { A_TRASH, STOCK_PIXMAP_TRASH, _("Trash") },
431 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
432 { A_LEARN_SPAM, STOCK_PIXMAP_SPAM_BTN, _("Spam") },
435 { A_SEPARATOR, 0, ("") },
436 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
441 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
443 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
445 if (default_toolbar[i].action != A_SEPARATOR) {
447 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
449 toolbar_item->file = g_strdup(file);
450 toolbar_item->index = default_toolbar[i].action;
451 toolbar_item->text = g_strdup(default_toolbar[i].text);
454 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
455 toolbar_item->index = A_SEPARATOR;
458 if (toolbar_item->index != -1) {
459 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
460 toolbar_config[TOOLBAR_MAIN].item_list =
461 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
466 static void toolbar_set_default_compose(void)
472 } default_toolbar[] = {
473 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
474 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
475 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
476 { A_SEPARATOR, 0, ("") },
478 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
480 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
481 { A_SEPARATOR, 0, ("") },
482 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
485 { A_SEPARATOR, 0, ("") },
486 { A_CLOSE, STOCK_PIXMAP_CLOSE, _("Close") }
492 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
494 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
496 if (default_toolbar[i].action != A_SEPARATOR) {
498 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
500 toolbar_item->file = g_strdup(file);
501 toolbar_item->index = default_toolbar[i].action;
502 toolbar_item->text = g_strdup(default_toolbar[i].text);
505 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
506 toolbar_item->index = A_SEPARATOR;
509 if (toolbar_item->index != -1) {
510 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
511 toolbar_config[TOOLBAR_COMPOSE].item_list =
512 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
517 static void toolbar_set_default_msgview(void)
523 } default_toolbar[] = {
524 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
525 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
526 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
527 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
528 { A_SEPARATOR, 0, ("") },
529 { A_TRASH, STOCK_PIXMAP_TRASH, _("Trash") },
531 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
532 { A_LEARN_SPAM, STOCK_PIXMAP_SPAM_BTN, _("Spam") },
535 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
538 { A_SEPARATOR, 0, ("") },
539 { A_CLOSE, STOCK_PIXMAP_CLOSE, _("Close") }
545 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
547 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
549 if (default_toolbar[i].action != A_SEPARATOR) {
551 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
553 toolbar_item->file = g_strdup(file);
554 toolbar_item->index = default_toolbar[i].action;
555 toolbar_item->text = g_strdup(default_toolbar[i].text);
558 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
559 toolbar_item->index = A_SEPARATOR;
562 if (toolbar_item->index != -1) {
563 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
564 toolbar_config[TOOLBAR_MSGVIEW].item_list =
565 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
570 void toolbar_set_default(ToolbarType source)
572 if (source == TOOLBAR_MAIN)
573 toolbar_set_default_main();
574 else if (source == TOOLBAR_COMPOSE)
575 toolbar_set_default_compose();
576 else if (source == TOOLBAR_MSGVIEW)
577 toolbar_set_default_msgview();
580 void toolbar_save_config_file(ToolbarType source)
585 gchar *fileSpec = NULL;
587 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
589 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
590 pfile = prefs_write_open(fileSpec);
594 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL);
596 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
598 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
599 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
601 if (toolbar_item->index != A_SEPARATOR) {
602 fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
604 TOOLBAR_ICON_FILE, toolbar_item->file,
606 xml_file_put_escape_str(fp, toolbar_item->text);
607 fprintf(fp, "\" %s=\"%s\"/>\n",
609 toolbar_ret_text_from_val(toolbar_item->index));
611 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
615 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
617 if (prefs_file_close (pfile) < 0 )
618 g_warning("failed to write toolbar configuration to file\n");
620 g_warning("failed to open toolbar configuration file for writing\n");
623 void toolbar_read_config_file(ToolbarType source)
625 XMLFile *file = NULL;
626 gchar *fileSpec = NULL;
631 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
633 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
634 file = xml_open_file(fileSpec);
637 toolbar_clear_list(source);
641 || (xml_get_dtd(file))
642 || (xml_parse_next_tag(file))
643 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
644 xml_close_file(file);
648 attr = xml_get_current_tag_attr(file);
655 if (xml_parse_next_tag(file))
658 /* Get next tag (icon, icon_text or icon_action) */
659 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
660 toolbar_parse_item(file, source);
661 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
662 ToolbarItem *item = g_new0(ToolbarItem, 1);
664 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
665 item->index = A_SEPARATOR;
666 toolbar_config[source].item_list =
667 g_slist_append(toolbar_config[source].item_list, item);
671 xml_close_file(file);
674 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
676 if (source == TOOLBAR_MAIN)
677 toolbar_set_default(TOOLBAR_MAIN);
678 else if (source == TOOLBAR_COMPOSE)
679 toolbar_set_default(TOOLBAR_COMPOSE);
680 else if (source == TOOLBAR_MSGVIEW)
681 toolbar_set_default(TOOLBAR_MSGVIEW);
683 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
687 toolbar_save_config_file(source);
692 * clears list of toolbar items read from configuration files
694 void toolbar_clear_list(ToolbarType source)
696 while (toolbar_config[source].item_list != NULL) {
697 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
699 toolbar_config[source].item_list =
700 g_slist_remove(toolbar_config[source].item_list, item);
706 g_slist_free(toolbar_config[source].item_list);
711 * return list of Toolbar items
713 GSList *toolbar_get_list(ToolbarType source)
717 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
718 list = toolbar_config[source].item_list;
723 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
725 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
727 toolbar_item->file = g_strdup(t_item->file);
728 toolbar_item->text = g_strdup(t_item->text);
729 toolbar_item->index = t_item->index;
731 toolbar_config[source].item_list =
732 g_slist_append(toolbar_config[source].item_list,
736 void toolbar_action_execute(GtkWidget *widget,
742 gchar *action, *action_p;
743 gboolean found = FALSE;
746 for (cur = action_list; cur != NULL; cur = cur->next) {
747 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
749 if (widget == act->widget) {
751 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
752 action = g_strdup((gchar*)lop->data);
754 action_p = strstr(action, ": ");
756 if (g_utf8_collate(act->name, action) == 0) {
770 actions_execute(data, i, widget, source);
772 g_warning ("Error: did not find Claws Action to execute");
775 static void activate_compose_button (Toolbar *toolbar,
777 ComposeButtonType type)
779 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
781 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
782 : toolbar->compose_news_btn);
783 gtk_widget_show_now(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
784 : toolbar->compose_mail_btn);
785 toolbar->compose_btn_type = type;
786 gtk_widget_queue_resize(toolbar->toolbar);
787 gtk_widget_show_now(toolbar->toolbar);
791 void toolbar_set_compose_button(Toolbar *toolbar,
792 ComposeButtonType compose_btn_type)
794 if (toolbar->compose_btn_type != compose_btn_type)
795 activate_compose_button(toolbar,
796 prefs_common.toolbar_style,
800 static void activate_learn_button (Toolbar *toolbar,
802 LearnButtonType type)
804 if ((!toolbar->learn_spam_btn) || (!toolbar->learn_ham_btn))
807 gtk_widget_hide(type == LEARN_SPAM ? toolbar->learn_ham_btn
808 : toolbar->learn_spam_btn);
809 gtk_widget_show_now(type == LEARN_SPAM ? toolbar->learn_spam_btn
810 : toolbar->learn_ham_btn);
811 toolbar->learn_btn_type = type;
812 gtk_widget_queue_resize(toolbar->toolbar);
813 gtk_widget_show_now(toolbar->toolbar);
817 void toolbar_set_learn_button(Toolbar *toolbar,
818 LearnButtonType learn_btn_type)
820 if (toolbar->learn_btn_type != learn_btn_type)
821 activate_learn_button(toolbar,
822 prefs_common.toolbar_style,
826 void toolbar_toggle(guint action, gpointer data)
828 MainWindow *mainwin = (MainWindow*)data;
832 g_return_if_fail(mainwin != NULL);
834 toolbar_style(TOOLBAR_MAIN, action, mainwin);
836 list = compose_get_compose_list();
837 for (cur = list; cur != NULL; cur = cur->next) {
838 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
840 list = messageview_get_msgview_list();
841 for (cur = list; cur != NULL; cur = cur->next) {
842 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
847 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
849 switch ((ToolbarStyle)action) {
851 gtk_widget_hide(handlebox_wid);
854 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
858 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
862 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
865 case TOOLBAR_BOTH_HORIZ:
866 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
867 GTK_TOOLBAR_BOTH_HORIZ);
873 prefs_common.toolbar_style = (ToolbarStyle)action;
874 gtk_widget_set_size_request(handlebox_wid, 1, -1);
876 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
877 gtk_widget_show(handlebox_wid);
878 gtk_widget_queue_resize(handlebox_wid);
882 * Change the style of toolbar
884 static void toolbar_style(ToolbarType type, guint action, gpointer data)
886 GtkWidget *handlebox_wid;
887 GtkWidget *toolbar_wid;
888 MainWindow *mainwin = (MainWindow*)data;
889 Compose *compose = (Compose*)data;
890 MessageView *msgview = (MessageView*)data;
892 g_return_if_fail(data != NULL);
896 handlebox_wid = mainwin->handlebox;
897 toolbar_wid = mainwin->toolbar->toolbar;
899 case TOOLBAR_COMPOSE:
900 handlebox_wid = compose->handlebox;
901 toolbar_wid = compose->toolbar->toolbar;
903 case TOOLBAR_MSGVIEW:
904 handlebox_wid = msgview->handlebox;
905 toolbar_wid = msgview->toolbar->toolbar;
911 toolbar_set_style(toolbar_wid, handlebox_wid, action);
914 /* Toolbar handling */
915 static void toolbar_inc_cb(GtkWidget *widget,
918 ToolbarItem *toolbar_item = (ToolbarItem*)data;
921 g_return_if_fail(toolbar_item != NULL);
923 switch (toolbar_item->type) {
925 mainwin = (MainWindow*)toolbar_item->parent;
926 inc_mail_cb(mainwin, 0, NULL);
933 static void toolbar_inc_all_cb(GtkWidget *widget,
936 ToolbarItem *toolbar_item = (ToolbarItem*)data;
939 g_return_if_fail(toolbar_item != NULL);
941 switch (toolbar_item->type) {
943 mainwin = (MainWindow*)toolbar_item->parent;
944 inc_all_account_mail_cb(mainwin, 0, NULL);
951 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
953 ToolbarItem *toolbar_item = (ToolbarItem*)data;
956 g_return_if_fail(toolbar_item != NULL);
958 switch (toolbar_item->type) {
960 mainwin = (MainWindow*)toolbar_item->parent;
961 send_queue_cb(mainwin, 0, NULL);
968 static void toolbar_exec_cb(GtkWidget *widget,
971 MainWindow *mainwin = get_mainwin(data);
973 g_return_if_fail(mainwin != NULL);
974 summary_execute(mainwin->summaryview);
978 * Delete current/selected(s) message(s)
980 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
982 ToolbarItem *toolbar_item = (ToolbarItem*)data;
985 g_return_if_fail(toolbar_item != NULL);
986 g_return_if_fail(toolbar_item->parent);
988 switch (toolbar_item->type) {
989 case TOOLBAR_MSGVIEW:
990 messageview_delete((MessageView *)toolbar_item->parent);
993 mainwin = (MainWindow *)toolbar_item->parent;
994 summary_delete_trash(mainwin->summaryview);
997 debug_print("toolbar event not supported\n");
1003 * Delete current/selected(s) message(s)
1005 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1007 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1008 MainWindow *mainwin;
1010 g_return_if_fail(toolbar_item != NULL);
1011 g_return_if_fail(toolbar_item->parent);
1013 switch (toolbar_item->type) {
1014 case TOOLBAR_MSGVIEW:
1015 messageview_delete((MessageView *)toolbar_item->parent);
1018 mainwin = (MainWindow *)toolbar_item->parent;
1019 summary_delete(mainwin->summaryview);
1022 debug_print("toolbar event not supported\n");
1029 * Compose new message
1031 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1033 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1034 MainWindow *mainwin;
1035 MessageView *msgview;
1037 g_return_if_fail(toolbar_item != NULL);
1039 switch (toolbar_item->type) {
1041 mainwin = (MainWindow*)toolbar_item->parent;
1042 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1043 compose_news_cb(mainwin, 0, NULL);
1045 compose_mail_cb(mainwin, 0, NULL);
1047 case TOOLBAR_MSGVIEW:
1048 msgview = (MessageView*)toolbar_item->parent;
1049 compose_new_with_folderitem(NULL,
1050 msgview->msginfo->folder, NULL);
1053 debug_print("toolbar event not supported\n");
1057 static void toolbar_learn(gpointer data, guint as_spam)
1059 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1060 MainWindow *mainwin;
1061 MessageView *msgview;
1063 g_return_if_fail(toolbar_item != NULL);
1065 switch (toolbar_item->type) {
1067 mainwin = (MainWindow*)toolbar_item->parent;
1069 mainwindow_learn(mainwin, TRUE);
1071 mainwindow_learn(mainwin, FALSE);
1073 case TOOLBAR_MSGVIEW:
1074 msgview = (MessageView*)toolbar_item->parent;
1076 messageview_learn(msgview, TRUE);
1078 messageview_learn(msgview, FALSE);
1081 debug_print("toolbar event not supported\n");
1085 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1087 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1088 MainWindow *mainwin;
1089 MessageView *msgview;
1091 g_return_if_fail(toolbar_item != NULL);
1093 switch (toolbar_item->type) {
1095 mainwin = (MainWindow*)toolbar_item->parent;
1096 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1097 mainwindow_learn(mainwin, TRUE);
1099 mainwindow_learn(mainwin, FALSE);
1101 case TOOLBAR_MSGVIEW:
1102 msgview = (MessageView*)toolbar_item->parent;
1103 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1104 messageview_learn(msgview, TRUE);
1106 messageview_learn(msgview, FALSE);
1109 debug_print("toolbar event not supported\n");
1117 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1119 toolbar_reply(data, prefs_common.reply_with_quote ?
1120 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1125 * Reply message to Sender and All recipients
1127 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1130 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1131 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1136 * Reply to Mailing List
1138 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1141 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1142 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1147 * Reply to sender of message
1149 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1152 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1153 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1159 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1161 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1164 g_return_if_fail(toolbar_item != NULL);
1166 switch (toolbar_item->type) {
1168 case TOOLBAR_MSGVIEW:
1171 case TOOLBAR_COMPOSE:
1172 compose = (Compose *)toolbar_item->parent;
1177 addressbook_open(compose);
1182 * Forward current/selected(s) message(s)
1184 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1186 toolbar_reply(data, COMPOSE_FORWARD);
1190 * Goto Prev Unread Message
1192 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1194 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1195 MainWindow *mainwin;
1196 MessageView *msgview;
1198 g_return_if_fail(toolbar_item != NULL);
1200 switch (toolbar_item->type) {
1202 mainwin = (MainWindow*)toolbar_item->parent;
1203 summary_select_prev_unread(mainwin->summaryview);
1206 case TOOLBAR_MSGVIEW:
1207 msgview = (MessageView*)toolbar_item->parent;
1208 msgview->updating = TRUE;
1209 summary_select_prev_unread(msgview->mainwin->summaryview);
1210 msgview->updating = FALSE;
1212 if (msgview->deferred_destroy) {
1213 debug_print("messageview got away!\n");
1214 messageview_destroy(msgview);
1218 /* Now we need to update the messageview window */
1219 if (msgview->mainwin->summaryview->selected) {
1220 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1223 messageview_show(msgview, msginfo,
1224 msgview->all_headers);
1226 gtk_widget_destroy(msgview->window);
1230 debug_print("toolbar event not supported\n");
1235 * Goto Next Unread Message
1237 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1239 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1240 MainWindow *mainwin;
1241 MessageView *msgview;
1243 g_return_if_fail(toolbar_item != NULL);
1245 switch (toolbar_item->type) {
1247 mainwin = (MainWindow*)toolbar_item->parent;
1248 summary_select_next_unread(mainwin->summaryview);
1251 case TOOLBAR_MSGVIEW:
1252 msgview = (MessageView*)toolbar_item->parent;
1253 msgview->updating = TRUE;
1254 summary_select_next_unread(msgview->mainwin->summaryview);
1255 msgview->updating = FALSE;
1257 if (msgview->deferred_destroy) {
1258 debug_print("messageview got away!\n");
1259 messageview_destroy(msgview);
1263 /* Now we need to update the messageview window */
1264 if (msgview->mainwin->summaryview->selected) {
1265 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1268 messageview_show(msgview, msginfo,
1269 msgview->all_headers);
1271 gtk_widget_destroy(msgview->window);
1275 debug_print("toolbar event not supported\n");
1279 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1281 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1282 MainWindow *mainwin;
1284 g_return_if_fail(toolbar_item != NULL);
1286 switch (toolbar_item->type) {
1288 mainwin = (MainWindow *) toolbar_item->parent;
1289 summary_toggle_ignore_thread(mainwin->summaryview);
1291 case TOOLBAR_MSGVIEW:
1292 /* TODO: see toolbar_next_unread_cb() if you need
1293 * this in the message view */
1296 debug_print("toolbar event not supported\n");
1301 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1303 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1305 g_return_if_fail(toolbar_item != NULL);
1311 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1313 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1314 MainWindow *mainwin;
1316 g_return_if_fail(toolbar_item != NULL);
1318 switch (toolbar_item->type) {
1320 mainwin = (MainWindow *) toolbar_item->parent;
1321 summary_print(mainwin->summaryview);
1323 case TOOLBAR_MSGVIEW:
1324 /* TODO: see toolbar_next_unread_cb() if you need
1325 * this in the message view */
1328 debug_print("toolbar event not supported\n");
1333 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1335 compose_toolbar_cb(A_SEND, data);
1338 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1340 compose_toolbar_cb(A_SENDL, data);
1343 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1345 compose_toolbar_cb(A_DRAFT, data);
1348 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1350 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1351 MainWindow *mainwin;
1352 MessageView *messageview;
1355 g_return_if_fail(toolbar_item != NULL);
1357 switch (toolbar_item->type) {
1359 mainwin = (MainWindow *) toolbar_item->parent;
1360 app_will_exit(NULL, mainwin);
1362 case TOOLBAR_MSGVIEW:
1363 messageview = (MessageView *)toolbar_item->parent;
1364 messageview_destroy(messageview);
1366 case TOOLBAR_COMPOSE:
1367 compose = (Compose *)toolbar_item->parent;
1368 compose_close_toolbar(compose);
1373 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1375 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1376 MainWindow *mainwin;
1378 g_return_if_fail(toolbar_item != NULL);
1380 switch (toolbar_item->type) {
1382 mainwin = (MainWindow *) toolbar_item->parent;
1383 summary_open_row(NULL, mainwin->summaryview);
1385 case TOOLBAR_MSGVIEW:
1386 debug_print("toolbar event not supported\n");
1388 case TOOLBAR_COMPOSE:
1389 debug_print("toolbar event not supported\n");
1394 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1396 compose_toolbar_cb(A_INSERT, data);
1399 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1401 compose_toolbar_cb(A_ATTACH, data);
1404 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1406 compose_toolbar_cb(A_SIG, data);
1409 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1411 compose_toolbar_cb(A_EXTEDITOR, data);
1414 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1416 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1419 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1421 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1425 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1427 compose_toolbar_cb(A_CHECK_SPELLING, data);
1431 * Execute actions from toolbar
1433 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1435 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1436 GSList *action_list;
1437 MainWindow *mainwin;
1439 MessageView *msgview;
1440 gpointer parent = toolbar_item->parent;
1442 g_return_if_fail(toolbar_item != NULL);
1444 switch (toolbar_item->type) {
1446 mainwin = (MainWindow*)parent;
1447 action_list = mainwin->toolbar->action_list;
1449 case TOOLBAR_COMPOSE:
1450 compose = (Compose*)parent;
1451 action_list = compose->toolbar->action_list;
1453 case TOOLBAR_MSGVIEW:
1454 msgview = (MessageView*)parent;
1455 action_list = msgview->toolbar->action_list;
1458 debug_print("toolbar event not supported\n");
1461 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1464 static MainWindow *get_mainwin(gpointer data)
1466 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1467 MainWindow *mainwin = NULL;
1468 MessageView *msgview;
1470 g_return_val_if_fail(toolbar_item != NULL, NULL);
1472 switch(toolbar_item->type) {
1474 mainwin = (MainWindow*)toolbar_item->parent;
1476 case TOOLBAR_MSGVIEW:
1477 msgview = (MessageView*)toolbar_item->parent;
1478 mainwin = (MainWindow*)msgview->mainwin;
1487 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1489 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1490 MainWindow *mainwin = NULL;
1491 switch(toolbar_item->type) {
1493 mainwin = (MainWindow*)toolbar_item->parent;
1496 g_warning("wrong toolbar type\n");
1500 if (!mainwin->in_folder) {
1501 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1503 folderview_select(mainwin->folderview, item);
1506 gtk_widget_grab_focus(mainwin->folderview->ctree);
1507 mainwindow_exit_folder(mainwin);
1511 static void toolbar_buttons_cb(GtkWidget *widget,
1518 void (*func)(GtkWidget *widget, gpointer data);
1520 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1521 { A_RECEIVE_CUR, toolbar_inc_cb },
1522 { A_SEND_QUEUED, toolbar_send_queued_cb },
1523 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1524 { A_COMPOSE_NEWS, toolbar_compose_cb },
1525 { A_REPLY_MESSAGE, toolbar_reply_cb },
1526 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1527 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1528 { A_REPLY_ML, toolbar_reply_to_list_cb },
1529 { A_FORWARD, toolbar_forward_cb },
1530 { A_TRASH, toolbar_trash_cb },
1531 { A_DELETE_REAL, toolbar_delete_cb },
1532 { A_EXECUTE, toolbar_exec_cb },
1533 { A_GOTO_PREV, toolbar_prev_unread_cb },
1534 { A_GOTO_NEXT, toolbar_next_unread_cb },
1535 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1536 { A_PRINT, toolbar_print_cb },
1537 { A_LEARN_SPAM, toolbar_learn_cb },
1538 { A_GO_FOLDERS, toolbar_go_folders_cb },
1540 { A_SEND, toolbar_send_cb },
1541 { A_SENDL, toolbar_send_later_cb },
1542 { A_DRAFT, toolbar_draft_cb },
1543 { A_OPEN_MAIL, toolbar_open_mail_cb },
1544 { A_CLOSE, toolbar_close_cb },
1545 { A_INSERT, toolbar_insert_cb },
1546 { A_ATTACH, toolbar_attach_cb },
1547 { A_SIG, toolbar_sig_cb },
1548 { A_EXTEDITOR, toolbar_ext_editor_cb },
1549 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1550 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1551 { A_ADDRBOOK, toolbar_addrbook_cb },
1553 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1555 { A_SYL_ACTIONS, toolbar_actions_execute_cb },
1556 { A_CANCEL_INC, toolbar_cancel_inc_cb }
1559 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1561 for (i = 0; i < num_items; i++) {
1562 if (callbacks[i].index == item->index) {
1563 callbacks[i].func(widget, item);
1570 #define HOMOGENEOUS TRUE
1572 #define HOMOGENEOUS FALSE
1574 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1575 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1576 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), HOMOGENEOUS); \
1577 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1578 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1579 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1580 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1584 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1585 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1586 GList *gchild = NULL; \
1587 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1588 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), HOMOGENEOUS); \
1589 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1590 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1591 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1592 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1594 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(item), \
1595 GTK_TOOLTIPS(toolbar_tips), menutip, NULL); \
1596 child = gtk_bin_get_child(GTK_BIN(item)); \
1597 gchild = gtk_container_get_children( \
1598 GTK_CONTAINER(child)); \
1599 btn = (GtkWidget *)gchild->data; \
1600 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1601 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1602 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1605 #define MAKE_MENU(entries,path,btn) { \
1606 n_menu_entries = sizeof(entries) / \
1607 sizeof(entries[0]); \
1608 menu = menu_create_items(entries, n_menu_entries, path, &factory, toolbar_item); \
1609 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(btn), menu); \
1613 * Create a new toolbar with specified type
1614 * if a callback list is passed it will be used before the
1615 * common callback list
1617 Toolbar *toolbar_create(ToolbarType type,
1618 GtkWidget *container,
1621 ToolbarItem *toolbar_item;
1624 GtkWidget *icon_wid = NULL;
1625 GtkWidget *icon_news;
1626 GtkWidget *icon_ham;
1629 guint n_menu_entries;
1630 GtkItemFactory *factory;
1631 GtkTooltips *toolbar_tips;
1632 ToolbarSylpheedActions *action_item;
1634 GSList *toolbar_list;
1635 Toolbar *toolbar_data;
1638 toolbar_tips = gtk_tooltips_new();
1640 toolbar_read_config_file(type);
1641 toolbar_list = toolbar_get_list(type);
1643 toolbar_data = g_new0(Toolbar, 1);
1645 toolbar = gtk_toolbar_new();
1647 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1648 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1649 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1651 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1653 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1654 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1658 toolbar_item = g_new0(ToolbarItem, 1);
1659 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1660 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1661 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1662 toolbar_item->parent = data;
1663 toolbar_item->type = type;
1665 /* collect toolbar items in list to keep track */
1666 toolbar_data->item_list =
1667 g_slist_append(toolbar_data->item_list,
1669 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1671 switch (toolbar_item->index) {
1674 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1675 toolbar_data->folders_btn = item;
1678 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1679 _("Receive Mail on all Accounts"),
1680 _("Receive Mail on selected Account"));
1681 toolbar_data->getall_btn = item;
1684 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail on current Account"));
1685 toolbar_data->get_btn = item;
1688 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1689 toolbar_data->send_btn = item;
1692 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1693 toolbar_data->close_window_btn = item;
1696 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1697 toolbar_data->open_mail_btn = item;
1699 case A_COMPOSE_EMAIL:
1701 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1703 _("Compose with selected Account"));
1704 toolbar_data->compose_mail_btn = item;
1706 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1707 TOOLBAR_MENUITEM(item,icon_news,_("Compose"),
1709 _("Compose with selected Account"));
1710 toolbar_data->compose_news_btn = item;
1712 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1713 _("Compose Email"));
1714 toolbar_data->compose_mail_btn = item;
1716 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1717 TOOLBAR_ITEM(item,icon_news,_("Compose"),
1719 toolbar_data->compose_news_btn = item;
1723 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1726 toolbar_data->learn_spam_btn = item;
1728 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1729 TOOLBAR_MENUITEM(item,icon_ham,_("Ham"),
1732 toolbar_data->learn_ham_btn = item;
1734 MAKE_MENU(learn_entries,"<LearnSpam>",toolbar_data->learn_spam_btn);
1735 MAKE_MENU(learn_entries,"<LearnHam>",toolbar_data->learn_ham_btn);
1737 case A_REPLY_MESSAGE:
1739 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1740 _("Reply to Message"),
1741 _("Reply to Message options"));
1742 toolbar_data->reply_btn = item;
1744 MAKE_MENU(reply_entries,"<Reply>",toolbar_data->reply_btn);
1746 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1747 _("Reply to Message"));
1748 toolbar_data->reply_btn = item;
1751 case A_REPLY_SENDER:
1753 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1754 _("Reply to Sender"),
1755 _("Reply to Sender options"));
1756 toolbar_data->replysender_btn = item;
1758 MAKE_MENU(replysender_entries,"<ReplySender>",toolbar_data->replysender_btn);
1760 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1761 _("Reply to Sender"));
1762 toolbar_data->replysender_btn = item;
1767 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1769 _("Reply to All options"));
1770 toolbar_data->replyall_btn = item;
1772 MAKE_MENU(replyall_entries,"<ReplyAll>",toolbar_data->replyall_btn);
1774 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1776 toolbar_data->replyall_btn = item;
1781 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1782 _("Reply to Mailing-list"),
1783 _("Reply to Mailing-list options"));
1784 toolbar_data->replylist_btn = item;
1786 MAKE_MENU(replylist_entries,"<ReplyList>",toolbar_data->replylist_btn);
1788 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1789 _("Reply to Mailing-list"));
1790 toolbar_data->replylist_btn = item;
1795 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1796 _("Forward Message"),
1797 _("Forward Message options"));
1798 toolbar_data->fwd_btn = item;
1800 MAKE_MENU(forward_entries,"<Forward>",toolbar_data->fwd_btn);
1802 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1803 _("Forward Message"));
1804 toolbar_data->fwd_btn = item;
1808 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
1809 toolbar_data->trash_btn = item;
1812 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
1813 toolbar_data->delete_btn = item;
1816 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
1817 toolbar_data->exec_btn = item;
1820 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
1821 toolbar_data->prev_btn = item;
1824 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
1825 toolbar_data->next_btn = item;
1828 /* Compose Toolbar */
1830 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
1831 toolbar_data->send_btn = item;
1834 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
1835 toolbar_data->sendl_btn = item;
1838 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
1839 toolbar_data->draft_btn = item;
1842 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
1843 toolbar_data->insert_btn = item;
1846 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
1847 toolbar_data->attach_btn = item;
1850 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
1851 toolbar_data->sig_btn = item;
1854 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
1855 toolbar_data->exteditor_btn = item;
1857 case A_LINEWRAP_CURRENT:
1858 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
1859 toolbar_data->linewrap_current_btn = item;
1861 case A_LINEWRAP_ALL:
1862 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
1863 toolbar_data->linewrap_all_btn = item;
1866 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
1867 toolbar_data->addrbook_btn = item;
1870 case A_CHECK_SPELLING:
1871 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
1872 toolbar_data->spellcheck_btn = item;
1877 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
1878 action_item = g_new0(ToolbarSylpheedActions, 1);
1879 action_item->widget = item;
1880 action_item->name = g_strdup(toolbar_item->text);
1882 toolbar_data->action_list =
1883 g_slist_append(toolbar_data->action_list,
1887 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
1888 toolbar_data->cancel_inc_btn = item;
1891 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1892 toolbar_ret_descr_from_val(toolbar_item->index));
1893 /* find and set the tool tip text */
1898 toolbar_data->toolbar = toolbar;
1899 gtk_widget_show_all(toolbar);
1901 if (type == TOOLBAR_MAIN)
1902 activate_compose_button(toolbar_data,
1903 prefs_common.toolbar_style,
1904 toolbar_data->compose_btn_type);
1905 if (type != TOOLBAR_COMPOSE)
1906 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
1910 gtk_container_add(GTK_CONTAINER(container), toolbar);
1911 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1913 if ( GTK_IS_WINDOW(container) ) {
1914 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
1915 gtk_widget_show_all (container);
1917 gtk_container_add(GTK_CONTAINER(container), toolbar);
1918 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1921 return toolbar_data;
1925 * Free toolbar structures
1927 void toolbar_destroy(Toolbar * toolbar) {
1929 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1930 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1933 void toolbar_update(ToolbarType type, gpointer data)
1935 Toolbar *toolbar_data;
1936 GtkWidget *handlebox;
1937 MainWindow *mainwin = (MainWindow*)data;
1938 Compose *compose = (Compose*)data;
1939 MessageView *msgview = (MessageView*)data;
1943 toolbar_data = mainwin->toolbar;
1944 handlebox = mainwin->handlebox;
1946 case TOOLBAR_COMPOSE:
1947 toolbar_data = compose->toolbar;
1948 handlebox = compose->handlebox;
1950 case TOOLBAR_MSGVIEW:
1951 toolbar_data = msgview->toolbar;
1952 handlebox = msgview->handlebox;
1958 gtk_container_remove(GTK_CONTAINER(handlebox),
1959 GTK_WIDGET(toolbar_data->toolbar));
1961 toolbar_init(toolbar_data);
1962 toolbar_data = toolbar_create(type, handlebox, data);
1965 mainwin->toolbar = toolbar_data;
1967 case TOOLBAR_COMPOSE:
1968 compose->toolbar = toolbar_data;
1970 case TOOLBAR_MSGVIEW:
1971 msgview->toolbar = toolbar_data;
1975 toolbar_style(type, prefs_common.toolbar_style, data);
1977 if (type == TOOLBAR_MAIN) {
1978 toolbar_main_set_sensitive((MainWindow*)data);
1979 account_set_menu_only_toolbar();
1983 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
1984 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
1985 if (GTK_IS_BUTTON(widget)) \
1986 in_btn1 = GTK_BUTTON(widget)->in_button; \
1987 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
1988 GtkWidget *child = gtk_bin_get_child( \
1990 GList *gchild = gtk_container_get_children( \
1991 GTK_CONTAINER(child)); \
1992 GtkWidget *btn = (GtkWidget *)gchild->data; \
1993 GtkWidget *arr = (GtkWidget *) \
1994 (gchild->next?gchild->next->data:NULL); \
1995 if (GTK_IS_BUTTON(btn)) \
1996 in_btn1 = GTK_BUTTON(btn)->in_button; \
1997 if (GTK_IS_BUTTON(arr)) \
1998 in_btn2 = GTK_BUTTON(arr)->in_button; \
2000 else if (GTK_IS_TOOL_ITEM(widget)) { \
2001 GtkWidget *child = gtk_bin_get_child( \
2003 if (GTK_IS_BUTTON(child)) \
2004 in_btn1 = GTK_BUTTON(child)->in_button; \
2006 gtk_widget_set_sensitive(widget, sensitive); \
2007 if (GTK_IS_BUTTON(widget)) \
2008 GTK_BUTTON(widget)->in_button = in_btn1; \
2009 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2010 GtkWidget *child = gtk_bin_get_child( \
2012 GList *gchild = gtk_container_get_children( \
2013 GTK_CONTAINER(child)); \
2014 GtkWidget *btn = (GtkWidget *)gchild->data; \
2015 GtkWidget *arr = (GtkWidget *) \
2016 (gchild->next?gchild->next->data:NULL); \
2017 if (GTK_IS_BUTTON(btn)) \
2018 GTK_BUTTON(btn)->in_button = in_btn1; \
2019 if (GTK_IS_BUTTON(arr)) \
2020 GTK_BUTTON(arr)->in_button = in_btn2; \
2022 else if (GTK_IS_TOOL_ITEM(widget)) { \
2023 GtkWidget *child = gtk_bin_get_child( \
2025 if (GTK_IS_BUTTON(child)) \
2026 GTK_BUTTON(child)->in_button = in_btn2; \
2030 void toolbar_main_set_sensitive(gpointer data)
2032 SensitiveCond state;
2034 MainWindow *mainwin = (MainWindow*)data;
2035 Toolbar *toolbar = mainwin->toolbar;
2037 GSList *entry_list = NULL;
2039 typedef struct _Entry Entry;
2046 #define SET_WIDGET_COND(w, c) \
2048 Entry *e = g_new0(Entry, 1); \
2051 entry_list = g_slist_append(entry_list, e); \
2055 if (toolbar->get_btn)
2056 SET_WIDGET_COND(toolbar->get_btn,
2057 M_HAVE_ACCOUNT|M_UNLOCKED);
2059 if (toolbar->getall_btn) {
2060 SET_WIDGET_COND(toolbar->getall_btn,
2061 M_HAVE_ACCOUNT|M_UNLOCKED);
2063 if (toolbar->send_btn) {
2064 SET_WIDGET_COND(toolbar->send_btn,
2065 M_HAVE_QUEUED_MAILS);
2067 if (toolbar->compose_mail_btn) {
2068 SET_WIDGET_COND(toolbar->compose_news_btn,
2071 if (toolbar->close_window_btn) {
2072 SET_WIDGET_COND(toolbar->compose_news_btn,
2075 if (toolbar->open_mail_btn) {
2076 SET_WIDGET_COND(toolbar->open_mail_btn,
2079 if (toolbar->reply_btn) {
2080 SET_WIDGET_COND(toolbar->reply_btn,
2081 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2083 if (toolbar->replyall_btn) {
2084 SET_WIDGET_COND(toolbar->replyall_btn,
2085 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2087 if (toolbar->replylist_btn) {
2088 SET_WIDGET_COND(toolbar->replylist_btn,
2089 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2091 if (toolbar->replysender_btn) {
2092 SET_WIDGET_COND(toolbar->replysender_btn,
2093 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2095 if (toolbar->fwd_btn) {
2096 SET_WIDGET_COND(toolbar->fwd_btn,
2097 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2100 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2101 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
2103 SET_WIDGET_COND(toolbar->next_btn, 0);
2106 if (toolbar->trash_btn)
2107 SET_WIDGET_COND(toolbar->trash_btn,
2108 M_TARGET_EXIST|M_ALLOW_DELETE);
2110 if (toolbar->delete_btn)
2111 SET_WIDGET_COND(toolbar->delete_btn,
2112 M_TARGET_EXIST|M_ALLOW_DELETE);
2114 if (toolbar->exec_btn)
2115 SET_WIDGET_COND(toolbar->exec_btn,
2118 if (toolbar->learn_ham_btn)
2119 SET_WIDGET_COND(toolbar->learn_ham_btn,
2120 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2122 if (toolbar->learn_spam_btn)
2123 SET_WIDGET_COND(toolbar->learn_spam_btn,
2124 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2126 if (toolbar->cancel_inc_btn)
2127 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2130 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2131 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
2133 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2136 #undef SET_WIDGET_COND
2138 state = main_window_get_current_state(mainwin);
2140 for (cur = entry_list; cur != NULL; cur = cur->next) {
2141 Entry *e = (Entry*) cur->data;
2143 if (e->widget != NULL) {
2144 sensitive = ((e->cond & state) == e->cond);
2145 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2149 while (entry_list != NULL) {
2150 Entry *e = (Entry*) entry_list->data;
2153 entry_list = g_slist_remove(entry_list, e);
2156 g_slist_free(entry_list);
2158 activate_compose_button(toolbar,
2159 prefs_common.toolbar_style,
2160 toolbar->compose_btn_type);
2164 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2166 Compose *compose = (Compose*)data;
2167 GSList *items = compose->toolbar->action_list;
2169 if (compose->toolbar->send_btn)
2170 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2171 if (compose->toolbar->sendl_btn)
2172 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2173 if (compose->toolbar->draft_btn )
2174 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2175 if (compose->toolbar->insert_btn )
2176 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2177 if (compose->toolbar->attach_btn)
2178 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2179 if (compose->toolbar->sig_btn)
2180 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2181 if (compose->toolbar->exteditor_btn)
2182 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2183 if (compose->toolbar->linewrap_current_btn)
2184 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2185 if (compose->toolbar->linewrap_all_btn)
2186 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2187 if (compose->toolbar->addrbook_btn)
2188 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2190 if (compose->toolbar->spellcheck_btn)
2191 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2193 for (; items != NULL; items = g_slist_next(items)) {
2194 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
2195 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2200 * Initialize toolbar structure
2202 void toolbar_init(Toolbar * toolbar) {
2204 toolbar->toolbar = NULL;
2205 toolbar->folders_btn = NULL;
2206 toolbar->get_btn = NULL;
2207 toolbar->getall_btn = NULL;
2208 toolbar->send_btn = NULL;
2209 toolbar->compose_mail_btn = NULL;
2210 toolbar->compose_news_btn = NULL;
2211 toolbar->reply_btn = NULL;
2212 toolbar->replysender_btn = NULL;
2213 toolbar->replyall_btn = NULL;
2214 toolbar->replylist_btn = NULL;
2215 toolbar->fwd_btn = NULL;
2216 toolbar->trash_btn = NULL;
2217 toolbar->delete_btn = NULL;
2218 toolbar->prev_btn = NULL;
2219 toolbar->next_btn = NULL;
2220 toolbar->exec_btn = NULL;
2221 toolbar->open_mail_btn = NULL;
2222 toolbar->close_window_btn = NULL;
2223 /* compose buttons */
2224 toolbar->sendl_btn = NULL;
2225 toolbar->draft_btn = NULL;
2226 toolbar->insert_btn = NULL;
2227 toolbar->attach_btn = NULL;
2228 toolbar->sig_btn = NULL;
2229 toolbar->exteditor_btn = NULL;
2230 toolbar->linewrap_current_btn = NULL;
2231 toolbar->linewrap_all_btn = NULL;
2232 toolbar->addrbook_btn = NULL;
2234 toolbar->spellcheck_btn = NULL;
2237 toolbar_destroy(toolbar);
2242 static void toolbar_reply(gpointer data, guint action)
2244 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2245 MainWindow *mainwin;
2246 MessageView *msgview;
2247 GSList *msginfo_list = NULL;
2249 g_return_if_fail(toolbar_item != NULL);
2251 switch (toolbar_item->type) {
2253 mainwin = (MainWindow*)toolbar_item->parent;
2254 msginfo_list = summary_get_selection(mainwin->summaryview);
2255 msgview = (MessageView*)mainwin->messageview;
2257 case TOOLBAR_MSGVIEW:
2258 msgview = (MessageView*)toolbar_item->parent;
2259 g_return_if_fail(msgview != NULL);
2260 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2266 g_return_if_fail(msgview != NULL);
2267 g_return_if_fail(msginfo_list != NULL);
2268 compose_reply_from_messageview(msgview, msginfo_list, action);
2269 g_slist_free(msginfo_list);
2271 /* TODO: update reply state ion summaryview */
2275 /* exported functions */
2277 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2279 MainWindow *mainwin = (MainWindow*)data;
2281 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2284 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2286 MainWindow *mainwin = (MainWindow*)data;
2288 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2291 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2295 gboolean got_error = FALSE;
2296 gchar *errstr = NULL;
2298 if (prefs_common.work_offline)
2299 if (alertpanel(_("Offline warning"),
2300 _("You're working offline. Override?"),
2301 GTK_STOCK_NO, GTK_STOCK_YES,
2302 NULL) != G_ALERTALTERNATE)
2305 /* ask for confirmation before sending queued messages only
2306 in online mode and if there is at least one message queued
2307 in any of the folder queue
2309 if (prefs_common.confirm_send_queued_messages) {
2311 /* check if there's a queued message */
2312 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2313 Folder *folder = list->data;
2315 found = !procmsg_queue_is_empty(folder->queue);
2317 /* if necessary, ask for confirmation before sending */
2318 if (found && !prefs_common.work_offline) {
2319 if (alertpanel(_("Send queued messages"),
2320 _("Send all queued messages?"),
2321 GTK_STOCK_CANCEL, _("_Send"),
2322 NULL) != G_ALERTALTERNATE)
2327 for (list = folder_get_list(); list != NULL; list = list->next) {
2328 Folder *folder = list->data;
2330 if (folder->queue) {
2331 if (procmsg_send_queue(folder->queue,
2332 prefs_common.savemsg,
2339 alertpanel_error_log(_("Some errors occurred while "
2340 "sending queued messages."));
2342 gchar *tmp = g_strdup_printf(_("Some errors occurred "
2343 "while sending queued messages:\n%s"), errstr);
2345 alertpanel_error_log(tmp);
2351 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2353 MainWindow *mainwin = (MainWindow*)data;
2354 PrefsAccount *ac = NULL;
2355 FolderItem *item = mainwin->summaryview->folder_item;
2360 ac = account_find_from_item(item);
2361 if (ac && ac->protocol != A_NNTP) {
2362 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2368 * CLAWS - use current account
2370 if (cur_account && (cur_account->protocol != A_NNTP)) {
2371 compose_new_with_folderitem(cur_account, item, NULL);
2376 * CLAWS - just get the first one
2378 list = account_get_list();
2379 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2380 ac = (PrefsAccount *) cur->data;
2381 if (ac->protocol != A_NNTP) {
2382 compose_new_with_folderitem(ac, item, NULL);
2388 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2390 MainWindow *mainwin = (MainWindow*)data;
2391 PrefsAccount * ac = NULL;
2395 if (mainwin->summaryview->folder_item) {
2396 ac = mainwin->summaryview->folder_item->folder->account;
2397 if (ac && ac->protocol == A_NNTP) {
2398 compose_new_with_folderitem(ac,
2399 mainwin->summaryview->folder_item, NULL);
2404 list = account_get_list();
2405 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2406 ac = (PrefsAccount *) cur->data;
2407 if (ac->protocol == A_NNTP) {
2408 compose_new_with_folderitem(ac,
2409 mainwin->summaryview->folder_item, NULL);