2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2024 the Claws Mail team and Hiroyuki Yamamoto
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 #include "claws-features.h"
27 #include <glib/gi18n.h>
35 #include "mainwindow.h"
36 #include "summaryview.h"
41 #include "prefs_gtk.h"
43 #include "stock_pixmap.h"
44 #include "manage_window.h"
50 #include "prefs_actions.h"
51 #include "prefs_common.h"
52 #include "prefs_toolbar.h"
53 #include "alertpanel.h"
56 #include "send_message.h"
57 #ifndef USE_ALT_ADDRBOOK
58 #include "addressbook.h"
60 #include "addressbook-dbus.h"
64 #define TOOLBAR_TAG_INDEX "toolbar"
65 #define TOOLBAR_TAG_ITEM "item"
66 #define TOOLBAR_TAG_SEPARATOR "separator"
68 #define TOOLBAR_ICON_FILE "file"
69 #define TOOLBAR_ICON_TEXT "text"
70 #define TOOLBAR_ICON_ACTION "action"
72 static void toolbar_init(Toolbar * toolbar);
73 static gboolean toolbar_is_duplicate (gint action,
75 static void toolbar_parse_item (XMLFile *file,
76 ToolbarType source, gboolean *rewrite);
78 static gint toolbar_ret_val_from_text (const gchar *text);
79 static gchar *toolbar_ret_text_from_val (gint val);
81 typedef struct _DefaultToolbar DefaultToolbar;
82 struct _DefaultToolbar {
85 static void toolbar_set_default_generic(ToolbarType toolbar_type,
86 DefaultToolbar *default_toolbar);
88 static void toolbar_style (ToolbarType type,
92 static MainWindow *get_mainwin (gpointer data);
93 static void activate_compose_button (Toolbar *toolbar,
95 ComposeButtonType type);
97 /* toolbar callbacks */
98 static void toolbar_reply (gpointer data,
101 static void toolbar_learn (gpointer data,
104 static void toolbar_delete_dup (gpointer data,
107 static void toolbar_trash_cb (GtkWidget *widget,
110 static void toolbar_delete_cb (GtkWidget *widget,
113 static void toolbar_delete_dup_cb (GtkWidget *widget,
117 static void toolbar_compose_cb (GtkWidget *widget,
120 static void toolbar_learn_cb (GtkWidget *widget,
123 static void toolbar_reply_cb (GtkWidget *widget,
126 static void toolbar_reply_to_all_cb (GtkWidget *widget,
129 static void toolbar_reply_to_list_cb (GtkWidget *widget,
132 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
135 static void toolbar_forward_cb (GtkWidget *widget,
138 static void toolbar_prev_unread_cb (GtkWidget *widget,
140 static void toolbar_next_unread_cb (GtkWidget *widget,
143 static void toolbar_ignore_thread_cb (GtkWidget *widget,
146 static void toolbar_watch_thread_cb (GtkWidget *widget,
149 static void toolbar_mark_cb (GtkWidget *widget,
152 static void toolbar_unmark_cb (GtkWidget *widget,
155 static void toolbar_lock_cb (GtkWidget *widget,
158 static void toolbar_unlock_cb (GtkWidget *widget,
161 static void toolbar_all_read_cb (GtkWidget *widget,
164 static void toolbar_all_unread_cb (GtkWidget *widget,
167 static void toolbar_read_cb (GtkWidget *widget,
170 static void toolbar_unread_cb (GtkWidget *widget,
173 static void toolbar_run_processing_cb (GtkWidget *widget,
176 static void toolbar_print_cb (GtkWidget *widget,
179 static void toolbar_actions_execute_cb (GtkWidget *widget,
181 static void toolbar_plugins_execute_cb (GtkWidget *widget,
185 static void toolbar_send_cb (GtkWidget *widget,
187 static void toolbar_send_later_cb (GtkWidget *widget,
189 static void toolbar_draft_cb (GtkWidget *widget,
191 static void toolbar_close_cb (GtkWidget *widget,
193 static void toolbar_preferences_cb (GtkWidget *widget,
195 static void toolbar_open_mail_cb (GtkWidget *widget,
197 static void toolbar_insert_cb (GtkWidget *widget,
199 static void toolbar_attach_cb (GtkWidget *widget,
201 static void toolbar_sig_cb (GtkWidget *widget,
203 static void toolbar_ext_editor_cb (GtkWidget *widget,
205 static void toolbar_linewrap_current_cb (GtkWidget *widget,
207 static void toolbar_linewrap_all_cb (GtkWidget *widget,
209 static void toolbar_addrbook_cb (GtkWidget *widget,
212 static void toolbar_check_spelling_cb (GtkWidget *widget,
215 static void toolbar_cancel_inc_cb (GtkWidget *widget,
217 static void toolbar_cancel_send_cb (GtkWidget *widget,
219 static void toolbar_cancel_all_cb (GtkWidget *widget,
225 } toolbar_text [] = {
226 { "A_RECEIVE_ALL", N_("Receive Mail from all Accounts") },
227 { "A_RECEIVE_CUR", N_("Receive Mail from current Account") },
228 { "A_SEND_QUEUED", N_("Send Queued Messages") },
229 { "A_COMPOSE_EMAIL", N_("Compose Email") },
230 { "A_COMPOSE_NEWS", N_("Compose News") },
231 { "A_REPLY_MESSAGE", N_("Reply to Message") },
232 { "A_REPLY_SENDER", N_("Reply to Sender") },
233 { "A_REPLY_ALL", N_("Reply to All") },
234 { "A_REPLY_ML", N_("Reply to Mailing-list") },
235 { "A_OPEN_MAIL", N_("Open email") },
236 { "A_FORWARD", N_("Forward Message") },
237 { "A_TRASH", N_("Trash Message") },
238 { "A_DELETE_REAL", N_("Delete Message") },
239 { "A_DELETE_DUP", N_("Delete duplicate messages") },
240 { "A_EXECUTE", N_("Execute") },
241 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
242 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
244 { "A_IGNORE_THREAD", N_("Ignore thread") },
245 { "A_WATCH_THREAD", N_("Watch thread") },
246 { "A_MARK", N_("Mark Message") },
247 { "A_UNMARK", N_("Unmark Message") },
248 { "A_LOCK", N_("Lock Message") },
249 { "A_UNLOCK", N_("Unlock Message") },
250 { "A_ALL_READ", N_("Mark all Messages as read") },
251 { "A_ALL_UNREAD", N_("Mark all Messages as unread") },
252 { "A_READ", N_("Mark Message as read") },
253 { "A_UNREAD", N_("Mark Message as unread") },
254 { "A_RUN_PROCESSING", N_("Run folder processing rules") },
256 { "A_PRINT", N_("Print") },
257 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
258 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
259 { "A_PREFERENCES", N_("Preferences") },
261 { "A_SEND", N_("Send Message") },
262 { "A_SEND_LATER", N_("Put into queue folder and send later") },
263 { "A_DRAFT", N_("Save to draft folder") },
264 { "A_INSERT", N_("Insert file") },
265 { "A_ATTACH", N_("Attach file") },
266 { "A_SIG", N_("Insert signature") },
267 { "A_REP_SIG", N_("Replace signature") },
268 { "A_EXTEDITOR", N_("Edit with external editor") },
269 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
270 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
271 { "A_ADDRBOOK", N_("Address book") },
273 { "A_CHECK_SPELLING", N_("Check spelling") },
275 { "A_PRIVACY_SIGN", N_("Sign") },
276 { "A_PRIVACY_ENCRYPT", N_("Encrypt") },
277 { "A_CLAWS_ACTIONS", N_("Claws Mail Actions Feature") },
278 { "A_CANCEL_INC", N_("Cancel receiving") },
279 { "A_CANCEL_SEND", N_("Cancel sending") },
280 { "A_CANCEL_ALL", N_("Cancel receiving/sending") },
281 { "A_CLOSE", N_("Close window") },
282 { "A_SEPARATOR", N_("Separator") },
283 { "A_CLAWS_PLUGINS", N_("Claws Mail Plugins") }
286 /* migration table: support reading toolbar configuration files with
287 old action names and converting them to current action names,
288 see toolbar_parse_item(), which makes uses of this alias table.
291 const gchar *old_name;
292 const gchar *current_name;
293 } toolbar_migration [] = {
294 { "A_SYL_ACTIONS", "A_CLAWS_ACTIONS" },
295 { "A_SENDL", "A_SEND_LATER" },
299 /* struct holds configuration files and a list of
300 * currently active toolbar items
301 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
305 const gchar *conf_file;
307 } toolbar_config[NUM_TOOLBARS] = {
308 { "toolbar_main.xml", NULL},
309 { "toolbar_compose.xml", NULL},
310 { "toolbar_msgview.xml", NULL}
313 gint toolbar_ret_val_from_descr(const gchar *descr)
317 for (i = 0; i < N_ACTION_VAL; i++) {
318 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
325 gchar *toolbar_ret_descr_from_val(gint val)
327 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
329 return gettext(toolbar_text[val].descr);
332 static gint toolbar_ret_val_from_text(const gchar *text)
336 for (i = 0; i < N_ACTION_VAL; i++) {
337 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
344 static gchar *toolbar_ret_text_from_val(gint val)
346 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
348 return toolbar_text[val].index_str;
351 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
355 if ((action == A_SEPARATOR) || (action == A_CLAWS_ACTIONS) || (action == A_CLAWS_PLUGINS))
358 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
359 ToolbarItem *item = (ToolbarItem*) cur->data;
361 if (item->index == action)
367 /* depending on toolbar type this function
368 returns a list of available toolbar events being
369 displayed by prefs_toolbar
371 GList *toolbar_get_action_items(ToolbarType source)
376 if (source == TOOLBAR_MAIN) {
377 gint main_items[] = {
378 A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
379 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
380 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
381 A_TRASH, A_DELETE_REAL, A_DELETE_DUP, A_EXECUTE,
382 A_GOTO_PREV, A_GOTO_NEXT, A_IGNORE_THREAD, A_WATCH_THREAD,
383 A_MARK, A_UNMARK, A_LOCK, A_UNLOCK,
384 A_ALL_READ, A_ALL_UNREAD, A_READ, A_UNREAD,
386 A_PRINT, A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
387 A_CANCEL_INC, A_CANCEL_SEND, A_CANCEL_ALL, A_PREFERENCES };
389 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
390 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
393 else if (source == TOOLBAR_COMPOSE) {
394 gint comp_items[] = {
395 A_SEND, A_SEND_LATER, A_DRAFT,
396 A_INSERT, A_ATTACH, A_SIG,
397 A_REP_SIG, A_EXTEDITOR, A_LINEWRAP_CURRENT,
398 A_LINEWRAP_ALL, A_ADDRBOOK,
402 A_PRIVACY_SIGN, A_PRIVACY_ENCRYPT,
405 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
406 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
408 else if (source == TOOLBAR_MSGVIEW) {
409 gint msgv_items[] = {
410 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
411 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
412 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
413 A_ADDRBOOK, A_LEARN_SPAM, A_CLOSE };
415 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
416 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
422 static void toolbar_parse_item(XMLFile *file, ToolbarType source, gboolean *rewrite)
426 ToolbarItem *item = NULL;
428 g_return_if_fail(rewrite != NULL);
430 attr = xml_get_current_tag_attr(file);
431 item = g_new0(ToolbarItem, 1);
433 name = ((XMLAttr *)attr->data)->name;
434 value = ((XMLAttr *)attr->data)->value;
436 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
437 item->file = g_strdup (value);
438 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
439 item->text = g_strdup (*value ? gettext(value):"");
440 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
441 item->index = toolbar_ret_val_from_text(value);
443 if ((item->index == -1) && !strcmp(value, "A_DELETE")) {
445 item->index = A_TRASH;
447 item->file = g_strdup("trash_btn");
449 item->text = g_strdup(C_("Toolbar", "Trash"));
452 if (!strcmp(item->file, "mail") && !strcmp(value, "A_DRAFT")) {
453 /* switch icon file */
455 item->file = g_strdup("mail_draft");
458 if (item->index == -1) {
459 /* item not found in table: try migrating old action names to current ones */
462 /* replace action name */
463 for (i = 0; toolbar_migration[i].old_name != NULL; i++) {
464 if (g_utf8_collate(value, toolbar_migration[i].old_name) == 0) {
465 item->index = toolbar_ret_val_from_text(toolbar_migration[i].current_name);
466 if (item->index != -1) {
468 debug_print("toolbar_parse_item: migrating action label from '%s' to '%s'\n",
469 value, toolbar_migration[i].current_name);
475 if ((item->index == -1) && !rewrite)
476 g_warning("toolbar_parse_item: unrecognized action name '%s'", value);
478 attr = g_list_next(attr);
480 if (item->index != -1) {
481 if (!toolbar_is_duplicate(item->index, source)) {
482 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
485 toolbar_item_destroy(item);
488 toolbar_item_destroy(item);
492 const gchar *toolbar_get_short_text(int action) {
494 case A_RECEIVE_ALL: return _("Get Mail");
495 case A_RECEIVE_CUR: return _("Get");
496 case A_SEND_QUEUED: return _("Send");
497 case A_COMPOSE_EMAIL: return C_("Toolbar", "Compose");
498 case A_COMPOSE_NEWS: return C_("Toolbar", "Compose");
499 case A_REPLY_MESSAGE: return _("Reply");
500 case A_REPLY_SENDER: return C_("Toolbar", "Sender");
501 case A_REPLY_ALL: return _("All");
502 case A_REPLY_ML: return _("List");
503 case A_OPEN_MAIL: return _("Open");
504 case A_FORWARD: return _("Forward");
505 case A_TRASH: return C_("Toolbar", "Trash");
506 case A_DELETE_REAL: return _("Delete");
507 case A_DELETE_DUP: return _("Delete duplicates");
508 case A_EXECUTE: return _("Execute");
509 case A_GOTO_PREV: return _("Prev");
510 case A_GOTO_NEXT: return _("Next");
512 case A_IGNORE_THREAD: return _("Ignore thread");
513 case A_WATCH_THREAD: return _("Watch thread");
514 case A_MARK: return _("Mark");
515 case A_UNMARK: return _("Unmark");
516 case A_LOCK: return _("Lock");
517 case A_UNLOCK: return _("Unlock");
518 case A_ALL_READ: return _("All read");
519 case A_ALL_UNREAD: return _("All unread");
520 case A_READ: return _("Read");
521 case A_UNREAD: return _("Unread");
522 case A_RUN_PROCESSING: return _("Run proc. rules");
524 case A_PRINT: return _("Print");
525 case A_LEARN_SPAM: return _("Spam");
526 case A_GO_FOLDERS: return _("Folders");
527 case A_PREFERENCES: return _("Preferences");
529 case A_SEND: return _("Send");
530 case A_SEND_LATER: return _("Send later");
531 case A_DRAFT: return _("Draft");
532 case A_INSERT: return _("Insert");
533 case A_ATTACH: return _("Attach");
534 case A_SIG: return _("Insert sig.");
535 case A_REP_SIG: return _("Replace sig.");
536 case A_EXTEDITOR: return _("Edit");
537 case A_LINEWRAP_CURRENT:return _("Wrap para.");
538 case A_LINEWRAP_ALL: return _("Wrap all");
539 case A_ADDRBOOK: return _("Address");
541 case A_CHECK_SPELLING: return _("Check spelling");
543 case A_PRIVACY_SIGN: return _("Sign");
544 case A_PRIVACY_ENCRYPT: return _("Encrypt");
546 case A_CANCEL_INC: return _("Stop");
547 case A_CANCEL_SEND: return _("Stop");
548 case A_CANCEL_ALL: return _("Stop all");
549 case A_CLOSE: return _("Close");
554 gint toolbar_get_icon(int action) {
556 case A_RECEIVE_ALL: return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
557 case A_RECEIVE_CUR: return STOCK_PIXMAP_MAIL_RECEIVE;
558 case A_SEND_QUEUED: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
559 case A_COMPOSE_EMAIL: return STOCK_PIXMAP_MAIL_COMPOSE;
560 case A_COMPOSE_NEWS: return STOCK_PIXMAP_NEWS_COMPOSE;
561 case A_REPLY_MESSAGE: return STOCK_PIXMAP_MAIL_REPLY;
562 case A_REPLY_SENDER: return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
563 case A_REPLY_ALL: return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
564 case A_REPLY_ML: return STOCK_PIXMAP_MAIL_REPLY_TO_LIST;
565 case A_OPEN_MAIL: return STOCK_PIXMAP_OPEN_MAIL;
566 case A_FORWARD: return STOCK_PIXMAP_MAIL_FORWARD;
567 case A_TRASH: return STOCK_PIXMAP_TRASH;
568 case A_DELETE_REAL: return STOCK_PIXMAP_DELETE;
569 case A_DELETE_DUP: return STOCK_PIXMAP_DELETE_DUP;
570 case A_EXECUTE: return STOCK_PIXMAP_EXEC;
571 case A_GOTO_PREV: return STOCK_PIXMAP_UP_ARROW;
572 case A_GOTO_NEXT: return STOCK_PIXMAP_DOWN_ARROW;
574 case A_IGNORE_THREAD: return STOCK_PIXMAP_MARK_IGNORETHREAD;
575 case A_WATCH_THREAD: return STOCK_PIXMAP_MARK_WATCHTHREAD;
576 case A_MARK: return STOCK_PIXMAP_MARK_MARK;
577 case A_UNMARK: return STOCK_PIXMAP_MARK_UNMARK;
578 case A_LOCK: return STOCK_PIXMAP_MARK_LOCKED;
579 case A_UNLOCK: return STOCK_PIXMAP_MARK_UNLOCKED;
580 case A_ALL_READ: return STOCK_PIXMAP_MARK_ALLREAD;
581 case A_ALL_UNREAD: return STOCK_PIXMAP_MARK_ALLUNREAD;
582 case A_READ: return STOCK_PIXMAP_MARK_READ;
583 case A_UNREAD: return STOCK_PIXMAP_MARK_UNREAD;
584 case A_RUN_PROCESSING: return STOCK_PIXMAP_DIR_OPEN;
586 case A_PRINT: return STOCK_PIXMAP_PRINTER_BTN;
587 case A_LEARN_SPAM: return STOCK_PIXMAP_SPAM_BTN;
588 case A_GO_FOLDERS: return STOCK_PIXMAP_GO_FOLDERS;
589 case A_PREFERENCES: return STOCK_PIXMAP_PREFERENCES;
591 case A_SEND: return STOCK_PIXMAP_MAIL_SEND;
592 case A_SEND_LATER: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
593 case A_DRAFT: return STOCK_PIXMAP_MAIL_DRAFT;
594 case A_INSERT: return STOCK_PIXMAP_INSERT_FILE;
595 case A_ATTACH: return STOCK_PIXMAP_MAIL_ATTACH;
596 case A_SIG: return STOCK_PIXMAP_MAIL_SIGN;
597 case A_REP_SIG: return STOCK_PIXMAP_MAIL_SIGN;
598 case A_EXTEDITOR: return STOCK_PIXMAP_EDIT_EXTERN;
599 case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
600 case A_LINEWRAP_ALL: return STOCK_PIXMAP_LINEWRAP_ALL;
601 case A_ADDRBOOK: return STOCK_PIXMAP_ADDRESS_BOOK;
603 case A_CHECK_SPELLING: return STOCK_PIXMAP_CHECK_SPELLING;
605 case A_PRIVACY_SIGN: return STOCK_PIXMAP_MAIL_PRIVACY_SIGNED;
606 case A_PRIVACY_ENCRYPT: return STOCK_PIXMAP_MAIL_PRIVACY_ENCRYPTED;
608 case A_CANCEL_INC: return STOCK_PIXMAP_CANCEL;
609 case A_CANCEL_SEND: return STOCK_PIXMAP_CANCEL;
610 case A_CANCEL_ALL: return STOCK_PIXMAP_CANCEL;
611 case A_CLOSE: return STOCK_PIXMAP_CLOSE;
616 static void toolbar_set_default_generic(ToolbarType toolbar_type, DefaultToolbar *default_toolbar)
620 g_return_if_fail(default_toolbar != NULL);
622 for (i = 0; default_toolbar[i].action != N_ACTION_VAL; i++) {
624 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
626 if (default_toolbar[i].action != A_SEPARATOR) {
630 icon = toolbar_get_icon(default_toolbar[i].action);
632 file = stock_pixmap_get_name((StockPixmap)icon);
634 toolbar_item->file = g_strdup(file);
635 toolbar_item->index = default_toolbar[i].action;
636 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
638 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
639 toolbar_item->index = A_SEPARATOR;
642 if (toolbar_item->index != -1) {
643 if (!toolbar_is_duplicate(toolbar_item->index, toolbar_type)) {
644 toolbar_config[toolbar_type].item_list =
645 g_slist_append(toolbar_config[toolbar_type].item_list, toolbar_item);
647 toolbar_item_destroy(toolbar_item);
650 toolbar_item_destroy(toolbar_item);
655 void toolbar_set_default(ToolbarType source)
657 DefaultToolbar default_toolbar_main[] = {
683 DefaultToolbar default_toolbar_compose[] = {
701 DefaultToolbar default_toolbar_msgview[] = {
719 if (source == TOOLBAR_MAIN)
720 toolbar_set_default_generic(TOOLBAR_MAIN, default_toolbar_main);
721 else if (source == TOOLBAR_COMPOSE)
722 toolbar_set_default_generic(TOOLBAR_COMPOSE, default_toolbar_compose);
723 else if (source == TOOLBAR_MSGVIEW)
724 toolbar_set_default_generic(TOOLBAR_MSGVIEW, default_toolbar_msgview);
727 void toolbar_save_config_file(ToolbarType source)
732 gchar *fileSpec = NULL;
734 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
736 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
737 pfile = prefs_write_open(fileSpec);
740 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
743 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
746 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
747 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
749 if (toolbar_item->index != A_SEPARATOR) {
750 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
752 TOOLBAR_ICON_FILE, toolbar_item->file,
753 TOOLBAR_ICON_TEXT) < 0)
755 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
757 if (fprintf(fp, "\" %s=\"%s\"/>\n",
759 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
762 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
767 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
771 if (prefs_file_close (pfile) < 0 )
772 g_warning("failed to write toolbar configuration to file");
776 FILE_OP_ERROR(fileSpec, "fprintf");
778 prefs_file_close_revert (pfile);
781 g_warning("failed to open toolbar configuration file for writing");
785 void toolbar_read_config_file(ToolbarType source)
787 XMLFile *file = NULL;
788 gchar *fileSpec = NULL;
790 gboolean rewrite = FALSE;
792 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
794 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
795 file = xml_open_file(fileSpec);
798 toolbar_clear_list(source);
802 || (xml_get_dtd(file))
803 || (xml_parse_next_tag(file))
804 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
805 xml_close_file(file);
813 if (xml_parse_next_tag(file))
816 /* Get next tag (icon, icon_text or icon_action) */
817 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
818 toolbar_parse_item(file, source, &rewrite);
819 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
820 ToolbarItem *item = g_new0(ToolbarItem, 1);
822 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
823 item->index = A_SEPARATOR;
824 toolbar_config[source].item_list =
825 g_slist_append(toolbar_config[source].item_list, item);
829 xml_close_file(file);
831 debug_print("toolbar_read_config_file: rewriting toolbar\n");
832 toolbar_save_config_file(source);
836 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
838 if (source == TOOLBAR_MAIN)
839 toolbar_set_default(TOOLBAR_MAIN);
840 else if (source == TOOLBAR_COMPOSE)
841 toolbar_set_default(TOOLBAR_COMPOSE);
842 else if (source == TOOLBAR_MSGVIEW)
843 toolbar_set_default(TOOLBAR_MSGVIEW);
845 g_warning("refusing to write unknown Toolbar Configuration number %d", source);
849 toolbar_save_config_file(source);
854 * clears list of toolbar items read from configuration files
856 void toolbar_clear_list(ToolbarType source)
858 while (toolbar_config[source].item_list != NULL) {
859 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
861 toolbar_config[source].item_list =
862 g_slist_remove(toolbar_config[source].item_list, item);
864 toolbar_item_destroy(item);
866 g_slist_free(toolbar_config[source].item_list);
871 * return list of Toolbar items
873 GSList *toolbar_get_list(ToolbarType source)
877 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
878 list = toolbar_config[source].item_list;
883 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
885 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
887 toolbar_item->file = g_strdup(t_item->file);
888 toolbar_item->text = g_strdup(t_item->text);
889 toolbar_item->index = t_item->index;
891 toolbar_config[source].item_list =
892 g_slist_append(toolbar_config[source].item_list,
896 static void toolbar_action_execute(GtkWidget *widget,
904 for (cur = action_list; cur != NULL; cur = cur->next) {
905 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
907 if (widget == act->widget) {
908 i = prefs_actions_find_by_name(act->name);
916 actions_execute(data, i, widget, source);
918 g_warning("error: did not find Action to execute");
921 gboolean toolbar_check_action_btns(ToolbarType type)
923 GSList *temp, *curr, *list = toolbar_config[type].item_list;
924 gboolean modified = FALSE;
927 while (curr != NULL) {
928 ToolbarItem *toolbar_item = (ToolbarItem *) curr->data;
932 if (toolbar_item->index != A_CLAWS_ACTIONS)
935 if (prefs_actions_find_by_name(toolbar_item->text) == -1) {
936 list = g_slist_delete_link(list, temp);
937 g_free(toolbar_item->file);
938 g_free(toolbar_item->text);
939 g_free(toolbar_item);
947 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
948 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), tip); \
951 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
952 gtk_menu_tool_button_set_arrow_tooltip_text(GTK_MENU_TOOL_BUTTON(widget), tip); \
955 static void activate_compose_button (Toolbar *toolbar,
957 ComposeButtonType type)
959 if ((!toolbar->compose_mail_btn))
962 if (type == COMPOSEBUTTON_NEWS) {
963 gtk_tool_button_set_icon_widget(
964 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
965 toolbar->compose_news_icon);
967 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose News message"));
969 gtk_widget_show(toolbar->compose_news_icon);
971 gtk_tool_button_set_icon_widget(
972 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
973 toolbar->compose_mail_icon);
975 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose Email"));
977 gtk_widget_show(toolbar->compose_mail_icon);
979 toolbar->compose_btn_type = type;
982 void toolbar_set_compose_button(Toolbar *toolbar,
983 ComposeButtonType compose_btn_type)
985 if (toolbar->compose_btn_type != compose_btn_type)
986 activate_compose_button(toolbar,
987 prefs_common.toolbar_style,
991 static void activate_learn_button (Toolbar *toolbar,
993 LearnButtonType type)
995 if ((!toolbar->learn_spam_btn))
998 if (type == LEARN_SPAM) {
999 gtk_tool_button_set_icon_widget(
1000 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
1001 toolbar->learn_spam_icon);
1002 gtk_tool_button_set_label(
1003 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
1005 #ifndef GENERIC_UMPC
1006 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn spam"));
1008 gtk_widget_show(toolbar->learn_spam_icon);
1010 gtk_tool_button_set_icon_widget(
1011 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
1012 toolbar->learn_ham_icon);
1013 gtk_tool_button_set_label(
1014 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
1016 #ifndef GENERIC_UMPC
1017 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn ham"));
1019 gtk_widget_show(toolbar->learn_ham_icon);
1021 toolbar->learn_btn_type = type;
1024 void toolbar_set_learn_button(Toolbar *toolbar,
1025 LearnButtonType learn_btn_type)
1027 if (toolbar->learn_btn_type != learn_btn_type)
1028 activate_learn_button(toolbar,
1029 prefs_common.toolbar_style,
1033 void toolbar_toggle(guint action, gpointer data)
1035 MainWindow *mainwin = (MainWindow*)data;
1039 cm_return_if_fail(mainwin != NULL);
1041 toolbar_style(TOOLBAR_MAIN, action, mainwin);
1043 list = compose_get_compose_list();
1044 for (cur = list; cur != NULL; cur = cur->next) {
1045 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
1047 list = messageview_get_msgview_list();
1048 for (cur = list; cur != NULL; cur = cur->next) {
1049 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
1054 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
1056 switch ((ToolbarStyle)action) {
1058 gtk_widget_hide(handlebox_wid);
1061 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1065 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1069 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1072 case TOOLBAR_BOTH_HORIZ:
1073 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1074 GTK_TOOLBAR_BOTH_HORIZ);
1080 prefs_common.toolbar_style = (ToolbarStyle)action;
1081 gtk_widget_set_size_request(handlebox_wid, 1, -1);
1083 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1084 gtk_widget_show(handlebox_wid);
1085 gtk_widget_queue_resize(handlebox_wid);
1089 * Change the style of toolbar
1091 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1093 GtkWidget *handlebox_wid;
1094 GtkWidget *toolbar_wid;
1095 MainWindow *mainwin = (MainWindow*)data;
1096 Compose *compose = (Compose*)data;
1097 MessageView *msgview = (MessageView*)data;
1099 cm_return_if_fail(data != NULL);
1103 handlebox_wid = mainwin->handlebox;
1104 toolbar_wid = mainwin->toolbar->toolbar;
1106 case TOOLBAR_COMPOSE:
1107 handlebox_wid = compose->handlebox;
1108 toolbar_wid = compose->toolbar->toolbar;
1110 case TOOLBAR_MSGVIEW:
1111 handlebox_wid = msgview->handlebox;
1112 toolbar_wid = msgview->toolbar->toolbar;
1118 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1121 /* Toolbar handling */
1122 static void toolbar_inc_cb(GtkWidget *widget,
1125 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1126 MainWindow *mainwin;
1128 cm_return_if_fail(toolbar_item != NULL);
1130 switch (toolbar_item->type) {
1132 mainwin = (MainWindow*)toolbar_item->parent;
1133 inc_mail_cb(mainwin, 0, NULL);
1140 static void toolbar_inc_all_cb(GtkWidget *widget,
1143 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1144 MainWindow *mainwin;
1146 cm_return_if_fail(toolbar_item != NULL);
1148 switch (toolbar_item->type) {
1150 mainwin = (MainWindow*)toolbar_item->parent;
1151 inc_all_account_mail_cb(mainwin, 0, NULL);
1158 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1160 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1161 MainWindow *mainwin;
1163 cm_return_if_fail(toolbar_item != NULL);
1165 switch (toolbar_item->type) {
1167 mainwin = (MainWindow*)toolbar_item->parent;
1168 send_queue_cb(mainwin, 0, NULL);
1175 static void toolbar_exec_cb(GtkWidget *widget,
1178 MainWindow *mainwin = get_mainwin(data);
1180 cm_return_if_fail(mainwin != NULL);
1181 summary_execute(mainwin->summaryview);
1185 * Delete current/selected(s) message(s)
1187 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1189 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1190 MainWindow *mainwin;
1192 cm_return_if_fail(toolbar_item != NULL);
1193 cm_return_if_fail(toolbar_item->parent);
1195 switch (toolbar_item->type) {
1196 case TOOLBAR_MSGVIEW:
1197 messageview_delete((MessageView *)toolbar_item->parent);
1200 mainwin = (MainWindow *)toolbar_item->parent;
1201 summary_delete_trash(mainwin->summaryview);
1204 debug_print("toolbar event not supported\n");
1210 * Delete current/selected(s) message(s)
1212 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1214 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1215 MainWindow *mainwin;
1217 cm_return_if_fail(toolbar_item != NULL);
1218 cm_return_if_fail(toolbar_item->parent);
1220 switch (toolbar_item->type) {
1221 case TOOLBAR_MSGVIEW:
1222 messageview_delete((MessageView *)toolbar_item->parent);
1225 mainwin = (MainWindow *)toolbar_item->parent;
1226 summary_delete(mainwin->summaryview);
1229 debug_print("toolbar event not supported\n");
1234 static void toolbar_delete_dup(gpointer data, guint all)
1236 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1237 MainWindow *mainwin = NULL;
1239 cm_return_if_fail(toolbar_item != NULL);
1241 switch (toolbar_item->type) {
1243 mainwin = (MainWindow*)toolbar_item->parent;
1245 mainwindow_delete_duplicated_all(mainwin);
1247 mainwindow_delete_duplicated(mainwin);
1249 case TOOLBAR_COMPOSE:
1250 case TOOLBAR_MSGVIEW:
1253 debug_print("toolbar event not supported\n");
1258 static void toolbar_delete_dup_cb(GtkWidget *widget, gpointer data)
1260 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1261 MainWindow *mainwin = NULL;
1263 cm_return_if_fail(toolbar_item != NULL);
1265 switch (toolbar_item->type) {
1267 mainwin = (MainWindow*)toolbar_item->parent;
1268 mainwindow_delete_duplicated(mainwin);
1270 case TOOLBAR_COMPOSE:
1271 case TOOLBAR_MSGVIEW:
1279 * Compose new message
1281 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1283 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1284 MainWindow *mainwin;
1285 MessageView *msgview;
1287 cm_return_if_fail(toolbar_item != NULL);
1289 switch (toolbar_item->type) {
1291 mainwin = (MainWindow*)toolbar_item->parent;
1292 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1293 compose_news_cb(mainwin, 0, NULL);
1295 compose_mail_cb(mainwin, 0, NULL);
1297 case TOOLBAR_MSGVIEW:
1298 msgview = (MessageView*)toolbar_item->parent;
1299 compose_new_with_folderitem(NULL,
1300 msgview->msginfo->folder, NULL);
1303 debug_print("toolbar event not supported\n");
1307 static void toolbar_learn(gpointer data, guint as_spam)
1309 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1310 MainWindow *mainwin;
1311 MessageView *msgview;
1313 cm_return_if_fail(toolbar_item != NULL);
1315 switch (toolbar_item->type) {
1317 mainwin = (MainWindow*)toolbar_item->parent;
1319 mainwindow_learn(mainwin, TRUE);
1321 mainwindow_learn(mainwin, FALSE);
1323 case TOOLBAR_MSGVIEW:
1324 msgview = (MessageView*)toolbar_item->parent;
1326 messageview_learn(msgview, TRUE);
1328 messageview_learn(msgview, FALSE);
1331 debug_print("toolbar event not supported\n");
1335 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1337 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1338 MainWindow *mainwin;
1339 MessageView *msgview;
1341 cm_return_if_fail(toolbar_item != NULL);
1343 switch (toolbar_item->type) {
1345 mainwin = (MainWindow*)toolbar_item->parent;
1346 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1347 mainwindow_learn(mainwin, TRUE);
1349 mainwindow_learn(mainwin, FALSE);
1351 case TOOLBAR_MSGVIEW:
1352 msgview = (MessageView*)toolbar_item->parent;
1353 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1354 messageview_learn(msgview, TRUE);
1356 messageview_learn(msgview, FALSE);
1359 debug_print("toolbar event not supported\n");
1367 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1369 toolbar_reply(data, (prefs_common.reply_with_quote ?
1370 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE));
1375 * Reply message to Sender and All recipients
1377 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1380 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1381 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE));
1386 * Reply to Mailing List
1388 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1391 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1392 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE));
1397 * Reply to sender of message
1399 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1402 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1403 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE));
1409 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1411 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1414 cm_return_if_fail(toolbar_item != NULL);
1416 switch (toolbar_item->type) {
1418 case TOOLBAR_MSGVIEW:
1421 case TOOLBAR_COMPOSE:
1422 compose = (Compose *)toolbar_item->parent;
1427 #ifndef USE_ALT_ADDRBOOK
1428 addressbook_open(compose);
1430 GError* error = NULL;
1431 addressbook_connect_signals(compose);
1432 addressbook_dbus_open(TRUE, &error);
1434 g_warning("%s", error->message);
1435 g_error_free(error);
1442 * Forward current/selected(s) message(s)
1444 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1446 toolbar_reply(data, (COMPOSE_FORWARD));
1450 * Goto Prev Unread Message
1452 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1454 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1455 MainWindow *mainwin;
1456 MessageView *msgview;
1458 cm_return_if_fail(toolbar_item != NULL);
1460 switch (toolbar_item->type) {
1462 mainwin = (MainWindow*)toolbar_item->parent;
1463 summary_select_prev_unread(mainwin->summaryview);
1466 case TOOLBAR_MSGVIEW:
1467 msgview = (MessageView*)toolbar_item->parent;
1468 msgview->updating = TRUE;
1469 summary_select_prev_unread(msgview->mainwin->summaryview);
1470 msgview->updating = FALSE;
1472 if (msgview->deferred_destroy) {
1473 debug_print("messageview got away!\n");
1474 messageview_destroy(msgview);
1478 /* Now we need to update the messageview window */
1479 if (msgview->mainwin->summaryview->selected) {
1480 #ifndef GENERIC_UMPC
1481 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1484 messageview_show(msgview, msginfo,
1485 msgview->all_headers);
1488 gtk_widget_destroy(msgview->window);
1492 debug_print("toolbar event not supported\n");
1497 * Goto Next Unread Message
1499 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1501 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1502 MainWindow *mainwin;
1503 MessageView *msgview;
1505 cm_return_if_fail(toolbar_item != NULL);
1507 switch (toolbar_item->type) {
1509 mainwin = (MainWindow*)toolbar_item->parent;
1510 summary_select_next_unread(mainwin->summaryview);
1513 case TOOLBAR_MSGVIEW:
1514 msgview = (MessageView*)toolbar_item->parent;
1515 msgview->updating = TRUE;
1516 summary_select_next_unread(msgview->mainwin->summaryview);
1517 msgview->updating = FALSE;
1519 if (msgview->deferred_destroy) {
1520 debug_print("messageview got away!\n");
1521 messageview_destroy(msgview);
1525 /* Now we need to update the messageview window */
1526 if (msgview->mainwin->summaryview->selected) {
1527 #ifndef GENERIC_UMPC
1528 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1531 messageview_show(msgview, msginfo,
1532 msgview->all_headers);
1535 gtk_widget_destroy(msgview->window);
1539 debug_print("toolbar event not supported\n");
1543 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1545 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1546 MainWindow *mainwin;
1548 cm_return_if_fail(toolbar_item != NULL);
1550 switch (toolbar_item->type) {
1552 mainwin = (MainWindow *) toolbar_item->parent;
1553 summary_toggle_ignore_thread(mainwin->summaryview);
1555 case TOOLBAR_MSGVIEW:
1556 /* TODO: see toolbar_next_unread_cb() if you need
1557 * this in the message view */
1560 debug_print("toolbar event not supported\n");
1565 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1567 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1568 MainWindow *mainwin;
1570 cm_return_if_fail(toolbar_item != NULL);
1572 switch (toolbar_item->type) {
1574 mainwin = (MainWindow *) toolbar_item->parent;
1575 summary_toggle_watch_thread(mainwin->summaryview);
1577 case TOOLBAR_MSGVIEW:
1578 /* TODO: see toolbar_next_unread_cb() if you need
1579 * this in the message view */
1582 debug_print("toolbar event not supported\n");
1587 static void toolbar_mark_cb(GtkWidget *widget, gpointer data)
1589 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1590 MainWindow *mainwin;
1592 cm_return_if_fail(toolbar_item != NULL);
1594 switch (toolbar_item->type) {
1596 mainwin = (MainWindow *) toolbar_item->parent;
1597 summary_mark(mainwin->summaryview);
1599 case TOOLBAR_MSGVIEW:
1600 /* TODO: see toolbar_next_unread_cb() if you need
1601 * this in the message view */
1604 debug_print("toolbar event not supported\n");
1609 static void toolbar_unmark_cb(GtkWidget *widget, gpointer data)
1611 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1612 MainWindow *mainwin;
1614 cm_return_if_fail(toolbar_item != NULL);
1616 switch (toolbar_item->type) {
1618 mainwin = (MainWindow *) toolbar_item->parent;
1619 summary_unmark(mainwin->summaryview);
1621 case TOOLBAR_MSGVIEW:
1622 /* TODO: see toolbar_next_unread_cb() if you need
1623 * this in the message view */
1626 debug_print("toolbar event not supported\n");
1631 static void toolbar_lock_cb(GtkWidget *widget, gpointer data)
1633 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1634 MainWindow *mainwin;
1636 cm_return_if_fail(toolbar_item != NULL);
1638 switch (toolbar_item->type) {
1640 mainwin = (MainWindow *) toolbar_item->parent;
1641 summary_msgs_lock(mainwin->summaryview);
1643 case TOOLBAR_MSGVIEW:
1644 /* TODO: see toolbar_next_unread_cb() if you need
1645 * this in the message view */
1648 debug_print("toolbar event not supported\n");
1653 static void toolbar_unlock_cb(GtkWidget *widget, gpointer data)
1655 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1656 MainWindow *mainwin;
1658 cm_return_if_fail(toolbar_item != NULL);
1660 switch (toolbar_item->type) {
1662 mainwin = (MainWindow *) toolbar_item->parent;
1663 summary_msgs_unlock(mainwin->summaryview);
1665 case TOOLBAR_MSGVIEW:
1666 /* TODO: see toolbar_next_unread_cb() if you need
1667 * this in the message view */
1670 debug_print("toolbar event not supported\n");
1675 static void toolbar_all_read_cb(GtkWidget *widget, gpointer data)
1677 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1678 MainWindow *mainwin;
1680 cm_return_if_fail(toolbar_item != NULL);
1682 switch (toolbar_item->type) {
1684 mainwin = (MainWindow *) toolbar_item->parent;
1685 summary_mark_all_read(mainwin->summaryview, TRUE);
1687 case TOOLBAR_MSGVIEW:
1688 /* TODO: see toolbar_next_unread_cb() if you need
1689 * this in the message view */
1692 debug_print("toolbar event not supported\n");
1697 static void toolbar_all_unread_cb(GtkWidget *widget, gpointer data)
1699 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1700 MainWindow *mainwin;
1702 cm_return_if_fail(toolbar_item != NULL);
1704 switch (toolbar_item->type) {
1706 mainwin = (MainWindow *) toolbar_item->parent;
1707 summary_mark_all_unread(mainwin->summaryview, TRUE);
1709 case TOOLBAR_MSGVIEW:
1710 /* TODO: see toolbar_next_unread_cb() if you need
1711 * this in the message view */
1714 debug_print("toolbar event not supported\n");
1719 static void toolbar_read_cb(GtkWidget *widget, gpointer data)
1721 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1722 MainWindow *mainwin;
1724 cm_return_if_fail(toolbar_item != NULL);
1726 switch (toolbar_item->type) {
1728 mainwin = (MainWindow *) toolbar_item->parent;
1729 summary_mark_as_read(mainwin->summaryview);
1731 case TOOLBAR_MSGVIEW:
1732 /* TODO: see toolbar_next_unread_cb() if you need
1733 * this in the message view */
1736 debug_print("toolbar event not supported\n");
1741 static void toolbar_unread_cb(GtkWidget *widget, gpointer data)
1743 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1744 MainWindow *mainwin;
1746 cm_return_if_fail(toolbar_item != NULL);
1748 switch (toolbar_item->type) {
1750 mainwin = (MainWindow *) toolbar_item->parent;
1751 summary_mark_as_unread(mainwin->summaryview);
1753 case TOOLBAR_MSGVIEW:
1754 /* TODO: see toolbar_next_unread_cb() if you need
1755 * this in the message view */
1758 debug_print("toolbar event not supported\n");
1763 static void toolbar_run_processing_cb(GtkWidget *widget, gpointer data)
1765 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1766 MainWindow *mainwin;
1769 cm_return_if_fail(toolbar_item != NULL);
1771 switch (toolbar_item->type) {
1773 mainwin = (MainWindow *) toolbar_item->parent;
1774 item = mainwin->summaryview->folder_item;
1775 cm_return_if_fail(item != NULL);
1776 item->processing_pending = TRUE;
1777 folder_item_apply_processing(item);
1778 item->processing_pending = FALSE;
1781 debug_print("toolbar event not supported\n");
1786 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1788 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1790 cm_return_if_fail(toolbar_item != NULL);
1795 static void toolbar_cancel_send_cb(GtkWidget *widget, gpointer data)
1797 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1799 cm_return_if_fail(toolbar_item != NULL);
1803 static void toolbar_cancel_all_cb(GtkWidget *widget, gpointer data)
1805 toolbar_cancel_inc_cb(widget, data);
1806 toolbar_cancel_send_cb(widget, data);
1809 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1811 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1812 MainWindow *mainwin;
1814 cm_return_if_fail(toolbar_item != NULL);
1816 switch (toolbar_item->type) {
1818 mainwin = (MainWindow *) toolbar_item->parent;
1819 summary_print(mainwin->summaryview);
1821 case TOOLBAR_MSGVIEW:
1822 /* TODO: see toolbar_next_unread_cb() if you need
1823 * this in the message view */
1826 debug_print("toolbar event not supported\n");
1831 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1833 compose_toolbar_cb(A_SEND, data);
1836 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1838 compose_toolbar_cb(A_SEND_LATER, data);
1841 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1843 compose_toolbar_cb(A_DRAFT, data);
1846 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1848 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1849 MainWindow *mainwin;
1850 MessageView *messageview;
1853 cm_return_if_fail(toolbar_item != NULL);
1855 switch (toolbar_item->type) {
1857 mainwin = (MainWindow *) toolbar_item->parent;
1858 app_will_exit(NULL, mainwin);
1860 case TOOLBAR_MSGVIEW:
1861 messageview = (MessageView *)toolbar_item->parent;
1862 messageview_destroy(messageview);
1864 case TOOLBAR_COMPOSE:
1865 compose = (Compose *)toolbar_item->parent;
1866 compose_close_toolbar(compose);
1871 static void toolbar_preferences_cb(GtkWidget *widget, gpointer data)
1876 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1878 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1879 MainWindow *mainwin;
1881 cm_return_if_fail(toolbar_item != NULL);
1883 switch (toolbar_item->type) {
1885 mainwin = (MainWindow *) toolbar_item->parent;
1886 summary_open_row(NULL, mainwin->summaryview);
1888 case TOOLBAR_MSGVIEW:
1889 debug_print("toolbar event not supported\n");
1891 case TOOLBAR_COMPOSE:
1892 debug_print("toolbar event not supported\n");
1897 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1899 compose_toolbar_cb(A_INSERT, data);
1902 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1904 compose_toolbar_cb(A_ATTACH, data);
1907 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1909 compose_toolbar_cb(A_SIG, data);
1912 static void toolbar_replace_sig_cb(GtkWidget *widget, gpointer data)
1914 compose_toolbar_cb(A_REP_SIG, data);
1917 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1919 compose_toolbar_cb(A_EXTEDITOR, data);
1922 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1924 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1927 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1929 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1933 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1935 compose_toolbar_cb(A_CHECK_SPELLING, data);
1939 static void toolbar_privacy_sign_cb(GtkWidget *widget, gpointer data)
1941 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1942 Compose *compose = (Compose *)toolbar_item->parent;
1943 gboolean state = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget));
1945 cm_return_if_fail(compose != NULL);
1946 compose_use_signing(compose, state);
1949 /* Any time the toggle button gets toggled, we want to update its tooltip. */
1950 static void toolbar_privacy_sign_toggled_cb(GtkWidget *widget, gpointer data)
1952 gboolean state = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget));
1955 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), _("Message will be signed"));
1957 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), _("Message will not be signed"));
1960 static void toolbar_privacy_encrypt_cb(GtkWidget *widget, gpointer data)
1962 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1963 Compose *compose = (Compose *)toolbar_item->parent;
1964 gboolean state = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget));
1966 cm_return_if_fail(compose != NULL);
1967 compose_use_encryption(compose, state);
1970 /* Any time the toggle button gets toggled, we want to update its tooltip. */
1971 static void toolbar_privacy_encrypt_toggled_cb(GtkWidget *widget, gpointer data)
1973 gboolean state = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget));
1976 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), _("Message will be encrypted"));
1978 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), _("Message will not be encrypted"));
1982 * Execute actions from toolbar
1984 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1986 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1987 GSList *action_list;
1988 MainWindow *mainwin;
1990 MessageView *msgview;
1991 gpointer parent = toolbar_item->parent;
1993 cm_return_if_fail(toolbar_item != NULL);
1995 switch (toolbar_item->type) {
1997 mainwin = (MainWindow*)parent;
1998 action_list = mainwin->toolbar->action_list;
2000 case TOOLBAR_COMPOSE:
2001 compose = (Compose*)parent;
2002 action_list = compose->toolbar->action_list;
2004 case TOOLBAR_MSGVIEW:
2005 msgview = (MessageView*)parent;
2006 action_list = msgview->toolbar->action_list;
2009 debug_print("toolbar event not supported\n");
2012 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
2015 static void toolbar_plugins_execute_cb(GtkWidget *widget, gpointer data)
2017 ToolbarItem *toolbar_item = data;
2018 prefs_toolbar_execute_plugin_item(toolbar_item->parent, toolbar_item->type, toolbar_item->text);
2021 static MainWindow *get_mainwin(gpointer data)
2023 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2024 MainWindow *mainwin = NULL;
2025 MessageView *msgview;
2027 cm_return_val_if_fail(toolbar_item != NULL, NULL);
2029 switch(toolbar_item->type) {
2031 mainwin = (MainWindow*)toolbar_item->parent;
2033 case TOOLBAR_MSGVIEW:
2034 msgview = (MessageView*)toolbar_item->parent;
2035 mainwin = (MainWindow*)msgview->mainwin;
2044 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
2046 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2047 MainWindow *mainwin = NULL;
2048 switch(toolbar_item->type) {
2050 mainwin = (MainWindow*)toolbar_item->parent;
2053 g_warning("wrong toolbar type");
2057 if (!mainwin->in_folder) {
2058 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
2060 folderview_select(mainwin->folderview, item);
2063 folderview_grab_focus(mainwin->folderview);
2064 mainwindow_exit_folder(mainwin);
2068 static void toolbar_buttons_cb(GtkWidget *widget,
2075 void (*func)(GtkWidget *widget, gpointer data);
2077 { A_RECEIVE_ALL, toolbar_inc_all_cb },
2078 { A_RECEIVE_CUR, toolbar_inc_cb },
2079 { A_SEND_QUEUED, toolbar_send_queued_cb },
2080 { A_COMPOSE_EMAIL, toolbar_compose_cb },
2081 { A_COMPOSE_NEWS, toolbar_compose_cb },
2082 { A_REPLY_MESSAGE, toolbar_reply_cb },
2083 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
2084 { A_REPLY_ALL, toolbar_reply_to_all_cb },
2085 { A_REPLY_ML, toolbar_reply_to_list_cb },
2086 { A_FORWARD, toolbar_forward_cb },
2087 { A_TRASH, toolbar_trash_cb },
2088 { A_DELETE_REAL, toolbar_delete_cb },
2089 { A_EXECUTE, toolbar_exec_cb },
2090 { A_GOTO_PREV, toolbar_prev_unread_cb },
2091 { A_GOTO_NEXT, toolbar_next_unread_cb },
2092 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
2093 { A_WATCH_THREAD, toolbar_watch_thread_cb },
2094 { A_MARK, toolbar_mark_cb },
2095 { A_UNMARK, toolbar_unmark_cb },
2096 { A_LOCK, toolbar_lock_cb },
2097 { A_UNLOCK, toolbar_unlock_cb },
2098 { A_ALL_READ, toolbar_all_read_cb },
2099 { A_ALL_UNREAD, toolbar_all_unread_cb },
2100 { A_READ, toolbar_read_cb },
2101 { A_UNREAD, toolbar_unread_cb },
2102 { A_RUN_PROCESSING, toolbar_run_processing_cb },
2103 { A_PRINT, toolbar_print_cb },
2104 { A_LEARN_SPAM, toolbar_learn_cb },
2105 { A_DELETE_DUP, toolbar_delete_dup_cb },
2106 { A_GO_FOLDERS, toolbar_go_folders_cb },
2108 { A_SEND, toolbar_send_cb },
2109 { A_SEND_LATER, toolbar_send_later_cb },
2110 { A_DRAFT, toolbar_draft_cb },
2111 { A_OPEN_MAIL, toolbar_open_mail_cb },
2112 { A_CLOSE, toolbar_close_cb },
2113 { A_PREFERENCES, toolbar_preferences_cb },
2114 { A_INSERT, toolbar_insert_cb },
2115 { A_ATTACH, toolbar_attach_cb },
2116 { A_SIG, toolbar_sig_cb },
2117 { A_REP_SIG, toolbar_replace_sig_cb },
2118 { A_EXTEDITOR, toolbar_ext_editor_cb },
2119 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
2120 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
2121 { A_ADDRBOOK, toolbar_addrbook_cb },
2123 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
2125 { A_PRIVACY_SIGN, toolbar_privacy_sign_cb },
2126 { A_PRIVACY_ENCRYPT, toolbar_privacy_encrypt_cb },
2127 { A_CLAWS_ACTIONS, toolbar_actions_execute_cb },
2128 { A_CANCEL_INC, toolbar_cancel_inc_cb },
2129 { A_CANCEL_SEND, toolbar_cancel_send_cb },
2130 { A_CANCEL_ALL, toolbar_cancel_all_cb },
2131 { A_CLAWS_PLUGINS, toolbar_plugins_execute_cb },
2134 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
2136 for (i = 0; i < num_items; i++) {
2137 if (callbacks[i].index == item->index) {
2138 callbacks[i].func(widget, item);
2143 #ifndef GENERIC_UMPC
2144 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
2145 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
2146 gtk_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
2147 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
2148 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
2149 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
2150 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2151 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
2155 #define TOOLBAR_TOGGLE_ITEM(item,icon,text,tooltip) { \
2156 item = GTK_WIDGET(gtk_toggle_tool_button_new()); \
2157 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(item), icon); \
2158 gtk_tool_button_set_label(GTK_TOOL_BUTTON(item), text); \
2159 gtk_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
2160 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
2161 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
2162 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
2163 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2164 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
2168 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
2169 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
2170 GList *gchild = NULL; \
2171 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
2172 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
2173 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
2174 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
2175 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2176 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
2178 CLAWS_SET_ARROW_TIP(GTK_MENU_TOOL_BUTTON(item), menutip); \
2179 child = gtk_bin_get_child(GTK_BIN(item)); \
2180 gchild = gtk_container_get_children( \
2181 GTK_CONTAINER(child)); \
2182 btn = (GtkWidget *)gchild->data; \
2183 gtk_widget_set_can_focus(btn, FALSE); \
2184 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
2185 gtk_widget_set_can_focus(arr, FALSE); \
2186 g_list_free(gchild); \
2187 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
2188 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
2189 g_list_free(gchild); \
2194 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
2195 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
2196 gtk_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
2197 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
2198 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
2199 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
2200 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2203 #define TOOLBAR_TOGGLE_ITEM(item,icon,text,tooltip) { \
2204 item = GTK_WIDGET(gtk_toggle_tool_button_new()); \
2205 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(item), icon); \
2206 gtk_tool_button_set_label(GTK_TOOL_BUTTON(item), text); \
2207 gtk_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
2208 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
2209 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
2210 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
2211 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2214 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
2215 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
2216 GList *gchild = NULL; \
2217 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
2218 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
2219 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
2220 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
2221 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2222 child = gtk_bin_get_child(GTK_BIN(item)); \
2223 gchild = gtk_container_get_children( \
2224 GTK_CONTAINER(child)); \
2225 btn = (GtkWidget *)gchild->data; \
2226 gtk_widget_set_can_focus(btn, FALSE); \
2227 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
2228 gtk_widget_set_can_focus(arr, FALSE); \
2229 g_list_free(gchild); \
2230 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
2231 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
2232 g_list_free(gchild); \
2236 #define ADD_MENU_ITEM(name,cb,data) { \
2237 item = gtk_menu_item_new_with_mnemonic(name); \
2238 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); \
2239 g_signal_connect(G_OBJECT(item), "activate", \
2242 g_object_set_data(G_OBJECT(item), "int-value", GINT_TO_POINTER(data)); \
2243 gtk_widget_show(item); \
2246 #ifndef GENERIC_UMPC
2247 static void toolbar_reply_menu_cb(GtkWidget *widget, gpointer data)
2249 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
2250 ToolbarItem *toolbar_item = (ToolbarItem *)data;
2252 toolbar_reply(toolbar_item, GPOINTER_TO_INT(int_value));
2255 static void toolbar_delete_dup_menu_cb(GtkWidget *widget, gpointer data)
2257 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
2258 ToolbarItem *toolbar_item = (ToolbarItem *)data;
2260 toolbar_delete_dup(toolbar_item, GPOINTER_TO_INT(int_value));
2264 static void toolbar_learn_menu_cb(GtkWidget *widget, gpointer data)
2266 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
2267 ToolbarItem *toolbar_item = (ToolbarItem *)data;
2269 toolbar_learn(toolbar_item, GPOINTER_TO_INT(int_value));
2274 * Create a new toolbar with specified type
2275 * if a callback list is passed it will be used before the
2276 * common callback list
2278 Toolbar *toolbar_create(ToolbarType type,
2279 GtkWidget *container,
2282 ToolbarItem *toolbar_item;
2285 GtkWidget *icon_wid = NULL;
2286 GtkWidget *icon_news;
2287 GtkWidget *icon_ham;
2289 ToolbarClawsActions *action_item;
2291 GSList *toolbar_list;
2292 Toolbar *toolbar_data;
2294 toolbar_read_config_file(type);
2295 toolbar_list = toolbar_get_list(type);
2297 toolbar_data = g_new0(Toolbar, 1);
2299 toolbar = gtk_toolbar_new();
2301 gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL);
2303 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
2304 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
2305 gtk_widget_set_hexpand(toolbar, TRUE);
2307 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
2309 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
2310 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
2314 toolbar_item = g_new0(ToolbarItem, 1);
2315 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
2316 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
2317 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
2318 toolbar_item->parent = data;
2319 toolbar_item->type = type;
2321 /* collect toolbar items in list to keep track */
2322 toolbar_data->item_list =
2323 g_slist_append(toolbar_data->item_list,
2325 icon_wid = stock_pixmap_widget(stock_pixmap_get_icon(toolbar_item->file));
2327 switch (toolbar_item->index) {
2330 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
2331 toolbar_data->folders_btn = item;
2334 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2335 _("Receive Mail from all Accounts"),
2336 _("Receive Mail from selected Account"));
2337 toolbar_data->getall_btn = item;
2340 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Receive Mail from current Account"));
2341 toolbar_data->get_btn = item;
2344 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
2345 toolbar_data->send_btn = item;
2348 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
2349 toolbar_data->close_window_btn = item;
2352 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open preferences"));
2353 toolbar_data->preferences_btn = item;
2356 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
2357 toolbar_data->open_mail_btn = item;
2359 case A_COMPOSE_EMAIL:
2360 #ifndef GENERIC_UMPC
2361 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2363 _("Compose with selected Account"));
2364 toolbar_data->compose_mail_btn = item;
2365 toolbar_data->compose_mail_icon = icon_wid;
2366 g_object_ref_sink(toolbar_data->compose_mail_icon);
2368 icon_news = stock_pixmap_widget(STOCK_PIXMAP_NEWS_COMPOSE);
2369 toolbar_data->compose_news_icon = icon_news;
2370 g_object_ref_sink(toolbar_data->compose_news_icon);
2372 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2373 _("Compose Email"));
2374 toolbar_data->compose_mail_btn = item;
2375 toolbar_data->compose_mail_icon = icon_wid;
2377 icon_news = stock_pixmap_widget(STOCK_PIXMAP_NEWS_COMPOSE);
2378 toolbar_data->compose_news_icon = icon_news;
2382 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2385 toolbar_data->learn_spam_btn = item;
2386 toolbar_data->learn_spam_icon = icon_wid;
2387 g_object_ref_sink(toolbar_data->learn_spam_icon);
2389 icon_ham = stock_pixmap_widget(STOCK_PIXMAP_HAM_BTN);
2390 toolbar_data->learn_ham_icon = icon_ham;
2391 g_object_ref_sink(toolbar_data->learn_ham_icon);
2393 menu = gtk_menu_new();
2394 ADD_MENU_ITEM(_("Learn as _Spam"), toolbar_learn_menu_cb, TRUE);
2395 ADD_MENU_ITEM(_("Learn as _Ham"), toolbar_learn_menu_cb, FALSE);
2396 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->learn_spam_btn), menu);
2399 #ifndef GENERIC_UMPC
2400 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2401 _("Delete duplicates"),
2402 _("Delete duplicates options"));
2403 toolbar_data->delete_dup_btn = item;
2405 menu = gtk_menu_new();
2406 ADD_MENU_ITEM(_("Delete duplicates in selected folder"), toolbar_delete_dup_menu_cb, FALSE);
2407 ADD_MENU_ITEM(_("Delete duplicates in all folders"), toolbar_delete_dup_menu_cb, TRUE);
2408 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->delete_dup_btn), menu);
2410 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete duplicates"));
2411 toolbar_data->delete_dup_btn = item;
2414 case A_REPLY_MESSAGE:
2415 #ifndef GENERIC_UMPC
2416 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2417 _("Reply to Message"),
2418 _("Reply to Message options"));
2419 toolbar_data->reply_btn = item;
2421 menu = gtk_menu_new();
2422 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITH_QUOTE);
2423 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITHOUT_QUOTE);
2424 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->reply_btn), menu);
2426 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2427 _("Reply to Message"));
2428 toolbar_data->reply_btn = item;
2431 case A_REPLY_SENDER:
2432 #ifndef GENERIC_UMPC
2433 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2434 _("Reply to Sender"),
2435 _("Reply to Sender options"));
2436 toolbar_data->replysender_btn = item;
2438 menu = gtk_menu_new();
2439 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE);
2440 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
2441 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replysender_btn), menu);
2443 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2444 _("Reply to Sender"));
2445 toolbar_data->replysender_btn = item;
2449 #ifndef GENERIC_UMPC
2450 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2452 _("Reply to All options"));
2453 toolbar_data->replyall_btn = item;
2455 menu = gtk_menu_new();
2456 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE);
2457 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
2458 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replyall_btn), menu);
2460 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2462 toolbar_data->replyall_btn = item;
2466 #ifndef GENERIC_UMPC
2467 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2468 _("Reply to Mailing-list"),
2469 _("Reply to Mailing-list options"));
2470 toolbar_data->replylist_btn = item;
2472 menu = gtk_menu_new();
2473 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE);
2474 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
2475 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replylist_btn), menu);
2477 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2478 _("Reply to Mailing-list"));
2479 toolbar_data->replylist_btn = item;
2483 #ifndef GENERIC_UMPC
2484 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2485 _("Forward Message"),
2486 _("Forward Message options"));
2487 toolbar_data->fwd_btn = item;
2489 menu = gtk_menu_new();
2490 ADD_MENU_ITEM(_("_Forward"), toolbar_reply_menu_cb, COMPOSE_FORWARD_INLINE);
2491 ADD_MENU_ITEM(_("For_ward as attachment"), toolbar_reply_menu_cb, COMPOSE_FORWARD_AS_ATTACH);
2492 ADD_MENU_ITEM(_("Redirec_t"), toolbar_reply_menu_cb, COMPOSE_REDIRECT);
2493 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->fwd_btn), menu);
2495 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2496 _("Forward Message"));
2497 toolbar_data->fwd_btn = item;
2501 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
2502 toolbar_data->trash_btn = item;
2505 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
2506 toolbar_data->delete_btn = item;
2509 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
2510 toolbar_data->exec_btn = item;
2513 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
2514 toolbar_data->prev_btn = item;
2517 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
2518 toolbar_data->next_btn = item;
2521 /* Compose Toolbar */
2523 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2524 toolbar_data->send_btn = item;
2527 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2528 toolbar_data->sendl_btn = item;
2531 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2532 toolbar_data->draft_btn = item;
2535 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2536 toolbar_data->insert_btn = item;
2539 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2540 toolbar_data->attach_btn = item;
2543 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2544 toolbar_data->sig_btn = item;
2547 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Replace signature"));
2548 toolbar_data->repsig_btn = item;
2551 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2552 toolbar_data->exteditor_btn = item;
2554 case A_LINEWRAP_CURRENT:
2555 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2556 toolbar_data->linewrap_current_btn = item;
2558 case A_LINEWRAP_ALL:
2559 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2560 toolbar_data->linewrap_all_btn = item;
2563 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2564 toolbar_data->addrbook_btn = item;
2567 case A_CHECK_SPELLING:
2568 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2569 toolbar_data->spellcheck_btn = item;
2572 case A_PRIVACY_SIGN:
2573 TOOLBAR_TOGGLE_ITEM(item,icon_wid,toolbar_item->text,_("Sign"));
2574 g_signal_connect (G_OBJECT(item), "toggled",
2575 G_CALLBACK(toolbar_privacy_sign_toggled_cb), NULL);
2576 /* Call the "toggled" handler to set correct tooltip. */
2577 toolbar_privacy_sign_toggled_cb(item, NULL);
2578 toolbar_data->privacy_sign_btn = item;
2580 case A_PRIVACY_ENCRYPT:
2581 TOOLBAR_TOGGLE_ITEM(item,icon_wid,toolbar_item->text,_("Encrypt"));
2582 g_signal_connect (G_OBJECT(item), "toggled",
2583 G_CALLBACK(toolbar_privacy_encrypt_toggled_cb), NULL);
2584 /* Call the "toggled" handler to set correct tooltip. */
2585 toolbar_privacy_encrypt_toggled_cb(item, NULL);
2586 toolbar_data->privacy_encrypt_btn = item;
2589 case A_CLAWS_ACTIONS:
2590 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2591 action_item = g_new0(ToolbarClawsActions, 1);
2592 action_item->widget = item;
2593 action_item->name = g_strdup(toolbar_item->text);
2595 toolbar_data->action_list =
2596 g_slist_append(toolbar_data->action_list,
2600 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2601 toolbar_data->cancel_inc_btn = item;
2604 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel sending"));
2605 toolbar_data->cancel_send_btn = item;
2608 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving/sending"));
2609 toolbar_data->cancel_all_btn = item;
2611 case A_CLAWS_PLUGINS:
2612 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, toolbar_item->text);
2615 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2616 toolbar_ret_descr_from_val(toolbar_item->index));
2617 /* find and set the tool tip text */
2622 toolbar_data->toolbar = toolbar;
2624 gtk_widget_show_all(toolbar);
2626 if (type == TOOLBAR_MAIN) {
2628 MainWindow *mainwin = mainwindow_get_mainwindow();
2629 GtkWidget *progressbar = gtk_progress_bar_new();
2630 item = GTK_WIDGET(gtk_tool_item_new());
2631 gtk_container_add (GTK_CONTAINER (item), progressbar);
2632 gtk_widget_show(item);
2633 gtk_widget_set_size_request(progressbar, 84, -1);
2634 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2635 mainwin->progressbar = progressbar;
2637 activate_compose_button(toolbar_data,
2638 prefs_common.toolbar_style,
2639 toolbar_data->compose_btn_type);
2641 if (type != TOOLBAR_COMPOSE)
2642 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2645 gtk_container_add(GTK_CONTAINER(container), toolbar);
2646 gtk_container_set_border_width(GTK_CONTAINER(container), 0);
2648 return toolbar_data;
2652 * Free toolbar structures
2655 #define UNREF_ICON(icon) if (toolbar->icon != NULL) \
2656 g_object_unref(toolbar->icon)
2658 void toolbar_destroy(Toolbar * toolbar)
2660 UNREF_ICON(compose_mail_icon);
2661 UNREF_ICON(compose_news_icon);
2662 UNREF_ICON(learn_spam_icon);
2663 UNREF_ICON(learn_ham_icon);
2664 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2665 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2670 void toolbar_item_destroy(ToolbarItem *item)
2672 cm_return_if_fail(item != NULL);
2681 void toolbar_update(ToolbarType type, gpointer data)
2683 Toolbar *toolbar_data;
2684 GtkWidget *handlebox;
2685 MainWindow *mainwin = (MainWindow*)data;
2686 Compose *compose = (Compose*)data;
2687 MessageView *msgview = (MessageView*)data;
2689 #ifndef GENERIC_UMPC
2692 toolbar_data = mainwin->toolbar;
2693 handlebox = mainwin->handlebox;
2695 case TOOLBAR_COMPOSE:
2696 toolbar_data = compose->toolbar;
2697 handlebox = compose->handlebox;
2699 case TOOLBAR_MSGVIEW:
2700 toolbar_data = msgview->toolbar;
2701 handlebox = msgview->handlebox;
2707 gtk_container_remove(GTK_CONTAINER(handlebox),
2708 GTK_WIDGET(toolbar_data->toolbar));
2710 toolbar_init(toolbar_data);
2711 toolbar_data = toolbar_create(type, handlebox, data);
2715 toolbar_data = mainwin->toolbar;
2716 handlebox = mainwin->window;
2718 case TOOLBAR_COMPOSE:
2719 toolbar_data = compose->toolbar;
2720 handlebox = compose->window;
2722 case TOOLBAR_MSGVIEW:
2723 toolbar_data = msgview->toolbar;
2724 handlebox = msgview->window;
2729 toolbar_init(toolbar_data);
2730 toolbar_data = toolbar_create(type, handlebox, data);
2735 mainwin->toolbar = toolbar_data;
2737 case TOOLBAR_COMPOSE:
2738 compose->toolbar = toolbar_data;
2740 case TOOLBAR_MSGVIEW:
2741 msgview->toolbar = toolbar_data;
2745 toolbar_style(type, prefs_common.toolbar_style, data);
2747 if (type == TOOLBAR_MAIN) {
2748 toolbar_main_set_sensitive((MainWindow*)data);
2749 account_set_menu_only_toolbar();
2753 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2754 gtk_widget_set_sensitive(widget, sensitive); \
2757 void toolbar_main_set_sensitive(gpointer data)
2759 SensitiveCondMask state;
2761 MainWindow *mainwin = (MainWindow*)data;
2762 Toolbar *toolbar = mainwin->toolbar;
2764 GSList *entry_list = NULL;
2766 typedef struct _Entry Entry;
2769 SensitiveCondMask cond;
2773 #define SET_WIDGET_COND(w, ...) \
2775 Entry *e = g_new0(Entry, 1); \
2777 e->cond = main_window_get_mask(__VA_ARGS__, -1); \
2778 entry_list = g_slist_append(entry_list, e); \
2781 /* match all bit flags */
2783 if (toolbar->get_btn)
2784 SET_WIDGET_COND(toolbar->get_btn,
2785 M_HAVE_ACCOUNT, M_UNLOCKED, M_HAVE_RETRIEVABLE_ACCOUNT);
2787 if (toolbar->getall_btn) {
2788 SET_WIDGET_COND(toolbar->getall_btn,
2789 M_HAVE_ACCOUNT, M_UNLOCKED, M_HAVE_ANY_RETRIEVABLE_ACCOUNT);
2791 if (toolbar->send_btn) {
2792 SET_WIDGET_COND(toolbar->send_btn,
2793 M_HAVE_QUEUED_MAILS);
2795 if (toolbar->compose_mail_btn) {
2796 SET_WIDGET_COND(toolbar->compose_mail_btn,
2799 if (toolbar->close_window_btn) {
2800 SET_WIDGET_COND(toolbar->close_window_btn,
2803 if (toolbar->open_mail_btn) {
2804 SET_WIDGET_COND(toolbar->open_mail_btn,
2805 M_TARGET_EXIST, M_SUMMARY_ISLIST);
2807 if (toolbar->reply_btn) {
2808 SET_WIDGET_COND(toolbar->reply_btn,
2809 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2811 if (toolbar->replyall_btn) {
2812 SET_WIDGET_COND(toolbar->replyall_btn,
2813 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2815 if (toolbar->replylist_btn) {
2816 SET_WIDGET_COND(toolbar->replylist_btn,
2817 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2819 if (toolbar->replysender_btn) {
2820 SET_WIDGET_COND(toolbar->replysender_btn,
2821 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2823 if (toolbar->fwd_btn) {
2824 SET_WIDGET_COND(toolbar->fwd_btn,
2825 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2828 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2829 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST, M_SUMMARY_ISLIST);
2831 SET_WIDGET_COND(toolbar->next_btn, -1);
2834 if (toolbar->trash_btn)
2835 SET_WIDGET_COND(toolbar->trash_btn,
2836 M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS);
2838 if (toolbar->delete_btn)
2839 SET_WIDGET_COND(toolbar->delete_btn,
2840 M_TARGET_EXIST, M_ALLOW_DELETE);
2842 if (toolbar->delete_dup_btn)
2843 SET_WIDGET_COND(toolbar->delete_dup_btn,
2844 M_MSG_EXIST, M_ALLOW_DELETE, M_SUMMARY_ISLIST);
2846 if (toolbar->exec_btn)
2847 SET_WIDGET_COND(toolbar->exec_btn,
2850 if (toolbar->learn_spam_btn)
2851 SET_WIDGET_COND(toolbar->learn_spam_btn,
2852 M_TARGET_EXIST, M_CAN_LEARN_SPAM, M_SUMMARY_ISLIST);
2854 if (toolbar->cancel_inc_btn)
2855 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2858 if (toolbar->cancel_send_btn)
2859 SET_WIDGET_COND(toolbar->cancel_send_btn,
2862 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2863 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2865 SET_WIDGET_COND(act->widget, M_TARGET_EXIST, M_UNLOCKED);
2868 state = main_window_get_current_state(mainwin);
2870 for (cur = entry_list; cur != NULL; cur = cur->next) {
2871 Entry *e = (Entry*) cur->data;
2873 if (e->widget != NULL) {
2874 sensitive = ((e->cond & state) == e->cond);
2875 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2879 while (entry_list != NULL) {
2880 Entry *e = (Entry*) entry_list->data;
2882 entry_list = g_slist_remove(entry_list, e);
2886 /* match any bit flags */
2888 if (toolbar->cancel_all_btn)
2889 SET_WIDGET_COND(toolbar->cancel_all_btn,
2890 M_INC_ACTIVE, M_SEND_ACTIVE);
2892 for (cur = entry_list; cur != NULL; cur = cur->next) {
2893 Entry *e = (Entry*) cur->data;
2895 if (e->widget != NULL) {
2896 sensitive = ((e->cond & state) != 0);
2897 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2901 while (entry_list != NULL) {
2902 Entry *e = (Entry*) entry_list->data;
2904 entry_list = g_slist_remove(entry_list, e);
2908 g_slist_free(entry_list);
2910 activate_compose_button(toolbar,
2911 prefs_common.toolbar_style,
2912 toolbar->compose_btn_type);
2914 #undef SET_WIDGET_COND
2917 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2919 Compose *compose = (Compose*)data;
2920 GSList *items = compose->toolbar->action_list;
2922 if (compose->toolbar->send_btn)
2923 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2924 if (compose->toolbar->sendl_btn)
2925 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2926 if (compose->toolbar->draft_btn )
2927 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2928 if (compose->toolbar->insert_btn )
2929 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2930 if (compose->toolbar->attach_btn)
2931 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2932 if (compose->toolbar->sig_btn)
2933 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2934 if (compose->toolbar->repsig_btn)
2935 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->repsig_btn, sensitive);
2936 if (compose->toolbar->exteditor_btn)
2937 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2938 if (compose->toolbar->linewrap_current_btn)
2939 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2940 if (compose->toolbar->linewrap_all_btn)
2941 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2942 if (compose->toolbar->addrbook_btn)
2943 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2945 if (compose->toolbar->spellcheck_btn)
2946 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2948 for (; items != NULL; items = g_slist_next(items)) {
2949 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2950 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2955 * Initialize toolbar structure
2957 static void toolbar_init(Toolbar * toolbar)
2960 toolbar->toolbar = NULL;
2961 toolbar->folders_btn = NULL;
2962 toolbar->get_btn = NULL;
2963 toolbar->getall_btn = NULL;
2964 toolbar->send_btn = NULL;
2965 toolbar->compose_mail_btn = NULL;
2966 toolbar->compose_mail_icon = NULL;
2967 toolbar->compose_news_icon = NULL;
2968 toolbar->reply_btn = NULL;
2969 toolbar->replysender_btn = NULL;
2970 toolbar->replyall_btn = NULL;
2971 toolbar->replylist_btn = NULL;
2972 toolbar->fwd_btn = NULL;
2973 toolbar->trash_btn = NULL;
2974 toolbar->delete_btn = NULL;
2975 toolbar->delete_dup_btn = NULL;
2976 toolbar->prev_btn = NULL;
2977 toolbar->next_btn = NULL;
2978 toolbar->exec_btn = NULL;
2979 toolbar->separator = NULL;
2980 toolbar->learn_spam_btn = NULL;
2981 toolbar->learn_spam_icon = NULL;
2982 toolbar->learn_ham_icon = NULL;
2983 toolbar->cancel_inc_btn = NULL;
2984 toolbar->cancel_send_btn = NULL;
2985 toolbar->cancel_all_btn = NULL;
2987 /* compose buttons */
2988 toolbar->sendl_btn = NULL;
2989 toolbar->draft_btn = NULL;
2990 toolbar->insert_btn = NULL;
2991 toolbar->attach_btn = NULL;
2992 toolbar->sig_btn = NULL;
2993 toolbar->repsig_btn = NULL;
2994 toolbar->exteditor_btn = NULL;
2995 toolbar->linewrap_current_btn = NULL;
2996 toolbar->linewrap_all_btn = NULL;
2997 toolbar->addrbook_btn = NULL;
2999 toolbar->open_mail_btn = NULL;
3000 toolbar->close_window_btn = NULL;
3001 toolbar->preferences_btn = NULL;
3002 toolbar->action_list = NULL;
3003 toolbar->item_list = NULL;
3005 toolbar->spellcheck_btn = NULL;
3008 toolbar->privacy_sign_btn = NULL;
3009 toolbar->privacy_encrypt_btn = NULL;
3011 toolbar_destroy(toolbar);
3016 static void toolbar_reply(gpointer data, guint action)
3018 ToolbarItem *toolbar_item = (ToolbarItem*)data;
3019 MainWindow *mainwin;
3020 MessageView *msgview;
3021 GSList *msginfo_list = NULL;
3022 gboolean msg_is_selected = FALSE;
3023 gboolean msg_is_opened = FALSE;
3025 cm_return_if_fail(toolbar_item != NULL);
3027 switch (toolbar_item->type) {
3029 mainwin = (MainWindow*)toolbar_item->parent;
3030 msginfo_list = summary_get_selection(mainwin->summaryview);
3031 msgview = (MessageView*)mainwin->messageview;
3032 msg_is_opened = summary_has_opened_message(mainwin->summaryview);
3033 msg_is_selected = summary_is_opened_message_selected(mainwin->summaryview);
3035 case TOOLBAR_MSGVIEW:
3036 msgview = (MessageView*)toolbar_item->parent;
3037 cm_return_if_fail(msgview != NULL);
3038 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
3039 msg_is_opened = TRUE;
3040 msg_is_selected = TRUE;
3046 cm_return_if_fail(msgview != NULL);
3047 cm_return_if_fail(msginfo_list != NULL);
3048 if (!msg_is_opened) {
3049 compose_reply_from_messageview(NULL, msginfo_list, action);
3050 } else if (msg_is_selected) {
3051 compose_reply_from_messageview(msgview, msginfo_list, action);
3053 compose_reply_from_messageview(msgview, NULL, action);
3055 g_slist_free(msginfo_list);
3057 /* TODO: update reply state ion summaryview */
3061 /* exported functions */
3063 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
3065 MainWindow *mainwin = (MainWindow*)data;
3067 inc_mail(mainwin, prefs_common.newmail_notify_manu);
3070 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
3072 MainWindow *mainwin = (MainWindow*)data;
3074 inc_all_account_mail(mainwin, FALSE, FALSE, prefs_common.newmail_notify_manu);
3077 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
3081 gboolean got_error = FALSE;
3082 gchar *errstr = NULL;
3084 if (prefs_common.work_offline)
3085 if (alertpanel(_("Offline warning"),
3086 _("You're working offline. Override?"),
3087 NULL, _("_No"), NULL, _("_Yes"),
3088 NULL, NULL, ALERTFOCUS_FIRST) != G_ALERTALTERNATE)
3091 /* ask for confirmation before sending queued messages only
3092 in online mode and if there is at least one message queued
3093 in any of the folder queue
3095 if (prefs_common.confirm_send_queued_messages) {
3097 /* check if there's a queued message */
3098 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
3099 Folder *folder = list->data;
3101 found = !procmsg_queue_is_empty(folder->queue);
3103 /* if necessary, ask for confirmation before sending */
3104 if (found && !prefs_common.work_offline) {
3105 if (alertpanel(_("Send queued messages"),
3106 _("Send all queued messages?"),
3107 NULL, _("_Cancel"), NULL, _("_Send"),
3108 NULL, NULL, ALERTFOCUS_FIRST) != G_ALERTALTERNATE)
3113 for (list = folder_get_list(); list != NULL; list = list->next) {
3114 Folder *folder = list->data;
3116 if (folder->queue) {
3117 if (procmsg_send_queue(folder->queue,
3118 prefs_common.savemsg,
3125 alertpanel_error_log(_("Some errors occurred while "
3126 "sending queued messages."));
3128 alertpanel_error_log(_("Some errors occurred "
3129 "while sending queued messages:\n%s"), errstr);
3135 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
3137 MainWindow *mainwin = (MainWindow*)data;
3138 PrefsAccount *ac = NULL;
3139 FolderItem *item = mainwin->summaryview->folder_item;
3144 ac = account_find_from_item(item);
3145 if (ac && ac->protocol != A_NNTP && ac->protocol != A_IMAP4) {
3146 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
3152 * CLAWS - use current account
3154 if (cur_account && (cur_account->protocol != A_NNTP)) {
3155 compose_new_with_folderitem(cur_account, item, NULL);
3160 * CLAWS - just get the first one
3162 list = account_get_list();
3163 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
3164 ac = (PrefsAccount *) cur->data;
3165 if (ac->protocol != A_NNTP) {
3166 compose_new_with_folderitem(ac, item, NULL);
3172 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
3174 MainWindow *mainwin = (MainWindow*)data;
3175 PrefsAccount * ac = NULL;
3179 if (mainwin->summaryview->folder_item) {
3180 ac = mainwin->summaryview->folder_item->folder->account;
3181 if (ac && ac->protocol == A_NNTP) {
3182 compose_new_with_folderitem(ac,
3183 mainwin->summaryview->folder_item, NULL);
3188 list = account_get_list();
3189 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
3190 ac = (PrefsAccount *) cur->data;
3191 if (ac->protocol == A_NNTP) {
3192 compose_new_with_folderitem(ac,
3193 mainwin->summaryview->folder_item, NULL);