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 void toolbar_init(Toolbar * toolbar);
71 static gboolean toolbar_is_duplicate (gint action,
73 static void toolbar_parse_item (XMLFile *file,
76 static gint toolbar_ret_val_from_text (const gchar *text);
77 static gchar *toolbar_ret_text_from_val (gint val);
79 static void toolbar_set_default_main (void);
80 static void toolbar_set_default_compose (void);
81 static void toolbar_set_default_msgview (void);
83 static void toolbar_style (ToolbarType type,
87 static MainWindow *get_mainwin (gpointer data);
88 static void activate_compose_button (Toolbar *toolbar,
90 ComposeButtonType type);
92 /* toolbar callbacks */
93 static void toolbar_reply (gpointer data,
95 static void toolbar_learn (gpointer data,
97 static void toolbar_delete_cb (GtkWidget *widget,
99 static void toolbar_trash_cb (GtkWidget *widget,
102 static void toolbar_compose_cb (GtkWidget *widget,
105 static void toolbar_learn_cb (GtkWidget *widget,
108 static void toolbar_reply_cb (GtkWidget *widget,
111 static void toolbar_reply_to_all_cb (GtkWidget *widget,
114 static void toolbar_reply_to_list_cb (GtkWidget *widget,
117 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
120 static void toolbar_forward_cb (GtkWidget *widget,
123 static void toolbar_prev_unread_cb (GtkWidget *widget,
125 static void toolbar_next_unread_cb (GtkWidget *widget,
128 static void toolbar_ignore_thread_cb (GtkWidget *widget,
131 static void toolbar_watch_thread_cb (GtkWidget *widget,
134 static void toolbar_print_cb (GtkWidget *widget,
137 static void toolbar_actions_execute_cb (GtkWidget *widget,
141 static void toolbar_send_cb (GtkWidget *widget,
143 static void toolbar_send_later_cb (GtkWidget *widget,
145 static void toolbar_draft_cb (GtkWidget *widget,
147 static void toolbar_close_cb (GtkWidget *widget,
149 static void toolbar_open_mail_cb (GtkWidget *widget,
151 static void toolbar_insert_cb (GtkWidget *widget,
153 static void toolbar_attach_cb (GtkWidget *widget,
155 static void toolbar_sig_cb (GtkWidget *widget,
157 static void toolbar_ext_editor_cb (GtkWidget *widget,
159 static void toolbar_linewrap_current_cb (GtkWidget *widget,
161 static void toolbar_linewrap_all_cb (GtkWidget *widget,
163 static void toolbar_addrbook_cb (GtkWidget *widget,
166 static void toolbar_check_spelling_cb (GtkWidget *widget,
169 static void toolbar_cancel_inc_cb (GtkWidget *widget,
175 } toolbar_text [] = {
176 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
177 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
178 { "A_SEND_QUEUED", N_("Send Queued Messages") },
179 { "A_COMPOSE_EMAIL", N_("Compose Email") },
180 { "A_COMPOSE_NEWS", N_("Compose News") },
181 { "A_REPLY_MESSAGE", N_("Reply to Message") },
182 { "A_REPLY_SENDER", N_("Reply to Sender") },
183 { "A_REPLY_ALL", N_("Reply to All") },
184 { "A_REPLY_ML", N_("Reply to Mailing-list") },
185 { "A_OPEN_MAIL", N_("Open email") },
186 { "A_FORWARD", N_("Forward Message") },
187 { "A_TRASH", N_("Trash Message") },
188 { "A_DELETE_REAL", N_("Delete Message") },
189 { "A_EXECUTE", N_("Execute") },
190 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
191 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
192 { "A_IGNORE_THREAD", N_("Ignore thread") },
193 { "A_WATCH_THREAD", N_("Watch thread") },
194 { "A_PRINT", N_("Print") },
195 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
196 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
198 { "A_SEND", N_("Send Message") },
199 { "A_SENDL", N_("Put into queue folder and send later") },
200 { "A_DRAFT", N_("Save to draft folder") },
201 { "A_INSERT", N_("Insert file") },
202 { "A_ATTACH", N_("Attach file") },
203 { "A_SIG", N_("Insert signature") },
204 { "A_EXTEDITOR", N_("Edit with external editor") },
205 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
206 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
207 { "A_ADDRBOOK", N_("Address book") },
209 { "A_CHECK_SPELLING", N_("Check spelling") },
211 { "A_SYL_ACTIONS", N_("Claws Mail Actions Feature") },
212 { "A_CANCEL_INC", N_("Cancel receiving") },
213 { "A_CLOSE", N_("Close window") },
214 { "A_SEPARATOR", "Separator" }
217 /* struct holds configuration files and a list of
218 * currently active toolbar items
219 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
223 const gchar *conf_file;
225 } toolbar_config[3] = {
226 { "toolbar_main.xml", NULL},
227 { "toolbar_compose.xml", NULL},
228 { "toolbar_msgview.xml", NULL}
231 static GtkItemFactoryEntry reply_entries[] =
233 {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
234 {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
236 static GtkItemFactoryEntry replyall_entries[] =
238 {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
239 {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
241 static GtkItemFactoryEntry replylist_entries[] =
243 {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
244 {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
246 static GtkItemFactoryEntry replysender_entries[] =
248 {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
249 {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
251 static GtkItemFactoryEntry forward_entries[] =
253 {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
254 {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
255 {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, NULL}
258 static GtkItemFactoryEntry learn_entries[] =
260 {N_("/Learn as _Spam"), NULL, toolbar_learn, TRUE, NULL},
261 {N_("/Learn as _Ham"), NULL, toolbar_learn, FALSE, NULL}
265 gint toolbar_ret_val_from_descr(const gchar *descr)
269 for (i = 0; i < N_ACTION_VAL; i++) {
270 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
277 gchar *toolbar_ret_descr_from_val(gint val)
279 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
281 return gettext(toolbar_text[val].descr);
284 static gint toolbar_ret_val_from_text(const gchar *text)
288 for (i = 0; i < N_ACTION_VAL; i++) {
289 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
296 static gchar *toolbar_ret_text_from_val(gint val)
298 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
300 return toolbar_text[val].index_str;
303 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
307 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
310 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
311 ToolbarItem *item = (ToolbarItem*) cur->data;
313 if (item->index == action)
319 /* depending on toolbar type this function
320 returns a list of available toolbar events being
321 displayed by prefs_toolbar
323 GList *toolbar_get_action_items(ToolbarType source)
328 if (source == TOOLBAR_MAIN) {
329 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
330 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
331 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
332 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
333 A_GOTO_NEXT, A_IGNORE_THREAD, A_WATCH_THREAD, A_PRINT,
334 A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
337 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
338 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
341 else if (source == TOOLBAR_COMPOSE) {
342 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
343 A_INSERT, A_ATTACH, A_SIG,
344 A_EXTEDITOR, A_LINEWRAP_CURRENT,
345 A_LINEWRAP_ALL, A_ADDRBOOK,
351 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
352 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
354 else if (source == TOOLBAR_MSGVIEW) {
355 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
356 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
357 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
358 A_ADDRBOOK, A_LEARN_SPAM, A_CLOSE };
360 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
361 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
367 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
371 ToolbarItem *item = NULL;
372 gboolean rewrite = FALSE;
374 attr = xml_get_current_tag_attr(file);
375 item = g_new0(ToolbarItem, 1);
377 name = ((XMLAttr *)attr->data)->name;
378 value = ((XMLAttr *)attr->data)->value;
380 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
381 item->file = g_strdup (value);
382 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
383 item->text = g_strdup (gettext(value));
384 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
385 item->index = toolbar_ret_val_from_text(value);
386 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
388 item->index = A_TRASH;
390 item->file = g_strdup("trash_btn");
392 item->text = g_strdup(_("Trash"));
395 attr = g_list_next(attr);
397 if (item->index != -1) {
399 if (!toolbar_is_duplicate(item->index, source))
400 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
404 toolbar_save_config_file(source);
408 const gchar *toolbar_get_short_text(int action) {
410 case A_GO_FOLDERS: return _("Folders");
411 case A_OPEN_MAIL: return _("Open");
412 case A_RECEIVE_ALL: return _("Get Mail");
413 case A_RECEIVE_CUR: return _("Get");
414 case A_SEND_QUEUED: return _("Send");
415 case A_COMPOSE_EMAIL: return Q_("Toolbar|Compose");
416 case A_COMPOSE_NEWS: return Q_("Toolbar|Compose");
417 case A_REPLY_MESSAGE: return _("Reply");
418 case A_REPLY_ALL: return _("All");
419 case A_REPLY_SENDER: return _("Sender");
420 case A_REPLY_ML: return _("List");
421 case A_FORWARD: return _("Forward");
422 case A_TRASH: return _("Trash");
423 case A_DELETE_REAL: return _("Delete");
424 case A_LEARN_SPAM: return _("Spam");
425 case A_GOTO_PREV: return _("Prev");
426 case A_GOTO_NEXT: return _("Next");
427 case A_IGNORE_THREAD: return _("Ignore thread");
428 case A_WATCH_THREAD: return _("Watch thread");
429 case A_PRINT: return _("Print");
430 case A_CLOSE: return _("Close");
431 case A_SEND: return _("Send");
432 case A_SENDL: return _("Send later");
433 case A_DRAFT: return _("Draft");
434 case A_INSERT: return _("Insert");
435 case A_ATTACH: return _("Attach");
436 case A_SIG: return _("Insert sig.");
437 case A_EXTEDITOR: return _("Edit");
438 case A_LINEWRAP_CURRENT:return _("Wrap para.");
439 case A_LINEWRAP_ALL: return _("Wrap all");
440 case A_ADDRBOOK: return _("Address");
441 case A_CANCEL_INC: return _("Stop");
442 case A_EXECUTE: return _("Execute");
444 case A_CHECK_SPELLING: return _("Check spelling");
450 gint toolbar_get_icon(int action) {
452 case A_GO_FOLDERS: return STOCK_PIXMAP_GO_FOLDERS;
453 case A_OPEN_MAIL: return STOCK_PIXMAP_OPEN_MAIL;
454 case A_RECEIVE_ALL: return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
455 case A_RECEIVE_CUR: return STOCK_PIXMAP_MAIL_RECEIVE;
456 case A_SEND_QUEUED: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
457 case A_COMPOSE_EMAIL: return STOCK_PIXMAP_MAIL_COMPOSE;
458 case A_COMPOSE_NEWS: return STOCK_PIXMAP_NEWS_COMPOSE;
459 case A_REPLY_MESSAGE: return STOCK_PIXMAP_MAIL_REPLY;
460 case A_REPLY_ALL: return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
461 case A_REPLY_SENDER: return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
462 case A_REPLY_ML: return STOCK_PIXMAP_MAIL_REPLY;
463 case A_FORWARD: return STOCK_PIXMAP_MAIL_FORWARD;
464 case A_TRASH: return STOCK_PIXMAP_TRASH;
465 case A_DELETE_REAL: return STOCK_PIXMAP_DELETED;
466 case A_LEARN_SPAM: return STOCK_PIXMAP_SPAM_BTN;
467 case A_GOTO_PREV: return STOCK_PIXMAP_UP_ARROW;
468 case A_GOTO_NEXT: return STOCK_PIXMAP_DOWN_ARROW;
469 case A_IGNORE_THREAD: return STOCK_PIXMAP_IGNORETHREAD;
470 case A_WATCH_THREAD: return STOCK_PIXMAP_WATCHTHREAD;
471 case A_PRINT: return STOCK_PIXMAP_PRINTER;
472 case A_CLOSE: return STOCK_PIXMAP_CLOSE;
473 case A_SEND: return STOCK_PIXMAP_MAIL_SEND;
474 case A_SENDL: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
475 case A_DRAFT: return STOCK_PIXMAP_MAIL;
476 case A_INSERT: return STOCK_PIXMAP_INSERT_FILE;
477 case A_ATTACH: return STOCK_PIXMAP_MAIL_ATTACH;
478 case A_SIG: return STOCK_PIXMAP_MAIL_SIGN;
479 case A_EXTEDITOR: return STOCK_PIXMAP_EDIT_EXTERN;
480 case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
481 case A_LINEWRAP_ALL: return STOCK_PIXMAP_LINEWRAP_ALL;
482 case A_ADDRBOOK: return STOCK_PIXMAP_ADDRESS_BOOK;
483 case A_CANCEL_INC: return STOCK_PIXMAP_NOTICE_ERROR;
484 case A_EXECUTE: return STOCK_PIXMAP_EXEC;
486 case A_CHECK_SPELLING: return STOCK_PIXMAP_CHECK_SPELLING;
492 static void toolbar_set_default_main(void)
496 } default_toolbar[] = {
516 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
526 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
528 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
530 if (default_toolbar[i].action != A_SEPARATOR) {
532 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
534 toolbar_item->file = g_strdup(file);
535 toolbar_item->index = default_toolbar[i].action;
536 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
539 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
540 toolbar_item->index = A_SEPARATOR;
543 if (toolbar_item->index != -1) {
544 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
545 toolbar_config[TOOLBAR_MAIN].item_list =
546 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
551 static void toolbar_set_default_compose(void)
555 } default_toolbar[] = {
574 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
576 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
578 if (default_toolbar[i].action != A_SEPARATOR) {
580 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
582 toolbar_item->file = g_strdup(file);
583 toolbar_item->index = default_toolbar[i].action;
584 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
587 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
588 toolbar_item->index = A_SEPARATOR;
591 if (toolbar_item->index != -1) {
592 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
593 toolbar_config[TOOLBAR_COMPOSE].item_list =
594 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
599 static void toolbar_set_default_msgview(void)
603 } default_toolbar[] = {
615 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
624 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
626 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
628 if (default_toolbar[i].action != A_SEPARATOR) {
630 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
632 toolbar_item->file = g_strdup(file);
633 toolbar_item->index = default_toolbar[i].action;
634 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
637 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
638 toolbar_item->index = A_SEPARATOR;
641 if (toolbar_item->index != -1) {
642 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
643 toolbar_config[TOOLBAR_MSGVIEW].item_list =
644 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
649 void toolbar_set_default(ToolbarType source)
651 if (source == TOOLBAR_MAIN)
652 toolbar_set_default_main();
653 else if (source == TOOLBAR_COMPOSE)
654 toolbar_set_default_compose();
655 else if (source == TOOLBAR_MSGVIEW)
656 toolbar_set_default_msgview();
659 void toolbar_save_config_file(ToolbarType source)
664 gchar *fileSpec = NULL;
666 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
668 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
669 pfile = prefs_write_open(fileSpec);
672 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
675 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
678 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
679 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
681 if (toolbar_item->index != A_SEPARATOR) {
682 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
684 TOOLBAR_ICON_FILE, toolbar_item->file,
685 TOOLBAR_ICON_TEXT) < 0)
687 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
689 if (fprintf(fp, "\" %s=\"%s\"/>\n",
691 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
694 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
699 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
703 if (prefs_file_close (pfile) < 0 )
704 g_warning("failed to write toolbar configuration to file\n");
708 FILE_OP_ERROR(fileSpec, "fprintf");
710 prefs_file_close_revert (pfile);
712 g_warning("failed to open toolbar configuration file for writing\n");
715 void toolbar_read_config_file(ToolbarType source)
717 XMLFile *file = NULL;
718 gchar *fileSpec = NULL;
723 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
725 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
726 file = xml_open_file(fileSpec);
729 toolbar_clear_list(source);
733 || (xml_get_dtd(file))
734 || (xml_parse_next_tag(file))
735 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
736 xml_close_file(file);
740 attr = xml_get_current_tag_attr(file);
747 if (xml_parse_next_tag(file))
750 /* Get next tag (icon, icon_text or icon_action) */
751 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
752 toolbar_parse_item(file, source);
753 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
754 ToolbarItem *item = g_new0(ToolbarItem, 1);
756 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
757 item->index = A_SEPARATOR;
758 toolbar_config[source].item_list =
759 g_slist_append(toolbar_config[source].item_list, item);
763 xml_close_file(file);
766 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
768 if (source == TOOLBAR_MAIN)
769 toolbar_set_default(TOOLBAR_MAIN);
770 else if (source == TOOLBAR_COMPOSE)
771 toolbar_set_default(TOOLBAR_COMPOSE);
772 else if (source == TOOLBAR_MSGVIEW)
773 toolbar_set_default(TOOLBAR_MSGVIEW);
775 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
779 toolbar_save_config_file(source);
784 * clears list of toolbar items read from configuration files
786 void toolbar_clear_list(ToolbarType source)
788 while (toolbar_config[source].item_list != NULL) {
789 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
791 toolbar_config[source].item_list =
792 g_slist_remove(toolbar_config[source].item_list, item);
798 g_slist_free(toolbar_config[source].item_list);
803 * return list of Toolbar items
805 GSList *toolbar_get_list(ToolbarType source)
809 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
810 list = toolbar_config[source].item_list;
815 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
817 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
819 toolbar_item->file = g_strdup(t_item->file);
820 toolbar_item->text = g_strdup(t_item->text);
821 toolbar_item->index = t_item->index;
823 toolbar_config[source].item_list =
824 g_slist_append(toolbar_config[source].item_list,
828 static void toolbar_action_execute(GtkWidget *widget,
834 gchar *action, *action_p;
835 gboolean found = FALSE;
838 for (cur = action_list; cur != NULL; cur = cur->next) {
839 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
841 if (widget == act->widget) {
843 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
844 action = g_strdup((gchar*)lop->data);
846 action_p = strstr(action, ": ");
848 if (g_utf8_collate(act->name, action) == 0) {
862 actions_execute(data, i, widget, source);
864 g_warning ("Error: did not find Claws Action to execute");
867 static void activate_compose_button (Toolbar *toolbar,
869 ComposeButtonType type)
871 if ((!toolbar->compose_mail_btn))
874 if (type == COMPOSEBUTTON_NEWS) {
875 gtk_tool_button_set_icon_widget(
876 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
877 toolbar->compose_news_icon);
878 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->compose_mail_btn), GTK_TOOLTIPS(toolbar->tooltips),
879 _("Compose News message"), NULL);
880 gtk_widget_show(toolbar->compose_news_icon);
882 gtk_tool_button_set_icon_widget(
883 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
884 toolbar->compose_mail_icon);
885 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->compose_mail_btn), GTK_TOOLTIPS(toolbar->tooltips),
886 _("Compose Email"), NULL);
887 gtk_widget_show(toolbar->compose_mail_icon);
889 toolbar->compose_btn_type = type;
892 void toolbar_set_compose_button(Toolbar *toolbar,
893 ComposeButtonType compose_btn_type)
895 if (toolbar->compose_btn_type != compose_btn_type)
896 activate_compose_button(toolbar,
897 prefs_common.toolbar_style,
901 static void activate_learn_button (Toolbar *toolbar,
903 LearnButtonType type)
905 if ((!toolbar->learn_spam_btn))
908 if (type == LEARN_SPAM) {
909 gtk_tool_button_set_icon_widget(
910 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
911 toolbar->learn_spam_icon);
912 gtk_tool_button_set_label(
913 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
915 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->learn_spam_btn), GTK_TOOLTIPS(toolbar->tooltips),
916 _("Learn spam"), NULL);
917 gtk_widget_show(toolbar->learn_spam_icon);
919 gtk_tool_button_set_icon_widget(
920 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
921 toolbar->learn_ham_icon);
922 gtk_tool_button_set_label(
923 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
925 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->learn_spam_btn), GTK_TOOLTIPS(toolbar->tooltips),
926 _("Learn ham"), NULL);
927 gtk_widget_show(toolbar->learn_ham_icon);
929 toolbar->learn_btn_type = type;
932 void toolbar_set_learn_button(Toolbar *toolbar,
933 LearnButtonType learn_btn_type)
935 if (toolbar->learn_btn_type != learn_btn_type)
936 activate_learn_button(toolbar,
937 prefs_common.toolbar_style,
941 void toolbar_toggle(guint action, gpointer data)
943 MainWindow *mainwin = (MainWindow*)data;
947 g_return_if_fail(mainwin != NULL);
949 toolbar_style(TOOLBAR_MAIN, action, mainwin);
951 list = compose_get_compose_list();
952 for (cur = list; cur != NULL; cur = cur->next) {
953 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
955 list = messageview_get_msgview_list();
956 for (cur = list; cur != NULL; cur = cur->next) {
957 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
962 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
964 switch ((ToolbarStyle)action) {
966 gtk_widget_hide(handlebox_wid);
969 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
973 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
977 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
980 case TOOLBAR_BOTH_HORIZ:
981 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
982 GTK_TOOLBAR_BOTH_HORIZ);
988 prefs_common.toolbar_style = (ToolbarStyle)action;
989 gtk_widget_set_size_request(handlebox_wid, 1, -1);
991 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
992 gtk_widget_show(handlebox_wid);
993 gtk_widget_queue_resize(handlebox_wid);
997 * Change the style of toolbar
999 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1001 GtkWidget *handlebox_wid;
1002 GtkWidget *toolbar_wid;
1003 MainWindow *mainwin = (MainWindow*)data;
1004 Compose *compose = (Compose*)data;
1005 MessageView *msgview = (MessageView*)data;
1007 g_return_if_fail(data != NULL);
1011 handlebox_wid = mainwin->handlebox;
1012 toolbar_wid = mainwin->toolbar->toolbar;
1014 case TOOLBAR_COMPOSE:
1015 handlebox_wid = compose->handlebox;
1016 toolbar_wid = compose->toolbar->toolbar;
1018 case TOOLBAR_MSGVIEW:
1019 handlebox_wid = msgview->handlebox;
1020 toolbar_wid = msgview->toolbar->toolbar;
1026 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1029 /* Toolbar handling */
1030 static void toolbar_inc_cb(GtkWidget *widget,
1033 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1034 MainWindow *mainwin;
1036 g_return_if_fail(toolbar_item != NULL);
1038 switch (toolbar_item->type) {
1040 mainwin = (MainWindow*)toolbar_item->parent;
1041 inc_mail_cb(mainwin, 0, NULL);
1048 static void toolbar_inc_all_cb(GtkWidget *widget,
1051 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1052 MainWindow *mainwin;
1054 g_return_if_fail(toolbar_item != NULL);
1056 switch (toolbar_item->type) {
1058 mainwin = (MainWindow*)toolbar_item->parent;
1059 inc_all_account_mail_cb(mainwin, 0, NULL);
1066 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1068 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1069 MainWindow *mainwin;
1071 g_return_if_fail(toolbar_item != NULL);
1073 switch (toolbar_item->type) {
1075 mainwin = (MainWindow*)toolbar_item->parent;
1076 send_queue_cb(mainwin, 0, NULL);
1083 static void toolbar_exec_cb(GtkWidget *widget,
1086 MainWindow *mainwin = get_mainwin(data);
1088 g_return_if_fail(mainwin != NULL);
1089 summary_execute(mainwin->summaryview);
1093 * Delete current/selected(s) message(s)
1095 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1097 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1098 MainWindow *mainwin;
1100 g_return_if_fail(toolbar_item != NULL);
1101 g_return_if_fail(toolbar_item->parent);
1103 switch (toolbar_item->type) {
1104 case TOOLBAR_MSGVIEW:
1105 messageview_delete((MessageView *)toolbar_item->parent);
1108 mainwin = (MainWindow *)toolbar_item->parent;
1109 summary_delete_trash(mainwin->summaryview);
1112 debug_print("toolbar event not supported\n");
1118 * Delete current/selected(s) message(s)
1120 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1122 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1123 MainWindow *mainwin;
1125 g_return_if_fail(toolbar_item != NULL);
1126 g_return_if_fail(toolbar_item->parent);
1128 switch (toolbar_item->type) {
1129 case TOOLBAR_MSGVIEW:
1130 messageview_delete((MessageView *)toolbar_item->parent);
1133 mainwin = (MainWindow *)toolbar_item->parent;
1134 summary_delete(mainwin->summaryview);
1137 debug_print("toolbar event not supported\n");
1144 * Compose new message
1146 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1148 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1149 MainWindow *mainwin;
1150 MessageView *msgview;
1152 g_return_if_fail(toolbar_item != NULL);
1154 switch (toolbar_item->type) {
1156 mainwin = (MainWindow*)toolbar_item->parent;
1157 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1158 compose_news_cb(mainwin, 0, NULL);
1160 compose_mail_cb(mainwin, 0, NULL);
1162 case TOOLBAR_MSGVIEW:
1163 msgview = (MessageView*)toolbar_item->parent;
1164 compose_new_with_folderitem(NULL,
1165 msgview->msginfo->folder, NULL);
1168 debug_print("toolbar event not supported\n");
1172 static void toolbar_learn(gpointer data, guint as_spam)
1174 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1175 MainWindow *mainwin;
1176 MessageView *msgview;
1178 g_return_if_fail(toolbar_item != NULL);
1180 switch (toolbar_item->type) {
1182 mainwin = (MainWindow*)toolbar_item->parent;
1184 mainwindow_learn(mainwin, TRUE);
1186 mainwindow_learn(mainwin, FALSE);
1188 case TOOLBAR_MSGVIEW:
1189 msgview = (MessageView*)toolbar_item->parent;
1191 messageview_learn(msgview, TRUE);
1193 messageview_learn(msgview, FALSE);
1196 debug_print("toolbar event not supported\n");
1200 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1202 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1203 MainWindow *mainwin;
1204 MessageView *msgview;
1206 g_return_if_fail(toolbar_item != NULL);
1208 switch (toolbar_item->type) {
1210 mainwin = (MainWindow*)toolbar_item->parent;
1211 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1212 mainwindow_learn(mainwin, TRUE);
1214 mainwindow_learn(mainwin, FALSE);
1216 case TOOLBAR_MSGVIEW:
1217 msgview = (MessageView*)toolbar_item->parent;
1218 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1219 messageview_learn(msgview, TRUE);
1221 messageview_learn(msgview, FALSE);
1224 debug_print("toolbar event not supported\n");
1232 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1234 toolbar_reply(data, prefs_common.reply_with_quote ?
1235 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1240 * Reply message to Sender and All recipients
1242 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1245 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1246 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1251 * Reply to Mailing List
1253 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1256 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1257 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1262 * Reply to sender of message
1264 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1267 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1268 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1274 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1276 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1279 g_return_if_fail(toolbar_item != NULL);
1281 switch (toolbar_item->type) {
1283 case TOOLBAR_MSGVIEW:
1286 case TOOLBAR_COMPOSE:
1287 compose = (Compose *)toolbar_item->parent;
1292 addressbook_open(compose);
1297 * Forward current/selected(s) message(s)
1299 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1301 toolbar_reply(data, COMPOSE_FORWARD);
1305 * Goto Prev Unread Message
1307 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1309 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1310 MainWindow *mainwin;
1311 MessageView *msgview;
1313 g_return_if_fail(toolbar_item != NULL);
1315 switch (toolbar_item->type) {
1317 mainwin = (MainWindow*)toolbar_item->parent;
1318 summary_select_prev_unread(mainwin->summaryview);
1321 case TOOLBAR_MSGVIEW:
1322 msgview = (MessageView*)toolbar_item->parent;
1323 msgview->updating = TRUE;
1324 summary_select_prev_unread(msgview->mainwin->summaryview);
1325 msgview->updating = FALSE;
1327 if (msgview->deferred_destroy) {
1328 debug_print("messageview got away!\n");
1329 messageview_destroy(msgview);
1333 /* Now we need to update the messageview window */
1334 if (msgview->mainwin->summaryview->selected) {
1336 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1339 messageview_show(msgview, msginfo,
1340 msgview->all_headers);
1343 gtk_widget_destroy(msgview->window);
1347 debug_print("toolbar event not supported\n");
1352 * Goto Next Unread Message
1354 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1356 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1357 MainWindow *mainwin;
1358 MessageView *msgview;
1360 g_return_if_fail(toolbar_item != NULL);
1362 switch (toolbar_item->type) {
1364 mainwin = (MainWindow*)toolbar_item->parent;
1365 summary_select_next_unread(mainwin->summaryview);
1368 case TOOLBAR_MSGVIEW:
1369 msgview = (MessageView*)toolbar_item->parent;
1370 msgview->updating = TRUE;
1371 summary_select_next_unread(msgview->mainwin->summaryview);
1372 msgview->updating = FALSE;
1374 if (msgview->deferred_destroy) {
1375 debug_print("messageview got away!\n");
1376 messageview_destroy(msgview);
1380 /* Now we need to update the messageview window */
1381 if (msgview->mainwin->summaryview->selected) {
1383 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1386 messageview_show(msgview, msginfo,
1387 msgview->all_headers);
1390 gtk_widget_destroy(msgview->window);
1394 debug_print("toolbar event not supported\n");
1398 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1400 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1401 MainWindow *mainwin;
1403 g_return_if_fail(toolbar_item != NULL);
1405 switch (toolbar_item->type) {
1407 mainwin = (MainWindow *) toolbar_item->parent;
1408 summary_toggle_ignore_thread(mainwin->summaryview);
1410 case TOOLBAR_MSGVIEW:
1411 /* TODO: see toolbar_next_unread_cb() if you need
1412 * this in the message view */
1415 debug_print("toolbar event not supported\n");
1420 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1422 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1423 MainWindow *mainwin;
1425 g_return_if_fail(toolbar_item != NULL);
1427 switch (toolbar_item->type) {
1429 mainwin = (MainWindow *) toolbar_item->parent;
1430 summary_toggle_watch_thread(mainwin->summaryview);
1432 case TOOLBAR_MSGVIEW:
1433 /* TODO: see toolbar_next_unread_cb() if you need
1434 * this in the message view */
1437 debug_print("toolbar event not supported\n");
1442 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1444 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1446 g_return_if_fail(toolbar_item != NULL);
1452 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1454 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1455 MainWindow *mainwin;
1457 g_return_if_fail(toolbar_item != NULL);
1459 switch (toolbar_item->type) {
1461 mainwin = (MainWindow *) toolbar_item->parent;
1462 summary_print(mainwin->summaryview);
1464 case TOOLBAR_MSGVIEW:
1465 /* TODO: see toolbar_next_unread_cb() if you need
1466 * this in the message view */
1469 debug_print("toolbar event not supported\n");
1474 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1476 compose_toolbar_cb(A_SEND, data);
1479 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1481 compose_toolbar_cb(A_SENDL, data);
1484 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1486 compose_toolbar_cb(A_DRAFT, data);
1489 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1491 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1492 MainWindow *mainwin;
1493 MessageView *messageview;
1496 g_return_if_fail(toolbar_item != NULL);
1498 switch (toolbar_item->type) {
1500 mainwin = (MainWindow *) toolbar_item->parent;
1501 app_will_exit(NULL, mainwin);
1503 case TOOLBAR_MSGVIEW:
1504 messageview = (MessageView *)toolbar_item->parent;
1505 messageview_destroy(messageview);
1507 case TOOLBAR_COMPOSE:
1508 compose = (Compose *)toolbar_item->parent;
1509 compose_close_toolbar(compose);
1514 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1516 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1517 MainWindow *mainwin;
1519 g_return_if_fail(toolbar_item != NULL);
1521 switch (toolbar_item->type) {
1523 mainwin = (MainWindow *) toolbar_item->parent;
1524 summary_open_row(NULL, mainwin->summaryview);
1526 case TOOLBAR_MSGVIEW:
1527 debug_print("toolbar event not supported\n");
1529 case TOOLBAR_COMPOSE:
1530 debug_print("toolbar event not supported\n");
1535 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1537 compose_toolbar_cb(A_INSERT, data);
1540 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1542 compose_toolbar_cb(A_ATTACH, data);
1545 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1547 compose_toolbar_cb(A_SIG, data);
1550 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1552 compose_toolbar_cb(A_EXTEDITOR, data);
1555 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1557 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1560 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1562 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1566 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1568 compose_toolbar_cb(A_CHECK_SPELLING, data);
1572 * Execute actions from toolbar
1574 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1576 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1577 GSList *action_list;
1578 MainWindow *mainwin;
1580 MessageView *msgview;
1581 gpointer parent = toolbar_item->parent;
1583 g_return_if_fail(toolbar_item != NULL);
1585 switch (toolbar_item->type) {
1587 mainwin = (MainWindow*)parent;
1588 action_list = mainwin->toolbar->action_list;
1590 case TOOLBAR_COMPOSE:
1591 compose = (Compose*)parent;
1592 action_list = compose->toolbar->action_list;
1594 case TOOLBAR_MSGVIEW:
1595 msgview = (MessageView*)parent;
1596 action_list = msgview->toolbar->action_list;
1599 debug_print("toolbar event not supported\n");
1602 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1605 static MainWindow *get_mainwin(gpointer data)
1607 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1608 MainWindow *mainwin = NULL;
1609 MessageView *msgview;
1611 g_return_val_if_fail(toolbar_item != NULL, NULL);
1613 switch(toolbar_item->type) {
1615 mainwin = (MainWindow*)toolbar_item->parent;
1617 case TOOLBAR_MSGVIEW:
1618 msgview = (MessageView*)toolbar_item->parent;
1619 mainwin = (MainWindow*)msgview->mainwin;
1628 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1630 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1631 MainWindow *mainwin = NULL;
1632 switch(toolbar_item->type) {
1634 mainwin = (MainWindow*)toolbar_item->parent;
1637 g_warning("wrong toolbar type\n");
1641 if (!mainwin->in_folder) {
1642 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1644 folderview_select(mainwin->folderview, item);
1647 gtk_widget_grab_focus(mainwin->folderview->ctree);
1648 mainwindow_exit_folder(mainwin);
1652 static void toolbar_buttons_cb(GtkWidget *widget,
1659 void (*func)(GtkWidget *widget, gpointer data);
1661 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1662 { A_RECEIVE_CUR, toolbar_inc_cb },
1663 { A_SEND_QUEUED, toolbar_send_queued_cb },
1664 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1665 { A_COMPOSE_NEWS, toolbar_compose_cb },
1666 { A_REPLY_MESSAGE, toolbar_reply_cb },
1667 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1668 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1669 { A_REPLY_ML, toolbar_reply_to_list_cb },
1670 { A_FORWARD, toolbar_forward_cb },
1671 { A_TRASH, toolbar_trash_cb },
1672 { A_DELETE_REAL, toolbar_delete_cb },
1673 { A_EXECUTE, toolbar_exec_cb },
1674 { A_GOTO_PREV, toolbar_prev_unread_cb },
1675 { A_GOTO_NEXT, toolbar_next_unread_cb },
1676 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1677 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1678 { A_PRINT, toolbar_print_cb },
1679 { A_LEARN_SPAM, toolbar_learn_cb },
1680 { A_GO_FOLDERS, toolbar_go_folders_cb },
1682 { A_SEND, toolbar_send_cb },
1683 { A_SENDL, toolbar_send_later_cb },
1684 { A_DRAFT, toolbar_draft_cb },
1685 { A_OPEN_MAIL, toolbar_open_mail_cb },
1686 { A_CLOSE, toolbar_close_cb },
1687 { A_INSERT, toolbar_insert_cb },
1688 { A_ATTACH, toolbar_attach_cb },
1689 { A_SIG, toolbar_sig_cb },
1690 { A_EXTEDITOR, toolbar_ext_editor_cb },
1691 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1692 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1693 { A_ADDRBOOK, toolbar_addrbook_cb },
1695 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1697 { A_SYL_ACTIONS, toolbar_actions_execute_cb },
1698 { A_CANCEL_INC, toolbar_cancel_inc_cb }
1701 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1703 for (i = 0; i < num_items; i++) {
1704 if (callbacks[i].index == item->index) {
1705 callbacks[i].func(widget, item);
1711 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1712 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1713 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1714 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1715 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1716 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1717 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1721 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1722 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1723 GList *gchild = NULL; \
1724 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1725 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1726 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1727 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1728 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1729 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1731 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(item), \
1732 GTK_TOOLTIPS(toolbar_tips), menutip, NULL); \
1733 child = gtk_bin_get_child(GTK_BIN(item)); \
1734 gchild = gtk_container_get_children( \
1735 GTK_CONTAINER(child)); \
1736 btn = (GtkWidget *)gchild->data; \
1737 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1738 g_list_free(gchild); \
1739 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1740 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1741 g_list_free(gchild); \
1744 #define MAKE_MENU(entries,path,btn) { \
1745 n_menu_entries = sizeof(entries) / \
1746 sizeof(entries[0]); \
1747 menu = menu_create_items(entries, n_menu_entries, path, &factory, toolbar_item); \
1748 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(btn), menu); \
1752 * Create a new toolbar with specified type
1753 * if a callback list is passed it will be used before the
1754 * common callback list
1756 Toolbar *toolbar_create(ToolbarType type,
1757 GtkWidget *container,
1760 ToolbarItem *toolbar_item;
1763 GtkWidget *icon_wid = NULL;
1764 GtkWidget *icon_news;
1765 GtkWidget *icon_ham;
1768 guint n_menu_entries;
1769 GtkItemFactory *factory;
1770 GtkTooltips *toolbar_tips;
1771 ToolbarSylpheedActions *action_item;
1773 GSList *toolbar_list;
1774 Toolbar *toolbar_data;
1777 toolbar_tips = gtk_tooltips_new();
1779 toolbar_read_config_file(type);
1780 toolbar_list = toolbar_get_list(type);
1782 toolbar_data = g_new0(Toolbar, 1);
1784 toolbar = gtk_toolbar_new();
1786 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1787 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1788 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1790 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1792 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1793 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1797 toolbar_item = g_new0(ToolbarItem, 1);
1798 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1799 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1800 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1801 toolbar_item->parent = data;
1802 toolbar_item->type = type;
1804 /* collect toolbar items in list to keep track */
1805 toolbar_data->item_list =
1806 g_slist_append(toolbar_data->item_list,
1808 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1810 switch (toolbar_item->index) {
1813 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1814 toolbar_data->folders_btn = item;
1817 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1818 _("Receive Mail on all Accounts"),
1819 _("Receive Mail on selected Account"));
1820 toolbar_data->getall_btn = item;
1823 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail on current Account"));
1824 toolbar_data->get_btn = item;
1827 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1828 toolbar_data->send_btn = item;
1831 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1832 toolbar_data->close_window_btn = item;
1835 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1836 toolbar_data->open_mail_btn = item;
1838 case A_COMPOSE_EMAIL:
1840 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1842 _("Compose with selected Account"));
1843 toolbar_data->compose_mail_btn = item;
1844 toolbar_data->compose_mail_icon = icon_wid;
1845 g_object_ref(toolbar_data->compose_mail_icon);
1847 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1848 toolbar_data->compose_news_icon = icon_news;
1849 g_object_ref(toolbar_data->compose_news_icon);
1851 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1852 _("Compose Email"));
1853 toolbar_data->compose_mail_btn = item;
1854 toolbar_data->compose_mail_icon = icon_wid;
1856 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1857 toolbar_data->compose_news_icon = icon_news;
1861 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1864 toolbar_data->learn_spam_btn = item;
1865 toolbar_data->learn_spam_icon = icon_wid;
1866 g_object_ref(toolbar_data->learn_spam_icon);
1868 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1869 toolbar_data->learn_ham_icon = icon_ham;
1870 g_object_ref(toolbar_data->learn_ham_icon);
1872 MAKE_MENU(learn_entries,"<LearnSpam>",toolbar_data->learn_spam_btn);
1874 case A_REPLY_MESSAGE:
1876 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1877 _("Reply to Message"),
1878 _("Reply to Message options"));
1879 toolbar_data->reply_btn = item;
1881 MAKE_MENU(reply_entries,"<Reply>",toolbar_data->reply_btn);
1883 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1884 _("Reply to Message"));
1885 toolbar_data->reply_btn = item;
1888 case A_REPLY_SENDER:
1890 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1891 _("Reply to Sender"),
1892 _("Reply to Sender options"));
1893 toolbar_data->replysender_btn = item;
1895 MAKE_MENU(replysender_entries,"<ReplySender>",toolbar_data->replysender_btn);
1897 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1898 _("Reply to Sender"));
1899 toolbar_data->replysender_btn = item;
1904 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1906 _("Reply to All options"));
1907 toolbar_data->replyall_btn = item;
1909 MAKE_MENU(replyall_entries,"<ReplyAll>",toolbar_data->replyall_btn);
1911 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1913 toolbar_data->replyall_btn = item;
1918 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1919 _("Reply to Mailing-list"),
1920 _("Reply to Mailing-list options"));
1921 toolbar_data->replylist_btn = item;
1923 MAKE_MENU(replylist_entries,"<ReplyList>",toolbar_data->replylist_btn);
1925 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1926 _("Reply to Mailing-list"));
1927 toolbar_data->replylist_btn = item;
1932 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1933 _("Forward Message"),
1934 _("Forward Message options"));
1935 toolbar_data->fwd_btn = item;
1937 MAKE_MENU(forward_entries,"<Forward>",toolbar_data->fwd_btn);
1939 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1940 _("Forward Message"));
1941 toolbar_data->fwd_btn = item;
1945 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
1946 toolbar_data->trash_btn = item;
1949 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
1950 toolbar_data->delete_btn = item;
1953 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
1954 toolbar_data->exec_btn = item;
1957 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
1958 toolbar_data->prev_btn = item;
1961 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
1962 toolbar_data->next_btn = item;
1965 /* Compose Toolbar */
1967 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
1968 toolbar_data->send_btn = item;
1971 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
1972 toolbar_data->sendl_btn = item;
1975 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
1976 toolbar_data->draft_btn = item;
1979 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
1980 toolbar_data->insert_btn = item;
1983 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
1984 toolbar_data->attach_btn = item;
1987 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
1988 toolbar_data->sig_btn = item;
1991 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
1992 toolbar_data->exteditor_btn = item;
1994 case A_LINEWRAP_CURRENT:
1995 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
1996 toolbar_data->linewrap_current_btn = item;
1998 case A_LINEWRAP_ALL:
1999 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2000 toolbar_data->linewrap_all_btn = item;
2003 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2004 toolbar_data->addrbook_btn = item;
2007 case A_CHECK_SPELLING:
2008 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2009 toolbar_data->spellcheck_btn = item;
2014 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2015 action_item = g_new0(ToolbarSylpheedActions, 1);
2016 action_item->widget = item;
2017 action_item->name = g_strdup(toolbar_item->text);
2019 toolbar_data->action_list =
2020 g_slist_append(toolbar_data->action_list,
2024 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2025 toolbar_data->cancel_inc_btn = item;
2028 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2029 toolbar_ret_descr_from_val(toolbar_item->index));
2030 /* find and set the tool tip text */
2035 toolbar_data->toolbar = toolbar;
2036 toolbar_data->tooltips = toolbar_tips;
2037 gtk_widget_show_all(toolbar);
2039 if (type == TOOLBAR_MAIN) {
2041 MainWindow *mainwin = mainwindow_get_mainwindow();
2042 GtkWidget *progressbar = gtk_progress_bar_new();
2043 item = GTK_WIDGET(gtk_tool_item_new());
2044 gtk_container_add (GTK_CONTAINER (item), progressbar);
2045 gtk_widget_show(item);
2046 gtk_widget_show(progressbar);
2047 gtk_widget_set_size_request(progressbar, 70, -1);
2048 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2049 mainwin->progressbar = progressbar;
2051 activate_compose_button(toolbar_data,
2052 prefs_common.toolbar_style,
2053 toolbar_data->compose_btn_type);
2055 if (type != TOOLBAR_COMPOSE)
2056 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2060 gtk_container_add(GTK_CONTAINER(container), toolbar);
2061 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2063 if ( GTK_IS_WINDOW(container) ) {
2064 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
2065 gtk_widget_show_all (container);
2067 gtk_container_add(GTK_CONTAINER(container), toolbar);
2068 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2071 return toolbar_data;
2075 * Free toolbar structures
2077 void toolbar_destroy(Toolbar * toolbar) {
2079 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2080 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2083 void toolbar_update(ToolbarType type, gpointer data)
2085 Toolbar *toolbar_data;
2086 GtkWidget *handlebox;
2087 MainWindow *mainwin = (MainWindow*)data;
2088 Compose *compose = (Compose*)data;
2089 MessageView *msgview = (MessageView*)data;
2094 toolbar_data = mainwin->toolbar;
2095 handlebox = mainwin->handlebox;
2097 case TOOLBAR_COMPOSE:
2098 toolbar_data = compose->toolbar;
2099 handlebox = compose->handlebox;
2101 case TOOLBAR_MSGVIEW:
2102 toolbar_data = msgview->toolbar;
2103 handlebox = msgview->handlebox;
2109 gtk_container_remove(GTK_CONTAINER(handlebox),
2110 GTK_WIDGET(toolbar_data->toolbar));
2112 toolbar_init(toolbar_data);
2113 toolbar_data = toolbar_create(type, handlebox, data);
2117 toolbar_data = mainwin->toolbar;
2118 handlebox = mainwin->window;
2120 case TOOLBAR_COMPOSE:
2121 toolbar_data = compose->toolbar;
2122 handlebox = compose->window;
2124 case TOOLBAR_MSGVIEW:
2125 toolbar_data = msgview->toolbar;
2126 handlebox = msgview->window;
2132 hildon_window_remove_toolbar(HILDON_WINDOW(handlebox), GTK_TOOLBAR(toolbar_data->toolbar));
2134 toolbar_init(toolbar_data);
2135 toolbar_data = toolbar_create(type, handlebox, data);
2140 mainwin->toolbar = toolbar_data;
2142 case TOOLBAR_COMPOSE:
2143 compose->toolbar = toolbar_data;
2145 case TOOLBAR_MSGVIEW:
2146 msgview->toolbar = toolbar_data;
2150 toolbar_style(type, prefs_common.toolbar_style, data);
2152 if (type == TOOLBAR_MAIN) {
2153 toolbar_main_set_sensitive((MainWindow*)data);
2154 account_set_menu_only_toolbar();
2158 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2159 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2160 if (GTK_IS_BUTTON(widget)) \
2161 in_btn1 = GTK_BUTTON(widget)->in_button; \
2162 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2163 GtkWidget *child = gtk_bin_get_child( \
2165 GList *gchild = gtk_container_get_children( \
2166 GTK_CONTAINER(child)); \
2167 GtkWidget *btn = (GtkWidget *)gchild->data; \
2168 GtkWidget *arr = (GtkWidget *) \
2169 (gchild->next?gchild->next->data:NULL); \
2170 g_list_free(gchild); \
2171 if (GTK_IS_BUTTON(btn)) \
2172 in_btn1 = GTK_BUTTON(btn)->in_button; \
2173 if (GTK_IS_BUTTON(arr)) \
2174 in_btn2 = GTK_BUTTON(arr)->in_button; \
2176 else if (GTK_IS_TOOL_ITEM(widget)) { \
2177 GtkWidget *child = gtk_bin_get_child( \
2179 if (GTK_IS_BUTTON(child)) \
2180 in_btn1 = GTK_BUTTON(child)->in_button; \
2182 gtk_widget_set_sensitive(widget, sensitive); \
2183 if (GTK_IS_BUTTON(widget)) \
2184 GTK_BUTTON(widget)->in_button = in_btn1; \
2185 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2186 GtkWidget *child = gtk_bin_get_child( \
2188 GList *gchild = gtk_container_get_children( \
2189 GTK_CONTAINER(child)); \
2190 GtkWidget *btn = (GtkWidget *)gchild->data; \
2191 GtkWidget *arr = (GtkWidget *) \
2192 (gchild->next?gchild->next->data:NULL); \
2193 g_list_free(gchild); \
2194 if (GTK_IS_BUTTON(btn)) \
2195 GTK_BUTTON(btn)->in_button = in_btn1; \
2196 if (GTK_IS_BUTTON(arr)) \
2197 GTK_BUTTON(arr)->in_button = in_btn2; \
2199 else if (GTK_IS_TOOL_ITEM(widget)) { \
2200 GtkWidget *child = gtk_bin_get_child( \
2202 if (GTK_IS_BUTTON(child)) \
2203 GTK_BUTTON(child)->in_button = in_btn1; \
2207 void toolbar_main_set_sensitive(gpointer data)
2209 SensitiveCond state;
2211 MainWindow *mainwin = (MainWindow*)data;
2212 Toolbar *toolbar = mainwin->toolbar;
2214 GSList *entry_list = NULL;
2216 typedef struct _Entry Entry;
2223 #define SET_WIDGET_COND(w, c) \
2225 Entry *e = g_new0(Entry, 1); \
2228 entry_list = g_slist_append(entry_list, e); \
2232 if (toolbar->get_btn)
2233 SET_WIDGET_COND(toolbar->get_btn,
2234 M_HAVE_ACCOUNT|M_UNLOCKED);
2236 if (toolbar->getall_btn) {
2237 SET_WIDGET_COND(toolbar->getall_btn,
2238 M_HAVE_ACCOUNT|M_UNLOCKED);
2240 if (toolbar->send_btn) {
2241 SET_WIDGET_COND(toolbar->send_btn,
2242 M_HAVE_QUEUED_MAILS);
2244 if (toolbar->compose_mail_btn) {
2245 SET_WIDGET_COND(toolbar->compose_mail_btn,
2248 if (toolbar->close_window_btn) {
2249 SET_WIDGET_COND(toolbar->close_window_btn,
2252 if (toolbar->open_mail_btn) {
2253 SET_WIDGET_COND(toolbar->open_mail_btn,
2256 if (toolbar->reply_btn) {
2257 SET_WIDGET_COND(toolbar->reply_btn,
2258 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2260 if (toolbar->replyall_btn) {
2261 SET_WIDGET_COND(toolbar->replyall_btn,
2262 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2264 if (toolbar->replylist_btn) {
2265 SET_WIDGET_COND(toolbar->replylist_btn,
2266 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2268 if (toolbar->replysender_btn) {
2269 SET_WIDGET_COND(toolbar->replysender_btn,
2270 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2272 if (toolbar->fwd_btn) {
2273 SET_WIDGET_COND(toolbar->fwd_btn,
2274 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2277 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2278 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
2280 SET_WIDGET_COND(toolbar->next_btn, 0);
2283 if (toolbar->trash_btn)
2284 SET_WIDGET_COND(toolbar->trash_btn,
2285 M_TARGET_EXIST|M_ALLOW_DELETE);
2287 if (toolbar->delete_btn)
2288 SET_WIDGET_COND(toolbar->delete_btn,
2289 M_TARGET_EXIST|M_ALLOW_DELETE);
2291 if (toolbar->exec_btn)
2292 SET_WIDGET_COND(toolbar->exec_btn,
2295 /* if (toolbar->learn_ham_btn)
2296 SET_WIDGET_COND(toolbar->learn_ham_btn,
2297 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2299 if (toolbar->learn_spam_btn)
2300 SET_WIDGET_COND(toolbar->learn_spam_btn,
2301 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2303 if (toolbar->cancel_inc_btn)
2304 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2307 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2308 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
2310 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2313 #undef SET_WIDGET_COND
2315 state = main_window_get_current_state(mainwin);
2317 for (cur = entry_list; cur != NULL; cur = cur->next) {
2318 Entry *e = (Entry*) cur->data;
2320 if (e->widget != NULL) {
2321 sensitive = ((e->cond & state) == e->cond);
2322 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2326 while (entry_list != NULL) {
2327 Entry *e = (Entry*) entry_list->data;
2330 entry_list = g_slist_remove(entry_list, e);
2333 g_slist_free(entry_list);
2335 activate_compose_button(toolbar,
2336 prefs_common.toolbar_style,
2337 toolbar->compose_btn_type);
2341 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2343 Compose *compose = (Compose*)data;
2344 GSList *items = compose->toolbar->action_list;
2346 if (compose->toolbar->send_btn)
2347 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2348 if (compose->toolbar->sendl_btn)
2349 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2350 if (compose->toolbar->draft_btn )
2351 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2352 if (compose->toolbar->insert_btn )
2353 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2354 if (compose->toolbar->attach_btn)
2355 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2356 if (compose->toolbar->sig_btn)
2357 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2358 if (compose->toolbar->exteditor_btn)
2359 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2360 if (compose->toolbar->linewrap_current_btn)
2361 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2362 if (compose->toolbar->linewrap_all_btn)
2363 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2364 if (compose->toolbar->addrbook_btn)
2365 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2367 if (compose->toolbar->spellcheck_btn)
2368 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2370 for (; items != NULL; items = g_slist_next(items)) {
2371 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
2372 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2377 * Initialize toolbar structure
2379 static void toolbar_init(Toolbar * toolbar)
2382 toolbar->toolbar = NULL;
2383 toolbar->folders_btn = NULL;
2384 toolbar->get_btn = NULL;
2385 toolbar->getall_btn = NULL;
2386 toolbar->send_btn = NULL;
2387 toolbar->compose_mail_btn = NULL;
2388 toolbar->compose_mail_icon = NULL;
2389 toolbar->compose_news_icon = NULL;
2390 toolbar->reply_btn = NULL;
2391 toolbar->replysender_btn = NULL;
2392 toolbar->replyall_btn = NULL;
2393 toolbar->replylist_btn = NULL;
2394 toolbar->fwd_btn = NULL;
2395 toolbar->trash_btn = NULL;
2396 toolbar->delete_btn = NULL;
2397 toolbar->prev_btn = NULL;
2398 toolbar->next_btn = NULL;
2399 toolbar->exec_btn = NULL;
2400 toolbar->open_mail_btn = NULL;
2401 toolbar->close_window_btn = NULL;
2402 /* compose buttons */
2403 toolbar->sendl_btn = NULL;
2404 toolbar->draft_btn = NULL;
2405 toolbar->insert_btn = NULL;
2406 toolbar->attach_btn = NULL;
2407 toolbar->sig_btn = NULL;
2408 toolbar->exteditor_btn = NULL;
2409 toolbar->linewrap_current_btn = NULL;
2410 toolbar->linewrap_all_btn = NULL;
2411 toolbar->addrbook_btn = NULL;
2413 toolbar->spellcheck_btn = NULL;
2416 toolbar_destroy(toolbar);
2421 static void toolbar_reply(gpointer data, guint action)
2423 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2424 MainWindow *mainwin;
2425 MessageView *msgview;
2426 GSList *msginfo_list = NULL;
2428 g_return_if_fail(toolbar_item != NULL);
2430 switch (toolbar_item->type) {
2432 mainwin = (MainWindow*)toolbar_item->parent;
2433 msginfo_list = summary_get_selection(mainwin->summaryview);
2434 msgview = (MessageView*)mainwin->messageview;
2436 case TOOLBAR_MSGVIEW:
2437 msgview = (MessageView*)toolbar_item->parent;
2438 g_return_if_fail(msgview != NULL);
2439 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2445 g_return_if_fail(msgview != NULL);
2446 g_return_if_fail(msginfo_list != NULL);
2447 compose_reply_from_messageview(msgview, msginfo_list, action);
2448 g_slist_free(msginfo_list);
2450 /* TODO: update reply state ion summaryview */
2454 /* exported functions */
2456 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2458 MainWindow *mainwin = (MainWindow*)data;
2460 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2463 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2465 MainWindow *mainwin = (MainWindow*)data;
2467 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2470 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2474 gboolean got_error = FALSE;
2475 gchar *errstr = NULL;
2477 if (prefs_common.work_offline)
2478 if (alertpanel(_("Offline warning"),
2479 _("You're working offline. Override?"),
2480 GTK_STOCK_NO, GTK_STOCK_YES,
2481 NULL) != G_ALERTALTERNATE)
2484 /* ask for confirmation before sending queued messages only
2485 in online mode and if there is at least one message queued
2486 in any of the folder queue
2488 if (prefs_common.confirm_send_queued_messages) {
2490 /* check if there's a queued message */
2491 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2492 Folder *folder = list->data;
2494 found = !procmsg_queue_is_empty(folder->queue);
2496 /* if necessary, ask for confirmation before sending */
2497 if (found && !prefs_common.work_offline) {
2498 if (alertpanel(_("Send queued messages"),
2499 _("Send all queued messages?"),
2500 GTK_STOCK_CANCEL, _("_Send"),
2501 NULL) != G_ALERTALTERNATE)
2506 for (list = folder_get_list(); list != NULL; list = list->next) {
2507 Folder *folder = list->data;
2509 if (folder->queue) {
2510 if (procmsg_send_queue(folder->queue,
2511 prefs_common.savemsg,
2518 alertpanel_error_log(_("Some errors occurred while "
2519 "sending queued messages."));
2521 alertpanel_error_log(_("Some errors occurred "
2522 "while sending queued messages:\n%s"), errstr);
2528 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2530 MainWindow *mainwin = (MainWindow*)data;
2531 PrefsAccount *ac = NULL;
2532 FolderItem *item = mainwin->summaryview->folder_item;
2537 ac = account_find_from_item(item);
2538 if (ac && ac->protocol != A_NNTP) {
2539 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2545 * CLAWS - use current account
2547 if (cur_account && (cur_account->protocol != A_NNTP)) {
2548 compose_new_with_folderitem(cur_account, item, NULL);
2553 * CLAWS - just get the first one
2555 list = account_get_list();
2556 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2557 ac = (PrefsAccount *) cur->data;
2558 if (ac->protocol != A_NNTP) {
2559 compose_new_with_folderitem(ac, item, NULL);
2565 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2567 MainWindow *mainwin = (MainWindow*)data;
2568 PrefsAccount * ac = NULL;
2572 if (mainwin->summaryview->folder_item) {
2573 ac = mainwin->summaryview->folder_item->folder->account;
2574 if (ac && ac->protocol == A_NNTP) {
2575 compose_new_with_folderitem(ac,
2576 mainwin->summaryview->folder_item, NULL);
2581 list = account_get_list();
2582 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2583 ac = (PrefsAccount *) cur->data;
2584 if (ac->protocol == A_NNTP) {
2585 compose_new_with_folderitem(ac,
2586 mainwin->summaryview->folder_item, NULL);