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;
710 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
712 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
713 file = xml_open_file(fileSpec);
716 toolbar_clear_list(source);
720 || (xml_get_dtd(file))
721 || (xml_parse_next_tag(file))
722 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
723 xml_close_file(file);
731 if (xml_parse_next_tag(file))
734 /* Get next tag (icon, icon_text or icon_action) */
735 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
736 toolbar_parse_item(file, source);
737 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
738 ToolbarItem *item = g_new0(ToolbarItem, 1);
740 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
741 item->index = A_SEPARATOR;
742 toolbar_config[source].item_list =
743 g_slist_append(toolbar_config[source].item_list, item);
747 xml_close_file(file);
750 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
752 if (source == TOOLBAR_MAIN)
753 toolbar_set_default(TOOLBAR_MAIN);
754 else if (source == TOOLBAR_COMPOSE)
755 toolbar_set_default(TOOLBAR_COMPOSE);
756 else if (source == TOOLBAR_MSGVIEW)
757 toolbar_set_default(TOOLBAR_MSGVIEW);
759 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
763 toolbar_save_config_file(source);
768 * clears list of toolbar items read from configuration files
770 void toolbar_clear_list(ToolbarType source)
772 while (toolbar_config[source].item_list != NULL) {
773 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
775 toolbar_config[source].item_list =
776 g_slist_remove(toolbar_config[source].item_list, item);
782 g_slist_free(toolbar_config[source].item_list);
787 * return list of Toolbar items
789 GSList *toolbar_get_list(ToolbarType source)
793 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
794 list = toolbar_config[source].item_list;
799 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
801 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
803 toolbar_item->file = g_strdup(t_item->file);
804 toolbar_item->text = g_strdup(t_item->text);
805 toolbar_item->index = t_item->index;
807 toolbar_config[source].item_list =
808 g_slist_append(toolbar_config[source].item_list,
812 static void toolbar_action_execute(GtkWidget *widget,
820 for (cur = action_list; cur != NULL; cur = cur->next) {
821 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
823 if (widget == act->widget) {
824 i = prefs_actions_find_by_name(act->name);
832 actions_execute(data, i, widget, source);
834 g_warning ("Error: did not find Claws Action to execute");
837 gboolean toolbar_check_action_btns(ToolbarType type)
839 GSList *temp, *curr, *list = toolbar_config[type].item_list;
840 gboolean modified = FALSE;
843 while (curr != NULL) {
844 ToolbarItem *toolbar_item = (ToolbarItem *) curr->data;
848 if (toolbar_item->index != A_CLAWS_ACTIONS)
851 if (prefs_actions_find_by_name(toolbar_item->text) == -1) {
852 list = g_slist_delete_link(list, temp);
853 g_free(toolbar_item->file);
854 g_free(toolbar_item->text);
855 g_free(toolbar_item);
863 #if !(GTK_CHECK_VERSION(2,12,0))
864 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
865 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(widget), GTK_TOOLTIPS(toolbar_tips), \
869 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
870 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), tip); \
874 #if !(GTK_CHECK_VERSION(2,12,0))
875 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
876 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(widget), GTK_TOOLTIPS(toolbar_tips), \
880 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
881 gtk_menu_tool_button_set_arrow_tooltip_text(GTK_MENU_TOOL_BUTTON(widget), tip); \
885 static void activate_compose_button (Toolbar *toolbar,
887 ComposeButtonType type)
889 #if !(GTK_CHECK_VERSION(2,12,0))
890 GtkTooltips *toolbar_tips = toolbar->tooltips;
892 if ((!toolbar->compose_mail_btn))
895 if (type == COMPOSEBUTTON_NEWS) {
896 gtk_tool_button_set_icon_widget(
897 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
898 toolbar->compose_news_icon);
900 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose News message"));
902 gtk_widget_show(toolbar->compose_news_icon);
904 gtk_tool_button_set_icon_widget(
905 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
906 toolbar->compose_mail_icon);
908 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose Email"));
910 gtk_widget_show(toolbar->compose_mail_icon);
912 toolbar->compose_btn_type = type;
915 void toolbar_set_compose_button(Toolbar *toolbar,
916 ComposeButtonType compose_btn_type)
918 if (toolbar->compose_btn_type != compose_btn_type)
919 activate_compose_button(toolbar,
920 prefs_common.toolbar_style,
924 static void activate_learn_button (Toolbar *toolbar,
926 LearnButtonType type)
928 #if !(GTK_CHECK_VERSION(2,12,0))
929 GtkTooltips *toolbar_tips = toolbar->tooltips;
931 if ((!toolbar->learn_spam_btn))
934 if (type == LEARN_SPAM) {
935 gtk_tool_button_set_icon_widget(
936 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
937 toolbar->learn_spam_icon);
938 gtk_tool_button_set_label(
939 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
942 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn spam"));
944 gtk_widget_show(toolbar->learn_spam_icon);
946 gtk_tool_button_set_icon_widget(
947 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
948 toolbar->learn_ham_icon);
949 gtk_tool_button_set_label(
950 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
953 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn ham"));
955 gtk_widget_show(toolbar->learn_ham_icon);
957 toolbar->learn_btn_type = type;
960 void toolbar_set_learn_button(Toolbar *toolbar,
961 LearnButtonType learn_btn_type)
963 if (toolbar->learn_btn_type != learn_btn_type)
964 activate_learn_button(toolbar,
965 prefs_common.toolbar_style,
969 void toolbar_toggle(guint action, gpointer data)
971 MainWindow *mainwin = (MainWindow*)data;
975 cm_return_if_fail(mainwin != NULL);
977 toolbar_style(TOOLBAR_MAIN, action, mainwin);
979 list = compose_get_compose_list();
980 for (cur = list; cur != NULL; cur = cur->next) {
981 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
983 list = messageview_get_msgview_list();
984 for (cur = list; cur != NULL; cur = cur->next) {
985 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
990 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
992 switch ((ToolbarStyle)action) {
994 gtk_widget_hide(handlebox_wid);
997 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1001 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1005 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1008 case TOOLBAR_BOTH_HORIZ:
1009 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1010 GTK_TOOLBAR_BOTH_HORIZ);
1016 prefs_common.toolbar_style = (ToolbarStyle)action;
1017 gtk_widget_set_size_request(handlebox_wid, 1, -1);
1019 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1020 gtk_widget_show(handlebox_wid);
1021 gtk_widget_queue_resize(handlebox_wid);
1025 * Change the style of toolbar
1027 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1029 GtkWidget *handlebox_wid;
1030 GtkWidget *toolbar_wid;
1031 MainWindow *mainwin = (MainWindow*)data;
1032 Compose *compose = (Compose*)data;
1033 MessageView *msgview = (MessageView*)data;
1035 cm_return_if_fail(data != NULL);
1039 handlebox_wid = mainwin->handlebox;
1040 toolbar_wid = mainwin->toolbar->toolbar;
1042 case TOOLBAR_COMPOSE:
1043 handlebox_wid = compose->handlebox;
1044 toolbar_wid = compose->toolbar->toolbar;
1046 case TOOLBAR_MSGVIEW:
1047 handlebox_wid = msgview->handlebox;
1048 toolbar_wid = msgview->toolbar->toolbar;
1054 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1057 /* Toolbar handling */
1058 static void toolbar_inc_cb(GtkWidget *widget,
1061 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1062 MainWindow *mainwin;
1064 cm_return_if_fail(toolbar_item != NULL);
1066 switch (toolbar_item->type) {
1068 mainwin = (MainWindow*)toolbar_item->parent;
1069 inc_mail_cb(mainwin, 0, NULL);
1076 static void toolbar_inc_all_cb(GtkWidget *widget,
1079 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1080 MainWindow *mainwin;
1082 cm_return_if_fail(toolbar_item != NULL);
1084 switch (toolbar_item->type) {
1086 mainwin = (MainWindow*)toolbar_item->parent;
1087 inc_all_account_mail_cb(mainwin, 0, NULL);
1094 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1096 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1097 MainWindow *mainwin;
1099 cm_return_if_fail(toolbar_item != NULL);
1101 switch (toolbar_item->type) {
1103 mainwin = (MainWindow*)toolbar_item->parent;
1104 send_queue_cb(mainwin, 0, NULL);
1111 static void toolbar_exec_cb(GtkWidget *widget,
1114 MainWindow *mainwin = get_mainwin(data);
1116 cm_return_if_fail(mainwin != NULL);
1117 summary_execute(mainwin->summaryview);
1121 * Delete current/selected(s) message(s)
1123 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1125 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1126 MainWindow *mainwin;
1128 cm_return_if_fail(toolbar_item != NULL);
1129 cm_return_if_fail(toolbar_item->parent);
1131 switch (toolbar_item->type) {
1132 case TOOLBAR_MSGVIEW:
1133 messageview_delete((MessageView *)toolbar_item->parent);
1136 mainwin = (MainWindow *)toolbar_item->parent;
1137 summary_delete_trash(mainwin->summaryview);
1140 debug_print("toolbar event not supported\n");
1146 * Delete current/selected(s) message(s)
1148 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1150 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1151 MainWindow *mainwin;
1153 cm_return_if_fail(toolbar_item != NULL);
1154 cm_return_if_fail(toolbar_item->parent);
1156 switch (toolbar_item->type) {
1157 case TOOLBAR_MSGVIEW:
1158 messageview_delete((MessageView *)toolbar_item->parent);
1161 mainwin = (MainWindow *)toolbar_item->parent;
1162 summary_delete(mainwin->summaryview);
1165 debug_print("toolbar event not supported\n");
1172 * Compose new message
1174 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1176 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1177 MainWindow *mainwin;
1178 MessageView *msgview;
1180 cm_return_if_fail(toolbar_item != NULL);
1182 switch (toolbar_item->type) {
1184 mainwin = (MainWindow*)toolbar_item->parent;
1185 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1186 compose_news_cb(mainwin, 0, NULL);
1188 compose_mail_cb(mainwin, 0, NULL);
1190 case TOOLBAR_MSGVIEW:
1191 msgview = (MessageView*)toolbar_item->parent;
1192 compose_new_with_folderitem(NULL,
1193 msgview->msginfo->folder, NULL);
1196 debug_print("toolbar event not supported\n");
1200 static void toolbar_learn(gpointer data, guint as_spam)
1202 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1203 MainWindow *mainwin;
1204 MessageView *msgview;
1206 cm_return_if_fail(toolbar_item != NULL);
1208 switch (toolbar_item->type) {
1210 mainwin = (MainWindow*)toolbar_item->parent;
1212 mainwindow_learn(mainwin, TRUE);
1214 mainwindow_learn(mainwin, FALSE);
1216 case TOOLBAR_MSGVIEW:
1217 msgview = (MessageView*)toolbar_item->parent;
1219 messageview_learn(msgview, TRUE);
1221 messageview_learn(msgview, FALSE);
1224 debug_print("toolbar event not supported\n");
1228 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1230 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1231 MainWindow *mainwin;
1232 MessageView *msgview;
1234 cm_return_if_fail(toolbar_item != NULL);
1236 switch (toolbar_item->type) {
1238 mainwin = (MainWindow*)toolbar_item->parent;
1239 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1240 mainwindow_learn(mainwin, TRUE);
1242 mainwindow_learn(mainwin, FALSE);
1244 case TOOLBAR_MSGVIEW:
1245 msgview = (MessageView*)toolbar_item->parent;
1246 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1247 messageview_learn(msgview, TRUE);
1249 messageview_learn(msgview, FALSE);
1252 debug_print("toolbar event not supported\n");
1260 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1262 toolbar_reply(data, (prefs_common.reply_with_quote ?
1263 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE));
1268 * Reply message to Sender and All recipients
1270 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1273 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1274 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE));
1279 * Reply to Mailing List
1281 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1284 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1285 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE));
1290 * Reply to sender of message
1292 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1295 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1296 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE));
1302 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1304 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1307 cm_return_if_fail(toolbar_item != NULL);
1309 switch (toolbar_item->type) {
1311 case TOOLBAR_MSGVIEW:
1314 case TOOLBAR_COMPOSE:
1315 compose = (Compose *)toolbar_item->parent;
1320 #ifndef USE_NEW_ADDRBOOK
1321 addressbook_open(compose);
1323 GError* error = NULL;
1324 addressbook_connect_signals(compose);
1325 addressbook_dbus_open(TRUE, &error);
1327 g_warning("%s", error->message);
1328 g_error_free(error);
1335 * Forward current/selected(s) message(s)
1337 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1339 toolbar_reply(data, (COMPOSE_FORWARD));
1343 * Goto Prev Unread Message
1345 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1347 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1348 MainWindow *mainwin;
1349 MessageView *msgview;
1351 cm_return_if_fail(toolbar_item != NULL);
1353 switch (toolbar_item->type) {
1355 mainwin = (MainWindow*)toolbar_item->parent;
1356 summary_select_prev_unread(mainwin->summaryview);
1359 case TOOLBAR_MSGVIEW:
1360 msgview = (MessageView*)toolbar_item->parent;
1361 msgview->updating = TRUE;
1362 summary_select_prev_unread(msgview->mainwin->summaryview);
1363 msgview->updating = FALSE;
1365 if (msgview->deferred_destroy) {
1366 debug_print("messageview got away!\n");
1367 messageview_destroy(msgview);
1371 /* Now we need to update the messageview window */
1372 if (msgview->mainwin->summaryview->selected) {
1373 #ifndef GENERIC_UMPC
1374 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1377 messageview_show(msgview, msginfo,
1378 msgview->all_headers);
1381 gtk_widget_destroy(msgview->window);
1385 debug_print("toolbar event not supported\n");
1390 * Goto Next Unread Message
1392 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1394 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1395 MainWindow *mainwin;
1396 MessageView *msgview;
1398 cm_return_if_fail(toolbar_item != NULL);
1400 switch (toolbar_item->type) {
1402 mainwin = (MainWindow*)toolbar_item->parent;
1403 summary_select_next_unread(mainwin->summaryview);
1406 case TOOLBAR_MSGVIEW:
1407 msgview = (MessageView*)toolbar_item->parent;
1408 msgview->updating = TRUE;
1409 summary_select_next_unread(msgview->mainwin->summaryview);
1410 msgview->updating = FALSE;
1412 if (msgview->deferred_destroy) {
1413 debug_print("messageview got away!\n");
1414 messageview_destroy(msgview);
1418 /* Now we need to update the messageview window */
1419 if (msgview->mainwin->summaryview->selected) {
1420 #ifndef GENERIC_UMPC
1421 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1424 messageview_show(msgview, msginfo,
1425 msgview->all_headers);
1428 gtk_widget_destroy(msgview->window);
1432 debug_print("toolbar event not supported\n");
1436 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1438 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1439 MainWindow *mainwin;
1441 cm_return_if_fail(toolbar_item != NULL);
1443 switch (toolbar_item->type) {
1445 mainwin = (MainWindow *) toolbar_item->parent;
1446 summary_toggle_ignore_thread(mainwin->summaryview);
1448 case TOOLBAR_MSGVIEW:
1449 /* TODO: see toolbar_next_unread_cb() if you need
1450 * this in the message view */
1453 debug_print("toolbar event not supported\n");
1458 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1460 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1461 MainWindow *mainwin;
1463 cm_return_if_fail(toolbar_item != NULL);
1465 switch (toolbar_item->type) {
1467 mainwin = (MainWindow *) toolbar_item->parent;
1468 summary_toggle_watch_thread(mainwin->summaryview);
1470 case TOOLBAR_MSGVIEW:
1471 /* TODO: see toolbar_next_unread_cb() if you need
1472 * this in the message view */
1475 debug_print("toolbar event not supported\n");
1480 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1482 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1484 cm_return_if_fail(toolbar_item != NULL);
1490 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1492 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1493 MainWindow *mainwin;
1495 cm_return_if_fail(toolbar_item != NULL);
1497 switch (toolbar_item->type) {
1499 mainwin = (MainWindow *) toolbar_item->parent;
1500 summary_print(mainwin->summaryview);
1502 case TOOLBAR_MSGVIEW:
1503 /* TODO: see toolbar_next_unread_cb() if you need
1504 * this in the message view */
1507 debug_print("toolbar event not supported\n");
1512 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1514 compose_toolbar_cb(A_SEND, data);
1517 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1519 compose_toolbar_cb(A_SENDL, data);
1522 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1524 compose_toolbar_cb(A_DRAFT, data);
1527 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1529 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1530 MainWindow *mainwin;
1531 MessageView *messageview;
1534 cm_return_if_fail(toolbar_item != NULL);
1536 switch (toolbar_item->type) {
1538 mainwin = (MainWindow *) toolbar_item->parent;
1539 app_will_exit(NULL, mainwin);
1541 case TOOLBAR_MSGVIEW:
1542 messageview = (MessageView *)toolbar_item->parent;
1543 messageview_destroy(messageview);
1545 case TOOLBAR_COMPOSE:
1546 compose = (Compose *)toolbar_item->parent;
1547 compose_close_toolbar(compose);
1552 static void toolbar_preferences_cb(GtkWidget *widget, gpointer data)
1557 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1559 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1560 MainWindow *mainwin;
1562 cm_return_if_fail(toolbar_item != NULL);
1564 switch (toolbar_item->type) {
1566 mainwin = (MainWindow *) toolbar_item->parent;
1567 summary_open_row(NULL, mainwin->summaryview);
1569 case TOOLBAR_MSGVIEW:
1570 debug_print("toolbar event not supported\n");
1572 case TOOLBAR_COMPOSE:
1573 debug_print("toolbar event not supported\n");
1578 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1580 compose_toolbar_cb(A_INSERT, data);
1583 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1585 compose_toolbar_cb(A_ATTACH, data);
1588 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1590 compose_toolbar_cb(A_SIG, data);
1593 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1595 compose_toolbar_cb(A_EXTEDITOR, data);
1598 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1600 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1603 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1605 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1609 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1611 compose_toolbar_cb(A_CHECK_SPELLING, data);
1615 * Execute actions from toolbar
1617 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1619 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1620 GSList *action_list;
1621 MainWindow *mainwin;
1623 MessageView *msgview;
1624 gpointer parent = toolbar_item->parent;
1626 cm_return_if_fail(toolbar_item != NULL);
1628 switch (toolbar_item->type) {
1630 mainwin = (MainWindow*)parent;
1631 action_list = mainwin->toolbar->action_list;
1633 case TOOLBAR_COMPOSE:
1634 compose = (Compose*)parent;
1635 action_list = compose->toolbar->action_list;
1637 case TOOLBAR_MSGVIEW:
1638 msgview = (MessageView*)parent;
1639 action_list = msgview->toolbar->action_list;
1642 debug_print("toolbar event not supported\n");
1645 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1648 static void toolbar_plugins_execute_cb(GtkWidget *widget, gpointer data)
1650 ToolbarItem *toolbar_item = data;
1651 prefs_toolbar_execute_plugin_item(toolbar_item->parent, toolbar_item->type, toolbar_item->text);
1654 static MainWindow *get_mainwin(gpointer data)
1656 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1657 MainWindow *mainwin = NULL;
1658 MessageView *msgview;
1660 cm_return_val_if_fail(toolbar_item != NULL, NULL);
1662 switch(toolbar_item->type) {
1664 mainwin = (MainWindow*)toolbar_item->parent;
1666 case TOOLBAR_MSGVIEW:
1667 msgview = (MessageView*)toolbar_item->parent;
1668 mainwin = (MainWindow*)msgview->mainwin;
1677 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1679 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1680 MainWindow *mainwin = NULL;
1681 switch(toolbar_item->type) {
1683 mainwin = (MainWindow*)toolbar_item->parent;
1686 g_warning("wrong toolbar type\n");
1690 if (!mainwin->in_folder) {
1691 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1693 folderview_select(mainwin->folderview, item);
1696 gtk_widget_grab_focus(mainwin->folderview->ctree);
1697 mainwindow_exit_folder(mainwin);
1701 static void toolbar_buttons_cb(GtkWidget *widget,
1708 void (*func)(GtkWidget *widget, gpointer data);
1710 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1711 { A_RECEIVE_CUR, toolbar_inc_cb },
1712 { A_SEND_QUEUED, toolbar_send_queued_cb },
1713 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1714 { A_COMPOSE_NEWS, toolbar_compose_cb },
1715 { A_REPLY_MESSAGE, toolbar_reply_cb },
1716 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1717 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1718 { A_REPLY_ML, toolbar_reply_to_list_cb },
1719 { A_FORWARD, toolbar_forward_cb },
1720 { A_TRASH, toolbar_trash_cb },
1721 { A_DELETE_REAL, toolbar_delete_cb },
1722 { A_EXECUTE, toolbar_exec_cb },
1723 { A_GOTO_PREV, toolbar_prev_unread_cb },
1724 { A_GOTO_NEXT, toolbar_next_unread_cb },
1725 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1726 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1727 { A_PRINT, toolbar_print_cb },
1728 { A_LEARN_SPAM, toolbar_learn_cb },
1729 { A_GO_FOLDERS, toolbar_go_folders_cb },
1731 { A_SEND, toolbar_send_cb },
1732 { A_SENDL, toolbar_send_later_cb },
1733 { A_DRAFT, toolbar_draft_cb },
1734 { A_OPEN_MAIL, toolbar_open_mail_cb },
1735 { A_CLOSE, toolbar_close_cb },
1736 { A_PREFERENCES, toolbar_preferences_cb },
1737 { A_INSERT, toolbar_insert_cb },
1738 { A_ATTACH, toolbar_attach_cb },
1739 { A_SIG, toolbar_sig_cb },
1740 { A_EXTEDITOR, toolbar_ext_editor_cb },
1741 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1742 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1743 { A_ADDRBOOK, toolbar_addrbook_cb },
1745 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1747 { A_CLAWS_ACTIONS, toolbar_actions_execute_cb },
1748 { A_CANCEL_INC, toolbar_cancel_inc_cb },
1749 { A_CLAWS_PLUGINS, toolbar_plugins_execute_cb },
1752 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1754 for (i = 0; i < num_items; i++) {
1755 if (callbacks[i].index == item->index) {
1756 callbacks[i].func(widget, item);
1761 #ifndef GENERIC_UMPC
1762 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1763 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1764 gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
1765 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1766 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1767 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1768 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1769 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1773 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1774 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1775 GList *gchild = NULL; \
1776 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1777 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1778 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1779 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1780 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1781 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1783 CLAWS_SET_ARROW_TIP(GTK_MENU_TOOL_BUTTON(item), menutip); \
1784 child = gtk_bin_get_child(GTK_BIN(item)); \
1785 gchild = gtk_container_get_children( \
1786 GTK_CONTAINER(child)); \
1787 btn = (GtkWidget *)gchild->data; \
1788 gtkut_widget_set_can_focus(btn, FALSE); \
1789 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1790 gtkut_widget_set_can_focus(arr, FALSE); \
1791 g_list_free(gchild); \
1792 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1793 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1794 g_list_free(gchild); \
1797 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1798 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1799 gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
1800 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1801 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1802 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1803 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1806 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1807 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1808 GList *gchild = NULL; \
1809 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1810 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1811 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1812 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1813 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1814 child = gtk_bin_get_child(GTK_BIN(item)); \
1815 gchild = gtk_container_get_children( \
1816 GTK_CONTAINER(child)); \
1817 btn = (GtkWidget *)gchild->data; \
1818 gtkut_widget_set_can_focus(btn, FALSE); \
1819 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1820 gtkut_widget_set_can_focus(arr, FALSE); \
1821 g_list_free(gchild); \
1822 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1823 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1824 g_list_free(gchild); \
1828 #define ADD_MENU_ITEM(name,cb,data) { \
1829 item = gtk_menu_item_new_with_mnemonic(name); \
1830 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); \
1831 g_signal_connect(G_OBJECT(item), "activate", \
1834 g_object_set_data(G_OBJECT(item), "int-value", GINT_TO_POINTER(data)); \
1835 gtk_widget_show(item); \
1838 static void toolbar_reply_menu_cb(GtkWidget *widget, gpointer data)
1840 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1841 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1843 toolbar_reply(toolbar_item, GPOINTER_TO_INT(int_value));
1846 static void toolbar_learn_menu_cb(GtkWidget *widget, gpointer data)
1848 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1849 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1851 toolbar_learn(toolbar_item, GPOINTER_TO_INT(int_value));
1855 * Create a new toolbar with specified type
1856 * if a callback list is passed it will be used before the
1857 * common callback list
1859 Toolbar *toolbar_create(ToolbarType type,
1860 GtkWidget *container,
1863 ToolbarItem *toolbar_item;
1866 GtkWidget *icon_wid = NULL;
1867 GtkWidget *icon_news;
1868 GtkWidget *icon_ham;
1870 ToolbarClawsActions *action_item;
1872 GSList *toolbar_list;
1873 Toolbar *toolbar_data;
1875 #ifndef GENERIC_UMPC
1876 #if !(GTK_CHECK_VERSION(2,12,0))
1877 GtkTooltips *toolbar_tips = gtk_tooltips_new();
1880 toolbar_read_config_file(type);
1881 toolbar_list = toolbar_get_list(type);
1883 toolbar_data = g_new0(Toolbar, 1);
1885 toolbar = gtk_toolbar_new();
1887 #if (GTK_CHECK_VERSION(2,16,0))
1888 gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL);
1890 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1892 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1893 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1895 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1897 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1898 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1902 toolbar_item = g_new0(ToolbarItem, 1);
1903 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1904 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1905 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1906 toolbar_item->parent = data;
1907 toolbar_item->type = type;
1909 /* collect toolbar items in list to keep track */
1910 toolbar_data->item_list =
1911 g_slist_append(toolbar_data->item_list,
1913 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1915 switch (toolbar_item->index) {
1918 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1919 toolbar_data->folders_btn = item;
1922 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1923 _("Receive Mail from all Accounts"),
1924 _("Receive Mail from selected Account"));
1925 toolbar_data->getall_btn = item;
1928 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail from current Account"));
1929 toolbar_data->get_btn = item;
1932 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1933 toolbar_data->send_btn = item;
1936 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1937 toolbar_data->close_window_btn = item;
1940 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open preferences"));
1941 toolbar_data->preferences_btn = item;
1944 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1945 toolbar_data->open_mail_btn = item;
1947 case A_COMPOSE_EMAIL:
1948 #ifndef GENERIC_UMPC
1949 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1951 _("Compose with selected Account"));
1952 toolbar_data->compose_mail_btn = item;
1953 toolbar_data->compose_mail_icon = icon_wid;
1954 g_object_ref(toolbar_data->compose_mail_icon);
1956 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1957 toolbar_data->compose_news_icon = icon_news;
1958 g_object_ref(toolbar_data->compose_news_icon);
1960 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1961 _("Compose Email"));
1962 toolbar_data->compose_mail_btn = item;
1963 toolbar_data->compose_mail_icon = icon_wid;
1965 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1966 toolbar_data->compose_news_icon = icon_news;
1970 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1973 toolbar_data->learn_spam_btn = item;
1974 toolbar_data->learn_spam_icon = icon_wid;
1975 g_object_ref(toolbar_data->learn_spam_icon);
1977 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1978 toolbar_data->learn_ham_icon = icon_ham;
1979 g_object_ref(toolbar_data->learn_ham_icon);
1981 menu = gtk_menu_new();
1982 ADD_MENU_ITEM(_("Learn as _Spam"), toolbar_learn_menu_cb, TRUE);
1983 ADD_MENU_ITEM(_("Learn as _Ham"), toolbar_learn_menu_cb, FALSE);
1984 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->learn_spam_btn), menu);
1986 case A_REPLY_MESSAGE:
1987 #ifndef GENERIC_UMPC
1988 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1989 _("Reply to Message"),
1990 _("Reply to Message options"));
1991 toolbar_data->reply_btn = item;
1993 menu = gtk_menu_new();
1994 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITH_QUOTE);
1995 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITHOUT_QUOTE);
1996 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->reply_btn), menu);
1998 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1999 _("Reply to Message"));
2000 toolbar_data->reply_btn = item;
2003 case A_REPLY_SENDER:
2004 #ifndef GENERIC_UMPC
2005 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2006 _("Reply to Sender"),
2007 _("Reply to Sender options"));
2008 toolbar_data->replysender_btn = item;
2010 menu = gtk_menu_new();
2011 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE);
2012 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
2013 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replysender_btn), menu);
2015 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2016 _("Reply to Sender"));
2017 toolbar_data->replysender_btn = item;
2021 #ifndef GENERIC_UMPC
2022 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2024 _("Reply to All options"));
2025 toolbar_data->replyall_btn = item;
2027 menu = gtk_menu_new();
2028 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE);
2029 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
2030 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replyall_btn), menu);
2032 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2034 toolbar_data->replyall_btn = item;
2038 #ifndef GENERIC_UMPC
2039 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2040 _("Reply to Mailing-list"),
2041 _("Reply to Mailing-list options"));
2042 toolbar_data->replylist_btn = item;
2044 menu = gtk_menu_new();
2045 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE);
2046 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
2047 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replylist_btn), menu);
2049 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2050 _("Reply to Mailing-list"));
2051 toolbar_data->replylist_btn = item;
2055 #ifndef GENERIC_UMPC
2056 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2057 _("Forward Message"),
2058 _("Forward Message options"));
2059 toolbar_data->fwd_btn = item;
2061 menu = gtk_menu_new();
2062 ADD_MENU_ITEM(_("_Forward"), toolbar_reply_menu_cb, COMPOSE_FORWARD_INLINE);
2063 ADD_MENU_ITEM(_("For_ward as attachment"), toolbar_reply_menu_cb, COMPOSE_FORWARD_AS_ATTACH);
2064 ADD_MENU_ITEM(_("Redirec_t"), toolbar_reply_menu_cb, COMPOSE_REDIRECT);
2065 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->fwd_btn), menu);
2067 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2068 _("Forward Message"));
2069 toolbar_data->fwd_btn = item;
2073 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
2074 toolbar_data->trash_btn = item;
2077 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
2078 toolbar_data->delete_btn = item;
2081 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
2082 toolbar_data->exec_btn = item;
2085 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
2086 toolbar_data->prev_btn = item;
2089 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
2090 toolbar_data->next_btn = item;
2093 /* Compose Toolbar */
2095 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2096 toolbar_data->send_btn = item;
2099 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2100 toolbar_data->sendl_btn = item;
2103 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2104 toolbar_data->draft_btn = item;
2107 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2108 toolbar_data->insert_btn = item;
2111 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2112 toolbar_data->attach_btn = item;
2115 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2116 toolbar_data->sig_btn = item;
2119 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2120 toolbar_data->exteditor_btn = item;
2122 case A_LINEWRAP_CURRENT:
2123 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2124 toolbar_data->linewrap_current_btn = item;
2126 case A_LINEWRAP_ALL:
2127 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2128 toolbar_data->linewrap_all_btn = item;
2131 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2132 toolbar_data->addrbook_btn = item;
2135 case A_CHECK_SPELLING:
2136 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2137 toolbar_data->spellcheck_btn = item;
2141 case A_CLAWS_ACTIONS:
2142 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2143 action_item = g_new0(ToolbarClawsActions, 1);
2144 action_item->widget = item;
2145 action_item->name = g_strdup(toolbar_item->text);
2147 toolbar_data->action_list =
2148 g_slist_append(toolbar_data->action_list,
2152 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2153 toolbar_data->cancel_inc_btn = item;
2155 case A_CLAWS_PLUGINS:
2156 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, toolbar_item->text);
2159 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2160 toolbar_ret_descr_from_val(toolbar_item->index));
2161 /* find and set the tool tip text */
2166 toolbar_data->toolbar = toolbar;
2167 #ifndef GENERIC_UMPC
2168 #if !(GTK_CHECK_VERSION(2,12,0))
2169 toolbar_data->tooltips = toolbar_tips;
2172 gtk_widget_show_all(toolbar);
2174 if (type == TOOLBAR_MAIN) {
2176 MainWindow *mainwin = mainwindow_get_mainwindow();
2177 GtkWidget *progressbar = gtk_progress_bar_new();
2178 item = GTK_WIDGET(gtk_tool_item_new());
2179 gtk_container_add (GTK_CONTAINER (item), progressbar);
2180 gtk_widget_show(item);
2181 gtk_widget_set_size_request(progressbar, 84, -1);
2182 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2183 mainwin->progressbar = progressbar;
2185 activate_compose_button(toolbar_data,
2186 prefs_common.toolbar_style,
2187 toolbar_data->compose_btn_type);
2189 if (type != TOOLBAR_COMPOSE)
2190 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2194 gtk_container_add(GTK_CONTAINER(container), toolbar);
2195 gtk_container_set_border_width(GTK_CONTAINER(container), 0);
2197 if ( GTK_IS_WINDOW(container) ) {
2198 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
2199 gtk_widget_show_all (container);
2201 gtk_container_add(GTK_CONTAINER(container), toolbar);
2202 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2205 return toolbar_data;
2209 * Free toolbar structures
2211 void toolbar_destroy(Toolbar * toolbar) {
2213 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2214 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2217 void toolbar_update(ToolbarType type, gpointer data)
2219 Toolbar *toolbar_data;
2220 GtkWidget *handlebox;
2221 MainWindow *mainwin = (MainWindow*)data;
2222 Compose *compose = (Compose*)data;
2223 MessageView *msgview = (MessageView*)data;
2225 #ifndef GENERIC_UMPC
2228 toolbar_data = mainwin->toolbar;
2229 handlebox = mainwin->handlebox;
2231 case TOOLBAR_COMPOSE:
2232 toolbar_data = compose->toolbar;
2233 handlebox = compose->handlebox;
2235 case TOOLBAR_MSGVIEW:
2236 toolbar_data = msgview->toolbar;
2237 handlebox = msgview->handlebox;
2243 gtk_container_remove(GTK_CONTAINER(handlebox),
2244 GTK_WIDGET(toolbar_data->toolbar));
2246 toolbar_init(toolbar_data);
2247 toolbar_data = toolbar_create(type, handlebox, data);
2251 toolbar_data = mainwin->toolbar;
2252 handlebox = mainwin->window;
2254 case TOOLBAR_COMPOSE:
2255 toolbar_data = compose->toolbar;
2256 handlebox = compose->window;
2258 case TOOLBAR_MSGVIEW:
2259 toolbar_data = msgview->toolbar;
2260 handlebox = msgview->window;
2266 hildon_window_remove_toolbar(HILDON_WINDOW(handlebox), GTK_TOOLBAR(toolbar_data->toolbar));
2268 toolbar_init(toolbar_data);
2269 toolbar_data = toolbar_create(type, handlebox, data);
2274 mainwin->toolbar = toolbar_data;
2276 case TOOLBAR_COMPOSE:
2277 compose->toolbar = toolbar_data;
2279 case TOOLBAR_MSGVIEW:
2280 msgview->toolbar = toolbar_data;
2284 toolbar_style(type, prefs_common.toolbar_style, data);
2286 if (type == TOOLBAR_MAIN) {
2287 toolbar_main_set_sensitive((MainWindow*)data);
2288 account_set_menu_only_toolbar();
2292 #if !GTK_CHECK_VERSION(2,14,0)
2293 /* Work around http://bugzilla.gnome.org/show_bug.cgi?id=56070 */
2294 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2295 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2296 if (GTK_IS_BUTTON(widget)) \
2297 in_btn1 = GTK_BUTTON(widget)->in_button; \
2298 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2299 GtkWidget *child = gtk_bin_get_child( \
2301 GList *gchild = gtk_container_get_children( \
2302 GTK_CONTAINER(child)); \
2303 GtkWidget *btn = (GtkWidget *)gchild->data; \
2304 GtkWidget *arr = (GtkWidget *) \
2305 (gchild->next?gchild->next->data:NULL); \
2306 g_list_free(gchild); \
2307 if (GTK_IS_BUTTON(btn)) \
2308 in_btn1 = GTK_BUTTON(btn)->in_button; \
2309 if (GTK_IS_BUTTON(arr)) \
2310 in_btn2 = GTK_BUTTON(arr)->in_button; \
2312 else if (GTK_IS_TOOL_ITEM(widget)) { \
2313 GtkWidget *child = gtk_bin_get_child( \
2315 if (GTK_IS_BUTTON(child)) \
2316 in_btn1 = GTK_BUTTON(child)->in_button; \
2318 gtk_widget_set_sensitive(widget, sensitive); \
2319 if (GTK_IS_BUTTON(widget)) \
2320 GTK_BUTTON(widget)->in_button = in_btn1; \
2321 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2322 GtkWidget *child = gtk_bin_get_child( \
2324 GList *gchild = gtk_container_get_children( \
2325 GTK_CONTAINER(child)); \
2326 GtkWidget *btn = (GtkWidget *)gchild->data; \
2327 GtkWidget *arr = (GtkWidget *) \
2328 (gchild->next?gchild->next->data:NULL); \
2329 g_list_free(gchild); \
2330 if (GTK_IS_BUTTON(btn)) \
2331 GTK_BUTTON(btn)->in_button = in_btn1; \
2332 if (GTK_IS_BUTTON(arr)) \
2333 GTK_BUTTON(arr)->in_button = in_btn2; \
2335 else if (GTK_IS_TOOL_ITEM(widget)) { \
2336 GtkWidget *child = gtk_bin_get_child( \
2338 if (GTK_IS_BUTTON(child)) \
2339 GTK_BUTTON(child)->in_button = in_btn1; \
2343 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2344 gtk_widget_set_sensitive(widget, sensitive); \
2348 void toolbar_main_set_sensitive(gpointer data)
2350 SensitiveCond state;
2352 MainWindow *mainwin = (MainWindow*)data;
2353 Toolbar *toolbar = mainwin->toolbar;
2355 GSList *entry_list = NULL;
2357 typedef struct _Entry Entry;
2364 #define SET_WIDGET_COND(w, c) \
2366 Entry *e = g_new0(Entry, 1); \
2369 entry_list = g_slist_append(entry_list, e); \
2373 if (toolbar->get_btn)
2374 SET_WIDGET_COND(toolbar->get_btn,
2375 M_HAVE_ACCOUNT|M_UNLOCKED|M_HAVE_RETRIEVABLE_ACCOUNT);
2377 if (toolbar->getall_btn) {
2378 SET_WIDGET_COND(toolbar->getall_btn,
2379 M_HAVE_ACCOUNT|M_UNLOCKED|M_HAVE_ANY_RETRIEVABLE_ACCOUNT);
2381 if (toolbar->send_btn) {
2382 SET_WIDGET_COND(toolbar->send_btn,
2383 M_HAVE_QUEUED_MAILS);
2385 if (toolbar->compose_mail_btn) {
2386 SET_WIDGET_COND(toolbar->compose_mail_btn,
2389 if (toolbar->close_window_btn) {
2390 SET_WIDGET_COND(toolbar->close_window_btn,
2393 if (toolbar->open_mail_btn) {
2394 SET_WIDGET_COND(toolbar->open_mail_btn,
2395 M_TARGET_EXIST|M_SUMMARY_ISLIST);
2397 if (toolbar->reply_btn) {
2398 SET_WIDGET_COND(toolbar->reply_btn,
2399 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2401 if (toolbar->replyall_btn) {
2402 SET_WIDGET_COND(toolbar->replyall_btn,
2403 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2405 if (toolbar->replylist_btn) {
2406 SET_WIDGET_COND(toolbar->replylist_btn,
2407 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2409 if (toolbar->replysender_btn) {
2410 SET_WIDGET_COND(toolbar->replysender_btn,
2411 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2413 if (toolbar->fwd_btn) {
2414 SET_WIDGET_COND(toolbar->fwd_btn,
2415 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2418 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2419 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST|M_SUMMARY_ISLIST);
2421 SET_WIDGET_COND(toolbar->next_btn, 0);
2424 if (toolbar->trash_btn)
2425 SET_WIDGET_COND(toolbar->trash_btn,
2426 M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS);
2428 if (toolbar->delete_btn)
2429 SET_WIDGET_COND(toolbar->delete_btn,
2430 M_TARGET_EXIST|M_ALLOW_DELETE);
2432 if (toolbar->exec_btn)
2433 SET_WIDGET_COND(toolbar->exec_btn,
2436 if (toolbar->learn_spam_btn)
2437 SET_WIDGET_COND(toolbar->learn_spam_btn,
2438 M_TARGET_EXIST|M_CAN_LEARN_SPAM|M_SUMMARY_ISLIST);
2440 if (toolbar->cancel_inc_btn)
2441 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2444 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2445 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2447 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2450 #undef SET_WIDGET_COND
2452 state = main_window_get_current_state(mainwin);
2454 for (cur = entry_list; cur != NULL; cur = cur->next) {
2455 Entry *e = (Entry*) cur->data;
2457 if (e->widget != NULL) {
2458 sensitive = ((e->cond & state) == e->cond);
2459 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2463 while (entry_list != NULL) {
2464 Entry *e = (Entry*) entry_list->data;
2467 entry_list = g_slist_remove(entry_list, e);
2470 g_slist_free(entry_list);
2472 activate_compose_button(toolbar,
2473 prefs_common.toolbar_style,
2474 toolbar->compose_btn_type);
2478 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2480 Compose *compose = (Compose*)data;
2481 GSList *items = compose->toolbar->action_list;
2483 if (compose->toolbar->send_btn)
2484 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2485 if (compose->toolbar->sendl_btn)
2486 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2487 if (compose->toolbar->draft_btn )
2488 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2489 if (compose->toolbar->insert_btn )
2490 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2491 if (compose->toolbar->attach_btn)
2492 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2493 if (compose->toolbar->sig_btn)
2494 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2495 if (compose->toolbar->exteditor_btn)
2496 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2497 if (compose->toolbar->linewrap_current_btn)
2498 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2499 if (compose->toolbar->linewrap_all_btn)
2500 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2501 if (compose->toolbar->addrbook_btn)
2502 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2504 if (compose->toolbar->spellcheck_btn)
2505 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2507 for (; items != NULL; items = g_slist_next(items)) {
2508 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2509 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2514 * Initialize toolbar structure
2516 static void toolbar_init(Toolbar * toolbar)
2519 toolbar->toolbar = NULL;
2520 toolbar->folders_btn = NULL;
2521 toolbar->get_btn = NULL;
2522 toolbar->getall_btn = NULL;
2523 toolbar->send_btn = NULL;
2524 toolbar->compose_mail_btn = NULL;
2525 toolbar->compose_mail_icon = NULL;
2526 toolbar->compose_news_icon = NULL;
2527 toolbar->reply_btn = NULL;
2528 toolbar->replysender_btn = NULL;
2529 toolbar->replyall_btn = NULL;
2530 toolbar->replylist_btn = NULL;
2531 toolbar->fwd_btn = NULL;
2532 toolbar->trash_btn = NULL;
2533 toolbar->delete_btn = NULL;
2534 toolbar->prev_btn = NULL;
2535 toolbar->next_btn = NULL;
2536 toolbar->exec_btn = NULL;
2537 toolbar->open_mail_btn = NULL;
2538 toolbar->close_window_btn = NULL;
2539 /* compose buttons */
2540 toolbar->sendl_btn = NULL;
2541 toolbar->draft_btn = NULL;
2542 toolbar->insert_btn = NULL;
2543 toolbar->attach_btn = NULL;
2544 toolbar->sig_btn = NULL;
2545 toolbar->exteditor_btn = NULL;
2546 toolbar->linewrap_current_btn = NULL;
2547 toolbar->linewrap_all_btn = NULL;
2548 toolbar->addrbook_btn = NULL;
2550 toolbar->spellcheck_btn = NULL;
2553 toolbar_destroy(toolbar);
2558 static void toolbar_reply(gpointer data, guint action)
2560 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2561 MainWindow *mainwin;
2562 MessageView *msgview;
2563 GSList *msginfo_list = NULL;
2565 cm_return_if_fail(toolbar_item != NULL);
2567 switch (toolbar_item->type) {
2569 mainwin = (MainWindow*)toolbar_item->parent;
2570 msginfo_list = summary_get_selection(mainwin->summaryview);
2571 msgview = (MessageView*)mainwin->messageview;
2573 case TOOLBAR_MSGVIEW:
2574 msgview = (MessageView*)toolbar_item->parent;
2575 cm_return_if_fail(msgview != NULL);
2576 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2582 cm_return_if_fail(msgview != NULL);
2583 cm_return_if_fail(msginfo_list != NULL);
2584 compose_reply_from_messageview(msgview, msginfo_list, action);
2585 g_slist_free(msginfo_list);
2587 /* TODO: update reply state ion summaryview */
2591 /* exported functions */
2593 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2595 MainWindow *mainwin = (MainWindow*)data;
2597 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2600 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2602 MainWindow *mainwin = (MainWindow*)data;
2604 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2607 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2611 gboolean got_error = FALSE;
2612 gchar *errstr = NULL;
2614 if (prefs_common.work_offline)
2615 if (alertpanel(_("Offline warning"),
2616 _("You're working offline. Override?"),
2617 GTK_STOCK_NO, GTK_STOCK_YES,
2618 NULL) != G_ALERTALTERNATE)
2621 /* ask for confirmation before sending queued messages only
2622 in online mode and if there is at least one message queued
2623 in any of the folder queue
2625 if (prefs_common.confirm_send_queued_messages) {
2627 /* check if there's a queued message */
2628 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2629 Folder *folder = list->data;
2631 found = !procmsg_queue_is_empty(folder->queue);
2633 /* if necessary, ask for confirmation before sending */
2634 if (found && !prefs_common.work_offline) {
2635 if (alertpanel(_("Send queued messages"),
2636 _("Send all queued messages?"),
2637 GTK_STOCK_CANCEL, _("_Send"),
2638 NULL) != G_ALERTALTERNATE)
2643 for (list = folder_get_list(); list != NULL; list = list->next) {
2644 Folder *folder = list->data;
2646 if (folder->queue) {
2647 if (procmsg_send_queue(folder->queue,
2648 prefs_common.savemsg,
2655 alertpanel_error_log(_("Some errors occurred while "
2656 "sending queued messages."));
2658 alertpanel_error_log(_("Some errors occurred "
2659 "while sending queued messages:\n%s"), errstr);
2665 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2667 MainWindow *mainwin = (MainWindow*)data;
2668 PrefsAccount *ac = NULL;
2669 FolderItem *item = mainwin->summaryview->folder_item;
2674 ac = account_find_from_item(item);
2675 if (ac && ac->protocol != A_NNTP) {
2676 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2682 * CLAWS - use current account
2684 if (cur_account && (cur_account->protocol != A_NNTP)) {
2685 compose_new_with_folderitem(cur_account, item, NULL);
2690 * CLAWS - just get the first one
2692 list = account_get_list();
2693 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2694 ac = (PrefsAccount *) cur->data;
2695 if (ac->protocol != A_NNTP) {
2696 compose_new_with_folderitem(ac, item, NULL);
2702 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2704 MainWindow *mainwin = (MainWindow*)data;
2705 PrefsAccount * ac = NULL;
2709 if (mainwin->summaryview->folder_item) {
2710 ac = mainwin->summaryview->folder_item->folder->account;
2711 if (ac && ac->protocol == A_NNTP) {
2712 compose_new_with_folderitem(ac,
2713 mainwin->summaryview->folder_item, NULL);
2718 list = account_get_list();
2719 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2720 ac = (PrefsAccount *) cur->data;
2721 if (ac->protocol == A_NNTP) {
2722 compose_new_with_folderitem(ac,
2723 mainwin->summaryview->folder_item, NULL);