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_preferences_cb (GtkWidget *widget,
151 static void toolbar_open_mail_cb (GtkWidget *widget,
153 static void toolbar_insert_cb (GtkWidget *widget,
155 static void toolbar_attach_cb (GtkWidget *widget,
157 static void toolbar_sig_cb (GtkWidget *widget,
159 static void toolbar_ext_editor_cb (GtkWidget *widget,
161 static void toolbar_linewrap_current_cb (GtkWidget *widget,
163 static void toolbar_linewrap_all_cb (GtkWidget *widget,
165 static void toolbar_addrbook_cb (GtkWidget *widget,
168 static void toolbar_check_spelling_cb (GtkWidget *widget,
171 static void toolbar_cancel_inc_cb (GtkWidget *widget,
177 } toolbar_text [] = {
178 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
179 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
180 { "A_SEND_QUEUED", N_("Send Queued Messages") },
181 { "A_COMPOSE_EMAIL", N_("Compose Email") },
182 { "A_COMPOSE_NEWS", N_("Compose News") },
183 { "A_REPLY_MESSAGE", N_("Reply to Message") },
184 { "A_REPLY_SENDER", N_("Reply to Sender") },
185 { "A_REPLY_ALL", N_("Reply to All") },
186 { "A_REPLY_ML", N_("Reply to Mailing-list") },
187 { "A_OPEN_MAIL", N_("Open email") },
188 { "A_FORWARD", N_("Forward Message") },
189 { "A_TRASH", N_("Trash Message") },
190 { "A_DELETE_REAL", N_("Delete Message") },
191 { "A_EXECUTE", N_("Execute") },
192 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
193 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
194 { "A_IGNORE_THREAD", N_("Ignore thread") },
195 { "A_WATCH_THREAD", N_("Watch thread") },
196 { "A_PRINT", N_("Print") },
197 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
198 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
199 { "A_PREFERENCES", N_("Preferences") },
201 { "A_SEND", N_("Send Message") },
202 { "A_SENDL", N_("Put into queue folder and send later") },
203 { "A_DRAFT", N_("Save to draft folder") },
204 { "A_INSERT", N_("Insert file") },
205 { "A_ATTACH", N_("Attach file") },
206 { "A_SIG", N_("Insert signature") },
207 { "A_EXTEDITOR", N_("Edit with external editor") },
208 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
209 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
210 { "A_ADDRBOOK", N_("Address book") },
212 { "A_CHECK_SPELLING", N_("Check spelling") },
214 { "A_CLAWS_ACTIONS", N_("Claws Mail Actions Feature") },
215 { "A_CANCEL_INC", N_("Cancel receiving") },
216 { "A_CLOSE", N_("Close window") },
217 { "A_SEPARATOR", N_("Separator") }
220 /* struct holds configuration files and a list of
221 * currently active toolbar items
222 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
226 const gchar *conf_file;
228 } toolbar_config[3] = {
229 { "toolbar_main.xml", NULL},
230 { "toolbar_compose.xml", NULL},
231 { "toolbar_msgview.xml", NULL}
234 static GtkItemFactoryEntry reply_entries[] =
236 {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
237 {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
239 static GtkItemFactoryEntry replyall_entries[] =
241 {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
242 {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
244 static GtkItemFactoryEntry replylist_entries[] =
246 {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
247 {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
249 static GtkItemFactoryEntry replysender_entries[] =
251 {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
252 {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
254 static GtkItemFactoryEntry forward_entries[] =
256 {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
257 {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
258 {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, NULL}
261 static GtkItemFactoryEntry learn_entries[] =
263 {N_("/Learn as _Spam"), NULL, toolbar_learn, TRUE, NULL},
264 {N_("/Learn as _Ham"), NULL, toolbar_learn, FALSE, NULL}
268 gint toolbar_ret_val_from_descr(const gchar *descr)
272 for (i = 0; i < N_ACTION_VAL; i++) {
273 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
280 gchar *toolbar_ret_descr_from_val(gint val)
282 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
284 return gettext(toolbar_text[val].descr);
287 static gint toolbar_ret_val_from_text(const gchar *text)
291 for (i = 0; i < N_ACTION_VAL; i++) {
292 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
299 static gchar *toolbar_ret_text_from_val(gint val)
301 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
303 return toolbar_text[val].index_str;
306 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
310 if ((action == A_SEPARATOR) || (action == A_CLAWS_ACTIONS))
313 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
314 ToolbarItem *item = (ToolbarItem*) cur->data;
316 if (item->index == action)
322 /* depending on toolbar type this function
323 returns a list of available toolbar events being
324 displayed by prefs_toolbar
326 GList *toolbar_get_action_items(ToolbarType source)
331 if (source == TOOLBAR_MAIN) {
332 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
333 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
334 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
335 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
336 A_GOTO_NEXT, A_IGNORE_THREAD, A_WATCH_THREAD, A_PRINT,
337 A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
338 A_CANCEL_INC, A_PREFERENCES };
340 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
341 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
344 else if (source == TOOLBAR_COMPOSE) {
345 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
346 A_INSERT, A_ATTACH, A_SIG,
347 A_EXTEDITOR, A_LINEWRAP_CURRENT,
348 A_LINEWRAP_ALL, A_ADDRBOOK,
354 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
355 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
357 else if (source == TOOLBAR_MSGVIEW) {
358 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
359 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
360 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
361 A_ADDRBOOK, A_LEARN_SPAM, A_CLOSE };
363 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
364 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
370 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
374 ToolbarItem *item = NULL;
375 gboolean rewrite = FALSE;
377 attr = xml_get_current_tag_attr(file);
378 item = g_new0(ToolbarItem, 1);
380 name = ((XMLAttr *)attr->data)->name;
381 value = ((XMLAttr *)attr->data)->value;
383 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
384 item->file = g_strdup (value);
385 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
386 item->text = g_strdup (gettext(value));
387 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
388 item->index = toolbar_ret_val_from_text(value);
389 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
391 item->index = A_TRASH;
393 item->file = g_strdup("trash_btn");
395 item->text = g_strdup(_("Trash"));
398 if (item->index == -1 && !strcmp(value, "A_SYL_ACTIONS")) {
400 item->index = A_CLAWS_ACTIONS;
403 attr = g_list_next(attr);
405 if (item->index != -1) {
407 if (!toolbar_is_duplicate(item->index, source))
408 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
412 toolbar_save_config_file(source);
416 const gchar *toolbar_get_short_text(int action) {
418 case A_GO_FOLDERS: return _("Folders");
419 case A_OPEN_MAIL: return _("Open");
420 case A_RECEIVE_ALL: return _("Get Mail");
421 case A_RECEIVE_CUR: return _("Get");
422 case A_SEND_QUEUED: return _("Send");
423 case A_COMPOSE_EMAIL: return Q_("Toolbar|Compose");
424 case A_COMPOSE_NEWS: return Q_("Toolbar|Compose");
425 case A_REPLY_MESSAGE: return _("Reply");
426 case A_REPLY_ALL: return _("All");
427 case A_REPLY_SENDER: return _("Sender");
428 case A_REPLY_ML: return _("List");
429 case A_FORWARD: return _("Forward");
430 case A_TRASH: return _("Trash");
431 case A_DELETE_REAL: return _("Delete");
432 case A_LEARN_SPAM: return _("Spam");
433 case A_GOTO_PREV: return _("Prev");
434 case A_GOTO_NEXT: return _("Next");
435 case A_IGNORE_THREAD: return _("Ignore thread");
436 case A_WATCH_THREAD: return _("Watch thread");
437 case A_PRINT: return _("Print");
438 case A_CLOSE: return _("Close");
439 case A_PREFERENCES: return _("Preferences");
440 case A_SEND: return _("Send");
441 case A_SENDL: return _("Send later");
442 case A_DRAFT: return _("Draft");
443 case A_INSERT: return _("Insert");
444 case A_ATTACH: return _("Attach");
445 case A_SIG: return _("Insert sig.");
446 case A_EXTEDITOR: return _("Edit");
447 case A_LINEWRAP_CURRENT:return _("Wrap para.");
448 case A_LINEWRAP_ALL: return _("Wrap all");
449 case A_ADDRBOOK: return _("Address");
450 case A_CANCEL_INC: return _("Stop");
451 case A_EXECUTE: return _("Execute");
453 case A_CHECK_SPELLING: return _("Check spelling");
459 gint toolbar_get_icon(int action) {
461 case A_GO_FOLDERS: return STOCK_PIXMAP_GO_FOLDERS;
462 case A_OPEN_MAIL: return STOCK_PIXMAP_OPEN_MAIL;
463 case A_RECEIVE_ALL: return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
464 case A_RECEIVE_CUR: return STOCK_PIXMAP_MAIL_RECEIVE;
465 case A_SEND_QUEUED: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
466 case A_COMPOSE_EMAIL: return STOCK_PIXMAP_MAIL_COMPOSE;
467 case A_COMPOSE_NEWS: return STOCK_PIXMAP_NEWS_COMPOSE;
468 case A_REPLY_MESSAGE: return STOCK_PIXMAP_MAIL_REPLY;
469 case A_REPLY_ALL: return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
470 case A_REPLY_SENDER: return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
471 case A_REPLY_ML: return STOCK_PIXMAP_MAIL_REPLY;
472 case A_FORWARD: return STOCK_PIXMAP_MAIL_FORWARD;
473 case A_TRASH: return STOCK_PIXMAP_TRASH;
474 case A_DELETE_REAL: return STOCK_PIXMAP_DELETED;
475 case A_LEARN_SPAM: return STOCK_PIXMAP_SPAM_BTN;
476 case A_GOTO_PREV: return STOCK_PIXMAP_UP_ARROW;
477 case A_GOTO_NEXT: return STOCK_PIXMAP_DOWN_ARROW;
478 case A_IGNORE_THREAD: return STOCK_PIXMAP_IGNORETHREAD;
479 case A_WATCH_THREAD: return STOCK_PIXMAP_WATCHTHREAD;
480 case A_PRINT: return STOCK_PIXMAP_PRINTER;
481 case A_CLOSE: return STOCK_PIXMAP_CLOSE;
482 case A_PREFERENCES: return STOCK_PIXMAP_PREFERENCES;
483 case A_SEND: return STOCK_PIXMAP_MAIL_SEND;
484 case A_SENDL: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
485 case A_DRAFT: return STOCK_PIXMAP_MAIL;
486 case A_INSERT: return STOCK_PIXMAP_INSERT_FILE;
487 case A_ATTACH: return STOCK_PIXMAP_MAIL_ATTACH;
488 case A_SIG: return STOCK_PIXMAP_MAIL_SIGN;
489 case A_EXTEDITOR: return STOCK_PIXMAP_EDIT_EXTERN;
490 case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
491 case A_LINEWRAP_ALL: return STOCK_PIXMAP_LINEWRAP_ALL;
492 case A_ADDRBOOK: return STOCK_PIXMAP_ADDRESS_BOOK;
493 case A_CANCEL_INC: return STOCK_PIXMAP_CLOSE;
494 case A_EXECUTE: return STOCK_PIXMAP_EXEC;
496 case A_CHECK_SPELLING: return STOCK_PIXMAP_CHECK_SPELLING;
502 static void toolbar_set_default_main(void)
506 } default_toolbar[] = {
526 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
536 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
538 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
540 if (default_toolbar[i].action != A_SEPARATOR) {
542 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
544 toolbar_item->file = g_strdup(file);
545 toolbar_item->index = default_toolbar[i].action;
546 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
549 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
550 toolbar_item->index = A_SEPARATOR;
553 if (toolbar_item->index != -1) {
554 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
555 toolbar_config[TOOLBAR_MAIN].item_list =
556 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
561 static void toolbar_set_default_compose(void)
565 } default_toolbar[] = {
584 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
586 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
588 if (default_toolbar[i].action != A_SEPARATOR) {
590 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
592 toolbar_item->file = g_strdup(file);
593 toolbar_item->index = default_toolbar[i].action;
594 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
597 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
598 toolbar_item->index = A_SEPARATOR;
601 if (toolbar_item->index != -1) {
602 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
603 toolbar_config[TOOLBAR_COMPOSE].item_list =
604 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
609 static void toolbar_set_default_msgview(void)
613 } default_toolbar[] = {
625 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
634 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
636 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
638 if (default_toolbar[i].action != A_SEPARATOR) {
640 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
642 toolbar_item->file = g_strdup(file);
643 toolbar_item->index = default_toolbar[i].action;
644 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
647 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
648 toolbar_item->index = A_SEPARATOR;
651 if (toolbar_item->index != -1) {
652 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
653 toolbar_config[TOOLBAR_MSGVIEW].item_list =
654 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
659 void toolbar_set_default(ToolbarType source)
661 if (source == TOOLBAR_MAIN)
662 toolbar_set_default_main();
663 else if (source == TOOLBAR_COMPOSE)
664 toolbar_set_default_compose();
665 else if (source == TOOLBAR_MSGVIEW)
666 toolbar_set_default_msgview();
669 void toolbar_save_config_file(ToolbarType source)
674 gchar *fileSpec = NULL;
676 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
678 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
679 pfile = prefs_write_open(fileSpec);
682 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
685 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
688 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
689 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
691 if (toolbar_item->index != A_SEPARATOR) {
692 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
694 TOOLBAR_ICON_FILE, toolbar_item->file,
695 TOOLBAR_ICON_TEXT) < 0)
697 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
699 if (fprintf(fp, "\" %s=\"%s\"/>\n",
701 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
704 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
709 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
713 if (prefs_file_close (pfile) < 0 )
714 g_warning("failed to write toolbar configuration to file\n");
718 FILE_OP_ERROR(fileSpec, "fprintf");
720 prefs_file_close_revert (pfile);
722 g_warning("failed to open toolbar configuration file for writing\n");
725 void toolbar_read_config_file(ToolbarType source)
727 XMLFile *file = NULL;
728 gchar *fileSpec = NULL;
733 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
735 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
736 file = xml_open_file(fileSpec);
739 toolbar_clear_list(source);
743 || (xml_get_dtd(file))
744 || (xml_parse_next_tag(file))
745 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
746 xml_close_file(file);
750 attr = xml_get_current_tag_attr(file);
757 if (xml_parse_next_tag(file))
760 /* Get next tag (icon, icon_text or icon_action) */
761 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
762 toolbar_parse_item(file, source);
763 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
764 ToolbarItem *item = g_new0(ToolbarItem, 1);
766 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
767 item->index = A_SEPARATOR;
768 toolbar_config[source].item_list =
769 g_slist_append(toolbar_config[source].item_list, item);
773 xml_close_file(file);
776 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
778 if (source == TOOLBAR_MAIN)
779 toolbar_set_default(TOOLBAR_MAIN);
780 else if (source == TOOLBAR_COMPOSE)
781 toolbar_set_default(TOOLBAR_COMPOSE);
782 else if (source == TOOLBAR_MSGVIEW)
783 toolbar_set_default(TOOLBAR_MSGVIEW);
785 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
789 toolbar_save_config_file(source);
794 * clears list of toolbar items read from configuration files
796 void toolbar_clear_list(ToolbarType source)
798 while (toolbar_config[source].item_list != NULL) {
799 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
801 toolbar_config[source].item_list =
802 g_slist_remove(toolbar_config[source].item_list, item);
808 g_slist_free(toolbar_config[source].item_list);
813 * return list of Toolbar items
815 GSList *toolbar_get_list(ToolbarType source)
819 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
820 list = toolbar_config[source].item_list;
825 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
827 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
829 toolbar_item->file = g_strdup(t_item->file);
830 toolbar_item->text = g_strdup(t_item->text);
831 toolbar_item->index = t_item->index;
833 toolbar_config[source].item_list =
834 g_slist_append(toolbar_config[source].item_list,
838 static void toolbar_action_execute(GtkWidget *widget,
844 gchar *action, *action_p;
845 gboolean found = FALSE;
848 for (cur = action_list; cur != NULL; cur = cur->next) {
849 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
851 if (widget == act->widget) {
853 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
854 action = g_strdup((gchar*)lop->data);
856 action_p = strstr(action, ": ");
858 if (g_utf8_collate(act->name, action) == 0) {
872 actions_execute(data, i, widget, source);
874 g_warning ("Error: did not find Claws Action to execute");
877 static void activate_compose_button (Toolbar *toolbar,
879 ComposeButtonType type)
881 if ((!toolbar->compose_mail_btn))
884 if (type == COMPOSEBUTTON_NEWS) {
885 gtk_tool_button_set_icon_widget(
886 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
887 toolbar->compose_news_icon);
889 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->compose_mail_btn), GTK_TOOLTIPS(toolbar->tooltips),
890 _("Compose News message"), NULL);
892 gtk_widget_show(toolbar->compose_news_icon);
894 gtk_tool_button_set_icon_widget(
895 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
896 toolbar->compose_mail_icon);
898 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->compose_mail_btn), GTK_TOOLTIPS(toolbar->tooltips),
899 _("Compose Email"), NULL);
901 gtk_widget_show(toolbar->compose_mail_icon);
903 toolbar->compose_btn_type = type;
906 void toolbar_set_compose_button(Toolbar *toolbar,
907 ComposeButtonType compose_btn_type)
909 if (toolbar->compose_btn_type != compose_btn_type)
910 activate_compose_button(toolbar,
911 prefs_common.toolbar_style,
915 static void activate_learn_button (Toolbar *toolbar,
917 LearnButtonType type)
919 if ((!toolbar->learn_spam_btn))
922 if (type == LEARN_SPAM) {
923 gtk_tool_button_set_icon_widget(
924 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
925 toolbar->learn_spam_icon);
926 gtk_tool_button_set_label(
927 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
930 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->learn_spam_btn), GTK_TOOLTIPS(toolbar->tooltips),
931 _("Learn spam"), NULL);
933 gtk_widget_show(toolbar->learn_spam_icon);
935 gtk_tool_button_set_icon_widget(
936 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
937 toolbar->learn_ham_icon);
938 gtk_tool_button_set_label(
939 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
942 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->learn_spam_btn), GTK_TOOLTIPS(toolbar->tooltips),
943 _("Learn ham"), NULL);
945 gtk_widget_show(toolbar->learn_ham_icon);
947 toolbar->learn_btn_type = type;
950 void toolbar_set_learn_button(Toolbar *toolbar,
951 LearnButtonType learn_btn_type)
953 if (toolbar->learn_btn_type != learn_btn_type)
954 activate_learn_button(toolbar,
955 prefs_common.toolbar_style,
959 void toolbar_toggle(guint action, gpointer data)
961 MainWindow *mainwin = (MainWindow*)data;
965 g_return_if_fail(mainwin != NULL);
967 toolbar_style(TOOLBAR_MAIN, action, mainwin);
969 list = compose_get_compose_list();
970 for (cur = list; cur != NULL; cur = cur->next) {
971 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
973 list = messageview_get_msgview_list();
974 for (cur = list; cur != NULL; cur = cur->next) {
975 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
980 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
982 switch ((ToolbarStyle)action) {
984 gtk_widget_hide(handlebox_wid);
987 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
991 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
995 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
998 case TOOLBAR_BOTH_HORIZ:
999 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1000 GTK_TOOLBAR_BOTH_HORIZ);
1006 prefs_common.toolbar_style = (ToolbarStyle)action;
1007 gtk_widget_set_size_request(handlebox_wid, 1, -1);
1009 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1010 gtk_widget_show(handlebox_wid);
1011 gtk_widget_queue_resize(handlebox_wid);
1015 * Change the style of toolbar
1017 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1019 GtkWidget *handlebox_wid;
1020 GtkWidget *toolbar_wid;
1021 MainWindow *mainwin = (MainWindow*)data;
1022 Compose *compose = (Compose*)data;
1023 MessageView *msgview = (MessageView*)data;
1025 g_return_if_fail(data != NULL);
1029 handlebox_wid = mainwin->handlebox;
1030 toolbar_wid = mainwin->toolbar->toolbar;
1032 case TOOLBAR_COMPOSE:
1033 handlebox_wid = compose->handlebox;
1034 toolbar_wid = compose->toolbar->toolbar;
1036 case TOOLBAR_MSGVIEW:
1037 handlebox_wid = msgview->handlebox;
1038 toolbar_wid = msgview->toolbar->toolbar;
1044 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1047 /* Toolbar handling */
1048 static void toolbar_inc_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_mail_cb(mainwin, 0, NULL);
1066 static void toolbar_inc_all_cb(GtkWidget *widget,
1069 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1070 MainWindow *mainwin;
1072 g_return_if_fail(toolbar_item != NULL);
1074 switch (toolbar_item->type) {
1076 mainwin = (MainWindow*)toolbar_item->parent;
1077 inc_all_account_mail_cb(mainwin, 0, NULL);
1084 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1086 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1087 MainWindow *mainwin;
1089 g_return_if_fail(toolbar_item != NULL);
1091 switch (toolbar_item->type) {
1093 mainwin = (MainWindow*)toolbar_item->parent;
1094 send_queue_cb(mainwin, 0, NULL);
1101 static void toolbar_exec_cb(GtkWidget *widget,
1104 MainWindow *mainwin = get_mainwin(data);
1106 g_return_if_fail(mainwin != NULL);
1107 summary_execute(mainwin->summaryview);
1111 * Delete current/selected(s) message(s)
1113 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1115 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1116 MainWindow *mainwin;
1118 g_return_if_fail(toolbar_item != NULL);
1119 g_return_if_fail(toolbar_item->parent);
1121 switch (toolbar_item->type) {
1122 case TOOLBAR_MSGVIEW:
1123 messageview_delete((MessageView *)toolbar_item->parent);
1126 mainwin = (MainWindow *)toolbar_item->parent;
1127 summary_delete_trash(mainwin->summaryview);
1130 debug_print("toolbar event not supported\n");
1136 * Delete current/selected(s) message(s)
1138 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1140 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1141 MainWindow *mainwin;
1143 g_return_if_fail(toolbar_item != NULL);
1144 g_return_if_fail(toolbar_item->parent);
1146 switch (toolbar_item->type) {
1147 case TOOLBAR_MSGVIEW:
1148 messageview_delete((MessageView *)toolbar_item->parent);
1151 mainwin = (MainWindow *)toolbar_item->parent;
1152 summary_delete(mainwin->summaryview);
1155 debug_print("toolbar event not supported\n");
1162 * Compose new message
1164 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1166 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1167 MainWindow *mainwin;
1168 MessageView *msgview;
1170 g_return_if_fail(toolbar_item != NULL);
1172 switch (toolbar_item->type) {
1174 mainwin = (MainWindow*)toolbar_item->parent;
1175 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1176 compose_news_cb(mainwin, 0, NULL);
1178 compose_mail_cb(mainwin, 0, NULL);
1180 case TOOLBAR_MSGVIEW:
1181 msgview = (MessageView*)toolbar_item->parent;
1182 compose_new_with_folderitem(NULL,
1183 msgview->msginfo->folder, NULL);
1186 debug_print("toolbar event not supported\n");
1190 static void toolbar_learn(gpointer data, guint as_spam)
1192 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1193 MainWindow *mainwin;
1194 MessageView *msgview;
1196 g_return_if_fail(toolbar_item != NULL);
1198 switch (toolbar_item->type) {
1200 mainwin = (MainWindow*)toolbar_item->parent;
1202 mainwindow_learn(mainwin, TRUE);
1204 mainwindow_learn(mainwin, FALSE);
1206 case TOOLBAR_MSGVIEW:
1207 msgview = (MessageView*)toolbar_item->parent;
1209 messageview_learn(msgview, TRUE);
1211 messageview_learn(msgview, FALSE);
1214 debug_print("toolbar event not supported\n");
1218 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1220 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1221 MainWindow *mainwin;
1222 MessageView *msgview;
1224 g_return_if_fail(toolbar_item != NULL);
1226 switch (toolbar_item->type) {
1228 mainwin = (MainWindow*)toolbar_item->parent;
1229 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1230 mainwindow_learn(mainwin, TRUE);
1232 mainwindow_learn(mainwin, FALSE);
1234 case TOOLBAR_MSGVIEW:
1235 msgview = (MessageView*)toolbar_item->parent;
1236 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1237 messageview_learn(msgview, TRUE);
1239 messageview_learn(msgview, FALSE);
1242 debug_print("toolbar event not supported\n");
1250 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1252 toolbar_reply(data, prefs_common.reply_with_quote ?
1253 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1258 * Reply message to Sender and All recipients
1260 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1263 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1264 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1269 * Reply to Mailing List
1271 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1274 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1275 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1280 * Reply to sender of message
1282 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1285 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1286 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1292 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1294 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1297 g_return_if_fail(toolbar_item != NULL);
1299 switch (toolbar_item->type) {
1301 case TOOLBAR_MSGVIEW:
1304 case TOOLBAR_COMPOSE:
1305 compose = (Compose *)toolbar_item->parent;
1310 addressbook_open(compose);
1315 * Forward current/selected(s) message(s)
1317 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1319 toolbar_reply(data, COMPOSE_FORWARD);
1323 * Goto Prev Unread Message
1325 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1327 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1328 MainWindow *mainwin;
1329 MessageView *msgview;
1331 g_return_if_fail(toolbar_item != NULL);
1333 switch (toolbar_item->type) {
1335 mainwin = (MainWindow*)toolbar_item->parent;
1336 summary_select_prev_unread(mainwin->summaryview);
1339 case TOOLBAR_MSGVIEW:
1340 msgview = (MessageView*)toolbar_item->parent;
1341 msgview->updating = TRUE;
1342 summary_select_prev_unread(msgview->mainwin->summaryview);
1343 msgview->updating = FALSE;
1345 if (msgview->deferred_destroy) {
1346 debug_print("messageview got away!\n");
1347 messageview_destroy(msgview);
1351 /* Now we need to update the messageview window */
1352 if (msgview->mainwin->summaryview->selected) {
1353 #ifndef GENERIC_UMPC
1354 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1357 messageview_show(msgview, msginfo,
1358 msgview->all_headers);
1361 gtk_widget_destroy(msgview->window);
1365 debug_print("toolbar event not supported\n");
1370 * Goto Next Unread Message
1372 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1374 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1375 MainWindow *mainwin;
1376 MessageView *msgview;
1378 g_return_if_fail(toolbar_item != NULL);
1380 switch (toolbar_item->type) {
1382 mainwin = (MainWindow*)toolbar_item->parent;
1383 summary_select_next_unread(mainwin->summaryview);
1386 case TOOLBAR_MSGVIEW:
1387 msgview = (MessageView*)toolbar_item->parent;
1388 msgview->updating = TRUE;
1389 summary_select_next_unread(msgview->mainwin->summaryview);
1390 msgview->updating = FALSE;
1392 if (msgview->deferred_destroy) {
1393 debug_print("messageview got away!\n");
1394 messageview_destroy(msgview);
1398 /* Now we need to update the messageview window */
1399 if (msgview->mainwin->summaryview->selected) {
1400 #ifndef GENERIC_UMPC
1401 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1404 messageview_show(msgview, msginfo,
1405 msgview->all_headers);
1408 gtk_widget_destroy(msgview->window);
1412 debug_print("toolbar event not supported\n");
1416 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1418 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1419 MainWindow *mainwin;
1421 g_return_if_fail(toolbar_item != NULL);
1423 switch (toolbar_item->type) {
1425 mainwin = (MainWindow *) toolbar_item->parent;
1426 summary_toggle_ignore_thread(mainwin->summaryview);
1428 case TOOLBAR_MSGVIEW:
1429 /* TODO: see toolbar_next_unread_cb() if you need
1430 * this in the message view */
1433 debug_print("toolbar event not supported\n");
1438 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1440 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1441 MainWindow *mainwin;
1443 g_return_if_fail(toolbar_item != NULL);
1445 switch (toolbar_item->type) {
1447 mainwin = (MainWindow *) toolbar_item->parent;
1448 summary_toggle_watch_thread(mainwin->summaryview);
1450 case TOOLBAR_MSGVIEW:
1451 /* TODO: see toolbar_next_unread_cb() if you need
1452 * this in the message view */
1455 debug_print("toolbar event not supported\n");
1460 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1462 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1464 g_return_if_fail(toolbar_item != NULL);
1470 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1472 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1473 MainWindow *mainwin;
1475 g_return_if_fail(toolbar_item != NULL);
1477 switch (toolbar_item->type) {
1479 mainwin = (MainWindow *) toolbar_item->parent;
1480 summary_print(mainwin->summaryview);
1482 case TOOLBAR_MSGVIEW:
1483 /* TODO: see toolbar_next_unread_cb() if you need
1484 * this in the message view */
1487 debug_print("toolbar event not supported\n");
1492 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1494 compose_toolbar_cb(A_SEND, data);
1497 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1499 compose_toolbar_cb(A_SENDL, data);
1502 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1504 compose_toolbar_cb(A_DRAFT, data);
1507 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1509 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1510 MainWindow *mainwin;
1511 MessageView *messageview;
1514 g_return_if_fail(toolbar_item != NULL);
1516 switch (toolbar_item->type) {
1518 mainwin = (MainWindow *) toolbar_item->parent;
1519 app_will_exit(NULL, mainwin);
1521 case TOOLBAR_MSGVIEW:
1522 messageview = (MessageView *)toolbar_item->parent;
1523 messageview_destroy(messageview);
1525 case TOOLBAR_COMPOSE:
1526 compose = (Compose *)toolbar_item->parent;
1527 compose_close_toolbar(compose);
1532 static void toolbar_preferences_cb(GtkWidget *widget, gpointer data)
1537 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1539 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1540 MainWindow *mainwin;
1542 g_return_if_fail(toolbar_item != NULL);
1544 switch (toolbar_item->type) {
1546 mainwin = (MainWindow *) toolbar_item->parent;
1547 summary_open_row(NULL, mainwin->summaryview);
1549 case TOOLBAR_MSGVIEW:
1550 debug_print("toolbar event not supported\n");
1552 case TOOLBAR_COMPOSE:
1553 debug_print("toolbar event not supported\n");
1558 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1560 compose_toolbar_cb(A_INSERT, data);
1563 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1565 compose_toolbar_cb(A_ATTACH, data);
1568 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1570 compose_toolbar_cb(A_SIG, data);
1573 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1575 compose_toolbar_cb(A_EXTEDITOR, data);
1578 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1580 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1583 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1585 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1589 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1591 compose_toolbar_cb(A_CHECK_SPELLING, data);
1595 * Execute actions from toolbar
1597 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1599 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1600 GSList *action_list;
1601 MainWindow *mainwin;
1603 MessageView *msgview;
1604 gpointer parent = toolbar_item->parent;
1606 g_return_if_fail(toolbar_item != NULL);
1608 switch (toolbar_item->type) {
1610 mainwin = (MainWindow*)parent;
1611 action_list = mainwin->toolbar->action_list;
1613 case TOOLBAR_COMPOSE:
1614 compose = (Compose*)parent;
1615 action_list = compose->toolbar->action_list;
1617 case TOOLBAR_MSGVIEW:
1618 msgview = (MessageView*)parent;
1619 action_list = msgview->toolbar->action_list;
1622 debug_print("toolbar event not supported\n");
1625 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1628 static MainWindow *get_mainwin(gpointer data)
1630 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1631 MainWindow *mainwin = NULL;
1632 MessageView *msgview;
1634 g_return_val_if_fail(toolbar_item != NULL, NULL);
1636 switch(toolbar_item->type) {
1638 mainwin = (MainWindow*)toolbar_item->parent;
1640 case TOOLBAR_MSGVIEW:
1641 msgview = (MessageView*)toolbar_item->parent;
1642 mainwin = (MainWindow*)msgview->mainwin;
1651 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1653 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1654 MainWindow *mainwin = NULL;
1655 switch(toolbar_item->type) {
1657 mainwin = (MainWindow*)toolbar_item->parent;
1660 g_warning("wrong toolbar type\n");
1664 if (!mainwin->in_folder) {
1665 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1667 folderview_select(mainwin->folderview, item);
1670 gtk_widget_grab_focus(mainwin->folderview->ctree);
1671 mainwindow_exit_folder(mainwin);
1675 static void toolbar_buttons_cb(GtkWidget *widget,
1682 void (*func)(GtkWidget *widget, gpointer data);
1684 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1685 { A_RECEIVE_CUR, toolbar_inc_cb },
1686 { A_SEND_QUEUED, toolbar_send_queued_cb },
1687 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1688 { A_COMPOSE_NEWS, toolbar_compose_cb },
1689 { A_REPLY_MESSAGE, toolbar_reply_cb },
1690 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1691 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1692 { A_REPLY_ML, toolbar_reply_to_list_cb },
1693 { A_FORWARD, toolbar_forward_cb },
1694 { A_TRASH, toolbar_trash_cb },
1695 { A_DELETE_REAL, toolbar_delete_cb },
1696 { A_EXECUTE, toolbar_exec_cb },
1697 { A_GOTO_PREV, toolbar_prev_unread_cb },
1698 { A_GOTO_NEXT, toolbar_next_unread_cb },
1699 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1700 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1701 { A_PRINT, toolbar_print_cb },
1702 { A_LEARN_SPAM, toolbar_learn_cb },
1703 { A_GO_FOLDERS, toolbar_go_folders_cb },
1705 { A_SEND, toolbar_send_cb },
1706 { A_SENDL, toolbar_send_later_cb },
1707 { A_DRAFT, toolbar_draft_cb },
1708 { A_OPEN_MAIL, toolbar_open_mail_cb },
1709 { A_CLOSE, toolbar_close_cb },
1710 { A_PREFERENCES, toolbar_preferences_cb },
1711 { A_INSERT, toolbar_insert_cb },
1712 { A_ATTACH, toolbar_attach_cb },
1713 { A_SIG, toolbar_sig_cb },
1714 { A_EXTEDITOR, toolbar_ext_editor_cb },
1715 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1716 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1717 { A_ADDRBOOK, toolbar_addrbook_cb },
1719 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1721 { A_CLAWS_ACTIONS, toolbar_actions_execute_cb },
1722 { A_CANCEL_INC, toolbar_cancel_inc_cb }
1725 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1727 for (i = 0; i < num_items; i++) {
1728 if (callbacks[i].index == item->index) {
1729 callbacks[i].func(widget, item);
1734 #ifndef GENERIC_UMPC
1735 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1736 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1737 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1738 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1739 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1740 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1741 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1745 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1746 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1747 GList *gchild = NULL; \
1748 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1749 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1750 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1751 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1752 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1753 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1755 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(item), \
1756 GTK_TOOLTIPS(toolbar_tips), menutip, NULL); \
1757 child = gtk_bin_get_child(GTK_BIN(item)); \
1758 gchild = gtk_container_get_children( \
1759 GTK_CONTAINER(child)); \
1760 btn = (GtkWidget *)gchild->data; \
1761 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1762 g_list_free(gchild); \
1763 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1764 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1765 g_list_free(gchild); \
1768 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1769 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1770 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1771 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1772 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1773 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1776 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1777 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1778 GList *gchild = NULL; \
1779 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1780 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1781 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1782 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1783 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1784 child = gtk_bin_get_child(GTK_BIN(item)); \
1785 gchild = gtk_container_get_children( \
1786 GTK_CONTAINER(child)); \
1787 btn = (GtkWidget *)gchild->data; \
1788 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1789 g_list_free(gchild); \
1790 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1791 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1792 g_list_free(gchild); \
1796 #define MAKE_MENU(entries,path,btn) { \
1797 n_menu_entries = sizeof(entries) / \
1798 sizeof(entries[0]); \
1799 menu = menu_create_items(entries, n_menu_entries, path, &factory, toolbar_item); \
1800 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(btn), menu); \
1804 * Create a new toolbar with specified type
1805 * if a callback list is passed it will be used before the
1806 * common callback list
1808 Toolbar *toolbar_create(ToolbarType type,
1809 GtkWidget *container,
1812 ToolbarItem *toolbar_item;
1815 GtkWidget *icon_wid = NULL;
1816 GtkWidget *icon_news;
1817 GtkWidget *icon_ham;
1820 guint n_menu_entries;
1821 GtkItemFactory *factory;
1822 ToolbarClawsActions *action_item;
1824 GSList *toolbar_list;
1825 Toolbar *toolbar_data;
1826 #ifndef GENERIC_UMPC
1827 GtkTooltips *toolbar_tips;
1829 toolbar_tips = gtk_tooltips_new();
1831 toolbar_read_config_file(type);
1832 toolbar_list = toolbar_get_list(type);
1834 toolbar_data = g_new0(Toolbar, 1);
1836 toolbar = gtk_toolbar_new();
1838 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1839 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1840 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1842 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1844 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1845 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1849 toolbar_item = g_new0(ToolbarItem, 1);
1850 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1851 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1852 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1853 toolbar_item->parent = data;
1854 toolbar_item->type = type;
1856 /* collect toolbar items in list to keep track */
1857 toolbar_data->item_list =
1858 g_slist_append(toolbar_data->item_list,
1860 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1862 switch (toolbar_item->index) {
1865 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1866 toolbar_data->folders_btn = item;
1869 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1870 _("Receive Mail on all Accounts"),
1871 _("Receive Mail on selected Account"));
1872 toolbar_data->getall_btn = item;
1875 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail on current Account"));
1876 toolbar_data->get_btn = item;
1879 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1880 toolbar_data->send_btn = item;
1883 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1884 toolbar_data->close_window_btn = item;
1887 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open preferences"));
1888 toolbar_data->preferences_btn = item;
1891 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1892 toolbar_data->open_mail_btn = item;
1894 case A_COMPOSE_EMAIL:
1895 #ifndef GENERIC_UMPC
1896 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1898 _("Compose with selected Account"));
1899 toolbar_data->compose_mail_btn = item;
1900 toolbar_data->compose_mail_icon = icon_wid;
1901 g_object_ref(toolbar_data->compose_mail_icon);
1903 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1904 toolbar_data->compose_news_icon = icon_news;
1905 g_object_ref(toolbar_data->compose_news_icon);
1907 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1908 _("Compose Email"));
1909 toolbar_data->compose_mail_btn = item;
1910 toolbar_data->compose_mail_icon = icon_wid;
1912 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1913 toolbar_data->compose_news_icon = icon_news;
1917 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1920 toolbar_data->learn_spam_btn = item;
1921 toolbar_data->learn_spam_icon = icon_wid;
1922 g_object_ref(toolbar_data->learn_spam_icon);
1924 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1925 toolbar_data->learn_ham_icon = icon_ham;
1926 g_object_ref(toolbar_data->learn_ham_icon);
1928 MAKE_MENU(learn_entries,"<LearnSpam>",toolbar_data->learn_spam_btn);
1930 case A_REPLY_MESSAGE:
1931 #ifndef GENERIC_UMPC
1932 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1933 _("Reply to Message"),
1934 _("Reply to Message options"));
1935 toolbar_data->reply_btn = item;
1937 MAKE_MENU(reply_entries,"<Reply>",toolbar_data->reply_btn);
1939 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1940 _("Reply to Message"));
1941 toolbar_data->reply_btn = item;
1944 case A_REPLY_SENDER:
1945 #ifndef GENERIC_UMPC
1946 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1947 _("Reply to Sender"),
1948 _("Reply to Sender options"));
1949 toolbar_data->replysender_btn = item;
1951 MAKE_MENU(replysender_entries,"<ReplySender>",toolbar_data->replysender_btn);
1953 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1954 _("Reply to Sender"));
1955 toolbar_data->replysender_btn = item;
1959 #ifndef GENERIC_UMPC
1960 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1962 _("Reply to All options"));
1963 toolbar_data->replyall_btn = item;
1965 MAKE_MENU(replyall_entries,"<ReplyAll>",toolbar_data->replyall_btn);
1967 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1969 toolbar_data->replyall_btn = item;
1973 #ifndef GENERIC_UMPC
1974 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1975 _("Reply to Mailing-list"),
1976 _("Reply to Mailing-list options"));
1977 toolbar_data->replylist_btn = item;
1979 MAKE_MENU(replylist_entries,"<ReplyList>",toolbar_data->replylist_btn);
1981 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1982 _("Reply to Mailing-list"));
1983 toolbar_data->replylist_btn = item;
1987 #ifndef GENERIC_UMPC
1988 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1989 _("Forward Message"),
1990 _("Forward Message options"));
1991 toolbar_data->fwd_btn = item;
1993 MAKE_MENU(forward_entries,"<Forward>",toolbar_data->fwd_btn);
1995 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1996 _("Forward Message"));
1997 toolbar_data->fwd_btn = item;
2001 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
2002 toolbar_data->trash_btn = item;
2005 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
2006 toolbar_data->delete_btn = item;
2009 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
2010 toolbar_data->exec_btn = item;
2013 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
2014 toolbar_data->prev_btn = item;
2017 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
2018 toolbar_data->next_btn = item;
2021 /* Compose Toolbar */
2023 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2024 toolbar_data->send_btn = item;
2027 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2028 toolbar_data->sendl_btn = item;
2031 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2032 toolbar_data->draft_btn = item;
2035 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2036 toolbar_data->insert_btn = item;
2039 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2040 toolbar_data->attach_btn = item;
2043 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2044 toolbar_data->sig_btn = item;
2047 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2048 toolbar_data->exteditor_btn = item;
2050 case A_LINEWRAP_CURRENT:
2051 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2052 toolbar_data->linewrap_current_btn = item;
2054 case A_LINEWRAP_ALL:
2055 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2056 toolbar_data->linewrap_all_btn = item;
2059 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2060 toolbar_data->addrbook_btn = item;
2063 case A_CHECK_SPELLING:
2064 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2065 toolbar_data->spellcheck_btn = item;
2069 case A_CLAWS_ACTIONS:
2070 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2071 action_item = g_new0(ToolbarClawsActions, 1);
2072 action_item->widget = item;
2073 action_item->name = g_strdup(toolbar_item->text);
2075 toolbar_data->action_list =
2076 g_slist_append(toolbar_data->action_list,
2080 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2081 toolbar_data->cancel_inc_btn = item;
2084 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2085 toolbar_ret_descr_from_val(toolbar_item->index));
2086 /* find and set the tool tip text */
2091 toolbar_data->toolbar = toolbar;
2092 #ifndef GENERIC_UMPC
2093 toolbar_data->tooltips = toolbar_tips;
2095 gtk_widget_show_all(toolbar);
2097 if (type == TOOLBAR_MAIN) {
2099 MainWindow *mainwin = mainwindow_get_mainwindow();
2100 GtkWidget *progressbar = gtk_progress_bar_new();
2101 item = GTK_WIDGET(gtk_tool_item_new());
2102 gtk_container_add (GTK_CONTAINER (item), progressbar);
2103 gtk_widget_show(item);
2104 gtk_widget_show(progressbar);
2105 gtk_widget_set_size_request(progressbar, 70, -1);
2106 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2107 mainwin->progressbar = progressbar;
2109 activate_compose_button(toolbar_data,
2110 prefs_common.toolbar_style,
2111 toolbar_data->compose_btn_type);
2113 if (type != TOOLBAR_COMPOSE)
2114 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2118 gtk_container_add(GTK_CONTAINER(container), toolbar);
2119 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2121 if ( GTK_IS_WINDOW(container) ) {
2122 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
2123 gtk_widget_show_all (container);
2125 gtk_container_add(GTK_CONTAINER(container), toolbar);
2126 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2129 return toolbar_data;
2133 * Free toolbar structures
2135 void toolbar_destroy(Toolbar * toolbar) {
2137 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2138 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2141 void toolbar_update(ToolbarType type, gpointer data)
2143 Toolbar *toolbar_data;
2144 GtkWidget *handlebox;
2145 MainWindow *mainwin = (MainWindow*)data;
2146 Compose *compose = (Compose*)data;
2147 MessageView *msgview = (MessageView*)data;
2149 #ifndef GENERIC_UMPC
2152 toolbar_data = mainwin->toolbar;
2153 handlebox = mainwin->handlebox;
2155 case TOOLBAR_COMPOSE:
2156 toolbar_data = compose->toolbar;
2157 handlebox = compose->handlebox;
2159 case TOOLBAR_MSGVIEW:
2160 toolbar_data = msgview->toolbar;
2161 handlebox = msgview->handlebox;
2167 gtk_container_remove(GTK_CONTAINER(handlebox),
2168 GTK_WIDGET(toolbar_data->toolbar));
2170 toolbar_init(toolbar_data);
2171 toolbar_data = toolbar_create(type, handlebox, data);
2175 toolbar_data = mainwin->toolbar;
2176 handlebox = mainwin->window;
2178 case TOOLBAR_COMPOSE:
2179 toolbar_data = compose->toolbar;
2180 handlebox = compose->window;
2182 case TOOLBAR_MSGVIEW:
2183 toolbar_data = msgview->toolbar;
2184 handlebox = msgview->window;
2190 hildon_window_remove_toolbar(HILDON_WINDOW(handlebox), GTK_TOOLBAR(toolbar_data->toolbar));
2192 toolbar_init(toolbar_data);
2193 toolbar_data = toolbar_create(type, handlebox, data);
2198 mainwin->toolbar = toolbar_data;
2200 case TOOLBAR_COMPOSE:
2201 compose->toolbar = toolbar_data;
2203 case TOOLBAR_MSGVIEW:
2204 msgview->toolbar = toolbar_data;
2208 toolbar_style(type, prefs_common.toolbar_style, data);
2210 if (type == TOOLBAR_MAIN) {
2211 toolbar_main_set_sensitive((MainWindow*)data);
2212 account_set_menu_only_toolbar();
2216 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2217 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2218 if (GTK_IS_BUTTON(widget)) \
2219 in_btn1 = GTK_BUTTON(widget)->in_button; \
2220 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2221 GtkWidget *child = gtk_bin_get_child( \
2223 GList *gchild = gtk_container_get_children( \
2224 GTK_CONTAINER(child)); \
2225 GtkWidget *btn = (GtkWidget *)gchild->data; \
2226 GtkWidget *arr = (GtkWidget *) \
2227 (gchild->next?gchild->next->data:NULL); \
2228 g_list_free(gchild); \
2229 if (GTK_IS_BUTTON(btn)) \
2230 in_btn1 = GTK_BUTTON(btn)->in_button; \
2231 if (GTK_IS_BUTTON(arr)) \
2232 in_btn2 = GTK_BUTTON(arr)->in_button; \
2234 else if (GTK_IS_TOOL_ITEM(widget)) { \
2235 GtkWidget *child = gtk_bin_get_child( \
2237 if (GTK_IS_BUTTON(child)) \
2238 in_btn1 = GTK_BUTTON(child)->in_button; \
2240 gtk_widget_set_sensitive(widget, sensitive); \
2241 if (GTK_IS_BUTTON(widget)) \
2242 GTK_BUTTON(widget)->in_button = in_btn1; \
2243 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2244 GtkWidget *child = gtk_bin_get_child( \
2246 GList *gchild = gtk_container_get_children( \
2247 GTK_CONTAINER(child)); \
2248 GtkWidget *btn = (GtkWidget *)gchild->data; \
2249 GtkWidget *arr = (GtkWidget *) \
2250 (gchild->next?gchild->next->data:NULL); \
2251 g_list_free(gchild); \
2252 if (GTK_IS_BUTTON(btn)) \
2253 GTK_BUTTON(btn)->in_button = in_btn1; \
2254 if (GTK_IS_BUTTON(arr)) \
2255 GTK_BUTTON(arr)->in_button = in_btn2; \
2257 else if (GTK_IS_TOOL_ITEM(widget)) { \
2258 GtkWidget *child = gtk_bin_get_child( \
2260 if (GTK_IS_BUTTON(child)) \
2261 GTK_BUTTON(child)->in_button = in_btn1; \
2265 void toolbar_main_set_sensitive(gpointer data)
2267 SensitiveCond state;
2269 MainWindow *mainwin = (MainWindow*)data;
2270 Toolbar *toolbar = mainwin->toolbar;
2272 GSList *entry_list = NULL;
2274 typedef struct _Entry Entry;
2281 #define SET_WIDGET_COND(w, c) \
2283 Entry *e = g_new0(Entry, 1); \
2286 entry_list = g_slist_append(entry_list, e); \
2290 if (toolbar->get_btn)
2291 SET_WIDGET_COND(toolbar->get_btn,
2292 M_HAVE_ACCOUNT|M_UNLOCKED);
2294 if (toolbar->getall_btn) {
2295 SET_WIDGET_COND(toolbar->getall_btn,
2296 M_HAVE_ACCOUNT|M_UNLOCKED);
2298 if (toolbar->send_btn) {
2299 SET_WIDGET_COND(toolbar->send_btn,
2300 M_HAVE_QUEUED_MAILS);
2302 if (toolbar->compose_mail_btn) {
2303 SET_WIDGET_COND(toolbar->compose_mail_btn,
2306 if (toolbar->close_window_btn) {
2307 SET_WIDGET_COND(toolbar->close_window_btn,
2310 if (toolbar->open_mail_btn) {
2311 SET_WIDGET_COND(toolbar->open_mail_btn,
2312 M_TARGET_EXIST|M_SUMMARY_ISLIST);
2314 if (toolbar->reply_btn) {
2315 SET_WIDGET_COND(toolbar->reply_btn,
2316 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2318 if (toolbar->replyall_btn) {
2319 SET_WIDGET_COND(toolbar->replyall_btn,
2320 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2322 if (toolbar->replylist_btn) {
2323 SET_WIDGET_COND(toolbar->replylist_btn,
2324 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2326 if (toolbar->replysender_btn) {
2327 SET_WIDGET_COND(toolbar->replysender_btn,
2328 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2330 if (toolbar->fwd_btn) {
2331 SET_WIDGET_COND(toolbar->fwd_btn,
2332 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2335 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2336 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST|M_SUMMARY_ISLIST);
2338 SET_WIDGET_COND(toolbar->next_btn, 0);
2341 if (toolbar->trash_btn)
2342 SET_WIDGET_COND(toolbar->trash_btn,
2343 M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS);
2345 if (toolbar->delete_btn)
2346 SET_WIDGET_COND(toolbar->delete_btn,
2347 M_TARGET_EXIST|M_ALLOW_DELETE);
2349 if (toolbar->exec_btn)
2350 SET_WIDGET_COND(toolbar->exec_btn,
2353 if (toolbar->learn_spam_btn)
2354 SET_WIDGET_COND(toolbar->learn_spam_btn,
2355 M_TARGET_EXIST|M_CAN_LEARN_SPAM|M_SUMMARY_ISLIST);
2357 if (toolbar->cancel_inc_btn)
2358 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2361 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2362 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2364 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2367 #undef SET_WIDGET_COND
2369 state = main_window_get_current_state(mainwin);
2371 for (cur = entry_list; cur != NULL; cur = cur->next) {
2372 Entry *e = (Entry*) cur->data;
2374 if (e->widget != NULL) {
2375 sensitive = ((e->cond & state) == e->cond);
2376 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2380 while (entry_list != NULL) {
2381 Entry *e = (Entry*) entry_list->data;
2384 entry_list = g_slist_remove(entry_list, e);
2387 g_slist_free(entry_list);
2389 activate_compose_button(toolbar,
2390 prefs_common.toolbar_style,
2391 toolbar->compose_btn_type);
2395 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2397 Compose *compose = (Compose*)data;
2398 GSList *items = compose->toolbar->action_list;
2400 if (compose->toolbar->send_btn)
2401 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2402 if (compose->toolbar->sendl_btn)
2403 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2404 if (compose->toolbar->draft_btn )
2405 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2406 if (compose->toolbar->insert_btn )
2407 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2408 if (compose->toolbar->attach_btn)
2409 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2410 if (compose->toolbar->sig_btn)
2411 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2412 if (compose->toolbar->exteditor_btn)
2413 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2414 if (compose->toolbar->linewrap_current_btn)
2415 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2416 if (compose->toolbar->linewrap_all_btn)
2417 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2418 if (compose->toolbar->addrbook_btn)
2419 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2421 if (compose->toolbar->spellcheck_btn)
2422 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2424 for (; items != NULL; items = g_slist_next(items)) {
2425 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2426 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2431 * Initialize toolbar structure
2433 static void toolbar_init(Toolbar * toolbar)
2436 toolbar->toolbar = NULL;
2437 toolbar->folders_btn = NULL;
2438 toolbar->get_btn = NULL;
2439 toolbar->getall_btn = NULL;
2440 toolbar->send_btn = NULL;
2441 toolbar->compose_mail_btn = NULL;
2442 toolbar->compose_mail_icon = NULL;
2443 toolbar->compose_news_icon = NULL;
2444 toolbar->reply_btn = NULL;
2445 toolbar->replysender_btn = NULL;
2446 toolbar->replyall_btn = NULL;
2447 toolbar->replylist_btn = NULL;
2448 toolbar->fwd_btn = NULL;
2449 toolbar->trash_btn = NULL;
2450 toolbar->delete_btn = NULL;
2451 toolbar->prev_btn = NULL;
2452 toolbar->next_btn = NULL;
2453 toolbar->exec_btn = NULL;
2454 toolbar->open_mail_btn = NULL;
2455 toolbar->close_window_btn = NULL;
2456 /* compose buttons */
2457 toolbar->sendl_btn = NULL;
2458 toolbar->draft_btn = NULL;
2459 toolbar->insert_btn = NULL;
2460 toolbar->attach_btn = NULL;
2461 toolbar->sig_btn = NULL;
2462 toolbar->exteditor_btn = NULL;
2463 toolbar->linewrap_current_btn = NULL;
2464 toolbar->linewrap_all_btn = NULL;
2465 toolbar->addrbook_btn = NULL;
2467 toolbar->spellcheck_btn = NULL;
2470 toolbar_destroy(toolbar);
2475 static void toolbar_reply(gpointer data, guint action)
2477 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2478 MainWindow *mainwin;
2479 MessageView *msgview;
2480 GSList *msginfo_list = NULL;
2482 g_return_if_fail(toolbar_item != NULL);
2484 switch (toolbar_item->type) {
2486 mainwin = (MainWindow*)toolbar_item->parent;
2487 msginfo_list = summary_get_selection(mainwin->summaryview);
2488 msgview = (MessageView*)mainwin->messageview;
2490 case TOOLBAR_MSGVIEW:
2491 msgview = (MessageView*)toolbar_item->parent;
2492 g_return_if_fail(msgview != NULL);
2493 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2499 g_return_if_fail(msgview != NULL);
2500 g_return_if_fail(msginfo_list != NULL);
2501 compose_reply_from_messageview(msgview, msginfo_list, action);
2502 g_slist_free(msginfo_list);
2504 /* TODO: update reply state ion summaryview */
2508 /* exported functions */
2510 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2512 MainWindow *mainwin = (MainWindow*)data;
2514 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2517 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2519 MainWindow *mainwin = (MainWindow*)data;
2521 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2524 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2528 gboolean got_error = FALSE;
2529 gchar *errstr = NULL;
2531 if (prefs_common.work_offline)
2532 if (alertpanel(_("Offline warning"),
2533 _("You're working offline. Override?"),
2534 GTK_STOCK_NO, GTK_STOCK_YES,
2535 NULL) != G_ALERTALTERNATE)
2538 /* ask for confirmation before sending queued messages only
2539 in online mode and if there is at least one message queued
2540 in any of the folder queue
2542 if (prefs_common.confirm_send_queued_messages) {
2544 /* check if there's a queued message */
2545 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2546 Folder *folder = list->data;
2548 found = !procmsg_queue_is_empty(folder->queue);
2550 /* if necessary, ask for confirmation before sending */
2551 if (found && !prefs_common.work_offline) {
2552 if (alertpanel(_("Send queued messages"),
2553 _("Send all queued messages?"),
2554 GTK_STOCK_CANCEL, _("_Send"),
2555 NULL) != G_ALERTALTERNATE)
2560 for (list = folder_get_list(); list != NULL; list = list->next) {
2561 Folder *folder = list->data;
2563 if (folder->queue) {
2564 if (procmsg_send_queue(folder->queue,
2565 prefs_common.savemsg,
2572 alertpanel_error_log(_("Some errors occurred while "
2573 "sending queued messages."));
2575 alertpanel_error_log(_("Some errors occurred "
2576 "while sending queued messages:\n%s"), errstr);
2582 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2584 MainWindow *mainwin = (MainWindow*)data;
2585 PrefsAccount *ac = NULL;
2586 FolderItem *item = mainwin->summaryview->folder_item;
2591 ac = account_find_from_item(item);
2592 if (ac && ac->protocol != A_NNTP) {
2593 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2599 * CLAWS - use current account
2601 if (cur_account && (cur_account->protocol != A_NNTP)) {
2602 compose_new_with_folderitem(cur_account, item, NULL);
2607 * CLAWS - just get the first one
2609 list = account_get_list();
2610 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2611 ac = (PrefsAccount *) cur->data;
2612 if (ac->protocol != A_NNTP) {
2613 compose_new_with_folderitem(ac, item, NULL);
2619 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2621 MainWindow *mainwin = (MainWindow*)data;
2622 PrefsAccount * ac = NULL;
2626 if (mainwin->summaryview->folder_item) {
2627 ac = mainwin->summaryview->folder_item->folder->account;
2628 if (ac && ac->protocol == A_NNTP) {
2629 compose_new_with_folderitem(ac,
2630 mainwin->summaryview->folder_item, NULL);
2635 list = account_get_list();
2636 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2637 ac = (PrefsAccount *) cur->data;
2638 if (ac->protocol == A_NNTP) {
2639 compose_new_with_folderitem(ac,
2640 mainwin->summaryview->folder_item, NULL);