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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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,
95 static void toolbar_compose_cb (GtkWidget *widget,
98 static void toolbar_reply_cb (GtkWidget *widget,
101 static void toolbar_reply_to_all_cb (GtkWidget *widget,
104 static void toolbar_reply_to_list_cb (GtkWidget *widget,
107 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
110 static void toolbar_forward_cb (GtkWidget *widget,
113 static void toolbar_prev_unread_cb (GtkWidget *widget,
115 static void toolbar_next_unread_cb (GtkWidget *widget,
118 static void toolbar_ignore_thread_cb (GtkWidget *widget,
121 static void toolbar_print_cb (GtkWidget *widget,
124 static void toolbar_actions_execute_cb (GtkWidget *widget,
128 static void toolbar_send_cb (GtkWidget *widget,
130 static void toolbar_send_later_cb (GtkWidget *widget,
132 static void toolbar_draft_cb (GtkWidget *widget,
134 static void toolbar_insert_cb (GtkWidget *widget,
136 static void toolbar_attach_cb (GtkWidget *widget,
138 static void toolbar_sig_cb (GtkWidget *widget,
140 static void toolbar_ext_editor_cb (GtkWidget *widget,
142 static void toolbar_linewrap_current_cb (GtkWidget *widget,
144 static void toolbar_linewrap_all_cb (GtkWidget *widget,
146 static void toolbar_addrbook_cb (GtkWidget *widget,
149 static void toolbar_check_spelling_cb (GtkWidget *widget,
156 } toolbar_text [] = {
157 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
158 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
159 { "A_SEND_QUEUED", N_("Send Queued Messages") },
160 { "A_COMPOSE_EMAIL", N_("Compose Email") },
161 { "A_COMPOSE_NEWS", N_("Compose News") },
162 { "A_REPLY_MESSAGE", N_("Reply to Message") },
163 { "A_REPLY_SENDER", N_("Reply to Sender") },
164 { "A_REPLY_ALL", N_("Reply to All") },
165 { "A_REPLY_ML", N_("Reply to Mailing-list") },
166 { "A_FORWARD", N_("Forward Message") },
167 { "A_DELETE", N_("Delete Message") },
168 { "A_EXECUTE", N_("Execute") },
169 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
170 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
171 { "A_IGNORE_THREAD", N_("Ignore thread") },
172 { "A_PRINT", N_("Print") },
174 { "A_SEND", N_("Send Message") },
175 { "A_SENDL", N_("Put into queue folder and send later") },
176 { "A_DRAFT", N_("Save to draft folder") },
177 { "A_INSERT", N_("Insert file") },
178 { "A_ATTACH", N_("Attach file") },
179 { "A_SIG", N_("Insert signature") },
180 { "A_EXTEDITOR", N_("Edit with external editor") },
181 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
182 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
183 { "A_ADDRBOOK", N_("Address book") },
185 { "A_CHECK_SPELLING", N_("Check spelling") },
187 { "A_SYL_ACTIONS", N_("Sylpheed Actions Feature") },
188 { "A_SEPARATOR", "Separator" }
191 /* struct holds configuration files and a list of
192 * currently active toolbar items
193 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
197 const gchar *conf_file;
199 } toolbar_config[3] = {
200 { "toolbar_main.xml", NULL},
201 { "toolbar_compose.xml", NULL},
202 { "toolbar_msgview.xml", NULL}
205 static GtkItemFactoryEntry reply_entries[] =
207 {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
208 {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
210 static GtkItemFactoryEntry replyall_entries[] =
212 {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
213 {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
215 static GtkItemFactoryEntry replylist_entries[] =
217 {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
218 {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
220 static GtkItemFactoryEntry replysender_entries[] =
222 {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
223 {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
225 static GtkItemFactoryEntry forward_entries[] =
227 {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
228 {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
229 {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, NULL}
233 gint toolbar_ret_val_from_descr(const gchar *descr)
237 for (i = 0; i < N_ACTION_VAL; i++) {
238 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
245 gchar *toolbar_ret_descr_from_val(gint val)
247 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
249 return gettext(toolbar_text[val].descr);
252 static gint toolbar_ret_val_from_text(const gchar *text)
256 for (i = 0; i < N_ACTION_VAL; i++) {
257 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
264 static gchar *toolbar_ret_text_from_val(gint val)
266 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
268 return toolbar_text[val].index_str;
271 gboolean toolbar_is_duplicate(gint action, ToolbarType source)
275 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
278 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
279 ToolbarItem *item = (ToolbarItem*) cur->data;
281 if (item->index == action)
287 /* depending on toolbar type this function
288 returns a list of available toolbar events being
289 displayed by prefs_toolbar
291 GList *toolbar_get_action_items(ToolbarType source)
296 if (source == TOOLBAR_MAIN) {
297 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
298 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
299 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
300 A_DELETE, A_EXECUTE, A_GOTO_PREV,
301 A_GOTO_NEXT, A_IGNORE_THREAD, A_PRINT,
302 A_ADDRBOOK, A_SYL_ACTIONS };
304 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
305 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
306 if (main_items[i] == A_PRINT) {
307 g_print("$$$ descr %s, trans %s\n",
308 toolbar_text[main_items[i]].descr,
309 gettext(toolbar_text[main_items[i]].descr));
313 else if (source == TOOLBAR_COMPOSE) {
314 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
315 A_INSERT, A_ATTACH, A_SIG,
316 A_EXTEDITOR, A_LINEWRAP_CURRENT,
317 A_LINEWRAP_ALL, A_ADDRBOOK,
323 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
324 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
326 else if (source == TOOLBAR_MSGVIEW) {
327 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
328 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
329 A_DELETE, A_GOTO_PREV, A_GOTO_NEXT,
330 A_ADDRBOOK, A_SYL_ACTIONS };
332 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
333 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
339 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
343 ToolbarItem *item = NULL;
345 attr = xml_get_current_tag_attr(file);
346 item = g_new0(ToolbarItem, 1);
348 name = ((XMLAttr *)attr->data)->name;
349 value = ((XMLAttr *)attr->data)->value;
351 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
352 item->file = g_strdup (value);
353 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
354 item->text = g_strdup (value);
355 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
356 item->index = toolbar_ret_val_from_text(value);
358 attr = g_list_next(attr);
360 if (item->index != -1) {
362 if (!toolbar_is_duplicate(item->index, source))
363 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
368 static void toolbar_set_default_main(void)
374 } default_toolbar[] = {
375 { A_RECEIVE_CUR, STOCK_PIXMAP_MAIL_RECEIVE, _("Get") },
376 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get All") },
377 { A_SEPARATOR, 0, ("") },
378 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
379 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Email") },
380 { A_SEPARATOR, 0, ("") },
381 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
382 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
383 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
384 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
385 { A_SEPARATOR, 0, ("") },
386 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
387 { A_EXECUTE, STOCK_PIXMAP_EXEC, _("Execute") },
388 { A_GOTO_PREV, STOCK_PIXMAP_UP_ARROW, _("Previous")},
389 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
394 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
396 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
398 if (default_toolbar[i].action != A_SEPARATOR) {
400 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
402 toolbar_item->file = g_strdup(file);
403 toolbar_item->index = default_toolbar[i].action;
404 toolbar_item->text = g_strdup(default_toolbar[i].text);
407 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
408 toolbar_item->index = A_SEPARATOR;
411 if (toolbar_item->index != -1) {
412 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
413 toolbar_config[TOOLBAR_MAIN].item_list =
414 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
419 static void toolbar_set_default_compose(void)
425 } default_toolbar[] = {
426 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
427 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
428 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
429 { A_SEPARATOR, 0, ("") },
430 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
431 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
432 { A_SIG, STOCK_PIXMAP_MAIL_SIGN, _("Signature") },
433 { A_SEPARATOR, 0, ("") },
434 { A_EXTEDITOR, STOCK_PIXMAP_EDIT_EXTERN, _("Editor") },
435 { A_LINEWRAP_CURRENT, STOCK_PIXMAP_LINEWRAP_CURRENT, _("Wrap paragraph") },
436 { A_LINEWRAP_ALL, STOCK_PIXMAP_LINEWRAP_ALL, _("Wrap all") },
437 { A_SEPARATOR, 0, ("") },
438 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
443 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
445 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
447 if (default_toolbar[i].action != A_SEPARATOR) {
449 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
451 toolbar_item->file = g_strdup(file);
452 toolbar_item->index = default_toolbar[i].action;
453 toolbar_item->text = g_strdup(default_toolbar[i].text);
456 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
457 toolbar_item->index = A_SEPARATOR;
460 if (toolbar_item->index != -1) {
461 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
462 toolbar_config[TOOLBAR_COMPOSE].item_list =
463 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
468 static void toolbar_set_default_msgview(void)
474 } default_toolbar[] = {
475 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
476 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
477 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
478 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
479 { A_SEPARATOR, 0, ("") },
480 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
481 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
486 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
488 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
490 if (default_toolbar[i].action != A_SEPARATOR) {
492 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
494 toolbar_item->file = g_strdup(file);
495 toolbar_item->index = default_toolbar[i].action;
496 toolbar_item->text = g_strdup(default_toolbar[i].text);
499 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
500 toolbar_item->index = A_SEPARATOR;
503 if (toolbar_item->index != -1) {
504 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
505 toolbar_config[TOOLBAR_MSGVIEW].item_list =
506 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
511 void toolbar_set_default(ToolbarType source)
513 if (source == TOOLBAR_MAIN)
514 toolbar_set_default_main();
515 else if (source == TOOLBAR_COMPOSE)
516 toolbar_set_default_compose();
517 else if (source == TOOLBAR_MSGVIEW)
518 toolbar_set_default_msgview();
521 void toolbar_save_config_file(ToolbarType source)
526 gchar *fileSpec = NULL;
528 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
530 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
531 pfile = prefs_write_open(fileSpec);
535 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL);
537 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
539 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
540 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
542 if (toolbar_item->index != A_SEPARATOR) {
543 fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
545 TOOLBAR_ICON_FILE, toolbar_item->file,
547 xml_file_put_escape_str(fp, toolbar_item->text);
548 fprintf(fp, "\" %s=\"%s\"/>\n",
550 toolbar_ret_text_from_val(toolbar_item->index));
552 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
556 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
558 if (prefs_file_close (pfile) < 0 )
559 g_warning("failed to write toolbar configuration to file\n");
561 g_warning("failed to open toolbar configuration file for writing\n");
564 void toolbar_read_config_file(ToolbarType source)
566 XMLFile *file = NULL;
567 gchar *fileSpec = NULL;
572 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
574 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
575 file = xml_open_file(fileSpec);
578 toolbar_clear_list(source);
582 || (xml_get_dtd(file))
583 || (xml_parse_next_tag(file))
584 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
585 xml_close_file(file);
589 attr = xml_get_current_tag_attr(file);
596 if (xml_parse_next_tag(file))
599 /* Get next tag (icon, icon_text or icon_action) */
600 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
601 toolbar_parse_item(file, source);
602 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
603 ToolbarItem *item = g_new0(ToolbarItem, 1);
605 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
606 item->index = A_SEPARATOR;
607 toolbar_config[source].item_list =
608 g_slist_append(toolbar_config[source].item_list, item);
612 xml_close_file(file);
615 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
617 if (source == TOOLBAR_MAIN)
618 toolbar_set_default(TOOLBAR_MAIN);
619 else if (source == TOOLBAR_COMPOSE)
620 toolbar_set_default(TOOLBAR_COMPOSE);
621 else if (source == TOOLBAR_MSGVIEW)
622 toolbar_set_default(TOOLBAR_MSGVIEW);
624 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
628 toolbar_save_config_file(source);
633 * clears list of toolbar items read from configuration files
635 void toolbar_clear_list(ToolbarType source)
637 while (toolbar_config[source].item_list != NULL) {
638 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
640 toolbar_config[source].item_list =
641 g_slist_remove(toolbar_config[source].item_list, item);
649 g_slist_free(toolbar_config[source].item_list);
654 * return list of Toolbar items
656 GSList *toolbar_get_list(ToolbarType source)
660 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
661 list = toolbar_config[source].item_list;
666 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
668 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
670 toolbar_item->file = g_strdup(t_item->file);
671 toolbar_item->text = g_strdup(t_item->text);
672 toolbar_item->index = t_item->index;
674 toolbar_config[source].item_list =
675 g_slist_append(toolbar_config[source].item_list,
679 void toolbar_action_execute(GtkWidget *widget,
685 gchar *action, *action_p;
686 gboolean found = FALSE;
689 for (cur = action_list; cur != NULL; cur = cur->next) {
690 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
692 if (widget == act->widget) {
694 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
695 action = g_strdup((gchar*)lop->data);
697 action_p = strstr(action, ": ");
699 if (g_utf8_collate(act->name, action) == 0) {
713 actions_execute(data, i, widget, source);
715 g_warning ("Error: did not find Sylpheed Action to execute");
718 static void activate_compose_button (Toolbar *toolbar,
720 ComposeButtonType type)
722 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
725 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
726 : toolbar->compose_news_btn);
727 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
728 : toolbar->compose_mail_btn);
729 toolbar->compose_btn_type = type;
732 void toolbar_set_compose_button(Toolbar *toolbar,
733 ComposeButtonType compose_btn_type)
735 if (toolbar->compose_btn_type != compose_btn_type)
736 activate_compose_button(toolbar,
737 prefs_common.toolbar_style,
741 void toolbar_toggle(guint action, gpointer data)
743 MainWindow *mainwin = (MainWindow*)data;
747 g_return_if_fail(mainwin != NULL);
749 toolbar_style(TOOLBAR_MAIN, action, mainwin);
751 list = compose_get_compose_list();
752 for (cur = list; cur != NULL; cur = cur->next) {
753 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
755 list = messageview_get_msgview_list();
756 for (cur = list; cur != NULL; cur = cur->next) {
757 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
762 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
764 switch ((ToolbarStyle)action) {
766 gtk_widget_hide(handlebox_wid);
769 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
773 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
777 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
784 prefs_common.toolbar_style = (ToolbarStyle)action;
785 gtk_widget_set_size_request(handlebox_wid, 1, -1);
787 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
788 gtk_widget_show(handlebox_wid);
789 gtk_widget_queue_resize(handlebox_wid);
793 * Change the style of toolbar
795 static void toolbar_style(ToolbarType type, guint action, gpointer data)
797 GtkWidget *handlebox_wid;
798 GtkWidget *toolbar_wid;
799 MainWindow *mainwin = (MainWindow*)data;
800 Compose *compose = (Compose*)data;
801 MessageView *msgview = (MessageView*)data;
803 g_return_if_fail(data != NULL);
807 handlebox_wid = mainwin->handlebox;
808 toolbar_wid = mainwin->toolbar->toolbar;
810 case TOOLBAR_COMPOSE:
811 handlebox_wid = compose->handlebox;
812 toolbar_wid = compose->toolbar->toolbar;
814 case TOOLBAR_MSGVIEW:
815 handlebox_wid = msgview->handlebox;
816 toolbar_wid = msgview->toolbar->toolbar;
822 toolbar_set_style(toolbar_wid, handlebox_wid, action);
825 /* Toolbar handling */
826 static void toolbar_inc_cb(GtkWidget *widget,
829 ToolbarItem *toolbar_item = (ToolbarItem*)data;
832 g_return_if_fail(toolbar_item != NULL);
834 switch (toolbar_item->type) {
836 mainwin = (MainWindow*)toolbar_item->parent;
837 inc_mail_cb(mainwin, 0, NULL);
844 static void toolbar_inc_all_cb(GtkWidget *widget,
847 ToolbarItem *toolbar_item = (ToolbarItem*)data;
850 g_return_if_fail(toolbar_item != NULL);
852 switch (toolbar_item->type) {
854 mainwin = (MainWindow*)toolbar_item->parent;
855 inc_all_account_mail_cb(mainwin, 0, NULL);
862 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
864 ToolbarItem *toolbar_item = (ToolbarItem*)data;
867 g_return_if_fail(toolbar_item != NULL);
869 switch (toolbar_item->type) {
871 mainwin = (MainWindow*)toolbar_item->parent;
872 send_queue_cb(mainwin, 0, NULL);
879 static void toolbar_exec_cb(GtkWidget *widget,
882 MainWindow *mainwin = get_mainwin(data);
884 g_return_if_fail(mainwin != NULL);
885 summary_execute(mainwin->summaryview);
889 * Delete current/selected(s) message(s)
891 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
893 ToolbarItem *toolbar_item = (ToolbarItem*)data;
896 g_return_if_fail(toolbar_item != NULL);
897 g_return_if_fail(toolbar_item->parent);
899 switch (toolbar_item->type) {
900 case TOOLBAR_MSGVIEW:
901 messageview_delete((MessageView *)toolbar_item->parent);
904 mainwin = (MainWindow *)toolbar_item->parent;
905 summary_delete_trash(mainwin->summaryview);
908 debug_print("toolbar event not supported\n");
915 * Compose new message
917 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
919 ToolbarItem *toolbar_item = (ToolbarItem*)data;
921 MessageView *msgview;
923 g_return_if_fail(toolbar_item != NULL);
925 switch (toolbar_item->type) {
927 mainwin = (MainWindow*)toolbar_item->parent;
928 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
929 compose_news_cb(mainwin, 0, NULL);
931 compose_mail_cb(mainwin, 0, NULL);
933 case TOOLBAR_MSGVIEW:
934 msgview = (MessageView*)toolbar_item->parent;
935 compose_new_with_folderitem(NULL,
936 msgview->msginfo->folder);
939 debug_print("toolbar event not supported\n");
947 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
949 toolbar_reply(data, prefs_common.reply_with_quote ?
950 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
955 * Reply message to Sender and All recipients
957 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
960 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
961 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
966 * Reply to Mailing List
968 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
971 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
972 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
977 * Reply to sender of message
979 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
982 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
983 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
989 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
991 ToolbarItem *toolbar_item = (ToolbarItem*)data;
994 g_return_if_fail(toolbar_item != NULL);
996 switch (toolbar_item->type) {
998 case TOOLBAR_MSGVIEW:
1001 case TOOLBAR_COMPOSE:
1002 compose = (Compose *)toolbar_item->parent;
1007 addressbook_open(compose);
1012 * Forward current/selected(s) message(s)
1014 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1016 toolbar_reply(data, COMPOSE_FORWARD);
1020 * Goto Prev Unread Message
1022 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1024 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1025 MainWindow *mainwin;
1026 MessageView *msgview;
1028 g_return_if_fail(toolbar_item != NULL);
1030 switch (toolbar_item->type) {
1032 mainwin = (MainWindow*)toolbar_item->parent;
1033 summary_select_prev_unread(mainwin->summaryview);
1036 case TOOLBAR_MSGVIEW:
1037 msgview = (MessageView*)toolbar_item->parent;
1038 summary_select_prev_unread(msgview->mainwin->summaryview);
1040 /* Now we need to update the messageview window */
1041 if (msgview->mainwin->summaryview->selected) {
1042 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1044 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1045 msgview->mainwin->summaryview->selected);
1047 messageview_show(msgview, msginfo,
1048 msgview->all_headers);
1050 gtk_widget_destroy(msgview->window);
1054 debug_print("toolbar event not supported\n");
1059 * Goto Next Unread Message
1061 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1063 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1064 MainWindow *mainwin;
1065 MessageView *msgview;
1067 g_return_if_fail(toolbar_item != NULL);
1069 switch (toolbar_item->type) {
1071 mainwin = (MainWindow*)toolbar_item->parent;
1072 summary_select_next_unread(mainwin->summaryview);
1075 case TOOLBAR_MSGVIEW:
1076 msgview = (MessageView*)toolbar_item->parent;
1077 summary_select_next_unread(msgview->mainwin->summaryview);
1079 /* Now we need to update the messageview window */
1080 if (msgview->mainwin->summaryview->selected) {
1081 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1083 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1084 msgview->mainwin->summaryview->selected);
1086 messageview_show(msgview, msginfo,
1087 msgview->all_headers);
1089 gtk_widget_destroy(msgview->window);
1093 debug_print("toolbar event not supported\n");
1097 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1099 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1100 MainWindow *mainwin;
1102 g_return_if_fail(toolbar_item != NULL);
1104 switch (toolbar_item->type) {
1106 mainwin = (MainWindow *) toolbar_item->parent;
1107 summary_toggle_ignore_thread(mainwin->summaryview);
1109 case TOOLBAR_MSGVIEW:
1110 /* TODO: see toolbar_next_unread_cb() if you need
1111 * this in the message view */
1114 debug_print("toolbar event not supported\n");
1119 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1121 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1122 MainWindow *mainwin;
1124 g_return_if_fail(toolbar_item != NULL);
1126 switch (toolbar_item->type) {
1128 mainwin = (MainWindow *) toolbar_item->parent;
1129 summary_print(mainwin->summaryview);
1131 case TOOLBAR_MSGVIEW:
1132 /* TODO: see toolbar_next_unread_cb() if you need
1133 * this in the message view */
1136 debug_print("toolbar event not supported\n");
1141 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1143 compose_toolbar_cb(A_SEND, data);
1146 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1148 compose_toolbar_cb(A_SENDL, data);
1151 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1153 compose_toolbar_cb(A_DRAFT, data);
1156 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1158 compose_toolbar_cb(A_INSERT, data);
1161 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1163 compose_toolbar_cb(A_ATTACH, data);
1166 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1168 compose_toolbar_cb(A_SIG, data);
1171 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1173 compose_toolbar_cb(A_EXTEDITOR, data);
1176 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1178 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1181 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1183 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1187 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1189 compose_toolbar_cb(A_CHECK_SPELLING, data);
1193 * Execute actions from toolbar
1195 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1197 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1198 GSList *action_list;
1199 MainWindow *mainwin;
1201 MessageView *msgview;
1202 gpointer parent = toolbar_item->parent;
1204 g_return_if_fail(toolbar_item != NULL);
1206 switch (toolbar_item->type) {
1208 mainwin = (MainWindow*)parent;
1209 action_list = mainwin->toolbar->action_list;
1211 case TOOLBAR_COMPOSE:
1212 compose = (Compose*)parent;
1213 action_list = compose->toolbar->action_list;
1215 case TOOLBAR_MSGVIEW:
1216 msgview = (MessageView*)parent;
1217 action_list = msgview->toolbar->action_list;
1220 debug_print("toolbar event not supported\n");
1223 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1226 static MainWindow *get_mainwin(gpointer data)
1228 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1229 MainWindow *mainwin = NULL;
1230 MessageView *msgview;
1232 g_return_val_if_fail(toolbar_item != NULL, NULL);
1234 switch(toolbar_item->type) {
1236 mainwin = (MainWindow*)toolbar_item->parent;
1238 case TOOLBAR_MSGVIEW:
1239 msgview = (MessageView*)toolbar_item->parent;
1240 mainwin = (MainWindow*)msgview->mainwin;
1249 static void toolbar_buttons_cb(GtkWidget *widget,
1256 void (*func)(GtkWidget *widget, gpointer data);
1258 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1259 { A_RECEIVE_CUR, toolbar_inc_cb },
1260 { A_SEND_QUEUED, toolbar_send_queued_cb },
1261 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1262 { A_COMPOSE_NEWS, toolbar_compose_cb },
1263 { A_REPLY_MESSAGE, toolbar_reply_cb },
1264 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1265 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1266 { A_REPLY_ML, toolbar_reply_to_list_cb },
1267 { A_FORWARD, toolbar_forward_cb },
1268 { A_DELETE, toolbar_delete_cb },
1269 { A_EXECUTE, toolbar_exec_cb },
1270 { A_GOTO_PREV, toolbar_prev_unread_cb },
1271 { A_GOTO_NEXT, toolbar_next_unread_cb },
1272 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1273 { A_PRINT, toolbar_print_cb },
1275 { A_SEND, toolbar_send_cb },
1276 { A_SENDL, toolbar_send_later_cb },
1277 { A_DRAFT, toolbar_draft_cb },
1278 { A_INSERT, toolbar_insert_cb },
1279 { A_ATTACH, toolbar_attach_cb },
1280 { A_SIG, toolbar_sig_cb },
1281 { A_EXTEDITOR, toolbar_ext_editor_cb },
1282 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1283 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1284 { A_ADDRBOOK, toolbar_addrbook_cb },
1286 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1288 { A_SYL_ACTIONS, toolbar_actions_execute_cb }
1291 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1293 for (i = 0; i < num_items; i++) {
1294 if (callbacks[i].index == item->index) {
1295 callbacks[i].func(widget, item);
1302 * Create a new toolbar with specified type
1303 * if a callback list is passed it will be used before the
1304 * common callback list
1306 Toolbar *toolbar_create(ToolbarType type,
1307 GtkWidget *container,
1310 ToolbarItem *toolbar_item;
1313 GtkWidget *icon_wid = NULL;
1314 GtkWidget *icon_news;
1316 GtkWidget *item_news;
1318 guint n_menu_entries;
1319 ComboButton *reply_combo;
1320 ComboButton *replyall_combo;
1321 ComboButton *replylist_combo;
1322 ComboButton *replysender_combo;
1323 ComboButton *fwd_combo;
1325 GtkTooltips *toolbar_tips;
1326 ToolbarSylpheedActions *action_item;
1328 GSList *toolbar_list;
1329 Toolbar *toolbar_data;
1332 toolbar_tips = gtk_tooltips_new();
1334 toolbar_read_config_file(type);
1335 toolbar_list = toolbar_get_list(type);
1337 toolbar_data = g_new0(Toolbar, 1);
1339 toolbar = gtk_toolbar_new();
1340 gtk_container_add(GTK_CONTAINER(container), toolbar);
1341 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1342 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1343 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1345 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1347 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1348 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1352 toolbar_item = g_new0(ToolbarItem, 1);
1353 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1354 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1355 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1356 toolbar_item->parent = data;
1357 toolbar_item->type = type;
1359 /* collect toolbar items in list to keep track */
1360 toolbar_data->item_list =
1361 g_slist_append(toolbar_data->item_list,
1364 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1365 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1369 icon_wid, G_CALLBACK(toolbar_buttons_cb),
1372 switch (toolbar_item->index) {
1375 toolbar_data->getall_btn = item;
1376 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1377 toolbar_data->getall_btn,
1378 _("Receive Mail on all Accounts"), NULL);
1381 toolbar_data->get_btn = item;
1382 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1383 toolbar_data->get_btn,
1384 _("Receive Mail on current Account"), NULL);
1387 toolbar_data->send_btn = item;
1388 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1389 toolbar_data->send_btn,
1390 _("Send Queued Messages"), NULL);
1392 case A_COMPOSE_EMAIL:
1393 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1394 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1398 icon_news, G_CALLBACK(toolbar_buttons_cb),
1400 toolbar_data->compose_mail_btn = item;
1401 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1402 toolbar_data->compose_mail_btn,
1403 _("Compose Email"), NULL);
1404 toolbar_data->compose_news_btn = item_news;
1405 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1406 toolbar_data->compose_news_btn,
1407 _("Compose News"), NULL);
1409 case A_REPLY_MESSAGE:
1410 toolbar_data->reply_btn = item;
1411 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1412 toolbar_data->reply_btn,
1413 _("Reply to Message"), NULL);
1414 n_menu_entries = sizeof(reply_entries) /
1415 sizeof(reply_entries[0]);
1416 reply_combo = gtkut_combo_button_create(toolbar_data->reply_btn,
1417 reply_entries, n_menu_entries,
1418 "<Reply>", (gpointer)toolbar_item);
1419 gtk_button_set_relief(GTK_BUTTON(reply_combo->arrow),
1421 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1422 GTK_WIDGET_PTR(reply_combo),
1423 _("Reply to Message"), "Reply");
1424 toolbar_data->reply_combo = reply_combo;
1426 case A_REPLY_SENDER:
1427 toolbar_data->replysender_btn = item;
1428 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1429 toolbar_data->replysender_btn,
1430 _("Reply to Sender"), NULL);
1431 n_menu_entries = sizeof(replysender_entries) /
1432 sizeof(replysender_entries[0]);
1433 replysender_combo = gtkut_combo_button_create(toolbar_data->replysender_btn,
1434 replysender_entries, n_menu_entries,
1435 "<ReplySender>", (gpointer)toolbar_item);
1436 gtk_button_set_relief(GTK_BUTTON(replysender_combo->arrow),
1438 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1439 GTK_WIDGET_PTR(replysender_combo),
1440 _("Reply to Sender"), "ReplySender");
1441 toolbar_data->replysender_combo = replysender_combo;
1444 toolbar_data->replyall_btn = item;
1445 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1446 toolbar_data->replyall_btn,
1447 _("Reply to All"), NULL);
1448 n_menu_entries = sizeof(replyall_entries) /
1449 sizeof(replyall_entries[0]);
1450 replyall_combo = gtkut_combo_button_create(toolbar_data->replyall_btn,
1451 replyall_entries, n_menu_entries,
1452 "<ReplyAll>", (gpointer)toolbar_item);
1453 gtk_button_set_relief(GTK_BUTTON(replyall_combo->arrow),
1455 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1456 GTK_WIDGET_PTR(replyall_combo),
1457 _("Reply to All"), "ReplyAll");
1458 toolbar_data->replyall_combo = replyall_combo;
1461 toolbar_data->replylist_btn = item;
1462 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1463 toolbar_data->replylist_btn,
1464 _("Reply to Mailing-list"), NULL);
1465 n_menu_entries = sizeof(replylist_entries) /
1466 sizeof(replylist_entries[0]);
1467 replylist_combo = gtkut_combo_button_create(toolbar_data->replylist_btn,
1468 replylist_entries, n_menu_entries,
1469 "<ReplyList>", (gpointer)toolbar_item);
1470 gtk_button_set_relief(GTK_BUTTON(replylist_combo->arrow),
1472 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1473 GTK_WIDGET_PTR(replylist_combo),
1474 _("Reply to Mailing-list"), "ReplyList");
1475 toolbar_data->replylist_combo = replylist_combo;
1478 toolbar_data->fwd_btn = item;
1479 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1480 toolbar_data->fwd_btn,
1481 _("Forward Message"), NULL);
1482 n_menu_entries = sizeof(forward_entries) /
1483 sizeof(forward_entries[0]);
1484 fwd_combo = gtkut_combo_button_create(toolbar_data->fwd_btn,
1485 forward_entries, n_menu_entries,
1486 "<Forward>", (gpointer)toolbar_item);
1487 gtk_button_set_relief(GTK_BUTTON(fwd_combo->arrow),
1489 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1490 GTK_WIDGET_PTR(fwd_combo),
1491 _("Forward Message"), "Fwd");
1492 toolbar_data->fwd_combo = fwd_combo;
1495 toolbar_data->delete_btn = item;
1496 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1497 toolbar_data->delete_btn,
1498 _("Delete Message"), NULL);
1501 toolbar_data->exec_btn = item;
1502 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1503 toolbar_data->exec_btn,
1504 _("Execute"), NULL);
1507 toolbar_data->prev_btn = item;
1508 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1509 toolbar_data->prev_btn,
1510 _("Go to Previous Unread Message"),
1514 toolbar_data->next_btn = item;
1515 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1516 toolbar_data->next_btn,
1517 _("Go to Next Unread Message"),
1521 /* Compose Toolbar */
1523 toolbar_data->send_btn = item;
1524 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1525 toolbar_data->send_btn,
1526 _("Send Message"), NULL);
1529 toolbar_data->sendl_btn = item;
1530 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1531 toolbar_data->sendl_btn,
1532 _("Put into queue folder and send later"), NULL);
1535 toolbar_data->draft_btn = item;
1536 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1537 toolbar_data->draft_btn,
1538 _("Save to draft folder"), NULL);
1541 toolbar_data->insert_btn = item;
1542 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1543 toolbar_data->insert_btn,
1544 _("Insert file"), NULL);
1547 toolbar_data->attach_btn = item;
1548 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1549 toolbar_data->attach_btn,
1550 _("Attach file"), NULL);
1553 toolbar_data->sig_btn = item;
1554 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1555 toolbar_data->sig_btn,
1556 _("Insert signature"), NULL);
1559 toolbar_data->exteditor_btn = item;
1560 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1561 toolbar_data->exteditor_btn,
1562 _("Edit with external editor"), NULL);
1564 case A_LINEWRAP_CURRENT:
1565 toolbar_data->linewrap_current_btn = item;
1566 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1567 toolbar_data->linewrap_current_btn,
1568 _("Wrap long lines of current paragraph"), NULL);
1570 case A_LINEWRAP_ALL:
1571 toolbar_data->linewrap_all_btn = item;
1572 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1573 toolbar_data->linewrap_all_btn,
1574 _("Wrap all long lines"), NULL);
1577 toolbar_data->addrbook_btn = item;
1578 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1579 toolbar_data->addrbook_btn,
1580 _("Address book"), NULL);
1583 case A_CHECK_SPELLING:
1584 toolbar_data->spellcheck_btn = item;
1585 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1586 toolbar_data->spellcheck_btn,
1587 _("Check spelling"), NULL);
1592 action_item = g_new0(ToolbarSylpheedActions, 1);
1593 action_item->widget = item;
1594 action_item->name = g_strdup(toolbar_item->text);
1596 toolbar_data->action_list =
1597 g_slist_append(toolbar_data->action_list,
1600 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1602 action_item->name, NULL);
1604 gtk_widget_show(item);
1607 /* find and set the tool tip text */
1608 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1610 toolbar_ret_descr_from_val
1611 (toolbar_item->index),
1617 toolbar_data->toolbar = toolbar;
1618 if (type == TOOLBAR_MAIN)
1619 activate_compose_button(toolbar_data,
1620 prefs_common.toolbar_style,
1621 toolbar_data->compose_btn_type);
1623 gtk_widget_show_all(toolbar);
1625 return toolbar_data;
1629 * Free toolbar structures
1631 void toolbar_destroy(Toolbar * toolbar) {
1633 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1634 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1637 void toolbar_update(ToolbarType type, gpointer data)
1639 Toolbar *toolbar_data;
1640 GtkWidget *handlebox;
1641 MainWindow *mainwin = (MainWindow*)data;
1642 Compose *compose = (Compose*)data;
1643 MessageView *msgview = (MessageView*)data;
1647 toolbar_data = mainwin->toolbar;
1648 handlebox = mainwin->handlebox;
1650 case TOOLBAR_COMPOSE:
1651 toolbar_data = compose->toolbar;
1652 handlebox = compose->handlebox;
1654 case TOOLBAR_MSGVIEW:
1655 toolbar_data = msgview->toolbar;
1656 handlebox = msgview->handlebox;
1662 gtk_container_remove(GTK_CONTAINER(handlebox),
1663 GTK_WIDGET(toolbar_data->toolbar));
1665 toolbar_init(toolbar_data);
1666 toolbar_data = toolbar_create(type, handlebox, data);
1669 mainwin->toolbar = toolbar_data;
1671 case TOOLBAR_COMPOSE:
1672 compose->toolbar = toolbar_data;
1674 case TOOLBAR_MSGVIEW:
1675 msgview->toolbar = toolbar_data;
1679 toolbar_style(type, prefs_common.toolbar_style, data);
1681 if (type == TOOLBAR_MAIN)
1682 toolbar_main_set_sensitive((MainWindow*)data);
1685 void toolbar_main_set_sensitive(gpointer data)
1687 SensitiveCond state;
1689 MainWindow *mainwin = (MainWindow*)data;
1690 Toolbar *toolbar = mainwin->toolbar;
1692 GSList *entry_list = NULL;
1694 typedef struct _Entry Entry;
1701 #define SET_WIDGET_COND(w, c) \
1703 Entry *e = g_new0(Entry, 1); \
1706 entry_list = g_slist_append(entry_list, e); \
1709 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1710 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1711 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1712 SET_WIDGET_COND(toolbar->reply_btn,
1713 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1714 if (toolbar->reply_btn)
1715 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->reply_combo),
1716 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1717 SET_WIDGET_COND(toolbar->replyall_btn,
1718 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1719 if (toolbar->replyall_btn)
1720 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replyall_combo),
1721 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1722 SET_WIDGET_COND(toolbar->replylist_btn,
1723 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1724 if (toolbar->replylist_btn)
1725 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replylist_combo),
1726 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1727 SET_WIDGET_COND(toolbar->replysender_btn,
1728 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1729 if (toolbar->replysender_btn)
1730 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replysender_combo),
1731 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1732 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1733 if (toolbar->fwd_btn)
1734 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->fwd_combo),
1735 M_HAVE_ACCOUNT|M_TARGET_EXIST);
1736 if (toolbar->fwd_combo) {
1737 GtkWidget *submenu = gtk_item_factory_get_widget(toolbar->fwd_combo->factory, "/Redirect");
1738 SET_WIDGET_COND(submenu, M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1741 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
1742 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1744 SET_WIDGET_COND(toolbar->next_btn, 0);
1747 SET_WIDGET_COND(toolbar->delete_btn,
1748 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1749 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1751 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
1752 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1754 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1757 #undef SET_WIDGET_COND
1759 state = main_window_get_current_state(mainwin);
1761 for (cur = entry_list; cur != NULL; cur = cur->next) {
1762 Entry *e = (Entry*) cur->data;
1764 if (e->widget != NULL) {
1765 sensitive = ((e->cond & state) == e->cond);
1766 gtk_widget_set_sensitive(e->widget, sensitive);
1770 while (entry_list != NULL) {
1771 Entry *e = (Entry*) entry_list->data;
1775 entry_list = g_slist_remove(entry_list, e);
1778 g_slist_free(entry_list);
1780 activate_compose_button(toolbar,
1781 prefs_common.toolbar_style,
1782 toolbar->compose_btn_type);
1785 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1787 Compose *compose = (Compose*)data;
1788 GSList *items = compose->toolbar->action_list;
1790 if (compose->toolbar->send_btn)
1791 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1792 if (compose->toolbar->sendl_btn)
1793 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1794 if (compose->toolbar->draft_btn )
1795 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1796 if (compose->toolbar->insert_btn )
1797 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1798 if (compose->toolbar->attach_btn)
1799 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1800 if (compose->toolbar->sig_btn)
1801 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1802 if (compose->toolbar->exteditor_btn)
1803 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1804 if (compose->toolbar->linewrap_current_btn)
1805 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
1806 if (compose->toolbar->linewrap_all_btn)
1807 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
1808 if (compose->toolbar->addrbook_btn)
1809 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1811 if (compose->toolbar->spellcheck_btn)
1812 gtk_widget_set_sensitive(compose->toolbar->spellcheck_btn, sensitive);
1814 for (; items != NULL; items = g_slist_next(items)) {
1815 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1816 gtk_widget_set_sensitive(item->widget, sensitive);
1821 * Initialize toolbar structure
1823 void toolbar_init(Toolbar * toolbar) {
1825 toolbar->toolbar = NULL;
1826 toolbar->get_btn = NULL;
1827 toolbar->getall_btn = NULL;
1828 toolbar->send_btn = NULL;
1829 toolbar->compose_mail_btn = NULL;
1830 toolbar->compose_news_btn = NULL;
1831 toolbar->reply_btn = NULL;
1832 toolbar->replysender_btn = NULL;
1833 toolbar->replyall_btn = NULL;
1834 toolbar->replylist_btn = NULL;
1835 toolbar->fwd_btn = NULL;
1836 toolbar->delete_btn = NULL;
1837 toolbar->prev_btn = NULL;
1838 toolbar->next_btn = NULL;
1839 toolbar->exec_btn = NULL;
1841 /* compose buttons */
1842 toolbar->sendl_btn = NULL;
1843 toolbar->draft_btn = NULL;
1844 toolbar->insert_btn = NULL;
1845 toolbar->attach_btn = NULL;
1846 toolbar->sig_btn = NULL;
1847 toolbar->exteditor_btn = NULL;
1848 toolbar->linewrap_current_btn = NULL;
1849 toolbar->linewrap_all_btn = NULL;
1850 toolbar->addrbook_btn = NULL;
1852 toolbar->spellcheck_btn = NULL;
1855 toolbar_destroy(toolbar);
1860 static void toolbar_reply(gpointer data, guint action)
1862 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1863 MainWindow *mainwin;
1864 MessageView *msgview;
1865 GSList *msginfo_list = NULL;
1867 g_return_if_fail(toolbar_item != NULL);
1869 switch (toolbar_item->type) {
1871 mainwin = (MainWindow*)toolbar_item->parent;
1872 msginfo_list = summary_get_selection(mainwin->summaryview);
1873 msgview = (MessageView*)mainwin->messageview;
1875 case TOOLBAR_MSGVIEW:
1876 msgview = (MessageView*)toolbar_item->parent;
1877 g_return_if_fail(msgview != NULL);
1878 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
1884 g_return_if_fail(msgview != NULL);
1885 g_return_if_fail(msginfo_list != NULL);
1886 compose_reply_from_messageview(msgview, msginfo_list, action);
1887 g_slist_free(msginfo_list);
1889 /* TODO: update reply state ion summaryview */
1893 /* exported functions */
1895 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
1897 MainWindow *mainwin = (MainWindow*)data;
1899 inc_mail(mainwin, prefs_common.newmail_notify_manu);
1902 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
1904 MainWindow *mainwin = (MainWindow*)data;
1906 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
1909 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
1914 if (prefs_common.work_offline)
1915 if (alertpanel(_("Offline warning"),
1916 _("You're working offline. Override?"),
1917 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1920 /* ask for confirmation before sending queued messages only
1921 in online mode and if there is at least one message queued
1922 in any of the folder queue
1924 if (prefs_common.confirm_send_queued_messages) {
1926 /* check if there's a queued message */
1927 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
1928 Folder *folder = list->data;
1930 found = !procmsg_queue_is_empty(folder->queue);
1932 /* if necessary, ask for confirmation before sending */
1933 if (found && !prefs_common.work_offline) {
1934 if (alertpanel(_("Send queued messages"),
1935 _("Send all queued messages?"),
1936 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1941 for (list = folder_get_list(); list != NULL; list = list->next) {
1942 Folder *folder = list->data;
1944 if (folder->queue) {
1945 if (procmsg_send_queue(folder->queue,
1946 prefs_common.savemsg) < 0)
1947 alertpanel_error(_("Some errors occurred while "
1948 "sending queued messages."));
1949 folder_item_scan(folder->queue);
1954 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
1956 MainWindow *mainwin = (MainWindow*)data;
1957 PrefsAccount *ac = NULL;
1958 FolderItem *item = mainwin->summaryview->folder_item;
1963 ac = account_find_from_item(item);
1964 if (ac && ac->protocol != A_NNTP) {
1965 compose_new_with_folderitem(ac, item); /* CLAWS */
1971 * CLAWS - use current account
1973 if (cur_account && (cur_account->protocol != A_NNTP)) {
1974 compose_new_with_folderitem(cur_account, item);
1979 * CLAWS - just get the first one
1981 list = account_get_list();
1982 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
1983 ac = (PrefsAccount *) cur->data;
1984 if (ac->protocol != A_NNTP) {
1985 compose_new_with_folderitem(ac, item);
1991 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
1993 MainWindow *mainwin = (MainWindow*)data;
1994 PrefsAccount * ac = NULL;
1998 if (mainwin->summaryview->folder_item) {
1999 ac = mainwin->summaryview->folder_item->folder->account;
2000 if (ac && ac->protocol == A_NNTP) {
2002 mainwin->summaryview->folder_item->path,
2008 list = account_get_list();
2009 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2010 ac = (PrefsAccount *) cur->data;
2011 if (ac->protocol == A_NNTP) {
2012 compose_new(ac, NULL, NULL);