2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001 Hiroyuki Yamamoto
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.
39 #include "mainwindow.h"
44 #include "prefs_gtk.h"
46 #include "stock_pixmap.h"
47 #include "manage_window.h"
52 #include "prefs_actions.h"
53 #include "prefs_common.h"
54 #include "prefs_toolbar.h"
55 #include "alertpanel.h"
58 #define TOOLBAR_TAG_INDEX "toolbar"
59 #define TOOLBAR_TAG_ITEM "item"
60 #define TOOLBAR_TAG_SEPARATOR "separator"
62 #define TOOLBAR_ICON_FILE "file"
63 #define TOOLBAR_ICON_TEXT "text"
64 #define TOOLBAR_ICON_ACTION "action"
66 gboolean toolbar_is_duplicate (gint action,
68 static void toolbar_parse_item (XMLFile *file,
71 static gint toolbar_ret_val_from_text (const gchar *text);
72 static gchar *toolbar_ret_text_from_val (gint val);
74 static void toolbar_set_default_main (void);
75 static void toolbar_set_default_compose (void);
76 static void toolbar_set_default_msgview (void);
78 static void toolbar_style (ToolbarType type,
82 static GtkWidget *get_window_widget (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_delete_cb (GtkWidget *widget,
93 static void toolbar_compose_cb (GtkWidget *widget,
96 static void toolbar_reply_cb (GtkWidget *widget,
99 static void toolbar_reply_to_all_cb (GtkWidget *widget,
102 static void toolbar_reply_to_list_cb (GtkWidget *widget,
105 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
108 static void toolbar_forward_cb (GtkWidget *widget,
111 static void toolbar_next_unread_cb (GtkWidget *widget,
114 static void toolbar_actions_execute_cb (GtkWidget *widget,
118 static void toolbar_send_cb (GtkWidget *widget,
120 static void toolbar_send_later_cb (GtkWidget *widget,
122 static void toolbar_draft_cb (GtkWidget *widget,
124 static void toolbar_insert_cb (GtkWidget *widget,
126 static void toolbar_attach_cb (GtkWidget *widget,
128 static void toolbar_sig_cb (GtkWidget *widget,
130 static void toolbar_ext_editor_cb (GtkWidget *widget,
132 static void toolbar_linewrap_cb (GtkWidget *widget,
134 static void toolbar_addrbook_cb (GtkWidget *widget,
137 static void toolbar_popup_cb (gpointer data,
143 } toolbar_text [] = {
144 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
145 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
146 { "A_SEND_QUEUED", N_("Send Queued Message(s)") },
147 { "A_COMPOSE_EMAIL", N_("Compose Email") },
148 { "A_COMPOSE_NEWS", N_("Compose News") },
149 { "A_REPLY_MESSAGE", N_("Reply to Message") },
150 { "A_REPLY_SENDER", N_("Reply to Sender") },
151 { "A_REPLY_ALL", N_("Reply to All") },
152 { "A_REPLY_ML", N_("Reply to Mailing-list") },
153 { "A_FORWARD", N_("Forward Message") },
154 { "A_DELETE", N_("Delete Message") },
155 { "A_EXECUTE", N_("Execute") },
156 { "A_GOTO_NEXT", N_("Goto Next Message") },
158 { "A_SEND", N_("Send Message") },
159 { "A_SENDL", N_("Put into queue folder and send later") },
160 { "A_DRAFT", N_("Save to draft folder") },
161 { "A_INSERT", N_("Insert file") },
162 { "A_ATTACH", N_("Attach file") },
163 { "A_SIG", N_("Insert signature") },
164 { "A_EXTEDITOR", N_("Edit with external editor") },
165 { "A_LINEWRAP", N_("Wrap all long lines") },
166 { "A_ADDRBOOK", N_("Address book") },
168 { "A_SYL_ACTIONS", N_("Sylpheed Actions Feature") },
169 { "A_SEPARATOR", N_("Separator") }
172 /* struct holds configuration files and a list of
173 * currently active toolbar items
174 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
178 const gchar *conf_file;
180 } toolbar_config[3] = {
181 { "toolbar_main.xml", NULL},
182 { "toolbar_compose.xml", NULL},
183 { "toolbar_msgview.xml", NULL}
186 static GtkItemFactoryEntry reply_popup_entries[] =
188 {N_("/Reply with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
189 {N_("/_Reply without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
191 static GtkItemFactoryEntry replyall_popup_entries[] =
193 {N_("/Reply to all with _quote"), "<shift>A", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
194 {N_("/_Reply to all without quote"), "a", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
196 static GtkItemFactoryEntry replylist_popup_entries[] =
198 {N_("/Reply to list with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
199 {N_("/_Reply to list without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
201 static GtkItemFactoryEntry replysender_popup_entries[] =
203 {N_("/Reply to sender with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
204 {N_("/_Reply to sender without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
206 static GtkItemFactoryEntry fwd_popup_entries[] =
208 {N_("/_Forward message (inline style)"), "f", toolbar_popup_cb, COMPOSE_FORWARD_INLINE, NULL},
209 {N_("/Forward message as _attachment"), "<shift>F", toolbar_popup_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
213 gint toolbar_ret_val_from_descr(const gchar *descr)
217 for (i = 0; i < N_ACTION_VAL; i++) {
218 if (g_strcasecmp(gettext(toolbar_text[i].descr), descr) == 0)
225 gchar *toolbar_ret_descr_from_val(gint val)
227 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
229 return gettext(toolbar_text[val].descr);
232 static gint toolbar_ret_val_from_text(const gchar *text)
236 for (i = 0; i < N_ACTION_VAL; i++) {
237 if (g_strcasecmp(toolbar_text[i].index_str, text) == 0)
244 static gchar *toolbar_ret_text_from_val(gint val)
246 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
248 return toolbar_text[val].index_str;
251 gboolean toolbar_is_duplicate(gint action, ToolbarType source)
255 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
258 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
259 ToolbarItem *item = (ToolbarItem*) cur->data;
261 if (item->index == action)
267 GList *toolbar_get_action_items(ToolbarType source)
272 if (source == TOOLBAR_MAIN) {
273 gint main_items[13] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
274 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
275 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
276 A_DELETE, A_EXECUTE, A_GOTO_NEXT,
279 for (i = 0; i < sizeof(main_items)/sizeof(main_items[0]); i++)
280 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
282 else if (source == TOOLBAR_COMPOSE) {
283 gint comp_items[10] = { A_SEND, A_SENDL, A_DRAFT,
284 A_INSERT, A_ATTACH, A_SIG,
285 A_EXTEDITOR, A_LINEWRAP, A_ADDRBOOK,
288 for (i = 0; i < sizeof(comp_items)/sizeof(comp_items[0]); i++)
289 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
291 else if (source == TOOLBAR_MSGVIEW) {
292 gint msgv_items[8] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
293 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
294 A_DELETE, A_GOTO_NEXT };
296 for (i = 0; i < sizeof(msgv_items)/sizeof(msgv_items[0]); i++)
297 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
303 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
307 ToolbarItem *item = NULL;
309 attr = xml_get_current_tag_attr(file);
310 item = g_new0(ToolbarItem, 1);
312 name = ((XMLAttr *)attr->data)->name;
313 value = ((XMLAttr *)attr->data)->value;
315 if (g_strcasecmp(name, TOOLBAR_ICON_FILE) == 0)
316 item->file = g_strdup (value);
317 else if (g_strcasecmp(name, TOOLBAR_ICON_TEXT) == 0)
318 item->text = g_strdup (value);
319 else if (g_strcasecmp(name, TOOLBAR_ICON_ACTION) == 0)
320 item->index = toolbar_ret_val_from_text(value);
322 attr = g_list_next(attr);
324 if (item->index != -1) {
326 if (!toolbar_is_duplicate(item->index, source))
327 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
332 static void toolbar_set_default_main(void)
338 } default_toolbar[] = {
339 { A_RECEIVE_CUR, STOCK_PIXMAP_MAIL_RECEIVE, _("Get") },
340 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get All") },
341 { A_SEPARATOR, 0, ("") },
342 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
343 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Email") },
344 { A_SEPARATOR, 0, ("") },
345 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
346 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
347 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
348 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
349 { A_SEPARATOR, 0, ("") },
350 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
351 { A_EXECUTE, STOCK_PIXMAP_EXEC, _("Execute") },
352 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
357 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
359 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
361 if (default_toolbar[i].action != A_SEPARATOR) {
363 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
365 toolbar_item->file = g_strdup(file);
366 toolbar_item->index = default_toolbar[i].action;
367 toolbar_item->text = g_strdup(default_toolbar[i].text);
370 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
371 toolbar_item->index = A_SEPARATOR;
374 if (toolbar_item->index != -1) {
375 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
376 toolbar_config[TOOLBAR_MAIN].item_list =
377 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
382 static void toolbar_set_default_compose(void)
388 } default_toolbar[] = {
389 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
390 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
391 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
392 { A_SEPARATOR, 0, ("") },
393 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
394 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
395 { A_SIG, STOCK_PIXMAP_MAIL_SIGN, _("Signature") },
396 { A_SEPARATOR, 0, ("") },
397 { A_EXTEDITOR, STOCK_PIXMAP_EDIT_EXTERN, _("Editor") },
398 { A_LINEWRAP, STOCK_PIXMAP_LINEWRAP, _("Linewrap") },
399 { A_SEPARATOR, 0, ("") },
400 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
405 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
407 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
409 if (default_toolbar[i].action != A_SEPARATOR) {
411 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
413 toolbar_item->file = g_strdup(file);
414 toolbar_item->index = default_toolbar[i].action;
415 toolbar_item->text = g_strdup(default_toolbar[i].text);
418 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
419 toolbar_item->index = A_SEPARATOR;
422 if (toolbar_item->index != -1) {
423 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
424 toolbar_config[TOOLBAR_COMPOSE].item_list =
425 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
430 static void toolbar_set_default_msgview(void)
436 } default_toolbar[] = {
437 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
438 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
439 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
440 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
441 { A_SEPARATOR, 0, ("") },
442 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
443 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
448 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
450 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
452 if (default_toolbar[i].action != A_SEPARATOR) {
454 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
456 toolbar_item->file = g_strdup(file);
457 toolbar_item->index = default_toolbar[i].action;
458 toolbar_item->text = g_strdup(default_toolbar[i].text);
461 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
462 toolbar_item->index = A_SEPARATOR;
465 if (toolbar_item->index != -1) {
466 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
467 toolbar_config[TOOLBAR_MSGVIEW].item_list =
468 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
473 void toolbar_set_default(ToolbarType source)
475 if (source == TOOLBAR_MAIN)
476 toolbar_set_default_main();
477 else if (source == TOOLBAR_COMPOSE)
478 toolbar_set_default_compose();
479 else if (source == TOOLBAR_MSGVIEW)
480 toolbar_set_default_msgview();
483 void toolbar_save_config_file(ToolbarType source)
488 gchar *fileSpec = NULL;
490 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
492 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
493 pfile = prefs_write_open(fileSpec);
497 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
498 conv_get_current_charset_str());
500 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
502 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
503 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
505 if (toolbar_item->index != A_SEPARATOR)
506 fprintf(fp, "\t<%s %s=\"%s\" %s=\"%s\" %s=\"%s\"/>\n",
508 TOOLBAR_ICON_FILE, toolbar_item->file,
509 TOOLBAR_ICON_TEXT, toolbar_item->text,
511 toolbar_ret_text_from_val(toolbar_item->index));
513 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
516 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
518 if (prefs_write_close (pfile) < 0 )
519 g_warning("failed to write toolbar configuration to file\n");
521 g_warning("failed to open toolbar configuration file for writing\n");
524 void toolbar_read_config_file(ToolbarType source)
526 XMLFile *file = NULL;
527 gchar *fileSpec = NULL;
532 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
534 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
535 file = xml_open_file(fileSpec);
538 toolbar_clear_list(source);
542 || (xml_get_dtd(file))
543 || (xml_parse_next_tag(file))
544 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
545 xml_close_file(file);
549 attr = xml_get_current_tag_attr(file);
556 if (xml_parse_next_tag(file))
559 /* Get next tag (icon, icon_text or icon_action) */
560 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
561 toolbar_parse_item(file, source);
562 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
563 ToolbarItem *item = g_new0(ToolbarItem, 1);
565 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
566 item->index = A_SEPARATOR;
567 toolbar_config[source].item_list =
568 g_slist_append(toolbar_config[source].item_list, item);
572 xml_close_file(file);
575 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
577 if (source == TOOLBAR_MAIN)
578 toolbar_set_default(TOOLBAR_MAIN);
579 else if (source == TOOLBAR_COMPOSE)
580 toolbar_set_default(TOOLBAR_COMPOSE);
581 else if (source == TOOLBAR_MSGVIEW)
582 toolbar_set_default(TOOLBAR_MSGVIEW);
584 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
588 toolbar_save_config_file(source);
593 * clears list of toolbar items read from configuration files
595 void toolbar_clear_list(ToolbarType source)
597 while (toolbar_config[source].item_list != NULL) {
598 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
600 toolbar_config[source].item_list =
601 g_slist_remove(toolbar_config[source].item_list, item);
609 g_slist_free(toolbar_config[source].item_list);
614 * return list of Toolbar items
616 GSList *toolbar_get_list(ToolbarType source)
620 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
621 list = toolbar_config[source].item_list;
626 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
628 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
630 toolbar_item->file = g_strdup(t_item->file);
631 toolbar_item->text = g_strdup(t_item->text);
632 toolbar_item->index = t_item->index;
634 toolbar_config[source].item_list =
635 g_slist_append(toolbar_config[source].item_list,
639 void toolbar_action_execute(GtkWidget *widget,
645 gchar *action, *action_p;
646 gboolean found = FALSE;
649 for (cur = action_list; cur != NULL; cur = cur->next) {
650 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
652 if (widget == act->widget) {
654 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
655 action = g_strdup((gchar*)lop->data);
657 action_p = strstr(action, ": ");
659 if (g_strcasecmp(act->name, action) == 0) {
673 actions_execute(data, i, widget, source);
675 g_warning ("Error: did not find Sylpheed Action to execute");
678 static void activate_compose_button (Toolbar *toolbar,
680 ComposeButtonType type)
682 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
685 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
686 : toolbar->compose_news_btn);
687 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
688 : toolbar->compose_mail_btn);
689 toolbar->compose_btn_type = type;
692 void toolbar_set_compose_button(Toolbar *toolbar,
693 ComposeButtonType compose_btn_type)
695 if (toolbar->compose_btn_type != compose_btn_type)
696 activate_compose_button(toolbar,
697 prefs_common.toolbar_style,
701 void toolbar_toggle(guint action, gpointer data)
703 MainWindow *mainwin = (MainWindow*)data;
707 g_return_if_fail(mainwin != NULL);
709 toolbar_style(TOOLBAR_MAIN, action, mainwin);
711 list = compose_get_compose_list();
712 for (cur = list; cur != NULL; cur = cur->next) {
713 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
715 list = messageview_get_msgview_list();
716 for (cur = list; cur != NULL; cur = cur->next) {
717 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
722 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
724 switch ((ToolbarStyle)action) {
726 gtk_widget_hide(handlebox_wid);
729 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
733 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
737 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
744 prefs_common.toolbar_style = (ToolbarStyle)action;
745 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
746 gtk_widget_show(handlebox_wid);
747 gtk_widget_queue_resize(handlebox_wid);
751 * Change the style of toolbar
753 static void toolbar_style(ToolbarType type, guint action, gpointer data)
755 GtkWidget *handlebox_wid;
756 GtkWidget *toolbar_wid;
757 MainWindow *mainwin = (MainWindow*)data;
758 Compose *compose = (Compose*)data;
759 MessageView *msgview = (MessageView*)data;
761 g_return_if_fail(data != NULL);
765 handlebox_wid = mainwin->handlebox;
766 toolbar_wid = mainwin->toolbar->toolbar;
768 case TOOLBAR_COMPOSE:
769 handlebox_wid = compose->handlebox;
770 toolbar_wid = compose->toolbar->toolbar;
772 case TOOLBAR_MSGVIEW:
773 handlebox_wid = msgview->handlebox;
774 toolbar_wid = msgview->toolbar->toolbar;
780 toolbar_set_style(toolbar_wid, handlebox_wid, action);
783 /* Toolbar handling */
784 static void toolbar_inc_cb(GtkWidget *widget,
787 ToolbarItem *toolbar_item = (ToolbarItem*)data;
790 g_return_if_fail(toolbar_item != NULL);
792 switch (toolbar_item->type) {
794 mainwin = (MainWindow*)toolbar_item->parent;
795 inc_mail_cb(mainwin, 0, NULL);
802 static void toolbar_inc_all_cb(GtkWidget *widget,
805 ToolbarItem *toolbar_item = (ToolbarItem*)data;
808 g_return_if_fail(toolbar_item != NULL);
810 switch (toolbar_item->type) {
812 mainwin = (MainWindow*)toolbar_item->parent;
813 inc_all_account_mail_cb(mainwin, 0, NULL);
820 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
822 ToolbarItem *toolbar_item = (ToolbarItem*)data;
825 g_return_if_fail(toolbar_item != NULL);
827 switch (toolbar_item->type) {
829 mainwin = (MainWindow*)toolbar_item->parent;
830 send_queue_cb(mainwin, 0, NULL);
837 static void toolbar_exec_cb(GtkWidget *widget,
840 MainWindow *mainwin = get_mainwin(data);
842 g_return_if_fail(mainwin != NULL);
843 summary_execute(mainwin->summaryview);
848 /* popup callback functions */
849 static void toolbar_reply_popup_cb(GtkWidget *widget,
850 GdkEventButton *event,
853 Toolbar *toolbar_data = (Toolbar*)data;
857 if (event->button == 3) {
858 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
859 gtk_menu_popup(GTK_MENU(toolbar_data->reply_popup), NULL, NULL,
860 menu_button_position, widget,
861 event->button, event->time);
865 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
867 ToolbarItem *toolbar_item = (ToolbarItem*)data;
869 GtkWidget *reply_btn;
871 MessageView *msgview;
873 g_return_if_fail(toolbar_item != NULL);
875 switch(toolbar_item->type) {
877 mainwin = (MainWindow*)toolbar_item->parent;
878 reply_btn = mainwin->toolbar->reply_btn;
879 window = mainwin->window;
881 case TOOLBAR_MSGVIEW:
882 msgview = (MessageView*)toolbar_item->parent;
883 reply_btn = msgview->toolbar->reply_btn;
884 window = msgview->window;
890 gtk_button_set_relief(GTK_BUTTON(reply_btn), GTK_RELIEF_NONE);
891 manage_window_focus_in(window, NULL, NULL);
894 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
896 Toolbar *toolbar_data = (Toolbar*)data;
900 if (event->button == 3) {
901 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
902 gtk_menu_popup(GTK_MENU(toolbar_data->replyall_popup), NULL, NULL,
903 menu_button_position, widget,
904 event->button, event->time);
908 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
910 ToolbarItem *toolbar_item = (ToolbarItem*)data;
912 GtkWidget *replyall_btn;
914 MessageView *msgview;
916 g_return_if_fail(toolbar_item != NULL);
918 switch(toolbar_item->type) {
920 mainwin = (MainWindow*)toolbar_item->parent;
921 replyall_btn = mainwin->toolbar->replyall_btn;
922 window = mainwin->window;
924 case TOOLBAR_MSGVIEW:
925 msgview = (MessageView*)toolbar_item->parent;
926 replyall_btn = msgview->toolbar->replyall_btn;
927 window = msgview->window;
933 gtk_button_set_relief(GTK_BUTTON(replyall_btn), GTK_RELIEF_NONE);
934 manage_window_focus_in(window, NULL, NULL);
937 static void toolbar_reply_to_list_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
939 Toolbar *toolbar_data = (Toolbar*)data;
941 if (event->button == 3) {
942 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
943 gtk_menu_popup(GTK_MENU(toolbar_data->replylist_popup), NULL, NULL,
944 menu_button_position, widget,
945 event->button, event->time);
949 static void toolbar_reply_to_list_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
951 ToolbarItem *toolbar_item = (ToolbarItem*)data;
952 gpointer parent = toolbar_item->parent;
954 GtkWidget *replylist_btn;
957 g_return_if_fail(toolbar_item != NULL);
959 switch(toolbar_item->type) {
961 replylist_btn = ((MainWindow*)parent)->toolbar->replylist_btn;
962 window = ((MainWindow*)parent)->window;
964 case TOOLBAR_MSGVIEW:
965 replylist_btn = ((MessageView*)parent)->toolbar->replylist_btn;
966 window = ((MessageView*)parent)->window;
972 gtk_button_set_relief(GTK_BUTTON(replylist_btn), GTK_RELIEF_NONE);
973 manage_window_focus_in(window, NULL, NULL);
976 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
978 Toolbar *toolbar_data = (Toolbar*)data;
980 if (event->button == 3) {
981 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
982 gtk_menu_popup(GTK_MENU(toolbar_data->replysender_popup), NULL, NULL,
983 menu_button_position, widget,
984 event->button, event->time);
988 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
990 ToolbarItem *toolbar_item = (ToolbarItem*)data;
991 gpointer parent = toolbar_item->parent;
993 GtkWidget *replysender_btn;
995 g_return_if_fail(toolbar_item != NULL);
997 switch(toolbar_item->type) {
999 replysender_btn = ((MainWindow*)parent)->toolbar->replysender_btn;
1000 window = ((MainWindow*)parent)->window;
1002 case TOOLBAR_MSGVIEW:
1003 replysender_btn = ((MessageView*)parent)->toolbar->replysender_btn;
1004 window = ((MessageView*)parent)->window;
1010 gtk_button_set_relief(GTK_BUTTON(replysender_btn), GTK_RELIEF_NONE);
1011 manage_window_focus_in(window, NULL, NULL);
1014 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1016 Toolbar *toolbar_data = (Toolbar*)data;
1018 if (event->button == 3) {
1019 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1020 gtk_menu_popup(GTK_MENU(toolbar_data->fwd_popup), NULL, NULL,
1021 menu_button_position, widget,
1022 event->button, event->time);
1026 static void toolbar_forward_popup_closed_cb (GtkMenuShell *menu_shell,
1029 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1030 gpointer parent = toolbar_item->parent;
1034 g_return_if_fail(toolbar_item != NULL);
1036 switch(toolbar_item->type) {
1038 fwd_btn = ((MainWindow*)parent)->toolbar->fwd_btn;
1039 window = ((MainWindow*)parent)->window;
1041 case TOOLBAR_MSGVIEW:
1042 fwd_btn = ((MessageView*)parent)->toolbar->fwd_btn;
1043 window = ((MessageView*)parent)->window;
1049 gtk_button_set_relief(GTK_BUTTON(fwd_btn), GTK_RELIEF_NONE);
1050 manage_window_focus_in(window, NULL, NULL);
1054 * Delete current/selected(s) message(s)
1056 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1058 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1059 MainWindow *mainwin;
1060 MessageView *msgview;
1062 g_return_if_fail(toolbar_item != NULL);
1064 switch (toolbar_item->type) {
1065 case TOOLBAR_MSGVIEW:
1066 msgview = (MessageView*)toolbar_item->parent;
1067 /* make sure the selected msg in summaryview is
1068 the one we are asked to delete */
1069 delete_msgview_cb(msgview, 0, widget);
1072 mainwin = (MainWindow*)toolbar_item->parent;
1073 summary_delete(mainwin->summaryview);
1076 debug_print("toolbar event not supported\n");
1083 * Compose new message
1085 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1087 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1088 MainWindow *mainwin;
1089 MessageView *msgview;
1091 g_return_if_fail(toolbar_item != NULL);
1093 switch (toolbar_item->type) {
1095 mainwin = (MainWindow*)toolbar_item->parent;
1096 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1097 compose_news_cb(mainwin, 0, NULL);
1099 compose_mail_cb(mainwin, 0, NULL);
1101 case TOOLBAR_MSGVIEW:
1102 msgview = (MessageView*)toolbar_item->parent;
1103 compose_new_with_folderitem(NULL,
1104 msgview->msginfo->folder);
1107 debug_print("toolbar event not supported\n");
1111 static void toolbar_popup_cb(gpointer data, guint action, GtkWidget *widget)
1113 MainWindow *mainwin = get_mainwin(data);
1115 g_return_if_fail(mainwin != NULL);
1116 reply_cb(mainwin, action, widget);
1123 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1125 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1126 MainWindow *mainwin;
1127 MessageView *msgview;
1129 g_return_if_fail(toolbar_item != NULL);
1131 switch (toolbar_item->type) {
1133 mainwin = (MainWindow*)toolbar_item->parent;
1134 if (prefs_common.default_reply_list)
1136 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1137 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE,
1141 prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE
1142 : COMPOSE_REPLY_WITHOUT_QUOTE,
1145 case TOOLBAR_MSGVIEW:
1146 msgview = (MessageView*)toolbar_item->parent;
1147 compose_reply(msgview->msginfo,
1148 prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE
1149 : COMPOSE_REPLY_WITHOUT_QUOTE,
1150 FALSE, FALSE, FALSE, NULL);
1153 debug_print("toolbar event not supported\n");
1159 * Reply message to Sender and All recipients
1161 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1163 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1164 MainWindow *mainwin;
1165 MessageView *msgview;
1167 g_return_if_fail(toolbar_item != NULL);
1169 switch (toolbar_item->type) {
1171 mainwin = (MainWindow*)toolbar_item->parent;
1173 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1174 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE,
1177 case TOOLBAR_MSGVIEW:
1178 msgview = (MessageView*)toolbar_item->parent;
1179 compose_reply(msgview->msginfo,
1180 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1181 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE,
1182 TRUE, FALSE, FALSE, NULL);
1185 debug_print("toolbar event not supported\n");
1191 * Reply to Mailing List
1193 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1195 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1196 MainWindow *mainwin;
1197 MessageView *msgview;
1199 g_return_if_fail(toolbar_item != NULL);
1201 switch (toolbar_item->type) {
1203 mainwin = (MainWindow*)toolbar_item->parent;
1205 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1206 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE,
1209 case TOOLBAR_MSGVIEW:
1210 msgview = (MessageView*)toolbar_item->parent;
1211 compose_reply(msgview->msginfo,
1212 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1213 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE,
1214 FALSE, TRUE, FALSE, NULL);
1217 debug_print("toolbar event not supported\n");
1223 * Reply to sender of message
1225 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1227 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1228 MainWindow *mainwin;
1229 MessageView *msgview;
1231 g_return_if_fail(toolbar_item != NULL);
1233 switch (toolbar_item->type) {
1235 mainwin = (MainWindow*)toolbar_item->parent;
1237 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1238 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE,
1241 case TOOLBAR_MSGVIEW:
1242 msgview = (MessageView*)toolbar_item->parent;
1243 compose_reply(msgview->msginfo,
1244 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1245 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE,
1246 FALSE, FALSE, FALSE, NULL);
1249 debug_print("toolbar event not supported\n\n");
1256 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1258 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1261 g_return_if_fail(toolbar_item != NULL);
1263 switch (toolbar_item->type) {
1264 case TOOLBAR_COMPOSE:
1265 compose = (Compose *)toolbar_item->parent;
1270 addressbook_open(compose);
1275 * Forward current/selected(s) message(s)
1277 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1279 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1280 MainWindow *mainwin;
1282 g_return_if_fail(toolbar_item != NULL);
1284 switch (toolbar_item->type) {
1286 mainwin = (MainWindow*)toolbar_item->parent;
1287 if (prefs_common.forward_as_attachment)
1288 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
1290 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1294 debug_print("toolbar event not supported\n");
1300 * Goto Next Unread Message
1302 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1304 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1305 MainWindow *mainwin;
1306 MessageView *msgview;
1308 g_return_if_fail(toolbar_item != NULL);
1310 switch (toolbar_item->type) {
1312 mainwin = (MainWindow*)toolbar_item->parent;
1313 summary_select_next_unread(mainwin->summaryview);
1316 case TOOLBAR_MSGVIEW:
1317 msgview = (MessageView*)toolbar_item->parent;
1319 * TODO: Check if summaryview stay in the same place when this message view was created
1320 * if summary have other message select the next will be based on message selected in summaryview
1322 summary_select_next_unread(msgview->mainwin->summaryview);
1324 /** Now we need to update the messageview window */
1325 if (msgview->mainwin->summaryview->selected) {
1326 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1328 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1329 msgview->mainwin->summaryview->selected);
1331 messageview_show(msgview, msginfo,
1332 msgview->all_headers);
1334 gtk_widget_destroy(msgview->window);
1338 debug_print("toolbar event not supported\n");
1342 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1344 compose_toolbar_cb(A_SEND, data);
1347 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1349 compose_toolbar_cb(A_SENDL, data);
1352 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1354 compose_toolbar_cb(A_DRAFT, data);
1357 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1359 compose_toolbar_cb(A_INSERT, data);
1362 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1364 compose_toolbar_cb(A_ATTACH, data);
1367 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1369 compose_toolbar_cb(A_SIG, data);
1372 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1374 compose_toolbar_cb(A_EXTEDITOR, data);
1377 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
1379 compose_toolbar_cb(A_LINEWRAP, data);
1383 * Execute actions from toolbar
1385 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1387 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1388 GSList *action_list;
1389 MainWindow *mainwin;
1392 g_return_if_fail(toolbar_item != NULL);
1394 switch (toolbar_item->type) {
1396 mainwin = (MainWindow*)toolbar_item->parent;
1397 action_list = mainwin->toolbar->action_list;
1399 case TOOLBAR_COMPOSE:
1400 compose = (Compose*)toolbar_item->parent;
1401 action_list = compose->toolbar->action_list;
1403 /* case TOOLBAR_MSGVIEW: not supported yet */
1405 debug_print("toolbar event not supported\n");
1409 toolbar_action_execute(widget, action_list, toolbar_item->parent, toolbar_item->type);
1412 static MainWindow *get_mainwin(gpointer data)
1414 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1415 MainWindow *mainwin = NULL;
1416 MessageView *msgview;
1418 g_return_val_if_fail(toolbar_item != NULL, NULL);
1420 switch(toolbar_item->type) {
1422 mainwin = (MainWindow*)toolbar_item->parent;
1424 case TOOLBAR_MSGVIEW:
1425 msgview = (MessageView*)toolbar_item->parent;
1426 mainwin = (MainWindow*)msgview->mainwin;
1435 static GtkWidget *get_window_widget(ToolbarType type, gpointer data)
1437 MainWindow *mainwin;
1438 MessageView *msgview;
1442 mainwin = (MainWindow*)data;
1443 return mainwin->window;
1445 case TOOLBAR_MSGVIEW:
1446 msgview = (MessageView*)data;
1447 return msgview->vbox;
1455 static void toolbar_buttons_cb(GtkWidget *widget,
1462 void (*func)(GtkWidget *widget, gpointer data);
1464 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1465 { A_RECEIVE_CUR, toolbar_inc_cb },
1466 { A_SEND_QUEUED, toolbar_send_queued_cb },
1467 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1468 { A_COMPOSE_NEWS, toolbar_compose_cb },
1469 { A_REPLY_MESSAGE, toolbar_reply_cb },
1470 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1471 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1472 { A_REPLY_ML, toolbar_reply_to_list_cb },
1473 { A_FORWARD, toolbar_forward_cb },
1474 { A_DELETE, toolbar_delete_cb },
1475 { A_EXECUTE, toolbar_exec_cb },
1476 { A_GOTO_NEXT, toolbar_next_unread_cb },
1478 { A_SEND, toolbar_send_cb },
1479 { A_SENDL, toolbar_send_later_cb },
1480 { A_DRAFT, toolbar_draft_cb },
1481 { A_INSERT, toolbar_insert_cb },
1482 { A_ATTACH, toolbar_attach_cb },
1483 { A_SIG, toolbar_sig_cb },
1484 { A_EXTEDITOR, toolbar_ext_editor_cb },
1485 { A_LINEWRAP, toolbar_linewrap_cb },
1486 { A_ADDRBOOK, toolbar_addrbook_cb },
1488 { A_SYL_ACTIONS, toolbar_actions_execute_cb }
1491 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1493 for (i = 0; i < num_items; i++) {
1494 if (callbacks[i].index == item->index) {
1495 callbacks[i].func(widget, item);
1502 * Create a new toolbar with specified type
1503 * if a callback list is passed it will be used before the
1504 * common callback list
1506 Toolbar *toolbar_create(ToolbarType type,
1507 GtkWidget *container,
1510 ToolbarItem *toolbar_item;
1513 GtkWidget *icon_wid = NULL;
1514 GtkWidget *icon_news;
1516 GtkWidget *item_news;
1517 GtkWidget *window_wid;
1519 guint n_menu_entries;
1520 GtkWidget *reply_popup;
1521 GtkWidget *replyall_popup;
1522 GtkWidget *replylist_popup;
1523 GtkWidget *replysender_popup;
1524 GtkWidget *fwd_popup;
1526 GtkTooltips *toolbar_tips;
1527 ToolbarSylpheedActions *action_item;
1529 GSList *toolbar_list;
1530 Toolbar *toolbar_data;
1533 toolbar_tips = gtk_tooltips_new();
1535 toolbar_read_config_file(type);
1536 toolbar_list = toolbar_get_list(type);
1538 toolbar_data = g_new0(Toolbar, 1);
1540 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1542 gtk_container_add(GTK_CONTAINER(container), toolbar);
1543 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1544 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1545 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1546 GTK_TOOLBAR_SPACE_LINE);
1548 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1550 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1551 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1555 toolbar_item = g_new0(ToolbarItem, 1);
1556 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1557 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1558 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1559 toolbar_item->parent = data;
1560 toolbar_item->type = type;
1562 /* collect toolbar items in list to keep track */
1563 toolbar_data->item_list =
1564 g_slist_append(toolbar_data->item_list,
1567 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1568 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1572 icon_wid, toolbar_buttons_cb,
1575 switch (toolbar_item->index) {
1578 toolbar_data->getall_btn = item;
1579 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1580 toolbar_data->getall_btn,
1581 _("Receive Mail on all Accounts"), NULL);
1584 toolbar_data->get_btn = item;
1585 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1586 toolbar_data->get_btn,
1587 _("Receive Mail on current Account"), NULL);
1590 toolbar_data->send_btn = item;
1591 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1592 toolbar_data->send_btn,
1593 _("Send Queued Message(s)"), NULL);
1595 case A_COMPOSE_EMAIL:
1596 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1597 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1601 icon_news, toolbar_buttons_cb,
1603 toolbar_data->compose_mail_btn = item;
1604 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1605 toolbar_data->compose_mail_btn,
1606 _("Compose Email"), NULL);
1607 toolbar_data->compose_news_btn = item_news;
1608 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1609 toolbar_data->compose_news_btn,
1610 _("Compose News"), NULL);
1612 case A_REPLY_MESSAGE:
1613 toolbar_data->reply_btn = item;
1614 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1615 toolbar_data->reply_btn,
1616 _("Reply to Message"), NULL);
1617 gtk_signal_connect(GTK_OBJECT(toolbar_data->reply_btn),
1618 "button_press_event",
1619 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
1621 n_menu_entries = sizeof(reply_popup_entries) /
1622 sizeof(reply_popup_entries[0]);
1624 window_wid = get_window_widget(type, data);
1625 reply_popup = popupmenu_create(window_wid,
1626 reply_popup_entries, n_menu_entries,
1627 "<ReplyPopup>", (gpointer)toolbar_item);
1629 gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
1630 GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), toolbar_item);
1631 toolbar_data->reply_popup = reply_popup;
1633 case A_REPLY_SENDER:
1634 toolbar_data->replysender_btn = item;
1635 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1636 toolbar_data->replysender_btn,
1637 _("Reply to Sender"), NULL);
1638 gtk_signal_connect(GTK_OBJECT(toolbar_data->replysender_btn),
1639 "button_press_event",
1640 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
1642 n_menu_entries = sizeof(replysender_popup_entries) /
1643 sizeof(replysender_popup_entries[0]);
1645 window_wid = get_window_widget(type, data);
1646 replysender_popup = popupmenu_create(window_wid,
1647 replysender_popup_entries, n_menu_entries,
1648 "<ReplySenderPopup>", (gpointer)toolbar_item);
1650 gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
1651 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), toolbar_item);
1652 toolbar_data->replysender_popup = replysender_popup;
1655 toolbar_data->replyall_btn = item;
1656 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1657 toolbar_data->replyall_btn,
1658 _("Reply to All"), NULL);
1659 gtk_signal_connect(GTK_OBJECT(toolbar_data->replyall_btn),
1660 "button_press_event",
1661 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
1663 n_menu_entries = sizeof(replyall_popup_entries) /
1664 sizeof(replyall_popup_entries[0]);
1666 window_wid = get_window_widget(type, data);
1667 replyall_popup = popupmenu_create(window_wid,
1668 replyall_popup_entries, n_menu_entries,
1669 "<ReplyAllPopup>", (gpointer)toolbar_item);
1671 gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
1672 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), toolbar_item);
1673 toolbar_data->replyall_popup = replyall_popup;
1676 toolbar_data->replylist_btn = item;
1677 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1678 toolbar_data->replylist_btn,
1679 _("Reply to Mailing-list"), NULL);
1680 gtk_signal_connect(GTK_OBJECT(toolbar_data->replylist_btn),
1681 "button_press_event",
1682 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_cb),
1684 n_menu_entries = sizeof(replylist_popup_entries) /
1685 sizeof(replylist_popup_entries[0]);
1687 window_wid = get_window_widget(type, data);
1688 replylist_popup = popupmenu_create(window_wid,
1689 replylist_popup_entries, n_menu_entries,
1690 "<ReplyMlPopup>", (gpointer)toolbar_item);
1692 gtk_signal_connect(GTK_OBJECT(replylist_popup), "selection_done",
1693 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_closed_cb), toolbar_item);
1694 toolbar_data->replylist_popup = replylist_popup;
1697 toolbar_data->fwd_btn = item;
1698 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1699 toolbar_data->fwd_btn,
1700 _("Forward Message"), NULL);
1701 gtk_signal_connect(GTK_OBJECT(toolbar_data->fwd_btn),
1702 "button_press_event",
1703 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
1705 n_menu_entries = sizeof(fwd_popup_entries) /
1706 sizeof(fwd_popup_entries[0]);
1708 window_wid = get_window_widget(type, data);
1709 fwd_popup = popupmenu_create(window_wid,
1710 fwd_popup_entries, n_menu_entries,
1711 "<ForwardPopup>", (gpointer)toolbar_item);
1713 gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
1714 GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), toolbar_item);
1715 toolbar_data->fwd_popup = fwd_popup;
1718 toolbar_data->delete_btn = item;
1719 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1720 toolbar_data->delete_btn,
1721 _("Delete Message"), NULL);
1724 toolbar_data->exec_btn = item;
1725 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1726 toolbar_data->exec_btn,
1727 _("Execute"), NULL);
1730 toolbar_data->next_btn = item;
1731 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1732 toolbar_data->next_btn,
1733 _("Goto Next Message"), NULL);
1736 /* Compose Toolbar */
1738 toolbar_data->send_btn = item;
1739 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1740 toolbar_data->send_btn,
1741 _("Send Message"), NULL);
1744 toolbar_data->sendl_btn = item;
1745 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1746 toolbar_data->sendl_btn,
1747 _("Put into queue folder and send later"), NULL);
1750 toolbar_data->draft_btn = item;
1751 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1752 toolbar_data->draft_btn,
1753 _("Save to draft folder"), NULL);
1756 toolbar_data->insert_btn = item;
1757 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1758 toolbar_data->insert_btn,
1759 _("Insert file"), NULL);
1762 toolbar_data->attach_btn = item;
1763 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1764 toolbar_data->attach_btn,
1765 _("Attach file"), NULL);
1768 toolbar_data->sig_btn = item;
1769 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1770 toolbar_data->sig_btn,
1771 _("Insert signature"), NULL);
1774 toolbar_data->exteditor_btn = item;
1775 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1776 toolbar_data->exteditor_btn,
1777 _("Edit with external editor"), NULL);
1780 toolbar_data->linewrap_btn = item;
1781 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1782 toolbar_data->linewrap_btn,
1783 _("Wrap all long lines"), NULL);
1786 toolbar_data->addrbook_btn = item;
1787 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1788 toolbar_data->addrbook_btn,
1789 _("Address book"), NULL);
1793 action_item = g_new0(ToolbarSylpheedActions, 1);
1794 action_item->widget = item;
1795 action_item->name = g_strdup(toolbar_item->text);
1797 toolbar_data->action_list =
1798 g_slist_append(toolbar_data->action_list,
1801 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1803 action_item->name, NULL);
1805 gtk_widget_show(item);
1812 toolbar_data->toolbar = toolbar;
1813 if (type == TOOLBAR_MAIN)
1814 activate_compose_button(toolbar_data,
1815 prefs_common.toolbar_style,
1816 toolbar_data->compose_btn_type);
1818 gtk_widget_show_all(toolbar);
1820 return toolbar_data;
1824 * Free toolbar structures
1826 void toolbar_destroy(Toolbar * toolbar) {
1828 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1829 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1832 void toolbar_update(ToolbarType type, gpointer data)
1834 Toolbar *toolbar_data;
1835 GtkWidget *handlebox;
1836 MainWindow *mainwin = (MainWindow*)data;
1837 Compose *compose = (Compose*)data;
1838 MessageView *msgview = (MessageView*)data;
1842 toolbar_data = mainwin->toolbar;
1843 handlebox = mainwin->handlebox;
1845 case TOOLBAR_COMPOSE:
1846 toolbar_data = compose->toolbar;
1847 handlebox = compose->handlebox;
1849 case TOOLBAR_MSGVIEW:
1850 toolbar_data = msgview->toolbar;
1851 handlebox = msgview->handlebox;
1857 gtk_container_remove(GTK_CONTAINER(handlebox),
1858 GTK_WIDGET(toolbar_data->toolbar));
1860 toolbar_init(toolbar_data);
1861 toolbar_data = toolbar_create(type, handlebox, data);
1864 mainwin->toolbar = toolbar_data;
1866 case TOOLBAR_COMPOSE:
1867 compose->toolbar = toolbar_data;
1869 case TOOLBAR_MSGVIEW:
1870 msgview->toolbar = toolbar_data;
1874 toolbar_style(type, prefs_common.toolbar_style, data);
1876 if (type == TOOLBAR_MAIN)
1877 toolbar_main_set_sensitive((MainWindow*)data);
1880 void toolbar_main_set_sensitive(gpointer data)
1882 SensitiveCond state;
1884 MainWindow *mainwin = (MainWindow*)data;
1885 Toolbar *toolbar = mainwin->toolbar;
1887 GSList *entry_list = NULL;
1889 typedef struct _Entry Entry;
1896 #define SET_WIDGET_COND(w, c) \
1898 Entry *e = g_new0(Entry, 1); \
1901 entry_list = g_slist_append(entry_list, e); \
1904 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1905 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1906 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1907 SET_WIDGET_COND(toolbar->reply_btn,
1908 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1909 SET_WIDGET_COND(toolbar->replyall_btn,
1910 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1911 SET_WIDGET_COND(toolbar->replylist_btn,
1912 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1913 SET_WIDGET_COND(toolbar->replysender_btn,
1914 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1915 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1917 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1918 SET_WIDGET_COND(toolbar->delete_btn,
1919 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1920 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1922 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
1923 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1925 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1928 #undef SET_WIDGET_COND
1930 state = main_window_get_current_state(mainwin);
1932 for (cur = entry_list; cur != NULL; cur = cur->next) {
1933 Entry *e = (Entry*) cur->data;
1935 if (e->widget != NULL) {
1936 sensitive = ((e->cond & state) == e->cond);
1937 gtk_widget_set_sensitive(e->widget, sensitive);
1941 while (entry_list != NULL) {
1942 Entry *e = (Entry*) entry_list->data;
1946 entry_list = g_slist_remove(entry_list, e);
1949 g_slist_free(entry_list);
1951 activate_compose_button(toolbar,
1952 prefs_common.toolbar_style,
1953 toolbar->compose_btn_type);
1956 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1958 Compose *compose = (Compose*)data;
1959 GSList *items = compose->toolbar->action_list;
1961 if (compose->toolbar->send_btn)
1962 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1963 if (compose->toolbar->sendl_btn)
1964 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1965 if (compose->toolbar->draft_btn )
1966 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1967 if (compose->toolbar->insert_btn )
1968 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1969 if (compose->toolbar->attach_btn)
1970 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1971 if (compose->toolbar->sig_btn)
1972 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1973 if (compose->toolbar->exteditor_btn)
1974 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1975 if (compose->toolbar->linewrap_btn)
1976 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
1977 if (compose->toolbar->addrbook_btn)
1978 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1979 for (; items != NULL; items = g_slist_next(items)) {
1980 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1981 gtk_widget_set_sensitive(item->widget, sensitive);
1986 * Initialize toolbar structure
1988 void toolbar_init(Toolbar * toolbar) {
1990 toolbar->toolbar = NULL;
1991 toolbar->get_btn = NULL;
1992 toolbar->getall_btn = NULL;
1993 toolbar->send_btn = NULL;
1994 toolbar->compose_mail_btn = NULL;
1995 toolbar->compose_news_btn = NULL;
1996 toolbar->reply_btn = NULL;
1997 toolbar->replysender_btn = NULL;
1998 toolbar->replyall_btn = NULL;
1999 toolbar->replylist_btn = NULL;
2000 toolbar->fwd_btn = NULL;
2001 toolbar->delete_btn = NULL;
2002 toolbar->next_btn = NULL;
2003 toolbar->exec_btn = NULL;
2005 /* compose buttons */
2006 toolbar->sendl_btn = NULL;
2007 toolbar->draft_btn = NULL;
2008 toolbar->insert_btn = NULL;
2009 toolbar->attach_btn = NULL;
2010 toolbar->sig_btn = NULL;
2011 toolbar->exteditor_btn = NULL;
2012 toolbar->linewrap_btn = NULL;
2013 toolbar->addrbook_btn = NULL;
2015 toolbar_destroy(toolbar);
2018 /* exported functions */
2020 void delete_msgview_cb(gpointer data, guint action, GtkWidget *widget)
2022 MessageView *msgview = (MessageView*)data;
2024 if (msgview->mainwin->summaryview->selected) {
2025 SummaryView *summaryview = msgview->mainwin->summaryview;
2026 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
2027 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
2028 summaryview->selected);
2029 if (msginfo->msgnum != msgview->msginfo->msgnum) {
2030 alertpanel_error(_("Message already removed from folder."));
2035 summary_delete(msgview->mainwin->summaryview);
2037 if (msgview->mainwin->summaryview->selected) {
2038 SummaryView *summaryview = msgview->mainwin->summaryview;
2039 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
2040 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
2041 summaryview->selected);
2042 messageview_show(msgview, msginfo,
2043 msgview->all_headers);
2045 toolbar_clear_list(TOOLBAR_MSGVIEW);
2046 toolbar_destroy(msgview->toolbar);
2047 gtk_widget_destroy(msgview->window);
2051 void reply_cb(gpointer data, guint action, GtkWidget *widget)
2053 MainWindow *mainwin = (MainWindow*)data;
2055 g_return_if_fail(mainwin != NULL);
2057 summary_reply(mainwin->summaryview, (ComposeMode)action);
2060 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2062 MainWindow *mainwin = (MainWindow*)data;
2064 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2067 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2069 MainWindow *mainwin = (MainWindow*)data;
2071 inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
2074 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2078 if (prefs_common.work_offline)
2079 if (alertpanel(_("Offline warning"),
2080 _("You're working offline. Override?"),
2081 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
2084 for (list = folder_get_list(); list != NULL; list = list->next) {
2085 Folder *folder = list->data;
2087 if (folder->queue) {
2088 if (procmsg_send_queue
2089 (folder->queue, prefs_common.savemsg) < 0)
2090 alertpanel_error(_("Some errors occurred while sending queued messages."));
2091 folder_item_scan(folder->queue);
2092 folder_update_item(folder->queue, TRUE);
2097 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2099 MainWindow *mainwin = (MainWindow*)data;
2100 PrefsAccount *ac = NULL;
2101 FolderItem *item = mainwin->summaryview->folder_item;
2106 ac = account_find_from_item(item);
2107 if (ac && ac->protocol != A_NNTP) {
2108 compose_new_with_folderitem(ac, item); /* CLAWS */
2114 * CLAWS - use current account
2116 if (cur_account && (cur_account->protocol != A_NNTP)) {
2117 compose_new_with_folderitem(cur_account, item);
2122 * CLAWS - just get the first one
2124 list = account_get_list();
2125 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2126 ac = (PrefsAccount *) cur->data;
2127 if (ac->protocol != A_NNTP) {
2128 compose_new_with_folderitem(ac, item);
2134 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2136 MainWindow *mainwin = (MainWindow*)data;
2137 PrefsAccount * ac = NULL;
2141 if (mainwin->summaryview->folder_item) {
2142 ac = mainwin->summaryview->folder_item->folder->account;
2143 if (ac && ac->protocol == A_NNTP) {
2145 mainwin->summaryview->folder_item->path,
2151 list = account_get_list();
2152 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2153 ac = (PrefsAccount *) cur->data;
2154 if (ac->protocol == A_NNTP) {
2155 compose_new(ac, NULL, NULL);