2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2012 Hiroyuki Yamamoto and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * General functions for accessing address book files.
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"
60 #ifdef USE_NEW_ADDRBOOK
61 #include "addressbook-dbus.h"
65 #define TOOLBAR_TAG_INDEX "toolbar"
66 #define TOOLBAR_TAG_ITEM "item"
67 #define TOOLBAR_TAG_SEPARATOR "separator"
69 #define TOOLBAR_ICON_FILE "file"
70 #define TOOLBAR_ICON_TEXT "text"
71 #define TOOLBAR_ICON_ACTION "action"
73 static void toolbar_init(Toolbar * toolbar);
74 static gboolean toolbar_is_duplicate (gint action,
76 static void toolbar_parse_item (XMLFile *file,
79 static gint toolbar_ret_val_from_text (const gchar *text);
80 static gchar *toolbar_ret_text_from_val (gint val);
82 static void toolbar_set_default_main (void);
83 static void toolbar_set_default_compose (void);
84 static void toolbar_set_default_msgview (void);
86 static void toolbar_style (ToolbarType type,
90 static MainWindow *get_mainwin (gpointer data);
91 static void activate_compose_button (Toolbar *toolbar,
93 ComposeButtonType type);
95 /* toolbar callbacks */
96 static void toolbar_reply (gpointer data,
98 static void toolbar_learn (gpointer data,
100 static void toolbar_delete_cb (GtkWidget *widget,
102 static void toolbar_trash_cb (GtkWidget *widget,
105 static void toolbar_compose_cb (GtkWidget *widget,
108 static void toolbar_learn_cb (GtkWidget *widget,
111 static void toolbar_reply_cb (GtkWidget *widget,
114 static void toolbar_reply_to_all_cb (GtkWidget *widget,
117 static void toolbar_reply_to_list_cb (GtkWidget *widget,
120 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
123 static void toolbar_forward_cb (GtkWidget *widget,
126 static void toolbar_prev_unread_cb (GtkWidget *widget,
128 static void toolbar_next_unread_cb (GtkWidget *widget,
131 static void toolbar_ignore_thread_cb (GtkWidget *widget,
134 static void toolbar_watch_thread_cb (GtkWidget *widget,
137 static void toolbar_print_cb (GtkWidget *widget,
140 static void toolbar_actions_execute_cb (GtkWidget *widget,
142 static void toolbar_plugins_execute_cb (GtkWidget *widget,
146 static void toolbar_send_cb (GtkWidget *widget,
148 static void toolbar_send_later_cb (GtkWidget *widget,
150 static void toolbar_draft_cb (GtkWidget *widget,
152 static void toolbar_close_cb (GtkWidget *widget,
154 static void toolbar_preferences_cb (GtkWidget *widget,
156 static void toolbar_open_mail_cb (GtkWidget *widget,
158 static void toolbar_insert_cb (GtkWidget *widget,
160 static void toolbar_attach_cb (GtkWidget *widget,
162 static void toolbar_sig_cb (GtkWidget *widget,
164 static void toolbar_ext_editor_cb (GtkWidget *widget,
166 static void toolbar_linewrap_current_cb (GtkWidget *widget,
168 static void toolbar_linewrap_all_cb (GtkWidget *widget,
170 static void toolbar_addrbook_cb (GtkWidget *widget,
173 static void toolbar_check_spelling_cb (GtkWidget *widget,
176 static void toolbar_cancel_inc_cb (GtkWidget *widget,
182 } toolbar_text [] = {
183 { "A_RECEIVE_ALL", N_("Receive Mail from all Accounts") },
184 { "A_RECEIVE_CUR", N_("Receive Mail from current Account") },
185 { "A_SEND_QUEUED", N_("Send Queued Messages") },
186 { "A_COMPOSE_EMAIL", N_("Compose Email") },
187 { "A_COMPOSE_NEWS", N_("Compose News") },
188 { "A_REPLY_MESSAGE", N_("Reply to Message") },
189 { "A_REPLY_SENDER", N_("Reply to Sender") },
190 { "A_REPLY_ALL", N_("Reply to All") },
191 { "A_REPLY_ML", N_("Reply to Mailing-list") },
192 { "A_OPEN_MAIL", N_("Open email") },
193 { "A_FORWARD", N_("Forward Message") },
194 { "A_TRASH", N_("Trash Message") },
195 { "A_DELETE_REAL", N_("Delete Message") },
196 { "A_EXECUTE", N_("Execute") },
197 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
198 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
199 { "A_IGNORE_THREAD", N_("Ignore thread") },
200 { "A_WATCH_THREAD", N_("Watch thread") },
201 { "A_PRINT", N_("Print") },
202 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
203 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
204 { "A_PREFERENCES", N_("Preferences") },
206 { "A_SEND", N_("Send Message") },
207 { "A_SENDL", N_("Put into queue folder and send later") },
208 { "A_DRAFT", N_("Save to draft folder") },
209 { "A_INSERT", N_("Insert file") },
210 { "A_ATTACH", N_("Attach file") },
211 { "A_SIG", N_("Insert signature") },
212 { "A_EXTEDITOR", N_("Edit with external editor") },
213 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
214 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
215 { "A_ADDRBOOK", N_("Address book") },
217 { "A_CHECK_SPELLING", N_("Check spelling") },
219 { "A_CLAWS_ACTIONS", N_("Claws Mail Actions Feature") },
220 { "A_CANCEL_INC", N_("Cancel receiving") },
221 { "A_CLOSE", N_("Close window") },
222 { "A_SEPARATOR", N_("Separator") },
223 { "A_CLAWS_PLUGINS", N_("Claws Mail Plugins") },
226 /* struct holds configuration files and a list of
227 * currently active toolbar items
228 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
232 const gchar *conf_file;
234 } toolbar_config[3] = {
235 { "toolbar_main.xml", NULL},
236 { "toolbar_compose.xml", NULL},
237 { "toolbar_msgview.xml", NULL}
240 gint toolbar_ret_val_from_descr(const gchar *descr)
244 for (i = 0; i < N_ACTION_VAL; i++) {
245 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
252 gchar *toolbar_ret_descr_from_val(gint val)
254 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
256 return gettext(toolbar_text[val].descr);
259 static gint toolbar_ret_val_from_text(const gchar *text)
263 for (i = 0; i < N_ACTION_VAL; i++) {
264 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
271 static gchar *toolbar_ret_text_from_val(gint val)
273 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
275 return toolbar_text[val].index_str;
278 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
282 if ((action == A_SEPARATOR) || (action == A_CLAWS_ACTIONS) || (action == A_CLAWS_PLUGINS))
285 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
286 ToolbarItem *item = (ToolbarItem*) cur->data;
288 if (item->index == action)
294 /* depending on toolbar type this function
295 returns a list of available toolbar events being
296 displayed by prefs_toolbar
298 GList *toolbar_get_action_items(ToolbarType source)
303 if (source == TOOLBAR_MAIN) {
304 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
305 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
306 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
307 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
308 A_GOTO_NEXT, A_IGNORE_THREAD, A_WATCH_THREAD, A_PRINT,
309 A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
310 A_CANCEL_INC, A_PREFERENCES };
312 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
313 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
316 else if (source == TOOLBAR_COMPOSE) {
317 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
318 A_INSERT, A_ATTACH, A_SIG,
319 A_EXTEDITOR, A_LINEWRAP_CURRENT,
320 A_LINEWRAP_ALL, A_ADDRBOOK,
326 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
327 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
329 else if (source == TOOLBAR_MSGVIEW) {
330 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
331 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
332 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
333 A_ADDRBOOK, A_LEARN_SPAM, A_CLOSE };
335 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
336 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
342 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
346 ToolbarItem *item = NULL;
347 gboolean rewrite = FALSE;
349 attr = xml_get_current_tag_attr(file);
350 item = g_new0(ToolbarItem, 1);
352 name = ((XMLAttr *)attr->data)->name;
353 value = ((XMLAttr *)attr->data)->value;
355 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
356 item->file = g_strdup (value);
357 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
358 item->text = g_strdup (*value ? gettext(value):"");
359 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
360 item->index = toolbar_ret_val_from_text(value);
361 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
363 item->index = A_TRASH;
365 item->file = g_strdup("trash_btn");
367 item->text = g_strdup(Q_("Toolbar|Trash"));
370 if (item->index == -1 && !strcmp(value, "A_SYL_ACTIONS")) {
372 item->index = A_CLAWS_ACTIONS;
375 attr = g_list_next(attr);
377 if (item->index != -1) {
379 if (!toolbar_is_duplicate(item->index, source))
380 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
384 toolbar_save_config_file(source);
388 const gchar *toolbar_get_short_text(int action) {
390 case A_GO_FOLDERS: return _("Folders");
391 case A_OPEN_MAIL: return _("Open");
392 case A_RECEIVE_ALL: return _("Get Mail");
393 case A_RECEIVE_CUR: return _("Get");
394 case A_SEND_QUEUED: return _("Send");
395 case A_COMPOSE_EMAIL: return Q_("Toolbar|Compose");
396 case A_COMPOSE_NEWS: return Q_("Toolbar|Compose");
397 case A_REPLY_MESSAGE: return _("Reply");
398 case A_REPLY_ALL: return _("All");
399 case A_REPLY_SENDER: return Q_("Toolbar|Sender");
400 case A_REPLY_ML: return _("List");
401 case A_FORWARD: return _("Forward");
402 case A_TRASH: return Q_("Toolbar|Trash");
403 case A_DELETE_REAL: return _("Delete");
404 case A_LEARN_SPAM: return _("Spam");
405 case A_GOTO_PREV: return _("Prev");
406 case A_GOTO_NEXT: return _("Next");
407 case A_IGNORE_THREAD: return _("Ignore thread");
408 case A_WATCH_THREAD: return _("Watch thread");
409 case A_PRINT: return _("Print");
410 case A_CLOSE: return _("Close");
411 case A_PREFERENCES: return _("Preferences");
412 case A_SEND: return _("Send");
413 case A_SENDL: return _("Send later");
414 case A_DRAFT: return _("Draft");
415 case A_INSERT: return _("Insert");
416 case A_ATTACH: return _("Attach");
417 case A_SIG: return _("Insert sig.");
418 case A_EXTEDITOR: return _("Edit");
419 case A_LINEWRAP_CURRENT:return _("Wrap para.");
420 case A_LINEWRAP_ALL: return _("Wrap all");
421 case A_ADDRBOOK: return _("Address");
422 case A_CANCEL_INC: return _("Stop");
423 case A_EXECUTE: return _("Execute");
425 case A_CHECK_SPELLING: return _("Check spelling");
431 gint toolbar_get_icon(int action) {
433 case A_GO_FOLDERS: return STOCK_PIXMAP_GO_FOLDERS;
434 case A_OPEN_MAIL: return STOCK_PIXMAP_OPEN_MAIL;
435 case A_RECEIVE_ALL: return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
436 case A_RECEIVE_CUR: return STOCK_PIXMAP_MAIL_RECEIVE;
437 case A_SEND_QUEUED: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
438 case A_COMPOSE_EMAIL: return STOCK_PIXMAP_MAIL_COMPOSE;
439 case A_COMPOSE_NEWS: return STOCK_PIXMAP_NEWS_COMPOSE;
440 case A_REPLY_MESSAGE: return STOCK_PIXMAP_MAIL_REPLY;
441 case A_REPLY_ALL: return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
442 case A_REPLY_SENDER: return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
443 case A_REPLY_ML: return STOCK_PIXMAP_MAIL_REPLY_TO_LIST;
444 case A_FORWARD: return STOCK_PIXMAP_MAIL_FORWARD;
445 case A_TRASH: return STOCK_PIXMAP_TRASH;
446 case A_DELETE_REAL: return STOCK_PIXMAP_DELETE;
447 case A_LEARN_SPAM: return STOCK_PIXMAP_SPAM_BTN;
448 case A_GOTO_PREV: return STOCK_PIXMAP_UP_ARROW;
449 case A_GOTO_NEXT: return STOCK_PIXMAP_DOWN_ARROW;
450 case A_IGNORE_THREAD: return STOCK_PIXMAP_IGNORETHREAD;
451 case A_WATCH_THREAD: return STOCK_PIXMAP_WATCHTHREAD;
452 case A_PRINT: return STOCK_PIXMAP_PRINTER;
453 case A_CLOSE: return STOCK_PIXMAP_CLOSE;
454 case A_PREFERENCES: return STOCK_PIXMAP_PREFERENCES;
455 case A_SEND: return STOCK_PIXMAP_MAIL_SEND;
456 case A_SENDL: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
457 case A_DRAFT: return STOCK_PIXMAP_MAIL;
458 case A_INSERT: return STOCK_PIXMAP_INSERT_FILE;
459 case A_ATTACH: return STOCK_PIXMAP_MAIL_ATTACH;
460 case A_SIG: return STOCK_PIXMAP_MAIL_SIGN;
461 case A_EXTEDITOR: return STOCK_PIXMAP_EDIT_EXTERN;
462 case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
463 case A_LINEWRAP_ALL: return STOCK_PIXMAP_LINEWRAP_ALL;
464 case A_ADDRBOOK: return STOCK_PIXMAP_ADDRESS_BOOK;
465 case A_CANCEL_INC: return STOCK_PIXMAP_CANCEL;
466 case A_EXECUTE: return STOCK_PIXMAP_EXEC;
468 case A_CHECK_SPELLING: return STOCK_PIXMAP_CHECK_SPELLING;
474 static void toolbar_set_default_main(void)
478 } default_toolbar[] = {
506 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
508 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
510 if (default_toolbar[i].action != A_SEPARATOR) {
513 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
514 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
517 toolbar_item->file = g_strdup(file);
518 toolbar_item->index = default_toolbar[i].action;
519 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
522 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
523 toolbar_item->index = A_SEPARATOR;
526 if (toolbar_item->index != -1) {
527 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
528 toolbar_config[TOOLBAR_MAIN].item_list =
529 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
534 static void toolbar_set_default_compose(void)
538 } default_toolbar[] = {
557 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
559 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
561 if (default_toolbar[i].action != A_SEPARATOR) {
564 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
565 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
567 toolbar_item->file = g_strdup(file);
568 toolbar_item->index = default_toolbar[i].action;
569 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
572 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
573 toolbar_item->index = A_SEPARATOR;
576 if (toolbar_item->index != -1) {
577 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
578 toolbar_config[TOOLBAR_COMPOSE].item_list =
579 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
584 static void toolbar_set_default_msgview(void)
588 } default_toolbar[] = {
607 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
609 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
611 if (default_toolbar[i].action != A_SEPARATOR) {
613 if (toolbar_get_icon(default_toolbar[i].action) > -1) {
614 file = stock_pixmap_get_name((StockPixmap)toolbar_get_icon(default_toolbar[i].action));
617 toolbar_item->file = g_strdup(file);
618 toolbar_item->index = default_toolbar[i].action;
619 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
622 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
623 toolbar_item->index = A_SEPARATOR;
626 if (toolbar_item->index != -1) {
627 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
628 toolbar_config[TOOLBAR_MSGVIEW].item_list =
629 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
634 void toolbar_set_default(ToolbarType source)
636 if (source == TOOLBAR_MAIN)
637 toolbar_set_default_main();
638 else if (source == TOOLBAR_COMPOSE)
639 toolbar_set_default_compose();
640 else if (source == TOOLBAR_MSGVIEW)
641 toolbar_set_default_msgview();
644 void toolbar_save_config_file(ToolbarType source)
649 gchar *fileSpec = NULL;
651 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
653 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
654 pfile = prefs_write_open(fileSpec);
657 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
660 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
663 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
664 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
666 if (toolbar_item->index != A_SEPARATOR) {
667 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
669 TOOLBAR_ICON_FILE, toolbar_item->file,
670 TOOLBAR_ICON_TEXT) < 0)
672 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
674 if (fprintf(fp, "\" %s=\"%s\"/>\n",
676 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
679 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
684 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
688 if (prefs_file_close (pfile) < 0 )
689 g_warning("failed to write toolbar configuration to file\n");
693 FILE_OP_ERROR(fileSpec, "fprintf");
695 prefs_file_close_revert (pfile);
697 g_warning("failed to open toolbar configuration file for writing\n");
700 void toolbar_read_config_file(ToolbarType source)
702 XMLFile *file = NULL;
703 gchar *fileSpec = NULL;
708 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
710 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
711 file = xml_open_file(fileSpec);
714 toolbar_clear_list(source);
718 || (xml_get_dtd(file))
719 || (xml_parse_next_tag(file))
720 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
721 xml_close_file(file);
725 attr = xml_get_current_tag_attr(file);
732 if (xml_parse_next_tag(file))
735 /* Get next tag (icon, icon_text or icon_action) */
736 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
737 toolbar_parse_item(file, source);
738 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
739 ToolbarItem *item = g_new0(ToolbarItem, 1);
741 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
742 item->index = A_SEPARATOR;
743 toolbar_config[source].item_list =
744 g_slist_append(toolbar_config[source].item_list, item);
748 xml_close_file(file);
751 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
753 if (source == TOOLBAR_MAIN)
754 toolbar_set_default(TOOLBAR_MAIN);
755 else if (source == TOOLBAR_COMPOSE)
756 toolbar_set_default(TOOLBAR_COMPOSE);
757 else if (source == TOOLBAR_MSGVIEW)
758 toolbar_set_default(TOOLBAR_MSGVIEW);
760 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
764 toolbar_save_config_file(source);
769 * clears list of toolbar items read from configuration files
771 void toolbar_clear_list(ToolbarType source)
773 while (toolbar_config[source].item_list != NULL) {
774 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
776 toolbar_config[source].item_list =
777 g_slist_remove(toolbar_config[source].item_list, item);
783 g_slist_free(toolbar_config[source].item_list);
788 * return list of Toolbar items
790 GSList *toolbar_get_list(ToolbarType source)
794 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
795 list = toolbar_config[source].item_list;
800 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
802 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
804 toolbar_item->file = g_strdup(t_item->file);
805 toolbar_item->text = g_strdup(t_item->text);
806 toolbar_item->index = t_item->index;
808 toolbar_config[source].item_list =
809 g_slist_append(toolbar_config[source].item_list,
813 static void toolbar_action_execute(GtkWidget *widget,
821 for (cur = action_list; cur != NULL; cur = cur->next) {
822 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
824 if (widget == act->widget) {
825 i = prefs_actions_find_by_name(act->name);
833 actions_execute(data, i, widget, source);
835 g_warning ("Error: did not find Claws Action to execute");
838 gboolean toolbar_check_action_btns(ToolbarType type)
840 GSList *temp, *curr, *list = toolbar_config[type].item_list;
841 gboolean modified = FALSE;
844 while (curr != NULL) {
845 ToolbarItem *toolbar_item = (ToolbarItem *) curr->data;
849 if (toolbar_item->index != A_CLAWS_ACTIONS)
852 if (prefs_actions_find_by_name(toolbar_item->text) == -1) {
853 list = g_slist_delete_link(list, temp);
854 g_free(toolbar_item->file);
855 g_free(toolbar_item->text);
856 g_free(toolbar_item);
864 #if !(GTK_CHECK_VERSION(2,12,0))
865 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
866 gtk_tool_item_set_tooltip(GTK_TOOL_ITEM(widget), GTK_TOOLTIPS(toolbar_tips), \
870 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
871 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), tip); \
875 #if !(GTK_CHECK_VERSION(2,12,0))
876 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
877 gtk_menu_tool_button_set_arrow_tooltip(GTK_MENU_TOOL_BUTTON(widget), GTK_TOOLTIPS(toolbar_tips), \
881 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
882 gtk_menu_tool_button_set_arrow_tooltip_text(GTK_MENU_TOOL_BUTTON(widget), tip); \
886 static void activate_compose_button (Toolbar *toolbar,
888 ComposeButtonType type)
890 #if !(GTK_CHECK_VERSION(2,12,0))
891 GtkTooltips *toolbar_tips = toolbar->tooltips;
893 if ((!toolbar->compose_mail_btn))
896 if (type == COMPOSEBUTTON_NEWS) {
897 gtk_tool_button_set_icon_widget(
898 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
899 toolbar->compose_news_icon);
901 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose News message"));
903 gtk_widget_show(toolbar->compose_news_icon);
905 gtk_tool_button_set_icon_widget(
906 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
907 toolbar->compose_mail_icon);
909 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose Email"));
911 gtk_widget_show(toolbar->compose_mail_icon);
913 toolbar->compose_btn_type = type;
916 void toolbar_set_compose_button(Toolbar *toolbar,
917 ComposeButtonType compose_btn_type)
919 if (toolbar->compose_btn_type != compose_btn_type)
920 activate_compose_button(toolbar,
921 prefs_common.toolbar_style,
925 static void activate_learn_button (Toolbar *toolbar,
927 LearnButtonType type)
929 #if !(GTK_CHECK_VERSION(2,12,0))
930 GtkTooltips *toolbar_tips = toolbar->tooltips;
932 if ((!toolbar->learn_spam_btn))
935 if (type == LEARN_SPAM) {
936 gtk_tool_button_set_icon_widget(
937 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
938 toolbar->learn_spam_icon);
939 gtk_tool_button_set_label(
940 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
943 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn spam"));
945 gtk_widget_show(toolbar->learn_spam_icon);
947 gtk_tool_button_set_icon_widget(
948 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
949 toolbar->learn_ham_icon);
950 gtk_tool_button_set_label(
951 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
954 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn ham"));
956 gtk_widget_show(toolbar->learn_ham_icon);
958 toolbar->learn_btn_type = type;
961 void toolbar_set_learn_button(Toolbar *toolbar,
962 LearnButtonType learn_btn_type)
964 if (toolbar->learn_btn_type != learn_btn_type)
965 activate_learn_button(toolbar,
966 prefs_common.toolbar_style,
970 void toolbar_toggle(guint action, gpointer data)
972 MainWindow *mainwin = (MainWindow*)data;
976 cm_return_if_fail(mainwin != NULL);
978 toolbar_style(TOOLBAR_MAIN, action, mainwin);
980 list = compose_get_compose_list();
981 for (cur = list; cur != NULL; cur = cur->next) {
982 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
984 list = messageview_get_msgview_list();
985 for (cur = list; cur != NULL; cur = cur->next) {
986 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
991 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
993 switch ((ToolbarStyle)action) {
995 gtk_widget_hide(handlebox_wid);
998 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1002 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1006 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1009 case TOOLBAR_BOTH_HORIZ:
1010 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1011 GTK_TOOLBAR_BOTH_HORIZ);
1017 prefs_common.toolbar_style = (ToolbarStyle)action;
1018 gtk_widget_set_size_request(handlebox_wid, 1, -1);
1020 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1021 gtk_widget_show(handlebox_wid);
1022 gtk_widget_queue_resize(handlebox_wid);
1026 * Change the style of toolbar
1028 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1030 GtkWidget *handlebox_wid;
1031 GtkWidget *toolbar_wid;
1032 MainWindow *mainwin = (MainWindow*)data;
1033 Compose *compose = (Compose*)data;
1034 MessageView *msgview = (MessageView*)data;
1036 cm_return_if_fail(data != NULL);
1040 handlebox_wid = mainwin->handlebox;
1041 toolbar_wid = mainwin->toolbar->toolbar;
1043 case TOOLBAR_COMPOSE:
1044 handlebox_wid = compose->handlebox;
1045 toolbar_wid = compose->toolbar->toolbar;
1047 case TOOLBAR_MSGVIEW:
1048 handlebox_wid = msgview->handlebox;
1049 toolbar_wid = msgview->toolbar->toolbar;
1055 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1058 /* Toolbar handling */
1059 static void toolbar_inc_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_mail_cb(mainwin, 0, NULL);
1077 static void toolbar_inc_all_cb(GtkWidget *widget,
1080 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1081 MainWindow *mainwin;
1083 cm_return_if_fail(toolbar_item != NULL);
1085 switch (toolbar_item->type) {
1087 mainwin = (MainWindow*)toolbar_item->parent;
1088 inc_all_account_mail_cb(mainwin, 0, NULL);
1095 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1097 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1098 MainWindow *mainwin;
1100 cm_return_if_fail(toolbar_item != NULL);
1102 switch (toolbar_item->type) {
1104 mainwin = (MainWindow*)toolbar_item->parent;
1105 send_queue_cb(mainwin, 0, NULL);
1112 static void toolbar_exec_cb(GtkWidget *widget,
1115 MainWindow *mainwin = get_mainwin(data);
1117 cm_return_if_fail(mainwin != NULL);
1118 summary_execute(mainwin->summaryview);
1122 * Delete current/selected(s) message(s)
1124 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1126 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1127 MainWindow *mainwin;
1129 cm_return_if_fail(toolbar_item != NULL);
1130 cm_return_if_fail(toolbar_item->parent);
1132 switch (toolbar_item->type) {
1133 case TOOLBAR_MSGVIEW:
1134 messageview_delete((MessageView *)toolbar_item->parent);
1137 mainwin = (MainWindow *)toolbar_item->parent;
1138 summary_delete_trash(mainwin->summaryview);
1141 debug_print("toolbar event not supported\n");
1147 * Delete current/selected(s) message(s)
1149 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1151 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1152 MainWindow *mainwin;
1154 cm_return_if_fail(toolbar_item != NULL);
1155 cm_return_if_fail(toolbar_item->parent);
1157 switch (toolbar_item->type) {
1158 case TOOLBAR_MSGVIEW:
1159 messageview_delete((MessageView *)toolbar_item->parent);
1162 mainwin = (MainWindow *)toolbar_item->parent;
1163 summary_delete(mainwin->summaryview);
1166 debug_print("toolbar event not supported\n");
1173 * Compose new message
1175 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1177 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1178 MainWindow *mainwin;
1179 MessageView *msgview;
1181 cm_return_if_fail(toolbar_item != NULL);
1183 switch (toolbar_item->type) {
1185 mainwin = (MainWindow*)toolbar_item->parent;
1186 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1187 compose_news_cb(mainwin, 0, NULL);
1189 compose_mail_cb(mainwin, 0, NULL);
1191 case TOOLBAR_MSGVIEW:
1192 msgview = (MessageView*)toolbar_item->parent;
1193 compose_new_with_folderitem(NULL,
1194 msgview->msginfo->folder, NULL);
1197 debug_print("toolbar event not supported\n");
1201 static void toolbar_learn(gpointer data, guint as_spam)
1203 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1204 MainWindow *mainwin;
1205 MessageView *msgview;
1207 cm_return_if_fail(toolbar_item != NULL);
1209 switch (toolbar_item->type) {
1211 mainwin = (MainWindow*)toolbar_item->parent;
1213 mainwindow_learn(mainwin, TRUE);
1215 mainwindow_learn(mainwin, FALSE);
1217 case TOOLBAR_MSGVIEW:
1218 msgview = (MessageView*)toolbar_item->parent;
1220 messageview_learn(msgview, TRUE);
1222 messageview_learn(msgview, FALSE);
1225 debug_print("toolbar event not supported\n");
1229 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1231 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1232 MainWindow *mainwin;
1233 MessageView *msgview;
1235 cm_return_if_fail(toolbar_item != NULL);
1237 switch (toolbar_item->type) {
1239 mainwin = (MainWindow*)toolbar_item->parent;
1240 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1241 mainwindow_learn(mainwin, TRUE);
1243 mainwindow_learn(mainwin, FALSE);
1245 case TOOLBAR_MSGVIEW:
1246 msgview = (MessageView*)toolbar_item->parent;
1247 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1248 messageview_learn(msgview, TRUE);
1250 messageview_learn(msgview, FALSE);
1253 debug_print("toolbar event not supported\n");
1261 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1263 toolbar_reply(data, (prefs_common.reply_with_quote ?
1264 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE));
1269 * Reply message to Sender and All recipients
1271 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1274 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1275 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE));
1280 * Reply to Mailing List
1282 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1285 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1286 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE));
1291 * Reply to sender of message
1293 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1296 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1297 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE));
1303 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1305 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1308 cm_return_if_fail(toolbar_item != NULL);
1310 switch (toolbar_item->type) {
1312 case TOOLBAR_MSGVIEW:
1315 case TOOLBAR_COMPOSE:
1316 compose = (Compose *)toolbar_item->parent;
1321 #ifndef USE_NEW_ADDRBOOK
1322 addressbook_open(compose);
1324 GError* error = NULL;
1325 addressbook_connect_signals(compose);
1326 addressbook_dbus_open(TRUE, &error);
1328 g_warning("%s", error->message);
1329 g_error_free(error);
1336 * Forward current/selected(s) message(s)
1338 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1340 toolbar_reply(data, (COMPOSE_FORWARD));
1344 * Goto Prev Unread Message
1346 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1348 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1349 MainWindow *mainwin;
1350 MessageView *msgview;
1352 cm_return_if_fail(toolbar_item != NULL);
1354 switch (toolbar_item->type) {
1356 mainwin = (MainWindow*)toolbar_item->parent;
1357 summary_select_prev_unread(mainwin->summaryview);
1360 case TOOLBAR_MSGVIEW:
1361 msgview = (MessageView*)toolbar_item->parent;
1362 msgview->updating = TRUE;
1363 summary_select_prev_unread(msgview->mainwin->summaryview);
1364 msgview->updating = FALSE;
1366 if (msgview->deferred_destroy) {
1367 debug_print("messageview got away!\n");
1368 messageview_destroy(msgview);
1372 /* Now we need to update the messageview window */
1373 if (msgview->mainwin->summaryview->selected) {
1374 #ifndef GENERIC_UMPC
1375 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1378 messageview_show(msgview, msginfo,
1379 msgview->all_headers);
1382 gtk_widget_destroy(msgview->window);
1386 debug_print("toolbar event not supported\n");
1391 * Goto Next Unread Message
1393 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1395 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1396 MainWindow *mainwin;
1397 MessageView *msgview;
1399 cm_return_if_fail(toolbar_item != NULL);
1401 switch (toolbar_item->type) {
1403 mainwin = (MainWindow*)toolbar_item->parent;
1404 summary_select_next_unread(mainwin->summaryview);
1407 case TOOLBAR_MSGVIEW:
1408 msgview = (MessageView*)toolbar_item->parent;
1409 msgview->updating = TRUE;
1410 summary_select_next_unread(msgview->mainwin->summaryview);
1411 msgview->updating = FALSE;
1413 if (msgview->deferred_destroy) {
1414 debug_print("messageview got away!\n");
1415 messageview_destroy(msgview);
1419 /* Now we need to update the messageview window */
1420 if (msgview->mainwin->summaryview->selected) {
1421 #ifndef GENERIC_UMPC
1422 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1425 messageview_show(msgview, msginfo,
1426 msgview->all_headers);
1429 gtk_widget_destroy(msgview->window);
1433 debug_print("toolbar event not supported\n");
1437 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1439 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1440 MainWindow *mainwin;
1442 cm_return_if_fail(toolbar_item != NULL);
1444 switch (toolbar_item->type) {
1446 mainwin = (MainWindow *) toolbar_item->parent;
1447 summary_toggle_ignore_thread(mainwin->summaryview);
1449 case TOOLBAR_MSGVIEW:
1450 /* TODO: see toolbar_next_unread_cb() if you need
1451 * this in the message view */
1454 debug_print("toolbar event not supported\n");
1459 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1461 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1462 MainWindow *mainwin;
1464 cm_return_if_fail(toolbar_item != NULL);
1466 switch (toolbar_item->type) {
1468 mainwin = (MainWindow *) toolbar_item->parent;
1469 summary_toggle_watch_thread(mainwin->summaryview);
1471 case TOOLBAR_MSGVIEW:
1472 /* TODO: see toolbar_next_unread_cb() if you need
1473 * this in the message view */
1476 debug_print("toolbar event not supported\n");
1481 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1483 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1485 cm_return_if_fail(toolbar_item != NULL);
1491 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1493 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1494 MainWindow *mainwin;
1496 cm_return_if_fail(toolbar_item != NULL);
1498 switch (toolbar_item->type) {
1500 mainwin = (MainWindow *) toolbar_item->parent;
1501 summary_print(mainwin->summaryview);
1503 case TOOLBAR_MSGVIEW:
1504 /* TODO: see toolbar_next_unread_cb() if you need
1505 * this in the message view */
1508 debug_print("toolbar event not supported\n");
1513 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1515 compose_toolbar_cb(A_SEND, data);
1518 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1520 compose_toolbar_cb(A_SENDL, data);
1523 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1525 compose_toolbar_cb(A_DRAFT, data);
1528 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1530 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1531 MainWindow *mainwin;
1532 MessageView *messageview;
1535 cm_return_if_fail(toolbar_item != NULL);
1537 switch (toolbar_item->type) {
1539 mainwin = (MainWindow *) toolbar_item->parent;
1540 app_will_exit(NULL, mainwin);
1542 case TOOLBAR_MSGVIEW:
1543 messageview = (MessageView *)toolbar_item->parent;
1544 messageview_destroy(messageview);
1546 case TOOLBAR_COMPOSE:
1547 compose = (Compose *)toolbar_item->parent;
1548 compose_close_toolbar(compose);
1553 static void toolbar_preferences_cb(GtkWidget *widget, gpointer data)
1558 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1560 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1561 MainWindow *mainwin;
1563 cm_return_if_fail(toolbar_item != NULL);
1565 switch (toolbar_item->type) {
1567 mainwin = (MainWindow *) toolbar_item->parent;
1568 summary_open_row(NULL, mainwin->summaryview);
1570 case TOOLBAR_MSGVIEW:
1571 debug_print("toolbar event not supported\n");
1573 case TOOLBAR_COMPOSE:
1574 debug_print("toolbar event not supported\n");
1579 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1581 compose_toolbar_cb(A_INSERT, data);
1584 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1586 compose_toolbar_cb(A_ATTACH, data);
1589 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1591 compose_toolbar_cb(A_SIG, data);
1594 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1596 compose_toolbar_cb(A_EXTEDITOR, data);
1599 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1601 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1604 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1606 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1610 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1612 compose_toolbar_cb(A_CHECK_SPELLING, data);
1616 * Execute actions from toolbar
1618 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1620 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1621 GSList *action_list;
1622 MainWindow *mainwin;
1624 MessageView *msgview;
1625 gpointer parent = toolbar_item->parent;
1627 cm_return_if_fail(toolbar_item != NULL);
1629 switch (toolbar_item->type) {
1631 mainwin = (MainWindow*)parent;
1632 action_list = mainwin->toolbar->action_list;
1634 case TOOLBAR_COMPOSE:
1635 compose = (Compose*)parent;
1636 action_list = compose->toolbar->action_list;
1638 case TOOLBAR_MSGVIEW:
1639 msgview = (MessageView*)parent;
1640 action_list = msgview->toolbar->action_list;
1643 debug_print("toolbar event not supported\n");
1646 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1649 static void toolbar_plugins_execute_cb(GtkWidget *widget, gpointer data)
1651 ToolbarItem *toolbar_item = data;
1652 prefs_toolbar_execute_plugin_item(toolbar_item->parent, toolbar_item->type, toolbar_item->text);
1655 static MainWindow *get_mainwin(gpointer data)
1657 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1658 MainWindow *mainwin = NULL;
1659 MessageView *msgview;
1661 cm_return_val_if_fail(toolbar_item != NULL, NULL);
1663 switch(toolbar_item->type) {
1665 mainwin = (MainWindow*)toolbar_item->parent;
1667 case TOOLBAR_MSGVIEW:
1668 msgview = (MessageView*)toolbar_item->parent;
1669 mainwin = (MainWindow*)msgview->mainwin;
1678 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
1680 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1681 MainWindow *mainwin = NULL;
1682 switch(toolbar_item->type) {
1684 mainwin = (MainWindow*)toolbar_item->parent;
1687 g_warning("wrong toolbar type\n");
1691 if (!mainwin->in_folder) {
1692 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
1694 folderview_select(mainwin->folderview, item);
1697 gtk_widget_grab_focus(mainwin->folderview->ctree);
1698 mainwindow_exit_folder(mainwin);
1702 static void toolbar_buttons_cb(GtkWidget *widget,
1709 void (*func)(GtkWidget *widget, gpointer data);
1711 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1712 { A_RECEIVE_CUR, toolbar_inc_cb },
1713 { A_SEND_QUEUED, toolbar_send_queued_cb },
1714 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1715 { A_COMPOSE_NEWS, toolbar_compose_cb },
1716 { A_REPLY_MESSAGE, toolbar_reply_cb },
1717 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1718 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1719 { A_REPLY_ML, toolbar_reply_to_list_cb },
1720 { A_FORWARD, toolbar_forward_cb },
1721 { A_TRASH, toolbar_trash_cb },
1722 { A_DELETE_REAL, toolbar_delete_cb },
1723 { A_EXECUTE, toolbar_exec_cb },
1724 { A_GOTO_PREV, toolbar_prev_unread_cb },
1725 { A_GOTO_NEXT, toolbar_next_unread_cb },
1726 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1727 { A_WATCH_THREAD, toolbar_watch_thread_cb },
1728 { A_PRINT, toolbar_print_cb },
1729 { A_LEARN_SPAM, toolbar_learn_cb },
1730 { A_GO_FOLDERS, toolbar_go_folders_cb },
1732 { A_SEND, toolbar_send_cb },
1733 { A_SENDL, toolbar_send_later_cb },
1734 { A_DRAFT, toolbar_draft_cb },
1735 { A_OPEN_MAIL, toolbar_open_mail_cb },
1736 { A_CLOSE, toolbar_close_cb },
1737 { A_PREFERENCES, toolbar_preferences_cb },
1738 { A_INSERT, toolbar_insert_cb },
1739 { A_ATTACH, toolbar_attach_cb },
1740 { A_SIG, toolbar_sig_cb },
1741 { A_EXTEDITOR, toolbar_ext_editor_cb },
1742 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1743 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1744 { A_ADDRBOOK, toolbar_addrbook_cb },
1746 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1748 { A_CLAWS_ACTIONS, toolbar_actions_execute_cb },
1749 { A_CANCEL_INC, toolbar_cancel_inc_cb },
1750 { A_CLAWS_PLUGINS, toolbar_plugins_execute_cb },
1753 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1755 for (i = 0; i < num_items; i++) {
1756 if (callbacks[i].index == item->index) {
1757 callbacks[i].func(widget, item);
1762 #ifndef GENERIC_UMPC
1763 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1764 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1765 gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
1766 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1767 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1768 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1769 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1770 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1774 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1775 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1776 GList *gchild = NULL; \
1777 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1778 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1779 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1780 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1781 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1782 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
1784 CLAWS_SET_ARROW_TIP(GTK_MENU_TOOL_BUTTON(item), menutip); \
1785 child = gtk_bin_get_child(GTK_BIN(item)); \
1786 gchild = gtk_container_get_children( \
1787 GTK_CONTAINER(child)); \
1788 btn = (GtkWidget *)gchild->data; \
1789 gtkut_widget_set_can_focus(btn, FALSE); \
1790 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1791 gtkut_widget_set_can_focus(arr, FALSE); \
1792 g_list_free(gchild); \
1793 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1794 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1795 g_list_free(gchild); \
1798 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
1799 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
1800 gtkut_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
1801 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1802 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1803 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1804 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1807 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
1808 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
1809 GList *gchild = NULL; \
1810 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
1811 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
1812 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
1813 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
1814 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
1815 child = gtk_bin_get_child(GTK_BIN(item)); \
1816 gchild = gtk_container_get_children( \
1817 GTK_CONTAINER(child)); \
1818 btn = (GtkWidget *)gchild->data; \
1819 gtkut_widget_set_can_focus(btn, FALSE); \
1820 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
1821 gtkut_widget_set_can_focus(arr, FALSE); \
1822 g_list_free(gchild); \
1823 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
1824 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
1825 g_list_free(gchild); \
1829 #define ADD_MENU_ITEM(name,cb,data) { \
1830 item = gtk_menu_item_new_with_mnemonic(name); \
1831 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); \
1832 g_signal_connect(G_OBJECT(item), "activate", \
1835 g_object_set_data(G_OBJECT(item), "int-value", GINT_TO_POINTER(data)); \
1836 gtk_widget_show(item); \
1839 static void toolbar_reply_menu_cb(GtkWidget *widget, gpointer data)
1841 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1842 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1844 toolbar_reply(toolbar_item, GPOINTER_TO_INT(int_value));
1847 static void toolbar_learn_menu_cb(GtkWidget *widget, gpointer data)
1849 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
1850 ToolbarItem *toolbar_item = (ToolbarItem *)data;
1852 toolbar_learn(toolbar_item, GPOINTER_TO_INT(int_value));
1856 * Create a new toolbar with specified type
1857 * if a callback list is passed it will be used before the
1858 * common callback list
1860 Toolbar *toolbar_create(ToolbarType type,
1861 GtkWidget *container,
1864 ToolbarItem *toolbar_item;
1867 GtkWidget *icon_wid = NULL;
1868 GtkWidget *icon_news;
1869 GtkWidget *icon_ham;
1871 ToolbarClawsActions *action_item;
1873 GSList *toolbar_list;
1874 Toolbar *toolbar_data;
1876 #ifndef GENERIC_UMPC
1877 #if !(GTK_CHECK_VERSION(2,12,0))
1878 GtkTooltips *toolbar_tips = gtk_tooltips_new();
1881 toolbar_read_config_file(type);
1882 toolbar_list = toolbar_get_list(type);
1884 toolbar_data = g_new0(Toolbar, 1);
1886 toolbar = gtk_toolbar_new();
1888 #if (GTK_CHECK_VERSION(2,16,0))
1889 gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL);
1891 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1893 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1894 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
1896 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1898 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1899 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
1903 toolbar_item = g_new0(ToolbarItem, 1);
1904 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1905 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1906 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1907 toolbar_item->parent = data;
1908 toolbar_item->type = type;
1910 /* collect toolbar items in list to keep track */
1911 toolbar_data->item_list =
1912 g_slist_append(toolbar_data->item_list,
1914 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1916 switch (toolbar_item->index) {
1919 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
1920 toolbar_data->folders_btn = item;
1923 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1924 _("Receive Mail from all Accounts"),
1925 _("Receive Mail from selected Account"));
1926 toolbar_data->getall_btn = item;
1929 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, _("Receive Mail from current Account"));
1930 toolbar_data->get_btn = item;
1933 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
1934 toolbar_data->send_btn = item;
1937 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
1938 toolbar_data->close_window_btn = item;
1941 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open preferences"));
1942 toolbar_data->preferences_btn = item;
1945 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
1946 toolbar_data->open_mail_btn = item;
1948 case A_COMPOSE_EMAIL:
1949 #ifndef GENERIC_UMPC
1950 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1952 _("Compose with selected Account"));
1953 toolbar_data->compose_mail_btn = item;
1954 toolbar_data->compose_mail_icon = icon_wid;
1955 g_object_ref(toolbar_data->compose_mail_icon);
1957 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1958 toolbar_data->compose_news_icon = icon_news;
1959 g_object_ref(toolbar_data->compose_news_icon);
1961 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
1962 _("Compose Email"));
1963 toolbar_data->compose_mail_btn = item;
1964 toolbar_data->compose_mail_icon = icon_wid;
1966 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1967 toolbar_data->compose_news_icon = icon_news;
1971 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1974 toolbar_data->learn_spam_btn = item;
1975 toolbar_data->learn_spam_icon = icon_wid;
1976 g_object_ref(toolbar_data->learn_spam_icon);
1978 icon_ham = stock_pixmap_widget(container, STOCK_PIXMAP_HAM_BTN);
1979 toolbar_data->learn_ham_icon = icon_ham;
1980 g_object_ref(toolbar_data->learn_ham_icon);
1982 menu = gtk_menu_new();
1983 ADD_MENU_ITEM(_("Learn as _Spam"), toolbar_learn_menu_cb, TRUE);
1984 ADD_MENU_ITEM(_("Learn as _Ham"), toolbar_learn_menu_cb, FALSE);
1985 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->learn_spam_btn), menu);
1987 case A_REPLY_MESSAGE:
1988 #ifndef GENERIC_UMPC
1989 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
1990 _("Reply to Message"),
1991 _("Reply to Message options"));
1992 toolbar_data->reply_btn = item;
1994 menu = gtk_menu_new();
1995 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITH_QUOTE);
1996 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITHOUT_QUOTE);
1997 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->reply_btn), menu);
1999 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2000 _("Reply to Message"));
2001 toolbar_data->reply_btn = item;
2004 case A_REPLY_SENDER:
2005 #ifndef GENERIC_UMPC
2006 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2007 _("Reply to Sender"),
2008 _("Reply to Sender options"));
2009 toolbar_data->replysender_btn = item;
2011 menu = gtk_menu_new();
2012 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE);
2013 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
2014 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replysender_btn), menu);
2016 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2017 _("Reply to Sender"));
2018 toolbar_data->replysender_btn = item;
2022 #ifndef GENERIC_UMPC
2023 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2025 _("Reply to All options"));
2026 toolbar_data->replyall_btn = item;
2028 menu = gtk_menu_new();
2029 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE);
2030 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
2031 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replyall_btn), menu);
2033 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2035 toolbar_data->replyall_btn = item;
2039 #ifndef GENERIC_UMPC
2040 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2041 _("Reply to Mailing-list"),
2042 _("Reply to Mailing-list options"));
2043 toolbar_data->replylist_btn = item;
2045 menu = gtk_menu_new();
2046 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE);
2047 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
2048 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replylist_btn), menu);
2050 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2051 _("Reply to Mailing-list"));
2052 toolbar_data->replylist_btn = item;
2056 #ifndef GENERIC_UMPC
2057 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2058 _("Forward Message"),
2059 _("Forward Message options"));
2060 toolbar_data->fwd_btn = item;
2062 menu = gtk_menu_new();
2063 ADD_MENU_ITEM(_("_Forward"), toolbar_reply_menu_cb, COMPOSE_FORWARD_INLINE);
2064 ADD_MENU_ITEM(_("For_ward as attachment"), toolbar_reply_menu_cb, COMPOSE_FORWARD_AS_ATTACH);
2065 ADD_MENU_ITEM(_("Redirec_t"), toolbar_reply_menu_cb, COMPOSE_REDIRECT);
2066 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->fwd_btn), menu);
2068 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2069 _("Forward Message"));
2070 toolbar_data->fwd_btn = item;
2074 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
2075 toolbar_data->trash_btn = item;
2078 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
2079 toolbar_data->delete_btn = item;
2082 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
2083 toolbar_data->exec_btn = item;
2086 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
2087 toolbar_data->prev_btn = item;
2090 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
2091 toolbar_data->next_btn = item;
2094 /* Compose Toolbar */
2096 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2097 toolbar_data->send_btn = item;
2100 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2101 toolbar_data->sendl_btn = item;
2104 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2105 toolbar_data->draft_btn = item;
2108 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2109 toolbar_data->insert_btn = item;
2112 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2113 toolbar_data->attach_btn = item;
2116 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2117 toolbar_data->sig_btn = item;
2120 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2121 toolbar_data->exteditor_btn = item;
2123 case A_LINEWRAP_CURRENT:
2124 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2125 toolbar_data->linewrap_current_btn = item;
2127 case A_LINEWRAP_ALL:
2128 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2129 toolbar_data->linewrap_all_btn = item;
2132 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2133 toolbar_data->addrbook_btn = item;
2136 case A_CHECK_SPELLING:
2137 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2138 toolbar_data->spellcheck_btn = item;
2142 case A_CLAWS_ACTIONS:
2143 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2144 action_item = g_new0(ToolbarClawsActions, 1);
2145 action_item->widget = item;
2146 action_item->name = g_strdup(toolbar_item->text);
2148 toolbar_data->action_list =
2149 g_slist_append(toolbar_data->action_list,
2153 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2154 toolbar_data->cancel_inc_btn = item;
2156 case A_CLAWS_PLUGINS:
2157 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, toolbar_item->text);
2160 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2161 toolbar_ret_descr_from_val(toolbar_item->index));
2162 /* find and set the tool tip text */
2167 toolbar_data->toolbar = toolbar;
2168 #ifndef GENERIC_UMPC
2169 #if !(GTK_CHECK_VERSION(2,12,0))
2170 toolbar_data->tooltips = toolbar_tips;
2173 gtk_widget_show_all(toolbar);
2175 if (type == TOOLBAR_MAIN) {
2177 MainWindow *mainwin = mainwindow_get_mainwindow();
2178 GtkWidget *progressbar = gtk_progress_bar_new();
2179 item = GTK_WIDGET(gtk_tool_item_new());
2180 gtk_container_add (GTK_CONTAINER (item), progressbar);
2181 gtk_widget_show(item);
2182 gtk_widget_set_size_request(progressbar, 84, -1);
2183 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2184 mainwin->progressbar = progressbar;
2186 activate_compose_button(toolbar_data,
2187 prefs_common.toolbar_style,
2188 toolbar_data->compose_btn_type);
2190 if (type != TOOLBAR_COMPOSE)
2191 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2195 gtk_container_add(GTK_CONTAINER(container), toolbar);
2196 gtk_container_set_border_width(GTK_CONTAINER(container), 0);
2198 if ( GTK_IS_WINDOW(container) ) {
2199 hildon_window_add_toolbar (HILDON_WINDOW(container), GTK_TOOLBAR(toolbar));
2200 gtk_widget_show_all (container);
2202 gtk_container_add(GTK_CONTAINER(container), toolbar);
2203 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
2206 return toolbar_data;
2210 * Free toolbar structures
2212 void toolbar_destroy(Toolbar * toolbar) {
2214 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2215 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2218 void toolbar_update(ToolbarType type, gpointer data)
2220 Toolbar *toolbar_data;
2221 GtkWidget *handlebox;
2222 MainWindow *mainwin = (MainWindow*)data;
2223 Compose *compose = (Compose*)data;
2224 MessageView *msgview = (MessageView*)data;
2226 #ifndef GENERIC_UMPC
2229 toolbar_data = mainwin->toolbar;
2230 handlebox = mainwin->handlebox;
2232 case TOOLBAR_COMPOSE:
2233 toolbar_data = compose->toolbar;
2234 handlebox = compose->handlebox;
2236 case TOOLBAR_MSGVIEW:
2237 toolbar_data = msgview->toolbar;
2238 handlebox = msgview->handlebox;
2244 gtk_container_remove(GTK_CONTAINER(handlebox),
2245 GTK_WIDGET(toolbar_data->toolbar));
2247 toolbar_init(toolbar_data);
2248 toolbar_data = toolbar_create(type, handlebox, data);
2252 toolbar_data = mainwin->toolbar;
2253 handlebox = mainwin->window;
2255 case TOOLBAR_COMPOSE:
2256 toolbar_data = compose->toolbar;
2257 handlebox = compose->window;
2259 case TOOLBAR_MSGVIEW:
2260 toolbar_data = msgview->toolbar;
2261 handlebox = msgview->window;
2267 hildon_window_remove_toolbar(HILDON_WINDOW(handlebox), GTK_TOOLBAR(toolbar_data->toolbar));
2269 toolbar_init(toolbar_data);
2270 toolbar_data = toolbar_create(type, handlebox, data);
2275 mainwin->toolbar = toolbar_data;
2277 case TOOLBAR_COMPOSE:
2278 compose->toolbar = toolbar_data;
2280 case TOOLBAR_MSGVIEW:
2281 msgview->toolbar = toolbar_data;
2285 toolbar_style(type, prefs_common.toolbar_style, data);
2287 if (type == TOOLBAR_MAIN) {
2288 toolbar_main_set_sensitive((MainWindow*)data);
2289 account_set_menu_only_toolbar();
2293 #if !GTK_CHECK_VERSION(2,14,0)
2294 /* Work around http://bugzilla.gnome.org/show_bug.cgi?id=56070 */
2295 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2296 gboolean in_btn1 = FALSE, in_btn2 = FALSE; \
2297 if (GTK_IS_BUTTON(widget)) \
2298 in_btn1 = GTK_BUTTON(widget)->in_button; \
2299 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2300 GtkWidget *child = gtk_bin_get_child( \
2302 GList *gchild = gtk_container_get_children( \
2303 GTK_CONTAINER(child)); \
2304 GtkWidget *btn = (GtkWidget *)gchild->data; \
2305 GtkWidget *arr = (GtkWidget *) \
2306 (gchild->next?gchild->next->data:NULL); \
2307 g_list_free(gchild); \
2308 if (GTK_IS_BUTTON(btn)) \
2309 in_btn1 = GTK_BUTTON(btn)->in_button; \
2310 if (GTK_IS_BUTTON(arr)) \
2311 in_btn2 = GTK_BUTTON(arr)->in_button; \
2313 else if (GTK_IS_TOOL_ITEM(widget)) { \
2314 GtkWidget *child = gtk_bin_get_child( \
2316 if (GTK_IS_BUTTON(child)) \
2317 in_btn1 = GTK_BUTTON(child)->in_button; \
2319 gtk_widget_set_sensitive(widget, sensitive); \
2320 if (GTK_IS_BUTTON(widget)) \
2321 GTK_BUTTON(widget)->in_button = in_btn1; \
2322 else if (GTK_IS_MENU_TOOL_BUTTON(widget)) { \
2323 GtkWidget *child = gtk_bin_get_child( \
2325 GList *gchild = gtk_container_get_children( \
2326 GTK_CONTAINER(child)); \
2327 GtkWidget *btn = (GtkWidget *)gchild->data; \
2328 GtkWidget *arr = (GtkWidget *) \
2329 (gchild->next?gchild->next->data:NULL); \
2330 g_list_free(gchild); \
2331 if (GTK_IS_BUTTON(btn)) \
2332 GTK_BUTTON(btn)->in_button = in_btn1; \
2333 if (GTK_IS_BUTTON(arr)) \
2334 GTK_BUTTON(arr)->in_button = in_btn2; \
2336 else if (GTK_IS_TOOL_ITEM(widget)) { \
2337 GtkWidget *child = gtk_bin_get_child( \
2339 if (GTK_IS_BUTTON(child)) \
2340 GTK_BUTTON(child)->in_button = in_btn1; \
2344 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2345 gtk_widget_set_sensitive(widget, sensitive); \
2349 void toolbar_main_set_sensitive(gpointer data)
2351 SensitiveCond state;
2353 MainWindow *mainwin = (MainWindow*)data;
2354 Toolbar *toolbar = mainwin->toolbar;
2356 GSList *entry_list = NULL;
2358 typedef struct _Entry Entry;
2365 #define SET_WIDGET_COND(w, c) \
2367 Entry *e = g_new0(Entry, 1); \
2370 entry_list = g_slist_append(entry_list, e); \
2374 if (toolbar->get_btn)
2375 SET_WIDGET_COND(toolbar->get_btn,
2376 M_HAVE_ACCOUNT|M_UNLOCKED|M_HAVE_RETRIEVABLE_ACCOUNT);
2378 if (toolbar->getall_btn) {
2379 SET_WIDGET_COND(toolbar->getall_btn,
2380 M_HAVE_ACCOUNT|M_UNLOCKED|M_HAVE_ANY_RETRIEVABLE_ACCOUNT);
2382 if (toolbar->send_btn) {
2383 SET_WIDGET_COND(toolbar->send_btn,
2384 M_HAVE_QUEUED_MAILS);
2386 if (toolbar->compose_mail_btn) {
2387 SET_WIDGET_COND(toolbar->compose_mail_btn,
2390 if (toolbar->close_window_btn) {
2391 SET_WIDGET_COND(toolbar->close_window_btn,
2394 if (toolbar->open_mail_btn) {
2395 SET_WIDGET_COND(toolbar->open_mail_btn,
2396 M_TARGET_EXIST|M_SUMMARY_ISLIST);
2398 if (toolbar->reply_btn) {
2399 SET_WIDGET_COND(toolbar->reply_btn,
2400 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2402 if (toolbar->replyall_btn) {
2403 SET_WIDGET_COND(toolbar->replyall_btn,
2404 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2406 if (toolbar->replylist_btn) {
2407 SET_WIDGET_COND(toolbar->replylist_btn,
2408 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2410 if (toolbar->replysender_btn) {
2411 SET_WIDGET_COND(toolbar->replysender_btn,
2412 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2414 if (toolbar->fwd_btn) {
2415 SET_WIDGET_COND(toolbar->fwd_btn,
2416 M_HAVE_ACCOUNT|M_TARGET_EXIST|M_SUMMARY_ISLIST);
2419 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2420 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST|M_SUMMARY_ISLIST);
2422 SET_WIDGET_COND(toolbar->next_btn, 0);
2425 if (toolbar->trash_btn)
2426 SET_WIDGET_COND(toolbar->trash_btn,
2427 M_TARGET_EXIST|M_ALLOW_DELETE|M_NOT_NEWS);
2429 if (toolbar->delete_btn)
2430 SET_WIDGET_COND(toolbar->delete_btn,
2431 M_TARGET_EXIST|M_ALLOW_DELETE);
2433 if (toolbar->exec_btn)
2434 SET_WIDGET_COND(toolbar->exec_btn,
2437 if (toolbar->learn_spam_btn)
2438 SET_WIDGET_COND(toolbar->learn_spam_btn,
2439 M_TARGET_EXIST|M_CAN_LEARN_SPAM|M_SUMMARY_ISLIST);
2441 if (toolbar->cancel_inc_btn)
2442 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2445 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2446 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2448 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
2451 #undef SET_WIDGET_COND
2453 state = main_window_get_current_state(mainwin);
2455 for (cur = entry_list; cur != NULL; cur = cur->next) {
2456 Entry *e = (Entry*) cur->data;
2458 if (e->widget != NULL) {
2459 sensitive = ((e->cond & state) == e->cond);
2460 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2464 while (entry_list != NULL) {
2465 Entry *e = (Entry*) entry_list->data;
2468 entry_list = g_slist_remove(entry_list, e);
2471 g_slist_free(entry_list);
2473 activate_compose_button(toolbar,
2474 prefs_common.toolbar_style,
2475 toolbar->compose_btn_type);
2479 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2481 Compose *compose = (Compose*)data;
2482 GSList *items = compose->toolbar->action_list;
2484 if (compose->toolbar->send_btn)
2485 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2486 if (compose->toolbar->sendl_btn)
2487 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2488 if (compose->toolbar->draft_btn )
2489 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2490 if (compose->toolbar->insert_btn )
2491 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2492 if (compose->toolbar->attach_btn)
2493 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2494 if (compose->toolbar->sig_btn)
2495 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2496 if (compose->toolbar->exteditor_btn)
2497 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2498 if (compose->toolbar->linewrap_current_btn)
2499 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2500 if (compose->toolbar->linewrap_all_btn)
2501 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2502 if (compose->toolbar->addrbook_btn)
2503 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2505 if (compose->toolbar->spellcheck_btn)
2506 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2508 for (; items != NULL; items = g_slist_next(items)) {
2509 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2510 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2515 * Initialize toolbar structure
2517 static void toolbar_init(Toolbar * toolbar)
2520 toolbar->toolbar = NULL;
2521 toolbar->folders_btn = NULL;
2522 toolbar->get_btn = NULL;
2523 toolbar->getall_btn = NULL;
2524 toolbar->send_btn = NULL;
2525 toolbar->compose_mail_btn = NULL;
2526 toolbar->compose_mail_icon = NULL;
2527 toolbar->compose_news_icon = NULL;
2528 toolbar->reply_btn = NULL;
2529 toolbar->replysender_btn = NULL;
2530 toolbar->replyall_btn = NULL;
2531 toolbar->replylist_btn = NULL;
2532 toolbar->fwd_btn = NULL;
2533 toolbar->trash_btn = NULL;
2534 toolbar->delete_btn = NULL;
2535 toolbar->prev_btn = NULL;
2536 toolbar->next_btn = NULL;
2537 toolbar->exec_btn = NULL;
2538 toolbar->open_mail_btn = NULL;
2539 toolbar->close_window_btn = NULL;
2540 /* compose buttons */
2541 toolbar->sendl_btn = NULL;
2542 toolbar->draft_btn = NULL;
2543 toolbar->insert_btn = NULL;
2544 toolbar->attach_btn = NULL;
2545 toolbar->sig_btn = NULL;
2546 toolbar->exteditor_btn = NULL;
2547 toolbar->linewrap_current_btn = NULL;
2548 toolbar->linewrap_all_btn = NULL;
2549 toolbar->addrbook_btn = NULL;
2551 toolbar->spellcheck_btn = NULL;
2554 toolbar_destroy(toolbar);
2559 static void toolbar_reply(gpointer data, guint action)
2561 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2562 MainWindow *mainwin;
2563 MessageView *msgview;
2564 GSList *msginfo_list = NULL;
2566 cm_return_if_fail(toolbar_item != NULL);
2568 switch (toolbar_item->type) {
2570 mainwin = (MainWindow*)toolbar_item->parent;
2571 msginfo_list = summary_get_selection(mainwin->summaryview);
2572 msgview = (MessageView*)mainwin->messageview;
2574 case TOOLBAR_MSGVIEW:
2575 msgview = (MessageView*)toolbar_item->parent;
2576 cm_return_if_fail(msgview != NULL);
2577 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2583 cm_return_if_fail(msgview != NULL);
2584 cm_return_if_fail(msginfo_list != NULL);
2585 compose_reply_from_messageview(msgview, msginfo_list, action);
2586 g_slist_free(msginfo_list);
2588 /* TODO: update reply state ion summaryview */
2592 /* exported functions */
2594 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2596 MainWindow *mainwin = (MainWindow*)data;
2598 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2601 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2603 MainWindow *mainwin = (MainWindow*)data;
2605 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2608 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2612 gboolean got_error = FALSE;
2613 gchar *errstr = NULL;
2615 if (prefs_common.work_offline)
2616 if (alertpanel(_("Offline warning"),
2617 _("You're working offline. Override?"),
2618 GTK_STOCK_NO, GTK_STOCK_YES,
2619 NULL) != G_ALERTALTERNATE)
2622 /* ask for confirmation before sending queued messages only
2623 in online mode and if there is at least one message queued
2624 in any of the folder queue
2626 if (prefs_common.confirm_send_queued_messages) {
2628 /* check if there's a queued message */
2629 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
2630 Folder *folder = list->data;
2632 found = !procmsg_queue_is_empty(folder->queue);
2634 /* if necessary, ask for confirmation before sending */
2635 if (found && !prefs_common.work_offline) {
2636 if (alertpanel(_("Send queued messages"),
2637 _("Send all queued messages?"),
2638 GTK_STOCK_CANCEL, _("_Send"),
2639 NULL) != G_ALERTALTERNATE)
2644 for (list = folder_get_list(); list != NULL; list = list->next) {
2645 Folder *folder = list->data;
2647 if (folder->queue) {
2648 if (procmsg_send_queue(folder->queue,
2649 prefs_common.savemsg,
2656 alertpanel_error_log(_("Some errors occurred while "
2657 "sending queued messages."));
2659 alertpanel_error_log(_("Some errors occurred "
2660 "while sending queued messages:\n%s"), errstr);
2666 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2668 MainWindow *mainwin = (MainWindow*)data;
2669 PrefsAccount *ac = NULL;
2670 FolderItem *item = mainwin->summaryview->folder_item;
2675 ac = account_find_from_item(item);
2676 if (ac && ac->protocol != A_NNTP) {
2677 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
2683 * CLAWS - use current account
2685 if (cur_account && (cur_account->protocol != A_NNTP)) {
2686 compose_new_with_folderitem(cur_account, item, NULL);
2691 * CLAWS - just get the first one
2693 list = account_get_list();
2694 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2695 ac = (PrefsAccount *) cur->data;
2696 if (ac->protocol != A_NNTP) {
2697 compose_new_with_folderitem(ac, item, NULL);
2703 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2705 MainWindow *mainwin = (MainWindow*)data;
2706 PrefsAccount * ac = NULL;
2710 if (mainwin->summaryview->folder_item) {
2711 ac = mainwin->summaryview->folder_item->folder->account;
2712 if (ac && ac->protocol == A_NNTP) {
2713 compose_new_with_folderitem(ac,
2714 mainwin->summaryview->folder_item, NULL);
2719 list = account_get_list();
2720 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2721 ac = (PrefsAccount *) cur->data;
2722 if (ac->protocol == A_NNTP) {
2723 compose_new_with_folderitem(ac,
2724 mainwin->summaryview->folder_item, NULL);