2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2007 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * General functions for accessing address book files.
31 #include <glib/gi18n.h>
40 #include "mainwindow.h"
41 #include "summaryview.h"
46 #include "prefs_gtk.h"
48 #include "stock_pixmap.h"
49 #include "manage_window.h"
55 #include "prefs_actions.h"
56 #include "prefs_common.h"
57 #include "prefs_toolbar.h"
58 #include "alertpanel.h"
62 #define TOOLBAR_TAG_INDEX "toolbar"
63 #define TOOLBAR_TAG_ITEM "item"
64 #define TOOLBAR_TAG_SEPARATOR "separator"
66 #define TOOLBAR_ICON_FILE "file"
67 #define TOOLBAR_ICON_TEXT "text"
68 #define TOOLBAR_ICON_ACTION "action"
70 static void toolbar_init(Toolbar * toolbar);
71 static gboolean toolbar_is_duplicate (gint action,
73 static void toolbar_parse_item (XMLFile *file,
76 static gint toolbar_ret_val_from_text (const gchar *text);
77 static gchar *toolbar_ret_text_from_val (gint val);
79 static void toolbar_set_default_main (void);
80 static void toolbar_set_default_compose (void);
81 static void toolbar_set_default_msgview (void);
83 static void toolbar_style (ToolbarType type,
87 static MainWindow *get_mainwin (gpointer data);
88 static void activate_compose_button (Toolbar *toolbar,
90 ComposeButtonType type);
92 /* toolbar callbacks */
93 static void toolbar_reply (gpointer data,
95 static void toolbar_learn (gpointer data,
97 static void toolbar_delete_cb (GtkWidget *widget,
99 static void toolbar_trash_cb (GtkWidget *widget,
102 static void toolbar_compose_cb (GtkWidget *widget,
105 static void toolbar_learn_cb (GtkWidget *widget,
108 static void toolbar_reply_cb (GtkWidget *widget,
111 static void toolbar_reply_to_all_cb (GtkWidget *widget,
114 static void toolbar_reply_to_list_cb (GtkWidget *widget,
117 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
120 static void toolbar_forward_cb (GtkWidget *widget,
123 static void toolbar_prev_unread_cb (GtkWidget *widget,
125 static void toolbar_next_unread_cb (GtkWidget *widget,
128 static void toolbar_ignore_thread_cb (GtkWidget *widget,
131 static void toolbar_watch_thread_cb (GtkWidget *widget,
134 static void toolbar_print_cb (GtkWidget *widget,
137 static void toolbar_actions_execute_cb (GtkWidget *widget,
141 static void toolbar_send_cb (GtkWidget *widget,
143 static void toolbar_send_later_cb (GtkWidget *widget,
145 static void toolbar_draft_cb (GtkWidget *widget,
147 static void toolbar_close_cb (GtkWidget *widget,
149 static void toolbar_open_mail_cb (GtkWidget *widget,
151 static void toolbar_insert_cb (GtkWidget *widget,
153 static void toolbar_attach_cb (GtkWidget *widget,
155 static void toolbar_sig_cb (GtkWidget *widget,
157 static void toolbar_ext_editor_cb (GtkWidget *widget,
159 static void toolbar_linewrap_current_cb (GtkWidget *widget,
161 static void toolbar_linewrap_all_cb (GtkWidget *widget,
163 static void toolbar_addrbook_cb (GtkWidget *widget,
166 static void toolbar_check_spelling_cb (GtkWidget *widget,
169 static void toolbar_cancel_inc_cb (GtkWidget *widget,
175 } toolbar_text [] = {
176 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
177 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
178 { "A_SEND_QUEUED", N_("Send Queued Messages") },
179 { "A_COMPOSE_EMAIL", N_("Compose Email") },
180 { "A_COMPOSE_NEWS", N_("Compose News") },
181 { "A_REPLY_MESSAGE", N_("Reply to Message") },
182 { "A_REPLY_SENDER", N_("Reply to Sender") },
183 { "A_REPLY_ALL", N_("Reply to All") },
184 { "A_REPLY_ML", N_("Reply to Mailing-list") },
185 { "A_OPEN_MAIL", N_("Open email") },
186 { "A_FORWARD", N_("Forward Message") },
187 { "A_TRASH", N_("Trash Message") },
188 { "A_DELETE_REAL", N_("Delete Message") },
189 { "A_EXECUTE", N_("Execute") },
190 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
191 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
192 { "A_IGNORE_THREAD", N_("Ignore thread") },
193 { "A_WATCH_THREAD", N_("Watch thread") },
194 { "A_PRINT", N_("Print") },
195 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
196 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
198 { "A_SEND", N_("Send Message") },
199 { "A_SENDL", N_("Put into queue folder and send later") },
200 { "A_DRAFT", N_("Save to draft folder") },
201 { "A_INSERT", N_("Insert file") },
202 { "A_ATTACH", N_("Attach file") },
203 { "A_SIG", N_("Insert signature") },
204 { "A_EXTEDITOR", N_("Edit with external editor") },
205 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
206 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
207 { "A_ADDRBOOK", N_("Address book") },
209 { "A_CHECK_SPELLING", N_("Check spelling") },
211 { "A_SYL_ACTIONS", N_("Claws Mail Actions Feature") },
212 { "A_CANCEL_INC", N_("Cancel receiving") },
213 { "A_CLOSE", N_("Close window") },
214 { "A_SEPARATOR", "Separator" }
217 /* struct holds configuration files and a list of
218 * currently active toolbar items
219 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
223 const gchar *conf_file;
225 } toolbar_config[3] = {
226 { "toolbar_main.xml", NULL},
227 { "toolbar_compose.xml", NULL},
228 { "toolbar_msgview.xml", NULL}
231 static GtkItemFactoryEntry reply_entries[] =
233 {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
234 {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
236 static GtkItemFactoryEntry replyall_entries[] =
238 {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
239 {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
241 static GtkItemFactoryEntry replylist_entries[] =
243 {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
244 {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
246 static GtkItemFactoryEntry replysender_entries[] =
248 {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
249 {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
251 static GtkItemFactoryEntry forward_entries[] =
253 {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
254 {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
255 {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, NULL}
258 static GtkItemFactoryEntry learn_entries[] =
260 {N_("/Learn as _Spam"), NULL, toolbar_learn, TRUE, NULL},
261 {N_("/Learn as _Ham"), NULL, toolbar_learn, FALSE, NULL}
265 gint toolbar_ret_val_from_descr(const gchar *descr)
269 for (i = 0; i < N_ACTION_VAL; i++) {
270 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
277 gchar *toolbar_ret_descr_from_val(gint val)
279 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
281 return gettext(toolbar_text[val].descr);
284 static gint toolbar_ret_val_from_text(const gchar *text)
288 for (i = 0; i < N_ACTION_VAL; i++) {
289 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
296 static gchar *toolbar_ret_text_from_val(gint val)
298 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
300 return toolbar_text[val].index_str;
303 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
307 if ((action == A_SEPARATOR) || (action == A_CLAWS_ACTIONS))
310 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
311 ToolbarItem *item = (ToolbarItem*) cur->data;
313 if (item->index == action)
319 /* depending on toolbar type this function
320 returns a list of available toolbar events being
321 displayed by prefs_toolbar
323 GList *toolbar_get_action_items(ToolbarType source)
328 if (source == TOOLBAR_MAIN) {
329 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
330 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
331 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
332 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
333 A_GOTO_NEXT, A_IGNORE_THREAD, A_WATCH_THREAD, A_PRINT,
334 A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
337 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
338 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
341 else if (source == TOOLBAR_COMPOSE) {
342 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
343 A_INSERT, A_ATTACH, A_SIG,
344 A_EXTEDITOR, A_LINEWRAP_CURRENT,
345 A_LINEWRAP_ALL, A_ADDRBOOK,
351 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
352 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
354 else if (source == TOOLBAR_MSGVIEW) {
355 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
356 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
357 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
358 A_ADDRBOOK, A_LEARN_SPAM, A_CLOSE };
360 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
361 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
367 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
371 ToolbarItem *item = NULL;
372 gboolean rewrite = FALSE;
374 attr = xml_get_current_tag_attr(file);
375 item = g_new0(ToolbarItem, 1);
377 name = ((XMLAttr *)attr->data)->name;
378 value = ((XMLAttr *)attr->data)->value;
380 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
381 item->file = g_strdup (value);
382 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
383 item->text = g_strdup (gettext(value));
384 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
385 item->index = toolbar_ret_val_from_text(value);
386 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
388 item->index = A_TRASH;
390 item->file = g_strdup("trash_btn");
392 item->text = g_strdup(_("Trash"));
395 attr = g_list_next(attr);
397 if (item->index != -1) {
399 if (!toolbar_is_duplicate(item->index, source))
400 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
404 toolbar_save_config_file(source);
408 const gchar *toolbar_get_short_text(int action) {
410 case A_GO_FOLDERS: return _("Folders");
411 case A_OPEN_MAIL: return _("Open");
412 case A_RECEIVE_ALL: return _("Get Mail");
413 case A_RECEIVE_CUR: return _("Get");
414 case A_SEND_QUEUED: return _("Send");
415 case A_COMPOSE_EMAIL: return Q_("Toolbar|Compose");
416 case A_COMPOSE_NEWS: return Q_("Toolbar|Compose");
417 case A_REPLY_MESSAGE: return _("Reply");
418 case A_REPLY_ALL: return _("All");
419 case A_REPLY_SENDER: return _("Sender");
420 case A_REPLY_ML: return _("List");
421 case A_FORWARD: return _("Forward");
422 case A_TRASH: return _("Trash");
423 case A_DELETE_REAL: return _("Delete");
424 case A_LEARN_SPAM: return _("Spam");
425 case A_GOTO_PREV: return _("Prev");
426 case A_GOTO_NEXT: return _("Next");
427 case A_IGNORE_THREAD: return _("Ignore thread");
428 case A_WATCH_THREAD: return _("Watch thread");
429 case A_PRINT: return _("Print");
430 case A_CLOSE: return _("Close");
431 case A_SEND: return _("Send");
432 case A_SENDL: return _("Send later");
433 case A_DRAFT: return _("Draft");
434 case A_INSERT: return _("Insert");
435 case A_ATTACH: return _("Attach");
436 case A_SIG: return _("Insert sig.");
437 case A_EXTEDITOR: return _("Edit");
438 case A_LINEWRAP_CURRENT:return _("Wrap para.");
439 case A_LINEWRAP_ALL: return _("Wrap all");
440 case A_ADDRBOOK: return _("Address");
441 case A_CANCEL_INC: return _("Stop");
442 case A_EXECUTE: return _("Execute");
444 case A_CHECK_SPELLING: return _("Check spelling");
450 gint toolbar_get_icon(int action) {
452 case A_GO_FOLDERS: return STOCK_PIXMAP_GO_FOLDERS;
453 case A_OPEN_MAIL: return STOCK_PIXMAP_OPEN_MAIL;
454 case A_RECEIVE_ALL: return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
455 case A_RECEIVE_CUR: return STOCK_PIXMAP_MAIL_RECEIVE;
456 case A_SEND_QUEUED: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
457 case A_COMPOSE_EMAIL: return STOCK_PIXMAP_MAIL_COMPOSE;
458 case A_COMPOSE_NEWS: return STOCK_PIXMAP_NEWS_COMPOSE;
459 case A_REPLY_MESSAGE: return STOCK_PIXMAP_MAIL_REPLY;
460 case A_REPLY_ALL: return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
461 case A_REPLY_SENDER: return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
462 case A_REPLY_ML: return STOCK_PIXMAP_MAIL_REPLY;
463 case A_FORWARD: return STOCK_PIXMAP_MAIL_FORWARD;
464 case A_TRASH: return STOCK_PIXMAP_TRASH;
465 case A_DELETE_REAL: return STOCK_PIXMAP_DELETED;
466 case A_LEARN_SPAM: return STOCK_PIXMAP_SPAM_BTN;
467 case A_GOTO_PREV: return STOCK_PIXMAP_UP_ARROW;
468 case A_GOTO_NEXT: return STOCK_PIXMAP_DOWN_ARROW;
469 case A_IGNORE_THREAD: return STOCK_PIXMAP_IGNORETHREAD;
470 case A_WATCH_THREAD: return STOCK_PIXMAP_WATCHTHREAD;
471 case A_PRINT: return STOCK_PIXMAP_PRINTER;
472 case A_CLOSE: return STOCK_PIXMAP_CLOSE;
473 case A_SEND: return STOCK_PIXMAP_MAIL_SEND;
474 case A_SENDL: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
475 case A_DRAFT: return STOCK_PIXMAP_MAIL;
476 case A_INSERT: return STOCK_PIXMAP_INSERT_FILE;
477 case A_ATTACH: return STOCK_PIXMAP_MAIL_ATTACH;
478 case A_SIG: return STOCK_PIXMAP_MAIL_SIGN;
479 case A_EXTEDITOR: return STOCK_PIXMAP_EDIT_EXTERN;
480 case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
481 case A_LINEWRAP_ALL: return STOCK_PIXMAP_LINEWRAP_ALL;
482 case A_ADDRBOOK: return STOCK_PIXMAP_ADDRESS_BOOK;
483 case A_CANCEL_INC: return STOCK_PIXMAP_NOTICE_ERROR;
484 case A_EXECUTE: return STOCK_PIXMAP_EXEC;
486 case A_CHECK_SPELLING: return STOCK_PIXMAP_CHECK_SPELLING;
492 static void toolbar_set_default_main(void)
496 } default_toolbar[] = {
516 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
526 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
528 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
530 if (default_toolbar[i].action != A_SEPARATOR) {
532 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
534 toolbar_item->file = g_strdup(file);
535 toolbar_item->index = default_toolbar[i].action;
536 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
539 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
540 toolbar_item->index = A_SEPARATOR;
543 if (toolbar_item->index != -1) {
544 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
545 toolbar_config[TOOLBAR_MAIN].item_list =
546 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
551 static void toolbar_set_default_compose(void)
555 } default_toolbar[] = {
574 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
576 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
578 if (default_toolbar[i].action != A_SEPARATOR) {
580 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
582 toolbar_item->file = g_strdup(file);
583 toolbar_item->index = default_toolbar[i].action;
584 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
587 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
588 toolbar_item->index = A_SEPARATOR;
591 if (toolbar_item->index != -1) {
592 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
593 toolbar_config[TOOLBAR_COMPOSE].item_list =
594 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
599 static void toolbar_set_default_msgview(void)
603 } default_toolbar[] = {
615 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
624 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
626 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
628 if (default_toolbar[i].action != A_SEPARATOR) {
630 gchar *file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
632 toolbar_item->file = g_strdup(file);
633 toolbar_item->index = default_toolbar[i].action;
634 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
637 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
638 toolbar_item->index = A_SEPARATOR;
641 if (toolbar_item->index != -1) {
642 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
643 toolbar_config[TOOLBAR_MSGVIEW].item_list =
644 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
649 void toolbar_set_default(ToolbarType source)
651 if (source == TOOLBAR_MAIN)
652 toolbar_set_default_main();
653 else if (source == TOOLBAR_COMPOSE)
654 toolbar_set_default_compose();
655 else if (source == TOOLBAR_MSGVIEW)
656 toolbar_set_default_msgview();
659 void toolbar_save_config_file(ToolbarType source)
664 gchar *fileSpec = NULL;
666 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
668 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
669 pfile = prefs_write_open(fileSpec);
672 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
675 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
678 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
679 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
681 if (toolbar_item->index != A_SEPARATOR) {
682 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
684 TOOLBAR_ICON_FILE, toolbar_item->file,
685 TOOLBAR_ICON_TEXT) < 0)
687 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
689 if (fprintf(fp, "\" %s=\"%s\"/>\n",
691 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
694 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
699 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
703 if (prefs_file_close (pfile) < 0 )
704 g_warning("failed to write toolbar configuration to file\n");
708 FILE_OP_ERROR(fileSpec, "fprintf");
710 prefs_file_close_revert (pfile);
712 g_warning("failed to open toolbar configuration file for writing\n");
715 void toolbar_read_config_file(ToolbarType source)
717 XMLFile *file = NULL;
718 gchar *fileSpec = NULL;
723 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
725 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
726 file = xml_open_file(fileSpec);
729 toolbar_clear_list(source);
733 || (xml_get_dtd(file))
734 || (xml_parse_next_tag(file))
735 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
736 xml_close_file(file);
740 attr = xml_get_current_tag_attr(file);
747 if (xml_parse_next_tag(file))
750 /* Get next tag (icon, icon_text or icon_action) */
751 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
752 toolbar_parse_item(file, source);
753 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
754 ToolbarItem *item = g_new0(ToolbarItem, 1);
756 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
757 item->index = A_SEPARATOR;
758 toolbar_config[source].item_list =
759 g_slist_append(toolbar_config[source].item_list, item);
763 xml_close_file(file);
766 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
768 if (source == TOOLBAR_MAIN)
769 toolbar_set_default(TOOLBAR_MAIN);
770 else if (source == TOOLBAR_COMPOSE)
771 toolbar_set_default(TOOLBAR_COMPOSE);
772 else if (source == TOOLBAR_MSGVIEW)
773 toolbar_set_default(TOOLBAR_MSGVIEW);
775 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
779 toolbar_save_config_file(source);
784 * clears list of toolbar items read from configuration files
786 void toolbar_clear_list(ToolbarType source)
788 while (toolbar_config[source].item_list != NULL) {
789 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
791 toolbar_config[source].item_list =
792 g_slist_remove(toolbar_config[source].item_list, item);
798 g_slist_free(toolbar_config[source].item_list);
803 * return list of Toolbar items
805 GSList *toolbar_get_list(ToolbarType source)
809 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
810 list = toolbar_config[source].item_list;
815 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
817 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
819 toolbar_item->file = g_strdup(t_item->file);
820 toolbar_item->text = g_strdup(t_item->text);
821 toolbar_item->index = t_item->index;
823 toolbar_config[source].item_list =
824 g_slist_append(toolbar_config[source].item_list,
828 static void toolbar_action_execute(GtkWidget *widget,
834 gchar *action, *action_p;
835 gboolean found = FALSE;
838 for (cur = action_list; cur != NULL; cur = cur->next) {
839 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
841 if (widget == act->widget) {
843 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
844 action = g_strdup((gchar*)lop->data);
846 action_p = strstr(action, ": ");
848 if (g_utf8_collate(act->name, action) == 0) {
862 actions_execute(data, i, widget, source);
864 g_warning ("Error: did not find Claws Action to execute");
867 static void activate_compose_button (Toolbar *toolbar,
869 ComposeButtonType type)
871 if ((!toolbar->compose_mail_btn))
874 if (type == COMPOSEBUTTON_NEWS) {
875 gtk_tool_button_set_icon_widget(
876 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
877 toolbar->compose_news_icon);
879 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->compose_mail_btn), GTK_TOOLTIPS(toolbar->tooltips),
880 _("Compose News message"), NULL);
882 gtk_widget_show(toolbar->compose_news_icon);
884 gtk_tool_button_set_icon_widget(
885 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
886 toolbar->compose_mail_icon);
888 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->compose_mail_btn), GTK_TOOLTIPS(toolbar->tooltips),
889 _("Compose Email"), NULL);
891 gtk_widget_show(toolbar->compose_mail_icon);
893 toolbar->compose_btn_type = type;
896 void toolbar_set_compose_button(Toolbar *toolbar,
897 ComposeButtonType compose_btn_type)
899 if (toolbar->compose_btn_type != compose_btn_type)
900 activate_compose_button(toolbar,
901 prefs_common.toolbar_style,
905 static void activate_learn_button (Toolbar *toolbar,
907 LearnButtonType type)
909 if ((!toolbar->learn_spam_btn))
912 if (type == LEARN_SPAM) {
913 gtk_tool_button_set_icon_widget(
914 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
915 toolbar->learn_spam_icon);
916 gtk_tool_button_set_label(
917 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
920 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->learn_spam_btn), GTK_TOOLTIPS(toolbar->tooltips),
921 _("Learn spam"), NULL);
923 gtk_widget_show(toolbar->learn_spam_icon);
925 gtk_tool_button_set_icon_widget(
926 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
927 toolbar->learn_ham_icon);
928 gtk_tool_button_set_label(
929 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
932 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(toolbar->learn_spam_btn), GTK_TOOLTIPS(toolbar->tooltips),
933 _("Learn ham"), NULL);
935 gtk_widget_show(toolbar->learn_ham_icon);
937 toolbar->learn_btn_type = type;
940 void toolbar_set_learn_button(Toolbar *toolbar,
941 LearnButtonType learn_btn_type)
943 if (toolbar->learn_btn_type != learn_btn_type)
944 activate_learn_button(toolbar,
945 prefs_common.toolbar_style,
949 void toolbar_toggle(guint action, gpointer data)
951 MainWindow *mainwin = (MainWindow*)data;
955 g_return_if_fail(mainwin != NULL);
957 toolbar_style(TOOLBAR_MAIN, action, mainwin);
959 list = compose_get_compose_list();
960 for (cur = list; cur != NULL; cur = cur->next) {
961 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
963 list = messageview_get_msgview_list();
964 for (cur = list; cur != NULL; cur = cur->next) {
965 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
970 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
972 switch ((ToolbarStyle)action) {
974 gtk_widget_hide(handlebox_wid);
977 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
981 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
985 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
988 case TOOLBAR_BOTH_HORIZ:
989 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
990 GTK_TOOLBAR_BOTH_HORIZ);
996 prefs_common.toolbar_style = (ToolbarStyle)action;
997 gtk_widget_set_size_request(handlebox_wid, 1, -1);
999 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1000 gtk_widget_show(handlebox_wid);
1001 gtk_widget_queue_resize(handlebox_wid);
1005 * Change the style of toolbar
1007 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1009 GtkWidget *handlebox_wid;
1010 GtkWidget *toolbar_wid;
1011 MainWindow *mainwin = (MainWindow*)data;
1012 Compose *compose = (Compose*)data;
1013 MessageView *msgview = (MessageView*)data;
1015 g_return_if_fail(data != NULL);
1019 handlebox_wid = mainwin->handlebox;
1020 toolbar_wid = mainwin->toolbar->toolbar;
1022 case TOOLBAR_COMPOSE:
1023 handlebox_wid = compose->handlebox;
1024 toolbar_wid = compose->toolbar->toolbar;
1026 case TOOLBAR_MSGVIEW:
1027 handlebox_wid = msgview->handlebox;
1028 toolbar_wid = msgview->toolbar->toolbar;
1034 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1037 /* Toolbar handling */
1038 static void toolbar_inc_cb(GtkWidget *widget,
1041 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1042 MainWindow *mainwin;
1044 g_return_if_fail(toolbar_item != NULL);
1046 switch (toolbar_item->type) {
1048 mainwin = (MainWindow*)toolbar_item->parent;
1049 inc_mail_cb(mainwin, 0, NULL);
1056 static void toolbar_inc_all_cb(GtkWidget *widget,
1059 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1060 MainWindow *mainwin;
1062 g_return_if_fail(toolbar_item != NULL);
1064 switch (toolbar_item->type) {
1066 mainwin = (MainWindow*)toolbar_item->parent;
1067 inc_all_account_mail_cb(mainwin, 0, NULL);
1074 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1076 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1077 MainWindow *mainwin;
1079 g_return_if_fail(toolbar_item != NULL);
1081 switch (toolbar_item->type) {
1083 mainwin = (MainWindow*)toolbar_item->parent;
1084 send_queue_cb(mainwin, 0, NULL);
1091 static void toolbar_exec_cb(GtkWidget *widget,
1094 MainWindow *mainwin = get_mainwin(data);
1096 g_return_if_fail(mainwin != NULL);
1097 summary_execute(mainwin->summaryview);
1101 * Delete current/selected(s) message(s)
1103 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1105 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1106 MainWindow *mainwin;
1108 g_return_if_fail(toolbar_item != NULL);
1109 g_return_if_fail(toolbar_item->parent);
1111 switch (toolbar_item->type) {
1112 case TOOLBAR_MSGVIEW:
1113 messageview_delete((MessageView *)toolbar_item->parent);
1116 mainwin = (MainWindow *)toolbar_item->parent;
1117 summary_delete_trash(mainwin->summaryview);
1120 debug_print("toolbar event not supported\n");
1126 * Delete current/selected(s) message(s)
1128 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1130 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1131 MainWindow *mainwin;
1133 g_return_if_fail(toolbar_item != NULL);
1134 g_return_if_fail(toolbar_item->parent);
1136 switch (toolbar_item->type) {
1137 case TOOLBAR_MSGVIEW:
1138 messageview_delete((MessageView *)toolbar_item->parent);
1141 mainwin = (MainWindow *)toolbar_item->parent;
1142 summary_delete(mainwin->summaryview);
1145 debug_print("toolbar event not supported\n");
1152 * Compose new message
1154 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1156 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1157 MainWindow *mainwin;
1158 MessageView *msgview;
1160 g_return_if_fail(toolbar_item != NULL);
1162 switch (toolbar_item->type) {
1164 mainwin = (MainWindow*)toolbar_item->parent;
1165 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1166 compose_news_cb(mainwin, 0, NULL);
1168 compose_mail_cb(mainwin, 0, NULL);
1170 case TOOLBAR_MSGVIEW:
1171 msgview = (MessageView*)toolbar_item->parent;
1172 compose_new_with_folderitem(NULL,
1173 msgview->msginfo->folder, NULL);
1176 debug_print("toolbar event not supported\n");
1180 static void toolbar_learn(gpointer data, guint as_spam)
1182 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1183 MainWindow *mainwin;
1184 MessageView *msgview;
1186 g_return_if_fail(toolbar_item != NULL);
1188 switch (toolbar_item->type) {
1190 mainwin = (MainWindow*)toolbar_item->parent;
1192 mainwindow_learn(mainwin, TRUE);
1194 mainwindow_learn(mainwin, FALSE);
1196 case TOOLBAR_MSGVIEW:
1197 msgview = (MessageView*)toolbar_item->parent;
1199 messageview_learn(msgview, TRUE);
1201 messageview_learn(msgview, FALSE);
1204 debug_print("toolbar event not supported\n");
1208 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1210 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1211 MainWindow *mainwin;
1212 MessageView *msgview;
1214 g_return_if_fail(toolbar_item != NULL);
1216 switch (toolbar_item->type) {
1218 mainwin = (MainWindow*)toolbar_item->parent;
1219 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1220 mainwindow_learn(mainwin, TRUE);
1222 mainwindow_learn(mainwin, FALSE);
1224 case TOOLBAR_MSGVIEW:
1225 msgview = (MessageView*)toolbar_item->parent;
1226 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1227 messageview_learn(msgview, TRUE);
1229 messageview_learn(msgview, FALSE);
1232 debug_print("toolbar event not supported\n");
1240 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1242 toolbar_reply(data, prefs_common.reply_with_quote ?
1243 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1248 * Reply message to Sender and All recipients
1250 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1253 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1254 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1259 * Reply to Mailing List
1261 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1264 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1265 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1270 * Reply to sender of message
1272 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1275 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1276 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1282 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1284 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1287 g_return_if_fail(toolbar_item != NULL);
1289 switch (toolbar_item->type) {
1291 case TOOLBAR_MSGVIEW:
1294 case TOOLBAR_COMPOSE:
1295 compose = (Compose *)toolbar_item->parent;
1300 addressbook_open(compose);
1305 * Forward current/selected(s) message(s)
1307 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1309 toolbar_reply(data, COMPOSE_FORWARD);
1313 * Goto Prev Unread Message
1315 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1317 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1318 MainWindow *mainwin;
1319 MessageView *msgview;
1321 g_return_if_fail(toolbar_item != NULL);
1323 switch (toolbar_item->type) {
1325 mainwin = (MainWindow*)toolbar_item->parent;
1326 summary_select_prev_unread(mainwin->summaryview);
1329 case TOOLBAR_MSGVIEW:
1330 msgview = (MessageView*)toolbar_item->parent;
1331 msgview->updating = TRUE;
1332 summary_select_prev_unread(msgview->mainwin->summaryview);
1333 msgview->updating = FALSE;
1335 if (msgview->deferred_destroy) {
1336 debug_print("messageview got away!\n");
1337 messageview_destroy(msgview);
1341 /* Now we need to update the messageview window */
1342 if (msgview->mainwin->summaryview->selected) {
1344 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1347 messageview_show(msgview, msginfo,
1348 msgview->all_headers);
1351 gtk_widget_destroy(msgview->window);
1355 debug_print("toolbar event not supported\n");
1360 * Goto Next Unread Message
1362 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1364 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1365 MainWindow *mainwin;
1366 MessageView *msgview;
1368 g_return_if_fail(toolbar_item != NULL);
1370 switch (toolbar_item->type) {
1372 mainwin = (MainWindow*)toolbar_item->parent;
1373 summary_select_next_unread(mainwin->summaryview);
1376 case TOOLBAR_MSGVIEW:
1377 msgview = (MessageView*)toolbar_item->parent;
1378 msgview->updating = TRUE;
1379 summary_select_next_unread(msgview->mainwin->summaryview);
1380 msgview->updating = FALSE;
1382 if (msgview->deferred_destroy) {
1383 debug_print("messageview got away!\n");
1384 messageview_destroy(msgview);
1388 /* Now we need to update the messageview window */
1389 if (msgview->mainwin->summaryview->selected) {
1391 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1394 messageview_show(msgview, msginfo,
1395 msgview->all_headers);
1398 gtk_widget_destroy(msgview->window);
1402 debug_print("toolbar event not supported\n");
1406 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1408 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1409 MainWindow *mainwin;
1411 g_return_if_fail(toolbar_item != NULL);
1413 switch (toolbar_item->type) {
1415 mainwin = (MainWindow *) toolbar_item->parent;
1416 summary_toggle_ignore_thread(mainwin->summaryview);
1418 case TOOLBAR_MSGVIEW:
1419 /* TODO: see toolbar_next_unread_cb() if you need
1420 * this in the message view */
1423 debug_print("toolbar event not supported\n");
1428 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1430 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1431 MainWindow *mainwin;
1433 g_return_if_fail(toolbar_item != NULL);
1435 switch (toolbar_item->type) {
1437 mainwin = (MainWindow *) toolbar_item->parent;
1438 summary_toggle_watch_thread(mainwin->summaryview);
1440 case TOOLBAR_MSGVIEW:
1441 /* TODO: see toolbar_next_unread_cb() if you need
1442 * this in the message view */
1445 debug_print("toolbar event not supported\n");
1450 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1452 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1454 g_return_if_fail(toolbar_item != NULL);
1460 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1462 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1463 MainWindow *mainwin;
1465 g_return_if_fail(toolbar_item != NULL);
1467 switch (toolbar_item->type) {
1469 mainwin = (MainWindow *) toolbar_item->parent;
1470 summary_print(mainwin->summaryview);
1472 case TOOLBAR_MSGVIEW:
1473 /* TODO: see toolbar_next_unread_cb() if you need
1474 * this in the message view */
1477 debug_print("toolbar event not supported\n");
1482 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1484 compose_toolbar_cb(A_SEND, data);
1487 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1489 compose_toolbar_cb(A_SENDL, data);
1492 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1494 compose_toolbar_cb(A_DRAFT, data);
1497 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1499 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1500 MainWindow *mainwin;
1501 MessageView *messageview;
1504 g_return_if_fail(toolbar_item != NULL);
1506 switch (toolbar_item->type) {
1508 mainwin = (MainWindow *) toolbar_item->parent;
1509 app_will_exit(NULL, mainwin);
1511 case TOOLBAR_MSGVIEW:
1512 messageview = (MessageView *)toolbar_item->parent;
1513 messageview_destroy(messageview);
1515 case TOOLBAR_COMPOSE:
1516 compose = (Compose *)toolbar_item->parent;
1517 compose_close_toolbar(compose);
1522 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1524 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1525 MainWindow *mainwin;
1527 g_return_if_fail(toolbar_item != NULL);
1529 switch (toolbar_item->type) {
1531 mainwin = (MainWindow *) toolbar_item->parent;
1532 summary_open_row(NULL, mainwin->summaryview);
1534 case TOOLBAR_MSGVIEW:
1535 debug_print("toolbar event not supported\n");
1537 case TOOLBAR_COMPOSE:
1538 debug_print("toolbar event not supported\n");
1543 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1545 compose_toolbar_cb(A_INSERT, data);
1548 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1550 compose_toolbar_cb(A_ATTACH, data);
1553 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1555 compose_toolbar_cb(A_SIG, data);
1558 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1560 compose_toolbar_cb(A_EXTEDITOR, data);
1563 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1565 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1568 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1570 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1574 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1576 compose_toolbar_cb(A_CHECK_SPELLING, data);
1580 * Execute actions from toolbar
1582 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1584 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1585 GSList *action_list;
1586 MainWindow *mainwin;
1588 MessageView *msgview;
1589 gpointer parent = toolbar_item->parent;
1591 g_return_if_fail(toolbar_item != NULL);
1593 switch (toolbar_item->type) {
1595 mainwin = (MainWindow*)parent;
1596 action_list = mainwin->toolbar->action_list;
1598 case TOOLBAR_COMPOSE:
1599 compose = (Compose*)parent;
1600 action_list = compose->toolbar->action_list;
1602 case TOOLBAR_MSGVIEW:
1603 msgview = (MessageView*)parent;
1604 action_list = msgview->toolbar->action_list;
1607 debug_print("toolbar event not supported\n");
1610 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1613 static MainWindow *get_mainwin(gpointer data)
1615 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1616 MainWindow *mainwin = NULL;
1617 MessageView *msgview;
1619 g_return_val_if_fail(toolbar_item != NULL, NULL);
1621 switch(toolbar_item->type) {
1623 mainwin = (MainWindow*)toolbar_item->parent;
1625 case TOOLBAR_MSGVIEW:
1626 msgview = (MessageView*)toolbar_item->parent;
1627 mainwin = (MainWindow*)msgview->mainwin;
1636 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1638 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1639 MainWindow *mainwin = NULL;
1640 switch(toolbar_item->type) {
1642 mainwin = (MainWindow*)toolbar_item->parent;
1645 g_warning("wrong toolbar type\n");
1649 if (!mainwin->in_folder) {
1650 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1652 folderview_select(mainwin->folderview, item);
1655 gtk_widget_grab_focus(mainwin->folderview->ctree);
1656 mainwindow_exit_folder(mainwin);
1660 static void toolbar_buttons_cb(GtkWidget *widget,
1667 void (*func)(GtkWidget *widget, gpointer data);
1669 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1670 { A_RECEIVE_CUR, toolbar_inc_cb },
1671 { A_SEND_QUEUED, toolbar_send_queued_cb },
1672 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1673 { A_COMPOSE_NEWS, toolbar_compose_cb },
1674 { A_REPLY_MESSAGE, toolbar_reply_cb },
1675 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1676 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1677 { A_REPLY_ML, toolbar_reply_to_list_cb },
1678 { A_FORWARD, toolbar_forward_cb },
1679 { A_TRASH, toolbar_trash_cb },
1680 { A_DELETE_REAL, toolbar_delete_cb },
1681 { A_EXECUTE, toolbar_exec_cb },
1682 { A_GOTO_PREV, toolbar_prev_unread_cb },
1683 { A_GOTO_NEXT, toolbar_next_unread_cb },
1684 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1685 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1686 { A_PRINT, toolbar_print_cb },
1687 { A_LEARN_SPAM, toolbar_learn_cb },
1688 { A_GO_FOLDERS, toolbar_go_folders_cb },
1690 { A_SEND, toolbar_send_cb },
1691 { A_SENDL, toolbar_send_later_cb },
1692 { A_DRAFT, toolbar_draft_cb },
1693 { A_OPEN_MAIL, toolbar_open_mail_cb },
1694 { A_CLOSE, toolbar_close_cb },
1695 { A_INSERT, toolbar_insert_cb },
1696 { A_ATTACH, toolbar_attach_cb },
1697 { A_SIG, toolbar_sig_cb },
1698 { A_EXTEDITOR, toolbar_ext_editor_cb },
1699 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1700 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1701 { A_ADDRBOOK, toolbar_addrbook_cb },
1703 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1705 { A_CLAWS_ACTIONS, toolbar_actions_execute_cb },
1706 { A_CANCEL_INC, toolbar_cancel_inc_cb }
1709 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1711 for (i = 0; i < num_items; i++) {
1712 if (callbacks[i].index == item->index) {
1713 callbacks[i].func(widget, item);
1719 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1720 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1721 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1722 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1723 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1724 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1725 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1729 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1730 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1731 GList *gchild = NULL; \
1732 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1733 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1734 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1735 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1736 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1737 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(item), GTK_TOOLTIPS(toolbar_tips), \
1739 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(item), \
1740 GTK_TOOLTIPS(toolbar_tips), menutip, NULL); \
1741 child = gtk_bin_get_child(GTK_BIN(item)); \
1742 gchild = gtk_container_get_children( \
1743 GTK_CONTAINER(child)); \
1744 btn = (GtkWidget *)gchild->data; \
1745 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1746 g_list_free(gchild); \
1747 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1748 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1749 g_list_free(gchild); \
1752 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1753 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1754 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1755 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1756 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1757 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1760 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1761 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1762 GList *gchild = NULL; \
1763 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1764 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1765 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1766 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1767 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1768 child = gtk_bin_get_child(GTK_BIN(item)); \
1769 gchild = gtk_container_get_children( \
1770 GTK_CONTAINER(child)); \
1771 btn = (GtkWidget *)gchild->data; \
1772 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1773 g_list_free(gchild); \
1774 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1775 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1776 g_list_free(gchild); \
1780 #define MAKE_MENU(entries,path,btn) { \
1781 n_menu_entries = sizeof(entries) / \
1782 sizeof(entries[0]); \
1783 menu = menu_create_items(entries, n_menu_entries, path, &factory, toolbar_item); \
1784 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(btn), menu); \
1788 * Create a new toolbar with specified type
1789 * if a callback list is passed it will be used before the
1790 * common callback list
1792 Toolbar *toolbar_create(ToolbarType type,
1793 GtkWidget *container,
1796 ToolbarItem *toolbar_item;
1799 GtkWidget *icon_wid = NULL;
1800 GtkWidget *icon_news;
1801 GtkWidget *icon_ham;
1804 guint n_menu_entries;
1805 GtkItemFactory *factory;
1806 ToolbarClawsActions *action_item;
1808 GSList *toolbar_list;
1809 Toolbar *toolbar_data;
1811 GtkTooltips *toolbar_tips;
1813 toolbar_tips = gtk_tooltips_new();
1815 toolbar_read_config_file(type);
1816 toolbar_list = toolbar_get_list(type);
1818 toolbar_data = g_new0(Toolbar, 1);
1820 toolbar = gtk_toolbar_new();
1822 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1823 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1824 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1826 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1828 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1829 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1833 toolbar_item = g_new0(ToolbarItem, 1);
1834 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1835 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1836 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1837 toolbar_item->parent = data;
1838 toolbar_item->type = type;
1840 /* collect toolbar items in list to keep track */
1841 toolbar_data->item_list =
1842 g_slist_append(toolbar_data->item_list,
1844 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1846 switch (toolbar_item->index) {
1849 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1850 toolbar_data->folders_btn = item;
1853 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1854 _("Receive Mail on all Accounts"),
1855 _("Receive Mail on selected Account"));
1856 toolbar_data->getall_btn = item;
1859 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail on current Account"));
1860 toolbar_data->get_btn = item;
1863 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1864 toolbar_data->send_btn = item;
1867 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1868 toolbar_data->close_window_btn = item;
1871 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1872 toolbar_data->open_mail_btn = item;
1874 case A_COMPOSE_EMAIL:
1876 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1878 _("Compose with selected Account"));
1879 toolbar_data->compose_mail_btn = item;
1880 toolbar_data->compose_mail_icon = icon_wid;
1881 g_object_ref(toolbar_data->compose_mail_icon);
1883 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1884 toolbar_data->compose_news_icon = icon_news;
1885 g_object_ref(toolbar_data->compose_news_icon);
1887 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1888 _("Compose Email"));
1889 toolbar_data->compose_mail_btn = item;
1890 toolbar_data->compose_mail_icon = icon_wid;
1892 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1893 toolbar_data->compose_news_icon = icon_news;
1897 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1900 toolbar_data->learn_spam_btn = item;
1901 toolbar_data->learn_spam_icon = icon_wid;
1902 g_object_ref(toolbar_data->learn_spam_icon);
1904 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1905 toolbar_data->learn_ham_icon = icon_ham;
1906 g_object_ref(toolbar_data->learn_ham_icon);
1908 MAKE_MENU(learn_entries,"<LearnSpam>",toolbar_data->learn_spam_btn);
1910 case A_REPLY_MESSAGE:
1912 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1913 _("Reply to Message"),
1914 _("Reply to Message options"));
1915 toolbar_data->reply_btn = item;
1917 MAKE_MENU(reply_entries,"<Reply>",toolbar_data->reply_btn);
1919 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1920 _("Reply to Message"));
1921 toolbar_data->reply_btn = item;
1924 case A_REPLY_SENDER:
1926 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1927 _("Reply to Sender"),
1928 _("Reply to Sender options"));
1929 toolbar_data->replysender_btn = item;
1931 MAKE_MENU(replysender_entries,"<ReplySender>",toolbar_data->replysender_btn);
1933 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1934 _("Reply to Sender"));
1935 toolbar_data->replysender_btn = item;
1940 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1942 _("Reply to All options"));
1943 toolbar_data->replyall_btn = item;
1945 MAKE_MENU(replyall_entries,"<ReplyAll>",toolbar_data->replyall_btn);
1947 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1949 toolbar_data->replyall_btn = item;
1954 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1955 _("Reply to Mailing-list"),
1956 _("Reply to Mailing-list options"));
1957 toolbar_data->replylist_btn = item;
1959 MAKE_MENU(replylist_entries,"<ReplyList>",toolbar_data->replylist_btn);
1961 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1962 _("Reply to Mailing-list"));
1963 toolbar_data->replylist_btn = item;
1968 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1969 _("Forward Message"),
1970 _("Forward Message options"));
1971 toolbar_data->fwd_btn = item;
1973 MAKE_MENU(forward_entries,"<Forward>",toolbar_data->fwd_btn);
1975 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1976 _("Forward Message"));
1977 toolbar_data->fwd_btn = item;
1981 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
1982 toolbar_data->trash_btn = item;
1985 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
1986 toolbar_data->delete_btn = item;
1989 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
1990 toolbar_data->exec_btn = item;
1993 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
1994 toolbar_data->prev_btn = item;
1997 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
1998 toolbar_data->next_btn = item;
2001 /* Compose Toolbar */
2003 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2004 toolbar_data->send_btn = item;
2007 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2008 toolbar_data->sendl_btn = item;
2011 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2012 toolbar_data->draft_btn = item;
2015 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2016 toolbar_data->insert_btn = item;
2019 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2020 toolbar_data->attach_btn = item;
2023 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2024 toolbar_data->sig_btn = item;
2027 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2028 toolbar_data->exteditor_btn = item;
2030 case A_LINEWRAP_CURRENT:
2031 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2032 toolbar_data->linewrap_current_btn = item;
2034 case A_LINEWRAP_ALL:
2035 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2036 toolbar_data->linewrap_all_btn = item;
2039 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2040 toolbar_data->addrbook_btn = item;
2043 case A_CHECK_SPELLING:
2044 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2045 toolbar_data->spellcheck_btn = item;
2049 case A_CLAWS_ACTIONS:
2050 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2051 action_item = g_new0(ToolbarClawsActions, 1);
2052 action_item->widget = item;
2053 action_item->name = g_strdup(toolbar_item->text);
2055 toolbar_data->action_list =
2056 g_slist_append(toolbar_data->action_list,
2060 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2061 toolbar_data->cancel_inc_btn = item;
2064 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2065 toolbar_ret_descr_from_val(toolbar_item->index));
2066 /* find and set the tool tip text */
2071 toolbar_data->toolbar = toolbar;
2073 toolbar_data->tooltips = toolbar_tips;
2075 gtk_widget_show_all(toolbar);
2077 if (type == TOOLBAR_MAIN) {
2079 MainWindow *mainwin = mainwindow_get_mainwindow();
2080 GtkWidget *progressbar = gtk_progress_bar_new();
2081 item = GTK_WIDGET(gtk_tool_item_new());
2082 gtk_container_add (GTK_CONTAINER (item), progressbar);
2083 gtk_widget_show(item);
2084 gtk_widget_show(progressbar);
2085 gtk_widget_set_size_request(progressbar, 70, -1);
2086 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2087 mainwin->progressbar = progressbar;
2089 activate_compose_button(toolbar_data,
2090 prefs_common.toolbar_style,
2091 toolbar_data->compose_btn_type);
2093 if (type != TOOLBAR_COMPOSE)
2094 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2098 gtk_container_add(GTK_CONTAINER(container), toolbar);
2099 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2101 if ( GTK_IS_WINDOW(container) ) {
2102 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
2103 gtk_widget_show_all (container);
2105 gtk_container_add(GTK_CONTAINER(container), toolbar);
2106 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2109 return toolbar_data;
2113 * Free toolbar structures
2115 void toolbar_destroy(Toolbar * toolbar) {
2117 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2118 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2121 void toolbar_update(ToolbarType type, gpointer data)
2123 Toolbar *toolbar_data;
2124 GtkWidget *handlebox;
2125 MainWindow *mainwin = (MainWindow*)data;
2126 Compose *compose = (Compose*)data;
2127 MessageView *msgview = (MessageView*)data;
2132 toolbar_data = mainwin->toolbar;
2133 handlebox = mainwin->handlebox;
2135 case TOOLBAR_COMPOSE:
2136 toolbar_data = compose->toolbar;
2137 handlebox = compose->handlebox;
2139 case TOOLBAR_MSGVIEW:
2140 toolbar_data = msgview->toolbar;
2141 handlebox = msgview->handlebox;
2147 gtk_container_remove(GTK_CONTAINER(handlebox),
2148 GTK_WIDGET(toolbar_data->toolbar));
2150 toolbar_init(toolbar_data);
2151 toolbar_data = toolbar_create(type, handlebox, data);
2155 toolbar_data = mainwin->toolbar;
2156 handlebox = mainwin->window;
2158 case TOOLBAR_COMPOSE:
2159 toolbar_data = compose->toolbar;
2160 handlebox = compose->window;
2162 case TOOLBAR_MSGVIEW:
2163 toolbar_data = msgview->toolbar;
2164 handlebox = msgview->window;
2170 hildon_window_remove_toolbar(HILDON_WINDOW(handlebox), GTK_TOOLBAR(toolbar_data->toolbar));
2172 toolbar_init(toolbar_data);
2173 toolbar_data = toolbar_create(type, handlebox, data);
2178 mainwin->toolbar = toolbar_data;
2180 case TOOLBAR_COMPOSE:
2181 compose->toolbar = toolbar_data;
2183 case TOOLBAR_MSGVIEW:
2184 msgview->toolbar = toolbar_data;
2188 toolbar_style(type, prefs_common.toolbar_style, data);
2190 if (type == TOOLBAR_MAIN) {
2191 toolbar_main_set_sensitive((MainWindow*)data);
2192 account_set_menu_only_toolbar();
2196 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2197 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2198 if (GTK_IS_BUTTON(widget)) \
2199 in_btn1 = GTK_BUTTON(widget)->in_button; \
2200 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2201 GtkWidget *child = gtk_bin_get_child( \
2203 GList *gchild = gtk_container_get_children( \
2204 GTK_CONTAINER(child)); \
2205 GtkWidget *btn = (GtkWidget *)gchild->data; \
2206 GtkWidget *arr = (GtkWidget *) \
2207 (gchild->next?gchild->next->data:NULL); \
2208 g_list_free(gchild); \
2209 if (GTK_IS_BUTTON(btn)) \
2210 in_btn1 = GTK_BUTTON(btn)->in_button; \
2211 if (GTK_IS_BUTTON(arr)) \
2212 in_btn2 = GTK_BUTTON(arr)->in_button; \
2214 else if (GTK_IS_TOOL_ITEM(widget)) { \
2215 GtkWidget *child = gtk_bin_get_child( \
2217 if (GTK_IS_BUTTON(child)) \
2218 in_btn1 = GTK_BUTTON(child)->in_button; \
2220 gtk_widget_set_sensitive(widget, sensitive); \
2221 if (GTK_IS_BUTTON(widget)) \
2222 GTK_BUTTON(widget)->in_button = in_btn1; \
2223 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2224 GtkWidget *child = gtk_bin_get_child( \
2226 GList *gchild = gtk_container_get_children( \
2227 GTK_CONTAINER(child)); \
2228 GtkWidget *btn = (GtkWidget *)gchild->data; \
2229 GtkWidget *arr = (GtkWidget *) \
2230 (gchild->next?gchild->next->data:NULL); \
2231 g_list_free(gchild); \
2232 if (GTK_IS_BUTTON(btn)) \
2233 GTK_BUTTON(btn)->in_button = in_btn1; \
2234 if (GTK_IS_BUTTON(arr)) \
2235 GTK_BUTTON(arr)->in_button = in_btn2; \
2237 else if (GTK_IS_TOOL_ITEM(widget)) { \
2238 GtkWidget *child = gtk_bin_get_child( \
2240 if (GTK_IS_BUTTON(child)) \
2241 GTK_BUTTON(child)->in_button = in_btn1; \
2245 void toolbar_main_set_sensitive(gpointer data)
2247 SensitiveCond state;
2249 MainWindow *mainwin = (MainWindow*)data;
2250 Toolbar *toolbar = mainwin->toolbar;
2252 GSList *entry_list = NULL;
2254 typedef struct _Entry Entry;
2261 #define SET_WIDGET_COND(w, c) \
2263 Entry *e = g_new0(Entry, 1); \
2266 entry_list = g_slist_append(entry_list, e); \
2270 if (toolbar->get_btn)
2271 SET_WIDGET_COND(toolbar->get_btn,
2272 M_HAVE_ACCOUNT|M_UNLOCKED);
2274 if (toolbar->getall_btn) {
2275 SET_WIDGET_COND(toolbar->getall_btn,
2276 M_HAVE_ACCOUNT|M_UNLOCKED);
2278 if (toolbar->send_btn) {
2279 SET_WIDGET_COND(toolbar->send_btn,
2280 M_HAVE_QUEUED_MAILS);
2282 if (toolbar->compose_mail_btn) {
2283 SET_WIDGET_COND(toolbar->compose_mail_btn,
2286 if (toolbar->close_window_btn) {
2287 SET_WIDGET_COND(toolbar->close_window_btn,
2290 if (toolbar->open_mail_btn) {
2291 SET_WIDGET_COND(toolbar->open_mail_btn,
2294 if (toolbar->reply_btn) {
2295 SET_WIDGET_COND(toolbar->reply_btn,
2296 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2298 if (toolbar->replyall_btn) {
2299 SET_WIDGET_COND(toolbar->replyall_btn,
2300 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2302 if (toolbar->replylist_btn) {
2303 SET_WIDGET_COND(toolbar->replylist_btn,
2304 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2306 if (toolbar->replysender_btn) {
2307 SET_WIDGET_COND(toolbar->replysender_btn,
2308 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2310 if (toolbar->fwd_btn) {
2311 SET_WIDGET_COND(toolbar->fwd_btn,
2312 M_HAVE_ACCOUNT|M_TARGET_EXIST);
2315 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2316 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
2318 SET_WIDGET_COND(toolbar->next_btn, 0);
2321 if (toolbar->trash_btn)
2322 SET_WIDGET_COND(toolbar->trash_btn,
2323 M_TARGET_EXIST|M_ALLOW_DELETE);
2325 if (toolbar->delete_btn)
2326 SET_WIDGET_COND(toolbar->delete_btn,
2327 M_TARGET_EXIST|M_ALLOW_DELETE);
2329 if (toolbar->exec_btn)
2330 SET_WIDGET_COND(toolbar->exec_btn,
2333 /* if (toolbar->learn_ham_btn)
2334 SET_WIDGET_COND(toolbar->learn_ham_btn,
2335 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2337 if (toolbar->learn_spam_btn)
2338 SET_WIDGET_COND(toolbar->learn_spam_btn,
2339 M_TARGET_EXIST|M_CAN_LEARN_SPAM);
2341 if (toolbar->cancel_inc_btn)
2342 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2345 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2346 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2348 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2351 #undef SET_WIDGET_COND
2353 state = main_window_get_current_state(mainwin);
2355 for (cur = entry_list; cur != NULL; cur = cur->next) {
2356 Entry *e = (Entry*) cur->data;
2358 if (e->widget != NULL) {
2359 sensitive = ((e->cond & state) == e->cond);
2360 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2364 while (entry_list != NULL) {
2365 Entry *e = (Entry*) entry_list->data;
2368 entry_list = g_slist_remove(entry_list, e);
2371 g_slist_free(entry_list);
2373 activate_compose_button(toolbar,
2374 prefs_common.toolbar_style,
2375 toolbar->compose_btn_type);
2379 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2381 Compose *compose = (Compose*)data;
2382 GSList *items = compose->toolbar->action_list;
2384 if (compose->toolbar->send_btn)
2385 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2386 if (compose->toolbar->sendl_btn)
2387 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2388 if (compose->toolbar->draft_btn )
2389 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2390 if (compose->toolbar->insert_btn )
2391 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2392 if (compose->toolbar->attach_btn)
2393 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2394 if (compose->toolbar->sig_btn)
2395 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2396 if (compose->toolbar->exteditor_btn)
2397 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2398 if (compose->toolbar->linewrap_current_btn)
2399 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2400 if (compose->toolbar->linewrap_all_btn)
2401 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2402 if (compose->toolbar->addrbook_btn)
2403 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2405 if (compose->toolbar->spellcheck_btn)
2406 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2408 for (; items != NULL; items = g_slist_next(items)) {
2409 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2410 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2415 * Initialize toolbar structure
2417 static void toolbar_init(Toolbar * toolbar)
2420 toolbar->toolbar = NULL;
2421 toolbar->folders_btn = NULL;
2422 toolbar->get_btn = NULL;
2423 toolbar->getall_btn = NULL;
2424 toolbar->send_btn = NULL;
2425 toolbar->compose_mail_btn = NULL;
2426 toolbar->compose_mail_icon = NULL;
2427 toolbar->compose_news_icon = NULL;
2428 toolbar->reply_btn = NULL;
2429 toolbar->replysender_btn = NULL;
2430 toolbar->replyall_btn = NULL;
2431 toolbar->replylist_btn = NULL;
2432 toolbar->fwd_btn = NULL;
2433 toolbar->trash_btn = NULL;
2434 toolbar->delete_btn = NULL;
2435 toolbar->prev_btn = NULL;
2436 toolbar->next_btn = NULL;
2437 toolbar->exec_btn = NULL;
2438 toolbar->open_mail_btn = NULL;
2439 toolbar->close_window_btn = NULL;
2440 /* compose buttons */
2441 toolbar->sendl_btn = NULL;
2442 toolbar->draft_btn = NULL;
2443 toolbar->insert_btn = NULL;
2444 toolbar->attach_btn = NULL;
2445 toolbar->sig_btn = NULL;
2446 toolbar->exteditor_btn = NULL;
2447 toolbar->linewrap_current_btn = NULL;
2448 toolbar->linewrap_all_btn = NULL;
2449 toolbar->addrbook_btn = NULL;
2451 toolbar->spellcheck_btn = NULL;
2454 toolbar_destroy(toolbar);
2459 static void toolbar_reply(gpointer data, guint action)
2461 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2462 MainWindow *mainwin;
2463 MessageView *msgview;
2464 GSList *msginfo_list = NULL;
2466 g_return_if_fail(toolbar_item != NULL);
2468 switch (toolbar_item->type) {
2470 mainwin = (MainWindow*)toolbar_item->parent;
2471 msginfo_list = summary_get_selection(mainwin->summaryview);
2472 msgview = (MessageView*)mainwin->messageview;
2474 case TOOLBAR_MSGVIEW:
2475 msgview = (MessageView*)toolbar_item->parent;
2476 g_return_if_fail(msgview != NULL);
2477 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2483 g_return_if_fail(msgview != NULL);
2484 g_return_if_fail(msginfo_list != NULL);
2485 compose_reply_from_messageview(msgview, msginfo_list, action);
2486 g_slist_free(msginfo_list);
2488 /* TODO: update reply state ion summaryview */
2492 /* exported functions */
2494 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2496 MainWindow *mainwin = (MainWindow*)data;
2498 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2501 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2503 MainWindow *mainwin = (MainWindow*)data;
2505 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2508 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2512 gboolean got_error = FALSE;
2513 gchar *errstr = NULL;
2515 if (prefs_common.work_offline)
2516 if (alertpanel(_("Offline warning"),
2517 _("You're working offline. Override?"),
2518 GTK_STOCK_NO, GTK_STOCK_YES,
2519 NULL) != G_ALERTALTERNATE)
2522 /* ask for confirmation before sending queued messages only
2523 in online mode and if there is at least one message queued
2524 in any of the folder queue
2526 if (prefs_common.confirm_send_queued_messages) {
2528 /* check if there's a queued message */
2529 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2530 Folder *folder = list->data;
2532 found = !procmsg_queue_is_empty(folder->queue);
2534 /* if necessary, ask for confirmation before sending */
2535 if (found && !prefs_common.work_offline) {
2536 if (alertpanel(_("Send queued messages"),
2537 _("Send all queued messages?"),
2538 GTK_STOCK_CANCEL, _("_Send"),
2539 NULL) != G_ALERTALTERNATE)
2544 for (list = folder_get_list(); list != NULL; list = list->next) {
2545 Folder *folder = list->data;
2547 if (folder->queue) {
2548 if (procmsg_send_queue(folder->queue,
2549 prefs_common.savemsg,
2556 alertpanel_error_log(_("Some errors occurred while "
2557 "sending queued messages."));
2559 alertpanel_error_log(_("Some errors occurred "
2560 "while sending queued messages:\n%s"), errstr);
2566 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2568 MainWindow *mainwin = (MainWindow*)data;
2569 PrefsAccount *ac = NULL;
2570 FolderItem *item = mainwin->summaryview->folder_item;
2575 ac = account_find_from_item(item);
2576 if (ac && ac->protocol != A_NNTP) {
2577 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2583 * CLAWS - use current account
2585 if (cur_account && (cur_account->protocol != A_NNTP)) {
2586 compose_new_with_folderitem(cur_account, item, NULL);
2591 * CLAWS - just get the first one
2593 list = account_get_list();
2594 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2595 ac = (PrefsAccount *) cur->data;
2596 if (ac->protocol != A_NNTP) {
2597 compose_new_with_folderitem(ac, item, NULL);
2603 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2605 MainWindow *mainwin = (MainWindow*)data;
2606 PrefsAccount * ac = NULL;
2610 if (mainwin->summaryview->folder_item) {
2611 ac = mainwin->summaryview->folder_item->folder->account;
2612 if (ac && ac->protocol == A_NNTP) {
2613 compose_new_with_folderitem(ac,
2614 mainwin->summaryview->folder_item, NULL);
2619 list = account_get_list();
2620 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2621 ac = (PrefsAccount *) cur->data;
2622 if (ac->protocol == A_NNTP) {
2623 compose_new_with_folderitem(ac,
2624 mainwin->summaryview->folder_item, NULL);