2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2012 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * General functions for accessing address book files.
26 #include "claws-features.h"
32 #include <glib/gi18n.h>
41 #include "mainwindow.h"
42 #include "summaryview.h"
47 #include "prefs_gtk.h"
49 #include "stock_pixmap.h"
50 #include "manage_window.h"
56 #include "prefs_actions.h"
57 #include "prefs_common.h"
58 #include "prefs_toolbar.h"
59 #include "alertpanel.h"
62 #ifndef USE_NEW_ADDRBOOK
63 #include "addressbook.h"
65 #include "addressbook-dbus.h"
69 #define TOOLBAR_TAG_INDEX "toolbar"
70 #define TOOLBAR_TAG_ITEM "item"
71 #define TOOLBAR_TAG_SEPARATOR "separator"
73 #define TOOLBAR_ICON_FILE "file"
74 #define TOOLBAR_ICON_TEXT "text"
75 #define TOOLBAR_ICON_ACTION "action"
77 static void toolbar_init(Toolbar * toolbar);
78 static gboolean toolbar_is_duplicate (gint action,
80 static void toolbar_parse_item (XMLFile *file,
83 static gint toolbar_ret_val_from_text (const gchar *text);
84 static gchar *toolbar_ret_text_from_val (gint val);
86 static void toolbar_set_default_main (void);
87 static void toolbar_set_default_compose (void);
88 static void toolbar_set_default_msgview (void);
90 static void toolbar_style (ToolbarType type,
94 static MainWindow *get_mainwin (gpointer data);
95 static void activate_compose_button (Toolbar *toolbar,
97 ComposeButtonType type);
99 /* toolbar callbacks */
100 static void toolbar_reply (gpointer data,
102 static void toolbar_learn (gpointer data,
104 static void toolbar_delete_cb (GtkWidget *widget,
106 static void toolbar_trash_cb (GtkWidget *widget,
109 static void toolbar_compose_cb (GtkWidget *widget,
112 static void toolbar_learn_cb (GtkWidget *widget,
115 static void toolbar_reply_cb (GtkWidget *widget,
118 static void toolbar_reply_to_all_cb (GtkWidget *widget,
121 static void toolbar_reply_to_list_cb (GtkWidget *widget,
124 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
127 static void toolbar_forward_cb (GtkWidget *widget,
130 static void toolbar_prev_unread_cb (GtkWidget *widget,
132 static void toolbar_next_unread_cb (GtkWidget *widget,
135 static void toolbar_ignore_thread_cb (GtkWidget *widget,
138 static void toolbar_watch_thread_cb (GtkWidget *widget,
141 static void toolbar_print_cb (GtkWidget *widget,
144 static void toolbar_actions_execute_cb (GtkWidget *widget,
146 static void toolbar_plugins_execute_cb (GtkWidget *widget,
150 static void toolbar_send_cb (GtkWidget *widget,
152 static void toolbar_send_later_cb (GtkWidget *widget,
154 static void toolbar_draft_cb (GtkWidget *widget,
156 static void toolbar_close_cb (GtkWidget *widget,
158 static void toolbar_preferences_cb (GtkWidget *widget,
160 static void toolbar_open_mail_cb (GtkWidget *widget,
162 static void toolbar_insert_cb (GtkWidget *widget,
164 static void toolbar_attach_cb (GtkWidget *widget,
166 static void toolbar_sig_cb (GtkWidget *widget,
168 static void toolbar_ext_editor_cb (GtkWidget *widget,
170 static void toolbar_linewrap_current_cb (GtkWidget *widget,
172 static void toolbar_linewrap_all_cb (GtkWidget *widget,
174 static void toolbar_addrbook_cb (GtkWidget *widget,
177 static void toolbar_check_spelling_cb (GtkWidget *widget,
180 static void toolbar_cancel_inc_cb (GtkWidget *widget,
186 } toolbar_text [] = {
187 { "A_RECEIVE_ALL", N_("Receive Mail from all Accounts") },
188 { "A_RECEIVE_CUR", N_("Receive Mail from current Account") },
189 { "A_SEND_QUEUED", N_("Send Queued Messages") },
190 { "A_COMPOSE_EMAIL", N_("Compose Email") },
191 { "A_COMPOSE_NEWS", N_("Compose News") },
192 { "A_REPLY_MESSAGE", N_("Reply to Message") },
193 { "A_REPLY_SENDER", N_("Reply to Sender") },
194 { "A_REPLY_ALL", N_("Reply to All") },
195 { "A_REPLY_ML", N_("Reply to Mailing-list") },
196 { "A_OPEN_MAIL", N_("Open email") },
197 { "A_FORWARD", N_("Forward Message") },
198 { "A_TRASH", N_("Trash Message") },
199 { "A_DELETE_REAL", N_("Delete Message") },
200 { "A_EXECUTE", N_("Execute") },
201 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
202 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
203 { "A_IGNORE_THREAD", N_("Ignore thread") },
204 { "A_WATCH_THREAD", N_("Watch thread") },
205 { "A_PRINT", N_("Print") },
206 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
207 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
208 { "A_PREFERENCES", N_("Preferences") },
210 { "A_SEND", N_("Send Message") },
211 { "A_SENDL", N_("Put into queue folder and send later") },
212 { "A_DRAFT", N_("Save to draft folder") },
213 { "A_INSERT", N_("Insert file") },
214 { "A_ATTACH", N_("Attach file") },
215 { "A_SIG", N_("Insert signature") },
216 { "A_EXTEDITOR", N_("Edit with external editor") },
217 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
218 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
219 { "A_ADDRBOOK", N_("Address book") },
221 { "A_CHECK_SPELLING", N_("Check spelling") },
223 { "A_CLAWS_ACTIONS", N_("Claws Mail Actions Feature") },
224 { "A_CANCEL_INC", N_("Cancel receiving") },
225 { "A_CLOSE", N_("Close window") },
226 { "A_SEPARATOR", N_("Separator") },
227 { "A_CLAWS_PLUGINS", N_("Claws Mail Plugins") },
230 /* struct holds configuration files and a list of
231 * currently active toolbar items
232 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
236 const gchar *conf_file;
238 } toolbar_config[3] = {
239 { "toolbar_main.xml", NULL},
240 { "toolbar_compose.xml", NULL},
241 { "toolbar_msgview.xml", NULL}
244 gint toolbar_ret_val_from_descr(const gchar *descr)
248 for (i = 0; i < N_ACTION_VAL; i++) {
249 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
256 gchar *toolbar_ret_descr_from_val(gint val)
258 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
260 return gettext(toolbar_text[val].descr);
263 static gint toolbar_ret_val_from_text(const gchar *text)
267 for (i = 0; i < N_ACTION_VAL; i++) {
268 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
275 static gchar *toolbar_ret_text_from_val(gint val)
277 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
279 return toolbar_text[val].index_str;
282 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
286 if ((action == A_SEPARATOR) || (action == A_CLAWS_ACTIONS) || (action == A_CLAWS_PLUGINS))
289 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
290 ToolbarItem *item = (ToolbarItem*) cur->data;
292 if (item->index == action)
298 /* depending on toolbar type this function
299 returns a list of available toolbar events being
300 displayed by prefs_toolbar
302 GList *toolbar_get_action_items(ToolbarType source)
307 if (source == TOOLBAR_MAIN) {
308 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
309 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
310 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
311 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
312 A_GOTO_NEXT, A_IGNORE_THREAD, A_WATCH_THREAD, A_PRINT,
313 A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
314 A_CANCEL_INC, A_PREFERENCES };
316 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
317 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
320 else if (source == TOOLBAR_COMPOSE) {
321 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
322 A_INSERT, A_ATTACH, A_SIG,
323 A_EXTEDITOR, A_LINEWRAP_CURRENT,
324 A_LINEWRAP_ALL, A_ADDRBOOK,
330 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
331 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
333 else if (source == TOOLBAR_MSGVIEW) {
334 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
335 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
336 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
337 A_ADDRBOOK, A_LEARN_SPAM, A_CLOSE };
339 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
340 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
346 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
350 ToolbarItem *item = NULL;
351 gboolean rewrite = FALSE;
353 attr = xml_get_current_tag_attr(file);
354 item = g_new0(ToolbarItem, 1);
356 name = ((XMLAttr *)attr->data)->name;
357 value = ((XMLAttr *)attr->data)->value;
359 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
360 item->file = g_strdup (value);
361 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
362 item->text = g_strdup (*value ? gettext(value):"");
363 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
364 item->index = toolbar_ret_val_from_text(value);
365 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
367 item->index = A_TRASH;
369 item->file = g_strdup("trash_btn");
371 item->text = g_strdup(Q_("Toolbar|Trash"));
374 if (item->index == -1 && !strcmp(value, "A_SYL_ACTIONS")) {
376 item->index = A_CLAWS_ACTIONS;
379 attr = g_list_next(attr);
381 if (item->index != -1) {
383 if (!toolbar_is_duplicate(item->index, source))
384 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
388 toolbar_save_config_file(source);
392 const gchar *toolbar_get_short_text(int action) {
394 case A_GO_FOLDERS: return _("Folders");
395 case A_OPEN_MAIL: return _("Open");
396 case A_RECEIVE_ALL: return _("Get Mail");
397 case A_RECEIVE_CUR: return _("Get");
398 case A_SEND_QUEUED: return _("Send");
399 case A_COMPOSE_EMAIL: return Q_("Toolbar|Compose");
400 case A_COMPOSE_NEWS: return Q_("Toolbar|Compose");
401 case A_REPLY_MESSAGE: return _("Reply");
402 case A_REPLY_ALL: return _("All");
403 case A_REPLY_SENDER: return Q_("Toolbar|Sender");
404 case A_REPLY_ML: return _("List");
405 case A_FORWARD: return _("Forward");
406 case A_TRASH: return Q_("Toolbar|Trash");
407 case A_DELETE_REAL: return _("Delete");
408 case A_LEARN_SPAM: return _("Spam");
409 case A_GOTO_PREV: return _("Prev");
410 case A_GOTO_NEXT: return _("Next");
411 case A_IGNORE_THREAD: return _("Ignore thread");
412 case A_WATCH_THREAD: return _("Watch thread");
413 case A_PRINT: return _("Print");
414 case A_CLOSE: return _("Close");
415 case A_PREFERENCES: return _("Preferences");
416 case A_SEND: return _("Send");
417 case A_SENDL: return _("Send later");
418 case A_DRAFT: return _("Draft");
419 case A_INSERT: return _("Insert");
420 case A_ATTACH: return _("Attach");
421 case A_SIG: return _("Insert sig.");
422 case A_EXTEDITOR: return _("Edit");
423 case A_LINEWRAP_CURRENT:return _("Wrap para.");
424 case A_LINEWRAP_ALL: return _("Wrap all");
425 case A_ADDRBOOK: return _("Address");
426 case A_CANCEL_INC: return _("Stop");
427 case A_EXECUTE: return _("Execute");
429 case A_CHECK_SPELLING: return _("Check spelling");
435 gint toolbar_get_icon(int action) {
437 case A_GO_FOLDERS: return STOCK_PIXMAP_GO_FOLDERS;
438 case A_OPEN_MAIL: return STOCK_PIXMAP_OPEN_MAIL;
439 case A_RECEIVE_ALL: return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
440 case A_RECEIVE_CUR: return STOCK_PIXMAP_MAIL_RECEIVE;
441 case A_SEND_QUEUED: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
442 case A_COMPOSE_EMAIL: return STOCK_PIXMAP_MAIL_COMPOSE;
443 case A_COMPOSE_NEWS: return STOCK_PIXMAP_NEWS_COMPOSE;
444 case A_REPLY_MESSAGE: return STOCK_PIXMAP_MAIL_REPLY;
445 case A_REPLY_ALL: return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
446 case A_REPLY_SENDER: return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
447 case A_REPLY_ML: return STOCK_PIXMAP_MAIL_REPLY_TO_LIST;
448 case A_FORWARD: return STOCK_PIXMAP_MAIL_FORWARD;
449 case A_TRASH: return STOCK_PIXMAP_TRASH;
450 case A_DELETE_REAL: return STOCK_PIXMAP_DELETE;
451 case A_LEARN_SPAM: return STOCK_PIXMAP_SPAM_BTN;
452 case A_GOTO_PREV: return STOCK_PIXMAP_UP_ARROW;
453 case A_GOTO_NEXT: return STOCK_PIXMAP_DOWN_ARROW;
454 case A_IGNORE_THREAD: return STOCK_PIXMAP_IGNORETHREAD;
455 case A_WATCH_THREAD: return STOCK_PIXMAP_WATCHTHREAD;
456 case A_PRINT: return STOCK_PIXMAP_PRINTER;
457 case A_CLOSE: return STOCK_PIXMAP_CLOSE;
458 case A_PREFERENCES: return STOCK_PIXMAP_PREFERENCES;
459 case A_SEND: return STOCK_PIXMAP_MAIL_SEND;
460 case A_SENDL: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
461 case A_DRAFT: return STOCK_PIXMAP_MAIL;
462 case A_INSERT: return STOCK_PIXMAP_INSERT_FILE;
463 case A_ATTACH: return STOCK_PIXMAP_MAIL_ATTACH;
464 case A_SIG: return STOCK_PIXMAP_MAIL_SIGN;
465 case A_EXTEDITOR: return STOCK_PIXMAP_EDIT_EXTERN;
466 case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
467 case A_LINEWRAP_ALL: return STOCK_PIXMAP_LINEWRAP_ALL;
468 case A_ADDRBOOK: return STOCK_PIXMAP_ADDRESS_BOOK;
469 case A_CANCEL_INC: return STOCK_PIXMAP_CANCEL;
470 case A_EXECUTE: return STOCK_PIXMAP_EXEC;
472 case A_CHECK_SPELLING: return STOCK_PIXMAP_CHECK_SPELLING;
478 static void toolbar_set_default_main(void)
482 } default_toolbar[] = {
510 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
512 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
514 if (default_toolbar[i].action != A_SEPARATOR) {
517 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
518 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
521 toolbar_item->file = g_strdup(file);
522 toolbar_item->index = default_toolbar[i].action;
523 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
526 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
527 toolbar_item->index = A_SEPARATOR;
530 if (toolbar_item->index != -1) {
531 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
532 toolbar_config[TOOLBAR_MAIN].item_list =
533 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
538 static void toolbar_set_default_compose(void)
542 } default_toolbar[] = {
561 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
563 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
565 if (default_toolbar[i].action != A_SEPARATOR) {
568 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
569 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
571 toolbar_item->file = g_strdup(file);
572 toolbar_item->index = default_toolbar[i].action;
573 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
576 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
577 toolbar_item->index = A_SEPARATOR;
580 if (toolbar_item->index != -1) {
581 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
582 toolbar_config[TOOLBAR_COMPOSE].item_list =
583 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
588 static void toolbar_set_default_msgview(void)
592 } default_toolbar[] = {
611 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
613 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
615 if (default_toolbar[i].action != A_SEPARATOR) {
617 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
618 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
621 toolbar_item->file = g_strdup(file);
622 toolbar_item->index = default_toolbar[i].action;
623 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
626 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
627 toolbar_item->index = A_SEPARATOR;
630 if (toolbar_item->index != -1) {
631 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
632 toolbar_config[TOOLBAR_MSGVIEW].item_list =
633 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
638 void toolbar_set_default(ToolbarType source)
640 if (source == TOOLBAR_MAIN)
641 toolbar_set_default_main();
642 else if (source == TOOLBAR_COMPOSE)
643 toolbar_set_default_compose();
644 else if (source == TOOLBAR_MSGVIEW)
645 toolbar_set_default_msgview();
648 void toolbar_save_config_file(ToolbarType source)
653 gchar *fileSpec = NULL;
655 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
657 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
658 pfile = prefs_write_open(fileSpec);
661 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
664 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
667 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
668 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
670 if (toolbar_item->index != A_SEPARATOR) {
671 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
673 TOOLBAR_ICON_FILE, toolbar_item->file,
674 TOOLBAR_ICON_TEXT) < 0)
676 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
678 if (fprintf(fp, "\" %s=\"%s\"/>\n",
680 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
683 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
688 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
692 if (prefs_file_close (pfile) < 0 )
693 g_warning("failed to write toolbar configuration to file\n");
697 FILE_OP_ERROR(fileSpec, "fprintf");
699 prefs_file_close_revert (pfile);
701 g_warning("failed to open toolbar configuration file for writing\n");
704 void toolbar_read_config_file(ToolbarType source)
706 XMLFile *file = NULL;
707 gchar *fileSpec = NULL;
712 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
714 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
715 file = xml_open_file(fileSpec);
718 toolbar_clear_list(source);
722 || (xml_get_dtd(file))
723 || (xml_parse_next_tag(file))
724 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
725 xml_close_file(file);
729 attr = xml_get_current_tag_attr(file);
736 if (xml_parse_next_tag(file))
739 /* Get next tag (icon, icon_text or icon_action) */
740 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
741 toolbar_parse_item(file, source);
742 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
743 ToolbarItem *item = g_new0(ToolbarItem, 1);
745 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
746 item->index = A_SEPARATOR;
747 toolbar_config[source].item_list =
748 g_slist_append(toolbar_config[source].item_list, item);
752 xml_close_file(file);
755 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
757 if (source == TOOLBAR_MAIN)
758 toolbar_set_default(TOOLBAR_MAIN);
759 else if (source == TOOLBAR_COMPOSE)
760 toolbar_set_default(TOOLBAR_COMPOSE);
761 else if (source == TOOLBAR_MSGVIEW)
762 toolbar_set_default(TOOLBAR_MSGVIEW);
764 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
768 toolbar_save_config_file(source);
773 * clears list of toolbar items read from configuration files
775 void toolbar_clear_list(ToolbarType source)
777 while (toolbar_config[source].item_list != NULL) {
778 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
780 toolbar_config[source].item_list =
781 g_slist_remove(toolbar_config[source].item_list, item);
787 g_slist_free(toolbar_config[source].item_list);
792 * return list of Toolbar items
794 GSList *toolbar_get_list(ToolbarType source)
798 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
799 list = toolbar_config[source].item_list;
804 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
806 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
808 toolbar_item->file = g_strdup(t_item->file);
809 toolbar_item->text = g_strdup(t_item->text);
810 toolbar_item->index = t_item->index;
812 toolbar_config[source].item_list =
813 g_slist_append(toolbar_config[source].item_list,
817 static void toolbar_action_execute(GtkWidget *widget,
825 for (cur = action_list; cur != NULL; cur = cur->next) {
826 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
828 if (widget == act->widget) {
829 i = prefs_actions_find_by_name(act->name);
837 actions_execute(data, i, widget, source);
839 g_warning ("Error: did not find Claws Action to execute");
842 gboolean toolbar_check_action_btns(ToolbarType type)
844 GSList *temp, *curr, *list = toolbar_config[type].item_list;
845 gboolean modified = FALSE;
848 while (curr != NULL) {
849 ToolbarItem *toolbar_item = (ToolbarItem *) curr->data;
853 if (toolbar_item->index != A_CLAWS_ACTIONS)
856 if (prefs_actions_find_by_name(toolbar_item->text) == -1) {
857 list = g_slist_delete_link(list, temp);
858 g_free(toolbar_item->file);
859 g_free(toolbar_item->text);
860 g_free(toolbar_item);
868 #if !(GTK_CHECK_VERSION(2,12,0))
869 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
870 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(widget), GTK_TOOLTIPS(toolbar_tips), \
874 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
875 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), tip); \
879 #if !(GTK_CHECK_VERSION(2,12,0))
880 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
881 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(widget), GTK_TOOLTIPS(toolbar_tips), \
885 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
886 gtk_menu_tool_button_set_arrow_tooltip_text(GTK_MENU_TOOL_BUTTON(widget), tip); \
890 static void activate_compose_button (Toolbar *toolbar,
892 ComposeButtonType type)
894 #if !(GTK_CHECK_VERSION(2,12,0))
895 GtkTooltips *toolbar_tips = toolbar->tooltips;
897 if ((!toolbar->compose_mail_btn))
900 if (type == COMPOSEBUTTON_NEWS) {
901 gtk_tool_button_set_icon_widget(
902 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
903 toolbar->compose_news_icon);
905 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose News message"));
907 gtk_widget_show(toolbar->compose_news_icon);
909 gtk_tool_button_set_icon_widget(
910 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
911 toolbar->compose_mail_icon);
913 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose Email"));
915 gtk_widget_show(toolbar->compose_mail_icon);
917 toolbar->compose_btn_type = type;
920 void toolbar_set_compose_button(Toolbar *toolbar,
921 ComposeButtonType compose_btn_type)
923 if (toolbar->compose_btn_type != compose_btn_type)
924 activate_compose_button(toolbar,
925 prefs_common.toolbar_style,
929 static void activate_learn_button (Toolbar *toolbar,
931 LearnButtonType type)
933 #if !(GTK_CHECK_VERSION(2,12,0))
934 GtkTooltips *toolbar_tips = toolbar->tooltips;
936 if ((!toolbar->learn_spam_btn))
939 if (type == LEARN_SPAM) {
940 gtk_tool_button_set_icon_widget(
941 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
942 toolbar->learn_spam_icon);
943 gtk_tool_button_set_label(
944 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
947 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn spam"));
949 gtk_widget_show(toolbar->learn_spam_icon);
951 gtk_tool_button_set_icon_widget(
952 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
953 toolbar->learn_ham_icon);
954 gtk_tool_button_set_label(
955 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
958 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn ham"));
960 gtk_widget_show(toolbar->learn_ham_icon);
962 toolbar->learn_btn_type = type;
965 void toolbar_set_learn_button(Toolbar *toolbar,
966 LearnButtonType learn_btn_type)
968 if (toolbar->learn_btn_type != learn_btn_type)
969 activate_learn_button(toolbar,
970 prefs_common.toolbar_style,
974 void toolbar_toggle(guint action, gpointer data)
976 MainWindow *mainwin = (MainWindow*)data;
980 cm_return_if_fail(mainwin != NULL);
982 toolbar_style(TOOLBAR_MAIN, action, mainwin);
984 list = compose_get_compose_list();
985 for (cur = list; cur != NULL; cur = cur->next) {
986 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
988 list = messageview_get_msgview_list();
989 for (cur = list; cur != NULL; cur = cur->next) {
990 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
995 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
997 switch ((ToolbarStyle)action) {
999 gtk_widget_hide(handlebox_wid);
1002 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1006 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1010 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1013 case TOOLBAR_BOTH_HORIZ:
1014 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1015 GTK_TOOLBAR_BOTH_HORIZ);
1021 prefs_common.toolbar_style = (ToolbarStyle)action;
1022 gtk_widget_set_size_request(handlebox_wid, 1, -1);
1024 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1025 gtk_widget_show(handlebox_wid);
1026 gtk_widget_queue_resize(handlebox_wid);
1030 * Change the style of toolbar
1032 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1034 GtkWidget *handlebox_wid;
1035 GtkWidget *toolbar_wid;
1036 MainWindow *mainwin = (MainWindow*)data;
1037 Compose *compose = (Compose*)data;
1038 MessageView *msgview = (MessageView*)data;
1040 cm_return_if_fail(data != NULL);
1044 handlebox_wid = mainwin->handlebox;
1045 toolbar_wid = mainwin->toolbar->toolbar;
1047 case TOOLBAR_COMPOSE:
1048 handlebox_wid = compose->handlebox;
1049 toolbar_wid = compose->toolbar->toolbar;
1051 case TOOLBAR_MSGVIEW:
1052 handlebox_wid = msgview->handlebox;
1053 toolbar_wid = msgview->toolbar->toolbar;
1059 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1062 /* Toolbar handling */
1063 static void toolbar_inc_cb(GtkWidget *widget,
1066 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1067 MainWindow *mainwin;
1069 cm_return_if_fail(toolbar_item != NULL);
1071 switch (toolbar_item->type) {
1073 mainwin = (MainWindow*)toolbar_item->parent;
1074 inc_mail_cb(mainwin, 0, NULL);
1081 static void toolbar_inc_all_cb(GtkWidget *widget,
1084 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1085 MainWindow *mainwin;
1087 cm_return_if_fail(toolbar_item != NULL);
1089 switch (toolbar_item->type) {
1091 mainwin = (MainWindow*)toolbar_item->parent;
1092 inc_all_account_mail_cb(mainwin, 0, NULL);
1099 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1101 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1102 MainWindow *mainwin;
1104 cm_return_if_fail(toolbar_item != NULL);
1106 switch (toolbar_item->type) {
1108 mainwin = (MainWindow*)toolbar_item->parent;
1109 send_queue_cb(mainwin, 0, NULL);
1116 static void toolbar_exec_cb(GtkWidget *widget,
1119 MainWindow *mainwin = get_mainwin(data);
1121 cm_return_if_fail(mainwin != NULL);
1122 summary_execute(mainwin->summaryview);
1126 * Delete current/selected(s) message(s)
1128 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1130 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1131 MainWindow *mainwin;
1133 cm_return_if_fail(toolbar_item != NULL);
1134 cm_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_trash(mainwin->summaryview);
1145 debug_print("toolbar event not supported\n");
1151 * Delete current/selected(s) message(s)
1153 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1155 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1156 MainWindow *mainwin;
1158 cm_return_if_fail(toolbar_item != NULL);
1159 cm_return_if_fail(toolbar_item->parent);
1161 switch (toolbar_item->type) {
1162 case TOOLBAR_MSGVIEW:
1163 messageview_delete((MessageView *)toolbar_item->parent);
1166 mainwin = (MainWindow *)toolbar_item->parent;
1167 summary_delete(mainwin->summaryview);
1170 debug_print("toolbar event not supported\n");
1177 * Compose new message
1179 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1181 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1182 MainWindow *mainwin;
1183 MessageView *msgview;
1185 cm_return_if_fail(toolbar_item != NULL);
1187 switch (toolbar_item->type) {
1189 mainwin = (MainWindow*)toolbar_item->parent;
1190 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1191 compose_news_cb(mainwin, 0, NULL);
1193 compose_mail_cb(mainwin, 0, NULL);
1195 case TOOLBAR_MSGVIEW:
1196 msgview = (MessageView*)toolbar_item->parent;
1197 compose_new_with_folderitem(NULL,
1198 msgview->msginfo->folder, NULL);
1201 debug_print("toolbar event not supported\n");
1205 static void toolbar_learn(gpointer data, guint as_spam)
1207 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1208 MainWindow *mainwin;
1209 MessageView *msgview;
1211 cm_return_if_fail(toolbar_item != NULL);
1213 switch (toolbar_item->type) {
1215 mainwin = (MainWindow*)toolbar_item->parent;
1217 mainwindow_learn(mainwin, TRUE);
1219 mainwindow_learn(mainwin, FALSE);
1221 case TOOLBAR_MSGVIEW:
1222 msgview = (MessageView*)toolbar_item->parent;
1224 messageview_learn(msgview, TRUE);
1226 messageview_learn(msgview, FALSE);
1229 debug_print("toolbar event not supported\n");
1233 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1235 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1236 MainWindow *mainwin;
1237 MessageView *msgview;
1239 cm_return_if_fail(toolbar_item != NULL);
1241 switch (toolbar_item->type) {
1243 mainwin = (MainWindow*)toolbar_item->parent;
1244 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1245 mainwindow_learn(mainwin, TRUE);
1247 mainwindow_learn(mainwin, FALSE);
1249 case TOOLBAR_MSGVIEW:
1250 msgview = (MessageView*)toolbar_item->parent;
1251 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1252 messageview_learn(msgview, TRUE);
1254 messageview_learn(msgview, FALSE);
1257 debug_print("toolbar event not supported\n");
1265 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1267 toolbar_reply(data, (prefs_common.reply_with_quote ?
1268 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE));
1273 * Reply message to Sender and All recipients
1275 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1278 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1279 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE));
1284 * Reply to Mailing List
1286 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1289 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1290 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE));
1295 * Reply to sender of message
1297 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1300 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1301 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE));
1307 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1309 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1312 cm_return_if_fail(toolbar_item != NULL);
1314 switch (toolbar_item->type) {
1316 case TOOLBAR_MSGVIEW:
1319 case TOOLBAR_COMPOSE:
1320 compose = (Compose *)toolbar_item->parent;
1325 #ifndef USE_NEW_ADDRBOOK
1326 addressbook_open(compose);
1328 GError* error = NULL;
1329 addressbook_connect_signals(compose);
1330 addressbook_dbus_open(TRUE, &error);
1332 g_warning("%s", error->message);
1333 g_error_free(error);
1340 * Forward current/selected(s) message(s)
1342 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1344 toolbar_reply(data, (COMPOSE_FORWARD));
1348 * Goto Prev Unread Message
1350 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1352 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1353 MainWindow *mainwin;
1354 MessageView *msgview;
1356 cm_return_if_fail(toolbar_item != NULL);
1358 switch (toolbar_item->type) {
1360 mainwin = (MainWindow*)toolbar_item->parent;
1361 summary_select_prev_unread(mainwin->summaryview);
1364 case TOOLBAR_MSGVIEW:
1365 msgview = (MessageView*)toolbar_item->parent;
1366 msgview->updating = TRUE;
1367 summary_select_prev_unread(msgview->mainwin->summaryview);
1368 msgview->updating = FALSE;
1370 if (msgview->deferred_destroy) {
1371 debug_print("messageview got away!\n");
1372 messageview_destroy(msgview);
1376 /* Now we need to update the messageview window */
1377 if (msgview->mainwin->summaryview->selected) {
1378 #ifndef GENERIC_UMPC
1379 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1382 messageview_show(msgview, msginfo,
1383 msgview->all_headers);
1386 gtk_widget_destroy(msgview->window);
1390 debug_print("toolbar event not supported\n");
1395 * Goto Next Unread Message
1397 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1399 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1400 MainWindow *mainwin;
1401 MessageView *msgview;
1403 cm_return_if_fail(toolbar_item != NULL);
1405 switch (toolbar_item->type) {
1407 mainwin = (MainWindow*)toolbar_item->parent;
1408 summary_select_next_unread(mainwin->summaryview);
1411 case TOOLBAR_MSGVIEW:
1412 msgview = (MessageView*)toolbar_item->parent;
1413 msgview->updating = TRUE;
1414 summary_select_next_unread(msgview->mainwin->summaryview);
1415 msgview->updating = FALSE;
1417 if (msgview->deferred_destroy) {
1418 debug_print("messageview got away!\n");
1419 messageview_destroy(msgview);
1423 /* Now we need to update the messageview window */
1424 if (msgview->mainwin->summaryview->selected) {
1425 #ifndef GENERIC_UMPC
1426 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1429 messageview_show(msgview, msginfo,
1430 msgview->all_headers);
1433 gtk_widget_destroy(msgview->window);
1437 debug_print("toolbar event not supported\n");
1441 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1443 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1444 MainWindow *mainwin;
1446 cm_return_if_fail(toolbar_item != NULL);
1448 switch (toolbar_item->type) {
1450 mainwin = (MainWindow *) toolbar_item->parent;
1451 summary_toggle_ignore_thread(mainwin->summaryview);
1453 case TOOLBAR_MSGVIEW:
1454 /* TODO: see toolbar_next_unread_cb() if you need
1455 * this in the message view */
1458 debug_print("toolbar event not supported\n");
1463 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1465 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1466 MainWindow *mainwin;
1468 cm_return_if_fail(toolbar_item != NULL);
1470 switch (toolbar_item->type) {
1472 mainwin = (MainWindow *) toolbar_item->parent;
1473 summary_toggle_watch_thread(mainwin->summaryview);
1475 case TOOLBAR_MSGVIEW:
1476 /* TODO: see toolbar_next_unread_cb() if you need
1477 * this in the message view */
1480 debug_print("toolbar event not supported\n");
1485 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1487 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1489 cm_return_if_fail(toolbar_item != NULL);
1495 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1497 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1498 MainWindow *mainwin;
1500 cm_return_if_fail(toolbar_item != NULL);
1502 switch (toolbar_item->type) {
1504 mainwin = (MainWindow *) toolbar_item->parent;
1505 summary_print(mainwin->summaryview);
1507 case TOOLBAR_MSGVIEW:
1508 /* TODO: see toolbar_next_unread_cb() if you need
1509 * this in the message view */
1512 debug_print("toolbar event not supported\n");
1517 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1519 compose_toolbar_cb(A_SEND, data);
1522 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1524 compose_toolbar_cb(A_SENDL, data);
1527 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1529 compose_toolbar_cb(A_DRAFT, data);
1532 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1534 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1535 MainWindow *mainwin;
1536 MessageView *messageview;
1539 cm_return_if_fail(toolbar_item != NULL);
1541 switch (toolbar_item->type) {
1543 mainwin = (MainWindow *) toolbar_item->parent;
1544 app_will_exit(NULL, mainwin);
1546 case TOOLBAR_MSGVIEW:
1547 messageview = (MessageView *)toolbar_item->parent;
1548 messageview_destroy(messageview);
1550 case TOOLBAR_COMPOSE:
1551 compose = (Compose *)toolbar_item->parent;
1552 compose_close_toolbar(compose);
1557 static void toolbar_preferences_cb(GtkWidget *widget, gpointer data)
1562 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1564 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1565 MainWindow *mainwin;
1567 cm_return_if_fail(toolbar_item != NULL);
1569 switch (toolbar_item->type) {
1571 mainwin = (MainWindow *) toolbar_item->parent;
1572 summary_open_row(NULL, mainwin->summaryview);
1574 case TOOLBAR_MSGVIEW:
1575 debug_print("toolbar event not supported\n");
1577 case TOOLBAR_COMPOSE:
1578 debug_print("toolbar event not supported\n");
1583 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1585 compose_toolbar_cb(A_INSERT, data);
1588 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1590 compose_toolbar_cb(A_ATTACH, data);
1593 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1595 compose_toolbar_cb(A_SIG, data);
1598 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1600 compose_toolbar_cb(A_EXTEDITOR, data);
1603 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1605 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1608 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1610 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1614 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1616 compose_toolbar_cb(A_CHECK_SPELLING, data);
1620 * Execute actions from toolbar
1622 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1624 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1625 GSList *action_list;
1626 MainWindow *mainwin;
1628 MessageView *msgview;
1629 gpointer parent = toolbar_item->parent;
1631 cm_return_if_fail(toolbar_item != NULL);
1633 switch (toolbar_item->type) {
1635 mainwin = (MainWindow*)parent;
1636 action_list = mainwin->toolbar->action_list;
1638 case TOOLBAR_COMPOSE:
1639 compose = (Compose*)parent;
1640 action_list = compose->toolbar->action_list;
1642 case TOOLBAR_MSGVIEW:
1643 msgview = (MessageView*)parent;
1644 action_list = msgview->toolbar->action_list;
1647 debug_print("toolbar event not supported\n");
1650 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1653 static void toolbar_plugins_execute_cb(GtkWidget *widget, gpointer data)
1655 ToolbarItem *toolbar_item = data;
1656 prefs_toolbar_execute_plugin_item(toolbar_item->parent, toolbar_item->type, toolbar_item->text);
1659 static MainWindow *get_mainwin(gpointer data)
1661 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1662 MainWindow *mainwin = NULL;
1663 MessageView *msgview;
1665 cm_return_val_if_fail(toolbar_item != NULL, NULL);
1667 switch(toolbar_item->type) {
1669 mainwin = (MainWindow*)toolbar_item->parent;
1671 case TOOLBAR_MSGVIEW:
1672 msgview = (MessageView*)toolbar_item->parent;
1673 mainwin = (MainWindow*)msgview->mainwin;
1682 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1684 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1685 MainWindow *mainwin = NULL;
1686 switch(toolbar_item->type) {
1688 mainwin = (MainWindow*)toolbar_item->parent;
1691 g_warning("wrong toolbar type\n");
1695 if (!mainwin->in_folder) {
1696 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1698 folderview_select(mainwin->folderview, item);
1701 gtk_widget_grab_focus(mainwin->folderview->ctree);
1702 mainwindow_exit_folder(mainwin);
1706 static void toolbar_buttons_cb(GtkWidget *widget,
1713 void (*func)(GtkWidget *widget, gpointer data);
1715 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1716 { A_RECEIVE_CUR, toolbar_inc_cb },
1717 { A_SEND_QUEUED, toolbar_send_queued_cb },
1718 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1719 { A_COMPOSE_NEWS, toolbar_compose_cb },
1720 { A_REPLY_MESSAGE, toolbar_reply_cb },
1721 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1722 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1723 { A_REPLY_ML, toolbar_reply_to_list_cb },
1724 { A_FORWARD, toolbar_forward_cb },
1725 { A_TRASH, toolbar_trash_cb },
1726 { A_DELETE_REAL, toolbar_delete_cb },
1727 { A_EXECUTE, toolbar_exec_cb },
1728 { A_GOTO_PREV, toolbar_prev_unread_cb },
1729 { A_GOTO_NEXT, toolbar_next_unread_cb },
1730 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1731 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1732 { A_PRINT, toolbar_print_cb },
1733 { A_LEARN_SPAM, toolbar_learn_cb },
1734 { A_GO_FOLDERS, toolbar_go_folders_cb },
1736 { A_SEND, toolbar_send_cb },
1737 { A_SENDL, toolbar_send_later_cb },
1738 { A_DRAFT, toolbar_draft_cb },
1739 { A_OPEN_MAIL, toolbar_open_mail_cb },
1740 { A_CLOSE, toolbar_close_cb },
1741 { A_PREFERENCES, toolbar_preferences_cb },
1742 { A_INSERT, toolbar_insert_cb },
1743 { A_ATTACH, toolbar_attach_cb },
1744 { A_SIG, toolbar_sig_cb },
1745 { A_EXTEDITOR, toolbar_ext_editor_cb },
1746 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1747 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1748 { A_ADDRBOOK, toolbar_addrbook_cb },
1750 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1752 { A_CLAWS_ACTIONS, toolbar_actions_execute_cb },
1753 { A_CANCEL_INC, toolbar_cancel_inc_cb },
1754 { A_CLAWS_PLUGINS, toolbar_plugins_execute_cb },
1757 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1759 for (i = 0; i < num_items; i++) {
1760 if (callbacks[i].index == item->index) {
1761 callbacks[i].func(widget, item);
1766 #ifndef GENERIC_UMPC
1767 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1768 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1769 gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
1770 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1771 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1772 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1773 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1774 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1778 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1779 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1780 GList *gchild = NULL; \
1781 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1782 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1783 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1784 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1785 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1786 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1788 CLAWS_SET_ARROW_TIP(GTK_MENU_TOOL_BUTTON(item), menutip); \
1789 child = gtk_bin_get_child(GTK_BIN(item)); \
1790 gchild = gtk_container_get_children( \
1791 GTK_CONTAINER(child)); \
1792 btn = (GtkWidget *)gchild->data; \
1793 gtkut_widget_set_can_focus(btn, FALSE); \
1794 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1795 gtkut_widget_set_can_focus(arr, FALSE); \
1796 g_list_free(gchild); \
1797 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1798 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1799 g_list_free(gchild); \
1802 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1803 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1804 gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
1805 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1806 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1807 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1808 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1811 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1812 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1813 GList *gchild = NULL; \
1814 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1815 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1816 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1817 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1818 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1819 child = gtk_bin_get_child(GTK_BIN(item)); \
1820 gchild = gtk_container_get_children( \
1821 GTK_CONTAINER(child)); \
1822 btn = (GtkWidget *)gchild->data; \
1823 gtkut_widget_set_can_focus(btn, FALSE); \
1824 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1825 gtkut_widget_set_can_focus(arr, FALSE); \
1826 g_list_free(gchild); \
1827 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1828 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1829 g_list_free(gchild); \
1833 #define ADD_MENU_ITEM(name,cb,data) { \
1834 item = gtk_menu_item_new_with_mnemonic(name); \
1835 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); \
1836 g_signal_connect(G_OBJECT(item), "activate", \
1839 g_object_set_data(G_OBJECT(item), "int-value", GINT_TO_POINTER(data)); \
1840 gtk_widget_show(item); \
1843 static void toolbar_reply_menu_cb(GtkWidget *widget, gpointer data)
1845 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1846 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1848 toolbar_reply(toolbar_item, GPOINTER_TO_INT(int_value));
1851 static void toolbar_learn_menu_cb(GtkWidget *widget, gpointer data)
1853 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1854 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1856 toolbar_learn(toolbar_item, GPOINTER_TO_INT(int_value));
1860 * Create a new toolbar with specified type
1861 * if a callback list is passed it will be used before the
1862 * common callback list
1864 Toolbar *toolbar_create(ToolbarType type,
1865 GtkWidget *container,
1868 ToolbarItem *toolbar_item;
1871 GtkWidget *icon_wid = NULL;
1872 GtkWidget *icon_news;
1873 GtkWidget *icon_ham;
1875 ToolbarClawsActions *action_item;
1877 GSList *toolbar_list;
1878 Toolbar *toolbar_data;
1880 #ifndef GENERIC_UMPC
1881 #if !(GTK_CHECK_VERSION(2,12,0))
1882 GtkTooltips *toolbar_tips = gtk_tooltips_new();
1885 toolbar_read_config_file(type);
1886 toolbar_list = toolbar_get_list(type);
1888 toolbar_data = g_new0(Toolbar, 1);
1890 toolbar = gtk_toolbar_new();
1892 #if (GTK_CHECK_VERSION(2,16,0))
1893 gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL);
1895 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1897 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1898 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1900 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1902 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1903 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1907 toolbar_item = g_new0(ToolbarItem, 1);
1908 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1909 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1910 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1911 toolbar_item->parent = data;
1912 toolbar_item->type = type;
1914 /* collect toolbar items in list to keep track */
1915 toolbar_data->item_list =
1916 g_slist_append(toolbar_data->item_list,
1918 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1920 switch (toolbar_item->index) {
1923 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1924 toolbar_data->folders_btn = item;
1927 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1928 _("Receive Mail from all Accounts"),
1929 _("Receive Mail from selected Account"));
1930 toolbar_data->getall_btn = item;
1933 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail from current Account"));
1934 toolbar_data->get_btn = item;
1937 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1938 toolbar_data->send_btn = item;
1941 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1942 toolbar_data->close_window_btn = item;
1945 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open preferences"));
1946 toolbar_data->preferences_btn = item;
1949 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1950 toolbar_data->open_mail_btn = item;
1952 case A_COMPOSE_EMAIL:
1953 #ifndef GENERIC_UMPC
1954 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1956 _("Compose with selected Account"));
1957 toolbar_data->compose_mail_btn = item;
1958 toolbar_data->compose_mail_icon = icon_wid;
1959 g_object_ref(toolbar_data->compose_mail_icon);
1961 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1962 toolbar_data->compose_news_icon = icon_news;
1963 g_object_ref(toolbar_data->compose_news_icon);
1965 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1966 _("Compose Email"));
1967 toolbar_data->compose_mail_btn = item;
1968 toolbar_data->compose_mail_icon = icon_wid;
1970 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1971 toolbar_data->compose_news_icon = icon_news;
1975 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1978 toolbar_data->learn_spam_btn = item;
1979 toolbar_data->learn_spam_icon = icon_wid;
1980 g_object_ref(toolbar_data->learn_spam_icon);
1982 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1983 toolbar_data->learn_ham_icon = icon_ham;
1984 g_object_ref(toolbar_data->learn_ham_icon);
1986 menu = gtk_menu_new();
1987 ADD_MENU_ITEM(_("Learn as _Spam"), toolbar_learn_menu_cb, TRUE);
1988 ADD_MENU_ITEM(_("Learn as _Ham"), toolbar_learn_menu_cb, FALSE);
1989 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->learn_spam_btn), menu);
1991 case A_REPLY_MESSAGE:
1992 #ifndef GENERIC_UMPC
1993 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1994 _("Reply to Message"),
1995 _("Reply to Message options"));
1996 toolbar_data->reply_btn = item;
1998 menu = gtk_menu_new();
1999 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITH_QUOTE);
2000 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITHOUT_QUOTE);
2001 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->reply_btn), menu);
2003 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2004 _("Reply to Message"));
2005 toolbar_data->reply_btn = item;
2008 case A_REPLY_SENDER:
2009 #ifndef GENERIC_UMPC
2010 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2011 _("Reply to Sender"),
2012 _("Reply to Sender options"));
2013 toolbar_data->replysender_btn = item;
2015 menu = gtk_menu_new();
2016 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE);
2017 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
2018 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replysender_btn), menu);
2020 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2021 _("Reply to Sender"));
2022 toolbar_data->replysender_btn = item;
2026 #ifndef GENERIC_UMPC
2027 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2029 _("Reply to All options"));
2030 toolbar_data->replyall_btn = item;
2032 menu = gtk_menu_new();
2033 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE);
2034 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
2035 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replyall_btn), menu);
2037 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2039 toolbar_data->replyall_btn = item;
2043 #ifndef GENERIC_UMPC
2044 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2045 _("Reply to Mailing-list"),
2046 _("Reply to Mailing-list options"));
2047 toolbar_data->replylist_btn = item;
2049 menu = gtk_menu_new();
2050 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE);
2051 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
2052 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replylist_btn), menu);
2054 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2055 _("Reply to Mailing-list"));
2056 toolbar_data->replylist_btn = item;
2060 #ifndef GENERIC_UMPC
2061 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2062 _("Forward Message"),
2063 _("Forward Message options"));
2064 toolbar_data->fwd_btn = item;
2066 menu = gtk_menu_new();
2067 ADD_MENU_ITEM(_("_Forward"), toolbar_reply_menu_cb, COMPOSE_FORWARD_INLINE);
2068 ADD_MENU_ITEM(_("For_ward as attachment"), toolbar_reply_menu_cb, COMPOSE_FORWARD_AS_ATTACH);
2069 ADD_MENU_ITEM(_("Redirec_t"), toolbar_reply_menu_cb, COMPOSE_REDIRECT);
2070 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->fwd_btn), menu);
2072 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2073 _("Forward Message"));
2074 toolbar_data->fwd_btn = item;
2078 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
2079 toolbar_data->trash_btn = item;
2082 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
2083 toolbar_data->delete_btn = item;
2086 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
2087 toolbar_data->exec_btn = item;
2090 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
2091 toolbar_data->prev_btn = item;
2094 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
2095 toolbar_data->next_btn = item;
2098 /* Compose Toolbar */
2100 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2101 toolbar_data->send_btn = item;
2104 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2105 toolbar_data->sendl_btn = item;
2108 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2109 toolbar_data->draft_btn = item;
2112 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2113 toolbar_data->insert_btn = item;
2116 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2117 toolbar_data->attach_btn = item;
2120 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2121 toolbar_data->sig_btn = item;
2124 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2125 toolbar_data->exteditor_btn = item;
2127 case A_LINEWRAP_CURRENT:
2128 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2129 toolbar_data->linewrap_current_btn = item;
2131 case A_LINEWRAP_ALL:
2132 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2133 toolbar_data->linewrap_all_btn = item;
2136 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2137 toolbar_data->addrbook_btn = item;
2140 case A_CHECK_SPELLING:
2141 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2142 toolbar_data->spellcheck_btn = item;
2146 case A_CLAWS_ACTIONS:
2147 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2148 action_item = g_new0(ToolbarClawsActions, 1);
2149 action_item->widget = item;
2150 action_item->name = g_strdup(toolbar_item->text);
2152 toolbar_data->action_list =
2153 g_slist_append(toolbar_data->action_list,
2157 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2158 toolbar_data->cancel_inc_btn = item;
2160 case A_CLAWS_PLUGINS:
2161 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, toolbar_item->text);
2164 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2165 toolbar_ret_descr_from_val(toolbar_item->index));
2166 /* find and set the tool tip text */
2171 toolbar_data->toolbar = toolbar;
2172 #ifndef GENERIC_UMPC
2173 #if !(GTK_CHECK_VERSION(2,12,0))
2174 toolbar_data->tooltips = toolbar_tips;
2177 gtk_widget_show_all(toolbar);
2179 if (type == TOOLBAR_MAIN) {
2181 MainWindow *mainwin = mainwindow_get_mainwindow();
2182 GtkWidget *progressbar = gtk_progress_bar_new();
2183 item = GTK_WIDGET(gtk_tool_item_new());
2184 gtk_container_add (GTK_CONTAINER (item), progressbar);
2185 gtk_widget_show(item);
2186 gtk_widget_set_size_request(progressbar, 84, -1);
2187 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2188 mainwin->progressbar = progressbar;
2190 activate_compose_button(toolbar_data,
2191 prefs_common.toolbar_style,
2192 toolbar_data->compose_btn_type);
2194 if (type != TOOLBAR_COMPOSE)
2195 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2199 gtk_container_add(GTK_CONTAINER(container), toolbar);
2200 gtk_container_set_border_width(GTK_CONTAINER(container), 0);
2202 if ( GTK_IS_WINDOW(container) ) {
2203 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
2204 gtk_widget_show_all (container);
2206 gtk_container_add(GTK_CONTAINER(container), toolbar);
2207 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2210 return toolbar_data;
2214 * Free toolbar structures
2216 void toolbar_destroy(Toolbar * toolbar) {
2218 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2219 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2222 void toolbar_update(ToolbarType type, gpointer data)
2224 Toolbar *toolbar_data;
2225 GtkWidget *handlebox;
2226 MainWindow *mainwin = (MainWindow*)data;
2227 Compose *compose = (Compose*)data;
2228 MessageView *msgview = (MessageView*)data;
2230 #ifndef GENERIC_UMPC
2233 toolbar_data = mainwin->toolbar;
2234 handlebox = mainwin->handlebox;
2236 case TOOLBAR_COMPOSE:
2237 toolbar_data = compose->toolbar;
2238 handlebox = compose->handlebox;
2240 case TOOLBAR_MSGVIEW:
2241 toolbar_data = msgview->toolbar;
2242 handlebox = msgview->handlebox;
2248 gtk_container_remove(GTK_CONTAINER(handlebox),
2249 GTK_WIDGET(toolbar_data->toolbar));
2251 toolbar_init(toolbar_data);
2252 toolbar_data = toolbar_create(type, handlebox, data);
2256 toolbar_data = mainwin->toolbar;
2257 handlebox = mainwin->window;
2259 case TOOLBAR_COMPOSE:
2260 toolbar_data = compose->toolbar;
2261 handlebox = compose->window;
2263 case TOOLBAR_MSGVIEW:
2264 toolbar_data = msgview->toolbar;
2265 handlebox = msgview->window;
2271 hildon_window_remove_toolbar(HILDON_WINDOW(handlebox), GTK_TOOLBAR(toolbar_data->toolbar));
2273 toolbar_init(toolbar_data);
2274 toolbar_data = toolbar_create(type, handlebox, data);
2279 mainwin->toolbar = toolbar_data;
2281 case TOOLBAR_COMPOSE:
2282 compose->toolbar = toolbar_data;
2284 case TOOLBAR_MSGVIEW:
2285 msgview->toolbar = toolbar_data;
2289 toolbar_style(type, prefs_common.toolbar_style, data);
2291 if (type == TOOLBAR_MAIN) {
2292 toolbar_main_set_sensitive((MainWindow*)data);
2293 account_set_menu_only_toolbar();
2297 #if !GTK_CHECK_VERSION(2,14,0)
2298 /* Work around http://bugzilla.gnome.org/show_bug.cgi?id=56070 */
2299 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2300 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2301 if (GTK_IS_BUTTON(widget)) \
2302 in_btn1 = GTK_BUTTON(widget)->in_button; \
2303 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2304 GtkWidget *child = gtk_bin_get_child( \
2306 GList *gchild = gtk_container_get_children( \
2307 GTK_CONTAINER(child)); \
2308 GtkWidget *btn = (GtkWidget *)gchild->data; \
2309 GtkWidget *arr = (GtkWidget *) \
2310 (gchild->next?gchild->next->data:NULL); \
2311 g_list_free(gchild); \
2312 if (GTK_IS_BUTTON(btn)) \
2313 in_btn1 = GTK_BUTTON(btn)->in_button; \
2314 if (GTK_IS_BUTTON(arr)) \
2315 in_btn2 = GTK_BUTTON(arr)->in_button; \
2317 else if (GTK_IS_TOOL_ITEM(widget)) { \
2318 GtkWidget *child = gtk_bin_get_child( \
2320 if (GTK_IS_BUTTON(child)) \
2321 in_btn1 = GTK_BUTTON(child)->in_button; \
2323 gtk_widget_set_sensitive(widget, sensitive); \
2324 if (GTK_IS_BUTTON(widget)) \
2325 GTK_BUTTON(widget)->in_button = in_btn1; \
2326 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2327 GtkWidget *child = gtk_bin_get_child( \
2329 GList *gchild = gtk_container_get_children( \
2330 GTK_CONTAINER(child)); \
2331 GtkWidget *btn = (GtkWidget *)gchild->data; \
2332 GtkWidget *arr = (GtkWidget *) \
2333 (gchild->next?gchild->next->data:NULL); \
2334 g_list_free(gchild); \
2335 if (GTK_IS_BUTTON(btn)) \
2336 GTK_BUTTON(btn)->in_button = in_btn1; \
2337 if (GTK_IS_BUTTON(arr)) \
2338 GTK_BUTTON(arr)->in_button = in_btn2; \
2340 else if (GTK_IS_TOOL_ITEM(widget)) { \
2341 GtkWidget *child = gtk_bin_get_child( \
2343 if (GTK_IS_BUTTON(child)) \
2344 GTK_BUTTON(child)->in_button = in_btn1; \
2348 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2349 gtk_widget_set_sensitive(widget, sensitive); \
2353 void toolbar_main_set_sensitive(gpointer data)
2355 SensitiveCond state;
2357 MainWindow *mainwin = (MainWindow*)data;
2358 Toolbar *toolbar = mainwin->toolbar;
2360 GSList *entry_list = NULL;
2362 typedef struct _Entry Entry;
2369 #define SET_WIDGET_COND(w, c) \
2371 Entry *e = g_new0(Entry, 1); \
2374 entry_list = g_slist_append(entry_list, e); \
2378 if (toolbar->get_btn)
2379 SET_WIDGET_COND(toolbar->get_btn,
2380 M_HAVE_ACCOUNT|M_UNLOCKED|M_HAVE_RETRIEVABLE_ACCOUNT);
2382 if (toolbar->getall_btn) {
2383 SET_WIDGET_COND(toolbar->getall_btn,
2384 M_HAVE_ACCOUNT|M_UNLOCKED|M_HAVE_ANY_RETRIEVABLE_ACCOUNT);
2386 if (toolbar->send_btn) {
2387 SET_WIDGET_COND(toolbar->send_btn,
2388 M_HAVE_QUEUED_MAILS);
2390 if (toolbar->compose_mail_btn) {
2391 SET_WIDGET_COND(toolbar->compose_mail_btn,
2394 if (toolbar->close_window_btn) {
2395 SET_WIDGET_COND(toolbar->close_window_btn,
2398 if (toolbar->open_mail_btn) {
2399 SET_WIDGET_COND(toolbar->open_mail_btn,
2400 M_TARGET_EXIST|M_SUMMARY_ISLIST);
2402 if (toolbar->reply_btn) {
2403 SET_WIDGET_COND(toolbar->reply_btn,
2404 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2406 if (toolbar->replyall_btn) {
2407 SET_WIDGET_COND(toolbar->replyall_btn,
2408 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2410 if (toolbar->replylist_btn) {
2411 SET_WIDGET_COND(toolbar->replylist_btn,
2412 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2414 if (toolbar->replysender_btn) {
2415 SET_WIDGET_COND(toolbar->replysender_btn,
2416 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2418 if (toolbar->fwd_btn) {
2419 SET_WIDGET_COND(toolbar->fwd_btn,
2420 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2423 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2424 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST|M_SUMMARY_ISLIST);
2426 SET_WIDGET_COND(toolbar->next_btn, 0);
2429 if (toolbar->trash_btn)
2430 SET_WIDGET_COND(toolbar->trash_btn,
2431 M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS);
2433 if (toolbar->delete_btn)
2434 SET_WIDGET_COND(toolbar->delete_btn,
2435 M_TARGET_EXIST|M_ALLOW_DELETE);
2437 if (toolbar->exec_btn)
2438 SET_WIDGET_COND(toolbar->exec_btn,
2441 if (toolbar->learn_spam_btn)
2442 SET_WIDGET_COND(toolbar->learn_spam_btn,
2443 M_TARGET_EXIST|M_CAN_LEARN_SPAM|M_SUMMARY_ISLIST);
2445 if (toolbar->cancel_inc_btn)
2446 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2449 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2450 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2452 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2455 #undef SET_WIDGET_COND
2457 state = main_window_get_current_state(mainwin);
2459 for (cur = entry_list; cur != NULL; cur = cur->next) {
2460 Entry *e = (Entry*) cur->data;
2462 if (e->widget != NULL) {
2463 sensitive = ((e->cond & state) == e->cond);
2464 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2468 while (entry_list != NULL) {
2469 Entry *e = (Entry*) entry_list->data;
2472 entry_list = g_slist_remove(entry_list, e);
2475 g_slist_free(entry_list);
2477 activate_compose_button(toolbar,
2478 prefs_common.toolbar_style,
2479 toolbar->compose_btn_type);
2483 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2485 Compose *compose = (Compose*)data;
2486 GSList *items = compose->toolbar->action_list;
2488 if (compose->toolbar->send_btn)
2489 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2490 if (compose->toolbar->sendl_btn)
2491 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2492 if (compose->toolbar->draft_btn )
2493 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2494 if (compose->toolbar->insert_btn )
2495 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2496 if (compose->toolbar->attach_btn)
2497 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2498 if (compose->toolbar->sig_btn)
2499 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2500 if (compose->toolbar->exteditor_btn)
2501 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2502 if (compose->toolbar->linewrap_current_btn)
2503 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2504 if (compose->toolbar->linewrap_all_btn)
2505 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2506 if (compose->toolbar->addrbook_btn)
2507 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2509 if (compose->toolbar->spellcheck_btn)
2510 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2512 for (; items != NULL; items = g_slist_next(items)) {
2513 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2514 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2519 * Initialize toolbar structure
2521 static void toolbar_init(Toolbar * toolbar)
2524 toolbar->toolbar = NULL;
2525 toolbar->folders_btn = NULL;
2526 toolbar->get_btn = NULL;
2527 toolbar->getall_btn = NULL;
2528 toolbar->send_btn = NULL;
2529 toolbar->compose_mail_btn = NULL;
2530 toolbar->compose_mail_icon = NULL;
2531 toolbar->compose_news_icon = NULL;
2532 toolbar->reply_btn = NULL;
2533 toolbar->replysender_btn = NULL;
2534 toolbar->replyall_btn = NULL;
2535 toolbar->replylist_btn = NULL;
2536 toolbar->fwd_btn = NULL;
2537 toolbar->trash_btn = NULL;
2538 toolbar->delete_btn = NULL;
2539 toolbar->prev_btn = NULL;
2540 toolbar->next_btn = NULL;
2541 toolbar->exec_btn = NULL;
2542 toolbar->open_mail_btn = NULL;
2543 toolbar->close_window_btn = NULL;
2544 /* compose buttons */
2545 toolbar->sendl_btn = NULL;
2546 toolbar->draft_btn = NULL;
2547 toolbar->insert_btn = NULL;
2548 toolbar->attach_btn = NULL;
2549 toolbar->sig_btn = NULL;
2550 toolbar->exteditor_btn = NULL;
2551 toolbar->linewrap_current_btn = NULL;
2552 toolbar->linewrap_all_btn = NULL;
2553 toolbar->addrbook_btn = NULL;
2555 toolbar->spellcheck_btn = NULL;
2558 toolbar_destroy(toolbar);
2563 static void toolbar_reply(gpointer data, guint action)
2565 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2566 MainWindow *mainwin;
2567 MessageView *msgview;
2568 GSList *msginfo_list = NULL;
2570 cm_return_if_fail(toolbar_item != NULL);
2572 switch (toolbar_item->type) {
2574 mainwin = (MainWindow*)toolbar_item->parent;
2575 msginfo_list = summary_get_selection(mainwin->summaryview);
2576 msgview = (MessageView*)mainwin->messageview;
2578 case TOOLBAR_MSGVIEW:
2579 msgview = (MessageView*)toolbar_item->parent;
2580 cm_return_if_fail(msgview != NULL);
2581 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2587 cm_return_if_fail(msgview != NULL);
2588 cm_return_if_fail(msginfo_list != NULL);
2589 compose_reply_from_messageview(msgview, msginfo_list, action);
2590 g_slist_free(msginfo_list);
2592 /* TODO: update reply state ion summaryview */
2596 /* exported functions */
2598 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2600 MainWindow *mainwin = (MainWindow*)data;
2602 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2605 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2607 MainWindow *mainwin = (MainWindow*)data;
2609 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2612 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2616 gboolean got_error = FALSE;
2617 gchar *errstr = NULL;
2619 if (prefs_common.work_offline)
2620 if (alertpanel(_("Offline warning"),
2621 _("You're working offline. Override?"),
2622 GTK_STOCK_NO, GTK_STOCK_YES,
2623 NULL) != G_ALERTALTERNATE)
2626 /* ask for confirmation before sending queued messages only
2627 in online mode and if there is at least one message queued
2628 in any of the folder queue
2630 if (prefs_common.confirm_send_queued_messages) {
2632 /* check if there's a queued message */
2633 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2634 Folder *folder = list->data;
2636 found = !procmsg_queue_is_empty(folder->queue);
2638 /* if necessary, ask for confirmation before sending */
2639 if (found && !prefs_common.work_offline) {
2640 if (alertpanel(_("Send queued messages"),
2641 _("Send all queued messages?"),
2642 GTK_STOCK_CANCEL, _("_Send"),
2643 NULL) != G_ALERTALTERNATE)
2648 for (list = folder_get_list(); list != NULL; list = list->next) {
2649 Folder *folder = list->data;
2651 if (folder->queue) {
2652 if (procmsg_send_queue(folder->queue,
2653 prefs_common.savemsg,
2660 alertpanel_error_log(_("Some errors occurred while "
2661 "sending queued messages."));
2663 alertpanel_error_log(_("Some errors occurred "
2664 "while sending queued messages:\n%s"), errstr);
2670 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2672 MainWindow *mainwin = (MainWindow*)data;
2673 PrefsAccount *ac = NULL;
2674 FolderItem *item = mainwin->summaryview->folder_item;
2679 ac = account_find_from_item(item);
2680 if (ac && ac->protocol != A_NNTP) {
2681 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2687 * CLAWS - use current account
2689 if (cur_account && (cur_account->protocol != A_NNTP)) {
2690 compose_new_with_folderitem(cur_account, item, NULL);
2695 * CLAWS - just get the first one
2697 list = account_get_list();
2698 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2699 ac = (PrefsAccount *) cur->data;
2700 if (ac->protocol != A_NNTP) {
2701 compose_new_with_folderitem(ac, item, NULL);
2707 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2709 MainWindow *mainwin = (MainWindow*)data;
2710 PrefsAccount * ac = NULL;
2714 if (mainwin->summaryview->folder_item) {
2715 ac = mainwin->summaryview->folder_item->folder->account;
2716 if (ac && ac->protocol == A_NNTP) {
2717 compose_new_with_folderitem(ac,
2718 mainwin->summaryview->folder_item, NULL);
2723 list = account_get_list();
2724 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2725 ac = (PrefsAccount *) cur->data;
2726 if (ac->protocol == A_NNTP) {
2727 compose_new_with_folderitem(ac,
2728 mainwin->summaryview->folder_item, NULL);