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[] = {
500 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
502 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
504 if (default_toolbar[i].action != A_SEPARATOR) {
507 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
508 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
511 toolbar_item->file = g_strdup(file);
512 toolbar_item->index = default_toolbar[i].action;
513 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
516 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
517 toolbar_item->index = A_SEPARATOR;
520 if (toolbar_item->index != -1) {
521 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
522 toolbar_config[TOOLBAR_MAIN].item_list =
523 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
528 static void toolbar_set_default_compose(void)
532 } default_toolbar[] = {
551 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
553 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
555 if (default_toolbar[i].action != A_SEPARATOR) {
558 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
559 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
561 toolbar_item->file = g_strdup(file);
562 toolbar_item->index = default_toolbar[i].action;
563 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
566 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
567 toolbar_item->index = A_SEPARATOR;
570 if (toolbar_item->index != -1) {
571 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
572 toolbar_config[TOOLBAR_COMPOSE].item_list =
573 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
578 static void toolbar_set_default_msgview(void)
582 } default_toolbar[] = {
601 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
603 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
605 if (default_toolbar[i].action != A_SEPARATOR) {
607 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
608 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
611 toolbar_item->file = g_strdup(file);
612 toolbar_item->index = default_toolbar[i].action;
613 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
616 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
617 toolbar_item->index = A_SEPARATOR;
620 if (toolbar_item->index != -1) {
621 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
622 toolbar_config[TOOLBAR_MSGVIEW].item_list =
623 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
628 void toolbar_set_default(ToolbarType source)
630 if (source == TOOLBAR_MAIN)
631 toolbar_set_default_main();
632 else if (source == TOOLBAR_COMPOSE)
633 toolbar_set_default_compose();
634 else if (source == TOOLBAR_MSGVIEW)
635 toolbar_set_default_msgview();
638 void toolbar_save_config_file(ToolbarType source)
643 gchar *fileSpec = NULL;
645 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
647 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
648 pfile = prefs_write_open(fileSpec);
651 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
654 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
657 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
658 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
660 if (toolbar_item->index != A_SEPARATOR) {
661 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
663 TOOLBAR_ICON_FILE, toolbar_item->file,
664 TOOLBAR_ICON_TEXT) < 0)
666 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
668 if (fprintf(fp, "\" %s=\"%s\"/>\n",
670 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
673 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
678 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
682 if (prefs_file_close (pfile) < 0 )
683 g_warning("failed to write toolbar configuration to file\n");
687 FILE_OP_ERROR(fileSpec, "fprintf");
689 prefs_file_close_revert (pfile);
691 g_warning("failed to open toolbar configuration file for writing\n");
694 void toolbar_read_config_file(ToolbarType source)
696 XMLFile *file = NULL;
697 gchar *fileSpec = NULL;
702 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
704 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
705 file = xml_open_file(fileSpec);
708 toolbar_clear_list(source);
712 || (xml_get_dtd(file))
713 || (xml_parse_next_tag(file))
714 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
715 xml_close_file(file);
719 attr = xml_get_current_tag_attr(file);
726 if (xml_parse_next_tag(file))
729 /* Get next tag (icon, icon_text or icon_action) */
730 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
731 toolbar_parse_item(file, source);
732 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
733 ToolbarItem *item = g_new0(ToolbarItem, 1);
735 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
736 item->index = A_SEPARATOR;
737 toolbar_config[source].item_list =
738 g_slist_append(toolbar_config[source].item_list, item);
742 xml_close_file(file);
745 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
747 if (source == TOOLBAR_MAIN)
748 toolbar_set_default(TOOLBAR_MAIN);
749 else if (source == TOOLBAR_COMPOSE)
750 toolbar_set_default(TOOLBAR_COMPOSE);
751 else if (source == TOOLBAR_MSGVIEW)
752 toolbar_set_default(TOOLBAR_MSGVIEW);
754 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
758 toolbar_save_config_file(source);
763 * clears list of toolbar items read from configuration files
765 void toolbar_clear_list(ToolbarType source)
767 while (toolbar_config[source].item_list != NULL) {
768 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
770 toolbar_config[source].item_list =
771 g_slist_remove(toolbar_config[source].item_list, item);
777 g_slist_free(toolbar_config[source].item_list);
782 * return list of Toolbar items
784 GSList *toolbar_get_list(ToolbarType source)
788 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
789 list = toolbar_config[source].item_list;
794 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
796 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
798 toolbar_item->file = g_strdup(t_item->file);
799 toolbar_item->text = g_strdup(t_item->text);
800 toolbar_item->index = t_item->index;
802 toolbar_config[source].item_list =
803 g_slist_append(toolbar_config[source].item_list,
807 static void toolbar_action_execute(GtkWidget *widget,
813 gchar *action, *action_p;
814 gboolean found = FALSE;
817 for (cur = action_list; cur != NULL; cur = cur->next) {
818 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
820 if (widget == act->widget) {
822 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
823 action = g_strdup((gchar*)lop->data);
825 action_p = strstr(action, ": ");
827 if (g_utf8_collate(act->name, action) == 0) {
841 actions_execute(data, i, widget, source);
843 g_warning ("Error: did not find Claws Action to execute");
846 #if !(GTK_CHECK_VERSION(2,12,0))
847 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
848 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(widget), GTK_TOOLTIPS(toolbar_tips), \
852 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
853 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), tip); \
857 #if !(GTK_CHECK_VERSION(2,12,0))
858 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
859 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(widget), GTK_TOOLTIPS(toolbar_tips), \
863 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
864 gtk_menu_tool_button_set_arrow_tooltip_text(GTK_MENU_TOOL_BUTTON(widget), tip); \
868 static void activate_compose_button (Toolbar *toolbar,
870 ComposeButtonType type)
872 #if !(GTK_CHECK_VERSION(2,12,0))
873 GtkTooltips *toolbar_tips = toolbar->tooltips;
875 if ((!toolbar->compose_mail_btn))
878 if (type == COMPOSEBUTTON_NEWS) {
879 gtk_tool_button_set_icon_widget(
880 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
881 toolbar->compose_news_icon);
883 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose News message"));
885 gtk_widget_show(toolbar->compose_news_icon);
887 gtk_tool_button_set_icon_widget(
888 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
889 toolbar->compose_mail_icon);
891 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose Email"));
893 gtk_widget_show(toolbar->compose_mail_icon);
895 toolbar->compose_btn_type = type;
898 void toolbar_set_compose_button(Toolbar *toolbar,
899 ComposeButtonType compose_btn_type)
901 if (toolbar->compose_btn_type != compose_btn_type)
902 activate_compose_button(toolbar,
903 prefs_common.toolbar_style,
907 static void activate_learn_button (Toolbar *toolbar,
909 LearnButtonType type)
911 #if !(GTK_CHECK_VERSION(2,12,0))
912 GtkTooltips *toolbar_tips = toolbar->tooltips;
914 if ((!toolbar->learn_spam_btn))
917 if (type == LEARN_SPAM) {
918 gtk_tool_button_set_icon_widget(
919 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
920 toolbar->learn_spam_icon);
921 gtk_tool_button_set_label(
922 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
925 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn spam"));
927 gtk_widget_show(toolbar->learn_spam_icon);
929 gtk_tool_button_set_icon_widget(
930 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
931 toolbar->learn_ham_icon);
932 gtk_tool_button_set_label(
933 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
936 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn ham"));
938 gtk_widget_show(toolbar->learn_ham_icon);
940 toolbar->learn_btn_type = type;
943 void toolbar_set_learn_button(Toolbar *toolbar,
944 LearnButtonType learn_btn_type)
946 if (toolbar->learn_btn_type != learn_btn_type)
947 activate_learn_button(toolbar,
948 prefs_common.toolbar_style,
952 void toolbar_toggle(guint action, gpointer data)
954 MainWindow *mainwin = (MainWindow*)data;
958 cm_return_if_fail(mainwin != NULL);
960 toolbar_style(TOOLBAR_MAIN, action, mainwin);
962 list = compose_get_compose_list();
963 for (cur = list; cur != NULL; cur = cur->next) {
964 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
966 list = messageview_get_msgview_list();
967 for (cur = list; cur != NULL; cur = cur->next) {
968 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
973 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
975 switch ((ToolbarStyle)action) {
977 gtk_widget_hide(handlebox_wid);
980 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
984 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
988 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
991 case TOOLBAR_BOTH_HORIZ:
992 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
993 GTK_TOOLBAR_BOTH_HORIZ);
999 prefs_common.toolbar_style = (ToolbarStyle)action;
1000 gtk_widget_set_size_request(handlebox_wid, 1, -1);
1002 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1003 gtk_widget_show(handlebox_wid);
1004 gtk_widget_queue_resize(handlebox_wid);
1008 * Change the style of toolbar
1010 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1012 GtkWidget *handlebox_wid;
1013 GtkWidget *toolbar_wid;
1014 MainWindow *mainwin = (MainWindow*)data;
1015 Compose *compose = (Compose*)data;
1016 MessageView *msgview = (MessageView*)data;
1018 cm_return_if_fail(data != NULL);
1022 handlebox_wid = mainwin->handlebox;
1023 toolbar_wid = mainwin->toolbar->toolbar;
1025 case TOOLBAR_COMPOSE:
1026 handlebox_wid = compose->handlebox;
1027 toolbar_wid = compose->toolbar->toolbar;
1029 case TOOLBAR_MSGVIEW:
1030 handlebox_wid = msgview->handlebox;
1031 toolbar_wid = msgview->toolbar->toolbar;
1037 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1040 /* Toolbar handling */
1041 static void toolbar_inc_cb(GtkWidget *widget,
1044 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1045 MainWindow *mainwin;
1047 cm_return_if_fail(toolbar_item != NULL);
1049 switch (toolbar_item->type) {
1051 mainwin = (MainWindow*)toolbar_item->parent;
1052 inc_mail_cb(mainwin, 0, NULL);
1059 static void toolbar_inc_all_cb(GtkWidget *widget,
1062 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1063 MainWindow *mainwin;
1065 cm_return_if_fail(toolbar_item != NULL);
1067 switch (toolbar_item->type) {
1069 mainwin = (MainWindow*)toolbar_item->parent;
1070 inc_all_account_mail_cb(mainwin, 0, NULL);
1077 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
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 send_queue_cb(mainwin, 0, NULL);
1094 static void toolbar_exec_cb(GtkWidget *widget,
1097 MainWindow *mainwin = get_mainwin(data);
1099 cm_return_if_fail(mainwin != NULL);
1100 summary_execute(mainwin->summaryview);
1104 * Delete current/selected(s) message(s)
1106 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1108 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1109 MainWindow *mainwin;
1111 cm_return_if_fail(toolbar_item != NULL);
1112 cm_return_if_fail(toolbar_item->parent);
1114 switch (toolbar_item->type) {
1115 case TOOLBAR_MSGVIEW:
1116 messageview_delete((MessageView *)toolbar_item->parent);
1119 mainwin = (MainWindow *)toolbar_item->parent;
1120 summary_delete_trash(mainwin->summaryview);
1123 debug_print("toolbar event not supported\n");
1129 * Delete current/selected(s) message(s)
1131 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1133 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1134 MainWindow *mainwin;
1136 cm_return_if_fail(toolbar_item != NULL);
1137 cm_return_if_fail(toolbar_item->parent);
1139 switch (toolbar_item->type) {
1140 case TOOLBAR_MSGVIEW:
1141 messageview_delete((MessageView *)toolbar_item->parent);
1144 mainwin = (MainWindow *)toolbar_item->parent;
1145 summary_delete(mainwin->summaryview);
1148 debug_print("toolbar event not supported\n");
1155 * Compose new message
1157 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1159 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1160 MainWindow *mainwin;
1161 MessageView *msgview;
1163 cm_return_if_fail(toolbar_item != NULL);
1165 switch (toolbar_item->type) {
1167 mainwin = (MainWindow*)toolbar_item->parent;
1168 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1169 compose_news_cb(mainwin, 0, NULL);
1171 compose_mail_cb(mainwin, 0, NULL);
1173 case TOOLBAR_MSGVIEW:
1174 msgview = (MessageView*)toolbar_item->parent;
1175 compose_new_with_folderitem(NULL,
1176 msgview->msginfo->folder, NULL);
1179 debug_print("toolbar event not supported\n");
1183 static void toolbar_learn(gpointer data, guint as_spam)
1185 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1186 MainWindow *mainwin;
1187 MessageView *msgview;
1189 cm_return_if_fail(toolbar_item != NULL);
1191 switch (toolbar_item->type) {
1193 mainwin = (MainWindow*)toolbar_item->parent;
1195 mainwindow_learn(mainwin, TRUE);
1197 mainwindow_learn(mainwin, FALSE);
1199 case TOOLBAR_MSGVIEW:
1200 msgview = (MessageView*)toolbar_item->parent;
1202 messageview_learn(msgview, TRUE);
1204 messageview_learn(msgview, FALSE);
1207 debug_print("toolbar event not supported\n");
1211 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1213 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1214 MainWindow *mainwin;
1215 MessageView *msgview;
1217 cm_return_if_fail(toolbar_item != NULL);
1219 switch (toolbar_item->type) {
1221 mainwin = (MainWindow*)toolbar_item->parent;
1222 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1223 mainwindow_learn(mainwin, TRUE);
1225 mainwindow_learn(mainwin, FALSE);
1227 case TOOLBAR_MSGVIEW:
1228 msgview = (MessageView*)toolbar_item->parent;
1229 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1230 messageview_learn(msgview, TRUE);
1232 messageview_learn(msgview, FALSE);
1235 debug_print("toolbar event not supported\n");
1243 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1245 toolbar_reply(data, (prefs_common.reply_with_quote ?
1246 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE));
1251 * Reply message to Sender and All recipients
1253 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1256 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1257 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE));
1262 * Reply to Mailing List
1264 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1267 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1268 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE));
1273 * Reply to sender of message
1275 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1278 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1279 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE));
1285 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1287 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1290 cm_return_if_fail(toolbar_item != NULL);
1292 switch (toolbar_item->type) {
1294 case TOOLBAR_MSGVIEW:
1297 case TOOLBAR_COMPOSE:
1298 compose = (Compose *)toolbar_item->parent;
1303 addressbook_open(compose);
1308 * Forward current/selected(s) message(s)
1310 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1312 toolbar_reply(data, (COMPOSE_FORWARD));
1316 * Goto Prev Unread Message
1318 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1320 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1321 MainWindow *mainwin;
1322 MessageView *msgview;
1324 cm_return_if_fail(toolbar_item != NULL);
1326 switch (toolbar_item->type) {
1328 mainwin = (MainWindow*)toolbar_item->parent;
1329 summary_select_prev_unread(mainwin->summaryview);
1332 case TOOLBAR_MSGVIEW:
1333 msgview = (MessageView*)toolbar_item->parent;
1334 msgview->updating = TRUE;
1335 summary_select_prev_unread(msgview->mainwin->summaryview);
1336 msgview->updating = FALSE;
1338 if (msgview->deferred_destroy) {
1339 debug_print("messageview got away!\n");
1340 messageview_destroy(msgview);
1344 /* Now we need to update the messageview window */
1345 if (msgview->mainwin->summaryview->selected) {
1346 #ifndef GENERIC_UMPC
1347 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1350 messageview_show(msgview, msginfo,
1351 msgview->all_headers);
1354 gtk_widget_destroy(msgview->window);
1358 debug_print("toolbar event not supported\n");
1363 * Goto Next Unread Message
1365 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1367 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1368 MainWindow *mainwin;
1369 MessageView *msgview;
1371 cm_return_if_fail(toolbar_item != NULL);
1373 switch (toolbar_item->type) {
1375 mainwin = (MainWindow*)toolbar_item->parent;
1376 summary_select_next_unread(mainwin->summaryview);
1379 case TOOLBAR_MSGVIEW:
1380 msgview = (MessageView*)toolbar_item->parent;
1381 msgview->updating = TRUE;
1382 summary_select_next_unread(msgview->mainwin->summaryview);
1383 msgview->updating = FALSE;
1385 if (msgview->deferred_destroy) {
1386 debug_print("messageview got away!\n");
1387 messageview_destroy(msgview);
1391 /* Now we need to update the messageview window */
1392 if (msgview->mainwin->summaryview->selected) {
1393 #ifndef GENERIC_UMPC
1394 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1397 messageview_show(msgview, msginfo,
1398 msgview->all_headers);
1401 gtk_widget_destroy(msgview->window);
1405 debug_print("toolbar event not supported\n");
1409 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1411 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1412 MainWindow *mainwin;
1414 cm_return_if_fail(toolbar_item != NULL);
1416 switch (toolbar_item->type) {
1418 mainwin = (MainWindow *) toolbar_item->parent;
1419 summary_toggle_ignore_thread(mainwin->summaryview);
1421 case TOOLBAR_MSGVIEW:
1422 /* TODO: see toolbar_next_unread_cb() if you need
1423 * this in the message view */
1426 debug_print("toolbar event not supported\n");
1431 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1433 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1434 MainWindow *mainwin;
1436 cm_return_if_fail(toolbar_item != NULL);
1438 switch (toolbar_item->type) {
1440 mainwin = (MainWindow *) toolbar_item->parent;
1441 summary_toggle_watch_thread(mainwin->summaryview);
1443 case TOOLBAR_MSGVIEW:
1444 /* TODO: see toolbar_next_unread_cb() if you need
1445 * this in the message view */
1448 debug_print("toolbar event not supported\n");
1453 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1455 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1457 cm_return_if_fail(toolbar_item != NULL);
1463 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1465 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1466 MainWindow *mainwin;
1468 cm_return_if_fail(toolbar_item != NULL);
1470 switch (toolbar_item->type) {
1472 mainwin = (MainWindow *) toolbar_item->parent;
1473 summary_print(mainwin->summaryview);
1475 case TOOLBAR_MSGVIEW:
1476 /* TODO: see toolbar_next_unread_cb() if you need
1477 * this in the message view */
1480 debug_print("toolbar event not supported\n");
1485 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1487 compose_toolbar_cb(A_SEND, data);
1490 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1492 compose_toolbar_cb(A_SENDL, data);
1495 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1497 compose_toolbar_cb(A_DRAFT, data);
1500 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1502 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1503 MainWindow *mainwin;
1504 MessageView *messageview;
1507 cm_return_if_fail(toolbar_item != NULL);
1509 switch (toolbar_item->type) {
1511 mainwin = (MainWindow *) toolbar_item->parent;
1512 app_will_exit(NULL, mainwin);
1514 case TOOLBAR_MSGVIEW:
1515 messageview = (MessageView *)toolbar_item->parent;
1516 messageview_destroy(messageview);
1518 case TOOLBAR_COMPOSE:
1519 compose = (Compose *)toolbar_item->parent;
1520 compose_close_toolbar(compose);
1525 static void toolbar_preferences_cb(GtkWidget *widget, gpointer data)
1530 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1532 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1533 MainWindow *mainwin;
1535 cm_return_if_fail(toolbar_item != NULL);
1537 switch (toolbar_item->type) {
1539 mainwin = (MainWindow *) toolbar_item->parent;
1540 summary_open_row(NULL, mainwin->summaryview);
1542 case TOOLBAR_MSGVIEW:
1543 debug_print("toolbar event not supported\n");
1545 case TOOLBAR_COMPOSE:
1546 debug_print("toolbar event not supported\n");
1551 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1553 compose_toolbar_cb(A_INSERT, data);
1556 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1558 compose_toolbar_cb(A_ATTACH, data);
1561 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1563 compose_toolbar_cb(A_SIG, data);
1566 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1568 compose_toolbar_cb(A_EXTEDITOR, data);
1571 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1573 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1576 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1578 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1582 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1584 compose_toolbar_cb(A_CHECK_SPELLING, data);
1588 * Execute actions from toolbar
1590 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1592 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1593 GSList *action_list;
1594 MainWindow *mainwin;
1596 MessageView *msgview;
1597 gpointer parent = toolbar_item->parent;
1599 cm_return_if_fail(toolbar_item != NULL);
1601 switch (toolbar_item->type) {
1603 mainwin = (MainWindow*)parent;
1604 action_list = mainwin->toolbar->action_list;
1606 case TOOLBAR_COMPOSE:
1607 compose = (Compose*)parent;
1608 action_list = compose->toolbar->action_list;
1610 case TOOLBAR_MSGVIEW:
1611 msgview = (MessageView*)parent;
1612 action_list = msgview->toolbar->action_list;
1615 debug_print("toolbar event not supported\n");
1618 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1621 static MainWindow *get_mainwin(gpointer data)
1623 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1624 MainWindow *mainwin = NULL;
1625 MessageView *msgview;
1627 cm_return_val_if_fail(toolbar_item != NULL, NULL);
1629 switch(toolbar_item->type) {
1631 mainwin = (MainWindow*)toolbar_item->parent;
1633 case TOOLBAR_MSGVIEW:
1634 msgview = (MessageView*)toolbar_item->parent;
1635 mainwin = (MainWindow*)msgview->mainwin;
1644 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1646 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1647 MainWindow *mainwin = NULL;
1648 switch(toolbar_item->type) {
1650 mainwin = (MainWindow*)toolbar_item->parent;
1653 g_warning("wrong toolbar type\n");
1657 if (!mainwin->in_folder) {
1658 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1660 folderview_select(mainwin->folderview, item);
1663 gtk_widget_grab_focus(mainwin->folderview->ctree);
1664 mainwindow_exit_folder(mainwin);
1668 static void toolbar_buttons_cb(GtkWidget *widget,
1675 void (*func)(GtkWidget *widget, gpointer data);
1677 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1678 { A_RECEIVE_CUR, toolbar_inc_cb },
1679 { A_SEND_QUEUED, toolbar_send_queued_cb },
1680 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1681 { A_COMPOSE_NEWS, toolbar_compose_cb },
1682 { A_REPLY_MESSAGE, toolbar_reply_cb },
1683 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1684 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1685 { A_REPLY_ML, toolbar_reply_to_list_cb },
1686 { A_FORWARD, toolbar_forward_cb },
1687 { A_TRASH, toolbar_trash_cb },
1688 { A_DELETE_REAL, toolbar_delete_cb },
1689 { A_EXECUTE, toolbar_exec_cb },
1690 { A_GOTO_PREV, toolbar_prev_unread_cb },
1691 { A_GOTO_NEXT, toolbar_next_unread_cb },
1692 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1693 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1694 { A_PRINT, toolbar_print_cb },
1695 { A_LEARN_SPAM, toolbar_learn_cb },
1696 { A_GO_FOLDERS, toolbar_go_folders_cb },
1698 { A_SEND, toolbar_send_cb },
1699 { A_SENDL, toolbar_send_later_cb },
1700 { A_DRAFT, toolbar_draft_cb },
1701 { A_OPEN_MAIL, toolbar_open_mail_cb },
1702 { A_CLOSE, toolbar_close_cb },
1703 { A_PREFERENCES, toolbar_preferences_cb },
1704 { A_INSERT, toolbar_insert_cb },
1705 { A_ATTACH, toolbar_attach_cb },
1706 { A_SIG, toolbar_sig_cb },
1707 { A_EXTEDITOR, toolbar_ext_editor_cb },
1708 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1709 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1710 { A_ADDRBOOK, toolbar_addrbook_cb },
1712 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1714 { A_CLAWS_ACTIONS, toolbar_actions_execute_cb },
1715 { A_CANCEL_INC, toolbar_cancel_inc_cb }
1718 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1720 for (i = 0; i < num_items; i++) {
1721 if (callbacks[i].index == item->index) {
1722 callbacks[i].func(widget, item);
1727 #ifndef GENERIC_UMPC
1728 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1729 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1730 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1731 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1732 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1733 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1734 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1738 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1739 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1740 GList *gchild = NULL; \
1741 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1742 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1743 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1744 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1745 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1746 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1748 CLAWS_SET_ARROW_TIP(GTK_MENU_TOOL_BUTTON(item), menutip); \
1749 child = gtk_bin_get_child(GTK_BIN(item)); \
1750 gchild = gtk_container_get_children( \
1751 GTK_CONTAINER(child)); \
1752 btn = (GtkWidget *)gchild->data; \
1753 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1754 g_list_free(gchild); \
1755 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1756 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1757 g_list_free(gchild); \
1760 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1761 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1762 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1763 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1764 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1765 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1768 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1769 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1770 GList *gchild = NULL; \
1771 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1772 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1773 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1774 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1775 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1776 child = gtk_bin_get_child(GTK_BIN(item)); \
1777 gchild = gtk_container_get_children( \
1778 GTK_CONTAINER(child)); \
1779 btn = (GtkWidget *)gchild->data; \
1780 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1781 g_list_free(gchild); \
1782 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1783 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1784 g_list_free(gchild); \
1788 #define ADD_MENU_ITEM(name,cb,data) { \
1789 item = gtk_menu_item_new_with_mnemonic(name); \
1790 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); \
1791 g_signal_connect(G_OBJECT(item), "activate", \
1794 g_object_set_data(G_OBJECT(item), "int-value", GINT_TO_POINTER(data)); \
1795 gtk_widget_show(item); \
1798 static void toolbar_reply_menu_cb(GtkWidget *widget, gpointer data)
1800 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1801 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1803 toolbar_reply(toolbar_item, GPOINTER_TO_INT(int_value));
1806 static void toolbar_learn_menu_cb(GtkWidget *widget, gpointer data)
1808 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1809 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1811 toolbar_learn(toolbar_item, GPOINTER_TO_INT(int_value));
1815 * Create a new toolbar with specified type
1816 * if a callback list is passed it will be used before the
1817 * common callback list
1819 Toolbar *toolbar_create(ToolbarType type,
1820 GtkWidget *container,
1823 ToolbarItem *toolbar_item;
1826 GtkWidget *icon_wid = NULL;
1827 GtkWidget *icon_news;
1828 GtkWidget *icon_ham;
1830 ToolbarClawsActions *action_item;
1832 GSList *toolbar_list;
1833 Toolbar *toolbar_data;
1835 #ifndef GENERIC_UMPC
1836 #if !(GTK_CHECK_VERSION(2,12,0))
1837 GtkTooltips *toolbar_tips = gtk_tooltips_new();
1840 toolbar_read_config_file(type);
1841 toolbar_list = toolbar_get_list(type);
1843 toolbar_data = g_new0(Toolbar, 1);
1845 toolbar = gtk_toolbar_new();
1847 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1848 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1849 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1851 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1853 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1854 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1858 toolbar_item = g_new0(ToolbarItem, 1);
1859 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1860 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1861 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1862 toolbar_item->parent = data;
1863 toolbar_item->type = type;
1865 /* collect toolbar items in list to keep track */
1866 toolbar_data->item_list =
1867 g_slist_append(toolbar_data->item_list,
1869 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1871 switch (toolbar_item->index) {
1874 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1875 toolbar_data->folders_btn = item;
1878 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1879 _("Receive Mail on all Accounts"),
1880 _("Receive Mail on selected Account"));
1881 toolbar_data->getall_btn = item;
1884 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail on current Account"));
1885 toolbar_data->get_btn = item;
1888 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1889 toolbar_data->send_btn = item;
1892 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1893 toolbar_data->close_window_btn = item;
1896 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open preferences"));
1897 toolbar_data->preferences_btn = item;
1900 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1901 toolbar_data->open_mail_btn = item;
1903 case A_COMPOSE_EMAIL:
1904 #ifndef GENERIC_UMPC
1905 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1907 _("Compose with selected Account"));
1908 toolbar_data->compose_mail_btn = item;
1909 toolbar_data->compose_mail_icon = icon_wid;
1910 g_object_ref(toolbar_data->compose_mail_icon);
1912 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1913 toolbar_data->compose_news_icon = icon_news;
1914 g_object_ref(toolbar_data->compose_news_icon);
1916 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1917 _("Compose Email"));
1918 toolbar_data->compose_mail_btn = item;
1919 toolbar_data->compose_mail_icon = icon_wid;
1921 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1922 toolbar_data->compose_news_icon = icon_news;
1926 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1929 toolbar_data->learn_spam_btn = item;
1930 toolbar_data->learn_spam_icon = icon_wid;
1931 g_object_ref(toolbar_data->learn_spam_icon);
1933 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1934 toolbar_data->learn_ham_icon = icon_ham;
1935 g_object_ref(toolbar_data->learn_ham_icon);
1937 menu = gtk_menu_new();
1938 ADD_MENU_ITEM(_("Learn as _Spam"), toolbar_learn_menu_cb, TRUE);
1939 ADD_MENU_ITEM(_("Learn as _Ham"), toolbar_learn_menu_cb, FALSE);
1940 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->learn_spam_btn), menu);
1942 case A_REPLY_MESSAGE:
1943 #ifndef GENERIC_UMPC
1944 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1945 _("Reply to Message"),
1946 _("Reply to Message options"));
1947 toolbar_data->reply_btn = item;
1949 menu = gtk_menu_new();
1950 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITH_QUOTE);
1951 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITHOUT_QUOTE);
1952 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->reply_btn), menu);
1954 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1955 _("Reply to Message"));
1956 toolbar_data->reply_btn = item;
1959 case A_REPLY_SENDER:
1960 #ifndef GENERIC_UMPC
1961 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1962 _("Reply to Sender"),
1963 _("Reply to Sender options"));
1964 toolbar_data->replysender_btn = item;
1966 menu = gtk_menu_new();
1967 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE);
1968 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1969 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replysender_btn), menu);
1971 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1972 _("Reply to Sender"));
1973 toolbar_data->replysender_btn = item;
1977 #ifndef GENERIC_UMPC
1978 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1980 _("Reply to All options"));
1981 toolbar_data->replyall_btn = item;
1983 menu = gtk_menu_new();
1984 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE);
1985 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1986 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replyall_btn), menu);
1988 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1990 toolbar_data->replyall_btn = item;
1994 #ifndef GENERIC_UMPC
1995 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1996 _("Reply to Mailing-list"),
1997 _("Reply to Mailing-list options"));
1998 toolbar_data->replylist_btn = item;
2000 menu = gtk_menu_new();
2001 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE);
2002 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
2003 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replylist_btn), menu);
2005 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2006 _("Reply to Mailing-list"));
2007 toolbar_data->replylist_btn = item;
2011 #ifndef GENERIC_UMPC
2012 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2013 _("Forward Message"),
2014 _("Forward Message options"));
2015 toolbar_data->fwd_btn = item;
2017 menu = gtk_menu_new();
2018 ADD_MENU_ITEM(_("_Forward"), toolbar_reply_menu_cb, COMPOSE_FORWARD_INLINE);
2019 ADD_MENU_ITEM(_("For_ward as attachment"), toolbar_reply_menu_cb, COMPOSE_FORWARD_AS_ATTACH);
2020 ADD_MENU_ITEM(_("Redirec_t"), toolbar_reply_menu_cb, COMPOSE_REDIRECT);
2021 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->fwd_btn), menu);
2023 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2024 _("Forward Message"));
2025 toolbar_data->fwd_btn = item;
2029 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
2030 toolbar_data->trash_btn = item;
2033 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
2034 toolbar_data->delete_btn = item;
2037 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
2038 toolbar_data->exec_btn = item;
2041 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
2042 toolbar_data->prev_btn = item;
2045 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
2046 toolbar_data->next_btn = item;
2049 /* Compose Toolbar */
2051 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2052 toolbar_data->send_btn = item;
2055 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2056 toolbar_data->sendl_btn = item;
2059 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2060 toolbar_data->draft_btn = item;
2063 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2064 toolbar_data->insert_btn = item;
2067 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2068 toolbar_data->attach_btn = item;
2071 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2072 toolbar_data->sig_btn = item;
2075 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2076 toolbar_data->exteditor_btn = item;
2078 case A_LINEWRAP_CURRENT:
2079 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2080 toolbar_data->linewrap_current_btn = item;
2082 case A_LINEWRAP_ALL:
2083 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2084 toolbar_data->linewrap_all_btn = item;
2087 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2088 toolbar_data->addrbook_btn = item;
2091 case A_CHECK_SPELLING:
2092 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2093 toolbar_data->spellcheck_btn = item;
2097 case A_CLAWS_ACTIONS:
2098 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2099 action_item = g_new0(ToolbarClawsActions, 1);
2100 action_item->widget = item;
2101 action_item->name = g_strdup(toolbar_item->text);
2103 toolbar_data->action_list =
2104 g_slist_append(toolbar_data->action_list,
2108 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2109 toolbar_data->cancel_inc_btn = item;
2112 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2113 toolbar_ret_descr_from_val(toolbar_item->index));
2114 /* find and set the tool tip text */
2119 toolbar_data->toolbar = toolbar;
2120 #ifndef GENERIC_UMPC
2121 #if !(GTK_CHECK_VERSION(2,12,0))
2122 toolbar_data->tooltips = toolbar_tips;
2125 gtk_widget_show_all(toolbar);
2127 if (type == TOOLBAR_MAIN) {
2129 MainWindow *mainwin = mainwindow_get_mainwindow();
2130 GtkWidget *progressbar = gtk_progress_bar_new();
2131 item = GTK_WIDGET(gtk_tool_item_new());
2132 gtk_container_add (GTK_CONTAINER (item), progressbar);
2133 gtk_widget_show(item);
2134 gtk_widget_show(progressbar);
2135 gtk_widget_set_size_request(progressbar, 70, -1);
2136 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2137 mainwin->progressbar = progressbar;
2139 activate_compose_button(toolbar_data,
2140 prefs_common.toolbar_style,
2141 toolbar_data->compose_btn_type);
2143 if (type != TOOLBAR_COMPOSE)
2144 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2148 gtk_container_add(GTK_CONTAINER(container), toolbar);
2149 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2151 if ( GTK_IS_WINDOW(container) ) {
2152 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
2153 gtk_widget_show_all (container);
2155 gtk_container_add(GTK_CONTAINER(container), toolbar);
2156 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2159 return toolbar_data;
2163 * Free toolbar structures
2165 void toolbar_destroy(Toolbar * toolbar) {
2167 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2168 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2171 void toolbar_update(ToolbarType type, gpointer data)
2173 Toolbar *toolbar_data;
2174 GtkWidget *handlebox;
2175 MainWindow *mainwin = (MainWindow*)data;
2176 Compose *compose = (Compose*)data;
2177 MessageView *msgview = (MessageView*)data;
2179 #ifndef GENERIC_UMPC
2182 toolbar_data = mainwin->toolbar;
2183 handlebox = mainwin->handlebox;
2185 case TOOLBAR_COMPOSE:
2186 toolbar_data = compose->toolbar;
2187 handlebox = compose->handlebox;
2189 case TOOLBAR_MSGVIEW:
2190 toolbar_data = msgview->toolbar;
2191 handlebox = msgview->handlebox;
2197 gtk_container_remove(GTK_CONTAINER(handlebox),
2198 GTK_WIDGET(toolbar_data->toolbar));
2200 toolbar_init(toolbar_data);
2201 toolbar_data = toolbar_create(type, handlebox, data);
2205 toolbar_data = mainwin->toolbar;
2206 handlebox = mainwin->window;
2208 case TOOLBAR_COMPOSE:
2209 toolbar_data = compose->toolbar;
2210 handlebox = compose->window;
2212 case TOOLBAR_MSGVIEW:
2213 toolbar_data = msgview->toolbar;
2214 handlebox = msgview->window;
2220 hildon_window_remove_toolbar(HILDON_WINDOW(handlebox), GTK_TOOLBAR(toolbar_data->toolbar));
2222 toolbar_init(toolbar_data);
2223 toolbar_data = toolbar_create(type, handlebox, data);
2228 mainwin->toolbar = toolbar_data;
2230 case TOOLBAR_COMPOSE:
2231 compose->toolbar = toolbar_data;
2233 case TOOLBAR_MSGVIEW:
2234 msgview->toolbar = toolbar_data;
2238 toolbar_style(type, prefs_common.toolbar_style, data);
2240 if (type == TOOLBAR_MAIN) {
2241 toolbar_main_set_sensitive((MainWindow*)data);
2242 account_set_menu_only_toolbar();
2246 #if !GTK_CHECK_VERSION(2,14,0)
2247 /* Work around http://bugzilla.gnome.org/show_bug.cgi?id=56070 */
2248 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2249 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2250 if (GTK_IS_BUTTON(widget)) \
2251 in_btn1 = GTK_BUTTON(widget)->in_button; \
2252 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2253 GtkWidget *child = gtk_bin_get_child( \
2255 GList *gchild = gtk_container_get_children( \
2256 GTK_CONTAINER(child)); \
2257 GtkWidget *btn = (GtkWidget *)gchild->data; \
2258 GtkWidget *arr = (GtkWidget *) \
2259 (gchild->next?gchild->next->data:NULL); \
2260 g_list_free(gchild); \
2261 if (GTK_IS_BUTTON(btn)) \
2262 in_btn1 = GTK_BUTTON(btn)->in_button; \
2263 if (GTK_IS_BUTTON(arr)) \
2264 in_btn2 = GTK_BUTTON(arr)->in_button; \
2266 else if (GTK_IS_TOOL_ITEM(widget)) { \
2267 GtkWidget *child = gtk_bin_get_child( \
2269 if (GTK_IS_BUTTON(child)) \
2270 in_btn1 = GTK_BUTTON(child)->in_button; \
2272 gtk_widget_set_sensitive(widget, sensitive); \
2273 if (GTK_IS_BUTTON(widget)) \
2274 GTK_BUTTON(widget)->in_button = in_btn1; \
2275 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2276 GtkWidget *child = gtk_bin_get_child( \
2278 GList *gchild = gtk_container_get_children( \
2279 GTK_CONTAINER(child)); \
2280 GtkWidget *btn = (GtkWidget *)gchild->data; \
2281 GtkWidget *arr = (GtkWidget *) \
2282 (gchild->next?gchild->next->data:NULL); \
2283 g_list_free(gchild); \
2284 if (GTK_IS_BUTTON(btn)) \
2285 GTK_BUTTON(btn)->in_button = in_btn1; \
2286 if (GTK_IS_BUTTON(arr)) \
2287 GTK_BUTTON(arr)->in_button = in_btn2; \
2289 else if (GTK_IS_TOOL_ITEM(widget)) { \
2290 GtkWidget *child = gtk_bin_get_child( \
2292 if (GTK_IS_BUTTON(child)) \
2293 GTK_BUTTON(child)->in_button = in_btn1; \
2297 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2298 gtk_widget_set_sensitive(widget, sensitive); \
2302 void toolbar_main_set_sensitive(gpointer data)
2304 SensitiveCond state;
2306 MainWindow *mainwin = (MainWindow*)data;
2307 Toolbar *toolbar = mainwin->toolbar;
2309 GSList *entry_list = NULL;
2311 typedef struct _Entry Entry;
2318 #define SET_WIDGET_COND(w, c) \
2320 Entry *e = g_new0(Entry, 1); \
2323 entry_list = g_slist_append(entry_list, e); \
2327 if (toolbar->get_btn)
2328 SET_WIDGET_COND(toolbar->get_btn,
2329 M_HAVE_ACCOUNT|M_UNLOCKED);
2331 if (toolbar->getall_btn) {
2332 SET_WIDGET_COND(toolbar->getall_btn,
2333 M_HAVE_ACCOUNT|M_UNLOCKED);
2335 if (toolbar->send_btn) {
2336 SET_WIDGET_COND(toolbar->send_btn,
2337 M_HAVE_QUEUED_MAILS);
2339 if (toolbar->compose_mail_btn) {
2340 SET_WIDGET_COND(toolbar->compose_mail_btn,
2343 if (toolbar->close_window_btn) {
2344 SET_WIDGET_COND(toolbar->close_window_btn,
2347 if (toolbar->open_mail_btn) {
2348 SET_WIDGET_COND(toolbar->open_mail_btn,
2349 M_TARGET_EXIST|M_SUMMARY_ISLIST);
2351 if (toolbar->reply_btn) {
2352 SET_WIDGET_COND(toolbar->reply_btn,
2353 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2355 if (toolbar->replyall_btn) {
2356 SET_WIDGET_COND(toolbar->replyall_btn,
2357 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2359 if (toolbar->replylist_btn) {
2360 SET_WIDGET_COND(toolbar->replylist_btn,
2361 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2363 if (toolbar->replysender_btn) {
2364 SET_WIDGET_COND(toolbar->replysender_btn,
2365 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2367 if (toolbar->fwd_btn) {
2368 SET_WIDGET_COND(toolbar->fwd_btn,
2369 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2372 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2373 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST|M_SUMMARY_ISLIST);
2375 SET_WIDGET_COND(toolbar->next_btn, 0);
2378 if (toolbar->trash_btn)
2379 SET_WIDGET_COND(toolbar->trash_btn,
2380 M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS);
2382 if (toolbar->delete_btn)
2383 SET_WIDGET_COND(toolbar->delete_btn,
2384 M_TARGET_EXIST|M_ALLOW_DELETE);
2386 if (toolbar->exec_btn)
2387 SET_WIDGET_COND(toolbar->exec_btn,
2390 if (toolbar->learn_spam_btn)
2391 SET_WIDGET_COND(toolbar->learn_spam_btn,
2392 M_TARGET_EXIST|M_CAN_LEARN_SPAM|M_SUMMARY_ISLIST);
2394 if (toolbar->cancel_inc_btn)
2395 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2398 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2399 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2401 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2404 #undef SET_WIDGET_COND
2406 state = main_window_get_current_state(mainwin);
2408 for (cur = entry_list; cur != NULL; cur = cur->next) {
2409 Entry *e = (Entry*) cur->data;
2411 if (e->widget != NULL) {
2412 sensitive = ((e->cond & state) == e->cond);
2413 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2417 while (entry_list != NULL) {
2418 Entry *e = (Entry*) entry_list->data;
2421 entry_list = g_slist_remove(entry_list, e);
2424 g_slist_free(entry_list);
2426 activate_compose_button(toolbar,
2427 prefs_common.toolbar_style,
2428 toolbar->compose_btn_type);
2432 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2434 Compose *compose = (Compose*)data;
2435 GSList *items = compose->toolbar->action_list;
2437 if (compose->toolbar->send_btn)
2438 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2439 if (compose->toolbar->sendl_btn)
2440 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2441 if (compose->toolbar->draft_btn )
2442 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2443 if (compose->toolbar->insert_btn )
2444 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2445 if (compose->toolbar->attach_btn)
2446 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2447 if (compose->toolbar->sig_btn)
2448 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2449 if (compose->toolbar->exteditor_btn)
2450 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2451 if (compose->toolbar->linewrap_current_btn)
2452 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2453 if (compose->toolbar->linewrap_all_btn)
2454 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2455 if (compose->toolbar->addrbook_btn)
2456 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2458 if (compose->toolbar->spellcheck_btn)
2459 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2461 for (; items != NULL; items = g_slist_next(items)) {
2462 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2463 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2468 * Initialize toolbar structure
2470 static void toolbar_init(Toolbar * toolbar)
2473 toolbar->toolbar = NULL;
2474 toolbar->folders_btn = NULL;
2475 toolbar->get_btn = NULL;
2476 toolbar->getall_btn = NULL;
2477 toolbar->send_btn = NULL;
2478 toolbar->compose_mail_btn = NULL;
2479 toolbar->compose_mail_icon = NULL;
2480 toolbar->compose_news_icon = NULL;
2481 toolbar->reply_btn = NULL;
2482 toolbar->replysender_btn = NULL;
2483 toolbar->replyall_btn = NULL;
2484 toolbar->replylist_btn = NULL;
2485 toolbar->fwd_btn = NULL;
2486 toolbar->trash_btn = NULL;
2487 toolbar->delete_btn = NULL;
2488 toolbar->prev_btn = NULL;
2489 toolbar->next_btn = NULL;
2490 toolbar->exec_btn = NULL;
2491 toolbar->open_mail_btn = NULL;
2492 toolbar->close_window_btn = NULL;
2493 /* compose buttons */
2494 toolbar->sendl_btn = NULL;
2495 toolbar->draft_btn = NULL;
2496 toolbar->insert_btn = NULL;
2497 toolbar->attach_btn = NULL;
2498 toolbar->sig_btn = NULL;
2499 toolbar->exteditor_btn = NULL;
2500 toolbar->linewrap_current_btn = NULL;
2501 toolbar->linewrap_all_btn = NULL;
2502 toolbar->addrbook_btn = NULL;
2504 toolbar->spellcheck_btn = NULL;
2507 toolbar_destroy(toolbar);
2512 static void toolbar_reply(gpointer data, guint action)
2514 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2515 MainWindow *mainwin;
2516 MessageView *msgview;
2517 GSList *msginfo_list = NULL;
2519 cm_return_if_fail(toolbar_item != NULL);
2521 switch (toolbar_item->type) {
2523 mainwin = (MainWindow*)toolbar_item->parent;
2524 msginfo_list = summary_get_selection(mainwin->summaryview);
2525 msgview = (MessageView*)mainwin->messageview;
2527 case TOOLBAR_MSGVIEW:
2528 msgview = (MessageView*)toolbar_item->parent;
2529 cm_return_if_fail(msgview != NULL);
2530 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2536 cm_return_if_fail(msgview != NULL);
2537 cm_return_if_fail(msginfo_list != NULL);
2538 compose_reply_from_messageview(msgview, msginfo_list, action);
2539 g_slist_free(msginfo_list);
2541 /* TODO: update reply state ion summaryview */
2545 /* exported functions */
2547 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2549 MainWindow *mainwin = (MainWindow*)data;
2551 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2554 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2556 MainWindow *mainwin = (MainWindow*)data;
2558 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2561 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2565 gboolean got_error = FALSE;
2566 gchar *errstr = NULL;
2568 if (prefs_common.work_offline)
2569 if (alertpanel(_("Offline warning"),
2570 _("You're working offline. Override?"),
2571 GTK_STOCK_NO, GTK_STOCK_YES,
2572 NULL) != G_ALERTALTERNATE)
2575 /* ask for confirmation before sending queued messages only
2576 in online mode and if there is at least one message queued
2577 in any of the folder queue
2579 if (prefs_common.confirm_send_queued_messages) {
2581 /* check if there's a queued message */
2582 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2583 Folder *folder = list->data;
2585 found = !procmsg_queue_is_empty(folder->queue);
2587 /* if necessary, ask for confirmation before sending */
2588 if (found && !prefs_common.work_offline) {
2589 if (alertpanel(_("Send queued messages"),
2590 _("Send all queued messages?"),
2591 GTK_STOCK_CANCEL, _("_Send"),
2592 NULL) != G_ALERTALTERNATE)
2597 for (list = folder_get_list(); list != NULL; list = list->next) {
2598 Folder *folder = list->data;
2600 if (folder->queue) {
2601 if (procmsg_send_queue(folder->queue,
2602 prefs_common.savemsg,
2609 alertpanel_error_log(_("Some errors occurred while "
2610 "sending queued messages."));
2612 alertpanel_error_log(_("Some errors occurred "
2613 "while sending queued messages:\n%s"), errstr);
2619 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2621 MainWindow *mainwin = (MainWindow*)data;
2622 PrefsAccount *ac = NULL;
2623 FolderItem *item = mainwin->summaryview->folder_item;
2628 ac = account_find_from_item(item);
2629 if (ac && ac->protocol != A_NNTP) {
2630 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2636 * CLAWS - use current account
2638 if (cur_account && (cur_account->protocol != A_NNTP)) {
2639 compose_new_with_folderitem(cur_account, item, NULL);
2644 * CLAWS - just get the first one
2646 list = account_get_list();
2647 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2648 ac = (PrefsAccount *) cur->data;
2649 if (ac->protocol != A_NNTP) {
2650 compose_new_with_folderitem(ac, item, NULL);
2656 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2658 MainWindow *mainwin = (MainWindow*)data;
2659 PrefsAccount * ac = NULL;
2663 if (mainwin->summaryview->folder_item) {
2664 ac = mainwin->summaryview->folder_item->folder->account;
2665 if (ac && ac->protocol == A_NNTP) {
2666 compose_new_with_folderitem(ac,
2667 mainwin->summaryview->folder_item, NULL);
2672 list = account_get_list();
2673 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2674 ac = (PrefsAccount *) cur->data;
2675 if (ac->protocol == A_NNTP) {
2676 compose_new_with_folderitem(ac,
2677 mainwin->summaryview->folder_item, NULL);