2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2011 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,
139 static void toolbar_plugins_execute_cb (GtkWidget *widget,
143 static void toolbar_send_cb (GtkWidget *widget,
145 static void toolbar_send_later_cb (GtkWidget *widget,
147 static void toolbar_draft_cb (GtkWidget *widget,
149 static void toolbar_close_cb (GtkWidget *widget,
151 static void toolbar_preferences_cb (GtkWidget *widget,
153 static void toolbar_open_mail_cb (GtkWidget *widget,
155 static void toolbar_insert_cb (GtkWidget *widget,
157 static void toolbar_attach_cb (GtkWidget *widget,
159 static void toolbar_sig_cb (GtkWidget *widget,
161 static void toolbar_ext_editor_cb (GtkWidget *widget,
163 static void toolbar_linewrap_current_cb (GtkWidget *widget,
165 static void toolbar_linewrap_all_cb (GtkWidget *widget,
167 static void toolbar_addrbook_cb (GtkWidget *widget,
170 static void toolbar_check_spelling_cb (GtkWidget *widget,
173 static void toolbar_cancel_inc_cb (GtkWidget *widget,
179 } toolbar_text [] = {
180 { "A_RECEIVE_ALL", N_("Receive Mail from all Accounts") },
181 { "A_RECEIVE_CUR", N_("Receive Mail from current Account") },
182 { "A_SEND_QUEUED", N_("Send Queued Messages") },
183 { "A_COMPOSE_EMAIL", N_("Compose Email") },
184 { "A_COMPOSE_NEWS", N_("Compose News") },
185 { "A_REPLY_MESSAGE", N_("Reply to Message") },
186 { "A_REPLY_SENDER", N_("Reply to Sender") },
187 { "A_REPLY_ALL", N_("Reply to All") },
188 { "A_REPLY_ML", N_("Reply to Mailing-list") },
189 { "A_OPEN_MAIL", N_("Open email") },
190 { "A_FORWARD", N_("Forward Message") },
191 { "A_TRASH", N_("Trash Message") },
192 { "A_DELETE_REAL", N_("Delete Message") },
193 { "A_EXECUTE", N_("Execute") },
194 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
195 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
196 { "A_IGNORE_THREAD", N_("Ignore thread") },
197 { "A_WATCH_THREAD", N_("Watch thread") },
198 { "A_PRINT", N_("Print") },
199 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
200 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
201 { "A_PREFERENCES", N_("Preferences") },
203 { "A_SEND", N_("Send Message") },
204 { "A_SENDL", N_("Put into queue folder and send later") },
205 { "A_DRAFT", N_("Save to draft folder") },
206 { "A_INSERT", N_("Insert file") },
207 { "A_ATTACH", N_("Attach file") },
208 { "A_SIG", N_("Insert signature") },
209 { "A_EXTEDITOR", N_("Edit with external editor") },
210 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
211 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
212 { "A_ADDRBOOK", N_("Address book") },
214 { "A_CHECK_SPELLING", N_("Check spelling") },
216 { "A_CLAWS_ACTIONS", N_("Claws Mail Actions Feature") },
217 { "A_CANCEL_INC", N_("Cancel receiving") },
218 { "A_CLOSE", N_("Close window") },
219 { "A_SEPARATOR", N_("Separator") },
220 { "A_CLAWS_PLUGINS", N_("Claws Mail Plugins") },
223 /* struct holds configuration files and a list of
224 * currently active toolbar items
225 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
229 const gchar *conf_file;
231 } toolbar_config[3] = {
232 { "toolbar_main.xml", NULL},
233 { "toolbar_compose.xml", NULL},
234 { "toolbar_msgview.xml", NULL}
237 gint toolbar_ret_val_from_descr(const gchar *descr)
241 for (i = 0; i < N_ACTION_VAL; i++) {
242 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
249 gchar *toolbar_ret_descr_from_val(gint val)
251 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
253 return gettext(toolbar_text[val].descr);
256 static gint toolbar_ret_val_from_text(const gchar *text)
260 for (i = 0; i < N_ACTION_VAL; i++) {
261 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
268 static gchar *toolbar_ret_text_from_val(gint val)
270 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
272 return toolbar_text[val].index_str;
275 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
279 if ((action == A_SEPARATOR) || (action == A_CLAWS_ACTIONS) || (action == A_CLAWS_PLUGINS))
282 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
283 ToolbarItem *item = (ToolbarItem*) cur->data;
285 if (item->index == action)
291 /* depending on toolbar type this function
292 returns a list of available toolbar events being
293 displayed by prefs_toolbar
295 GList *toolbar_get_action_items(ToolbarType source)
300 if (source == TOOLBAR_MAIN) {
301 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
302 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
303 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
304 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
305 A_GOTO_NEXT, A_IGNORE_THREAD, A_WATCH_THREAD, A_PRINT,
306 A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
307 A_CANCEL_INC, A_PREFERENCES };
309 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
310 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
313 else if (source == TOOLBAR_COMPOSE) {
314 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
315 A_INSERT, A_ATTACH, A_SIG,
316 A_EXTEDITOR, A_LINEWRAP_CURRENT,
317 A_LINEWRAP_ALL, A_ADDRBOOK,
323 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
324 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
326 else if (source == TOOLBAR_MSGVIEW) {
327 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
328 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
329 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
330 A_ADDRBOOK, A_LEARN_SPAM, A_CLOSE };
332 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
333 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
339 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
343 ToolbarItem *item = NULL;
344 gboolean rewrite = FALSE;
346 attr = xml_get_current_tag_attr(file);
347 item = g_new0(ToolbarItem, 1);
349 name = ((XMLAttr *)attr->data)->name;
350 value = ((XMLAttr *)attr->data)->value;
352 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
353 item->file = g_strdup (value);
354 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
355 item->text = g_strdup (*value ? gettext(value):"");
356 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
357 item->index = toolbar_ret_val_from_text(value);
358 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
360 item->index = A_TRASH;
362 item->file = g_strdup("trash_btn");
364 item->text = g_strdup(Q_("Toolbar|Trash"));
367 if (item->index == -1 && !strcmp(value, "A_SYL_ACTIONS")) {
369 item->index = A_CLAWS_ACTIONS;
372 attr = g_list_next(attr);
374 if (item->index != -1) {
376 if (!toolbar_is_duplicate(item->index, source))
377 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
381 toolbar_save_config_file(source);
385 const gchar *toolbar_get_short_text(int action) {
387 case A_GO_FOLDERS: return _("Folders");
388 case A_OPEN_MAIL: return _("Open");
389 case A_RECEIVE_ALL: return _("Get Mail");
390 case A_RECEIVE_CUR: return _("Get");
391 case A_SEND_QUEUED: return _("Send");
392 case A_COMPOSE_EMAIL: return Q_("Toolbar|Compose");
393 case A_COMPOSE_NEWS: return Q_("Toolbar|Compose");
394 case A_REPLY_MESSAGE: return _("Reply");
395 case A_REPLY_ALL: return _("All");
396 case A_REPLY_SENDER: return Q_("Toolbar|Sender");
397 case A_REPLY_ML: return _("List");
398 case A_FORWARD: return _("Forward");
399 case A_TRASH: return Q_("Toolbar|Trash");
400 case A_DELETE_REAL: return _("Delete");
401 case A_LEARN_SPAM: return _("Spam");
402 case A_GOTO_PREV: return _("Prev");
403 case A_GOTO_NEXT: return _("Next");
404 case A_IGNORE_THREAD: return _("Ignore thread");
405 case A_WATCH_THREAD: return _("Watch thread");
406 case A_PRINT: return _("Print");
407 case A_CLOSE: return _("Close");
408 case A_PREFERENCES: return _("Preferences");
409 case A_SEND: return _("Send");
410 case A_SENDL: return _("Send later");
411 case A_DRAFT: return _("Draft");
412 case A_INSERT: return _("Insert");
413 case A_ATTACH: return _("Attach");
414 case A_SIG: return _("Insert sig.");
415 case A_EXTEDITOR: return _("Edit");
416 case A_LINEWRAP_CURRENT:return _("Wrap para.");
417 case A_LINEWRAP_ALL: return _("Wrap all");
418 case A_ADDRBOOK: return _("Address");
419 case A_CANCEL_INC: return _("Stop");
420 case A_EXECUTE: return _("Execute");
422 case A_CHECK_SPELLING: return _("Check spelling");
428 gint toolbar_get_icon(int action) {
430 case A_GO_FOLDERS: return STOCK_PIXMAP_GO_FOLDERS;
431 case A_OPEN_MAIL: return STOCK_PIXMAP_OPEN_MAIL;
432 case A_RECEIVE_ALL: return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
433 case A_RECEIVE_CUR: return STOCK_PIXMAP_MAIL_RECEIVE;
434 case A_SEND_QUEUED: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
435 case A_COMPOSE_EMAIL: return STOCK_PIXMAP_MAIL_COMPOSE;
436 case A_COMPOSE_NEWS: return STOCK_PIXMAP_NEWS_COMPOSE;
437 case A_REPLY_MESSAGE: return STOCK_PIXMAP_MAIL_REPLY;
438 case A_REPLY_ALL: return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
439 case A_REPLY_SENDER: return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
440 case A_REPLY_ML: return STOCK_PIXMAP_MAIL_REPLY_TO_LIST;
441 case A_FORWARD: return STOCK_PIXMAP_MAIL_FORWARD;
442 case A_TRASH: return STOCK_PIXMAP_TRASH;
443 case A_DELETE_REAL: return STOCK_PIXMAP_DELETE;
444 case A_LEARN_SPAM: return STOCK_PIXMAP_SPAM_BTN;
445 case A_GOTO_PREV: return STOCK_PIXMAP_UP_ARROW;
446 case A_GOTO_NEXT: return STOCK_PIXMAP_DOWN_ARROW;
447 case A_IGNORE_THREAD: return STOCK_PIXMAP_IGNORETHREAD;
448 case A_WATCH_THREAD: return STOCK_PIXMAP_WATCHTHREAD;
449 case A_PRINT: return STOCK_PIXMAP_PRINTER;
450 case A_CLOSE: return STOCK_PIXMAP_CLOSE;
451 case A_PREFERENCES: return STOCK_PIXMAP_PREFERENCES;
452 case A_SEND: return STOCK_PIXMAP_MAIL_SEND;
453 case A_SENDL: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
454 case A_DRAFT: return STOCK_PIXMAP_MAIL;
455 case A_INSERT: return STOCK_PIXMAP_INSERT_FILE;
456 case A_ATTACH: return STOCK_PIXMAP_MAIL_ATTACH;
457 case A_SIG: return STOCK_PIXMAP_MAIL_SIGN;
458 case A_EXTEDITOR: return STOCK_PIXMAP_EDIT_EXTERN;
459 case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
460 case A_LINEWRAP_ALL: return STOCK_PIXMAP_LINEWRAP_ALL;
461 case A_ADDRBOOK: return STOCK_PIXMAP_ADDRESS_BOOK;
462 case A_CANCEL_INC: return STOCK_PIXMAP_CANCEL;
463 case A_EXECUTE: return STOCK_PIXMAP_EXEC;
465 case A_CHECK_SPELLING: return STOCK_PIXMAP_CHECK_SPELLING;
471 static void toolbar_set_default_main(void)
475 } default_toolbar[] = {
503 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
505 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
507 if (default_toolbar[i].action != A_SEPARATOR) {
510 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
511 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
514 toolbar_item->file = g_strdup(file);
515 toolbar_item->index = default_toolbar[i].action;
516 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
519 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
520 toolbar_item->index = A_SEPARATOR;
523 if (toolbar_item->index != -1) {
524 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
525 toolbar_config[TOOLBAR_MAIN].item_list =
526 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
531 static void toolbar_set_default_compose(void)
535 } default_toolbar[] = {
554 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
556 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
558 if (default_toolbar[i].action != A_SEPARATOR) {
561 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
562 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
564 toolbar_item->file = g_strdup(file);
565 toolbar_item->index = default_toolbar[i].action;
566 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
569 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
570 toolbar_item->index = A_SEPARATOR;
573 if (toolbar_item->index != -1) {
574 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
575 toolbar_config[TOOLBAR_COMPOSE].item_list =
576 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
581 static void toolbar_set_default_msgview(void)
585 } default_toolbar[] = {
604 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
606 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
608 if (default_toolbar[i].action != A_SEPARATOR) {
610 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
611 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
614 toolbar_item->file = g_strdup(file);
615 toolbar_item->index = default_toolbar[i].action;
616 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
619 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
620 toolbar_item->index = A_SEPARATOR;
623 if (toolbar_item->index != -1) {
624 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
625 toolbar_config[TOOLBAR_MSGVIEW].item_list =
626 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
631 void toolbar_set_default(ToolbarType source)
633 if (source == TOOLBAR_MAIN)
634 toolbar_set_default_main();
635 else if (source == TOOLBAR_COMPOSE)
636 toolbar_set_default_compose();
637 else if (source == TOOLBAR_MSGVIEW)
638 toolbar_set_default_msgview();
641 void toolbar_save_config_file(ToolbarType source)
646 gchar *fileSpec = NULL;
648 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
650 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
651 pfile = prefs_write_open(fileSpec);
654 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
657 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
660 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
661 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
663 if (toolbar_item->index != A_SEPARATOR) {
664 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
666 TOOLBAR_ICON_FILE, toolbar_item->file,
667 TOOLBAR_ICON_TEXT) < 0)
669 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
671 if (fprintf(fp, "\" %s=\"%s\"/>\n",
673 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
676 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
681 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
685 if (prefs_file_close (pfile) < 0 )
686 g_warning("failed to write toolbar configuration to file\n");
690 FILE_OP_ERROR(fileSpec, "fprintf");
692 prefs_file_close_revert (pfile);
694 g_warning("failed to open toolbar configuration file for writing\n");
697 void toolbar_read_config_file(ToolbarType source)
699 XMLFile *file = NULL;
700 gchar *fileSpec = NULL;
705 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
707 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
708 file = xml_open_file(fileSpec);
711 toolbar_clear_list(source);
715 || (xml_get_dtd(file))
716 || (xml_parse_next_tag(file))
717 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
718 xml_close_file(file);
722 attr = xml_get_current_tag_attr(file);
729 if (xml_parse_next_tag(file))
732 /* Get next tag (icon, icon_text or icon_action) */
733 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
734 toolbar_parse_item(file, source);
735 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
736 ToolbarItem *item = g_new0(ToolbarItem, 1);
738 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
739 item->index = A_SEPARATOR;
740 toolbar_config[source].item_list =
741 g_slist_append(toolbar_config[source].item_list, item);
745 xml_close_file(file);
748 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
750 if (source == TOOLBAR_MAIN)
751 toolbar_set_default(TOOLBAR_MAIN);
752 else if (source == TOOLBAR_COMPOSE)
753 toolbar_set_default(TOOLBAR_COMPOSE);
754 else if (source == TOOLBAR_MSGVIEW)
755 toolbar_set_default(TOOLBAR_MSGVIEW);
757 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
761 toolbar_save_config_file(source);
766 * clears list of toolbar items read from configuration files
768 void toolbar_clear_list(ToolbarType source)
770 while (toolbar_config[source].item_list != NULL) {
771 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
773 toolbar_config[source].item_list =
774 g_slist_remove(toolbar_config[source].item_list, item);
780 g_slist_free(toolbar_config[source].item_list);
785 * return list of Toolbar items
787 GSList *toolbar_get_list(ToolbarType source)
791 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
792 list = toolbar_config[source].item_list;
797 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
799 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
801 toolbar_item->file = g_strdup(t_item->file);
802 toolbar_item->text = g_strdup(t_item->text);
803 toolbar_item->index = t_item->index;
805 toolbar_config[source].item_list =
806 g_slist_append(toolbar_config[source].item_list,
810 static void toolbar_action_execute(GtkWidget *widget,
816 gchar *action, *action_p;
817 gboolean found = FALSE;
820 for (cur = action_list; cur != NULL; cur = cur->next) {
821 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
823 if (widget == act->widget) {
825 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
826 action = g_strdup((gchar*)lop->data);
828 action_p = strstr(action, ": ");
830 if (g_utf8_collate(act->name, action) == 0) {
844 actions_execute(data, i, widget, source);
846 g_warning ("Error: did not find Claws Action to execute");
849 #if !(GTK_CHECK_VERSION(2,12,0))
850 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
851 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(widget), GTK_TOOLTIPS(toolbar_tips), \
855 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
856 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), tip); \
860 #if !(GTK_CHECK_VERSION(2,12,0))
861 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
862 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(widget), GTK_TOOLTIPS(toolbar_tips), \
866 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
867 gtk_menu_tool_button_set_arrow_tooltip_text(GTK_MENU_TOOL_BUTTON(widget), tip); \
871 static void activate_compose_button (Toolbar *toolbar,
873 ComposeButtonType type)
875 #if !(GTK_CHECK_VERSION(2,12,0))
876 GtkTooltips *toolbar_tips = toolbar->tooltips;
878 if ((!toolbar->compose_mail_btn))
881 if (type == COMPOSEBUTTON_NEWS) {
882 gtk_tool_button_set_icon_widget(
883 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
884 toolbar->compose_news_icon);
886 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose News message"));
888 gtk_widget_show(toolbar->compose_news_icon);
890 gtk_tool_button_set_icon_widget(
891 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
892 toolbar->compose_mail_icon);
894 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose Email"));
896 gtk_widget_show(toolbar->compose_mail_icon);
898 toolbar->compose_btn_type = type;
901 void toolbar_set_compose_button(Toolbar *toolbar,
902 ComposeButtonType compose_btn_type)
904 if (toolbar->compose_btn_type != compose_btn_type)
905 activate_compose_button(toolbar,
906 prefs_common.toolbar_style,
910 static void activate_learn_button (Toolbar *toolbar,
912 LearnButtonType type)
914 #if !(GTK_CHECK_VERSION(2,12,0))
915 GtkTooltips *toolbar_tips = toolbar->tooltips;
917 if ((!toolbar->learn_spam_btn))
920 if (type == LEARN_SPAM) {
921 gtk_tool_button_set_icon_widget(
922 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
923 toolbar->learn_spam_icon);
924 gtk_tool_button_set_label(
925 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
928 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn spam"));
930 gtk_widget_show(toolbar->learn_spam_icon);
932 gtk_tool_button_set_icon_widget(
933 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
934 toolbar->learn_ham_icon);
935 gtk_tool_button_set_label(
936 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
939 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn ham"));
941 gtk_widget_show(toolbar->learn_ham_icon);
943 toolbar->learn_btn_type = type;
946 void toolbar_set_learn_button(Toolbar *toolbar,
947 LearnButtonType learn_btn_type)
949 if (toolbar->learn_btn_type != learn_btn_type)
950 activate_learn_button(toolbar,
951 prefs_common.toolbar_style,
955 void toolbar_toggle(guint action, gpointer data)
957 MainWindow *mainwin = (MainWindow*)data;
961 cm_return_if_fail(mainwin != NULL);
963 toolbar_style(TOOLBAR_MAIN, action, mainwin);
965 list = compose_get_compose_list();
966 for (cur = list; cur != NULL; cur = cur->next) {
967 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
969 list = messageview_get_msgview_list();
970 for (cur = list; cur != NULL; cur = cur->next) {
971 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
976 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
978 switch ((ToolbarStyle)action) {
980 gtk_widget_hide(handlebox_wid);
983 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
987 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
991 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
994 case TOOLBAR_BOTH_HORIZ:
995 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
996 GTK_TOOLBAR_BOTH_HORIZ);
1002 prefs_common.toolbar_style = (ToolbarStyle)action;
1003 gtk_widget_set_size_request(handlebox_wid, 1, -1);
1005 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1006 gtk_widget_show(handlebox_wid);
1007 gtk_widget_queue_resize(handlebox_wid);
1011 * Change the style of toolbar
1013 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1015 GtkWidget *handlebox_wid;
1016 GtkWidget *toolbar_wid;
1017 MainWindow *mainwin = (MainWindow*)data;
1018 Compose *compose = (Compose*)data;
1019 MessageView *msgview = (MessageView*)data;
1021 cm_return_if_fail(data != NULL);
1025 handlebox_wid = mainwin->handlebox;
1026 toolbar_wid = mainwin->toolbar->toolbar;
1028 case TOOLBAR_COMPOSE:
1029 handlebox_wid = compose->handlebox;
1030 toolbar_wid = compose->toolbar->toolbar;
1032 case TOOLBAR_MSGVIEW:
1033 handlebox_wid = msgview->handlebox;
1034 toolbar_wid = msgview->toolbar->toolbar;
1040 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1043 /* Toolbar handling */
1044 static void toolbar_inc_cb(GtkWidget *widget,
1047 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1048 MainWindow *mainwin;
1050 cm_return_if_fail(toolbar_item != NULL);
1052 switch (toolbar_item->type) {
1054 mainwin = (MainWindow*)toolbar_item->parent;
1055 inc_mail_cb(mainwin, 0, NULL);
1062 static void toolbar_inc_all_cb(GtkWidget *widget,
1065 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1066 MainWindow *mainwin;
1068 cm_return_if_fail(toolbar_item != NULL);
1070 switch (toolbar_item->type) {
1072 mainwin = (MainWindow*)toolbar_item->parent;
1073 inc_all_account_mail_cb(mainwin, 0, NULL);
1080 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1082 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1083 MainWindow *mainwin;
1085 cm_return_if_fail(toolbar_item != NULL);
1087 switch (toolbar_item->type) {
1089 mainwin = (MainWindow*)toolbar_item->parent;
1090 send_queue_cb(mainwin, 0, NULL);
1097 static void toolbar_exec_cb(GtkWidget *widget,
1100 MainWindow *mainwin = get_mainwin(data);
1102 cm_return_if_fail(mainwin != NULL);
1103 summary_execute(mainwin->summaryview);
1107 * Delete current/selected(s) message(s)
1109 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1111 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1112 MainWindow *mainwin;
1114 cm_return_if_fail(toolbar_item != NULL);
1115 cm_return_if_fail(toolbar_item->parent);
1117 switch (toolbar_item->type) {
1118 case TOOLBAR_MSGVIEW:
1119 messageview_delete((MessageView *)toolbar_item->parent);
1122 mainwin = (MainWindow *)toolbar_item->parent;
1123 summary_delete_trash(mainwin->summaryview);
1126 debug_print("toolbar event not supported\n");
1132 * Delete current/selected(s) message(s)
1134 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1136 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1137 MainWindow *mainwin;
1139 cm_return_if_fail(toolbar_item != NULL);
1140 cm_return_if_fail(toolbar_item->parent);
1142 switch (toolbar_item->type) {
1143 case TOOLBAR_MSGVIEW:
1144 messageview_delete((MessageView *)toolbar_item->parent);
1147 mainwin = (MainWindow *)toolbar_item->parent;
1148 summary_delete(mainwin->summaryview);
1151 debug_print("toolbar event not supported\n");
1158 * Compose new message
1160 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1162 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1163 MainWindow *mainwin;
1164 MessageView *msgview;
1166 cm_return_if_fail(toolbar_item != NULL);
1168 switch (toolbar_item->type) {
1170 mainwin = (MainWindow*)toolbar_item->parent;
1171 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1172 compose_news_cb(mainwin, 0, NULL);
1174 compose_mail_cb(mainwin, 0, NULL);
1176 case TOOLBAR_MSGVIEW:
1177 msgview = (MessageView*)toolbar_item->parent;
1178 compose_new_with_folderitem(NULL,
1179 msgview->msginfo->folder, NULL);
1182 debug_print("toolbar event not supported\n");
1186 static void toolbar_learn(gpointer data, guint as_spam)
1188 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1189 MainWindow *mainwin;
1190 MessageView *msgview;
1192 cm_return_if_fail(toolbar_item != NULL);
1194 switch (toolbar_item->type) {
1196 mainwin = (MainWindow*)toolbar_item->parent;
1198 mainwindow_learn(mainwin, TRUE);
1200 mainwindow_learn(mainwin, FALSE);
1202 case TOOLBAR_MSGVIEW:
1203 msgview = (MessageView*)toolbar_item->parent;
1205 messageview_learn(msgview, TRUE);
1207 messageview_learn(msgview, FALSE);
1210 debug_print("toolbar event not supported\n");
1214 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1216 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1217 MainWindow *mainwin;
1218 MessageView *msgview;
1220 cm_return_if_fail(toolbar_item != NULL);
1222 switch (toolbar_item->type) {
1224 mainwin = (MainWindow*)toolbar_item->parent;
1225 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1226 mainwindow_learn(mainwin, TRUE);
1228 mainwindow_learn(mainwin, FALSE);
1230 case TOOLBAR_MSGVIEW:
1231 msgview = (MessageView*)toolbar_item->parent;
1232 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1233 messageview_learn(msgview, TRUE);
1235 messageview_learn(msgview, FALSE);
1238 debug_print("toolbar event not supported\n");
1246 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1248 toolbar_reply(data, (prefs_common.reply_with_quote ?
1249 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE));
1254 * Reply message to Sender and All recipients
1256 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1259 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1260 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE));
1265 * Reply to Mailing List
1267 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1270 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1271 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE));
1276 * Reply to sender of message
1278 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1281 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1282 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE));
1288 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1290 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1293 cm_return_if_fail(toolbar_item != NULL);
1295 switch (toolbar_item->type) {
1297 case TOOLBAR_MSGVIEW:
1300 case TOOLBAR_COMPOSE:
1301 compose = (Compose *)toolbar_item->parent;
1306 addressbook_open(compose);
1311 * Forward current/selected(s) message(s)
1313 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1315 toolbar_reply(data, (COMPOSE_FORWARD));
1319 * Goto Prev Unread Message
1321 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1323 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1324 MainWindow *mainwin;
1325 MessageView *msgview;
1327 cm_return_if_fail(toolbar_item != NULL);
1329 switch (toolbar_item->type) {
1331 mainwin = (MainWindow*)toolbar_item->parent;
1332 summary_select_prev_unread(mainwin->summaryview);
1335 case TOOLBAR_MSGVIEW:
1336 msgview = (MessageView*)toolbar_item->parent;
1337 msgview->updating = TRUE;
1338 summary_select_prev_unread(msgview->mainwin->summaryview);
1339 msgview->updating = FALSE;
1341 if (msgview->deferred_destroy) {
1342 debug_print("messageview got away!\n");
1343 messageview_destroy(msgview);
1347 /* Now we need to update the messageview window */
1348 if (msgview->mainwin->summaryview->selected) {
1349 #ifndef GENERIC_UMPC
1350 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1353 messageview_show(msgview, msginfo,
1354 msgview->all_headers);
1357 gtk_widget_destroy(msgview->window);
1361 debug_print("toolbar event not supported\n");
1366 * Goto Next Unread Message
1368 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1370 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1371 MainWindow *mainwin;
1372 MessageView *msgview;
1374 cm_return_if_fail(toolbar_item != NULL);
1376 switch (toolbar_item->type) {
1378 mainwin = (MainWindow*)toolbar_item->parent;
1379 summary_select_next_unread(mainwin->summaryview);
1382 case TOOLBAR_MSGVIEW:
1383 msgview = (MessageView*)toolbar_item->parent;
1384 msgview->updating = TRUE;
1385 summary_select_next_unread(msgview->mainwin->summaryview);
1386 msgview->updating = FALSE;
1388 if (msgview->deferred_destroy) {
1389 debug_print("messageview got away!\n");
1390 messageview_destroy(msgview);
1394 /* Now we need to update the messageview window */
1395 if (msgview->mainwin->summaryview->selected) {
1396 #ifndef GENERIC_UMPC
1397 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1400 messageview_show(msgview, msginfo,
1401 msgview->all_headers);
1404 gtk_widget_destroy(msgview->window);
1408 debug_print("toolbar event not supported\n");
1412 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1414 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1415 MainWindow *mainwin;
1417 cm_return_if_fail(toolbar_item != NULL);
1419 switch (toolbar_item->type) {
1421 mainwin = (MainWindow *) toolbar_item->parent;
1422 summary_toggle_ignore_thread(mainwin->summaryview);
1424 case TOOLBAR_MSGVIEW:
1425 /* TODO: see toolbar_next_unread_cb() if you need
1426 * this in the message view */
1429 debug_print("toolbar event not supported\n");
1434 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1436 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1437 MainWindow *mainwin;
1439 cm_return_if_fail(toolbar_item != NULL);
1441 switch (toolbar_item->type) {
1443 mainwin = (MainWindow *) toolbar_item->parent;
1444 summary_toggle_watch_thread(mainwin->summaryview);
1446 case TOOLBAR_MSGVIEW:
1447 /* TODO: see toolbar_next_unread_cb() if you need
1448 * this in the message view */
1451 debug_print("toolbar event not supported\n");
1456 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1458 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1460 cm_return_if_fail(toolbar_item != NULL);
1466 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1468 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1469 MainWindow *mainwin;
1471 cm_return_if_fail(toolbar_item != NULL);
1473 switch (toolbar_item->type) {
1475 mainwin = (MainWindow *) toolbar_item->parent;
1476 summary_print(mainwin->summaryview);
1478 case TOOLBAR_MSGVIEW:
1479 /* TODO: see toolbar_next_unread_cb() if you need
1480 * this in the message view */
1483 debug_print("toolbar event not supported\n");
1488 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1490 compose_toolbar_cb(A_SEND, data);
1493 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1495 compose_toolbar_cb(A_SENDL, data);
1498 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1500 compose_toolbar_cb(A_DRAFT, data);
1503 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1505 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1506 MainWindow *mainwin;
1507 MessageView *messageview;
1510 cm_return_if_fail(toolbar_item != NULL);
1512 switch (toolbar_item->type) {
1514 mainwin = (MainWindow *) toolbar_item->parent;
1515 app_will_exit(NULL, mainwin);
1517 case TOOLBAR_MSGVIEW:
1518 messageview = (MessageView *)toolbar_item->parent;
1519 messageview_destroy(messageview);
1521 case TOOLBAR_COMPOSE:
1522 compose = (Compose *)toolbar_item->parent;
1523 compose_close_toolbar(compose);
1528 static void toolbar_preferences_cb(GtkWidget *widget, gpointer data)
1533 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1535 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1536 MainWindow *mainwin;
1538 cm_return_if_fail(toolbar_item != NULL);
1540 switch (toolbar_item->type) {
1542 mainwin = (MainWindow *) toolbar_item->parent;
1543 summary_open_row(NULL, mainwin->summaryview);
1545 case TOOLBAR_MSGVIEW:
1546 debug_print("toolbar event not supported\n");
1548 case TOOLBAR_COMPOSE:
1549 debug_print("toolbar event not supported\n");
1554 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1556 compose_toolbar_cb(A_INSERT, data);
1559 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1561 compose_toolbar_cb(A_ATTACH, data);
1564 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1566 compose_toolbar_cb(A_SIG, data);
1569 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1571 compose_toolbar_cb(A_EXTEDITOR, data);
1574 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1576 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1579 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1581 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1585 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1587 compose_toolbar_cb(A_CHECK_SPELLING, data);
1591 * Execute actions from toolbar
1593 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1595 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1596 GSList *action_list;
1597 MainWindow *mainwin;
1599 MessageView *msgview;
1600 gpointer parent = toolbar_item->parent;
1602 cm_return_if_fail(toolbar_item != NULL);
1604 switch (toolbar_item->type) {
1606 mainwin = (MainWindow*)parent;
1607 action_list = mainwin->toolbar->action_list;
1609 case TOOLBAR_COMPOSE:
1610 compose = (Compose*)parent;
1611 action_list = compose->toolbar->action_list;
1613 case TOOLBAR_MSGVIEW:
1614 msgview = (MessageView*)parent;
1615 action_list = msgview->toolbar->action_list;
1618 debug_print("toolbar event not supported\n");
1621 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1624 static void toolbar_plugins_execute_cb(GtkWidget *widget, gpointer data)
1626 ToolbarItem *toolbar_item = data;
1627 prefs_toolbar_execute_plugin_item(toolbar_item->parent, toolbar_item->type, toolbar_item->text);
1630 static MainWindow *get_mainwin(gpointer data)
1632 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1633 MainWindow *mainwin = NULL;
1634 MessageView *msgview;
1636 cm_return_val_if_fail(toolbar_item != NULL, NULL);
1638 switch(toolbar_item->type) {
1640 mainwin = (MainWindow*)toolbar_item->parent;
1642 case TOOLBAR_MSGVIEW:
1643 msgview = (MessageView*)toolbar_item->parent;
1644 mainwin = (MainWindow*)msgview->mainwin;
1653 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1655 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1656 MainWindow *mainwin = NULL;
1657 switch(toolbar_item->type) {
1659 mainwin = (MainWindow*)toolbar_item->parent;
1662 g_warning("wrong toolbar type\n");
1666 if (!mainwin->in_folder) {
1667 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1669 folderview_select(mainwin->folderview, item);
1672 gtk_widget_grab_focus(mainwin->folderview->ctree);
1673 mainwindow_exit_folder(mainwin);
1677 static void toolbar_buttons_cb(GtkWidget *widget,
1684 void (*func)(GtkWidget *widget, gpointer data);
1686 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1687 { A_RECEIVE_CUR, toolbar_inc_cb },
1688 { A_SEND_QUEUED, toolbar_send_queued_cb },
1689 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1690 { A_COMPOSE_NEWS, toolbar_compose_cb },
1691 { A_REPLY_MESSAGE, toolbar_reply_cb },
1692 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1693 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1694 { A_REPLY_ML, toolbar_reply_to_list_cb },
1695 { A_FORWARD, toolbar_forward_cb },
1696 { A_TRASH, toolbar_trash_cb },
1697 { A_DELETE_REAL, toolbar_delete_cb },
1698 { A_EXECUTE, toolbar_exec_cb },
1699 { A_GOTO_PREV, toolbar_prev_unread_cb },
1700 { A_GOTO_NEXT, toolbar_next_unread_cb },
1701 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1702 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1703 { A_PRINT, toolbar_print_cb },
1704 { A_LEARN_SPAM, toolbar_learn_cb },
1705 { A_GO_FOLDERS, toolbar_go_folders_cb },
1707 { A_SEND, toolbar_send_cb },
1708 { A_SENDL, toolbar_send_later_cb },
1709 { A_DRAFT, toolbar_draft_cb },
1710 { A_OPEN_MAIL, toolbar_open_mail_cb },
1711 { A_CLOSE, toolbar_close_cb },
1712 { A_PREFERENCES, toolbar_preferences_cb },
1713 { A_INSERT, toolbar_insert_cb },
1714 { A_ATTACH, toolbar_attach_cb },
1715 { A_SIG, toolbar_sig_cb },
1716 { A_EXTEDITOR, toolbar_ext_editor_cb },
1717 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1718 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1719 { A_ADDRBOOK, toolbar_addrbook_cb },
1721 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1723 { A_CLAWS_ACTIONS, toolbar_actions_execute_cb },
1724 { A_CANCEL_INC, toolbar_cancel_inc_cb },
1725 { A_CLAWS_PLUGINS, toolbar_plugins_execute_cb },
1728 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1730 for (i = 0; i < num_items; i++) {
1731 if (callbacks[i].index == item->index) {
1732 callbacks[i].func(widget, item);
1737 #ifndef GENERIC_UMPC
1738 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1739 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1740 gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
1741 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1742 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1743 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1744 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1745 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1749 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1750 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1751 GList *gchild = NULL; \
1752 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1753 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1754 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1755 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1756 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1757 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1759 CLAWS_SET_ARROW_TIP(GTK_MENU_TOOL_BUTTON(item), menutip); \
1760 child = gtk_bin_get_child(GTK_BIN(item)); \
1761 gchild = gtk_container_get_children( \
1762 GTK_CONTAINER(child)); \
1763 btn = (GtkWidget *)gchild->data; \
1764 gtkut_widget_set_can_focus(btn, FALSE); \
1765 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1766 gtkut_widget_set_can_focus(arr, FALSE); \
1767 g_list_free(gchild); \
1768 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1769 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1770 g_list_free(gchild); \
1773 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1774 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1775 gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
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); \
1782 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1783 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1784 GList *gchild = NULL; \
1785 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1786 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1787 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1788 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1789 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1790 child = gtk_bin_get_child(GTK_BIN(item)); \
1791 gchild = gtk_container_get_children( \
1792 GTK_CONTAINER(child)); \
1793 btn = (GtkWidget *)gchild->data; \
1794 gtkut_widget_set_can_focus(btn, FALSE); \
1795 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1796 gtkut_widget_set_can_focus(arr, FALSE); \
1797 g_list_free(gchild); \
1798 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1799 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1800 g_list_free(gchild); \
1804 #define ADD_MENU_ITEM(name,cb,data) { \
1805 item = gtk_menu_item_new_with_mnemonic(name); \
1806 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); \
1807 g_signal_connect(G_OBJECT(item), "activate", \
1810 g_object_set_data(G_OBJECT(item), "int-value", GINT_TO_POINTER(data)); \
1811 gtk_widget_show(item); \
1814 static void toolbar_reply_menu_cb(GtkWidget *widget, gpointer data)
1816 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1817 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1819 toolbar_reply(toolbar_item, GPOINTER_TO_INT(int_value));
1822 static void toolbar_learn_menu_cb(GtkWidget *widget, gpointer data)
1824 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1825 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1827 toolbar_learn(toolbar_item, GPOINTER_TO_INT(int_value));
1831 * Create a new toolbar with specified type
1832 * if a callback list is passed it will be used before the
1833 * common callback list
1835 Toolbar *toolbar_create(ToolbarType type,
1836 GtkWidget *container,
1839 ToolbarItem *toolbar_item;
1842 GtkWidget *icon_wid = NULL;
1843 GtkWidget *icon_news;
1844 GtkWidget *icon_ham;
1846 ToolbarClawsActions *action_item;
1848 GSList *toolbar_list;
1849 Toolbar *toolbar_data;
1851 #ifndef GENERIC_UMPC
1852 #if !(GTK_CHECK_VERSION(2,12,0))
1853 GtkTooltips *toolbar_tips = gtk_tooltips_new();
1856 toolbar_read_config_file(type);
1857 toolbar_list = toolbar_get_list(type);
1859 toolbar_data = g_new0(Toolbar, 1);
1861 toolbar = gtk_toolbar_new();
1863 #if (GTK_CHECK_VERSION(2,16,0))
1864 gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL);
1866 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1868 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1869 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1871 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1873 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1874 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1878 toolbar_item = g_new0(ToolbarItem, 1);
1879 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1880 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1881 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1882 toolbar_item->parent = data;
1883 toolbar_item->type = type;
1885 /* collect toolbar items in list to keep track */
1886 toolbar_data->item_list =
1887 g_slist_append(toolbar_data->item_list,
1889 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1891 switch (toolbar_item->index) {
1894 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1895 toolbar_data->folders_btn = item;
1898 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1899 _("Receive Mail from all Accounts"),
1900 _("Receive Mail from selected Account"));
1901 toolbar_data->getall_btn = item;
1904 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail from current Account"));
1905 toolbar_data->get_btn = item;
1908 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1909 toolbar_data->send_btn = item;
1912 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1913 toolbar_data->close_window_btn = item;
1916 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open preferences"));
1917 toolbar_data->preferences_btn = item;
1920 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1921 toolbar_data->open_mail_btn = item;
1923 case A_COMPOSE_EMAIL:
1924 #ifndef GENERIC_UMPC
1925 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1927 _("Compose with selected Account"));
1928 toolbar_data->compose_mail_btn = item;
1929 toolbar_data->compose_mail_icon = icon_wid;
1930 g_object_ref(toolbar_data->compose_mail_icon);
1932 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1933 toolbar_data->compose_news_icon = icon_news;
1934 g_object_ref(toolbar_data->compose_news_icon);
1936 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1937 _("Compose Email"));
1938 toolbar_data->compose_mail_btn = item;
1939 toolbar_data->compose_mail_icon = icon_wid;
1941 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1942 toolbar_data->compose_news_icon = icon_news;
1946 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1949 toolbar_data->learn_spam_btn = item;
1950 toolbar_data->learn_spam_icon = icon_wid;
1951 g_object_ref(toolbar_data->learn_spam_icon);
1953 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1954 toolbar_data->learn_ham_icon = icon_ham;
1955 g_object_ref(toolbar_data->learn_ham_icon);
1957 menu = gtk_menu_new();
1958 ADD_MENU_ITEM(_("Learn as _Spam"), toolbar_learn_menu_cb, TRUE);
1959 ADD_MENU_ITEM(_("Learn as _Ham"), toolbar_learn_menu_cb, FALSE);
1960 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->learn_spam_btn), menu);
1962 case A_REPLY_MESSAGE:
1963 #ifndef GENERIC_UMPC
1964 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1965 _("Reply to Message"),
1966 _("Reply to Message options"));
1967 toolbar_data->reply_btn = item;
1969 menu = gtk_menu_new();
1970 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITH_QUOTE);
1971 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITHOUT_QUOTE);
1972 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->reply_btn), menu);
1974 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1975 _("Reply to Message"));
1976 toolbar_data->reply_btn = item;
1979 case A_REPLY_SENDER:
1980 #ifndef GENERIC_UMPC
1981 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1982 _("Reply to Sender"),
1983 _("Reply to Sender options"));
1984 toolbar_data->replysender_btn = item;
1986 menu = gtk_menu_new();
1987 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE);
1988 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1989 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replysender_btn), menu);
1991 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1992 _("Reply to Sender"));
1993 toolbar_data->replysender_btn = item;
1997 #ifndef GENERIC_UMPC
1998 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2000 _("Reply to All options"));
2001 toolbar_data->replyall_btn = item;
2003 menu = gtk_menu_new();
2004 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE);
2005 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
2006 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replyall_btn), menu);
2008 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2010 toolbar_data->replyall_btn = item;
2014 #ifndef GENERIC_UMPC
2015 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2016 _("Reply to Mailing-list"),
2017 _("Reply to Mailing-list options"));
2018 toolbar_data->replylist_btn = item;
2020 menu = gtk_menu_new();
2021 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE);
2022 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
2023 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replylist_btn), menu);
2025 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2026 _("Reply to Mailing-list"));
2027 toolbar_data->replylist_btn = item;
2031 #ifndef GENERIC_UMPC
2032 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2033 _("Forward Message"),
2034 _("Forward Message options"));
2035 toolbar_data->fwd_btn = item;
2037 menu = gtk_menu_new();
2038 ADD_MENU_ITEM(_("_Forward"), toolbar_reply_menu_cb, COMPOSE_FORWARD_INLINE);
2039 ADD_MENU_ITEM(_("For_ward as attachment"), toolbar_reply_menu_cb, COMPOSE_FORWARD_AS_ATTACH);
2040 ADD_MENU_ITEM(_("Redirec_t"), toolbar_reply_menu_cb, COMPOSE_REDIRECT);
2041 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->fwd_btn), menu);
2043 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2044 _("Forward Message"));
2045 toolbar_data->fwd_btn = item;
2049 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
2050 toolbar_data->trash_btn = item;
2053 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
2054 toolbar_data->delete_btn = item;
2057 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
2058 toolbar_data->exec_btn = item;
2061 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
2062 toolbar_data->prev_btn = item;
2065 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
2066 toolbar_data->next_btn = item;
2069 /* Compose Toolbar */
2071 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2072 toolbar_data->send_btn = item;
2075 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2076 toolbar_data->sendl_btn = item;
2079 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2080 toolbar_data->draft_btn = item;
2083 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2084 toolbar_data->insert_btn = item;
2087 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2088 toolbar_data->attach_btn = item;
2091 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2092 toolbar_data->sig_btn = item;
2095 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2096 toolbar_data->exteditor_btn = item;
2098 case A_LINEWRAP_CURRENT:
2099 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2100 toolbar_data->linewrap_current_btn = item;
2102 case A_LINEWRAP_ALL:
2103 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2104 toolbar_data->linewrap_all_btn = item;
2107 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2108 toolbar_data->addrbook_btn = item;
2111 case A_CHECK_SPELLING:
2112 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2113 toolbar_data->spellcheck_btn = item;
2117 case A_CLAWS_ACTIONS:
2118 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2119 action_item = g_new0(ToolbarClawsActions, 1);
2120 action_item->widget = item;
2121 action_item->name = g_strdup(toolbar_item->text);
2123 toolbar_data->action_list =
2124 g_slist_append(toolbar_data->action_list,
2128 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2129 toolbar_data->cancel_inc_btn = item;
2131 case A_CLAWS_PLUGINS:
2132 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, toolbar_item->text);
2135 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2136 toolbar_ret_descr_from_val(toolbar_item->index));
2137 /* find and set the tool tip text */
2142 toolbar_data->toolbar = toolbar;
2143 #ifndef GENERIC_UMPC
2144 #if !(GTK_CHECK_VERSION(2,12,0))
2145 toolbar_data->tooltips = toolbar_tips;
2148 gtk_widget_show_all(toolbar);
2150 if (type == TOOLBAR_MAIN) {
2152 MainWindow *mainwin = mainwindow_get_mainwindow();
2153 GtkWidget *progressbar = gtk_progress_bar_new();
2154 item = GTK_WIDGET(gtk_tool_item_new());
2155 gtk_container_add (GTK_CONTAINER (item), progressbar);
2156 gtk_widget_show(item);
2157 gtk_widget_set_size_request(progressbar, 84, -1);
2158 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2159 mainwin->progressbar = progressbar;
2161 activate_compose_button(toolbar_data,
2162 prefs_common.toolbar_style,
2163 toolbar_data->compose_btn_type);
2165 if (type != TOOLBAR_COMPOSE)
2166 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2170 gtk_container_add(GTK_CONTAINER(container), toolbar);
2171 gtk_container_set_border_width(GTK_CONTAINER(container), 0);
2173 if ( GTK_IS_WINDOW(container) ) {
2174 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
2175 gtk_widget_show_all (container);
2177 gtk_container_add(GTK_CONTAINER(container), toolbar);
2178 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2181 return toolbar_data;
2185 * Free toolbar structures
2187 void toolbar_destroy(Toolbar * toolbar) {
2189 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2190 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2193 void toolbar_update(ToolbarType type, gpointer data)
2195 Toolbar *toolbar_data;
2196 GtkWidget *handlebox;
2197 MainWindow *mainwin = (MainWindow*)data;
2198 Compose *compose = (Compose*)data;
2199 MessageView *msgview = (MessageView*)data;
2201 #ifndef GENERIC_UMPC
2204 toolbar_data = mainwin->toolbar;
2205 handlebox = mainwin->handlebox;
2207 case TOOLBAR_COMPOSE:
2208 toolbar_data = compose->toolbar;
2209 handlebox = compose->handlebox;
2211 case TOOLBAR_MSGVIEW:
2212 toolbar_data = msgview->toolbar;
2213 handlebox = msgview->handlebox;
2219 gtk_container_remove(GTK_CONTAINER(handlebox),
2220 GTK_WIDGET(toolbar_data->toolbar));
2222 toolbar_init(toolbar_data);
2223 toolbar_data = toolbar_create(type, handlebox, data);
2227 toolbar_data = mainwin->toolbar;
2228 handlebox = mainwin->window;
2230 case TOOLBAR_COMPOSE:
2231 toolbar_data = compose->toolbar;
2232 handlebox = compose->window;
2234 case TOOLBAR_MSGVIEW:
2235 toolbar_data = msgview->toolbar;
2236 handlebox = msgview->window;
2242 hildon_window_remove_toolbar(HILDON_WINDOW(handlebox), GTK_TOOLBAR(toolbar_data->toolbar));
2244 toolbar_init(toolbar_data);
2245 toolbar_data = toolbar_create(type, handlebox, data);
2250 mainwin->toolbar = toolbar_data;
2252 case TOOLBAR_COMPOSE:
2253 compose->toolbar = toolbar_data;
2255 case TOOLBAR_MSGVIEW:
2256 msgview->toolbar = toolbar_data;
2260 toolbar_style(type, prefs_common.toolbar_style, data);
2262 if (type == TOOLBAR_MAIN) {
2263 toolbar_main_set_sensitive((MainWindow*)data);
2264 account_set_menu_only_toolbar();
2268 #if !GTK_CHECK_VERSION(2,14,0)
2269 /* Work around http://bugzilla.gnome.org/show_bug.cgi?id=56070 */
2270 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2271 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2272 if (GTK_IS_BUTTON(widget)) \
2273 in_btn1 = GTK_BUTTON(widget)->in_button; \
2274 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2275 GtkWidget *child = gtk_bin_get_child( \
2277 GList *gchild = gtk_container_get_children( \
2278 GTK_CONTAINER(child)); \
2279 GtkWidget *btn = (GtkWidget *)gchild->data; \
2280 GtkWidget *arr = (GtkWidget *) \
2281 (gchild->next?gchild->next->data:NULL); \
2282 g_list_free(gchild); \
2283 if (GTK_IS_BUTTON(btn)) \
2284 in_btn1 = GTK_BUTTON(btn)->in_button; \
2285 if (GTK_IS_BUTTON(arr)) \
2286 in_btn2 = GTK_BUTTON(arr)->in_button; \
2288 else if (GTK_IS_TOOL_ITEM(widget)) { \
2289 GtkWidget *child = gtk_bin_get_child( \
2291 if (GTK_IS_BUTTON(child)) \
2292 in_btn1 = GTK_BUTTON(child)->in_button; \
2294 gtk_widget_set_sensitive(widget, sensitive); \
2295 if (GTK_IS_BUTTON(widget)) \
2296 GTK_BUTTON(widget)->in_button = in_btn1; \
2297 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2298 GtkWidget *child = gtk_bin_get_child( \
2300 GList *gchild = gtk_container_get_children( \
2301 GTK_CONTAINER(child)); \
2302 GtkWidget *btn = (GtkWidget *)gchild->data; \
2303 GtkWidget *arr = (GtkWidget *) \
2304 (gchild->next?gchild->next->data:NULL); \
2305 g_list_free(gchild); \
2306 if (GTK_IS_BUTTON(btn)) \
2307 GTK_BUTTON(btn)->in_button = in_btn1; \
2308 if (GTK_IS_BUTTON(arr)) \
2309 GTK_BUTTON(arr)->in_button = in_btn2; \
2311 else if (GTK_IS_TOOL_ITEM(widget)) { \
2312 GtkWidget *child = gtk_bin_get_child( \
2314 if (GTK_IS_BUTTON(child)) \
2315 GTK_BUTTON(child)->in_button = in_btn1; \
2319 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2320 gtk_widget_set_sensitive(widget, sensitive); \
2324 void toolbar_main_set_sensitive(gpointer data)
2326 SensitiveCond state;
2328 MainWindow *mainwin = (MainWindow*)data;
2329 Toolbar *toolbar = mainwin->toolbar;
2331 GSList *entry_list = NULL;
2333 typedef struct _Entry Entry;
2340 #define SET_WIDGET_COND(w, c) \
2342 Entry *e = g_new0(Entry, 1); \
2345 entry_list = g_slist_append(entry_list, e); \
2349 if (toolbar->get_btn)
2350 SET_WIDGET_COND(toolbar->get_btn,
2351 M_HAVE_ACCOUNT|M_UNLOCKED);
2353 if (toolbar->getall_btn) {
2354 SET_WIDGET_COND(toolbar->getall_btn,
2355 M_HAVE_ACCOUNT|M_UNLOCKED);
2357 if (toolbar->send_btn) {
2358 SET_WIDGET_COND(toolbar->send_btn,
2359 M_HAVE_QUEUED_MAILS);
2361 if (toolbar->compose_mail_btn) {
2362 SET_WIDGET_COND(toolbar->compose_mail_btn,
2365 if (toolbar->close_window_btn) {
2366 SET_WIDGET_COND(toolbar->close_window_btn,
2369 if (toolbar->open_mail_btn) {
2370 SET_WIDGET_COND(toolbar->open_mail_btn,
2371 M_TARGET_EXIST|M_SUMMARY_ISLIST);
2373 if (toolbar->reply_btn) {
2374 SET_WIDGET_COND(toolbar->reply_btn,
2375 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2377 if (toolbar->replyall_btn) {
2378 SET_WIDGET_COND(toolbar->replyall_btn,
2379 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2381 if (toolbar->replylist_btn) {
2382 SET_WIDGET_COND(toolbar->replylist_btn,
2383 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2385 if (toolbar->replysender_btn) {
2386 SET_WIDGET_COND(toolbar->replysender_btn,
2387 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2389 if (toolbar->fwd_btn) {
2390 SET_WIDGET_COND(toolbar->fwd_btn,
2391 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2394 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2395 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST|M_SUMMARY_ISLIST);
2397 SET_WIDGET_COND(toolbar->next_btn, 0);
2400 if (toolbar->trash_btn)
2401 SET_WIDGET_COND(toolbar->trash_btn,
2402 M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS);
2404 if (toolbar->delete_btn)
2405 SET_WIDGET_COND(toolbar->delete_btn,
2406 M_TARGET_EXIST|M_ALLOW_DELETE);
2408 if (toolbar->exec_btn)
2409 SET_WIDGET_COND(toolbar->exec_btn,
2412 if (toolbar->learn_spam_btn)
2413 SET_WIDGET_COND(toolbar->learn_spam_btn,
2414 M_TARGET_EXIST|M_CAN_LEARN_SPAM|M_SUMMARY_ISLIST);
2416 if (toolbar->cancel_inc_btn)
2417 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2420 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2421 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2423 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2426 #undef SET_WIDGET_COND
2428 state = main_window_get_current_state(mainwin);
2430 for (cur = entry_list; cur != NULL; cur = cur->next) {
2431 Entry *e = (Entry*) cur->data;
2433 if (e->widget != NULL) {
2434 sensitive = ((e->cond & state) == e->cond);
2435 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2439 while (entry_list != NULL) {
2440 Entry *e = (Entry*) entry_list->data;
2443 entry_list = g_slist_remove(entry_list, e);
2446 g_slist_free(entry_list);
2448 activate_compose_button(toolbar,
2449 prefs_common.toolbar_style,
2450 toolbar->compose_btn_type);
2454 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2456 Compose *compose = (Compose*)data;
2457 GSList *items = compose->toolbar->action_list;
2459 if (compose->toolbar->send_btn)
2460 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2461 if (compose->toolbar->sendl_btn)
2462 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2463 if (compose->toolbar->draft_btn )
2464 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2465 if (compose->toolbar->insert_btn )
2466 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2467 if (compose->toolbar->attach_btn)
2468 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2469 if (compose->toolbar->sig_btn)
2470 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2471 if (compose->toolbar->exteditor_btn)
2472 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2473 if (compose->toolbar->linewrap_current_btn)
2474 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2475 if (compose->toolbar->linewrap_all_btn)
2476 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2477 if (compose->toolbar->addrbook_btn)
2478 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2480 if (compose->toolbar->spellcheck_btn)
2481 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2483 for (; items != NULL; items = g_slist_next(items)) {
2484 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2485 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2490 * Initialize toolbar structure
2492 static void toolbar_init(Toolbar * toolbar)
2495 toolbar->toolbar = NULL;
2496 toolbar->folders_btn = NULL;
2497 toolbar->get_btn = NULL;
2498 toolbar->getall_btn = NULL;
2499 toolbar->send_btn = NULL;
2500 toolbar->compose_mail_btn = NULL;
2501 toolbar->compose_mail_icon = NULL;
2502 toolbar->compose_news_icon = NULL;
2503 toolbar->reply_btn = NULL;
2504 toolbar->replysender_btn = NULL;
2505 toolbar->replyall_btn = NULL;
2506 toolbar->replylist_btn = NULL;
2507 toolbar->fwd_btn = NULL;
2508 toolbar->trash_btn = NULL;
2509 toolbar->delete_btn = NULL;
2510 toolbar->prev_btn = NULL;
2511 toolbar->next_btn = NULL;
2512 toolbar->exec_btn = NULL;
2513 toolbar->open_mail_btn = NULL;
2514 toolbar->close_window_btn = NULL;
2515 /* compose buttons */
2516 toolbar->sendl_btn = NULL;
2517 toolbar->draft_btn = NULL;
2518 toolbar->insert_btn = NULL;
2519 toolbar->attach_btn = NULL;
2520 toolbar->sig_btn = NULL;
2521 toolbar->exteditor_btn = NULL;
2522 toolbar->linewrap_current_btn = NULL;
2523 toolbar->linewrap_all_btn = NULL;
2524 toolbar->addrbook_btn = NULL;
2526 toolbar->spellcheck_btn = NULL;
2529 toolbar_destroy(toolbar);
2534 static void toolbar_reply(gpointer data, guint action)
2536 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2537 MainWindow *mainwin;
2538 MessageView *msgview;
2539 GSList *msginfo_list = NULL;
2541 cm_return_if_fail(toolbar_item != NULL);
2543 switch (toolbar_item->type) {
2545 mainwin = (MainWindow*)toolbar_item->parent;
2546 msginfo_list = summary_get_selection(mainwin->summaryview);
2547 msgview = (MessageView*)mainwin->messageview;
2549 case TOOLBAR_MSGVIEW:
2550 msgview = (MessageView*)toolbar_item->parent;
2551 cm_return_if_fail(msgview != NULL);
2552 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2558 cm_return_if_fail(msgview != NULL);
2559 cm_return_if_fail(msginfo_list != NULL);
2560 compose_reply_from_messageview(msgview, msginfo_list, action);
2561 g_slist_free(msginfo_list);
2563 /* TODO: update reply state ion summaryview */
2567 /* exported functions */
2569 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2571 MainWindow *mainwin = (MainWindow*)data;
2573 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2576 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2578 MainWindow *mainwin = (MainWindow*)data;
2580 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2583 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2587 gboolean got_error = FALSE;
2588 gchar *errstr = NULL;
2590 if (prefs_common.work_offline)
2591 if (alertpanel(_("Offline warning"),
2592 _("You're working offline. Override?"),
2593 GTK_STOCK_NO, GTK_STOCK_YES,
2594 NULL) != G_ALERTALTERNATE)
2597 /* ask for confirmation before sending queued messages only
2598 in online mode and if there is at least one message queued
2599 in any of the folder queue
2601 if (prefs_common.confirm_send_queued_messages) {
2603 /* check if there's a queued message */
2604 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2605 Folder *folder = list->data;
2607 found = !procmsg_queue_is_empty(folder->queue);
2609 /* if necessary, ask for confirmation before sending */
2610 if (found && !prefs_common.work_offline) {
2611 if (alertpanel(_("Send queued messages"),
2612 _("Send all queued messages?"),
2613 GTK_STOCK_CANCEL, _("_Send"),
2614 NULL) != G_ALERTALTERNATE)
2619 for (list = folder_get_list(); list != NULL; list = list->next) {
2620 Folder *folder = list->data;
2622 if (folder->queue) {
2623 if (procmsg_send_queue(folder->queue,
2624 prefs_common.savemsg,
2631 alertpanel_error_log(_("Some errors occurred while "
2632 "sending queued messages."));
2634 alertpanel_error_log(_("Some errors occurred "
2635 "while sending queued messages:\n%s"), errstr);
2641 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2643 MainWindow *mainwin = (MainWindow*)data;
2644 PrefsAccount *ac = NULL;
2645 FolderItem *item = mainwin->summaryview->folder_item;
2650 ac = account_find_from_item(item);
2651 if (ac && ac->protocol != A_NNTP) {
2652 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2658 * CLAWS - use current account
2660 if (cur_account && (cur_account->protocol != A_NNTP)) {
2661 compose_new_with_folderitem(cur_account, item, NULL);
2666 * CLAWS - just get the first one
2668 list = account_get_list();
2669 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2670 ac = (PrefsAccount *) cur->data;
2671 if (ac->protocol != A_NNTP) {
2672 compose_new_with_folderitem(ac, item, NULL);
2678 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2680 MainWindow *mainwin = (MainWindow*)data;
2681 PrefsAccount * ac = NULL;
2685 if (mainwin->summaryview->folder_item) {
2686 ac = mainwin->summaryview->folder_item->folder->account;
2687 if (ac && ac->protocol == A_NNTP) {
2688 compose_new_with_folderitem(ac,
2689 mainwin->summaryview->folder_item, NULL);
2694 list = account_get_list();
2695 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2696 ac = (PrefsAccount *) cur->data;
2697 if (ac->protocol == A_NNTP) {
2698 compose_new_with_folderitem(ac,
2699 mainwin->summaryview->folder_item, NULL);