2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2003 Hiroyuki Yamamoto and the Sylpheed-Claws 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 2 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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * General functions for accessing address book files.
31 #include <glib/gi18n.h>
39 #include "mainwindow.h"
40 #include "summaryview.h"
45 #include "prefs_gtk.h"
47 #include "stock_pixmap.h"
48 #include "manage_window.h"
54 #include "prefs_actions.h"
55 #include "prefs_common.h"
56 #include "prefs_toolbar.h"
57 #include "alertpanel.h"
60 #define TOOLBAR_TAG_INDEX "toolbar"
61 #define TOOLBAR_TAG_ITEM "item"
62 #define TOOLBAR_TAG_SEPARATOR "separator"
64 #define TOOLBAR_ICON_FILE "file"
65 #define TOOLBAR_ICON_TEXT "text"
66 #define TOOLBAR_ICON_ACTION "action"
68 gboolean toolbar_is_duplicate (gint action,
70 static void toolbar_parse_item (XMLFile *file,
73 static gint toolbar_ret_val_from_text (const gchar *text);
74 static gchar *toolbar_ret_text_from_val (gint val);
76 static void toolbar_set_default_main (void);
77 static void toolbar_set_default_compose (void);
78 static void toolbar_set_default_msgview (void);
80 static void toolbar_style (ToolbarType type,
84 static MainWindow *get_mainwin (gpointer data);
85 static void activate_compose_button (Toolbar *toolbar,
87 ComposeButtonType type);
89 /* toolbar callbacks */
90 static void toolbar_reply (gpointer data,
92 static void toolbar_delete_cb (GtkWidget *widget,
94 static void toolbar_trash_cb (GtkWidget *widget,
97 static void toolbar_compose_cb (GtkWidget *widget,
100 static void toolbar_reply_cb (GtkWidget *widget,
103 static void toolbar_reply_to_all_cb (GtkWidget *widget,
106 static void toolbar_reply_to_list_cb (GtkWidget *widget,
109 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
112 static void toolbar_forward_cb (GtkWidget *widget,
115 static void toolbar_prev_unread_cb (GtkWidget *widget,
117 static void toolbar_next_unread_cb (GtkWidget *widget,
120 static void toolbar_ignore_thread_cb (GtkWidget *widget,
123 static void toolbar_print_cb (GtkWidget *widget,
126 static void toolbar_actions_execute_cb (GtkWidget *widget,
130 static void toolbar_send_cb (GtkWidget *widget,
132 static void toolbar_send_later_cb (GtkWidget *widget,
134 static void toolbar_draft_cb (GtkWidget *widget,
136 static void toolbar_insert_cb (GtkWidget *widget,
138 static void toolbar_attach_cb (GtkWidget *widget,
140 static void toolbar_sig_cb (GtkWidget *widget,
142 static void toolbar_ext_editor_cb (GtkWidget *widget,
144 static void toolbar_linewrap_current_cb (GtkWidget *widget,
146 static void toolbar_linewrap_all_cb (GtkWidget *widget,
148 static void toolbar_addrbook_cb (GtkWidget *widget,
151 static void toolbar_check_spelling_cb (GtkWidget *widget,
158 } toolbar_text [] = {
159 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
160 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
161 { "A_SEND_QUEUED", N_("Send Queued Messages") },
162 { "A_COMPOSE_EMAIL", N_("Compose Email") },
163 { "A_COMPOSE_NEWS", N_("Compose News") },
164 { "A_REPLY_MESSAGE", N_("Reply to Message") },
165 { "A_REPLY_SENDER", N_("Reply to Sender") },
166 { "A_REPLY_ALL", N_("Reply to All") },
167 { "A_REPLY_ML", N_("Reply to Mailing-list") },
168 { "A_FORWARD", N_("Forward Message") },
169 { "A_TRASH", N_("Trash Message") },
170 { "A_DELETE_REAL", N_("Delete Message") },
171 { "A_EXECUTE", N_("Execute") },
172 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
173 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
174 { "A_IGNORE_THREAD", N_("Ignore thread") },
175 { "A_PRINT", N_("Print") },
177 { "A_SEND", N_("Send Message") },
178 { "A_SENDL", N_("Put into queue folder and send later") },
179 { "A_DRAFT", N_("Save to draft folder") },
180 { "A_INSERT", N_("Insert file") },
181 { "A_ATTACH", N_("Attach file") },
182 { "A_SIG", N_("Insert signature") },
183 { "A_EXTEDITOR", N_("Edit with external editor") },
184 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
185 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
186 { "A_ADDRBOOK", N_("Address book") },
188 { "A_CHECK_SPELLING", N_("Check spelling") },
190 { "A_SYL_ACTIONS", N_("Sylpheed-Claws Actions Feature") },
191 { "A_SEPARATOR", "Separator" }
194 /* struct holds configuration files and a list of
195 * currently active toolbar items
196 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
200 const gchar *conf_file;
202 } toolbar_config[3] = {
203 { "toolbar_main.xml", NULL},
204 { "toolbar_compose.xml", NULL},
205 { "toolbar_msgview.xml", NULL}
208 static GtkItemFactoryEntry reply_entries[] =
210 {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
211 {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
213 static GtkItemFactoryEntry replyall_entries[] =
215 {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
216 {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
218 static GtkItemFactoryEntry replylist_entries[] =
220 {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
221 {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
223 static GtkItemFactoryEntry replysender_entries[] =
225 {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
226 {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
228 static GtkItemFactoryEntry forward_entries[] =
230 {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
231 {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
232 {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, NULL}
236 gint toolbar_ret_val_from_descr(const gchar *descr)
240 for (i = 0; i < N_ACTION_VAL; i++) {
241 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
248 gchar *toolbar_ret_descr_from_val(gint val)
250 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
252 return gettext(toolbar_text[val].descr);
255 static gint toolbar_ret_val_from_text(const gchar *text)
259 for (i = 0; i < N_ACTION_VAL; i++) {
260 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
267 static gchar *toolbar_ret_text_from_val(gint val)
269 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
271 return toolbar_text[val].index_str;
274 gboolean toolbar_is_duplicate(gint action, ToolbarType source)
278 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
281 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
282 ToolbarItem *item = (ToolbarItem*) cur->data;
284 if (item->index == action)
290 /* depending on toolbar type this function
291 returns a list of available toolbar events being
292 displayed by prefs_toolbar
294 GList *toolbar_get_action_items(ToolbarType source)
299 if (source == TOOLBAR_MAIN) {
300 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
301 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
302 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
303 A_TRASH , A_DELETE_REAL, A_EXECUTE, A_GOTO_PREV,
304 A_GOTO_NEXT, A_IGNORE_THREAD, A_PRINT,
305 A_ADDRBOOK, A_SYL_ACTIONS };
307 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
308 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
311 else if (source == TOOLBAR_COMPOSE) {
312 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
313 A_INSERT, A_ATTACH, A_SIG,
314 A_EXTEDITOR, A_LINEWRAP_CURRENT,
315 A_LINEWRAP_ALL, A_ADDRBOOK,
321 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
322 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
324 else if (source == TOOLBAR_MSGVIEW) {
325 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
326 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
327 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
328 A_ADDRBOOK, A_SYL_ACTIONS };
330 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
331 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
337 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
341 ToolbarItem *item = NULL;
342 gboolean rewrite = FALSE;
344 attr = xml_get_current_tag_attr(file);
345 item = g_new0(ToolbarItem, 1);
347 name = ((XMLAttr *)attr->data)->name;
348 value = ((XMLAttr *)attr->data)->value;
350 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
351 item->file = g_strdup (value);
352 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
353 item->text = g_strdup (value);
354 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
355 item->index = toolbar_ret_val_from_text(value);
356 if (item->index == -1 && !strcmp(value, "A_DELETE")) {
358 item->index = A_TRASH;
360 item->file = g_strdup("trash_btn");
362 item->text = g_strdup(_("Trash"));
365 attr = g_list_next(attr);
367 if (item->index != -1) {
369 if (!toolbar_is_duplicate(item->index, source))
370 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
374 toolbar_save_config_file(source);
378 static void toolbar_set_default_main(void)
384 } default_toolbar[] = {
385 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get Mail") },
386 { A_SEPARATOR, 0, ("") },
387 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
388 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Compose") },
389 { A_SEPARATOR, 0, ("") },
390 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
391 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
392 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
393 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
394 { A_SEPARATOR, 0, ("") },
395 { A_TRASH, STOCK_PIXMAP_TRASH, _("Trash") },
396 { A_SEPARATOR, 0, ("") },
397 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
402 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
404 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
406 if (default_toolbar[i].action != A_SEPARATOR) {
408 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
410 toolbar_item->file = g_strdup(file);
411 toolbar_item->index = default_toolbar[i].action;
412 toolbar_item->text = g_strdup(default_toolbar[i].text);
415 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
416 toolbar_item->index = A_SEPARATOR;
419 if (toolbar_item->index != -1) {
420 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
421 toolbar_config[TOOLBAR_MAIN].item_list =
422 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
427 static void toolbar_set_default_compose(void)
433 } default_toolbar[] = {
434 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
435 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
436 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
437 { A_SEPARATOR, 0, ("") },
438 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
439 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
440 { A_SEPARATOR, 0, ("") },
441 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
446 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
448 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
450 if (default_toolbar[i].action != A_SEPARATOR) {
452 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
454 toolbar_item->file = g_strdup(file);
455 toolbar_item->index = default_toolbar[i].action;
456 toolbar_item->text = g_strdup(default_toolbar[i].text);
459 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
460 toolbar_item->index = A_SEPARATOR;
463 if (toolbar_item->index != -1) {
464 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
465 toolbar_config[TOOLBAR_COMPOSE].item_list =
466 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
471 static void toolbar_set_default_msgview(void)
477 } default_toolbar[] = {
478 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
479 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
480 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
481 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
482 { A_SEPARATOR, 0, ("") },
483 { A_TRASH, STOCK_PIXMAP_TRASH, _("Trash") },
484 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
489 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
491 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
493 if (default_toolbar[i].action != A_SEPARATOR) {
495 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
497 toolbar_item->file = g_strdup(file);
498 toolbar_item->index = default_toolbar[i].action;
499 toolbar_item->text = g_strdup(default_toolbar[i].text);
502 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
503 toolbar_item->index = A_SEPARATOR;
506 if (toolbar_item->index != -1) {
507 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
508 toolbar_config[TOOLBAR_MSGVIEW].item_list =
509 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
514 void toolbar_set_default(ToolbarType source)
516 if (source == TOOLBAR_MAIN)
517 toolbar_set_default_main();
518 else if (source == TOOLBAR_COMPOSE)
519 toolbar_set_default_compose();
520 else if (source == TOOLBAR_MSGVIEW)
521 toolbar_set_default_msgview();
524 void toolbar_save_config_file(ToolbarType source)
529 gchar *fileSpec = NULL;
531 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
533 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
534 pfile = prefs_write_open(fileSpec);
538 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL);
540 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
542 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
543 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
545 if (toolbar_item->index != A_SEPARATOR) {
546 fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
548 TOOLBAR_ICON_FILE, toolbar_item->file,
550 xml_file_put_escape_str(fp, toolbar_item->text);
551 fprintf(fp, "\" %s=\"%s\"/>\n",
553 toolbar_ret_text_from_val(toolbar_item->index));
555 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
559 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
561 if (prefs_file_close (pfile) < 0 )
562 g_warning("failed to write toolbar configuration to file\n");
564 g_warning("failed to open toolbar configuration file for writing\n");
567 void toolbar_read_config_file(ToolbarType source)
569 XMLFile *file = NULL;
570 gchar *fileSpec = NULL;
575 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
577 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
578 file = xml_open_file(fileSpec);
581 toolbar_clear_list(source);
585 || (xml_get_dtd(file))
586 || (xml_parse_next_tag(file))
587 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
588 xml_close_file(file);
592 attr = xml_get_current_tag_attr(file);
599 if (xml_parse_next_tag(file))
602 /* Get next tag (icon, icon_text or icon_action) */
603 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
604 toolbar_parse_item(file, source);
605 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
606 ToolbarItem *item = g_new0(ToolbarItem, 1);
608 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
609 item->index = A_SEPARATOR;
610 toolbar_config[source].item_list =
611 g_slist_append(toolbar_config[source].item_list, item);
615 xml_close_file(file);
618 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
620 if (source == TOOLBAR_MAIN)
621 toolbar_set_default(TOOLBAR_MAIN);
622 else if (source == TOOLBAR_COMPOSE)
623 toolbar_set_default(TOOLBAR_COMPOSE);
624 else if (source == TOOLBAR_MSGVIEW)
625 toolbar_set_default(TOOLBAR_MSGVIEW);
627 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
631 toolbar_save_config_file(source);
636 * clears list of toolbar items read from configuration files
638 void toolbar_clear_list(ToolbarType source)
640 while (toolbar_config[source].item_list != NULL) {
641 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
643 toolbar_config[source].item_list =
644 g_slist_remove(toolbar_config[source].item_list, item);
652 g_slist_free(toolbar_config[source].item_list);
657 * return list of Toolbar items
659 GSList *toolbar_get_list(ToolbarType source)
663 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
664 list = toolbar_config[source].item_list;
669 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
671 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
673 toolbar_item->file = g_strdup(t_item->file);
674 toolbar_item->text = g_strdup(t_item->text);
675 toolbar_item->index = t_item->index;
677 toolbar_config[source].item_list =
678 g_slist_append(toolbar_config[source].item_list,
682 void toolbar_action_execute(GtkWidget *widget,
688 gchar *action, *action_p;
689 gboolean found = FALSE;
692 for (cur = action_list; cur != NULL; cur = cur->next) {
693 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
695 if (widget == act->widget) {
697 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
698 action = g_strdup((gchar*)lop->data);
700 action_p = strstr(action, ": ");
702 if (g_utf8_collate(act->name, action) == 0) {
716 actions_execute(data, i, widget, source);
718 g_warning ("Error: did not find Sylpheed Action to execute");
721 static void activate_compose_button (Toolbar *toolbar,
723 ComposeButtonType type)
725 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
728 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
729 : toolbar->compose_news_btn);
730 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
731 : toolbar->compose_mail_btn);
732 toolbar->compose_btn_type = type;
735 void toolbar_set_compose_button(Toolbar *toolbar,
736 ComposeButtonType compose_btn_type)
738 if (toolbar->compose_btn_type != compose_btn_type)
739 activate_compose_button(toolbar,
740 prefs_common.toolbar_style,
744 void toolbar_toggle(guint action, gpointer data)
746 MainWindow *mainwin = (MainWindow*)data;
750 g_return_if_fail(mainwin != NULL);
752 toolbar_style(TOOLBAR_MAIN, action, mainwin);
754 list = compose_get_compose_list();
755 for (cur = list; cur != NULL; cur = cur->next) {
756 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
758 list = messageview_get_msgview_list();
759 for (cur = list; cur != NULL; cur = cur->next) {
760 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
765 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
767 switch ((ToolbarStyle)action) {
769 gtk_widget_hide(handlebox_wid);
772 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
776 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
780 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
787 prefs_common.toolbar_style = (ToolbarStyle)action;
788 gtk_widget_set_size_request(handlebox_wid, 1, -1);
790 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
791 gtk_widget_show(handlebox_wid);
792 gtk_widget_queue_resize(handlebox_wid);
796 * Change the style of toolbar
798 static void toolbar_style(ToolbarType type, guint action, gpointer data)
800 GtkWidget *handlebox_wid;
801 GtkWidget *toolbar_wid;
802 MainWindow *mainwin = (MainWindow*)data;
803 Compose *compose = (Compose*)data;
804 MessageView *msgview = (MessageView*)data;
806 g_return_if_fail(data != NULL);
810 handlebox_wid = mainwin->handlebox;
811 toolbar_wid = mainwin->toolbar->toolbar;
813 case TOOLBAR_COMPOSE:
814 handlebox_wid = compose->handlebox;
815 toolbar_wid = compose->toolbar->toolbar;
817 case TOOLBAR_MSGVIEW:
818 handlebox_wid = msgview->handlebox;
819 toolbar_wid = msgview->toolbar->toolbar;
825 toolbar_set_style(toolbar_wid, handlebox_wid, action);
828 /* Toolbar handling */
829 static void toolbar_inc_cb(GtkWidget *widget,
832 ToolbarItem *toolbar_item = (ToolbarItem*)data;
835 g_return_if_fail(toolbar_item != NULL);
837 switch (toolbar_item->type) {
839 mainwin = (MainWindow*)toolbar_item->parent;
840 inc_mail_cb(mainwin, 0, NULL);
847 static void toolbar_inc_all_cb(GtkWidget *widget,
850 ToolbarItem *toolbar_item = (ToolbarItem*)data;
853 g_return_if_fail(toolbar_item != NULL);
855 switch (toolbar_item->type) {
857 mainwin = (MainWindow*)toolbar_item->parent;
858 inc_all_account_mail_cb(mainwin, 0, NULL);
865 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
867 ToolbarItem *toolbar_item = (ToolbarItem*)data;
870 g_return_if_fail(toolbar_item != NULL);
872 switch (toolbar_item->type) {
874 mainwin = (MainWindow*)toolbar_item->parent;
875 send_queue_cb(mainwin, 0, NULL);
882 static void toolbar_exec_cb(GtkWidget *widget,
885 MainWindow *mainwin = get_mainwin(data);
887 g_return_if_fail(mainwin != NULL);
888 summary_execute(mainwin->summaryview);
892 * Delete current/selected(s) message(s)
894 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
896 ToolbarItem *toolbar_item = (ToolbarItem*)data;
899 g_return_if_fail(toolbar_item != NULL);
900 g_return_if_fail(toolbar_item->parent);
902 switch (toolbar_item->type) {
903 case TOOLBAR_MSGVIEW:
904 messageview_delete((MessageView *)toolbar_item->parent);
907 mainwin = (MainWindow *)toolbar_item->parent;
908 summary_delete_trash(mainwin->summaryview);
911 debug_print("toolbar event not supported\n");
917 * Delete current/selected(s) message(s)
919 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
921 ToolbarItem *toolbar_item = (ToolbarItem*)data;
924 g_return_if_fail(toolbar_item != NULL);
925 g_return_if_fail(toolbar_item->parent);
927 switch (toolbar_item->type) {
928 case TOOLBAR_MSGVIEW:
929 messageview_delete((MessageView *)toolbar_item->parent);
932 mainwin = (MainWindow *)toolbar_item->parent;
933 summary_delete(mainwin->summaryview);
936 debug_print("toolbar event not supported\n");
943 * Compose new message
945 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
947 ToolbarItem *toolbar_item = (ToolbarItem*)data;
949 MessageView *msgview;
951 g_return_if_fail(toolbar_item != NULL);
953 switch (toolbar_item->type) {
955 mainwin = (MainWindow*)toolbar_item->parent;
956 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
957 compose_news_cb(mainwin, 0, NULL);
959 compose_mail_cb(mainwin, 0, NULL);
961 case TOOLBAR_MSGVIEW:
962 msgview = (MessageView*)toolbar_item->parent;
963 compose_new_with_folderitem(NULL,
964 msgview->msginfo->folder);
967 debug_print("toolbar event not supported\n");
975 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
977 toolbar_reply(data, prefs_common.reply_with_quote ?
978 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
983 * Reply message to Sender and All recipients
985 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
988 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
989 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
994 * Reply to Mailing List
996 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
999 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1000 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1005 * Reply to sender of message
1007 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1010 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1011 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1017 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1019 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1022 g_return_if_fail(toolbar_item != NULL);
1024 switch (toolbar_item->type) {
1026 case TOOLBAR_MSGVIEW:
1029 case TOOLBAR_COMPOSE:
1030 compose = (Compose *)toolbar_item->parent;
1035 addressbook_open(compose);
1040 * Forward current/selected(s) message(s)
1042 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1044 toolbar_reply(data, COMPOSE_FORWARD);
1048 * Goto Prev Unread Message
1050 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1052 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1053 MainWindow *mainwin;
1054 MessageView *msgview;
1056 g_return_if_fail(toolbar_item != NULL);
1058 switch (toolbar_item->type) {
1060 mainwin = (MainWindow*)toolbar_item->parent;
1061 summary_select_prev_unread(mainwin->summaryview);
1064 case TOOLBAR_MSGVIEW:
1065 msgview = (MessageView*)toolbar_item->parent;
1066 summary_select_prev_unread(msgview->mainwin->summaryview);
1068 /* Now we need to update the messageview window */
1069 if (msgview->mainwin->summaryview->selected) {
1070 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1072 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1073 msgview->mainwin->summaryview->selected);
1075 messageview_show(msgview, msginfo,
1076 msgview->all_headers);
1078 gtk_widget_destroy(msgview->window);
1082 debug_print("toolbar event not supported\n");
1087 * Goto Next Unread Message
1089 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1091 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1092 MainWindow *mainwin;
1093 MessageView *msgview;
1095 g_return_if_fail(toolbar_item != NULL);
1097 switch (toolbar_item->type) {
1099 mainwin = (MainWindow*)toolbar_item->parent;
1100 summary_select_next_unread(mainwin->summaryview);
1103 case TOOLBAR_MSGVIEW:
1104 msgview = (MessageView*)toolbar_item->parent;
1105 summary_select_next_unread(msgview->mainwin->summaryview);
1107 /* Now we need to update the messageview window */
1108 if (msgview->mainwin->summaryview->selected) {
1109 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1111 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1112 msgview->mainwin->summaryview->selected);
1114 messageview_show(msgview, msginfo,
1115 msgview->all_headers);
1117 gtk_widget_destroy(msgview->window);
1121 debug_print("toolbar event not supported\n");
1125 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1127 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1128 MainWindow *mainwin;
1130 g_return_if_fail(toolbar_item != NULL);
1132 switch (toolbar_item->type) {
1134 mainwin = (MainWindow *) toolbar_item->parent;
1135 summary_toggle_ignore_thread(mainwin->summaryview);
1137 case TOOLBAR_MSGVIEW:
1138 /* TODO: see toolbar_next_unread_cb() if you need
1139 * this in the message view */
1142 debug_print("toolbar event not supported\n");
1147 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1149 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1150 MainWindow *mainwin;
1152 g_return_if_fail(toolbar_item != NULL);
1154 switch (toolbar_item->type) {
1156 mainwin = (MainWindow *) toolbar_item->parent;
1157 summary_print(mainwin->summaryview);
1159 case TOOLBAR_MSGVIEW:
1160 /* TODO: see toolbar_next_unread_cb() if you need
1161 * this in the message view */
1164 debug_print("toolbar event not supported\n");
1169 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1171 compose_toolbar_cb(A_SEND, data);
1174 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1176 compose_toolbar_cb(A_SENDL, data);
1179 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1181 compose_toolbar_cb(A_DRAFT, data);
1184 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1186 compose_toolbar_cb(A_INSERT, data);
1189 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1191 compose_toolbar_cb(A_ATTACH, data);
1194 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1196 compose_toolbar_cb(A_SIG, data);
1199 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1201 compose_toolbar_cb(A_EXTEDITOR, data);
1204 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1206 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1209 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1211 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1215 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1217 compose_toolbar_cb(A_CHECK_SPELLING, data);
1221 * Execute actions from toolbar
1223 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1225 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1226 GSList *action_list;
1227 MainWindow *mainwin;
1229 MessageView *msgview;
1230 gpointer parent = toolbar_item->parent;
1232 g_return_if_fail(toolbar_item != NULL);
1234 switch (toolbar_item->type) {
1236 mainwin = (MainWindow*)parent;
1237 action_list = mainwin->toolbar->action_list;
1239 case TOOLBAR_COMPOSE:
1240 compose = (Compose*)parent;
1241 action_list = compose->toolbar->action_list;
1243 case TOOLBAR_MSGVIEW:
1244 msgview = (MessageView*)parent;
1245 action_list = msgview->toolbar->action_list;
1248 debug_print("toolbar event not supported\n");
1251 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1254 static MainWindow *get_mainwin(gpointer data)
1256 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1257 MainWindow *mainwin = NULL;
1258 MessageView *msgview;
1260 g_return_val_if_fail(toolbar_item != NULL, NULL);
1262 switch(toolbar_item->type) {
1264 mainwin = (MainWindow*)toolbar_item->parent;
1266 case TOOLBAR_MSGVIEW:
1267 msgview = (MessageView*)toolbar_item->parent;
1268 mainwin = (MainWindow*)msgview->mainwin;
1277 static void toolbar_buttons_cb(GtkWidget *widget,
1284 void (*func)(GtkWidget *widget, gpointer data);
1286 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1287 { A_RECEIVE_CUR, toolbar_inc_cb },
1288 { A_SEND_QUEUED, toolbar_send_queued_cb },
1289 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1290 { A_COMPOSE_NEWS, toolbar_compose_cb },
1291 { A_REPLY_MESSAGE, toolbar_reply_cb },
1292 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1293 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1294 { A_REPLY_ML, toolbar_reply_to_list_cb },
1295 { A_FORWARD, toolbar_forward_cb },
1296 { A_TRASH, toolbar_trash_cb },
1297 { A_DELETE_REAL, toolbar_delete_cb },
1298 { A_EXECUTE, toolbar_exec_cb },
1299 { A_GOTO_PREV, toolbar_prev_unread_cb },
1300 { A_GOTO_NEXT, toolbar_next_unread_cb },
1301 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1302 { A_PRINT, toolbar_print_cb },
1304 { A_SEND, toolbar_send_cb },
1305 { A_SENDL, toolbar_send_later_cb },
1306 { A_DRAFT, toolbar_draft_cb },
1307 { A_INSERT, toolbar_insert_cb },
1308 { A_ATTACH, toolbar_attach_cb },
1309 { A_SIG, toolbar_sig_cb },
1310 { A_EXTEDITOR, toolbar_ext_editor_cb },
1311 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1312 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1313 { A_ADDRBOOK, toolbar_addrbook_cb },
1315 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1317 { A_SYL_ACTIONS, toolbar_actions_execute_cb }
1320 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1322 for (i = 0; i < num_items; i++) {
1323 if (callbacks[i].index == item->index) {
1324 callbacks[i].func(widget, item);
1331 * Create a new toolbar with specified type
1332 * if a callback list is passed it will be used before the
1333 * common callback list
1335 Toolbar *toolbar_create(ToolbarType type,
1336 GtkWidget *container,
1339 ToolbarItem *toolbar_item;
1342 GtkWidget *icon_wid = NULL;
1343 GtkWidget *icon_news;
1345 GtkWidget *item_news;
1347 guint n_menu_entries;
1348 ComboButton *getall_combo;
1349 ComboButton *reply_combo;
1350 ComboButton *replyall_combo;
1351 ComboButton *replylist_combo;
1352 ComboButton *replysender_combo;
1353 ComboButton *fwd_combo;
1355 GtkTooltips *toolbar_tips;
1356 ToolbarSylpheedActions *action_item;
1358 GSList *toolbar_list;
1359 Toolbar *toolbar_data;
1362 toolbar_tips = gtk_tooltips_new();
1364 toolbar_read_config_file(type);
1365 toolbar_list = toolbar_get_list(type);
1367 toolbar_data = g_new0(Toolbar, 1);
1369 toolbar = gtk_toolbar_new();
1370 gtk_container_add(GTK_CONTAINER(container), toolbar);
1371 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1372 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1373 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1375 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1377 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1378 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1382 toolbar_item = g_new0(ToolbarItem, 1);
1383 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1384 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1385 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1386 toolbar_item->parent = data;
1387 toolbar_item->type = type;
1389 /* collect toolbar items in list to keep track */
1390 toolbar_data->item_list =
1391 g_slist_append(toolbar_data->item_list,
1394 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1395 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1399 icon_wid, G_CALLBACK(toolbar_buttons_cb),
1402 switch (toolbar_item->index) {
1405 toolbar_data->getall_btn = item;
1406 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1407 toolbar_data->getall_btn,
1408 _("Receive Mail on all Accounts"), NULL);
1409 getall_combo = gtkut_combo_button_create(toolbar_data->getall_btn, NULL, 0,
1410 "<GetAll>", (gpointer)toolbar_item);
1411 gtk_button_set_relief(GTK_BUTTON(getall_combo->arrow),
1413 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1414 GTK_WIDGET_PTR(getall_combo),
1415 _("Receive Mail on selected Account"), "Reply");
1416 toolbar_data->getall_combo = getall_combo;
1419 toolbar_data->get_btn = item;
1420 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1421 toolbar_data->get_btn,
1422 _("Receive Mail on current Account"), NULL);
1425 toolbar_data->send_btn = item;
1426 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1427 toolbar_data->send_btn,
1428 _("Send Queued Messages"), NULL);
1430 case A_COMPOSE_EMAIL:
1431 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1432 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1436 icon_news, G_CALLBACK(toolbar_buttons_cb),
1438 toolbar_data->compose_mail_btn = item;
1439 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1440 toolbar_data->compose_mail_btn,
1441 _("Compose Email"), NULL);
1442 toolbar_data->compose_news_btn = item_news;
1443 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1444 toolbar_data->compose_news_btn,
1445 _("Compose News"), NULL);
1447 case A_REPLY_MESSAGE:
1448 toolbar_data->reply_btn = item;
1449 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1450 toolbar_data->reply_btn,
1451 _("Reply to Message"), NULL);
1452 n_menu_entries = sizeof(reply_entries) /
1453 sizeof(reply_entries[0]);
1454 reply_combo = gtkut_combo_button_create(toolbar_data->reply_btn,
1455 reply_entries, n_menu_entries,
1456 "<Reply>", (gpointer)toolbar_item);
1457 gtk_button_set_relief(GTK_BUTTON(reply_combo->arrow),
1459 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1460 GTK_WIDGET_PTR(reply_combo),
1461 _("Reply to Message"), "Reply");
1462 toolbar_data->reply_combo = reply_combo;
1464 case A_REPLY_SENDER:
1465 toolbar_data->replysender_btn = item;
1466 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1467 toolbar_data->replysender_btn,
1468 _("Reply to Sender"), NULL);
1469 n_menu_entries = sizeof(replysender_entries) /
1470 sizeof(replysender_entries[0]);
1471 replysender_combo = gtkut_combo_button_create(toolbar_data->replysender_btn,
1472 replysender_entries, n_menu_entries,
1473 "<ReplySender>", (gpointer)toolbar_item);
1474 gtk_button_set_relief(GTK_BUTTON(replysender_combo->arrow),
1476 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1477 GTK_WIDGET_PTR(replysender_combo),
1478 _("Reply to Sender"), "ReplySender");
1479 toolbar_data->replysender_combo = replysender_combo;
1482 toolbar_data->replyall_btn = item;
1483 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1484 toolbar_data->replyall_btn,
1485 _("Reply to All"), NULL);
1486 n_menu_entries = sizeof(replyall_entries) /
1487 sizeof(replyall_entries[0]);
1488 replyall_combo = gtkut_combo_button_create(toolbar_data->replyall_btn,
1489 replyall_entries, n_menu_entries,
1490 "<ReplyAll>", (gpointer)toolbar_item);
1491 gtk_button_set_relief(GTK_BUTTON(replyall_combo->arrow),
1493 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1494 GTK_WIDGET_PTR(replyall_combo),
1495 _("Reply to All"), "ReplyAll");
1496 toolbar_data->replyall_combo = replyall_combo;
1499 toolbar_data->replylist_btn = item;
1500 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1501 toolbar_data->replylist_btn,
1502 _("Reply to Mailing-list"), NULL);
1503 n_menu_entries = sizeof(replylist_entries) /
1504 sizeof(replylist_entries[0]);
1505 replylist_combo = gtkut_combo_button_create(toolbar_data->replylist_btn,
1506 replylist_entries, n_menu_entries,
1507 "<ReplyList>", (gpointer)toolbar_item);
1508 gtk_button_set_relief(GTK_BUTTON(replylist_combo->arrow),
1510 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1511 GTK_WIDGET_PTR(replylist_combo),
1512 _("Reply to Mailing-list"), "ReplyList");
1513 toolbar_data->replylist_combo = replylist_combo;
1516 toolbar_data->fwd_btn = item;
1517 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1518 toolbar_data->fwd_btn,
1519 _("Forward Message"), NULL);
1520 n_menu_entries = sizeof(forward_entries) /
1521 sizeof(forward_entries[0]);
1522 fwd_combo = gtkut_combo_button_create(toolbar_data->fwd_btn,
1523 forward_entries, n_menu_entries,
1524 "<Forward>", (gpointer)toolbar_item);
1525 gtk_button_set_relief(GTK_BUTTON(fwd_combo->arrow),
1527 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1528 GTK_WIDGET_PTR(fwd_combo),
1529 _("Forward Message"), "Fwd");
1530 toolbar_data->fwd_combo = fwd_combo;
1533 toolbar_data->trash_btn = item;
1534 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1535 toolbar_data->trash_btn,
1536 _("Trash Message"), NULL);
1539 toolbar_data->delete_btn = item;
1540 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1541 toolbar_data->delete_btn,
1542 _("Delete Message"), NULL);
1545 toolbar_data->exec_btn = item;
1546 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1547 toolbar_data->exec_btn,
1548 _("Execute"), NULL);
1551 toolbar_data->prev_btn = item;
1552 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1553 toolbar_data->prev_btn,
1554 _("Go to Previous Unread Message"),
1558 toolbar_data->next_btn = item;
1559 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1560 toolbar_data->next_btn,
1561 _("Go to Next Unread Message"),
1565 /* Compose Toolbar */
1567 toolbar_data->send_btn = item;
1568 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1569 toolbar_data->send_btn,
1570 _("Send Message"), NULL);
1573 toolbar_data->sendl_btn = item;
1574 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1575 toolbar_data->sendl_btn,
1576 _("Put into queue folder and send later"), NULL);
1579 toolbar_data->draft_btn = item;
1580 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1581 toolbar_data->draft_btn,
1582 _("Save to draft folder"), NULL);
1585 toolbar_data->insert_btn = item;
1586 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1587 toolbar_data->insert_btn,
1588 _("Insert file"), NULL);
1591 toolbar_data->attach_btn = item;
1592 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1593 toolbar_data->attach_btn,
1594 _("Attach file"), NULL);
1597 toolbar_data->sig_btn = item;
1598 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1599 toolbar_data->sig_btn,
1600 _("Insert signature"), NULL);
1603 toolbar_data->exteditor_btn = item;
1604 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1605 toolbar_data->exteditor_btn,
1606 _("Edit with external editor"), NULL);
1608 case A_LINEWRAP_CURRENT:
1609 toolbar_data->linewrap_current_btn = item;
1610 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1611 toolbar_data->linewrap_current_btn,
1612 _("Wrap long lines of current paragraph"), NULL);
1614 case A_LINEWRAP_ALL:
1615 toolbar_data->linewrap_all_btn = item;
1616 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1617 toolbar_data->linewrap_all_btn,
1618 _("Wrap all long lines"), NULL);
1621 toolbar_data->addrbook_btn = item;
1622 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1623 toolbar_data->addrbook_btn,
1624 _("Address book"), NULL);
1627 case A_CHECK_SPELLING:
1628 toolbar_data->spellcheck_btn = item;
1629 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1630 toolbar_data->spellcheck_btn,
1631 _("Check spelling"), NULL);
1636 action_item = g_new0(ToolbarSylpheedActions, 1);
1637 action_item->widget = item;
1638 action_item->name = g_strdup(toolbar_item->text);
1640 toolbar_data->action_list =
1641 g_slist_append(toolbar_data->action_list,
1644 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1646 action_item->name, NULL);
1648 gtk_widget_show(item);
1651 /* find and set the tool tip text */
1652 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1654 toolbar_ret_descr_from_val
1655 (toolbar_item->index),
1661 toolbar_data->toolbar = toolbar;
1662 if (type == TOOLBAR_MAIN)
1663 activate_compose_button(toolbar_data,
1664 prefs_common.toolbar_style,
1665 toolbar_data->compose_btn_type);
1667 gtk_widget_show_all(toolbar);
1669 return toolbar_data;
1673 * Free toolbar structures
1675 void toolbar_destroy(Toolbar * toolbar) {
1677 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1678 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1681 void toolbar_update(ToolbarType type, gpointer data)
1683 Toolbar *toolbar_data;
1684 GtkWidget *handlebox;
1685 MainWindow *mainwin = (MainWindow*)data;
1686 Compose *compose = (Compose*)data;
1687 MessageView *msgview = (MessageView*)data;
1691 toolbar_data = mainwin->toolbar;
1692 handlebox = mainwin->handlebox;
1694 case TOOLBAR_COMPOSE:
1695 toolbar_data = compose->toolbar;
1696 handlebox = compose->handlebox;
1698 case TOOLBAR_MSGVIEW:
1699 toolbar_data = msgview->toolbar;
1700 handlebox = msgview->handlebox;
1706 gtk_container_remove(GTK_CONTAINER(handlebox),
1707 GTK_WIDGET(toolbar_data->toolbar));
1709 toolbar_init(toolbar_data);
1710 toolbar_data = toolbar_create(type, handlebox, data);
1713 mainwin->toolbar = toolbar_data;
1715 case TOOLBAR_COMPOSE:
1716 compose->toolbar = toolbar_data;
1718 case TOOLBAR_MSGVIEW:
1719 msgview->toolbar = toolbar_data;
1723 toolbar_style(type, prefs_common.toolbar_style, data);
1725 if (type == TOOLBAR_MAIN) {
1726 toolbar_main_set_sensitive((MainWindow*)data);
1727 account_set_menu_only_toolbar();
1731 void toolbar_main_set_sensitive(gpointer data)
1733 SensitiveCond state;
1735 MainWindow *mainwin = (MainWindow*)data;
1736 Toolbar *toolbar = mainwin->toolbar;
1738 GSList *entry_list = NULL;
1740 typedef struct _Entry Entry;
1747 #define SET_WIDGET_COND(w, c) \
1749 Entry *e = g_new0(Entry, 1); \
1752 entry_list = g_slist_append(entry_list, e); \
1755 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1756 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1757 if (toolbar->getall_btn)
1758 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->getall_combo),
1759 M_HAVE_ACCOUNT|M_UNLOCKED);
1760 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1761 SET_WIDGET_COND(toolbar->reply_btn,
1762 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1763 if (toolbar->reply_btn)
1764 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->reply_combo),
1765 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1766 SET_WIDGET_COND(toolbar->replyall_btn,
1767 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1768 if (toolbar->replyall_btn)
1769 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replyall_combo),
1770 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1771 SET_WIDGET_COND(toolbar->replylist_btn,
1772 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1773 if (toolbar->replylist_btn)
1774 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replylist_combo),
1775 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1776 SET_WIDGET_COND(toolbar->replysender_btn,
1777 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1778 if (toolbar->replysender_btn)
1779 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replysender_combo),
1780 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1781 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1782 if (toolbar->fwd_btn)
1783 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->fwd_combo),
1784 M_HAVE_ACCOUNT|M_TARGET_EXIST);
1785 if (toolbar->fwd_combo) {
1786 GtkWidget *submenu = gtk_item_factory_get_widget(toolbar->fwd_combo->factory, "/Redirect");
1787 SET_WIDGET_COND(submenu, M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1790 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
1791 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1793 SET_WIDGET_COND(toolbar->next_btn, 0);
1796 SET_WIDGET_COND(toolbar->trash_btn,
1797 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1798 SET_WIDGET_COND(toolbar->delete_btn,
1799 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1800 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1802 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
1803 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1805 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1808 #undef SET_WIDGET_COND
1810 state = main_window_get_current_state(mainwin);
1812 for (cur = entry_list; cur != NULL; cur = cur->next) {
1813 Entry *e = (Entry*) cur->data;
1815 if (e->widget != NULL) {
1816 sensitive = ((e->cond & state) == e->cond);
1817 gtk_widget_set_sensitive(e->widget, sensitive);
1821 while (entry_list != NULL) {
1822 Entry *e = (Entry*) entry_list->data;
1826 entry_list = g_slist_remove(entry_list, e);
1829 g_slist_free(entry_list);
1831 activate_compose_button(toolbar,
1832 prefs_common.toolbar_style,
1833 toolbar->compose_btn_type);
1836 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1838 Compose *compose = (Compose*)data;
1839 GSList *items = compose->toolbar->action_list;
1841 if (compose->toolbar->send_btn)
1842 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1843 if (compose->toolbar->sendl_btn)
1844 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1845 if (compose->toolbar->draft_btn )
1846 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1847 if (compose->toolbar->insert_btn )
1848 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1849 if (compose->toolbar->attach_btn)
1850 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1851 if (compose->toolbar->sig_btn)
1852 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1853 if (compose->toolbar->exteditor_btn)
1854 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1855 if (compose->toolbar->linewrap_current_btn)
1856 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
1857 if (compose->toolbar->linewrap_all_btn)
1858 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
1859 if (compose->toolbar->addrbook_btn)
1860 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1862 if (compose->toolbar->spellcheck_btn)
1863 gtk_widget_set_sensitive(compose->toolbar->spellcheck_btn, sensitive);
1865 for (; items != NULL; items = g_slist_next(items)) {
1866 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1867 gtk_widget_set_sensitive(item->widget, sensitive);
1872 * Initialize toolbar structure
1874 void toolbar_init(Toolbar * toolbar) {
1876 toolbar->toolbar = NULL;
1877 toolbar->get_btn = NULL;
1878 toolbar->getall_btn = NULL;
1879 toolbar->getall_combo = NULL;
1880 toolbar->send_btn = NULL;
1881 toolbar->compose_mail_btn = NULL;
1882 toolbar->compose_news_btn = NULL;
1883 toolbar->reply_btn = NULL;
1884 toolbar->replysender_btn = NULL;
1885 toolbar->replyall_btn = NULL;
1886 toolbar->replylist_btn = NULL;
1887 toolbar->fwd_btn = NULL;
1888 toolbar->trash_btn = NULL;
1889 toolbar->delete_btn = NULL;
1890 toolbar->prev_btn = NULL;
1891 toolbar->next_btn = NULL;
1892 toolbar->exec_btn = NULL;
1894 /* compose buttons */
1895 toolbar->sendl_btn = NULL;
1896 toolbar->draft_btn = NULL;
1897 toolbar->insert_btn = NULL;
1898 toolbar->attach_btn = NULL;
1899 toolbar->sig_btn = NULL;
1900 toolbar->exteditor_btn = NULL;
1901 toolbar->linewrap_current_btn = NULL;
1902 toolbar->linewrap_all_btn = NULL;
1903 toolbar->addrbook_btn = NULL;
1905 toolbar->spellcheck_btn = NULL;
1908 toolbar_destroy(toolbar);
1913 static void toolbar_reply(gpointer data, guint action)
1915 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1916 MainWindow *mainwin;
1917 MessageView *msgview;
1918 GSList *msginfo_list = NULL;
1920 g_return_if_fail(toolbar_item != NULL);
1922 switch (toolbar_item->type) {
1924 mainwin = (MainWindow*)toolbar_item->parent;
1925 msginfo_list = summary_get_selection(mainwin->summaryview);
1926 msgview = (MessageView*)mainwin->messageview;
1928 case TOOLBAR_MSGVIEW:
1929 msgview = (MessageView*)toolbar_item->parent;
1930 g_return_if_fail(msgview != NULL);
1931 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
1937 g_return_if_fail(msgview != NULL);
1938 g_return_if_fail(msginfo_list != NULL);
1939 compose_reply_from_messageview(msgview, msginfo_list, action);
1940 g_slist_free(msginfo_list);
1942 /* TODO: update reply state ion summaryview */
1946 /* exported functions */
1948 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
1950 MainWindow *mainwin = (MainWindow*)data;
1952 inc_mail(mainwin, prefs_common.newmail_notify_manu);
1955 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
1957 MainWindow *mainwin = (MainWindow*)data;
1959 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
1962 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
1967 if (prefs_common.work_offline)
1968 if (alertpanel(_("Offline warning"),
1969 _("You're working offline. Override?"),
1970 GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
1973 /* ask for confirmation before sending queued messages only
1974 in online mode and if there is at least one message queued
1975 in any of the folder queue
1977 if (prefs_common.confirm_send_queued_messages) {
1979 /* check if there's a queued message */
1980 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
1981 Folder *folder = list->data;
1983 found = !procmsg_queue_is_empty(folder->queue);
1985 /* if necessary, ask for confirmation before sending */
1986 if (found && !prefs_common.work_offline) {
1987 if (alertpanel(_("Send queued messages"),
1988 _("Send all queued messages?"),
1989 GTK_STOCK_YES, GTK_STOCK_NO, NULL) != G_ALERTDEFAULT)
1994 for (list = folder_get_list(); list != NULL; list = list->next) {
1995 Folder *folder = list->data;
1997 if (folder->queue) {
1998 if (procmsg_send_queue(folder->queue,
1999 prefs_common.savemsg) < 0)
2000 alertpanel_error(_("Some errors occurred while "
2001 "sending queued messages."));
2006 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2008 MainWindow *mainwin = (MainWindow*)data;
2009 PrefsAccount *ac = NULL;
2010 FolderItem *item = mainwin->summaryview->folder_item;
2015 ac = account_find_from_item(item);
2016 if (ac && ac->protocol != A_NNTP) {
2017 compose_new_with_folderitem(ac, item); /* CLAWS */
2023 * CLAWS - use current account
2025 if (cur_account && (cur_account->protocol != A_NNTP)) {
2026 compose_new_with_folderitem(cur_account, item);
2031 * CLAWS - just get the first one
2033 list = account_get_list();
2034 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2035 ac = (PrefsAccount *) cur->data;
2036 if (ac->protocol != A_NNTP) {
2037 compose_new_with_folderitem(ac, item);
2043 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2045 MainWindow *mainwin = (MainWindow*)data;
2046 PrefsAccount * ac = NULL;
2050 if (mainwin->summaryview->folder_item) {
2051 ac = mainwin->summaryview->folder_item->folder->account;
2052 if (ac && ac->protocol == A_NNTP) {
2053 compose_new_with_folderitem(ac,
2054 mainwin->summaryview->folder_item);
2059 list = account_get_list();
2060 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2061 ac = (PrefsAccount *) cur->data;
2062 if (ac->protocol == A_NNTP) {
2063 compose_new_with_folderitem(ac,
2064 mainwin->summaryview->folder_item);