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.
44 #include "stock_pixmap.h"
45 #include "mainwindow.h"
46 #include "prefs_common.h"
48 #include "prefs_actions.h"
49 #include "manage_window.h"
52 #include "prefs_toolbar.h"
55 #define TOOLBAR_TAG_INDEX "toolbar"
56 #define TOOLBAR_TAG_ITEM "item"
57 #define TOOLBAR_TAG_SEPARATOR SEPARATOR
65 #define TOOLBAR_ICON_FILE "file"
66 #define TOOLBAR_ICON_TEXT "text"
67 #define TOOLBAR_ICON_ACTION "action"
69 gboolean toolbar_is_duplicate (gint action);
70 static void toolbar_parse_item (XMLFile *file);
71 static gint toolbar_ret_val_from_text (gchar *text);
74 /* callback functions */
75 static void toolbar_inc_cb (GtkWidget *widget,
78 static void toolbar_inc_all_cb (GtkWidget *widget,
81 static void toolbar_send_cb (GtkWidget *widget,
84 static void toolbar_compose_news_cb (GtkWidget *widget,
87 static void toolbar_compose_mail_cb (GtkWidget *widget,
90 static void toolbar_reply_cb (GtkWidget *widget,
93 static void toolbar_reply_to_all_cb (GtkWidget *widget,
96 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
99 static void toolbar_forward_cb (GtkWidget *widget,
102 static void toolbar_delete_cb (GtkWidget *widget,
105 static void toolbar_exec_cb (GtkWidget *widget,
108 static void toolbar_next_unread_cb (GtkWidget *widget,
111 static void toolbar_actions_execute_cb (GtkWidget *widget,
114 static void toolbar_reply_popup_cb (GtkWidget *widget,
115 GdkEventButton *event,
117 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell,
120 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget,
121 GdkEventButton *event,
124 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell,
127 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget,
128 GdkEventButton *event,
130 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell,
133 static void toolbar_forward_popup_cb (GtkWidget *widget,
134 GdkEventButton *event,
137 static void toolbar_forward_popup_closed_cb (GtkMenuShell *menu_shell,
140 static ToolbarAction t_action[] =
142 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts"), toolbar_inc_all_cb },
143 { "A_RECEIVE_CUR", N_("Receive Mail on current Account"), toolbar_inc_cb },
144 { "A_SEND_QUEUD", N_("Send Queud Message(s)"), toolbar_send_cb },
145 { "A_COMPOSE_EMAIL", N_("Compose Email"), toolbar_compose_mail_cb },
146 { "A_REPLY_MESSAGE", N_("Reply to Message"), toolbar_reply_cb },
147 { "A_REPLY_SENDER", N_("Reply to Sender"), toolbar_reply_to_sender_cb },
148 { "A_REPLY_ALL", N_("Reply to All"), toolbar_reply_to_all_cb },
149 { "A_FORWARD", N_("Forward Message"), toolbar_forward_cb },
150 { "A_DELETE", N_("Delete Message"), toolbar_delete_cb },
151 { "A_EXECUTE", N_("Execute"), toolbar_exec_cb },
152 { "A_GOTO_NEXT", N_("Goto Next Message"), toolbar_next_unread_cb },
153 { "A_SYL_ACTIONS", N_("Sylpheed Actions Feature"), toolbar_actions_execute_cb },
155 { "A_COMPOSE_NEWS", N_("Compose News"), toolbar_compose_news_cb },
156 { "A_SEPARATOR", SEPARATOR, NULL },
159 static GtkItemFactoryEntry reply_popup_entries[] =
161 {N_("/Reply with _quote"), NULL, reply_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
162 {N_("/_Reply without quote"), NULL, reply_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
164 static GtkItemFactoryEntry replyall_popup_entries[] =
166 {N_("/Reply to all with _quote"), "<shift>A", reply_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
167 {N_("/_Reply to all without quote"), "a", reply_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
169 static GtkItemFactoryEntry replysender_popup_entries[] =
171 {N_("/Reply to sender with _quote"), NULL, reply_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
172 {N_("/_Reply to sender without quote"), NULL, reply_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
174 static GtkItemFactoryEntry fwd_popup_entries[] =
176 {N_("/_Forward message (inline style)"), "f", reply_cb, COMPOSE_FORWARD_INLINE, NULL},
177 {N_("/Forward message as _attachment"), "<shift>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
181 void toolbar_actions_cb(GtkWidget *widget, ToolbarItem *toolbar_item)
183 if (toolbar_item->action < sizeof (t_action) / sizeof (t_action[0]))
184 t_action[toolbar_item->action].func(widget, mwin);
187 gint toolbar_ret_val_from_descr(gchar *descr)
191 for (i = 0; i < sizeof (t_action) / sizeof (t_action[0]); i++) {
192 if (g_strcasecmp (t_action[i].descr, descr) == 0)
199 gchar *toolbar_ret_descr_from_val(gint val)
201 g_return_val_if_fail (val >=0 && val <= sizeof(t_action) / sizeof(t_action[0]), NULL);
203 return t_action[val].descr;
207 static gint toolbar_ret_val_from_text(gchar *text)
211 for (i = 0; i < sizeof (t_action) / sizeof (t_action[0]); i++) {
212 if (g_strcasecmp (t_action[i].action_text, text) == 0)
219 gchar *toolbar_ret_text_from_val(gint val)
221 g_return_val_if_fail (val >=0 && val <= sizeof(t_action) / sizeof(t_action[0]), NULL);
223 return t_action[val].action_text;
226 gboolean toolbar_is_duplicate(gint action)
230 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
233 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
234 ToolbarItem *item = (ToolbarItem*) cur->data;
236 if (item->action == action)
242 GList *toolbar_get_action_items(void)
247 for (i = 0; i < N_ACTION_VAL; i++) {
248 items = g_list_append (items, t_action[i].descr);
254 static void toolbar_parse_item(XMLFile *file)
258 ToolbarItem *item = NULL;
260 attr = xml_get_current_tag_attr(file);
261 item = g_new0 (ToolbarItem, 1);
263 name = ((XMLAttr *)attr->data)->name;
264 value = ((XMLAttr *)attr->data)->value;
266 if (strcmp (name, TOOLBAR_ICON_FILE) == 0)
267 item->file = g_strdup (value);
268 else if (strcmp (name, TOOLBAR_ICON_TEXT) == 0)
269 item->text = g_strdup (value);
270 else if (strcmp (name, TOOLBAR_ICON_ACTION) == 0)
271 item->action = toolbar_ret_val_from_text(value);
273 attr = g_list_next (attr);
275 if (item->action != -1) {
277 if ( !toolbar_is_duplicate(item->action))
278 toolbar_list = g_slist_append (toolbar_list, item);
282 void toolbar_set_default_toolbar(void)
285 /* create default toolbar */
286 struct _default_toolbar {
290 } default_toolbar[] = {
291 { A_RECEIVE_CUR, STOCK_PIXMAP_MAIL_RECEIVE, _("Get") },
292 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get All") },
293 { A_SEPARATOR, 0, ("") },
294 { A_SEND_QUEUD, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
295 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Email") },
296 { A_SEPARATOR, 0, ("") },
297 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
298 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
299 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
300 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
301 { A_SEPARATOR, 0, ("") },
302 { A_DELETE, STOCK_PIXMAP_DELETED, _("Delete") },
303 { A_EXECUTE, STOCK_PIXMAP_EXEC, _("Execute") },
304 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") },
307 for (i = 0; i < sizeof (default_toolbar) / sizeof (default_toolbar[0]); i++) {
309 ToolbarItem *toolbar_item = g_new0 (ToolbarItem, 1);
311 if (default_toolbar[i].action != A_SEPARATOR) {
313 gchar *file = stock_pixmap_get_name ((StockPixmap)default_toolbar[i].icon);
315 toolbar_item->file = g_strdup (file);
316 toolbar_item->action = default_toolbar[i].action;
317 toolbar_item->text = g_strdup (default_toolbar[i].text);
320 toolbar_item->file = g_strdup (SEPARATOR);
321 toolbar_item->action = A_SEPARATOR;
324 if (toolbar_item->action != -1) {
326 if ( !toolbar_is_duplicate(toolbar_item->action))
327 toolbar_list = g_slist_append (toolbar_list, toolbar_item);
332 void toolbar_save_config_file ()
337 gchar *fileSpec = NULL;
339 debug_print("save Toolbar Configuration\n");
341 fileSpec = g_strconcat (get_rc_dir(), G_DIR_SEPARATOR_S, TOOLBAR_FILE, NULL );
342 pfile = prefs_write_open (fileSpec);
346 fprintf (fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
347 conv_get_current_charset_str());
349 fprintf (fp, "<%s>\n", TOOLBAR_TAG_INDEX);
351 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
352 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
354 if (g_strcasecmp (toolbar_item->file, SEPARATOR) != 0)
355 fprintf (fp, "\t<%s %s=\"%s\" %s=\"%s\" %s=\"%s\"/>\n",
357 TOOLBAR_ICON_FILE, toolbar_item->file,
358 TOOLBAR_ICON_TEXT, toolbar_item->text,
360 toolbar_ret_text_from_val (toolbar_item->action));
362 fprintf (fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
365 fprintf (fp, "</%s>\n", TOOLBAR_TAG_INDEX);
367 if( prefs_write_close (pfile) < 0 )
368 g_warning(_("failed to write toolbar configuration to file\n"));
370 g_warning(_("failed to open toolbar configuration file for writing\n"));
372 toolbar_clear_list();
375 void toolbar_clear_list()
377 while (toolbar_list != NULL) {
378 ToolbarItem *item = (ToolbarItem*) toolbar_list->data;
380 toolbar_list = g_slist_remove (toolbar_list, item);
386 g_slist_free (toolbar_list);
389 void toolbar_read_config_file ()
391 XMLFile *file = NULL;
392 gchar *fileSpec = NULL;
396 debug_print("read Toolbar Configuration\n");
398 fileSpec = g_strconcat (get_rc_dir(), G_DIR_SEPARATOR_S, TOOLBAR_FILE, NULL );
399 file = xml_open_file (fileSpec);
402 toolbar_clear_list();
406 if (setjmp (jumper)) {
407 xml_close_file (file);
411 if (xml_get_dtd (file))
413 if (xml_parse_next_tag (file))
415 if (!xml_compare_tag (file, TOOLBAR_TAG_INDEX))
418 attr = xml_get_current_tag_attr (file);
425 if (xml_parse_next_tag (file))
428 /* Get next tag (icon, icon_text or icon_action) */
429 if (xml_compare_tag (file, TOOLBAR_TAG_ITEM)) {
430 toolbar_parse_item (file);
431 } else if (xml_compare_tag (file, TOOLBAR_TAG_SEPARATOR)) {
432 ToolbarItem *item = g_new0 (ToolbarItem, 1);
434 item->file = g_strdup (SEPARATOR);
435 item->action = A_SEPARATOR;
436 toolbar_list = g_slist_append (toolbar_list, item);
442 /* save default toolbar */
443 toolbar_set_default_toolbar();
444 toolbar_save_config_file();
448 static void toolbar_actions_execute_cb (GtkWidget *widget,
453 MainWindow *mainwin = (MainWindow*)data;
454 gchar *action, *action_p;
455 gboolean found = FALSE;
457 for (cur = mainwin->toolbar->syl_action; cur != NULL; cur = cur->next) {
458 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
460 if (widget == act->widget) {
462 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
463 action = g_strdup((gchar*)lop->data);
465 action_p = strstr(action, ": ");
467 if (g_strcasecmp(act->name, action) == 0) {
481 actions_execute(mwin, i, widget);
483 g_warning (_("Error: did not find Sylpheed Action to execute"));
486 static void toolbar_inc_cb (GtkWidget *widget,
489 MainWindow *mainwin = (MainWindow *)data;
491 inc_mail_cb(mainwin, 0, NULL);
494 static void toolbar_inc_all_cb (GtkWidget *widget,
497 MainWindow *mainwin = (MainWindow *)data;
499 inc_all_account_mail_cb(mainwin, 0, NULL);
502 static void toolbar_send_cb (GtkWidget *widget,
505 MainWindow *mainwin = (MainWindow *)data;
507 send_queue_cb(mainwin, 0, NULL);
510 static void toolbar_compose_news_cb (GtkWidget *widget,
513 MainWindow *mainwin = (MainWindow *)data;
515 compose_news_cb(mainwin, 0, NULL);
518 static void toolbar_compose_mail_cb (GtkWidget *widget,
521 MainWindow *mainwin = (MainWindow *)data;
523 compose_mail_cb(mainwin, 0, NULL);
526 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
528 MainWindow *mainwin = (MainWindow *)data;
531 prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE
532 : COMPOSE_REPLY_WITHOUT_QUOTE,
536 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
538 MainWindow *mainwin = (MainWindow *)data;
541 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
542 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE,
547 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
549 MainWindow *mainwin = (MainWindow *)data;
552 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
553 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE,
557 static void toolbar_forward_cb (GtkWidget *widget,
560 MainWindow *mainwin = (MainWindow *)data;
562 if (prefs_common.forward_as_attachment)
563 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
565 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
568 static void toolbar_delete_cb (GtkWidget *widget,
571 MainWindow *mainwin = (MainWindow *)data;
573 summary_delete(mainwin->summaryview);
576 static void toolbar_exec_cb (GtkWidget *widget,
579 MainWindow *mainwin = (MainWindow *)data;
581 summary_execute(mainwin->summaryview);
584 static void toolbar_next_unread_cb (GtkWidget *widget,
587 MainWindow *mainwin = (MainWindow *)data;
589 next_unread_cb(mainwin, 0, NULL);
592 /* popup callback functions */
593 static void toolbar_reply_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
595 MainWindow *mainwindow = (MainWindow *) data;
599 if (event->button == 3) {
600 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
601 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->reply_popup), NULL, NULL,
602 menu_button_position, widget,
603 event->button, event->time);
607 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
609 MainWindow *mainwin = (MainWindow *)data;
611 gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->reply_btn), GTK_RELIEF_NONE);
612 manage_window_focus_in(mainwin->window, NULL, NULL);
615 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
617 MainWindow *mainwindow = (MainWindow *) data;
621 if (event->button == 3) {
622 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
623 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->replyall_popup), NULL, NULL,
624 menu_button_position, widget,
625 event->button, event->time);
629 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
631 MainWindow *mainwin = (MainWindow *)data;
633 gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->replyall_btn), GTK_RELIEF_NONE);
634 manage_window_focus_in(mainwin->window, NULL, NULL);
637 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
639 MainWindow *mainwindow = (MainWindow *) data;
643 if (event->button == 3) {
644 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
645 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->replysender_popup), NULL, NULL,
646 menu_button_position, widget,
647 event->button, event->time);
651 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
653 MainWindow *mainwin = (MainWindow *)data;
655 gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->replysender_btn), GTK_RELIEF_NONE);
656 manage_window_focus_in(mainwin->window, NULL, NULL);
659 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
661 MainWindow *mainwindow = (MainWindow *) data;
665 if (event->button == 3) {
666 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
667 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->fwd_popup), NULL, NULL,
668 menu_button_position, widget,
669 event->button, event->time);
673 static void toolbar_forward_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
675 MainWindow *mainwin = (MainWindow *)data;
677 gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->fwd_btn), GTK_RELIEF_NONE);
678 manage_window_focus_in(mainwin->window, NULL, NULL);
681 static void activate_compose_button (MainToolbar *toolbar,
683 ComposeButtonType type)
685 if (style == TOOLBAR_NONE)
688 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
691 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
692 : toolbar->compose_news_btn);
693 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
694 : toolbar->compose_mail_btn);
695 toolbar->compose_btn_type = type;
698 void toolbar_reflect_prefs_pixmap_theme(MainWindow *mainwin)
700 gtk_container_remove(GTK_CONTAINER(mainwin->handlebox),
701 GTK_WIDGET(mainwin->toolbar->toolbar));
703 mainwin->toolbar->toolbar = NULL;
704 toolbar_create(mainwin, mainwin->handlebox);
708 void toolbar_set_compose_button(MainToolbar *toolbar, ComposeButtonType compose_btn_type)
710 if (toolbar->compose_btn_type != compose_btn_type)
711 activate_compose_button(toolbar,
712 prefs_common.toolbar_style,
716 void toolbar_set_sensitive(MainWindow *mainwin)
720 MainToolbar *toolbar = mainwin->toolbar;
730 #define SET_WIDGET_COND(w, c) \
732 entry[total].widget = w; \
733 entry[total].cond = c; \
737 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
738 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
739 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
740 SET_WIDGET_COND(toolbar->reply_btn,
741 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
742 SET_WIDGET_COND(toolbar->replyall_btn,
743 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
744 SET_WIDGET_COND(toolbar->replysender_btn,
745 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
746 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
748 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
749 SET_WIDGET_COND(toolbar->delete_btn,
750 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
751 SET_WIDGET_COND(toolbar->exec_btn, M_MSG_EXIST|M_EXEC|M_UNLOCKED);
753 #undef SET_WIDGET_COND
755 state = main_window_get_current_state(mainwin);
757 for (i = 0; i < total; i++) {
759 if (entry[i].widget == NULL) continue;
760 sensitive = ((entry[i].cond & state) == entry[i].cond);
761 gtk_widget_set_sensitive(entry[i].widget, sensitive);
764 activate_compose_button(toolbar,
765 prefs_common.toolbar_style,
766 toolbar->compose_btn_type);
769 void toolbar_popups_create(MainWindow *mainwin, GtkWidget *window)
771 guint n_menu_entries;
772 GtkWidget *reply_popup;
773 GtkWidget *replyall_popup;
774 GtkWidget *replysender_popup;
775 GtkWidget *fwd_popup;
777 if (mainwin->toolbar != NULL)
778 g_free (mainwin->toolbar);
780 mainwin->toolbar = g_new0(MainToolbar, 1);
782 /* store mainwin localy */
785 n_menu_entries = sizeof(reply_popup_entries) /
786 sizeof(reply_popup_entries[0]);
787 reply_popup = popupmenu_create(window, reply_popup_entries, n_menu_entries,
788 "<ReplyPopup>", mainwin);
789 gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
790 GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), mainwin);
791 n_menu_entries = sizeof(replyall_popup_entries) /
792 sizeof(replyall_popup_entries[0]);
793 replyall_popup = popupmenu_create(window, replyall_popup_entries, n_menu_entries,
794 "<ReplyAllPopup>", mainwin);
795 gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
796 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), mainwin);
797 n_menu_entries = sizeof(replysender_popup_entries) /
798 sizeof(replysender_popup_entries[0]);
799 replysender_popup = popupmenu_create(window, replysender_popup_entries, n_menu_entries,
800 "<ReplySenderPopup>", mainwin);
801 gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
802 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), mainwin);
803 /* create the popup menu for the forward button */
804 n_menu_entries = sizeof(fwd_popup_entries) /
805 sizeof(fwd_popup_entries[0]);
806 fwd_popup = popupmenu_create(window, fwd_popup_entries, n_menu_entries,
807 "<ForwardPopup>", mainwin);
808 gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
809 GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), mainwin);
811 mainwin->toolbar->reply_popup = reply_popup;
812 mainwin->toolbar->replyall_popup = replyall_popup;
813 mainwin->toolbar->replysender_popup = replysender_popup;
814 mainwin->toolbar->fwd_popup = fwd_popup;
817 void toolbar_destroy(MainWindow *mainwin)
819 ToolbarSylpheedActions *syl_action;
821 toolbar_clear_list();
823 while (mainwin->toolbar->syl_action != NULL) {
824 syl_action = (ToolbarSylpheedActions*)mainwin->toolbar->syl_action->data;
826 if (syl_action->name)
827 g_free (syl_action->name);
828 mainwin->toolbar->syl_action = g_slist_remove(mainwin->toolbar->syl_action, syl_action);
831 g_slist_free (mainwin->toolbar->syl_action);
834 void toolbar_create(MainWindow *mainwin,
835 GtkWidget *container)
837 ToolbarItem *toolbar_item;
840 GtkWidget *icon_wid = NULL;
841 GtkWidget *icon_news = NULL;
842 GtkWidget *item_news = NULL;
844 ToolbarSylpheedActions *syl_action;
847 toolbar_destroy(mainwin);
848 toolbar_read_config_file();
850 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
852 gtk_container_add(GTK_CONTAINER(container), toolbar);
853 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
854 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
855 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
856 GTK_TOOLBAR_SPACE_LINE);
858 mainwin->toolbar->exec_btn = NULL;
860 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
861 toolbar_item = (ToolbarItem*) cur->data;
864 if (g_strcasecmp (toolbar_item->file, SEPARATOR) == 0) {
865 gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
869 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon (toolbar_item->file));
870 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
872 toolbar_ret_descr_from_val (toolbar_item->action),
874 icon_wid, toolbar_actions_cb,
877 switch (toolbar_item->action) {
879 mainwin->toolbar->getall_btn = item;
882 mainwin->toolbar->get_btn = item;
885 mainwin->toolbar->send_btn = item;
887 case A_COMPOSE_EMAIL:
888 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
889 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
891 toolbar_ret_descr_from_val (A_COMPOSE_NEWS),
893 icon_news, toolbar_actions_cb,
895 mainwin->toolbar->compose_mail_btn = item;
896 mainwin->toolbar->compose_news_btn = item_news;
898 case A_REPLY_MESSAGE:
899 mainwin->toolbar->reply_btn = item;
900 gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->reply_btn),
901 "button_press_event",
902 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
906 mainwin->toolbar->replysender_btn = item;
907 gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->replysender_btn),
908 "button_press_event",
909 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
913 mainwin->toolbar->replyall_btn = item;
914 gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->replyall_btn),
915 "button_press_event",
916 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
920 mainwin->toolbar->fwd_btn = item;
921 gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->fwd_btn),
922 "button_press_event",
923 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
927 mainwin->toolbar->delete_btn = item;
930 mainwin->toolbar->exec_btn = item;
933 mainwin->toolbar->next_btn = item;
936 syl_action = g_new0(ToolbarSylpheedActions, 1);
937 syl_action->widget = item;
938 syl_action->name = g_strdup(toolbar_item->text);
940 mainwin->toolbar->syl_action = g_slist_append(mainwin->toolbar->syl_action,
942 gtk_widget_show (item);
949 /* we always create an exec button, if there isn't one yet */
950 if (!mainwin->toolbar->exec_btn) {
951 toolbar_item = g_new0(ToolbarItem, 1);
952 toolbar_item->action = A_EXECUTE;
953 toolbar_item->file = stock_pixmap_get_name (STOCK_PIXMAP_EXEC);
954 toolbar_item->text = toolbar_ret_text_from_val(A_EXECUTE);
956 icon_wid = stock_pixmap_widget(container, STOCK_PIXMAP_EXEC);
957 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
959 toolbar_ret_descr_from_val (A_EXECUTE),
961 icon_wid, toolbar_actions_cb,
963 mainwin->toolbar->exec_btn = item;
964 g_free (toolbar_item);
967 mainwin->toolbar->toolbar = toolbar;
969 activate_compose_button(mainwin->toolbar,
970 prefs_common.toolbar_style,
971 mainwin->toolbar->compose_btn_type);
973 gtk_widget_show_all(toolbar);