2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2009 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * General functions for accessing address book files.
31 #include <glib/gi18n.h>
40 #include "mainwindow.h"
41 #include "summaryview.h"
46 #include "prefs_gtk.h"
48 #include "stock_pixmap.h"
49 #include "manage_window.h"
55 #include "prefs_actions.h"
56 #include "prefs_common.h"
57 #include "prefs_toolbar.h"
58 #include "alertpanel.h"
62 #define TOOLBAR_TAG_INDEX "toolbar"
63 #define TOOLBAR_TAG_ITEM "item"
64 #define TOOLBAR_TAG_SEPARATOR "separator"
66 #define TOOLBAR_ICON_FILE "file"
67 #define TOOLBAR_ICON_TEXT "text"
68 #define TOOLBAR_ICON_ACTION "action"
70 static void toolbar_init(Toolbar * toolbar);
71 static gboolean toolbar_is_duplicate (gint action,
73 static void toolbar_parse_item (XMLFile *file,
76 static gint toolbar_ret_val_from_text (const gchar *text);
77 static gchar *toolbar_ret_text_from_val (gint val);
79 static void toolbar_set_default_main (void);
80 static void toolbar_set_default_compose (void);
81 static void toolbar_set_default_msgview (void);
83 static void toolbar_style (ToolbarType type,
87 static MainWindow *get_mainwin (gpointer data);
88 static void activate_compose_button (Toolbar *toolbar,
90 ComposeButtonType type);
92 /* toolbar callbacks */
93 static void toolbar_reply (gpointer data,
95 static void toolbar_learn (gpointer data,
97 static void toolbar_delete_cb (GtkWidget *widget,
99 static void toolbar_trash_cb (GtkWidget *widget,
102 static void toolbar_compose_cb (GtkWidget *widget,
105 static void toolbar_learn_cb (GtkWidget *widget,
108 static void toolbar_reply_cb (GtkWidget *widget,
111 static void toolbar_reply_to_all_cb (GtkWidget *widget,
114 static void toolbar_reply_to_list_cb (GtkWidget *widget,
117 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
120 static void toolbar_forward_cb (GtkWidget *widget,
123 static void toolbar_prev_unread_cb (GtkWidget *widget,
125 static void toolbar_next_unread_cb (GtkWidget *widget,
128 static void toolbar_ignore_thread_cb (GtkWidget *widget,
131 static void toolbar_watch_thread_cb (GtkWidget *widget,
134 static void toolbar_print_cb (GtkWidget *widget,
137 static void toolbar_actions_execute_cb (GtkWidget *widget,
141 static void toolbar_send_cb (GtkWidget *widget,
143 static void toolbar_send_later_cb (GtkWidget *widget,
145 static void toolbar_draft_cb (GtkWidget *widget,
147 static void toolbar_close_cb (GtkWidget *widget,
149 static void toolbar_preferences_cb (GtkWidget *widget,
151 static void toolbar_open_mail_cb (GtkWidget *widget,
153 static void toolbar_insert_cb (GtkWidget *widget,
155 static void toolbar_attach_cb (GtkWidget *widget,
157 static void toolbar_sig_cb (GtkWidget *widget,
159 static void toolbar_ext_editor_cb (GtkWidget *widget,
161 static void toolbar_linewrap_current_cb (GtkWidget *widget,
163 static void toolbar_linewrap_all_cb (GtkWidget *widget,
165 static void toolbar_addrbook_cb (GtkWidget *widget,
168 static void toolbar_check_spelling_cb (GtkWidget *widget,
171 static void toolbar_cancel_inc_cb (GtkWidget *widget,
177 } toolbar_text [] = {
178 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
179 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
180 { "A_SEND_QUEUED", N_("Send Queued Messages") },
181 { "A_COMPOSE_EMAIL", N_("Compose Email") },
182 { "A_COMPOSE_NEWS", N_("Compose News") },
183 { "A_REPLY_MESSAGE", N_("Reply to Message") },
184 { "A_REPLY_SENDER", N_("Reply to Sender") },
185 { "A_REPLY_ALL", N_("Reply to All") },
186 { "A_REPLY_ML", N_("Reply to Mailing-list") },
187 { "A_OPEN_MAIL", N_("Open email") },
188 { "A_FORWARD", N_("Forward Message") },
189 { "A_TRASH", N_("Trash Message") },
190 { "A_DELETE_REAL", N_("Delete Message") },
191 { "A_EXECUTE", N_("Execute") },
192 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
193 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
194 { "A_IGNORE_THREAD", N_("Ignore thread") },
195 { "A_WATCH_THREAD", N_("Watch thread") },
196 { "A_PRINT", N_("Print") },
197 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
198 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
199 { "A_PREFERENCES", N_("Preferences") },
201 { "A_SEND", N_("Send Message") },
202 { "A_SENDL", N_("Put into queue folder and send later") },
203 { "A_DRAFT", N_("Save to draft folder") },
204 { "A_INSERT", N_("Insert file") },
205 { "A_ATTACH", N_("Attach file") },
206 { "A_SIG", N_("Insert signature") },
207 { "A_EXTEDITOR", N_("Edit with external editor") },
208 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
209 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
210 { "A_ADDRBOOK", N_("Address book") },
212 { "A_CHECK_SPELLING", N_("Check spelling") },
214 { "A_CLAWS_ACTIONS", N_("Claws Mail Actions Feature") },
215 { "A_CANCEL_INC", N_("Cancel receiving") },
216 { "A_CLOSE", N_("Close window") },
217 { "A_SEPARATOR", N_("Separator") }
220 /* struct holds configuration files and a list of
221 * currently active toolbar items
222 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
226 const gchar *conf_file;
228 } toolbar_config[3] = {
229 { "toolbar_main.xml", NULL},
230 { "toolbar_compose.xml", NULL},
231 { "toolbar_msgview.xml", NULL}
234 gint toolbar_ret_val_from_descr(const gchar *descr)
238 for (i = 0; i < N_ACTION_VAL; i++) {
239 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
246 gchar *toolbar_ret_descr_from_val(gint val)
248 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
250 return gettext(toolbar_text[val].descr);
253 static gint toolbar_ret_val_from_text(const gchar *text)
257 for (i = 0; i < N_ACTION_VAL; i++) {
258 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
265 static gchar *toolbar_ret_text_from_val(gint val)
267 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
269 return toolbar_text[val].index_str;
272 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
276 if ((action == A_SEPARATOR) || (action == A_CLAWS_ACTIONS))
279 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
280 ToolbarItem *item = (ToolbarItem*) cur->data;
282 if (item->index == action)
288 /* depending on toolbar type this function
289 returns a list of available toolbar events being
290 displayed by prefs_toolbar
292 GList *toolbar_get_action_items(ToolbarType source)
297 if (source == TOOLBAR_MAIN) {
298 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
299 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
300 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
301 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
302 A_GOTO_NEXT, A_IGNORE_THREAD, A_WATCH_THREAD, A_PRINT,
303 A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
304 A_CANCEL_INC, A_PREFERENCES };
306 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
307 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
310 else if (source == TOOLBAR_COMPOSE) {
311 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
312 A_INSERT, A_ATTACH, A_SIG,
313 A_EXTEDITOR, A_LINEWRAP_CURRENT,
314 A_LINEWRAP_ALL, A_ADDRBOOK,
320 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
321 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
323 else if (source == TOOLBAR_MSGVIEW) {
324 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
325 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
326 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
327 A_ADDRBOOK, A_LEARN_SPAM, A_CLOSE };
329 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
330 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
336 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
340 ToolbarItem *item = NULL;
341 gboolean rewrite = FALSE;
343 attr = xml_get_current_tag_attr(file);
344 item = g_new0(ToolbarItem, 1);
346 name = ((XMLAttr *)attr->data)->name;
347 value = ((XMLAttr *)attr->data)->value;
349 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
350 item->file = g_strdup (value);
351 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
352 item->text = g_strdup (gettext(value));
353 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
354 item->index = toolbar_ret_val_from_text(value);
355 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
357 item->index = A_TRASH;
359 item->file = g_strdup("trash_btn");
361 item->text = g_strdup(_("Trash"));
364 if (item->index == -1 && !strcmp(value, "A_SYL_ACTIONS")) {
366 item->index = A_CLAWS_ACTIONS;
369 attr = g_list_next(attr);
371 if (item->index != -1) {
373 if (!toolbar_is_duplicate(item->index, source))
374 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
378 toolbar_save_config_file(source);
382 const gchar *toolbar_get_short_text(int action) {
384 case A_GO_FOLDERS: return _("Folders");
385 case A_OPEN_MAIL: return _("Open");
386 case A_RECEIVE_ALL: return _("Get Mail");
387 case A_RECEIVE_CUR: return _("Get");
388 case A_SEND_QUEUED: return _("Send");
389 case A_COMPOSE_EMAIL: return Q_("Toolbar|Compose");
390 case A_COMPOSE_NEWS: return Q_("Toolbar|Compose");
391 case A_REPLY_MESSAGE: return _("Reply");
392 case A_REPLY_ALL: return _("All");
393 case A_REPLY_SENDER: return _("Sender");
394 case A_REPLY_ML: return _("List");
395 case A_FORWARD: return _("Forward");
396 case A_TRASH: return _("Trash");
397 case A_DELETE_REAL: return _("Delete");
398 case A_LEARN_SPAM: return _("Spam");
399 case A_GOTO_PREV: return _("Prev");
400 case A_GOTO_NEXT: return _("Next");
401 case A_IGNORE_THREAD: return _("Ignore thread");
402 case A_WATCH_THREAD: return _("Watch thread");
403 case A_PRINT: return _("Print");
404 case A_CLOSE: return _("Close");
405 case A_PREFERENCES: return _("Preferences");
406 case A_SEND: return _("Send");
407 case A_SENDL: return _("Send later");
408 case A_DRAFT: return _("Draft");
409 case A_INSERT: return _("Insert");
410 case A_ATTACH: return _("Attach");
411 case A_SIG: return _("Insert sig.");
412 case A_EXTEDITOR: return _("Edit");
413 case A_LINEWRAP_CURRENT:return _("Wrap para.");
414 case A_LINEWRAP_ALL: return _("Wrap all");
415 case A_ADDRBOOK: return _("Address");
416 case A_CANCEL_INC: return _("Stop");
417 case A_EXECUTE: return _("Execute");
419 case A_CHECK_SPELLING: return _("Check spelling");
425 gint toolbar_get_icon(int action) {
427 case A_GO_FOLDERS: return STOCK_PIXMAP_GO_FOLDERS;
428 case A_OPEN_MAIL: return STOCK_PIXMAP_OPEN_MAIL;
429 case A_RECEIVE_ALL: return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
430 case A_RECEIVE_CUR: return STOCK_PIXMAP_MAIL_RECEIVE;
431 case A_SEND_QUEUED: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
432 case A_COMPOSE_EMAIL: return STOCK_PIXMAP_MAIL_COMPOSE;
433 case A_COMPOSE_NEWS: return STOCK_PIXMAP_NEWS_COMPOSE;
434 case A_REPLY_MESSAGE: return STOCK_PIXMAP_MAIL_REPLY;
435 case A_REPLY_ALL: return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
436 case A_REPLY_SENDER: return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
437 case A_REPLY_ML: return STOCK_PIXMAP_MAIL_REPLY_TO_LIST;
438 case A_FORWARD: return STOCK_PIXMAP_MAIL_FORWARD;
439 case A_TRASH: return STOCK_PIXMAP_TRASH;
440 case A_DELETE_REAL: return STOCK_PIXMAP_DELETE;
441 case A_LEARN_SPAM: return STOCK_PIXMAP_SPAM_BTN;
442 case A_GOTO_PREV: return STOCK_PIXMAP_UP_ARROW;
443 case A_GOTO_NEXT: return STOCK_PIXMAP_DOWN_ARROW;
444 case A_IGNORE_THREAD: return STOCK_PIXMAP_IGNORETHREAD;
445 case A_WATCH_THREAD: return STOCK_PIXMAP_WATCHTHREAD;
446 case A_PRINT: return STOCK_PIXMAP_PRINTER;
447 case A_CLOSE: return STOCK_PIXMAP_CLOSE;
448 case A_PREFERENCES: return STOCK_PIXMAP_PREFERENCES;
449 case A_SEND: return STOCK_PIXMAP_MAIL_SEND;
450 case A_SENDL: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
451 case A_DRAFT: return STOCK_PIXMAP_MAIL;
452 case A_INSERT: return STOCK_PIXMAP_INSERT_FILE;
453 case A_ATTACH: return STOCK_PIXMAP_MAIL_ATTACH;
454 case A_SIG: return STOCK_PIXMAP_MAIL_SIGN;
455 case A_EXTEDITOR: return STOCK_PIXMAP_EDIT_EXTERN;
456 case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
457 case A_LINEWRAP_ALL: return STOCK_PIXMAP_LINEWRAP_ALL;
458 case A_ADDRBOOK: return STOCK_PIXMAP_ADDRESS_BOOK;
459 case A_CANCEL_INC: return STOCK_PIXMAP_CANCEL;
460 case A_EXECUTE: return STOCK_PIXMAP_EXEC;
462 case A_CHECK_SPELLING: return STOCK_PIXMAP_CHECK_SPELLING;
468 static void toolbar_set_default_main(void)
472 } default_toolbar[] = {
492 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
502 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
504 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
506 if (default_toolbar[i].action != A_SEPARATOR) {
509 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
510 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
513 toolbar_item->file = g_strdup(file);
514 toolbar_item->index = default_toolbar[i].action;
515 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
518 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
519 toolbar_item->index = A_SEPARATOR;
522 if (toolbar_item->index != -1) {
523 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
524 toolbar_config[TOOLBAR_MAIN].item_list =
525 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
530 static void toolbar_set_default_compose(void)
534 } default_toolbar[] = {
553 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
555 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
557 if (default_toolbar[i].action != A_SEPARATOR) {
560 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
561 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
563 toolbar_item->file = g_strdup(file);
564 toolbar_item->index = default_toolbar[i].action;
565 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
568 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
569 toolbar_item->index = A_SEPARATOR;
572 if (toolbar_item->index != -1) {
573 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
574 toolbar_config[TOOLBAR_COMPOSE].item_list =
575 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
580 static void toolbar_set_default_msgview(void)
584 } default_toolbar[] = {
596 #if (defined(USE_SPAMASSASSIN_PLUGIN) || defined(USE_BOGOFILTER_PLUGIN))
605 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
607 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
609 if (default_toolbar[i].action != A_SEPARATOR) {
611 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
612 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
615 toolbar_item->file = g_strdup(file);
616 toolbar_item->index = default_toolbar[i].action;
617 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
620 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
621 toolbar_item->index = A_SEPARATOR;
624 if (toolbar_item->index != -1) {
625 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
626 toolbar_config[TOOLBAR_MSGVIEW].item_list =
627 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
632 void toolbar_set_default(ToolbarType source)
634 if (source == TOOLBAR_MAIN)
635 toolbar_set_default_main();
636 else if (source == TOOLBAR_COMPOSE)
637 toolbar_set_default_compose();
638 else if (source == TOOLBAR_MSGVIEW)
639 toolbar_set_default_msgview();
642 void toolbar_save_config_file(ToolbarType source)
647 gchar *fileSpec = NULL;
649 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
651 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
652 pfile = prefs_write_open(fileSpec);
655 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
658 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
661 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
662 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
664 if (toolbar_item->index != A_SEPARATOR) {
665 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
667 TOOLBAR_ICON_FILE, toolbar_item->file,
668 TOOLBAR_ICON_TEXT) < 0)
670 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
672 if (fprintf(fp, "\" %s=\"%s\"/>\n",
674 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
677 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
682 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
686 if (prefs_file_close (pfile) < 0 )
687 g_warning("failed to write toolbar configuration to file\n");
691 FILE_OP_ERROR(fileSpec, "fprintf");
693 prefs_file_close_revert (pfile);
695 g_warning("failed to open toolbar configuration file for writing\n");
698 void toolbar_read_config_file(ToolbarType source)
700 XMLFile *file = NULL;
701 gchar *fileSpec = NULL;
706 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
708 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
709 file = xml_open_file(fileSpec);
712 toolbar_clear_list(source);
716 || (xml_get_dtd(file))
717 || (xml_parse_next_tag(file))
718 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
719 xml_close_file(file);
723 attr = xml_get_current_tag_attr(file);
730 if (xml_parse_next_tag(file))
733 /* Get next tag (icon, icon_text or icon_action) */
734 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
735 toolbar_parse_item(file, source);
736 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
737 ToolbarItem *item = g_new0(ToolbarItem, 1);
739 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
740 item->index = A_SEPARATOR;
741 toolbar_config[source].item_list =
742 g_slist_append(toolbar_config[source].item_list, item);
746 xml_close_file(file);
749 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
751 if (source == TOOLBAR_MAIN)
752 toolbar_set_default(TOOLBAR_MAIN);
753 else if (source == TOOLBAR_COMPOSE)
754 toolbar_set_default(TOOLBAR_COMPOSE);
755 else if (source == TOOLBAR_MSGVIEW)
756 toolbar_set_default(TOOLBAR_MSGVIEW);
758 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
762 toolbar_save_config_file(source);
767 * clears list of toolbar items read from configuration files
769 void toolbar_clear_list(ToolbarType source)
771 while (toolbar_config[source].item_list != NULL) {
772 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
774 toolbar_config[source].item_list =
775 g_slist_remove(toolbar_config[source].item_list, item);
781 g_slist_free(toolbar_config[source].item_list);
786 * return list of Toolbar items
788 GSList *toolbar_get_list(ToolbarType source)
792 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
793 list = toolbar_config[source].item_list;
798 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
800 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
802 toolbar_item->file = g_strdup(t_item->file);
803 toolbar_item->text = g_strdup(t_item->text);
804 toolbar_item->index = t_item->index;
806 toolbar_config[source].item_list =
807 g_slist_append(toolbar_config[source].item_list,
811 static void toolbar_action_execute(GtkWidget *widget,
817 gchar *action, *action_p;
818 gboolean found = FALSE;
821 for (cur = action_list; cur != NULL; cur = cur->next) {
822 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
824 if (widget == act->widget) {
826 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
827 action = g_strdup((gchar*)lop->data);
829 action_p = strstr(action, ": ");
831 if (g_utf8_collate(act->name, action) == 0) {
845 actions_execute(data, i, widget, source);
847 g_warning ("Error: did not find Claws Action to execute");
850 #if !(GTK_CHECK_VERSION(2,12,0))
851 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
852 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(widget), GTK_TOOLTIPS(toolbar_tips), \
856 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
857 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), tip); \
861 #if !(GTK_CHECK_VERSION(2,12,0))
862 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
863 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(widget), GTK_TOOLTIPS(toolbar_tips), \
867 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
868 gtk_menu_tool_button_set_arrow_tooltip_text(GTK_MENU_TOOL_BUTTON(widget), tip); \
872 static void activate_compose_button (Toolbar *toolbar,
874 ComposeButtonType type)
876 #if !(GTK_CHECK_VERSION(2,12,0))
877 GtkTooltips *toolbar_tips = toolbar->tooltips;
879 if ((!toolbar->compose_mail_btn))
882 if (type == COMPOSEBUTTON_NEWS) {
883 gtk_tool_button_set_icon_widget(
884 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
885 toolbar->compose_news_icon);
887 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose News message"));
889 gtk_widget_show(toolbar->compose_news_icon);
891 gtk_tool_button_set_icon_widget(
892 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
893 toolbar->compose_mail_icon);
895 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose Email"));
897 gtk_widget_show(toolbar->compose_mail_icon);
899 toolbar->compose_btn_type = type;
902 void toolbar_set_compose_button(Toolbar *toolbar,
903 ComposeButtonType compose_btn_type)
905 if (toolbar->compose_btn_type != compose_btn_type)
906 activate_compose_button(toolbar,
907 prefs_common.toolbar_style,
911 static void activate_learn_button (Toolbar *toolbar,
913 LearnButtonType type)
915 #if !(GTK_CHECK_VERSION(2,12,0))
916 GtkTooltips *toolbar_tips = toolbar->tooltips;
918 if ((!toolbar->learn_spam_btn))
921 if (type == LEARN_SPAM) {
922 gtk_tool_button_set_icon_widget(
923 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
924 toolbar->learn_spam_icon);
925 gtk_tool_button_set_label(
926 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
929 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn spam"));
931 gtk_widget_show(toolbar->learn_spam_icon);
933 gtk_tool_button_set_icon_widget(
934 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
935 toolbar->learn_ham_icon);
936 gtk_tool_button_set_label(
937 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
940 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn ham"));
942 gtk_widget_show(toolbar->learn_ham_icon);
944 toolbar->learn_btn_type = type;
947 void toolbar_set_learn_button(Toolbar *toolbar,
948 LearnButtonType learn_btn_type)
950 if (toolbar->learn_btn_type != learn_btn_type)
951 activate_learn_button(toolbar,
952 prefs_common.toolbar_style,
956 void toolbar_toggle(guint action, gpointer data)
958 MainWindow *mainwin = (MainWindow*)data;
962 cm_return_if_fail(mainwin != NULL);
964 toolbar_style(TOOLBAR_MAIN, action, mainwin);
966 list = compose_get_compose_list();
967 for (cur = list; cur != NULL; cur = cur->next) {
968 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
970 list = messageview_get_msgview_list();
971 for (cur = list; cur != NULL; cur = cur->next) {
972 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
977 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
979 switch ((ToolbarStyle)action) {
981 gtk_widget_hide(handlebox_wid);
984 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
988 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
992 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
995 case TOOLBAR_BOTH_HORIZ:
996 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
997 GTK_TOOLBAR_BOTH_HORIZ);
1003 prefs_common.toolbar_style = (ToolbarStyle)action;
1004 gtk_widget_set_size_request(handlebox_wid, 1, -1);
1006 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1007 gtk_widget_show(handlebox_wid);
1008 gtk_widget_queue_resize(handlebox_wid);
1012 * Change the style of toolbar
1014 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1016 GtkWidget *handlebox_wid;
1017 GtkWidget *toolbar_wid;
1018 MainWindow *mainwin = (MainWindow*)data;
1019 Compose *compose = (Compose*)data;
1020 MessageView *msgview = (MessageView*)data;
1022 cm_return_if_fail(data != NULL);
1026 handlebox_wid = mainwin->handlebox;
1027 toolbar_wid = mainwin->toolbar->toolbar;
1029 case TOOLBAR_COMPOSE:
1030 handlebox_wid = compose->handlebox;
1031 toolbar_wid = compose->toolbar->toolbar;
1033 case TOOLBAR_MSGVIEW:
1034 handlebox_wid = msgview->handlebox;
1035 toolbar_wid = msgview->toolbar->toolbar;
1041 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1044 /* Toolbar handling */
1045 static void toolbar_inc_cb(GtkWidget *widget,
1048 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1049 MainWindow *mainwin;
1051 cm_return_if_fail(toolbar_item != NULL);
1053 switch (toolbar_item->type) {
1055 mainwin = (MainWindow*)toolbar_item->parent;
1056 inc_mail_cb(mainwin, 0, NULL);
1063 static void toolbar_inc_all_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_all_account_mail_cb(mainwin, 0, NULL);
1081 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1083 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1084 MainWindow *mainwin;
1086 cm_return_if_fail(toolbar_item != NULL);
1088 switch (toolbar_item->type) {
1090 mainwin = (MainWindow*)toolbar_item->parent;
1091 send_queue_cb(mainwin, 0, NULL);
1098 static void toolbar_exec_cb(GtkWidget *widget,
1101 MainWindow *mainwin = get_mainwin(data);
1103 cm_return_if_fail(mainwin != NULL);
1104 summary_execute(mainwin->summaryview);
1108 * Delete current/selected(s) message(s)
1110 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1112 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1113 MainWindow *mainwin;
1115 cm_return_if_fail(toolbar_item != NULL);
1116 cm_return_if_fail(toolbar_item->parent);
1118 switch (toolbar_item->type) {
1119 case TOOLBAR_MSGVIEW:
1120 messageview_delete((MessageView *)toolbar_item->parent);
1123 mainwin = (MainWindow *)toolbar_item->parent;
1124 summary_delete_trash(mainwin->summaryview);
1127 debug_print("toolbar event not supported\n");
1133 * Delete current/selected(s) message(s)
1135 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1137 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1138 MainWindow *mainwin;
1140 cm_return_if_fail(toolbar_item != NULL);
1141 cm_return_if_fail(toolbar_item->parent);
1143 switch (toolbar_item->type) {
1144 case TOOLBAR_MSGVIEW:
1145 messageview_delete((MessageView *)toolbar_item->parent);
1148 mainwin = (MainWindow *)toolbar_item->parent;
1149 summary_delete(mainwin->summaryview);
1152 debug_print("toolbar event not supported\n");
1159 * Compose new message
1161 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1163 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1164 MainWindow *mainwin;
1165 MessageView *msgview;
1167 cm_return_if_fail(toolbar_item != NULL);
1169 switch (toolbar_item->type) {
1171 mainwin = (MainWindow*)toolbar_item->parent;
1172 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1173 compose_news_cb(mainwin, 0, NULL);
1175 compose_mail_cb(mainwin, 0, NULL);
1177 case TOOLBAR_MSGVIEW:
1178 msgview = (MessageView*)toolbar_item->parent;
1179 compose_new_with_folderitem(NULL,
1180 msgview->msginfo->folder, NULL);
1183 debug_print("toolbar event not supported\n");
1187 static void toolbar_learn(gpointer data, guint as_spam)
1189 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1190 MainWindow *mainwin;
1191 MessageView *msgview;
1193 cm_return_if_fail(toolbar_item != NULL);
1195 switch (toolbar_item->type) {
1197 mainwin = (MainWindow*)toolbar_item->parent;
1199 mainwindow_learn(mainwin, TRUE);
1201 mainwindow_learn(mainwin, FALSE);
1203 case TOOLBAR_MSGVIEW:
1204 msgview = (MessageView*)toolbar_item->parent;
1206 messageview_learn(msgview, TRUE);
1208 messageview_learn(msgview, FALSE);
1211 debug_print("toolbar event not supported\n");
1215 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1217 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1218 MainWindow *mainwin;
1219 MessageView *msgview;
1221 cm_return_if_fail(toolbar_item != NULL);
1223 switch (toolbar_item->type) {
1225 mainwin = (MainWindow*)toolbar_item->parent;
1226 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1227 mainwindow_learn(mainwin, TRUE);
1229 mainwindow_learn(mainwin, FALSE);
1231 case TOOLBAR_MSGVIEW:
1232 msgview = (MessageView*)toolbar_item->parent;
1233 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1234 messageview_learn(msgview, TRUE);
1236 messageview_learn(msgview, FALSE);
1239 debug_print("toolbar event not supported\n");
1247 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1249 toolbar_reply(data, (prefs_common.reply_with_quote ?
1250 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE));
1255 * Reply message to Sender and All recipients
1257 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1260 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1261 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE));
1266 * Reply to Mailing List
1268 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1271 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1272 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE));
1277 * Reply to sender of message
1279 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1282 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1283 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE));
1289 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1291 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1294 cm_return_if_fail(toolbar_item != NULL);
1296 switch (toolbar_item->type) {
1298 case TOOLBAR_MSGVIEW:
1301 case TOOLBAR_COMPOSE:
1302 compose = (Compose *)toolbar_item->parent;
1307 addressbook_open(compose);
1312 * Forward current/selected(s) message(s)
1314 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1316 toolbar_reply(data, (COMPOSE_FORWARD));
1320 * Goto Prev Unread Message
1322 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1324 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1325 MainWindow *mainwin;
1326 MessageView *msgview;
1328 cm_return_if_fail(toolbar_item != NULL);
1330 switch (toolbar_item->type) {
1332 mainwin = (MainWindow*)toolbar_item->parent;
1333 summary_select_prev_unread(mainwin->summaryview);
1336 case TOOLBAR_MSGVIEW:
1337 msgview = (MessageView*)toolbar_item->parent;
1338 msgview->updating = TRUE;
1339 summary_select_prev_unread(msgview->mainwin->summaryview);
1340 msgview->updating = FALSE;
1342 if (msgview->deferred_destroy) {
1343 debug_print("messageview got away!\n");
1344 messageview_destroy(msgview);
1348 /* Now we need to update the messageview window */
1349 if (msgview->mainwin->summaryview->selected) {
1350 #ifndef GENERIC_UMPC
1351 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1354 messageview_show(msgview, msginfo,
1355 msgview->all_headers);
1358 gtk_widget_destroy(msgview->window);
1362 debug_print("toolbar event not supported\n");
1367 * Goto Next Unread Message
1369 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1371 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1372 MainWindow *mainwin;
1373 MessageView *msgview;
1375 cm_return_if_fail(toolbar_item != NULL);
1377 switch (toolbar_item->type) {
1379 mainwin = (MainWindow*)toolbar_item->parent;
1380 summary_select_next_unread(mainwin->summaryview);
1383 case TOOLBAR_MSGVIEW:
1384 msgview = (MessageView*)toolbar_item->parent;
1385 msgview->updating = TRUE;
1386 summary_select_next_unread(msgview->mainwin->summaryview);
1387 msgview->updating = FALSE;
1389 if (msgview->deferred_destroy) {
1390 debug_print("messageview got away!\n");
1391 messageview_destroy(msgview);
1395 /* Now we need to update the messageview window */
1396 if (msgview->mainwin->summaryview->selected) {
1397 #ifndef GENERIC_UMPC
1398 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1401 messageview_show(msgview, msginfo,
1402 msgview->all_headers);
1405 gtk_widget_destroy(msgview->window);
1409 debug_print("toolbar event not supported\n");
1413 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1415 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1416 MainWindow *mainwin;
1418 cm_return_if_fail(toolbar_item != NULL);
1420 switch (toolbar_item->type) {
1422 mainwin = (MainWindow *) toolbar_item->parent;
1423 summary_toggle_ignore_thread(mainwin->summaryview);
1425 case TOOLBAR_MSGVIEW:
1426 /* TODO: see toolbar_next_unread_cb() if you need
1427 * this in the message view */
1430 debug_print("toolbar event not supported\n");
1435 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1437 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1438 MainWindow *mainwin;
1440 cm_return_if_fail(toolbar_item != NULL);
1442 switch (toolbar_item->type) {
1444 mainwin = (MainWindow *) toolbar_item->parent;
1445 summary_toggle_watch_thread(mainwin->summaryview);
1447 case TOOLBAR_MSGVIEW:
1448 /* TODO: see toolbar_next_unread_cb() if you need
1449 * this in the message view */
1452 debug_print("toolbar event not supported\n");
1457 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1459 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1461 cm_return_if_fail(toolbar_item != NULL);
1467 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1469 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1470 MainWindow *mainwin;
1472 cm_return_if_fail(toolbar_item != NULL);
1474 switch (toolbar_item->type) {
1476 mainwin = (MainWindow *) toolbar_item->parent;
1477 summary_print(mainwin->summaryview);
1479 case TOOLBAR_MSGVIEW:
1480 /* TODO: see toolbar_next_unread_cb() if you need
1481 * this in the message view */
1484 debug_print("toolbar event not supported\n");
1489 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1491 compose_toolbar_cb(A_SEND, data);
1494 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1496 compose_toolbar_cb(A_SENDL, data);
1499 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1501 compose_toolbar_cb(A_DRAFT, data);
1504 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1506 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1507 MainWindow *mainwin;
1508 MessageView *messageview;
1511 cm_return_if_fail(toolbar_item != NULL);
1513 switch (toolbar_item->type) {
1515 mainwin = (MainWindow *) toolbar_item->parent;
1516 app_will_exit(NULL, mainwin);
1518 case TOOLBAR_MSGVIEW:
1519 messageview = (MessageView *)toolbar_item->parent;
1520 messageview_destroy(messageview);
1522 case TOOLBAR_COMPOSE:
1523 compose = (Compose *)toolbar_item->parent;
1524 compose_close_toolbar(compose);
1529 static void toolbar_preferences_cb(GtkWidget *widget, gpointer data)
1534 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1536 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1537 MainWindow *mainwin;
1539 cm_return_if_fail(toolbar_item != NULL);
1541 switch (toolbar_item->type) {
1543 mainwin = (MainWindow *) toolbar_item->parent;
1544 summary_open_row(NULL, mainwin->summaryview);
1546 case TOOLBAR_MSGVIEW:
1547 debug_print("toolbar event not supported\n");
1549 case TOOLBAR_COMPOSE:
1550 debug_print("toolbar event not supported\n");
1555 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1557 compose_toolbar_cb(A_INSERT, data);
1560 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1562 compose_toolbar_cb(A_ATTACH, data);
1565 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1567 compose_toolbar_cb(A_SIG, data);
1570 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1572 compose_toolbar_cb(A_EXTEDITOR, data);
1575 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1577 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1580 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1582 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1586 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1588 compose_toolbar_cb(A_CHECK_SPELLING, data);
1592 * Execute actions from toolbar
1594 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1596 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1597 GSList *action_list;
1598 MainWindow *mainwin;
1600 MessageView *msgview;
1601 gpointer parent = toolbar_item->parent;
1603 cm_return_if_fail(toolbar_item != NULL);
1605 switch (toolbar_item->type) {
1607 mainwin = (MainWindow*)parent;
1608 action_list = mainwin->toolbar->action_list;
1610 case TOOLBAR_COMPOSE:
1611 compose = (Compose*)parent;
1612 action_list = compose->toolbar->action_list;
1614 case TOOLBAR_MSGVIEW:
1615 msgview = (MessageView*)parent;
1616 action_list = msgview->toolbar->action_list;
1619 debug_print("toolbar event not supported\n");
1622 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1625 static MainWindow *get_mainwin(gpointer data)
1627 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1628 MainWindow *mainwin = NULL;
1629 MessageView *msgview;
1631 cm_return_val_if_fail(toolbar_item != NULL, NULL);
1633 switch(toolbar_item->type) {
1635 mainwin = (MainWindow*)toolbar_item->parent;
1637 case TOOLBAR_MSGVIEW:
1638 msgview = (MessageView*)toolbar_item->parent;
1639 mainwin = (MainWindow*)msgview->mainwin;
1648 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1650 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1651 MainWindow *mainwin = NULL;
1652 switch(toolbar_item->type) {
1654 mainwin = (MainWindow*)toolbar_item->parent;
1657 g_warning("wrong toolbar type\n");
1661 if (!mainwin->in_folder) {
1662 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1664 folderview_select(mainwin->folderview, item);
1667 gtk_widget_grab_focus(mainwin->folderview->ctree);
1668 mainwindow_exit_folder(mainwin);
1672 static void toolbar_buttons_cb(GtkWidget *widget,
1679 void (*func)(GtkWidget *widget, gpointer data);
1681 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1682 { A_RECEIVE_CUR, toolbar_inc_cb },
1683 { A_SEND_QUEUED, toolbar_send_queued_cb },
1684 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1685 { A_COMPOSE_NEWS, toolbar_compose_cb },
1686 { A_REPLY_MESSAGE, toolbar_reply_cb },
1687 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1688 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1689 { A_REPLY_ML, toolbar_reply_to_list_cb },
1690 { A_FORWARD, toolbar_forward_cb },
1691 { A_TRASH, toolbar_trash_cb },
1692 { A_DELETE_REAL, toolbar_delete_cb },
1693 { A_EXECUTE, toolbar_exec_cb },
1694 { A_GOTO_PREV, toolbar_prev_unread_cb },
1695 { A_GOTO_NEXT, toolbar_next_unread_cb },
1696 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1697 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1698 { A_PRINT, toolbar_print_cb },
1699 { A_LEARN_SPAM, toolbar_learn_cb },
1700 { A_GO_FOLDERS, toolbar_go_folders_cb },
1702 { A_SEND, toolbar_send_cb },
1703 { A_SENDL, toolbar_send_later_cb },
1704 { A_DRAFT, toolbar_draft_cb },
1705 { A_OPEN_MAIL, toolbar_open_mail_cb },
1706 { A_CLOSE, toolbar_close_cb },
1707 { A_PREFERENCES, toolbar_preferences_cb },
1708 { A_INSERT, toolbar_insert_cb },
1709 { A_ATTACH, toolbar_attach_cb },
1710 { A_SIG, toolbar_sig_cb },
1711 { A_EXTEDITOR, toolbar_ext_editor_cb },
1712 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1713 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1714 { A_ADDRBOOK, toolbar_addrbook_cb },
1716 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1718 { A_CLAWS_ACTIONS, toolbar_actions_execute_cb },
1719 { A_CANCEL_INC, toolbar_cancel_inc_cb }
1722 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1724 for (i = 0; i < num_items; i++) {
1725 if (callbacks[i].index == item->index) {
1726 callbacks[i].func(widget, item);
1731 #ifndef GENERIC_UMPC
1732 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1733 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1734 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1735 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1736 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1737 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1738 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1742 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1743 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1744 GList *gchild = NULL; \
1745 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1746 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1747 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1748 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1749 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1750 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1752 CLAWS_SET_ARROW_TIP(GTK_MENU_TOOL_BUTTON(item), menutip); \
1753 child = gtk_bin_get_child(GTK_BIN(item)); \
1754 gchild = gtk_container_get_children( \
1755 GTK_CONTAINER(child)); \
1756 btn = (GtkWidget *)gchild->data; \
1757 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1758 g_list_free(gchild); \
1759 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1760 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1761 g_list_free(gchild); \
1764 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1765 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1766 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1767 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1768 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1769 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1772 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1773 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1774 GList *gchild = NULL; \
1775 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1776 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1777 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1778 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1779 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1780 child = gtk_bin_get_child(GTK_BIN(item)); \
1781 gchild = gtk_container_get_children( \
1782 GTK_CONTAINER(child)); \
1783 btn = (GtkWidget *)gchild->data; \
1784 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1785 g_list_free(gchild); \
1786 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1787 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1788 g_list_free(gchild); \
1792 #define ADD_MENU_ITEM(name,cb,data) { \
1793 item = gtk_menu_item_new_with_mnemonic(name); \
1794 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); \
1795 g_signal_connect(G_OBJECT(item), "activate", \
1798 g_object_set_data(G_OBJECT(item), "int-value", GINT_TO_POINTER(data)); \
1799 gtk_widget_show(item); \
1802 static void toolbar_reply_menu_cb(GtkWidget *widget, gpointer data)
1804 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1805 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1807 toolbar_reply(toolbar_item, GPOINTER_TO_INT(int_value));
1810 static void toolbar_learn_menu_cb(GtkWidget *widget, gpointer data)
1812 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1813 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1815 toolbar_learn(toolbar_item, GPOINTER_TO_INT(int_value));
1819 * Create a new toolbar with specified type
1820 * if a callback list is passed it will be used before the
1821 * common callback list
1823 Toolbar *toolbar_create(ToolbarType type,
1824 GtkWidget *container,
1827 ToolbarItem *toolbar_item;
1830 GtkWidget *icon_wid = NULL;
1831 GtkWidget *icon_news;
1832 GtkWidget *icon_ham;
1834 ToolbarClawsActions *action_item;
1836 GSList *toolbar_list;
1837 Toolbar *toolbar_data;
1839 #ifndef GENERIC_UMPC
1840 #if !(GTK_CHECK_VERSION(2,12,0))
1841 GtkTooltips *toolbar_tips = gtk_tooltips_new();
1844 toolbar_read_config_file(type);
1845 toolbar_list = toolbar_get_list(type);
1847 toolbar_data = g_new0(Toolbar, 1);
1849 toolbar = gtk_toolbar_new();
1851 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1852 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1853 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1855 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1857 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1858 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1862 toolbar_item = g_new0(ToolbarItem, 1);
1863 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1864 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1865 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1866 toolbar_item->parent = data;
1867 toolbar_item->type = type;
1869 /* collect toolbar items in list to keep track */
1870 toolbar_data->item_list =
1871 g_slist_append(toolbar_data->item_list,
1873 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1875 switch (toolbar_item->index) {
1878 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1879 toolbar_data->folders_btn = item;
1882 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1883 _("Receive Mail on all Accounts"),
1884 _("Receive Mail on selected Account"));
1885 toolbar_data->getall_btn = item;
1888 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail on current Account"));
1889 toolbar_data->get_btn = item;
1892 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1893 toolbar_data->send_btn = item;
1896 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1897 toolbar_data->close_window_btn = item;
1900 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open preferences"));
1901 toolbar_data->preferences_btn = item;
1904 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1905 toolbar_data->open_mail_btn = item;
1907 case A_COMPOSE_EMAIL:
1908 #ifndef GENERIC_UMPC
1909 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1911 _("Compose with selected Account"));
1912 toolbar_data->compose_mail_btn = item;
1913 toolbar_data->compose_mail_icon = icon_wid;
1914 g_object_ref(toolbar_data->compose_mail_icon);
1916 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1917 toolbar_data->compose_news_icon = icon_news;
1918 g_object_ref(toolbar_data->compose_news_icon);
1920 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1921 _("Compose Email"));
1922 toolbar_data->compose_mail_btn = item;
1923 toolbar_data->compose_mail_icon = icon_wid;
1925 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1926 toolbar_data->compose_news_icon = icon_news;
1930 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1933 toolbar_data->learn_spam_btn = item;
1934 toolbar_data->learn_spam_icon = icon_wid;
1935 g_object_ref(toolbar_data->learn_spam_icon);
1937 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1938 toolbar_data->learn_ham_icon = icon_ham;
1939 g_object_ref(toolbar_data->learn_ham_icon);
1941 menu = gtk_menu_new();
1942 ADD_MENU_ITEM(_("Learn as _Spam"), toolbar_learn_menu_cb, TRUE);
1943 ADD_MENU_ITEM(_("Learn as _Ham"), toolbar_learn_menu_cb, FALSE);
1944 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->learn_spam_btn), menu);
1946 case A_REPLY_MESSAGE:
1947 #ifndef GENERIC_UMPC
1948 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1949 _("Reply to Message"),
1950 _("Reply to Message options"));
1951 toolbar_data->reply_btn = item;
1953 menu = gtk_menu_new();
1954 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITH_QUOTE);
1955 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITHOUT_QUOTE);
1956 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->reply_btn), menu);
1958 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1959 _("Reply to Message"));
1960 toolbar_data->reply_btn = item;
1963 case A_REPLY_SENDER:
1964 #ifndef GENERIC_UMPC
1965 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1966 _("Reply to Sender"),
1967 _("Reply to Sender options"));
1968 toolbar_data->replysender_btn = item;
1970 menu = gtk_menu_new();
1971 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE);
1972 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1973 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replysender_btn), menu);
1975 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1976 _("Reply to Sender"));
1977 toolbar_data->replysender_btn = item;
1981 #ifndef GENERIC_UMPC
1982 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1984 _("Reply to All options"));
1985 toolbar_data->replyall_btn = item;
1987 menu = gtk_menu_new();
1988 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE);
1989 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1990 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replyall_btn), menu);
1992 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1994 toolbar_data->replyall_btn = item;
1998 #ifndef GENERIC_UMPC
1999 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2000 _("Reply to Mailing-list"),
2001 _("Reply to Mailing-list options"));
2002 toolbar_data->replylist_btn = item;
2004 menu = gtk_menu_new();
2005 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE);
2006 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
2007 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replylist_btn), menu);
2009 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2010 _("Reply to Mailing-list"));
2011 toolbar_data->replylist_btn = item;
2015 #ifndef GENERIC_UMPC
2016 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2017 _("Forward Message"),
2018 _("Forward Message options"));
2019 toolbar_data->fwd_btn = item;
2021 menu = gtk_menu_new();
2022 ADD_MENU_ITEM(_("_Forward"), toolbar_reply_menu_cb, COMPOSE_FORWARD_INLINE);
2023 ADD_MENU_ITEM(_("For_ward as attachment"), toolbar_reply_menu_cb, COMPOSE_FORWARD_AS_ATTACH);
2024 ADD_MENU_ITEM(_("Redirec_t"), toolbar_reply_menu_cb, COMPOSE_REDIRECT);
2025 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->fwd_btn), menu);
2027 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2028 _("Forward Message"));
2029 toolbar_data->fwd_btn = item;
2033 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
2034 toolbar_data->trash_btn = item;
2037 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
2038 toolbar_data->delete_btn = item;
2041 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
2042 toolbar_data->exec_btn = item;
2045 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
2046 toolbar_data->prev_btn = item;
2049 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
2050 toolbar_data->next_btn = item;
2053 /* Compose Toolbar */
2055 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2056 toolbar_data->send_btn = item;
2059 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2060 toolbar_data->sendl_btn = item;
2063 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2064 toolbar_data->draft_btn = item;
2067 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2068 toolbar_data->insert_btn = item;
2071 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2072 toolbar_data->attach_btn = item;
2075 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2076 toolbar_data->sig_btn = item;
2079 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2080 toolbar_data->exteditor_btn = item;
2082 case A_LINEWRAP_CURRENT:
2083 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2084 toolbar_data->linewrap_current_btn = item;
2086 case A_LINEWRAP_ALL:
2087 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2088 toolbar_data->linewrap_all_btn = item;
2091 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2092 toolbar_data->addrbook_btn = item;
2095 case A_CHECK_SPELLING:
2096 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2097 toolbar_data->spellcheck_btn = item;
2101 case A_CLAWS_ACTIONS:
2102 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2103 action_item = g_new0(ToolbarClawsActions, 1);
2104 action_item->widget = item;
2105 action_item->name = g_strdup(toolbar_item->text);
2107 toolbar_data->action_list =
2108 g_slist_append(toolbar_data->action_list,
2112 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2113 toolbar_data->cancel_inc_btn = item;
2116 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2117 toolbar_ret_descr_from_val(toolbar_item->index));
2118 /* find and set the tool tip text */
2123 toolbar_data->toolbar = toolbar;
2124 #ifndef GENERIC_UMPC
2125 #if !(GTK_CHECK_VERSION(2,12,0))
2126 toolbar_data->tooltips = toolbar_tips;
2129 gtk_widget_show_all(toolbar);
2131 if (type == TOOLBAR_MAIN) {
2133 MainWindow *mainwin = mainwindow_get_mainwindow();
2134 GtkWidget *progressbar = gtk_progress_bar_new();
2135 item = GTK_WIDGET(gtk_tool_item_new());
2136 gtk_container_add (GTK_CONTAINER (item), progressbar);
2137 gtk_widget_show(item);
2138 gtk_widget_show(progressbar);
2139 gtk_widget_set_size_request(progressbar, 70, -1);
2140 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2141 mainwin->progressbar = progressbar;
2143 activate_compose_button(toolbar_data,
2144 prefs_common.toolbar_style,
2145 toolbar_data->compose_btn_type);
2147 if (type != TOOLBAR_COMPOSE)
2148 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2152 gtk_container_add(GTK_CONTAINER(container), toolbar);
2153 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2155 if ( GTK_IS_WINDOW(container) ) {
2156 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
2157 gtk_widget_show_all (container);
2159 gtk_container_add(GTK_CONTAINER(container), toolbar);
2160 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2163 return toolbar_data;
2167 * Free toolbar structures
2169 void toolbar_destroy(Toolbar * toolbar) {
2171 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2172 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2175 void toolbar_update(ToolbarType type, gpointer data)
2177 Toolbar *toolbar_data;
2178 GtkWidget *handlebox;
2179 MainWindow *mainwin = (MainWindow*)data;
2180 Compose *compose = (Compose*)data;
2181 MessageView *msgview = (MessageView*)data;
2183 #ifndef GENERIC_UMPC
2186 toolbar_data = mainwin->toolbar;
2187 handlebox = mainwin->handlebox;
2189 case TOOLBAR_COMPOSE:
2190 toolbar_data = compose->toolbar;
2191 handlebox = compose->handlebox;
2193 case TOOLBAR_MSGVIEW:
2194 toolbar_data = msgview->toolbar;
2195 handlebox = msgview->handlebox;
2201 gtk_container_remove(GTK_CONTAINER(handlebox),
2202 GTK_WIDGET(toolbar_data->toolbar));
2204 toolbar_init(toolbar_data);
2205 toolbar_data = toolbar_create(type, handlebox, data);
2209 toolbar_data = mainwin->toolbar;
2210 handlebox = mainwin->window;
2212 case TOOLBAR_COMPOSE:
2213 toolbar_data = compose->toolbar;
2214 handlebox = compose->window;
2216 case TOOLBAR_MSGVIEW:
2217 toolbar_data = msgview->toolbar;
2218 handlebox = msgview->window;
2224 hildon_window_remove_toolbar(HILDON_WINDOW(handlebox), GTK_TOOLBAR(toolbar_data->toolbar));
2226 toolbar_init(toolbar_data);
2227 toolbar_data = toolbar_create(type, handlebox, data);
2232 mainwin->toolbar = toolbar_data;
2234 case TOOLBAR_COMPOSE:
2235 compose->toolbar = toolbar_data;
2237 case TOOLBAR_MSGVIEW:
2238 msgview->toolbar = toolbar_data;
2242 toolbar_style(type, prefs_common.toolbar_style, data);
2244 if (type == TOOLBAR_MAIN) {
2245 toolbar_main_set_sensitive((MainWindow*)data);
2246 account_set_menu_only_toolbar();
2250 #if !GTK_CHECK_VERSION(2,14,0)
2251 /* Work around http://bugzilla.gnome.org/show_bug.cgi?id=56070 */
2252 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2253 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2254 if (GTK_IS_BUTTON(widget)) \
2255 in_btn1 = GTK_BUTTON(widget)->in_button; \
2256 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2257 GtkWidget *child = gtk_bin_get_child( \
2259 GList *gchild = gtk_container_get_children( \
2260 GTK_CONTAINER(child)); \
2261 GtkWidget *btn = (GtkWidget *)gchild->data; \
2262 GtkWidget *arr = (GtkWidget *) \
2263 (gchild->next?gchild->next->data:NULL); \
2264 g_list_free(gchild); \
2265 if (GTK_IS_BUTTON(btn)) \
2266 in_btn1 = GTK_BUTTON(btn)->in_button; \
2267 if (GTK_IS_BUTTON(arr)) \
2268 in_btn2 = GTK_BUTTON(arr)->in_button; \
2270 else if (GTK_IS_TOOL_ITEM(widget)) { \
2271 GtkWidget *child = gtk_bin_get_child( \
2273 if (GTK_IS_BUTTON(child)) \
2274 in_btn1 = GTK_BUTTON(child)->in_button; \
2276 gtk_widget_set_sensitive(widget, sensitive); \
2277 if (GTK_IS_BUTTON(widget)) \
2278 GTK_BUTTON(widget)->in_button = in_btn1; \
2279 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2280 GtkWidget *child = gtk_bin_get_child( \
2282 GList *gchild = gtk_container_get_children( \
2283 GTK_CONTAINER(child)); \
2284 GtkWidget *btn = (GtkWidget *)gchild->data; \
2285 GtkWidget *arr = (GtkWidget *) \
2286 (gchild->next?gchild->next->data:NULL); \
2287 g_list_free(gchild); \
2288 if (GTK_IS_BUTTON(btn)) \
2289 GTK_BUTTON(btn)->in_button = in_btn1; \
2290 if (GTK_IS_BUTTON(arr)) \
2291 GTK_BUTTON(arr)->in_button = in_btn2; \
2293 else if (GTK_IS_TOOL_ITEM(widget)) { \
2294 GtkWidget *child = gtk_bin_get_child( \
2296 if (GTK_IS_BUTTON(child)) \
2297 GTK_BUTTON(child)->in_button = in_btn1; \
2301 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2302 gtk_widget_set_sensitive(widget, sensitive); \
2306 void toolbar_main_set_sensitive(gpointer data)
2308 SensitiveCond state;
2310 MainWindow *mainwin = (MainWindow*)data;
2311 Toolbar *toolbar = mainwin->toolbar;
2313 GSList *entry_list = NULL;
2315 typedef struct _Entry Entry;
2322 #define SET_WIDGET_COND(w, c) \
2324 Entry *e = g_new0(Entry, 1); \
2327 entry_list = g_slist_append(entry_list, e); \
2331 if (toolbar->get_btn)
2332 SET_WIDGET_COND(toolbar->get_btn,
2333 M_HAVE_ACCOUNT|M_UNLOCKED);
2335 if (toolbar->getall_btn) {
2336 SET_WIDGET_COND(toolbar->getall_btn,
2337 M_HAVE_ACCOUNT|M_UNLOCKED);
2339 if (toolbar->send_btn) {
2340 SET_WIDGET_COND(toolbar->send_btn,
2341 M_HAVE_QUEUED_MAILS);
2343 if (toolbar->compose_mail_btn) {
2344 SET_WIDGET_COND(toolbar->compose_mail_btn,
2347 if (toolbar->close_window_btn) {
2348 SET_WIDGET_COND(toolbar->close_window_btn,
2351 if (toolbar->open_mail_btn) {
2352 SET_WIDGET_COND(toolbar->open_mail_btn,
2353 M_TARGET_EXIST|M_SUMMARY_ISLIST);
2355 if (toolbar->reply_btn) {
2356 SET_WIDGET_COND(toolbar->reply_btn,
2357 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2359 if (toolbar->replyall_btn) {
2360 SET_WIDGET_COND(toolbar->replyall_btn,
2361 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2363 if (toolbar->replylist_btn) {
2364 SET_WIDGET_COND(toolbar->replylist_btn,
2365 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2367 if (toolbar->replysender_btn) {
2368 SET_WIDGET_COND(toolbar->replysender_btn,
2369 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2371 if (toolbar->fwd_btn) {
2372 SET_WIDGET_COND(toolbar->fwd_btn,
2373 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2376 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2377 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST|M_SUMMARY_ISLIST);
2379 SET_WIDGET_COND(toolbar->next_btn, 0);
2382 if (toolbar->trash_btn)
2383 SET_WIDGET_COND(toolbar->trash_btn,
2384 M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS);
2386 if (toolbar->delete_btn)
2387 SET_WIDGET_COND(toolbar->delete_btn,
2388 M_TARGET_EXIST|M_ALLOW_DELETE);
2390 if (toolbar->exec_btn)
2391 SET_WIDGET_COND(toolbar->exec_btn,
2394 if (toolbar->learn_spam_btn)
2395 SET_WIDGET_COND(toolbar->learn_spam_btn,
2396 M_TARGET_EXIST|M_CAN_LEARN_SPAM|M_SUMMARY_ISLIST);
2398 if (toolbar->cancel_inc_btn)
2399 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2402 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2403 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2405 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2408 #undef SET_WIDGET_COND
2410 state = main_window_get_current_state(mainwin);
2412 for (cur = entry_list; cur != NULL; cur = cur->next) {
2413 Entry *e = (Entry*) cur->data;
2415 if (e->widget != NULL) {
2416 sensitive = ((e->cond & state) == e->cond);
2417 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2421 while (entry_list != NULL) {
2422 Entry *e = (Entry*) entry_list->data;
2425 entry_list = g_slist_remove(entry_list, e);
2428 g_slist_free(entry_list);
2430 activate_compose_button(toolbar,
2431 prefs_common.toolbar_style,
2432 toolbar->compose_btn_type);
2436 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2438 Compose *compose = (Compose*)data;
2439 GSList *items = compose->toolbar->action_list;
2441 if (compose->toolbar->send_btn)
2442 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2443 if (compose->toolbar->sendl_btn)
2444 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2445 if (compose->toolbar->draft_btn )
2446 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2447 if (compose->toolbar->insert_btn )
2448 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2449 if (compose->toolbar->attach_btn)
2450 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2451 if (compose->toolbar->sig_btn)
2452 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2453 if (compose->toolbar->exteditor_btn)
2454 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2455 if (compose->toolbar->linewrap_current_btn)
2456 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2457 if (compose->toolbar->linewrap_all_btn)
2458 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2459 if (compose->toolbar->addrbook_btn)
2460 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2462 if (compose->toolbar->spellcheck_btn)
2463 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2465 for (; items != NULL; items = g_slist_next(items)) {
2466 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2467 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2472 * Initialize toolbar structure
2474 static void toolbar_init(Toolbar * toolbar)
2477 toolbar->toolbar = NULL;
2478 toolbar->folders_btn = NULL;
2479 toolbar->get_btn = NULL;
2480 toolbar->getall_btn = NULL;
2481 toolbar->send_btn = NULL;
2482 toolbar->compose_mail_btn = NULL;
2483 toolbar->compose_mail_icon = NULL;
2484 toolbar->compose_news_icon = NULL;
2485 toolbar->reply_btn = NULL;
2486 toolbar->replysender_btn = NULL;
2487 toolbar->replyall_btn = NULL;
2488 toolbar->replylist_btn = NULL;
2489 toolbar->fwd_btn = NULL;
2490 toolbar->trash_btn = NULL;
2491 toolbar->delete_btn = NULL;
2492 toolbar->prev_btn = NULL;
2493 toolbar->next_btn = NULL;
2494 toolbar->exec_btn = NULL;
2495 toolbar->open_mail_btn = NULL;
2496 toolbar->close_window_btn = NULL;
2497 /* compose buttons */
2498 toolbar->sendl_btn = NULL;
2499 toolbar->draft_btn = NULL;
2500 toolbar->insert_btn = NULL;
2501 toolbar->attach_btn = NULL;
2502 toolbar->sig_btn = NULL;
2503 toolbar->exteditor_btn = NULL;
2504 toolbar->linewrap_current_btn = NULL;
2505 toolbar->linewrap_all_btn = NULL;
2506 toolbar->addrbook_btn = NULL;
2508 toolbar->spellcheck_btn = NULL;
2511 toolbar_destroy(toolbar);
2516 static void toolbar_reply(gpointer data, guint action)
2518 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2519 MainWindow *mainwin;
2520 MessageView *msgview;
2521 GSList *msginfo_list = NULL;
2523 cm_return_if_fail(toolbar_item != NULL);
2525 switch (toolbar_item->type) {
2527 mainwin = (MainWindow*)toolbar_item->parent;
2528 msginfo_list = summary_get_selection(mainwin->summaryview);
2529 msgview = (MessageView*)mainwin->messageview;
2531 case TOOLBAR_MSGVIEW:
2532 msgview = (MessageView*)toolbar_item->parent;
2533 cm_return_if_fail(msgview != NULL);
2534 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2540 cm_return_if_fail(msgview != NULL);
2541 cm_return_if_fail(msginfo_list != NULL);
2542 compose_reply_from_messageview(msgview, msginfo_list, action);
2543 g_slist_free(msginfo_list);
2545 /* TODO: update reply state ion summaryview */
2549 /* exported functions */
2551 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2553 MainWindow *mainwin = (MainWindow*)data;
2555 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2558 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2560 MainWindow *mainwin = (MainWindow*)data;
2562 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2565 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2569 gboolean got_error = FALSE;
2570 gchar *errstr = NULL;
2572 if (prefs_common.work_offline)
2573 if (alertpanel(_("Offline warning"),
2574 _("You're working offline. Override?"),
2575 GTK_STOCK_NO, GTK_STOCK_YES,
2576 NULL) != G_ALERTALTERNATE)
2579 /* ask for confirmation before sending queued messages only
2580 in online mode and if there is at least one message queued
2581 in any of the folder queue
2583 if (prefs_common.confirm_send_queued_messages) {
2585 /* check if there's a queued message */
2586 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2587 Folder *folder = list->data;
2589 found = !procmsg_queue_is_empty(folder->queue);
2591 /* if necessary, ask for confirmation before sending */
2592 if (found && !prefs_common.work_offline) {
2593 if (alertpanel(_("Send queued messages"),
2594 _("Send all queued messages?"),
2595 GTK_STOCK_CANCEL, _("_Send"),
2596 NULL) != G_ALERTALTERNATE)
2601 for (list = folder_get_list(); list != NULL; list = list->next) {
2602 Folder *folder = list->data;
2604 if (folder->queue) {
2605 if (procmsg_send_queue(folder->queue,
2606 prefs_common.savemsg,
2613 alertpanel_error_log(_("Some errors occurred while "
2614 "sending queued messages."));
2616 alertpanel_error_log(_("Some errors occurred "
2617 "while sending queued messages:\n%s"), errstr);
2623 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2625 MainWindow *mainwin = (MainWindow*)data;
2626 PrefsAccount *ac = NULL;
2627 FolderItem *item = mainwin->summaryview->folder_item;
2632 ac = account_find_from_item(item);
2633 if (ac && ac->protocol != A_NNTP) {
2634 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2640 * CLAWS - use current account
2642 if (cur_account && (cur_account->protocol != A_NNTP)) {
2643 compose_new_with_folderitem(cur_account, item, NULL);
2648 * CLAWS - just get the first one
2650 list = account_get_list();
2651 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2652 ac = (PrefsAccount *) cur->data;
2653 if (ac->protocol != A_NNTP) {
2654 compose_new_with_folderitem(ac, item, NULL);
2660 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2662 MainWindow *mainwin = (MainWindow*)data;
2663 PrefsAccount * ac = NULL;
2667 if (mainwin->summaryview->folder_item) {
2668 ac = mainwin->summaryview->folder_item->folder->account;
2669 if (ac && ac->protocol == A_NNTP) {
2670 compose_new_with_folderitem(ac,
2671 mainwin->summaryview->folder_item, NULL);
2676 list = account_get_list();
2677 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2678 ac = (PrefsAccount *) cur->data;
2679 if (ac->protocol == A_NNTP) {
2680 compose_new_with_folderitem(ac,
2681 mainwin->summaryview->folder_item, NULL);