2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2013 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.
26 #include "claws-features.h"
32 #include <glib/gi18n.h>
41 #include "mainwindow.h"
42 #include "summaryview.h"
47 #include "prefs_gtk.h"
49 #include "stock_pixmap.h"
50 #include "manage_window.h"
56 #include "prefs_actions.h"
57 #include "prefs_common.h"
58 #include "prefs_toolbar.h"
59 #include "alertpanel.h"
62 #include "send_message.h"
63 #ifndef USE_NEW_ADDRBOOK
64 #include "addressbook.h"
66 #include "addressbook-dbus.h"
70 #define TOOLBAR_TAG_INDEX "toolbar"
71 #define TOOLBAR_TAG_ITEM "item"
72 #define TOOLBAR_TAG_SEPARATOR "separator"
74 #define TOOLBAR_ICON_FILE "file"
75 #define TOOLBAR_ICON_TEXT "text"
76 #define TOOLBAR_ICON_ACTION "action"
78 static void toolbar_init(Toolbar * toolbar);
79 static gboolean toolbar_is_duplicate (gint action,
81 static void toolbar_parse_item (XMLFile *file,
84 static gint toolbar_ret_val_from_text (const gchar *text);
85 static gchar *toolbar_ret_text_from_val (gint val);
87 static void toolbar_set_default_main (void);
88 static void toolbar_set_default_compose (void);
89 static void toolbar_set_default_msgview (void);
91 static void toolbar_style (ToolbarType type,
95 static MainWindow *get_mainwin (gpointer data);
96 static void activate_compose_button (Toolbar *toolbar,
98 ComposeButtonType type);
100 /* toolbar callbacks */
101 static void toolbar_reply (gpointer data,
103 static void toolbar_learn (gpointer data,
105 static void toolbar_delete_cb (GtkWidget *widget,
107 static void toolbar_trash_cb (GtkWidget *widget,
110 static void toolbar_compose_cb (GtkWidget *widget,
113 static void toolbar_learn_cb (GtkWidget *widget,
116 static void toolbar_reply_cb (GtkWidget *widget,
119 static void toolbar_reply_to_all_cb (GtkWidget *widget,
122 static void toolbar_reply_to_list_cb (GtkWidget *widget,
125 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
128 static void toolbar_forward_cb (GtkWidget *widget,
131 static void toolbar_prev_unread_cb (GtkWidget *widget,
133 static void toolbar_next_unread_cb (GtkWidget *widget,
136 static void toolbar_ignore_thread_cb (GtkWidget *widget,
139 static void toolbar_watch_thread_cb (GtkWidget *widget,
142 static void toolbar_print_cb (GtkWidget *widget,
145 static void toolbar_actions_execute_cb (GtkWidget *widget,
147 static void toolbar_plugins_execute_cb (GtkWidget *widget,
151 static void toolbar_send_cb (GtkWidget *widget,
153 static void toolbar_send_later_cb (GtkWidget *widget,
155 static void toolbar_draft_cb (GtkWidget *widget,
157 static void toolbar_close_cb (GtkWidget *widget,
159 static void toolbar_preferences_cb (GtkWidget *widget,
161 static void toolbar_open_mail_cb (GtkWidget *widget,
163 static void toolbar_insert_cb (GtkWidget *widget,
165 static void toolbar_attach_cb (GtkWidget *widget,
167 static void toolbar_sig_cb (GtkWidget *widget,
169 static void toolbar_ext_editor_cb (GtkWidget *widget,
171 static void toolbar_linewrap_current_cb (GtkWidget *widget,
173 static void toolbar_linewrap_all_cb (GtkWidget *widget,
175 static void toolbar_addrbook_cb (GtkWidget *widget,
178 static void toolbar_check_spelling_cb (GtkWidget *widget,
181 static void toolbar_cancel_inc_cb (GtkWidget *widget,
183 static void toolbar_cancel_send_cb (GtkWidget *widget,
185 static void toolbar_cancel_all_cb (GtkWidget *widget,
191 } toolbar_text [] = {
192 { "A_RECEIVE_ALL", N_("Receive Mail from all Accounts") },
193 { "A_RECEIVE_CUR", N_("Receive Mail from current Account") },
194 { "A_SEND_QUEUED", N_("Send Queued Messages") },
195 { "A_COMPOSE_EMAIL", N_("Compose Email") },
196 { "A_COMPOSE_NEWS", N_("Compose News") },
197 { "A_REPLY_MESSAGE", N_("Reply to Message") },
198 { "A_REPLY_SENDER", N_("Reply to Sender") },
199 { "A_REPLY_ALL", N_("Reply to All") },
200 { "A_REPLY_ML", N_("Reply to Mailing-list") },
201 { "A_OPEN_MAIL", N_("Open email") },
202 { "A_FORWARD", N_("Forward Message") },
203 { "A_TRASH", N_("Trash Message") },
204 { "A_DELETE_REAL", N_("Delete Message") },
205 { "A_EXECUTE", N_("Execute") },
206 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
207 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
208 { "A_IGNORE_THREAD", N_("Ignore thread") },
209 { "A_WATCH_THREAD", N_("Watch thread") },
210 { "A_PRINT", N_("Print") },
211 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
212 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
213 { "A_PREFERENCES", N_("Preferences") },
215 { "A_SEND", N_("Send Message") },
216 { "A_SENDL", N_("Put into queue folder and send later") },
217 { "A_DRAFT", N_("Save to draft folder") },
218 { "A_INSERT", N_("Insert file") },
219 { "A_ATTACH", N_("Attach file") },
220 { "A_SIG", N_("Insert signature") },
221 { "A_REP_SIG", N_("Replace signature") },
222 { "A_EXTEDITOR", N_("Edit with external editor") },
223 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
224 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
225 { "A_ADDRBOOK", N_("Address book") },
227 { "A_CHECK_SPELLING", N_("Check spelling") },
229 { "A_CLAWS_ACTIONS", N_("Claws Mail Actions Feature") },
230 { "A_CANCEL_INC", N_("Cancel receiving") },
231 { "A_CANCEL_SEND", N_("Cancel sending") },
232 { "A_CANCEL_ALL", N_("Cancel receiving/sending") },
233 { "A_CLOSE", N_("Close window") },
234 { "A_SEPARATOR", N_("Separator") },
235 { "A_CLAWS_PLUGINS", N_("Claws Mail Plugins") },
238 /* struct holds configuration files and a list of
239 * currently active toolbar items
240 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
244 const gchar *conf_file;
246 } toolbar_config[NUM_TOOLBARS] = {
247 { "toolbar_main.xml", NULL},
248 { "toolbar_compose.xml", NULL},
249 { "toolbar_msgview.xml", NULL}
252 gint toolbar_ret_val_from_descr(const gchar *descr)
256 for (i = 0; i < N_ACTION_VAL; i++) {
257 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
264 gchar *toolbar_ret_descr_from_val(gint val)
266 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
268 return gettext(toolbar_text[val].descr);
271 static gint toolbar_ret_val_from_text(const gchar *text)
275 for (i = 0; i < N_ACTION_VAL; i++) {
276 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
283 static gchar *toolbar_ret_text_from_val(gint val)
285 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
287 return toolbar_text[val].index_str;
290 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
294 if ((action == A_SEPARATOR) || (action == A_CLAWS_ACTIONS) || (action == A_CLAWS_PLUGINS))
297 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
298 ToolbarItem *item = (ToolbarItem*) cur->data;
300 if (item->index == action)
306 /* depending on toolbar type this function
307 returns a list of available toolbar events being
308 displayed by prefs_toolbar
310 GList *toolbar_get_action_items(ToolbarType source)
315 if (source == TOOLBAR_MAIN) {
316 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
317 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
318 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
319 A_TRASH, A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
320 A_GOTO_NEXT, A_IGNORE_THREAD, A_WATCH_THREAD, A_PRINT,
321 A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
322 A_CANCEL_INC, A_CANCEL_SEND, A_CANCEL_ALL, A_PREFERENCES };
324 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
325 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
328 else if (source == TOOLBAR_COMPOSE) {
329 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
330 A_INSERT, A_ATTACH, A_SIG,
331 A_REP_SIG, A_EXTEDITOR, A_LINEWRAP_CURRENT,
332 A_LINEWRAP_ALL, A_ADDRBOOK,
338 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
339 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
341 else if (source == TOOLBAR_MSGVIEW) {
342 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
343 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
344 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
345 A_ADDRBOOK, A_LEARN_SPAM, A_CLOSE };
347 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
348 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
354 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
358 ToolbarItem *item = NULL;
359 gboolean rewrite = FALSE;
361 attr = xml_get_current_tag_attr(file);
362 item = g_new0(ToolbarItem, 1);
364 name = ((XMLAttr *)attr->data)->name;
365 value = ((XMLAttr *)attr->data)->value;
367 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
368 item->file = g_strdup (value);
369 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
370 item->text = g_strdup (*value ? gettext(value):"");
371 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
372 item->index = toolbar_ret_val_from_text(value);
373 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
375 item->index = A_TRASH;
377 item->file = g_strdup("trash_btn");
379 item->text = g_strdup(C_("Toolbar", "Trash"));
382 if (item->index == -1 && !strcmp(value, "A_SYL_ACTIONS")) {
384 item->index = A_CLAWS_ACTIONS;
387 attr = g_list_next(attr);
389 if (item->index != -1) {
391 if (!toolbar_is_duplicate(item->index, source))
392 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
396 toolbar_save_config_file(source);
400 const gchar *toolbar_get_short_text(int action) {
402 case A_GO_FOLDERS: return _("Folders");
403 case A_OPEN_MAIL: return _("Open");
404 case A_RECEIVE_ALL: return _("Get Mail");
405 case A_RECEIVE_CUR: return _("Get");
406 case A_SEND_QUEUED: return _("Send");
407 case A_COMPOSE_EMAIL: return C_("Toolbar", "Compose");
408 case A_COMPOSE_NEWS: return C_("Toolbar", "Compose");
409 case A_REPLY_MESSAGE: return _("Reply");
410 case A_REPLY_ALL: return _("All");
411 case A_REPLY_SENDER: return C_("Toolbar", "Sender");
412 case A_REPLY_ML: return _("List");
413 case A_FORWARD: return _("Forward");
414 case A_TRASH: return C_("Toolbar", "Trash");
415 case A_DELETE_REAL: return _("Delete");
416 case A_LEARN_SPAM: return _("Spam");
417 case A_GOTO_PREV: return _("Prev");
418 case A_GOTO_NEXT: return _("Next");
419 case A_IGNORE_THREAD: return _("Ignore thread");
420 case A_WATCH_THREAD: return _("Watch thread");
421 case A_PRINT: return _("Print");
422 case A_CLOSE: return _("Close");
423 case A_PREFERENCES: return _("Preferences");
424 case A_SEND: return _("Send");
425 case A_SENDL: return _("Send later");
426 case A_DRAFT: return _("Draft");
427 case A_INSERT: return _("Insert");
428 case A_ATTACH: return _("Attach");
429 case A_SIG: return _("Insert sig.");
430 case A_REP_SIG: return _("Replace sig.");
431 case A_EXTEDITOR: return _("Edit");
432 case A_LINEWRAP_CURRENT:return _("Wrap para.");
433 case A_LINEWRAP_ALL: return _("Wrap all");
434 case A_ADDRBOOK: return _("Address");
435 case A_CANCEL_INC: return _("Stop");
436 case A_CANCEL_SEND: return _("Stop");
437 case A_CANCEL_ALL: return _("Stop all");
438 case A_EXECUTE: return _("Execute");
440 case A_CHECK_SPELLING: return _("Check spelling");
446 gint toolbar_get_icon(int action) {
448 case A_GO_FOLDERS: return STOCK_PIXMAP_GO_FOLDERS;
449 case A_OPEN_MAIL: return STOCK_PIXMAP_OPEN_MAIL;
450 case A_RECEIVE_ALL: return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
451 case A_RECEIVE_CUR: return STOCK_PIXMAP_MAIL_RECEIVE;
452 case A_SEND_QUEUED: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
453 case A_COMPOSE_EMAIL: return STOCK_PIXMAP_MAIL_COMPOSE;
454 case A_COMPOSE_NEWS: return STOCK_PIXMAP_NEWS_COMPOSE;
455 case A_REPLY_MESSAGE: return STOCK_PIXMAP_MAIL_REPLY;
456 case A_REPLY_ALL: return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
457 case A_REPLY_SENDER: return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
458 case A_REPLY_ML: return STOCK_PIXMAP_MAIL_REPLY_TO_LIST;
459 case A_FORWARD: return STOCK_PIXMAP_MAIL_FORWARD;
460 case A_TRASH: return STOCK_PIXMAP_TRASH;
461 case A_DELETE_REAL: return STOCK_PIXMAP_DELETE;
462 case A_LEARN_SPAM: return STOCK_PIXMAP_SPAM_BTN;
463 case A_GOTO_PREV: return STOCK_PIXMAP_UP_ARROW;
464 case A_GOTO_NEXT: return STOCK_PIXMAP_DOWN_ARROW;
465 case A_IGNORE_THREAD: return STOCK_PIXMAP_IGNORETHREAD;
466 case A_WATCH_THREAD: return STOCK_PIXMAP_WATCHTHREAD;
467 case A_PRINT: return STOCK_PIXMAP_PRINTER;
468 case A_CLOSE: return STOCK_PIXMAP_CLOSE;
469 case A_PREFERENCES: return STOCK_PIXMAP_PREFERENCES;
470 case A_SEND: return STOCK_PIXMAP_MAIL_SEND;
471 case A_SENDL: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
472 case A_DRAFT: return STOCK_PIXMAP_MAIL;
473 case A_INSERT: return STOCK_PIXMAP_INSERT_FILE;
474 case A_ATTACH: return STOCK_PIXMAP_MAIL_ATTACH;
475 case A_SIG: return STOCK_PIXMAP_MAIL_SIGN;
476 case A_REP_SIG: return STOCK_PIXMAP_MAIL_SIGN;
477 case A_EXTEDITOR: return STOCK_PIXMAP_EDIT_EXTERN;
478 case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
479 case A_LINEWRAP_ALL: return STOCK_PIXMAP_LINEWRAP_ALL;
480 case A_ADDRBOOK: return STOCK_PIXMAP_ADDRESS_BOOK;
481 case A_CANCEL_INC: return STOCK_PIXMAP_CANCEL;
482 case A_CANCEL_SEND: return STOCK_PIXMAP_CANCEL;
483 case A_CANCEL_ALL: return STOCK_PIXMAP_CANCEL;
484 case A_EXECUTE: return STOCK_PIXMAP_EXEC;
486 case A_CHECK_SPELLING: return STOCK_PIXMAP_CHECK_SPELLING;
492 static void toolbar_set_default_main(void)
496 } default_toolbar[] = {
524 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
526 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
528 if (default_toolbar[i].action != A_SEPARATOR) {
531 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
532 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
535 toolbar_item->file = g_strdup(file);
536 toolbar_item->index = default_toolbar[i].action;
537 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
540 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
541 toolbar_item->index = A_SEPARATOR;
544 if (toolbar_item->index != -1) {
545 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
546 toolbar_config[TOOLBAR_MAIN].item_list =
547 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
552 static void toolbar_set_default_compose(void)
556 } default_toolbar[] = {
575 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
577 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
579 if (default_toolbar[i].action != A_SEPARATOR) {
582 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
583 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
585 toolbar_item->file = g_strdup(file);
586 toolbar_item->index = default_toolbar[i].action;
587 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
590 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
591 toolbar_item->index = A_SEPARATOR;
594 if (toolbar_item->index != -1) {
595 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
596 toolbar_config[TOOLBAR_COMPOSE].item_list =
597 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
602 static void toolbar_set_default_msgview(void)
606 } default_toolbar[] = {
625 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
627 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
629 if (default_toolbar[i].action != A_SEPARATOR) {
631 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
632 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
635 toolbar_item->file = g_strdup(file);
636 toolbar_item->index = default_toolbar[i].action;
637 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
640 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
641 toolbar_item->index = A_SEPARATOR;
644 if (toolbar_item->index != -1) {
645 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
646 toolbar_config[TOOLBAR_MSGVIEW].item_list =
647 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
652 void toolbar_set_default(ToolbarType source)
654 if (source == TOOLBAR_MAIN)
655 toolbar_set_default_main();
656 else if (source == TOOLBAR_COMPOSE)
657 toolbar_set_default_compose();
658 else if (source == TOOLBAR_MSGVIEW)
659 toolbar_set_default_msgview();
662 void toolbar_save_config_file(ToolbarType source)
667 gchar *fileSpec = NULL;
669 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
671 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
672 pfile = prefs_write_open(fileSpec);
675 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
678 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
681 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
682 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
684 if (toolbar_item->index != A_SEPARATOR) {
685 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
687 TOOLBAR_ICON_FILE, toolbar_item->file,
688 TOOLBAR_ICON_TEXT) < 0)
690 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
692 if (fprintf(fp, "\" %s=\"%s\"/>\n",
694 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
697 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
702 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
706 if (prefs_file_close (pfile) < 0 )
707 g_warning("failed to write toolbar configuration to file\n");
711 FILE_OP_ERROR(fileSpec, "fprintf");
713 prefs_file_close_revert (pfile);
715 g_warning("failed to open toolbar configuration file for writing\n");
718 void toolbar_read_config_file(ToolbarType source)
720 XMLFile *file = NULL;
721 gchar *fileSpec = NULL;
724 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
726 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
727 file = xml_open_file(fileSpec);
730 toolbar_clear_list(source);
734 || (xml_get_dtd(file))
735 || (xml_parse_next_tag(file))
736 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
737 xml_close_file(file);
745 if (xml_parse_next_tag(file))
748 /* Get next tag (icon, icon_text or icon_action) */
749 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
750 toolbar_parse_item(file, source);
751 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
752 ToolbarItem *item = g_new0(ToolbarItem, 1);
754 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
755 item->index = A_SEPARATOR;
756 toolbar_config[source].item_list =
757 g_slist_append(toolbar_config[source].item_list, item);
761 xml_close_file(file);
764 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
766 if (source == TOOLBAR_MAIN)
767 toolbar_set_default(TOOLBAR_MAIN);
768 else if (source == TOOLBAR_COMPOSE)
769 toolbar_set_default(TOOLBAR_COMPOSE);
770 else if (source == TOOLBAR_MSGVIEW)
771 toolbar_set_default(TOOLBAR_MSGVIEW);
773 g_warning("refusing to write unknown Toolbar Configuration number %d\n", source);
777 toolbar_save_config_file(source);
782 * clears list of toolbar items read from configuration files
784 void toolbar_clear_list(ToolbarType source)
786 while (toolbar_config[source].item_list != NULL) {
787 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
789 toolbar_config[source].item_list =
790 g_slist_remove(toolbar_config[source].item_list, item);
796 g_slist_free(toolbar_config[source].item_list);
801 * return list of Toolbar items
803 GSList *toolbar_get_list(ToolbarType source)
807 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
808 list = toolbar_config[source].item_list;
813 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
815 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
817 toolbar_item->file = g_strdup(t_item->file);
818 toolbar_item->text = g_strdup(t_item->text);
819 toolbar_item->index = t_item->index;
821 toolbar_config[source].item_list =
822 g_slist_append(toolbar_config[source].item_list,
826 static void toolbar_action_execute(GtkWidget *widget,
834 for (cur = action_list; cur != NULL; cur = cur->next) {
835 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
837 if (widget == act->widget) {
838 i = prefs_actions_find_by_name(act->name);
846 actions_execute(data, i, widget, source);
848 g_warning ("Error: did not find Claws Action to execute");
851 gboolean toolbar_check_action_btns(ToolbarType type)
853 GSList *temp, *curr, *list = toolbar_config[type].item_list;
854 gboolean modified = FALSE;
857 while (curr != NULL) {
858 ToolbarItem *toolbar_item = (ToolbarItem *) curr->data;
862 if (toolbar_item->index != A_CLAWS_ACTIONS)
865 if (prefs_actions_find_by_name(toolbar_item->text) == -1) {
866 list = g_slist_delete_link(list, temp);
867 g_free(toolbar_item->file);
868 g_free(toolbar_item->text);
869 g_free(toolbar_item);
877 #if !(GTK_CHECK_VERSION(2,12,0))
878 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
879 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(widget), GTK_TOOLTIPS(toolbar_tips), \
883 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
884 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), tip); \
888 #if !(GTK_CHECK_VERSION(2,12,0))
889 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
890 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(widget), GTK_TOOLTIPS(toolbar_tips), \
894 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
895 gtk_menu_tool_button_set_arrow_tooltip_text(GTK_MENU_TOOL_BUTTON(widget), tip); \
899 static void activate_compose_button (Toolbar *toolbar,
901 ComposeButtonType type)
903 #if !(GTK_CHECK_VERSION(2,12,0))
904 GtkTooltips *toolbar_tips = toolbar->tooltips;
906 if ((!toolbar->compose_mail_btn))
909 if (type == COMPOSEBUTTON_NEWS) {
910 gtk_tool_button_set_icon_widget(
911 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
912 toolbar->compose_news_icon);
914 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose News message"));
916 gtk_widget_show(toolbar->compose_news_icon);
918 gtk_tool_button_set_icon_widget(
919 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
920 toolbar->compose_mail_icon);
922 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose Email"));
924 gtk_widget_show(toolbar->compose_mail_icon);
926 toolbar->compose_btn_type = type;
929 void toolbar_set_compose_button(Toolbar *toolbar,
930 ComposeButtonType compose_btn_type)
932 if (toolbar->compose_btn_type != compose_btn_type)
933 activate_compose_button(toolbar,
934 prefs_common.toolbar_style,
938 static void activate_learn_button (Toolbar *toolbar,
940 LearnButtonType type)
942 #if !(GTK_CHECK_VERSION(2,12,0))
943 GtkTooltips *toolbar_tips = toolbar->tooltips;
945 if ((!toolbar->learn_spam_btn))
948 if (type == LEARN_SPAM) {
949 gtk_tool_button_set_icon_widget(
950 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
951 toolbar->learn_spam_icon);
952 gtk_tool_button_set_label(
953 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
956 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn spam"));
958 gtk_widget_show(toolbar->learn_spam_icon);
960 gtk_tool_button_set_icon_widget(
961 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
962 toolbar->learn_ham_icon);
963 gtk_tool_button_set_label(
964 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
967 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn ham"));
969 gtk_widget_show(toolbar->learn_ham_icon);
971 toolbar->learn_btn_type = type;
974 void toolbar_set_learn_button(Toolbar *toolbar,
975 LearnButtonType learn_btn_type)
977 if (toolbar->learn_btn_type != learn_btn_type)
978 activate_learn_button(toolbar,
979 prefs_common.toolbar_style,
983 void toolbar_toggle(guint action, gpointer data)
985 MainWindow *mainwin = (MainWindow*)data;
989 cm_return_if_fail(mainwin != NULL);
991 toolbar_style(TOOLBAR_MAIN, action, mainwin);
993 list = compose_get_compose_list();
994 for (cur = list; cur != NULL; cur = cur->next) {
995 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
997 list = messageview_get_msgview_list();
998 for (cur = list; cur != NULL; cur = cur->next) {
999 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
1004 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
1006 switch ((ToolbarStyle)action) {
1008 gtk_widget_hide(handlebox_wid);
1011 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1015 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1019 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1022 case TOOLBAR_BOTH_HORIZ:
1023 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1024 GTK_TOOLBAR_BOTH_HORIZ);
1030 prefs_common.toolbar_style = (ToolbarStyle)action;
1031 gtk_widget_set_size_request(handlebox_wid, 1, -1);
1033 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1034 gtk_widget_show(handlebox_wid);
1035 gtk_widget_queue_resize(handlebox_wid);
1039 * Change the style of toolbar
1041 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1043 GtkWidget *handlebox_wid;
1044 GtkWidget *toolbar_wid;
1045 MainWindow *mainwin = (MainWindow*)data;
1046 Compose *compose = (Compose*)data;
1047 MessageView *msgview = (MessageView*)data;
1049 cm_return_if_fail(data != NULL);
1053 handlebox_wid = mainwin->handlebox;
1054 toolbar_wid = mainwin->toolbar->toolbar;
1056 case TOOLBAR_COMPOSE:
1057 handlebox_wid = compose->handlebox;
1058 toolbar_wid = compose->toolbar->toolbar;
1060 case TOOLBAR_MSGVIEW:
1061 handlebox_wid = msgview->handlebox;
1062 toolbar_wid = msgview->toolbar->toolbar;
1068 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1071 /* Toolbar handling */
1072 static void toolbar_inc_cb(GtkWidget *widget,
1075 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1076 MainWindow *mainwin;
1078 cm_return_if_fail(toolbar_item != NULL);
1080 switch (toolbar_item->type) {
1082 mainwin = (MainWindow*)toolbar_item->parent;
1083 inc_mail_cb(mainwin, 0, NULL);
1090 static void toolbar_inc_all_cb(GtkWidget *widget,
1093 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1094 MainWindow *mainwin;
1096 cm_return_if_fail(toolbar_item != NULL);
1098 switch (toolbar_item->type) {
1100 mainwin = (MainWindow*)toolbar_item->parent;
1101 inc_all_account_mail_cb(mainwin, 0, NULL);
1108 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1110 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1111 MainWindow *mainwin;
1113 cm_return_if_fail(toolbar_item != NULL);
1115 switch (toolbar_item->type) {
1117 mainwin = (MainWindow*)toolbar_item->parent;
1118 send_queue_cb(mainwin, 0, NULL);
1125 static void toolbar_exec_cb(GtkWidget *widget,
1128 MainWindow *mainwin = get_mainwin(data);
1130 cm_return_if_fail(mainwin != NULL);
1131 summary_execute(mainwin->summaryview);
1135 * Delete current/selected(s) message(s)
1137 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1139 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1140 MainWindow *mainwin;
1142 cm_return_if_fail(toolbar_item != NULL);
1143 cm_return_if_fail(toolbar_item->parent);
1145 switch (toolbar_item->type) {
1146 case TOOLBAR_MSGVIEW:
1147 messageview_delete((MessageView *)toolbar_item->parent);
1150 mainwin = (MainWindow *)toolbar_item->parent;
1151 summary_delete_trash(mainwin->summaryview);
1154 debug_print("toolbar event not supported\n");
1160 * Delete current/selected(s) message(s)
1162 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1164 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1165 MainWindow *mainwin;
1167 cm_return_if_fail(toolbar_item != NULL);
1168 cm_return_if_fail(toolbar_item->parent);
1170 switch (toolbar_item->type) {
1171 case TOOLBAR_MSGVIEW:
1172 messageview_delete((MessageView *)toolbar_item->parent);
1175 mainwin = (MainWindow *)toolbar_item->parent;
1176 summary_delete(mainwin->summaryview);
1179 debug_print("toolbar event not supported\n");
1186 * Compose new message
1188 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1190 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1191 MainWindow *mainwin;
1192 MessageView *msgview;
1194 cm_return_if_fail(toolbar_item != NULL);
1196 switch (toolbar_item->type) {
1198 mainwin = (MainWindow*)toolbar_item->parent;
1199 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1200 compose_news_cb(mainwin, 0, NULL);
1202 compose_mail_cb(mainwin, 0, NULL);
1204 case TOOLBAR_MSGVIEW:
1205 msgview = (MessageView*)toolbar_item->parent;
1206 compose_new_with_folderitem(NULL,
1207 msgview->msginfo->folder, NULL);
1210 debug_print("toolbar event not supported\n");
1214 static void toolbar_learn(gpointer data, guint as_spam)
1216 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1217 MainWindow *mainwin;
1218 MessageView *msgview;
1220 cm_return_if_fail(toolbar_item != NULL);
1222 switch (toolbar_item->type) {
1224 mainwin = (MainWindow*)toolbar_item->parent;
1226 mainwindow_learn(mainwin, TRUE);
1228 mainwindow_learn(mainwin, FALSE);
1230 case TOOLBAR_MSGVIEW:
1231 msgview = (MessageView*)toolbar_item->parent;
1233 messageview_learn(msgview, TRUE);
1235 messageview_learn(msgview, FALSE);
1238 debug_print("toolbar event not supported\n");
1242 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1244 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1245 MainWindow *mainwin;
1246 MessageView *msgview;
1248 cm_return_if_fail(toolbar_item != NULL);
1250 switch (toolbar_item->type) {
1252 mainwin = (MainWindow*)toolbar_item->parent;
1253 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1254 mainwindow_learn(mainwin, TRUE);
1256 mainwindow_learn(mainwin, FALSE);
1258 case TOOLBAR_MSGVIEW:
1259 msgview = (MessageView*)toolbar_item->parent;
1260 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1261 messageview_learn(msgview, TRUE);
1263 messageview_learn(msgview, FALSE);
1266 debug_print("toolbar event not supported\n");
1274 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1276 toolbar_reply(data, (prefs_common.reply_with_quote ?
1277 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE));
1282 * Reply message to Sender and All recipients
1284 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1287 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1288 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE));
1293 * Reply to Mailing List
1295 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1298 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1299 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE));
1304 * Reply to sender of message
1306 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1309 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1310 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE));
1316 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1318 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1321 cm_return_if_fail(toolbar_item != NULL);
1323 switch (toolbar_item->type) {
1325 case TOOLBAR_MSGVIEW:
1328 case TOOLBAR_COMPOSE:
1329 compose = (Compose *)toolbar_item->parent;
1334 #ifndef USE_NEW_ADDRBOOK
1335 addressbook_open(compose);
1337 GError* error = NULL;
1338 addressbook_connect_signals(compose);
1339 addressbook_dbus_open(TRUE, &error);
1341 g_warning("%s", error->message);
1342 g_error_free(error);
1349 * Forward current/selected(s) message(s)
1351 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1353 toolbar_reply(data, (COMPOSE_FORWARD));
1357 * Goto Prev Unread Message
1359 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1361 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1362 MainWindow *mainwin;
1363 MessageView *msgview;
1365 cm_return_if_fail(toolbar_item != NULL);
1367 switch (toolbar_item->type) {
1369 mainwin = (MainWindow*)toolbar_item->parent;
1370 summary_select_prev_unread(mainwin->summaryview);
1373 case TOOLBAR_MSGVIEW:
1374 msgview = (MessageView*)toolbar_item->parent;
1375 msgview->updating = TRUE;
1376 summary_select_prev_unread(msgview->mainwin->summaryview);
1377 msgview->updating = FALSE;
1379 if (msgview->deferred_destroy) {
1380 debug_print("messageview got away!\n");
1381 messageview_destroy(msgview);
1385 /* Now we need to update the messageview window */
1386 if (msgview->mainwin->summaryview->selected) {
1387 #ifndef GENERIC_UMPC
1388 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1391 messageview_show(msgview, msginfo,
1392 msgview->all_headers);
1395 gtk_widget_destroy(msgview->window);
1399 debug_print("toolbar event not supported\n");
1404 * Goto Next Unread Message
1406 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1408 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1409 MainWindow *mainwin;
1410 MessageView *msgview;
1412 cm_return_if_fail(toolbar_item != NULL);
1414 switch (toolbar_item->type) {
1416 mainwin = (MainWindow*)toolbar_item->parent;
1417 summary_select_next_unread(mainwin->summaryview);
1420 case TOOLBAR_MSGVIEW:
1421 msgview = (MessageView*)toolbar_item->parent;
1422 msgview->updating = TRUE;
1423 summary_select_next_unread(msgview->mainwin->summaryview);
1424 msgview->updating = FALSE;
1426 if (msgview->deferred_destroy) {
1427 debug_print("messageview got away!\n");
1428 messageview_destroy(msgview);
1432 /* Now we need to update the messageview window */
1433 if (msgview->mainwin->summaryview->selected) {
1434 #ifndef GENERIC_UMPC
1435 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1438 messageview_show(msgview, msginfo,
1439 msgview->all_headers);
1442 gtk_widget_destroy(msgview->window);
1446 debug_print("toolbar event not supported\n");
1450 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1452 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1453 MainWindow *mainwin;
1455 cm_return_if_fail(toolbar_item != NULL);
1457 switch (toolbar_item->type) {
1459 mainwin = (MainWindow *) toolbar_item->parent;
1460 summary_toggle_ignore_thread(mainwin->summaryview);
1462 case TOOLBAR_MSGVIEW:
1463 /* TODO: see toolbar_next_unread_cb() if you need
1464 * this in the message view */
1467 debug_print("toolbar event not supported\n");
1472 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1474 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1475 MainWindow *mainwin;
1477 cm_return_if_fail(toolbar_item != NULL);
1479 switch (toolbar_item->type) {
1481 mainwin = (MainWindow *) toolbar_item->parent;
1482 summary_toggle_watch_thread(mainwin->summaryview);
1484 case TOOLBAR_MSGVIEW:
1485 /* TODO: see toolbar_next_unread_cb() if you need
1486 * this in the message view */
1489 debug_print("toolbar event not supported\n");
1494 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1496 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1498 cm_return_if_fail(toolbar_item != NULL);
1503 static void toolbar_cancel_send_cb(GtkWidget *widget, gpointer data)
1505 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1507 cm_return_if_fail(toolbar_item != NULL);
1511 static void toolbar_cancel_all_cb(GtkWidget *widget, gpointer data)
1513 toolbar_cancel_inc_cb(widget, data);
1514 toolbar_cancel_send_cb(widget, data);
1517 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1519 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1520 MainWindow *mainwin;
1522 cm_return_if_fail(toolbar_item != NULL);
1524 switch (toolbar_item->type) {
1526 mainwin = (MainWindow *) toolbar_item->parent;
1527 summary_print(mainwin->summaryview);
1529 case TOOLBAR_MSGVIEW:
1530 /* TODO: see toolbar_next_unread_cb() if you need
1531 * this in the message view */
1534 debug_print("toolbar event not supported\n");
1539 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1541 compose_toolbar_cb(A_SEND, data);
1544 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1546 compose_toolbar_cb(A_SENDL, data);
1549 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1551 compose_toolbar_cb(A_DRAFT, data);
1554 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1556 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1557 MainWindow *mainwin;
1558 MessageView *messageview;
1561 cm_return_if_fail(toolbar_item != NULL);
1563 switch (toolbar_item->type) {
1565 mainwin = (MainWindow *) toolbar_item->parent;
1566 app_will_exit(NULL, mainwin);
1568 case TOOLBAR_MSGVIEW:
1569 messageview = (MessageView *)toolbar_item->parent;
1570 messageview_destroy(messageview);
1572 case TOOLBAR_COMPOSE:
1573 compose = (Compose *)toolbar_item->parent;
1574 compose_close_toolbar(compose);
1579 static void toolbar_preferences_cb(GtkWidget *widget, gpointer data)
1584 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1586 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1587 MainWindow *mainwin;
1589 cm_return_if_fail(toolbar_item != NULL);
1591 switch (toolbar_item->type) {
1593 mainwin = (MainWindow *) toolbar_item->parent;
1594 summary_open_row(NULL, mainwin->summaryview);
1596 case TOOLBAR_MSGVIEW:
1597 debug_print("toolbar event not supported\n");
1599 case TOOLBAR_COMPOSE:
1600 debug_print("toolbar event not supported\n");
1605 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1607 compose_toolbar_cb(A_INSERT, data);
1610 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1612 compose_toolbar_cb(A_ATTACH, data);
1615 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1617 compose_toolbar_cb(A_SIG, data);
1620 static void toolbar_replace_sig_cb(GtkWidget *widget, gpointer data)
1622 compose_toolbar_cb(A_REP_SIG, data);
1625 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1627 compose_toolbar_cb(A_EXTEDITOR, data);
1630 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1632 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1635 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1637 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1641 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1643 compose_toolbar_cb(A_CHECK_SPELLING, data);
1647 * Execute actions from toolbar
1649 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1651 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1652 GSList *action_list;
1653 MainWindow *mainwin;
1655 MessageView *msgview;
1656 gpointer parent = toolbar_item->parent;
1658 cm_return_if_fail(toolbar_item != NULL);
1660 switch (toolbar_item->type) {
1662 mainwin = (MainWindow*)parent;
1663 action_list = mainwin->toolbar->action_list;
1665 case TOOLBAR_COMPOSE:
1666 compose = (Compose*)parent;
1667 action_list = compose->toolbar->action_list;
1669 case TOOLBAR_MSGVIEW:
1670 msgview = (MessageView*)parent;
1671 action_list = msgview->toolbar->action_list;
1674 debug_print("toolbar event not supported\n");
1677 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1680 static void toolbar_plugins_execute_cb(GtkWidget *widget, gpointer data)
1682 ToolbarItem *toolbar_item = data;
1683 prefs_toolbar_execute_plugin_item(toolbar_item->parent, toolbar_item->type, toolbar_item->text);
1686 static MainWindow *get_mainwin(gpointer data)
1688 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1689 MainWindow *mainwin = NULL;
1690 MessageView *msgview;
1692 cm_return_val_if_fail(toolbar_item != NULL, NULL);
1694 switch(toolbar_item->type) {
1696 mainwin = (MainWindow*)toolbar_item->parent;
1698 case TOOLBAR_MSGVIEW:
1699 msgview = (MessageView*)toolbar_item->parent;
1700 mainwin = (MainWindow*)msgview->mainwin;
1709 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1711 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1712 MainWindow *mainwin = NULL;
1713 switch(toolbar_item->type) {
1715 mainwin = (MainWindow*)toolbar_item->parent;
1718 g_warning("wrong toolbar type\n");
1722 if (!mainwin->in_folder) {
1723 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1725 folderview_select(mainwin->folderview, item);
1728 gtk_widget_grab_focus(mainwin->folderview->ctree);
1729 mainwindow_exit_folder(mainwin);
1733 static void toolbar_buttons_cb(GtkWidget *widget,
1740 void (*func)(GtkWidget *widget, gpointer data);
1742 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1743 { A_RECEIVE_CUR, toolbar_inc_cb },
1744 { A_SEND_QUEUED, toolbar_send_queued_cb },
1745 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1746 { A_COMPOSE_NEWS, toolbar_compose_cb },
1747 { A_REPLY_MESSAGE, toolbar_reply_cb },
1748 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1749 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1750 { A_REPLY_ML, toolbar_reply_to_list_cb },
1751 { A_FORWARD, toolbar_forward_cb },
1752 { A_TRASH, toolbar_trash_cb },
1753 { A_DELETE_REAL, toolbar_delete_cb },
1754 { A_EXECUTE, toolbar_exec_cb },
1755 { A_GOTO_PREV, toolbar_prev_unread_cb },
1756 { A_GOTO_NEXT, toolbar_next_unread_cb },
1757 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1758 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1759 { A_PRINT, toolbar_print_cb },
1760 { A_LEARN_SPAM, toolbar_learn_cb },
1761 { A_GO_FOLDERS, toolbar_go_folders_cb },
1763 { A_SEND, toolbar_send_cb },
1764 { A_SENDL, toolbar_send_later_cb },
1765 { A_DRAFT, toolbar_draft_cb },
1766 { A_OPEN_MAIL, toolbar_open_mail_cb },
1767 { A_CLOSE, toolbar_close_cb },
1768 { A_PREFERENCES, toolbar_preferences_cb },
1769 { A_INSERT, toolbar_insert_cb },
1770 { A_ATTACH, toolbar_attach_cb },
1771 { A_SIG, toolbar_sig_cb },
1772 { A_REP_SIG, toolbar_replace_sig_cb },
1773 { A_EXTEDITOR, toolbar_ext_editor_cb },
1774 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1775 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1776 { A_ADDRBOOK, toolbar_addrbook_cb },
1778 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1780 { A_CLAWS_ACTIONS, toolbar_actions_execute_cb },
1781 { A_CANCEL_INC, toolbar_cancel_inc_cb },
1782 { A_CANCEL_SEND, toolbar_cancel_send_cb },
1783 { A_CANCEL_ALL, toolbar_cancel_all_cb },
1784 { A_CLAWS_PLUGINS, toolbar_plugins_execute_cb },
1787 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1789 for (i = 0; i < num_items; i++) {
1790 if (callbacks[i].index == item->index) {
1791 callbacks[i].func(widget, item);
1796 #ifndef GENERIC_UMPC
1797 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1798 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1799 gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
1800 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1801 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1802 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1803 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1804 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1808 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1809 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1810 GList *gchild = NULL; \
1811 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1812 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1813 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1814 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1815 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1816 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1818 CLAWS_SET_ARROW_TIP(GTK_MENU_TOOL_BUTTON(item), menutip); \
1819 child = gtk_bin_get_child(GTK_BIN(item)); \
1820 gchild = gtk_container_get_children( \
1821 GTK_CONTAINER(child)); \
1822 btn = (GtkWidget *)gchild->data; \
1823 gtkut_widget_set_can_focus(btn, FALSE); \
1824 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1825 gtkut_widget_set_can_focus(arr, FALSE); \
1826 g_list_free(gchild); \
1827 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1828 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1829 g_list_free(gchild); \
1832 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1833 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1834 gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
1835 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1836 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1837 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1838 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1841 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1842 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1843 GList *gchild = NULL; \
1844 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1845 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1846 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1847 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1848 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1849 child = gtk_bin_get_child(GTK_BIN(item)); \
1850 gchild = gtk_container_get_children( \
1851 GTK_CONTAINER(child)); \
1852 btn = (GtkWidget *)gchild->data; \
1853 gtkut_widget_set_can_focus(btn, FALSE); \
1854 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1855 gtkut_widget_set_can_focus(arr, FALSE); \
1856 g_list_free(gchild); \
1857 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1858 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1859 g_list_free(gchild); \
1863 #define ADD_MENU_ITEM(name,cb,data) { \
1864 item = gtk_menu_item_new_with_mnemonic(name); \
1865 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); \
1866 g_signal_connect(G_OBJECT(item), "activate", \
1869 g_object_set_data(G_OBJECT(item), "int-value", GINT_TO_POINTER(data)); \
1870 gtk_widget_show(item); \
1873 static void toolbar_reply_menu_cb(GtkWidget *widget, gpointer data)
1875 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1876 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1878 toolbar_reply(toolbar_item, GPOINTER_TO_INT(int_value));
1881 static void toolbar_learn_menu_cb(GtkWidget *widget, gpointer data)
1883 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1884 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1886 toolbar_learn(toolbar_item, GPOINTER_TO_INT(int_value));
1890 * Create a new toolbar with specified type
1891 * if a callback list is passed it will be used before the
1892 * common callback list
1894 Toolbar *toolbar_create(ToolbarType type,
1895 GtkWidget *container,
1898 ToolbarItem *toolbar_item;
1901 GtkWidget *icon_wid = NULL;
1902 GtkWidget *icon_news;
1903 GtkWidget *icon_ham;
1905 ToolbarClawsActions *action_item;
1907 GSList *toolbar_list;
1908 Toolbar *toolbar_data;
1910 #ifndef GENERIC_UMPC
1911 #if !(GTK_CHECK_VERSION(2,12,0))
1912 GtkTooltips *toolbar_tips = gtk_tooltips_new();
1915 toolbar_read_config_file(type);
1916 toolbar_list = toolbar_get_list(type);
1918 toolbar_data = g_new0(Toolbar, 1);
1920 toolbar = gtk_toolbar_new();
1922 #if (GTK_CHECK_VERSION(2,16,0))
1923 gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL);
1925 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1927 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1928 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1930 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1932 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1933 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1937 toolbar_item = g_new0(ToolbarItem, 1);
1938 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1939 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1940 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1941 toolbar_item->parent = data;
1942 toolbar_item->type = type;
1944 /* collect toolbar items in list to keep track */
1945 toolbar_data->item_list =
1946 g_slist_append(toolbar_data->item_list,
1948 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1950 switch (toolbar_item->index) {
1953 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1954 toolbar_data->folders_btn = item;
1957 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1958 _("Receive Mail from all Accounts"),
1959 _("Receive Mail from selected Account"));
1960 toolbar_data->getall_btn = item;
1963 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail from current Account"));
1964 toolbar_data->get_btn = item;
1967 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1968 toolbar_data->send_btn = item;
1971 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1972 toolbar_data->close_window_btn = item;
1975 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open preferences"));
1976 toolbar_data->preferences_btn = item;
1979 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1980 toolbar_data->open_mail_btn = item;
1982 case A_COMPOSE_EMAIL:
1983 #ifndef GENERIC_UMPC
1984 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1986 _("Compose with selected Account"));
1987 toolbar_data->compose_mail_btn = item;
1988 toolbar_data->compose_mail_icon = icon_wid;
1989 g_object_ref(toolbar_data->compose_mail_icon);
1991 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1992 toolbar_data->compose_news_icon = icon_news;
1993 g_object_ref(toolbar_data->compose_news_icon);
1995 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1996 _("Compose Email"));
1997 toolbar_data->compose_mail_btn = item;
1998 toolbar_data->compose_mail_icon = icon_wid;
2000 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
2001 toolbar_data->compose_news_icon = icon_news;
2005 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2008 toolbar_data->learn_spam_btn = item;
2009 toolbar_data->learn_spam_icon = icon_wid;
2010 g_object_ref(toolbar_data->learn_spam_icon);
2012 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
2013 toolbar_data->learn_ham_icon = icon_ham;
2014 g_object_ref(toolbar_data->learn_ham_icon);
2016 menu = gtk_menu_new();
2017 ADD_MENU_ITEM(_("Learn as _Spam"), toolbar_learn_menu_cb, TRUE);
2018 ADD_MENU_ITEM(_("Learn as _Ham"), toolbar_learn_menu_cb, FALSE);
2019 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->learn_spam_btn), menu);
2021 case A_REPLY_MESSAGE:
2022 #ifndef GENERIC_UMPC
2023 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2024 _("Reply to Message"),
2025 _("Reply to Message options"));
2026 toolbar_data->reply_btn = item;
2028 menu = gtk_menu_new();
2029 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITH_QUOTE);
2030 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITHOUT_QUOTE);
2031 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->reply_btn), menu);
2033 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2034 _("Reply to Message"));
2035 toolbar_data->reply_btn = item;
2038 case A_REPLY_SENDER:
2039 #ifndef GENERIC_UMPC
2040 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2041 _("Reply to Sender"),
2042 _("Reply to Sender options"));
2043 toolbar_data->replysender_btn = item;
2045 menu = gtk_menu_new();
2046 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE);
2047 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
2048 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replysender_btn), menu);
2050 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2051 _("Reply to Sender"));
2052 toolbar_data->replysender_btn = item;
2056 #ifndef GENERIC_UMPC
2057 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2059 _("Reply to All options"));
2060 toolbar_data->replyall_btn = item;
2062 menu = gtk_menu_new();
2063 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE);
2064 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
2065 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replyall_btn), menu);
2067 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2069 toolbar_data->replyall_btn = item;
2073 #ifndef GENERIC_UMPC
2074 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2075 _("Reply to Mailing-list"),
2076 _("Reply to Mailing-list options"));
2077 toolbar_data->replylist_btn = item;
2079 menu = gtk_menu_new();
2080 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE);
2081 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
2082 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replylist_btn), menu);
2084 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2085 _("Reply to Mailing-list"));
2086 toolbar_data->replylist_btn = item;
2090 #ifndef GENERIC_UMPC
2091 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2092 _("Forward Message"),
2093 _("Forward Message options"));
2094 toolbar_data->fwd_btn = item;
2096 menu = gtk_menu_new();
2097 ADD_MENU_ITEM(_("_Forward"), toolbar_reply_menu_cb, COMPOSE_FORWARD_INLINE);
2098 ADD_MENU_ITEM(_("For_ward as attachment"), toolbar_reply_menu_cb, COMPOSE_FORWARD_AS_ATTACH);
2099 ADD_MENU_ITEM(_("Redirec_t"), toolbar_reply_menu_cb, COMPOSE_REDIRECT);
2100 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->fwd_btn), menu);
2102 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2103 _("Forward Message"));
2104 toolbar_data->fwd_btn = item;
2108 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
2109 toolbar_data->trash_btn = item;
2112 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
2113 toolbar_data->delete_btn = item;
2116 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
2117 toolbar_data->exec_btn = item;
2120 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
2121 toolbar_data->prev_btn = item;
2124 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
2125 toolbar_data->next_btn = item;
2128 /* Compose Toolbar */
2130 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2131 toolbar_data->send_btn = item;
2134 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2135 toolbar_data->sendl_btn = item;
2138 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2139 toolbar_data->draft_btn = item;
2142 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2143 toolbar_data->insert_btn = item;
2146 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2147 toolbar_data->attach_btn = item;
2150 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2151 toolbar_data->sig_btn = item;
2154 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Replace signature"));
2155 toolbar_data->repsig_btn = item;
2158 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2159 toolbar_data->exteditor_btn = item;
2161 case A_LINEWRAP_CURRENT:
2162 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2163 toolbar_data->linewrap_current_btn = item;
2165 case A_LINEWRAP_ALL:
2166 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2167 toolbar_data->linewrap_all_btn = item;
2170 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2171 toolbar_data->addrbook_btn = item;
2174 case A_CHECK_SPELLING:
2175 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2176 toolbar_data->spellcheck_btn = item;
2180 case A_CLAWS_ACTIONS:
2181 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2182 action_item = g_new0(ToolbarClawsActions, 1);
2183 action_item->widget = item;
2184 action_item->name = g_strdup(toolbar_item->text);
2186 toolbar_data->action_list =
2187 g_slist_append(toolbar_data->action_list,
2191 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2192 toolbar_data->cancel_inc_btn = item;
2195 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel sending"));
2196 toolbar_data->cancel_send_btn = item;
2199 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving/sending"));
2200 toolbar_data->cancel_all_btn = item;
2202 case A_CLAWS_PLUGINS:
2203 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, toolbar_item->text);
2206 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2207 toolbar_ret_descr_from_val(toolbar_item->index));
2208 /* find and set the tool tip text */
2213 toolbar_data->toolbar = toolbar;
2214 #ifndef GENERIC_UMPC
2215 #if !(GTK_CHECK_VERSION(2,12,0))
2216 toolbar_data->tooltips = toolbar_tips;
2219 gtk_widget_show_all(toolbar);
2221 if (type == TOOLBAR_MAIN) {
2223 MainWindow *mainwin = mainwindow_get_mainwindow();
2224 GtkWidget *progressbar = gtk_progress_bar_new();
2225 item = GTK_WIDGET(gtk_tool_item_new());
2226 gtk_container_add (GTK_CONTAINER (item), progressbar);
2227 gtk_widget_show(item);
2228 gtk_widget_set_size_request(progressbar, 84, -1);
2229 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2230 mainwin->progressbar = progressbar;
2232 activate_compose_button(toolbar_data,
2233 prefs_common.toolbar_style,
2234 toolbar_data->compose_btn_type);
2236 if (type != TOOLBAR_COMPOSE)
2237 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2240 gtk_container_add(GTK_CONTAINER(container), toolbar);
2241 gtk_container_set_border_width(GTK_CONTAINER(container), 0);
2243 return toolbar_data;
2247 * Free toolbar structures
2249 void toolbar_destroy(Toolbar * toolbar) {
2251 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2252 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2255 void toolbar_update(ToolbarType type, gpointer data)
2257 Toolbar *toolbar_data;
2258 GtkWidget *handlebox;
2259 MainWindow *mainwin = (MainWindow*)data;
2260 Compose *compose = (Compose*)data;
2261 MessageView *msgview = (MessageView*)data;
2263 #ifndef GENERIC_UMPC
2266 toolbar_data = mainwin->toolbar;
2267 handlebox = mainwin->handlebox;
2269 case TOOLBAR_COMPOSE:
2270 toolbar_data = compose->toolbar;
2271 handlebox = compose->handlebox;
2273 case TOOLBAR_MSGVIEW:
2274 toolbar_data = msgview->toolbar;
2275 handlebox = msgview->handlebox;
2281 gtk_container_remove(GTK_CONTAINER(handlebox),
2282 GTK_WIDGET(toolbar_data->toolbar));
2284 toolbar_init(toolbar_data);
2285 toolbar_data = toolbar_create(type, handlebox, data);
2289 toolbar_data = mainwin->toolbar;
2290 handlebox = mainwin->window;
2292 case TOOLBAR_COMPOSE:
2293 toolbar_data = compose->toolbar;
2294 handlebox = compose->window;
2296 case TOOLBAR_MSGVIEW:
2297 toolbar_data = msgview->toolbar;
2298 handlebox = msgview->window;
2303 toolbar_init(toolbar_data);
2304 toolbar_data = toolbar_create(type, handlebox, data);
2309 mainwin->toolbar = toolbar_data;
2311 case TOOLBAR_COMPOSE:
2312 compose->toolbar = toolbar_data;
2314 case TOOLBAR_MSGVIEW:
2315 msgview->toolbar = toolbar_data;
2319 toolbar_style(type, prefs_common.toolbar_style, data);
2321 if (type == TOOLBAR_MAIN) {
2322 toolbar_main_set_sensitive((MainWindow*)data);
2323 account_set_menu_only_toolbar();
2327 #if !GTK_CHECK_VERSION(2,14,0)
2328 /* Work around http://bugzilla.gnome.org/show_bug.cgi?id=56070 */
2329 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2330 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2331 if (GTK_IS_BUTTON(widget)) \
2332 in_btn1 = GTK_BUTTON(widget)->in_button; \
2333 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2334 GtkWidget *child = gtk_bin_get_child( \
2336 GList *gchild = gtk_container_get_children( \
2337 GTK_CONTAINER(child)); \
2338 GtkWidget *btn = (GtkWidget *)gchild->data; \
2339 GtkWidget *arr = (GtkWidget *) \
2340 (gchild->next?gchild->next->data:NULL); \
2341 g_list_free(gchild); \
2342 if (GTK_IS_BUTTON(btn)) \
2343 in_btn1 = GTK_BUTTON(btn)->in_button; \
2344 if (GTK_IS_BUTTON(arr)) \
2345 in_btn2 = GTK_BUTTON(arr)->in_button; \
2347 else if (GTK_IS_TOOL_ITEM(widget)) { \
2348 GtkWidget *child = gtk_bin_get_child( \
2350 if (GTK_IS_BUTTON(child)) \
2351 in_btn1 = GTK_BUTTON(child)->in_button; \
2353 gtk_widget_set_sensitive(widget, sensitive); \
2354 if (GTK_IS_BUTTON(widget)) \
2355 GTK_BUTTON(widget)->in_button = in_btn1; \
2356 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2357 GtkWidget *child = gtk_bin_get_child( \
2359 GList *gchild = gtk_container_get_children( \
2360 GTK_CONTAINER(child)); \
2361 GtkWidget *btn = (GtkWidget *)gchild->data; \
2362 GtkWidget *arr = (GtkWidget *) \
2363 (gchild->next?gchild->next->data:NULL); \
2364 g_list_free(gchild); \
2365 if (GTK_IS_BUTTON(btn)) \
2366 GTK_BUTTON(btn)->in_button = in_btn1; \
2367 if (GTK_IS_BUTTON(arr)) \
2368 GTK_BUTTON(arr)->in_button = in_btn2; \
2370 else if (GTK_IS_TOOL_ITEM(widget)) { \
2371 GtkWidget *child = gtk_bin_get_child( \
2373 if (GTK_IS_BUTTON(child)) \
2374 GTK_BUTTON(child)->in_button = in_btn1; \
2378 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2379 gtk_widget_set_sensitive(widget, sensitive); \
2383 void toolbar_main_set_sensitive(gpointer data)
2385 SensitiveCondMask state;
2387 MainWindow *mainwin = (MainWindow*)data;
2388 Toolbar *toolbar = mainwin->toolbar;
2390 GSList *entry_list = NULL;
2392 typedef struct _Entry Entry;
2395 SensitiveCondMask cond;
2399 #define SET_WIDGET_COND(w, ...) \
2401 Entry *e = g_new0(Entry, 1); \
2403 e->cond = main_window_get_mask(__VA_ARGS__, -1); \
2404 entry_list = g_slist_append(entry_list, e); \
2407 /* match all bit flags */
2409 if (toolbar->get_btn)
2410 SET_WIDGET_COND(toolbar->get_btn,
2411 M_HAVE_ACCOUNT, M_UNLOCKED, M_HAVE_RETRIEVABLE_ACCOUNT);
2413 if (toolbar->getall_btn) {
2414 SET_WIDGET_COND(toolbar->getall_btn,
2415 M_HAVE_ACCOUNT, M_UNLOCKED, M_HAVE_ANY_RETRIEVABLE_ACCOUNT);
2417 if (toolbar->send_btn) {
2418 SET_WIDGET_COND(toolbar->send_btn,
2419 M_HAVE_QUEUED_MAILS);
2421 if (toolbar->compose_mail_btn) {
2422 SET_WIDGET_COND(toolbar->compose_mail_btn,
2425 if (toolbar->close_window_btn) {
2426 SET_WIDGET_COND(toolbar->close_window_btn,
2429 if (toolbar->open_mail_btn) {
2430 SET_WIDGET_COND(toolbar->open_mail_btn,
2431 M_TARGET_EXIST, M_SUMMARY_ISLIST);
2433 if (toolbar->reply_btn) {
2434 SET_WIDGET_COND(toolbar->reply_btn,
2435 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2437 if (toolbar->replyall_btn) {
2438 SET_WIDGET_COND(toolbar->replyall_btn,
2439 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2441 if (toolbar->replylist_btn) {
2442 SET_WIDGET_COND(toolbar->replylist_btn,
2443 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2445 if (toolbar->replysender_btn) {
2446 SET_WIDGET_COND(toolbar->replysender_btn,
2447 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2449 if (toolbar->fwd_btn) {
2450 SET_WIDGET_COND(toolbar->fwd_btn,
2451 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2454 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2455 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST, M_SUMMARY_ISLIST);
2457 SET_WIDGET_COND(toolbar->next_btn, -1);
2460 if (toolbar->trash_btn)
2461 SET_WIDGET_COND(toolbar->trash_btn,
2462 M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS);
2464 if (toolbar->delete_btn)
2465 SET_WIDGET_COND(toolbar->delete_btn,
2466 M_TARGET_EXIST, M_ALLOW_DELETE);
2468 if (toolbar->exec_btn)
2469 SET_WIDGET_COND(toolbar->exec_btn,
2472 if (toolbar->learn_spam_btn)
2473 SET_WIDGET_COND(toolbar->learn_spam_btn,
2474 M_TARGET_EXIST, M_CAN_LEARN_SPAM, M_SUMMARY_ISLIST);
2476 if (toolbar->cancel_inc_btn)
2477 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2480 if (toolbar->cancel_send_btn)
2481 SET_WIDGET_COND(toolbar->cancel_send_btn,
2484 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2485 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2487 SET_WIDGET_COND(act->widget, M_TARGET_EXIST, M_UNLOCKED);
2490 state = main_window_get_current_state(mainwin);
2492 for (cur = entry_list; cur != NULL; cur = cur->next) {
2493 Entry *e = (Entry*) cur->data;
2495 if (e->widget != NULL) {
2496 sensitive = ((e->cond & state) == e->cond);
2497 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2501 while (entry_list != NULL) {
2502 Entry *e = (Entry*) entry_list->data;
2505 entry_list = g_slist_remove(entry_list, e);
2508 /* match any bit flags */
2510 if (toolbar->cancel_all_btn)
2511 SET_WIDGET_COND(toolbar->cancel_all_btn,
2512 M_INC_ACTIVE, M_SEND_ACTIVE);
2514 for (cur = entry_list; cur != NULL; cur = cur->next) {
2515 Entry *e = (Entry*) cur->data;
2517 if (e->widget != NULL) {
2518 sensitive = ((e->cond & state) != 0);
2519 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2523 while (entry_list != NULL) {
2524 Entry *e = (Entry*) entry_list->data;
2527 entry_list = g_slist_remove(entry_list, e);
2530 g_slist_free(entry_list);
2532 activate_compose_button(toolbar,
2533 prefs_common.toolbar_style,
2534 toolbar->compose_btn_type);
2536 #undef SET_WIDGET_COND
2539 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2541 Compose *compose = (Compose*)data;
2542 GSList *items = compose->toolbar->action_list;
2544 if (compose->toolbar->send_btn)
2545 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2546 if (compose->toolbar->sendl_btn)
2547 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2548 if (compose->toolbar->draft_btn )
2549 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2550 if (compose->toolbar->insert_btn )
2551 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2552 if (compose->toolbar->attach_btn)
2553 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2554 if (compose->toolbar->sig_btn)
2555 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2556 if (compose->toolbar->repsig_btn)
2557 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->repsig_btn, sensitive);
2558 if (compose->toolbar->exteditor_btn)
2559 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2560 if (compose->toolbar->linewrap_current_btn)
2561 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2562 if (compose->toolbar->linewrap_all_btn)
2563 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2564 if (compose->toolbar->addrbook_btn)
2565 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2567 if (compose->toolbar->spellcheck_btn)
2568 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2570 for (; items != NULL; items = g_slist_next(items)) {
2571 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2572 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2577 * Initialize toolbar structure
2579 static void toolbar_init(Toolbar * toolbar)
2582 toolbar->toolbar = NULL;
2583 toolbar->folders_btn = NULL;
2584 toolbar->get_btn = NULL;
2585 toolbar->getall_btn = NULL;
2586 toolbar->send_btn = NULL;
2587 toolbar->compose_mail_btn = NULL;
2588 toolbar->compose_mail_icon = NULL;
2589 toolbar->compose_news_icon = NULL;
2590 toolbar->reply_btn = NULL;
2591 toolbar->replysender_btn = NULL;
2592 toolbar->replyall_btn = NULL;
2593 toolbar->replylist_btn = NULL;
2594 toolbar->fwd_btn = NULL;
2595 toolbar->trash_btn = NULL;
2596 toolbar->delete_btn = NULL;
2597 toolbar->prev_btn = NULL;
2598 toolbar->next_btn = NULL;
2599 toolbar->exec_btn = NULL;
2600 toolbar->separator = NULL;
2601 toolbar->learn_spam_btn = NULL;
2602 toolbar->learn_spam_icon = NULL;
2603 toolbar->learn_ham_icon = NULL;
2604 toolbar->cancel_inc_btn = NULL;
2605 toolbar->cancel_send_btn = NULL;
2606 toolbar->cancel_all_btn = NULL;
2608 /* compose buttons */
2609 toolbar->sendl_btn = NULL;
2610 toolbar->draft_btn = NULL;
2611 toolbar->insert_btn = NULL;
2612 toolbar->attach_btn = NULL;
2613 toolbar->sig_btn = NULL;
2614 toolbar->repsig_btn = NULL;
2615 toolbar->exteditor_btn = NULL;
2616 toolbar->linewrap_current_btn = NULL;
2617 toolbar->linewrap_all_btn = NULL;
2618 toolbar->addrbook_btn = NULL;
2620 toolbar->open_mail_btn = NULL;
2621 toolbar->close_window_btn = NULL;
2622 toolbar->preferences_btn = NULL;
2623 toolbar->action_list = NULL;
2624 toolbar->item_list = NULL;
2626 toolbar->spellcheck_btn = NULL;
2628 #if !GTK_CHECK_VERSION(2,12,0)
2629 toolbar->tooltips = NULL;
2632 toolbar_destroy(toolbar);
2637 static void toolbar_reply(gpointer data, guint action)
2639 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2640 MainWindow *mainwin;
2641 MessageView *msgview;
2642 GSList *msginfo_list = NULL;
2644 cm_return_if_fail(toolbar_item != NULL);
2646 switch (toolbar_item->type) {
2648 mainwin = (MainWindow*)toolbar_item->parent;
2649 msginfo_list = summary_get_selection(mainwin->summaryview);
2650 msgview = (MessageView*)mainwin->messageview;
2652 case TOOLBAR_MSGVIEW:
2653 msgview = (MessageView*)toolbar_item->parent;
2654 cm_return_if_fail(msgview != NULL);
2655 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2661 cm_return_if_fail(msgview != NULL);
2662 cm_return_if_fail(msginfo_list != NULL);
2663 compose_reply_from_messageview(msgview, msginfo_list, action);
2664 g_slist_free(msginfo_list);
2666 /* TODO: update reply state ion summaryview */
2670 /* exported functions */
2672 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2674 MainWindow *mainwin = (MainWindow*)data;
2676 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2679 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2681 MainWindow *mainwin = (MainWindow*)data;
2683 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2686 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2690 gboolean got_error = FALSE;
2691 gchar *errstr = NULL;
2693 if (prefs_common.work_offline)
2694 if (alertpanel(_("Offline warning"),
2695 _("You're working offline. Override?"),
2696 GTK_STOCK_NO, GTK_STOCK_YES,
2697 NULL) != G_ALERTALTERNATE)
2700 /* ask for confirmation before sending queued messages only
2701 in online mode and if there is at least one message queued
2702 in any of the folder queue
2704 if (prefs_common.confirm_send_queued_messages) {
2706 /* check if there's a queued message */
2707 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2708 Folder *folder = list->data;
2710 found = !procmsg_queue_is_empty(folder->queue);
2712 /* if necessary, ask for confirmation before sending */
2713 if (found && !prefs_common.work_offline) {
2714 if (alertpanel(_("Send queued messages"),
2715 _("Send all queued messages?"),
2716 GTK_STOCK_CANCEL, _("_Send"),
2717 NULL) != G_ALERTALTERNATE)
2722 for (list = folder_get_list(); list != NULL; list = list->next) {
2723 Folder *folder = list->data;
2725 if (folder->queue) {
2726 if (procmsg_send_queue(folder->queue,
2727 prefs_common.savemsg,
2734 alertpanel_error_log(_("Some errors occurred while "
2735 "sending queued messages."));
2737 alertpanel_error_log(_("Some errors occurred "
2738 "while sending queued messages:\n%s"), errstr);
2744 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2746 MainWindow *mainwin = (MainWindow*)data;
2747 PrefsAccount *ac = NULL;
2748 FolderItem *item = mainwin->summaryview->folder_item;
2753 ac = account_find_from_item(item);
2754 if (ac && ac->protocol != A_NNTP) {
2755 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2761 * CLAWS - use current account
2763 if (cur_account && (cur_account->protocol != A_NNTP)) {
2764 compose_new_with_folderitem(cur_account, item, NULL);
2769 * CLAWS - just get the first one
2771 list = account_get_list();
2772 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2773 ac = (PrefsAccount *) cur->data;
2774 if (ac->protocol != A_NNTP) {
2775 compose_new_with_folderitem(ac, item, NULL);
2781 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2783 MainWindow *mainwin = (MainWindow*)data;
2784 PrefsAccount * ac = NULL;
2788 if (mainwin->summaryview->folder_item) {
2789 ac = mainwin->summaryview->folder_item->folder->account;
2790 if (ac && ac->protocol == A_NNTP) {
2791 compose_new_with_folderitem(ac,
2792 mainwin->summaryview->folder_item, NULL);
2797 list = account_get_list();
2798 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2799 ac = (PrefsAccount *) cur->data;
2800 if (ac->protocol == A_NNTP) {
2801 compose_new_with_folderitem(ac,
2802 mainwin->summaryview->folder_item, NULL);