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_CLAWS_ACTIONS", N_("Claws Mail Actions Feature") },
212 { "A_CANCEL_INC", N_("Cancel receiving") },
213 { "A_CLOSE", N_("Close window") },
214 { "A_SEPARATOR", N_("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_CLAWS_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 if (item->index == -1 && !strcmp(value, "A_SYL_ACTIONS")) {
397 item->index = A_CLAWS_ACTIONS;
400 attr = g_list_next(attr);
402 if (item->index != -1) {
404 if (!toolbar_is_duplicate(item->index, source))
405 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
409 toolbar_save_config_file(source);
413 const gchar *toolbar_get_short_text(int action) {
415 case A_GO_FOLDERS: return _("Folders");
416 case A_OPEN_MAIL: return _("Open");
417 case A_RECEIVE_ALL: return _("Get Mail");
418 case A_RECEIVE_CUR: return _("Get");
419 case A_SEND_QUEUED: return _("Send");
420 case A_COMPOSE_EMAIL: return Q_("Toolbar|Compose");
421 case A_COMPOSE_NEWS: return Q_("Toolbar|Compose");
422 case A_REPLY_MESSAGE: return _("Reply");
423 case A_REPLY_ALL: return _("All");
424 case A_REPLY_SENDER: return _("Sender");
425 case A_REPLY_ML: return _("List");
426 case A_FORWARD: return _("Forward");
427 case A_TRASH: return _("Trash");
428 case A_DELETE_REAL: return _("Delete");
429 case A_LEARN_SPAM: return _("Spam");
430 case A_GOTO_PREV: return _("Prev");
431 case A_GOTO_NEXT: return _("Next");
432 case A_IGNORE_THREAD: return _("Ignore thread");
433 case A_WATCH_THREAD: return _("Watch thread");
434 case A_PRINT: return _("Print");
435 case A_CLOSE: return _("Close");
436 case A_SEND: return _("Send");
437 case A_SENDL: return _("Send later");
438 case A_DRAFT: return _("Draft");
439 case A_INSERT: return _("Insert");
440 case A_ATTACH: return _("Attach");
441 case A_SIG: return _("Insert sig.");
442 case A_EXTEDITOR: return _("Edit");
443 case A_LINEWRAP_CURRENT:return _("Wrap para.");
444 case A_LINEWRAP_ALL: return _("Wrap all");
445 case A_ADDRBOOK: return _("Address");
446 case A_CANCEL_INC: return _("Stop");
447 case A_EXECUTE: return _("Execute");
449 case A_CHECK_SPELLING: return _("Check spelling");
455 gint toolbar_get_icon(int action) {
457 case A_GO_FOLDERS: return STOCK_PIXMAP_GO_FOLDERS;
458 case A_OPEN_MAIL: return STOCK_PIXMAP_OPEN_MAIL;
459 case A_RECEIVE_ALL: return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
460 case A_RECEIVE_CUR: return STOCK_PIXMAP_MAIL_RECEIVE;
461 case A_SEND_QUEUED: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
462 case A_COMPOSE_EMAIL: return STOCK_PIXMAP_MAIL_COMPOSE;
463 case A_COMPOSE_NEWS: return STOCK_PIXMAP_NEWS_COMPOSE;
464 case A_REPLY_MESSAGE: return STOCK_PIXMAP_MAIL_REPLY;
465 case A_REPLY_ALL: return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
466 case A_REPLY_SENDER: return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
467 case A_REPLY_ML: return STOCK_PIXMAP_MAIL_REPLY;
468 case A_FORWARD: return STOCK_PIXMAP_MAIL_FORWARD;
469 case A_TRASH: return STOCK_PIXMAP_TRASH;
470 case A_DELETE_REAL: return STOCK_PIXMAP_DELETED;
471 case A_LEARN_SPAM: return STOCK_PIXMAP_SPAM_BTN;
472 case A_GOTO_PREV: return STOCK_PIXMAP_UP_ARROW;
473 case A_GOTO_NEXT: return STOCK_PIXMAP_DOWN_ARROW;
474 case A_IGNORE_THREAD: return STOCK_PIXMAP_IGNORETHREAD;
475 case A_WATCH_THREAD: return STOCK_PIXMAP_WATCHTHREAD;
476 case A_PRINT: return STOCK_PIXMAP_PRINTER;
477 case A_CLOSE: return STOCK_PIXMAP_CLOSE;
478 case A_SEND: return STOCK_PIXMAP_MAIL_SEND;
479 case A_SENDL: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
480 case A_DRAFT: return STOCK_PIXMAP_MAIL;
481 case A_INSERT: return STOCK_PIXMAP_INSERT_FILE;
482 case A_ATTACH: return STOCK_PIXMAP_MAIL_ATTACH;
483 case A_SIG: return STOCK_PIXMAP_MAIL_SIGN;
484 case A_EXTEDITOR: return STOCK_PIXMAP_EDIT_EXTERN;
485 case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
486 case A_LINEWRAP_ALL: return STOCK_PIXMAP_LINEWRAP_ALL;
487 case A_ADDRBOOK: return STOCK_PIXMAP_ADDRESS_BOOK;
488 case A_CANCEL_INC: return STOCK_PIXMAP_NOTICE_ERROR;
489 case A_EXECUTE: return STOCK_PIXMAP_EXEC;
491 case A_CHECK_SPELLING: return STOCK_PIXMAP_CHECK_SPELLING;
497 static void toolbar_set_default_main(void)
501 } default_toolbar[] = {
521 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
531 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
533 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
535 if (default_toolbar[i].action != A_SEPARATOR) {
537 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
539 toolbar_item->file = g_strdup(file);
540 toolbar_item->index = default_toolbar[i].action;
541 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
544 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
545 toolbar_item->index = A_SEPARATOR;
548 if (toolbar_item->index != -1) {
549 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
550 toolbar_config[TOOLBAR_MAIN].item_list =
551 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
556 static void toolbar_set_default_compose(void)
560 } default_toolbar[] = {
579 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
581 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
583 if (default_toolbar[i].action != A_SEPARATOR) {
585 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
587 toolbar_item->file = g_strdup(file);
588 toolbar_item->index = default_toolbar[i].action;
589 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
592 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
593 toolbar_item->index = A_SEPARATOR;
596 if (toolbar_item->index != -1) {
597 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
598 toolbar_config[TOOLBAR_COMPOSE].item_list =
599 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
604 static void toolbar_set_default_msgview(void)
608 } default_toolbar[] = {
620 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
629 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
631 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
633 if (default_toolbar[i].action != A_SEPARATOR) {
635 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
637 toolbar_item->file = g_strdup(file);
638 toolbar_item->index = default_toolbar[i].action;
639 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
642 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
643 toolbar_item->index = A_SEPARATOR;
646 if (toolbar_item->index != -1) {
647 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
648 toolbar_config[TOOLBAR_MSGVIEW].item_list =
649 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
654 void toolbar_set_default(ToolbarType source)
656 if (source == TOOLBAR_MAIN)
657 toolbar_set_default_main();
658 else if (source == TOOLBAR_COMPOSE)
659 toolbar_set_default_compose();
660 else if (source == TOOLBAR_MSGVIEW)
661 toolbar_set_default_msgview();
664 void toolbar_save_config_file(ToolbarType source)
669 gchar *fileSpec = NULL;
671 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
673 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
674 pfile = prefs_write_open(fileSpec);
677 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
680 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
683 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
684 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
686 if (toolbar_item->index != A_SEPARATOR) {
687 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
689 TOOLBAR_ICON_FILE, toolbar_item->file,
690 TOOLBAR_ICON_TEXT) < 0)
692 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
694 if (fprintf(fp, "\" %s=\"%s\"/>\n",
696 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
699 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
704 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
708 if (prefs_file_close (pfile) < 0 )
709 g_warning("failed to write toolbar configuration to file\n");
713 FILE_OP_ERROR(fileSpec, "fprintf");
715 prefs_file_close_revert (pfile);
717 g_warning("failed to open toolbar configuration file for writing\n");
720 void toolbar_read_config_file(ToolbarType source)
722 XMLFile *file = NULL;
723 gchar *fileSpec = NULL;
728 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
730 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
731 file = xml_open_file(fileSpec);
734 toolbar_clear_list(source);
738 || (xml_get_dtd(file))
739 || (xml_parse_next_tag(file))
740 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
741 xml_close_file(file);
745 attr = xml_get_current_tag_attr(file);
752 if (xml_parse_next_tag(file))
755 /* Get next tag (icon, icon_text or icon_action) */
756 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
757 toolbar_parse_item(file, source);
758 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
759 ToolbarItem *item = g_new0(ToolbarItem, 1);
761 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
762 item->index = A_SEPARATOR;
763 toolbar_config[source].item_list =
764 g_slist_append(toolbar_config[source].item_list, item);
768 xml_close_file(file);
771 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
773 if (source == TOOLBAR_MAIN)
774 toolbar_set_default(TOOLBAR_MAIN);
775 else if (source == TOOLBAR_COMPOSE)
776 toolbar_set_default(TOOLBAR_COMPOSE);
777 else if (source == TOOLBAR_MSGVIEW)
778 toolbar_set_default(TOOLBAR_MSGVIEW);
780 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
784 toolbar_save_config_file(source);
789 * clears list of toolbar items read from configuration files
791 void toolbar_clear_list(ToolbarType source)
793 while (toolbar_config[source].item_list != NULL) {
794 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
796 toolbar_config[source].item_list =
797 g_slist_remove(toolbar_config[source].item_list, item);
803 g_slist_free(toolbar_config[source].item_list);
808 * return list of Toolbar items
810 GSList *toolbar_get_list(ToolbarType source)
814 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
815 list = toolbar_config[source].item_list;
820 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
822 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
824 toolbar_item->file = g_strdup(t_item->file);
825 toolbar_item->text = g_strdup(t_item->text);
826 toolbar_item->index = t_item->index;
828 toolbar_config[source].item_list =
829 g_slist_append(toolbar_config[source].item_list,
833 static void toolbar_action_execute(GtkWidget *widget,
839 gchar *action, *action_p;
840 gboolean found = FALSE;
843 for (cur = action_list; cur != NULL; cur = cur->next) {
844 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
846 if (widget == act->widget) {
848 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
849 action = g_strdup((gchar*)lop->data);
851 action_p = strstr(action, ": ");
853 if (g_utf8_collate(act->name, action) == 0) {
867 actions_execute(data, i, widget, source);
869 g_warning ("Error: did not find Claws Action to execute");
872 static void activate_compose_button (Toolbar *toolbar,
874 ComposeButtonType type)
876 if ((!toolbar->compose_mail_btn))
879 if (type == COMPOSEBUTTON_NEWS) {
880 gtk_tool_button_set_icon_widget(
881 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
882 toolbar->compose_news_icon);
884 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->compose_mail_btn), GTK_TOOLTIPS(toolbar->tooltips),
885 _("Compose News message"), NULL);
887 gtk_widget_show(toolbar->compose_news_icon);
889 gtk_tool_button_set_icon_widget(
890 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
891 toolbar->compose_mail_icon);
893 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->compose_mail_btn), GTK_TOOLTIPS(toolbar->tooltips),
894 _("Compose Email"), NULL);
896 gtk_widget_show(toolbar->compose_mail_icon);
898 toolbar->compose_btn_type = type;
901 void toolbar_set_compose_button(Toolbar *toolbar,
902 ComposeButtonType compose_btn_type)
904 if (toolbar->compose_btn_type != compose_btn_type)
905 activate_compose_button(toolbar,
906 prefs_common.toolbar_style,
910 static void activate_learn_button (Toolbar *toolbar,
912 LearnButtonType type)
914 if ((!toolbar->learn_spam_btn))
917 if (type == LEARN_SPAM) {
918 gtk_tool_button_set_icon_widget(
919 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
920 toolbar->learn_spam_icon);
921 gtk_tool_button_set_label(
922 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 spam"), NULL);
928 gtk_widget_show(toolbar->learn_spam_icon);
930 gtk_tool_button_set_icon_widget(
931 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
932 toolbar->learn_ham_icon);
933 gtk_tool_button_set_label(
934 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
937 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->learn_spam_btn), GTK_TOOLTIPS(toolbar->tooltips),
938 _("Learn ham"), NULL);
940 gtk_widget_show(toolbar->learn_ham_icon);
942 toolbar->learn_btn_type = type;
945 void toolbar_set_learn_button(Toolbar *toolbar,
946 LearnButtonType learn_btn_type)
948 if (toolbar->learn_btn_type != learn_btn_type)
949 activate_learn_button(toolbar,
950 prefs_common.toolbar_style,
954 void toolbar_toggle(guint action, gpointer data)
956 MainWindow *mainwin = (MainWindow*)data;
960 g_return_if_fail(mainwin != NULL);
962 toolbar_style(TOOLBAR_MAIN, action, mainwin);
964 list = compose_get_compose_list();
965 for (cur = list; cur != NULL; cur = cur->next) {
966 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
968 list = messageview_get_msgview_list();
969 for (cur = list; cur != NULL; cur = cur->next) {
970 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
975 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
977 switch ((ToolbarStyle)action) {
979 gtk_widget_hide(handlebox_wid);
982 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
986 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
990 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
993 case TOOLBAR_BOTH_HORIZ:
994 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
995 GTK_TOOLBAR_BOTH_HORIZ);
1001 prefs_common.toolbar_style = (ToolbarStyle)action;
1002 gtk_widget_set_size_request(handlebox_wid, 1, -1);
1004 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1005 gtk_widget_show(handlebox_wid);
1006 gtk_widget_queue_resize(handlebox_wid);
1010 * Change the style of toolbar
1012 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1014 GtkWidget *handlebox_wid;
1015 GtkWidget *toolbar_wid;
1016 MainWindow *mainwin = (MainWindow*)data;
1017 Compose *compose = (Compose*)data;
1018 MessageView *msgview = (MessageView*)data;
1020 g_return_if_fail(data != NULL);
1024 handlebox_wid = mainwin->handlebox;
1025 toolbar_wid = mainwin->toolbar->toolbar;
1027 case TOOLBAR_COMPOSE:
1028 handlebox_wid = compose->handlebox;
1029 toolbar_wid = compose->toolbar->toolbar;
1031 case TOOLBAR_MSGVIEW:
1032 handlebox_wid = msgview->handlebox;
1033 toolbar_wid = msgview->toolbar->toolbar;
1039 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1042 /* Toolbar handling */
1043 static void toolbar_inc_cb(GtkWidget *widget,
1046 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1047 MainWindow *mainwin;
1049 g_return_if_fail(toolbar_item != NULL);
1051 switch (toolbar_item->type) {
1053 mainwin = (MainWindow*)toolbar_item->parent;
1054 inc_mail_cb(mainwin, 0, NULL);
1061 static void toolbar_inc_all_cb(GtkWidget *widget,
1064 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1065 MainWindow *mainwin;
1067 g_return_if_fail(toolbar_item != NULL);
1069 switch (toolbar_item->type) {
1071 mainwin = (MainWindow*)toolbar_item->parent;
1072 inc_all_account_mail_cb(mainwin, 0, NULL);
1079 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1081 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1082 MainWindow *mainwin;
1084 g_return_if_fail(toolbar_item != NULL);
1086 switch (toolbar_item->type) {
1088 mainwin = (MainWindow*)toolbar_item->parent;
1089 send_queue_cb(mainwin, 0, NULL);
1096 static void toolbar_exec_cb(GtkWidget *widget,
1099 MainWindow *mainwin = get_mainwin(data);
1101 g_return_if_fail(mainwin != NULL);
1102 summary_execute(mainwin->summaryview);
1106 * Delete current/selected(s) message(s)
1108 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1110 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1111 MainWindow *mainwin;
1113 g_return_if_fail(toolbar_item != NULL);
1114 g_return_if_fail(toolbar_item->parent);
1116 switch (toolbar_item->type) {
1117 case TOOLBAR_MSGVIEW:
1118 messageview_delete((MessageView *)toolbar_item->parent);
1121 mainwin = (MainWindow *)toolbar_item->parent;
1122 summary_delete_trash(mainwin->summaryview);
1125 debug_print("toolbar event not supported\n");
1131 * Delete current/selected(s) message(s)
1133 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1135 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1136 MainWindow *mainwin;
1138 g_return_if_fail(toolbar_item != NULL);
1139 g_return_if_fail(toolbar_item->parent);
1141 switch (toolbar_item->type) {
1142 case TOOLBAR_MSGVIEW:
1143 messageview_delete((MessageView *)toolbar_item->parent);
1146 mainwin = (MainWindow *)toolbar_item->parent;
1147 summary_delete(mainwin->summaryview);
1150 debug_print("toolbar event not supported\n");
1157 * Compose new message
1159 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1161 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1162 MainWindow *mainwin;
1163 MessageView *msgview;
1165 g_return_if_fail(toolbar_item != NULL);
1167 switch (toolbar_item->type) {
1169 mainwin = (MainWindow*)toolbar_item->parent;
1170 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1171 compose_news_cb(mainwin, 0, NULL);
1173 compose_mail_cb(mainwin, 0, NULL);
1175 case TOOLBAR_MSGVIEW:
1176 msgview = (MessageView*)toolbar_item->parent;
1177 compose_new_with_folderitem(NULL,
1178 msgview->msginfo->folder, NULL);
1181 debug_print("toolbar event not supported\n");
1185 static void toolbar_learn(gpointer data, guint as_spam)
1187 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1188 MainWindow *mainwin;
1189 MessageView *msgview;
1191 g_return_if_fail(toolbar_item != NULL);
1193 switch (toolbar_item->type) {
1195 mainwin = (MainWindow*)toolbar_item->parent;
1197 mainwindow_learn(mainwin, TRUE);
1199 mainwindow_learn(mainwin, FALSE);
1201 case TOOLBAR_MSGVIEW:
1202 msgview = (MessageView*)toolbar_item->parent;
1204 messageview_learn(msgview, TRUE);
1206 messageview_learn(msgview, FALSE);
1209 debug_print("toolbar event not supported\n");
1213 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1215 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1216 MainWindow *mainwin;
1217 MessageView *msgview;
1219 g_return_if_fail(toolbar_item != NULL);
1221 switch (toolbar_item->type) {
1223 mainwin = (MainWindow*)toolbar_item->parent;
1224 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1225 mainwindow_learn(mainwin, TRUE);
1227 mainwindow_learn(mainwin, FALSE);
1229 case TOOLBAR_MSGVIEW:
1230 msgview = (MessageView*)toolbar_item->parent;
1231 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1232 messageview_learn(msgview, TRUE);
1234 messageview_learn(msgview, FALSE);
1237 debug_print("toolbar event not supported\n");
1245 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1247 toolbar_reply(data, prefs_common.reply_with_quote ?
1248 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1253 * Reply message to Sender and All recipients
1255 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1258 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1259 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1264 * Reply to Mailing List
1266 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1269 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1270 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1275 * Reply to sender of message
1277 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1280 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1281 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1287 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1289 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1292 g_return_if_fail(toolbar_item != NULL);
1294 switch (toolbar_item->type) {
1296 case TOOLBAR_MSGVIEW:
1299 case TOOLBAR_COMPOSE:
1300 compose = (Compose *)toolbar_item->parent;
1305 addressbook_open(compose);
1310 * Forward current/selected(s) message(s)
1312 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1314 toolbar_reply(data, COMPOSE_FORWARD);
1318 * Goto Prev Unread Message
1320 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1322 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1323 MainWindow *mainwin;
1324 MessageView *msgview;
1326 g_return_if_fail(toolbar_item != NULL);
1328 switch (toolbar_item->type) {
1330 mainwin = (MainWindow*)toolbar_item->parent;
1331 summary_select_prev_unread(mainwin->summaryview);
1334 case TOOLBAR_MSGVIEW:
1335 msgview = (MessageView*)toolbar_item->parent;
1336 msgview->updating = TRUE;
1337 summary_select_prev_unread(msgview->mainwin->summaryview);
1338 msgview->updating = FALSE;
1340 if (msgview->deferred_destroy) {
1341 debug_print("messageview got away!\n");
1342 messageview_destroy(msgview);
1346 /* Now we need to update the messageview window */
1347 if (msgview->mainwin->summaryview->selected) {
1349 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1352 messageview_show(msgview, msginfo,
1353 msgview->all_headers);
1356 gtk_widget_destroy(msgview->window);
1360 debug_print("toolbar event not supported\n");
1365 * Goto Next Unread Message
1367 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1369 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1370 MainWindow *mainwin;
1371 MessageView *msgview;
1373 g_return_if_fail(toolbar_item != NULL);
1375 switch (toolbar_item->type) {
1377 mainwin = (MainWindow*)toolbar_item->parent;
1378 summary_select_next_unread(mainwin->summaryview);
1381 case TOOLBAR_MSGVIEW:
1382 msgview = (MessageView*)toolbar_item->parent;
1383 msgview->updating = TRUE;
1384 summary_select_next_unread(msgview->mainwin->summaryview);
1385 msgview->updating = FALSE;
1387 if (msgview->deferred_destroy) {
1388 debug_print("messageview got away!\n");
1389 messageview_destroy(msgview);
1393 /* Now we need to update the messageview window */
1394 if (msgview->mainwin->summaryview->selected) {
1396 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1399 messageview_show(msgview, msginfo,
1400 msgview->all_headers);
1403 gtk_widget_destroy(msgview->window);
1407 debug_print("toolbar event not supported\n");
1411 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1413 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1414 MainWindow *mainwin;
1416 g_return_if_fail(toolbar_item != NULL);
1418 switch (toolbar_item->type) {
1420 mainwin = (MainWindow *) toolbar_item->parent;
1421 summary_toggle_ignore_thread(mainwin->summaryview);
1423 case TOOLBAR_MSGVIEW:
1424 /* TODO: see toolbar_next_unread_cb() if you need
1425 * this in the message view */
1428 debug_print("toolbar event not supported\n");
1433 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1435 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1436 MainWindow *mainwin;
1438 g_return_if_fail(toolbar_item != NULL);
1440 switch (toolbar_item->type) {
1442 mainwin = (MainWindow *) toolbar_item->parent;
1443 summary_toggle_watch_thread(mainwin->summaryview);
1445 case TOOLBAR_MSGVIEW:
1446 /* TODO: see toolbar_next_unread_cb() if you need
1447 * this in the message view */
1450 debug_print("toolbar event not supported\n");
1455 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1457 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1459 g_return_if_fail(toolbar_item != NULL);
1465 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1467 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1468 MainWindow *mainwin;
1470 g_return_if_fail(toolbar_item != NULL);
1472 switch (toolbar_item->type) {
1474 mainwin = (MainWindow *) toolbar_item->parent;
1475 summary_print(mainwin->summaryview);
1477 case TOOLBAR_MSGVIEW:
1478 /* TODO: see toolbar_next_unread_cb() if you need
1479 * this in the message view */
1482 debug_print("toolbar event not supported\n");
1487 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1489 compose_toolbar_cb(A_SEND, data);
1492 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1494 compose_toolbar_cb(A_SENDL, data);
1497 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1499 compose_toolbar_cb(A_DRAFT, data);
1502 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1504 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1505 MainWindow *mainwin;
1506 MessageView *messageview;
1509 g_return_if_fail(toolbar_item != NULL);
1511 switch (toolbar_item->type) {
1513 mainwin = (MainWindow *) toolbar_item->parent;
1514 app_will_exit(NULL, mainwin);
1516 case TOOLBAR_MSGVIEW:
1517 messageview = (MessageView *)toolbar_item->parent;
1518 messageview_destroy(messageview);
1520 case TOOLBAR_COMPOSE:
1521 compose = (Compose *)toolbar_item->parent;
1522 compose_close_toolbar(compose);
1527 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1529 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1530 MainWindow *mainwin;
1532 g_return_if_fail(toolbar_item != NULL);
1534 switch (toolbar_item->type) {
1536 mainwin = (MainWindow *) toolbar_item->parent;
1537 summary_open_row(NULL, mainwin->summaryview);
1539 case TOOLBAR_MSGVIEW:
1540 debug_print("toolbar event not supported\n");
1542 case TOOLBAR_COMPOSE:
1543 debug_print("toolbar event not supported\n");
1548 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1550 compose_toolbar_cb(A_INSERT, data);
1553 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1555 compose_toolbar_cb(A_ATTACH, data);
1558 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1560 compose_toolbar_cb(A_SIG, data);
1563 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1565 compose_toolbar_cb(A_EXTEDITOR, data);
1568 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1570 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1573 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1575 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1579 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1581 compose_toolbar_cb(A_CHECK_SPELLING, data);
1585 * Execute actions from toolbar
1587 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1589 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1590 GSList *action_list;
1591 MainWindow *mainwin;
1593 MessageView *msgview;
1594 gpointer parent = toolbar_item->parent;
1596 g_return_if_fail(toolbar_item != NULL);
1598 switch (toolbar_item->type) {
1600 mainwin = (MainWindow*)parent;
1601 action_list = mainwin->toolbar->action_list;
1603 case TOOLBAR_COMPOSE:
1604 compose = (Compose*)parent;
1605 action_list = compose->toolbar->action_list;
1607 case TOOLBAR_MSGVIEW:
1608 msgview = (MessageView*)parent;
1609 action_list = msgview->toolbar->action_list;
1612 debug_print("toolbar event not supported\n");
1615 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1618 static MainWindow *get_mainwin(gpointer data)
1620 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1621 MainWindow *mainwin = NULL;
1622 MessageView *msgview;
1624 g_return_val_if_fail(toolbar_item != NULL, NULL);
1626 switch(toolbar_item->type) {
1628 mainwin = (MainWindow*)toolbar_item->parent;
1630 case TOOLBAR_MSGVIEW:
1631 msgview = (MessageView*)toolbar_item->parent;
1632 mainwin = (MainWindow*)msgview->mainwin;
1641 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1643 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1644 MainWindow *mainwin = NULL;
1645 switch(toolbar_item->type) {
1647 mainwin = (MainWindow*)toolbar_item->parent;
1650 g_warning("wrong toolbar type\n");
1654 if (!mainwin->in_folder) {
1655 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1657 folderview_select(mainwin->folderview, item);
1660 gtk_widget_grab_focus(mainwin->folderview->ctree);
1661 mainwindow_exit_folder(mainwin);
1665 static void toolbar_buttons_cb(GtkWidget *widget,
1672 void (*func)(GtkWidget *widget, gpointer data);
1674 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1675 { A_RECEIVE_CUR, toolbar_inc_cb },
1676 { A_SEND_QUEUED, toolbar_send_queued_cb },
1677 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1678 { A_COMPOSE_NEWS, toolbar_compose_cb },
1679 { A_REPLY_MESSAGE, toolbar_reply_cb },
1680 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1681 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1682 { A_REPLY_ML, toolbar_reply_to_list_cb },
1683 { A_FORWARD, toolbar_forward_cb },
1684 { A_TRASH, toolbar_trash_cb },
1685 { A_DELETE_REAL, toolbar_delete_cb },
1686 { A_EXECUTE, toolbar_exec_cb },
1687 { A_GOTO_PREV, toolbar_prev_unread_cb },
1688 { A_GOTO_NEXT, toolbar_next_unread_cb },
1689 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1690 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1691 { A_PRINT, toolbar_print_cb },
1692 { A_LEARN_SPAM, toolbar_learn_cb },
1693 { A_GO_FOLDERS, toolbar_go_folders_cb },
1695 { A_SEND, toolbar_send_cb },
1696 { A_SENDL, toolbar_send_later_cb },
1697 { A_DRAFT, toolbar_draft_cb },
1698 { A_OPEN_MAIL, toolbar_open_mail_cb },
1699 { A_CLOSE, toolbar_close_cb },
1700 { A_INSERT, toolbar_insert_cb },
1701 { A_ATTACH, toolbar_attach_cb },
1702 { A_SIG, toolbar_sig_cb },
1703 { A_EXTEDITOR, toolbar_ext_editor_cb },
1704 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1705 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1706 { A_ADDRBOOK, toolbar_addrbook_cb },
1708 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1710 { A_CLAWS_ACTIONS, toolbar_actions_execute_cb },
1711 { A_CANCEL_INC, toolbar_cancel_inc_cb }
1714 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1716 for (i = 0; i < num_items; i++) {
1717 if (callbacks[i].index == item->index) {
1718 callbacks[i].func(widget, item);
1724 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1725 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1726 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1727 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1728 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1729 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1730 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1734 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1735 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1736 GList *gchild = NULL; \
1737 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1738 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1739 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1740 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1741 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1742 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1744 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(item), \
1745 GTK_TOOLTIPS(toolbar_tips), menutip, NULL); \
1746 child = gtk_bin_get_child(GTK_BIN(item)); \
1747 gchild = gtk_container_get_children( \
1748 GTK_CONTAINER(child)); \
1749 btn = (GtkWidget *)gchild->data; \
1750 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1751 g_list_free(gchild); \
1752 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1753 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1754 g_list_free(gchild); \
1757 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1758 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1759 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1760 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1761 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1762 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1765 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1766 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1767 GList *gchild = NULL; \
1768 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1769 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1770 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1771 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1772 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1773 child = gtk_bin_get_child(GTK_BIN(item)); \
1774 gchild = gtk_container_get_children( \
1775 GTK_CONTAINER(child)); \
1776 btn = (GtkWidget *)gchild->data; \
1777 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1778 g_list_free(gchild); \
1779 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1780 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1781 g_list_free(gchild); \
1785 #define MAKE_MENU(entries,path,btn) { \
1786 n_menu_entries = sizeof(entries) / \
1787 sizeof(entries[0]); \
1788 menu = menu_create_items(entries, n_menu_entries, path, &factory, toolbar_item); \
1789 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(btn), menu); \
1793 * Create a new toolbar with specified type
1794 * if a callback list is passed it will be used before the
1795 * common callback list
1797 Toolbar *toolbar_create(ToolbarType type,
1798 GtkWidget *container,
1801 ToolbarItem *toolbar_item;
1804 GtkWidget *icon_wid = NULL;
1805 GtkWidget *icon_news;
1806 GtkWidget *icon_ham;
1809 guint n_menu_entries;
1810 GtkItemFactory *factory;
1811 ToolbarClawsActions *action_item;
1813 GSList *toolbar_list;
1814 Toolbar *toolbar_data;
1816 GtkTooltips *toolbar_tips;
1818 toolbar_tips = gtk_tooltips_new();
1820 toolbar_read_config_file(type);
1821 toolbar_list = toolbar_get_list(type);
1823 toolbar_data = g_new0(Toolbar, 1);
1825 toolbar = gtk_toolbar_new();
1827 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1828 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1829 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1831 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1833 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1834 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1838 toolbar_item = g_new0(ToolbarItem, 1);
1839 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1840 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1841 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1842 toolbar_item->parent = data;
1843 toolbar_item->type = type;
1845 /* collect toolbar items in list to keep track */
1846 toolbar_data->item_list =
1847 g_slist_append(toolbar_data->item_list,
1849 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1851 switch (toolbar_item->index) {
1854 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1855 toolbar_data->folders_btn = item;
1858 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1859 _("Receive Mail on all Accounts"),
1860 _("Receive Mail on selected Account"));
1861 toolbar_data->getall_btn = item;
1864 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail on current Account"));
1865 toolbar_data->get_btn = item;
1868 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1869 toolbar_data->send_btn = item;
1872 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1873 toolbar_data->close_window_btn = item;
1876 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1877 toolbar_data->open_mail_btn = item;
1879 case A_COMPOSE_EMAIL:
1881 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1883 _("Compose with selected Account"));
1884 toolbar_data->compose_mail_btn = item;
1885 toolbar_data->compose_mail_icon = icon_wid;
1886 g_object_ref(toolbar_data->compose_mail_icon);
1888 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1889 toolbar_data->compose_news_icon = icon_news;
1890 g_object_ref(toolbar_data->compose_news_icon);
1892 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1893 _("Compose Email"));
1894 toolbar_data->compose_mail_btn = item;
1895 toolbar_data->compose_mail_icon = icon_wid;
1897 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1898 toolbar_data->compose_news_icon = icon_news;
1902 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1905 toolbar_data->learn_spam_btn = item;
1906 toolbar_data->learn_spam_icon = icon_wid;
1907 g_object_ref(toolbar_data->learn_spam_icon);
1909 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1910 toolbar_data->learn_ham_icon = icon_ham;
1911 g_object_ref(toolbar_data->learn_ham_icon);
1913 MAKE_MENU(learn_entries,"<LearnSpam>",toolbar_data->learn_spam_btn);
1915 case A_REPLY_MESSAGE:
1917 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1918 _("Reply to Message"),
1919 _("Reply to Message options"));
1920 toolbar_data->reply_btn = item;
1922 MAKE_MENU(reply_entries,"<Reply>",toolbar_data->reply_btn);
1924 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1925 _("Reply to Message"));
1926 toolbar_data->reply_btn = item;
1929 case A_REPLY_SENDER:
1931 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1932 _("Reply to Sender"),
1933 _("Reply to Sender options"));
1934 toolbar_data->replysender_btn = item;
1936 MAKE_MENU(replysender_entries,"<ReplySender>",toolbar_data->replysender_btn);
1938 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1939 _("Reply to Sender"));
1940 toolbar_data->replysender_btn = item;
1945 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1947 _("Reply to All options"));
1948 toolbar_data->replyall_btn = item;
1950 MAKE_MENU(replyall_entries,"<ReplyAll>",toolbar_data->replyall_btn);
1952 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1954 toolbar_data->replyall_btn = item;
1959 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1960 _("Reply to Mailing-list"),
1961 _("Reply to Mailing-list options"));
1962 toolbar_data->replylist_btn = item;
1964 MAKE_MENU(replylist_entries,"<ReplyList>",toolbar_data->replylist_btn);
1966 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1967 _("Reply to Mailing-list"));
1968 toolbar_data->replylist_btn = item;
1973 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1974 _("Forward Message"),
1975 _("Forward Message options"));
1976 toolbar_data->fwd_btn = item;
1978 MAKE_MENU(forward_entries,"<Forward>",toolbar_data->fwd_btn);
1980 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1981 _("Forward Message"));
1982 toolbar_data->fwd_btn = item;
1986 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
1987 toolbar_data->trash_btn = item;
1990 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
1991 toolbar_data->delete_btn = item;
1994 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
1995 toolbar_data->exec_btn = item;
1998 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
1999 toolbar_data->prev_btn = item;
2002 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
2003 toolbar_data->next_btn = item;
2006 /* Compose Toolbar */
2008 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2009 toolbar_data->send_btn = item;
2012 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2013 toolbar_data->sendl_btn = item;
2016 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2017 toolbar_data->draft_btn = item;
2020 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2021 toolbar_data->insert_btn = item;
2024 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2025 toolbar_data->attach_btn = item;
2028 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2029 toolbar_data->sig_btn = item;
2032 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2033 toolbar_data->exteditor_btn = item;
2035 case A_LINEWRAP_CURRENT:
2036 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2037 toolbar_data->linewrap_current_btn = item;
2039 case A_LINEWRAP_ALL:
2040 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2041 toolbar_data->linewrap_all_btn = item;
2044 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2045 toolbar_data->addrbook_btn = item;
2048 case A_CHECK_SPELLING:
2049 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2050 toolbar_data->spellcheck_btn = item;
2054 case A_CLAWS_ACTIONS:
2055 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2056 action_item = g_new0(ToolbarClawsActions, 1);
2057 action_item->widget = item;
2058 action_item->name = g_strdup(toolbar_item->text);
2060 toolbar_data->action_list =
2061 g_slist_append(toolbar_data->action_list,
2065 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2066 toolbar_data->cancel_inc_btn = item;
2069 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2070 toolbar_ret_descr_from_val(toolbar_item->index));
2071 /* find and set the tool tip text */
2076 toolbar_data->toolbar = toolbar;
2078 toolbar_data->tooltips = toolbar_tips;
2080 gtk_widget_show_all(toolbar);
2082 if (type == TOOLBAR_MAIN) {
2084 MainWindow *mainwin = mainwindow_get_mainwindow();
2085 GtkWidget *progressbar = gtk_progress_bar_new();
2086 item = GTK_WIDGET(gtk_tool_item_new());
2087 gtk_container_add (GTK_CONTAINER (item), progressbar);
2088 gtk_widget_show(item);
2089 gtk_widget_show(progressbar);
2090 gtk_widget_set_size_request(progressbar, 70, -1);
2091 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2092 mainwin->progressbar = progressbar;
2094 activate_compose_button(toolbar_data,
2095 prefs_common.toolbar_style,
2096 toolbar_data->compose_btn_type);
2098 if (type != TOOLBAR_COMPOSE)
2099 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2103 gtk_container_add(GTK_CONTAINER(container), toolbar);
2104 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2106 if ( GTK_IS_WINDOW(container) ) {
2107 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
2108 gtk_widget_show_all (container);
2110 gtk_container_add(GTK_CONTAINER(container), toolbar);
2111 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2114 return toolbar_data;
2118 * Free toolbar structures
2120 void toolbar_destroy(Toolbar * toolbar) {
2122 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2123 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2126 void toolbar_update(ToolbarType type, gpointer data)
2128 Toolbar *toolbar_data;
2129 GtkWidget *handlebox;
2130 MainWindow *mainwin = (MainWindow*)data;
2131 Compose *compose = (Compose*)data;
2132 MessageView *msgview = (MessageView*)data;
2137 toolbar_data = mainwin->toolbar;
2138 handlebox = mainwin->handlebox;
2140 case TOOLBAR_COMPOSE:
2141 toolbar_data = compose->toolbar;
2142 handlebox = compose->handlebox;
2144 case TOOLBAR_MSGVIEW:
2145 toolbar_data = msgview->toolbar;
2146 handlebox = msgview->handlebox;
2152 gtk_container_remove(GTK_CONTAINER(handlebox),
2153 GTK_WIDGET(toolbar_data->toolbar));
2155 toolbar_init(toolbar_data);
2156 toolbar_data = toolbar_create(type, handlebox, data);
2160 toolbar_data = mainwin->toolbar;
2161 handlebox = mainwin->window;
2163 case TOOLBAR_COMPOSE:
2164 toolbar_data = compose->toolbar;
2165 handlebox = compose->window;
2167 case TOOLBAR_MSGVIEW:
2168 toolbar_data = msgview->toolbar;
2169 handlebox = msgview->window;
2175 hildon_window_remove_toolbar(HILDON_WINDOW(handlebox), GTK_TOOLBAR(toolbar_data->toolbar));
2177 toolbar_init(toolbar_data);
2178 toolbar_data = toolbar_create(type, handlebox, data);
2183 mainwin->toolbar = toolbar_data;
2185 case TOOLBAR_COMPOSE:
2186 compose->toolbar = toolbar_data;
2188 case TOOLBAR_MSGVIEW:
2189 msgview->toolbar = toolbar_data;
2193 toolbar_style(type, prefs_common.toolbar_style, data);
2195 if (type == TOOLBAR_MAIN) {
2196 toolbar_main_set_sensitive((MainWindow*)data);
2197 account_set_menu_only_toolbar();
2201 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2202 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2203 if (GTK_IS_BUTTON(widget)) \
2204 in_btn1 = GTK_BUTTON(widget)->in_button; \
2205 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2206 GtkWidget *child = gtk_bin_get_child( \
2208 GList *gchild = gtk_container_get_children( \
2209 GTK_CONTAINER(child)); \
2210 GtkWidget *btn = (GtkWidget *)gchild->data; \
2211 GtkWidget *arr = (GtkWidget *) \
2212 (gchild->next?gchild->next->data:NULL); \
2213 g_list_free(gchild); \
2214 if (GTK_IS_BUTTON(btn)) \
2215 in_btn1 = GTK_BUTTON(btn)->in_button; \
2216 if (GTK_IS_BUTTON(arr)) \
2217 in_btn2 = GTK_BUTTON(arr)->in_button; \
2219 else if (GTK_IS_TOOL_ITEM(widget)) { \
2220 GtkWidget *child = gtk_bin_get_child( \
2222 if (GTK_IS_BUTTON(child)) \
2223 in_btn1 = GTK_BUTTON(child)->in_button; \
2225 gtk_widget_set_sensitive(widget, sensitive); \
2226 if (GTK_IS_BUTTON(widget)) \
2227 GTK_BUTTON(widget)->in_button = in_btn1; \
2228 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2229 GtkWidget *child = gtk_bin_get_child( \
2231 GList *gchild = gtk_container_get_children( \
2232 GTK_CONTAINER(child)); \
2233 GtkWidget *btn = (GtkWidget *)gchild->data; \
2234 GtkWidget *arr = (GtkWidget *) \
2235 (gchild->next?gchild->next->data:NULL); \
2236 g_list_free(gchild); \
2237 if (GTK_IS_BUTTON(btn)) \
2238 GTK_BUTTON(btn)->in_button = in_btn1; \
2239 if (GTK_IS_BUTTON(arr)) \
2240 GTK_BUTTON(arr)->in_button = in_btn2; \
2242 else if (GTK_IS_TOOL_ITEM(widget)) { \
2243 GtkWidget *child = gtk_bin_get_child( \
2245 if (GTK_IS_BUTTON(child)) \
2246 GTK_BUTTON(child)->in_button = in_btn1; \
2250 void toolbar_main_set_sensitive(gpointer data)
2252 SensitiveCond state;
2254 MainWindow *mainwin = (MainWindow*)data;
2255 Toolbar *toolbar = mainwin->toolbar;
2257 GSList *entry_list = NULL;
2259 typedef struct _Entry Entry;
2266 #define SET_WIDGET_COND(w, c) \
2268 Entry *e = g_new0(Entry, 1); \
2271 entry_list = g_slist_append(entry_list, e); \
2275 if (toolbar->get_btn)
2276 SET_WIDGET_COND(toolbar->get_btn,
2277 M_HAVE_ACCOUNT|M_UNLOCKED);
2279 if (toolbar->getall_btn) {
2280 SET_WIDGET_COND(toolbar->getall_btn,
2281 M_HAVE_ACCOUNT|M_UNLOCKED);
2283 if (toolbar->send_btn) {
2284 SET_WIDGET_COND(toolbar->send_btn,
2285 M_HAVE_QUEUED_MAILS);
2287 if (toolbar->compose_mail_btn) {
2288 SET_WIDGET_COND(toolbar->compose_mail_btn,
2291 if (toolbar->close_window_btn) {
2292 SET_WIDGET_COND(toolbar->close_window_btn,
2295 if (toolbar->open_mail_btn) {
2296 SET_WIDGET_COND(toolbar->open_mail_btn,
2297 M_TARGET_EXIST|M_SUMMARY_ISLIST);
2299 if (toolbar->reply_btn) {
2300 SET_WIDGET_COND(toolbar->reply_btn,
2301 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2303 if (toolbar->replyall_btn) {
2304 SET_WIDGET_COND(toolbar->replyall_btn,
2305 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2307 if (toolbar->replylist_btn) {
2308 SET_WIDGET_COND(toolbar->replylist_btn,
2309 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2311 if (toolbar->replysender_btn) {
2312 SET_WIDGET_COND(toolbar->replysender_btn,
2313 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2315 if (toolbar->fwd_btn) {
2316 SET_WIDGET_COND(toolbar->fwd_btn,
2317 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2320 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2321 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST|M_SUMMARY_ISLIST);
2323 SET_WIDGET_COND(toolbar->next_btn, 0);
2326 if (toolbar->trash_btn)
2327 SET_WIDGET_COND(toolbar->trash_btn,
2328 M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS);
2330 if (toolbar->delete_btn)
2331 SET_WIDGET_COND(toolbar->delete_btn,
2332 M_TARGET_EXIST|M_ALLOW_DELETE);
2334 if (toolbar->exec_btn)
2335 SET_WIDGET_COND(toolbar->exec_btn,
2338 if (toolbar->learn_spam_btn)
2339 SET_WIDGET_COND(toolbar->learn_spam_btn,
2340 M_TARGET_EXIST|M_CAN_LEARN_SPAM|M_SUMMARY_ISLIST);
2342 if (toolbar->cancel_inc_btn)
2343 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2346 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2347 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2349 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2352 #undef SET_WIDGET_COND
2354 state = main_window_get_current_state(mainwin);
2356 for (cur = entry_list; cur != NULL; cur = cur->next) {
2357 Entry *e = (Entry*) cur->data;
2359 if (e->widget != NULL) {
2360 sensitive = ((e->cond & state) == e->cond);
2361 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2365 while (entry_list != NULL) {
2366 Entry *e = (Entry*) entry_list->data;
2369 entry_list = g_slist_remove(entry_list, e);
2372 g_slist_free(entry_list);
2374 activate_compose_button(toolbar,
2375 prefs_common.toolbar_style,
2376 toolbar->compose_btn_type);
2380 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2382 Compose *compose = (Compose*)data;
2383 GSList *items = compose->toolbar->action_list;
2385 if (compose->toolbar->send_btn)
2386 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2387 if (compose->toolbar->sendl_btn)
2388 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2389 if (compose->toolbar->draft_btn )
2390 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2391 if (compose->toolbar->insert_btn )
2392 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2393 if (compose->toolbar->attach_btn)
2394 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2395 if (compose->toolbar->sig_btn)
2396 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2397 if (compose->toolbar->exteditor_btn)
2398 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2399 if (compose->toolbar->linewrap_current_btn)
2400 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2401 if (compose->toolbar->linewrap_all_btn)
2402 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2403 if (compose->toolbar->addrbook_btn)
2404 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2406 if (compose->toolbar->spellcheck_btn)
2407 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2409 for (; items != NULL; items = g_slist_next(items)) {
2410 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2411 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2416 * Initialize toolbar structure
2418 static void toolbar_init(Toolbar * toolbar)
2421 toolbar->toolbar = NULL;
2422 toolbar->folders_btn = NULL;
2423 toolbar->get_btn = NULL;
2424 toolbar->getall_btn = NULL;
2425 toolbar->send_btn = NULL;
2426 toolbar->compose_mail_btn = NULL;
2427 toolbar->compose_mail_icon = NULL;
2428 toolbar->compose_news_icon = NULL;
2429 toolbar->reply_btn = NULL;
2430 toolbar->replysender_btn = NULL;
2431 toolbar->replyall_btn = NULL;
2432 toolbar->replylist_btn = NULL;
2433 toolbar->fwd_btn = NULL;
2434 toolbar->trash_btn = NULL;
2435 toolbar->delete_btn = NULL;
2436 toolbar->prev_btn = NULL;
2437 toolbar->next_btn = NULL;
2438 toolbar->exec_btn = NULL;
2439 toolbar->open_mail_btn = NULL;
2440 toolbar->close_window_btn = NULL;
2441 /* compose buttons */
2442 toolbar->sendl_btn = NULL;
2443 toolbar->draft_btn = NULL;
2444 toolbar->insert_btn = NULL;
2445 toolbar->attach_btn = NULL;
2446 toolbar->sig_btn = NULL;
2447 toolbar->exteditor_btn = NULL;
2448 toolbar->linewrap_current_btn = NULL;
2449 toolbar->linewrap_all_btn = NULL;
2450 toolbar->addrbook_btn = NULL;
2452 toolbar->spellcheck_btn = NULL;
2455 toolbar_destroy(toolbar);
2460 static void toolbar_reply(gpointer data, guint action)
2462 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2463 MainWindow *mainwin;
2464 MessageView *msgview;
2465 GSList *msginfo_list = NULL;
2467 g_return_if_fail(toolbar_item != NULL);
2469 switch (toolbar_item->type) {
2471 mainwin = (MainWindow*)toolbar_item->parent;
2472 msginfo_list = summary_get_selection(mainwin->summaryview);
2473 msgview = (MessageView*)mainwin->messageview;
2475 case TOOLBAR_MSGVIEW:
2476 msgview = (MessageView*)toolbar_item->parent;
2477 g_return_if_fail(msgview != NULL);
2478 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2484 g_return_if_fail(msgview != NULL);
2485 g_return_if_fail(msginfo_list != NULL);
2486 compose_reply_from_messageview(msgview, msginfo_list, action);
2487 g_slist_free(msginfo_list);
2489 /* TODO: update reply state ion summaryview */
2493 /* exported functions */
2495 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2497 MainWindow *mainwin = (MainWindow*)data;
2499 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2502 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2504 MainWindow *mainwin = (MainWindow*)data;
2506 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2509 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2513 gboolean got_error = FALSE;
2514 gchar *errstr = NULL;
2516 if (prefs_common.work_offline)
2517 if (alertpanel(_("Offline warning"),
2518 _("You're working offline. Override?"),
2519 GTK_STOCK_NO, GTK_STOCK_YES,
2520 NULL) != G_ALERTALTERNATE)
2523 /* ask for confirmation before sending queued messages only
2524 in online mode and if there is at least one message queued
2525 in any of the folder queue
2527 if (prefs_common.confirm_send_queued_messages) {
2529 /* check if there's a queued message */
2530 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2531 Folder *folder = list->data;
2533 found = !procmsg_queue_is_empty(folder->queue);
2535 /* if necessary, ask for confirmation before sending */
2536 if (found && !prefs_common.work_offline) {
2537 if (alertpanel(_("Send queued messages"),
2538 _("Send all queued messages?"),
2539 GTK_STOCK_CANCEL, _("_Send"),
2540 NULL) != G_ALERTALTERNATE)
2545 for (list = folder_get_list(); list != NULL; list = list->next) {
2546 Folder *folder = list->data;
2548 if (folder->queue) {
2549 if (procmsg_send_queue(folder->queue,
2550 prefs_common.savemsg,
2557 alertpanel_error_log(_("Some errors occurred while "
2558 "sending queued messages."));
2560 alertpanel_error_log(_("Some errors occurred "
2561 "while sending queued messages:\n%s"), errstr);
2567 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2569 MainWindow *mainwin = (MainWindow*)data;
2570 PrefsAccount *ac = NULL;
2571 FolderItem *item = mainwin->summaryview->folder_item;
2576 ac = account_find_from_item(item);
2577 if (ac && ac->protocol != A_NNTP) {
2578 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2584 * CLAWS - use current account
2586 if (cur_account && (cur_account->protocol != A_NNTP)) {
2587 compose_new_with_folderitem(cur_account, item, NULL);
2592 * CLAWS - just get the first one
2594 list = account_get_list();
2595 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2596 ac = (PrefsAccount *) cur->data;
2597 if (ac->protocol != A_NNTP) {
2598 compose_new_with_folderitem(ac, item, NULL);
2604 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2606 MainWindow *mainwin = (MainWindow*)data;
2607 PrefsAccount * ac = NULL;
2611 if (mainwin->summaryview->folder_item) {
2612 ac = mainwin->summaryview->folder_item->folder->account;
2613 if (ac && ac->protocol == A_NNTP) {
2614 compose_new_with_folderitem(ac,
2615 mainwin->summaryview->folder_item, NULL);
2620 list = account_get_list();
2621 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2622 ac = (PrefsAccount *) cur->data;
2623 if (ac->protocol == A_NNTP) {
2624 compose_new_with_folderitem(ac,
2625 mainwin->summaryview->folder_item, NULL);