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_cb (GtkWidget *widget,
87 static void toolbar_reply_cb (GtkWidget *widget,
90 static void toolbar_reply_to_all_cb (GtkWidget *widget,
93 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
96 static void toolbar_forward_cb (GtkWidget *widget,
99 static void toolbar_delete_cb (GtkWidget *widget,
102 static void toolbar_exec_cb (GtkWidget *widget,
105 static void toolbar_next_unread_cb (GtkWidget *widget,
108 static void toolbar_actions_execute_cb (GtkWidget *widget,
111 static void toolbar_reply_popup_cb (GtkWidget *widget,
112 GdkEventButton *event,
114 static void toolbar_reply_popup_closed_cb (GtkMenuShell *menu_shell,
117 static void toolbar_reply_to_all_popup_cb (GtkWidget *widget,
118 GdkEventButton *event,
121 static void toolbar_reply_to_all_popup_closed_cb
122 (GtkMenuShell *menu_shell,
125 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget,
126 GdkEventButton *event,
128 static void toolbar_reply_to_sender_popup_closed_cb
129 (GtkMenuShell *menu_shell,
132 static void toolbar_forward_popup_cb (GtkWidget *widget,
133 GdkEventButton *event,
136 static void toolbar_forward_popup_closed_cb
137 (GtkMenuShell *menu_shell,
140 static void activate_compose_button (MainToolbar *toolbar,
142 ComposeButtonType type);
143 static ToolbarAction t_action[] =
145 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts"), toolbar_inc_all_cb },
146 { "A_RECEIVE_CUR", N_("Receive Mail on current Account"), toolbar_inc_cb },
147 { "A_SEND_QUEUED", N_("Send Queued Message(s)"), toolbar_send_cb },
148 { "A_COMPOSE_EMAIL", N_("Compose Email"), toolbar_compose_cb },
149 { "A_REPLY_MESSAGE", N_("Reply to Message"), toolbar_reply_cb },
150 { "A_REPLY_SENDER", N_("Reply to Sender"), toolbar_reply_to_sender_cb},
151 { "A_REPLY_ALL", N_("Reply to All"), toolbar_reply_to_all_cb },
152 { "A_FORWARD", N_("Forward Message"), toolbar_forward_cb },
153 { "A_DELETE", N_("Delete Message"), toolbar_delete_cb },
154 { "A_EXECUTE", N_("Execute"), toolbar_exec_cb },
155 { "A_GOTO_NEXT", N_("Goto Next Message"), toolbar_next_unread_cb },
156 { "A_SYL_ACTIONS", N_("Sylpheed Actions Feature"), toolbar_actions_execute_cb},
158 { "A_COMPOSE_NEWS", N_("Compose News"), toolbar_compose_cb },
159 { "A_SEPARATOR", SEPARATOR, NULL }
162 static GtkItemFactoryEntry reply_popup_entries[] =
164 {N_("/Reply with _quote"), NULL, reply_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
165 {N_("/_Reply without quote"), NULL, reply_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
167 static GtkItemFactoryEntry replyall_popup_entries[] =
169 {N_("/Reply to all with _quote"), "<shift>A", reply_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
170 {N_("/_Reply to all without quote"), "a", reply_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
172 static GtkItemFactoryEntry replysender_popup_entries[] =
174 {N_("/Reply to sender with _quote"), NULL, reply_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
175 {N_("/_Reply to sender without quote"), NULL, reply_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
177 static GtkItemFactoryEntry fwd_popup_entries[] =
179 {N_("/_Forward message (inline style)"), "f", reply_cb, COMPOSE_FORWARD_INLINE, NULL},
180 {N_("/Forward message as _attachment"), "<shift>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
184 void toolbar_actions_cb(GtkWidget *widget, ToolbarItem *toolbar_item)
186 if (toolbar_item->action < sizeof(t_action) / sizeof(t_action[0]))
187 t_action[toolbar_item->action].func(widget, mwin);
190 gint toolbar_ret_val_from_descr(gchar *descr)
194 for (i = 0; i < sizeof(t_action) / sizeof(t_action[0]); i++) {
195 if (g_strcasecmp(t_action[i].descr, descr) == 0)
202 gchar *toolbar_ret_descr_from_val(gint val)
204 g_return_val_if_fail(val >=0 && val <= sizeof(t_action) / sizeof(t_action[0]), NULL);
206 return t_action[val].descr;
210 static gint toolbar_ret_val_from_text(gchar *text)
214 for (i = 0; i < sizeof(t_action) / sizeof(t_action[0]); i++) {
215 if (g_strcasecmp(t_action[i].action_text, text) == 0)
222 gchar *toolbar_ret_text_from_val(gint val)
224 g_return_val_if_fail(val >=0 && val <= sizeof(t_action) / sizeof(t_action[0]), NULL);
226 return t_action[val].action_text;
229 gboolean toolbar_is_duplicate(gint action)
233 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
236 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
237 ToolbarItem *item = (ToolbarItem*) cur->data;
239 if (item->action == action)
245 GList *toolbar_get_action_items(void)
250 for (i = 0; i < N_ACTION_VAL; i++) {
251 items = g_list_append(items, t_action[i].descr);
257 static void toolbar_parse_item(XMLFile *file)
261 ToolbarItem *item = NULL;
263 attr = xml_get_current_tag_attr(file);
264 item = g_new0(ToolbarItem, 1);
266 name = ((XMLAttr *)attr->data)->name;
267 value = ((XMLAttr *)attr->data)->value;
269 if (g_strcasecmp(name, TOOLBAR_ICON_FILE) == 0)
270 item->file = g_strdup (value);
271 else if (g_strcasecmp(name, TOOLBAR_ICON_TEXT) == 0)
272 item->text = g_strdup (value);
273 else if (g_strcasecmp(name, TOOLBAR_ICON_ACTION) == 0)
274 item->action = toolbar_ret_val_from_text(value);
276 attr = g_list_next(attr);
278 if (item->action != -1) {
280 if ( !toolbar_is_duplicate(item->action))
281 toolbar_list = g_slist_append(toolbar_list, item);
285 void toolbar_set_default_toolbar(void)
288 /* create default toolbar */
289 struct _default_toolbar {
293 } default_toolbar[] = {
294 { A_RECEIVE_CUR, STOCK_PIXMAP_MAIL_RECEIVE, _("Get") },
295 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get All") },
296 { A_SEPARATOR, 0, ("") },
297 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
298 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Email") },
299 { A_SEPARATOR, 0, ("") },
300 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
301 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
302 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
303 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
304 { A_SEPARATOR, 0, ("") },
305 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
306 { A_EXECUTE, STOCK_PIXMAP_EXEC, _("Execute") },
307 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") },
310 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
312 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
314 if (default_toolbar[i].action != A_SEPARATOR) {
316 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
318 toolbar_item->file = g_strdup(file);
319 toolbar_item->action = default_toolbar[i].action;
320 toolbar_item->text = g_strdup(default_toolbar[i].text);
323 toolbar_item->file = g_strdup(SEPARATOR);
324 toolbar_item->action = A_SEPARATOR;
327 if (toolbar_item->action != -1) {
329 if ( !toolbar_is_duplicate(toolbar_item->action))
330 toolbar_list = g_slist_append(toolbar_list, toolbar_item);
335 void toolbar_save_config_file()
340 gchar *fileSpec = NULL;
342 debug_print("save Toolbar Configuration\n");
344 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, TOOLBAR_FILE, NULL );
345 pfile = prefs_write_open(fileSpec);
349 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
350 conv_get_current_charset_str());
352 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
354 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
355 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
357 if (g_strcasecmp(toolbar_item->file, SEPARATOR) != 0)
358 fprintf(fp, "\t<%s %s=\"%s\" %s=\"%s\" %s=\"%s\"/>\n",
360 TOOLBAR_ICON_FILE, toolbar_item->file,
361 TOOLBAR_ICON_TEXT, toolbar_item->text,
363 toolbar_ret_text_from_val(toolbar_item->action));
365 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
368 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
370 if (prefs_write_close (pfile) < 0 )
371 g_warning("failed to write toolbar configuration to file\n");
373 g_warning("failed to open toolbar configuration file for writing\n");
376 void toolbar_clear_list()
378 while (toolbar_list != NULL) {
379 ToolbarItem *item = (ToolbarItem*) toolbar_list->data;
381 toolbar_list = g_slist_remove(toolbar_list, item);
388 g_slist_free(toolbar_list);
391 void toolbar_read_config_file(void)
393 XMLFile *file = NULL;
394 gchar *fileSpec = NULL;
398 debug_print("read Toolbar Configuration\n");
400 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, TOOLBAR_FILE, NULL );
401 file = xml_open_file(fileSpec);
404 toolbar_clear_list();
408 || (xml_get_dtd(file))
409 || (xml_parse_next_tag(file))
410 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
411 xml_close_file(file);
415 attr = xml_get_current_tag_attr(file);
422 if (xml_parse_next_tag(file))
425 /* Get next tag (icon, icon_text or icon_action) */
426 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
427 toolbar_parse_item(file);
428 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
429 ToolbarItem *item = g_new0(ToolbarItem, 1);
431 item->file = g_strdup(SEPARATOR);
432 item->action = A_SEPARATOR;
433 toolbar_list = g_slist_append(toolbar_list, item);
437 xml_close_file(file);
440 /* save default toolbar */
441 toolbar_set_default_toolbar();
442 toolbar_save_config_file();
446 static void toolbar_actions_execute_cb(GtkWidget *widget,
451 MainWindow *mainwin = (MainWindow*)data;
452 gchar *action, *action_p;
453 gboolean found = FALSE;
455 for (cur = mainwin->toolbar->syl_action; cur != NULL; cur = cur->next) {
456 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
458 if (widget == act->widget) {
460 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
461 action = g_strdup((gchar*)lop->data);
463 action_p = strstr(action, ": ");
465 if (g_strcasecmp(act->name, action) == 0) {
479 actions_execute(mwin, i, widget);
481 g_warning ("Error: did not find Sylpheed Action to execute");
484 static void toolbar_inc_cb (GtkWidget *widget,
487 MainWindow *mainwin = (MainWindow *)data;
489 inc_mail_cb(mainwin, 0, NULL);
492 static void toolbar_inc_all_cb (GtkWidget *widget,
495 MainWindow *mainwin = (MainWindow *)data;
497 inc_all_account_mail_cb(mainwin, 0, NULL);
500 static void toolbar_send_cb (GtkWidget *widget,
503 MainWindow *mainwin = (MainWindow *)data;
505 send_queue_cb(mainwin, 0, NULL);
508 static void toolbar_compose_cb (GtkWidget *widget,
511 MainWindow *mainwin = (MainWindow *)data;
513 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
514 compose_news_cb(mainwin, 0, NULL);
516 compose_mail_cb(mainwin, 0, NULL);
519 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
521 MainWindow *mainwin = (MainWindow *)data;
524 prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE
525 : COMPOSE_REPLY_WITHOUT_QUOTE,
529 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
531 MainWindow *mainwin = (MainWindow *)data;
534 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
535 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE,
540 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
542 MainWindow *mainwin = (MainWindow *)data;
545 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
546 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE,
550 static void toolbar_forward_cb (GtkWidget *widget,
553 MainWindow *mainwin = (MainWindow *)data;
555 if (prefs_common.forward_as_attachment)
556 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
558 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
561 static void toolbar_delete_cb (GtkWidget *widget,
564 MainWindow *mainwin = (MainWindow *)data;
566 summary_delete(mainwin->summaryview);
569 static void toolbar_exec_cb (GtkWidget *widget,
572 MainWindow *mainwin = (MainWindow *)data;
574 summary_execute(mainwin->summaryview);
577 static void toolbar_next_unread_cb (GtkWidget *widget,
580 MainWindow *mainwin = (MainWindow *)data;
582 next_unread_cb(mainwin, 0, NULL);
585 /* popup callback functions */
586 static void toolbar_reply_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
588 MainWindow *mainwindow = (MainWindow *) data;
592 if (event->button == 3) {
593 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
594 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->reply_popup), NULL, NULL,
595 menu_button_position, widget,
596 event->button, event->time);
600 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
602 MainWindow *mainwin = (MainWindow *)data;
604 gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->reply_btn), GTK_RELIEF_NONE);
605 manage_window_focus_in(mainwin->window, NULL, NULL);
608 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
610 MainWindow *mainwindow = (MainWindow *) data;
614 if (event->button == 3) {
615 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
616 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->replyall_popup), NULL, NULL,
617 menu_button_position, widget,
618 event->button, event->time);
622 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
624 MainWindow *mainwin = (MainWindow *)data;
626 gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->replyall_btn), GTK_RELIEF_NONE);
627 manage_window_focus_in(mainwin->window, NULL, NULL);
630 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
632 MainWindow *mainwindow = (MainWindow *) data;
636 if (event->button == 3) {
637 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
638 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->replysender_popup), NULL, NULL,
639 menu_button_position, widget,
640 event->button, event->time);
644 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
646 MainWindow *mainwin = (MainWindow *)data;
648 gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->replysender_btn), GTK_RELIEF_NONE);
649 manage_window_focus_in(mainwin->window, NULL, NULL);
652 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
654 MainWindow *mainwindow = (MainWindow *) data;
658 if (event->button == 3) {
659 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
660 gtk_menu_popup(GTK_MENU(mainwindow->toolbar->fwd_popup), NULL, NULL,
661 menu_button_position, widget,
662 event->button, event->time);
666 static void toolbar_forward_popup_closed_cb (GtkMenuShell *menu_shell,
669 MainWindow *mainwin = (MainWindow *)data;
671 gtk_button_set_relief(GTK_BUTTON(mainwin->toolbar->fwd_btn), GTK_RELIEF_NONE);
672 manage_window_focus_in(mainwin->window, NULL, NULL);
675 static void activate_compose_button (MainToolbar *toolbar,
677 ComposeButtonType type)
679 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
682 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
683 : toolbar->compose_news_btn);
684 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
685 : toolbar->compose_mail_btn);
686 toolbar->compose_btn_type = type;
689 void toolbar_set_compose_button (MainToolbar *toolbar,
690 ComposeButtonType compose_btn_type)
692 if (toolbar->compose_btn_type != compose_btn_type)
693 activate_compose_button(toolbar,
694 prefs_common.toolbar_style,
698 void toolbar_set_sensitive(MainWindow *mainwin)
702 MainToolbar *toolbar = mainwin->toolbar;
704 GSList *entry_list = NULL;
706 typedef struct _Entry Entry;
713 #define SET_WIDGET_COND(w, c) \
715 Entry *e = g_new0(Entry, 1); \
718 entry_list = g_slist_append(entry_list, e); \
721 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
722 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
723 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
724 SET_WIDGET_COND(toolbar->reply_btn,
725 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
726 SET_WIDGET_COND(toolbar->replyall_btn,
727 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
728 SET_WIDGET_COND(toolbar->replysender_btn,
729 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
730 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
732 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
733 SET_WIDGET_COND(toolbar->delete_btn,
734 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
735 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
737 for (cur = toolbar->syl_action; cur != NULL; cur = cur->next) {
738 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
740 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
743 #undef SET_WIDGET_COND
745 state = main_window_get_current_state(mainwin);
747 for (cur = entry_list; cur != NULL; cur = cur->next) {
748 Entry *e = (Entry*) cur->data;
750 if (e->widget != NULL) {
751 sensitive = ((e->cond & state) == e->cond);
752 gtk_widget_set_sensitive(e->widget, sensitive);
756 while (entry_list != NULL) {
757 Entry *e = (Entry*) entry_list->data;
761 entry_list = g_slist_remove(entry_list, e);
764 g_slist_free(entry_list);
766 activate_compose_button(toolbar,
767 prefs_common.toolbar_style,
768 toolbar->compose_btn_type);
771 void toolbar_update(void)
773 gtk_container_remove(GTK_CONTAINER(mwin->handlebox),
774 GTK_WIDGET(mwin->toolbar->toolbar));
776 mwin->toolbar->toolbar = NULL;
777 mwin->toolbar->get_btn = NULL;
778 mwin->toolbar->getall_btn = NULL;
779 mwin->toolbar->send_btn = NULL;
780 mwin->toolbar->compose_mail_btn = NULL;
781 mwin->toolbar->compose_news_btn = NULL;
782 mwin->toolbar->reply_btn = NULL;
783 mwin->toolbar->replyall_btn = NULL;
784 mwin->toolbar->replysender_btn = NULL;
785 mwin->toolbar->fwd_btn = NULL;
786 mwin->toolbar->delete_btn = NULL;
787 mwin->toolbar->next_btn = NULL;
788 mwin->toolbar->exec_btn = NULL;
790 toolbar_destroy(mwin);
791 toolbar_create(mwin, mwin->handlebox);
792 toolbar_set_sensitive(mwin);
796 void toolbar_destroy(MainWindow *mainwin)
798 ToolbarSylpheedActions *syl_action;
800 toolbar_clear_list();
802 while (mainwin->toolbar->syl_action != NULL) {
803 syl_action = (ToolbarSylpheedActions*)mainwin->toolbar->syl_action->data;
805 mainwin->toolbar->syl_action = g_slist_remove(mainwin->toolbar->syl_action, syl_action);
806 if (syl_action->name)
807 g_free(syl_action->name);
811 g_slist_free(mainwin->toolbar->syl_action);
814 void toolbar_create(MainWindow *mainwin,
815 GtkWidget *container)
817 ToolbarItem *toolbar_item;
820 GtkWidget *icon_wid = NULL;
821 GtkWidget *icon_news = NULL;
822 GtkWidget *item_news = NULL;
824 GtkTooltips *toolbar_tips;
825 ToolbarSylpheedActions *syl_action;
828 guint n_menu_entries;
829 GtkWidget *reply_popup;
830 GtkWidget *replyall_popup;
831 GtkWidget *replysender_popup;
832 GtkWidget *fwd_popup;
834 toolbar_tips = gtk_tooltips_new();
836 /* store mainwin localy */
839 if (mainwin->toolbar != NULL) {
840 toolbar_destroy(mainwin);
841 g_free(mainwin->toolbar);
844 toolbar_read_config_file();
846 mainwin->toolbar = g_new0(MainToolbar, 1);
848 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
850 gtk_container_add(GTK_CONTAINER(container), toolbar);
851 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
852 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
853 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
854 GTK_TOOLBAR_SPACE_LINE);
856 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
857 toolbar_item = (ToolbarItem*) cur->data;
860 if (g_strcasecmp(toolbar_item->file, SEPARATOR) == 0) {
861 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
865 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
866 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
870 icon_wid, toolbar_actions_cb,
873 switch (toolbar_item->action) {
875 mainwin->toolbar->getall_btn = item;
876 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
877 mainwin->toolbar->getall_btn,
878 _("Receive Mail on all Accounts"), NULL);
881 mainwin->toolbar->get_btn = item;
882 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
883 mainwin->toolbar->get_btn,
884 _("Receive Mail on current Account"), NULL);
887 mainwin->toolbar->send_btn = item;
888 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
889 mainwin->toolbar->send_btn,
890 _("Send Queued Message(s)"), NULL);
892 case A_COMPOSE_EMAIL:
893 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
894 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
896 toolbar_ret_descr_from_val(A_COMPOSE_NEWS),
898 icon_news, toolbar_actions_cb,
900 mainwin->toolbar->compose_mail_btn = item;
901 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
902 mainwin->toolbar->compose_mail_btn,
903 _("Compose Email"), NULL);
904 mainwin->toolbar->compose_news_btn = item_news;
905 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
906 mainwin->toolbar->compose_news_btn,
907 _("Compose News"), NULL);
909 case A_REPLY_MESSAGE:
910 mainwin->toolbar->reply_btn = item;
911 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
912 mainwin->toolbar->reply_btn,
913 _("Reply to Message"), NULL);
914 gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->reply_btn),
915 "button_press_event",
916 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
918 n_menu_entries = sizeof(reply_popup_entries) /
919 sizeof(reply_popup_entries[0]);
920 reply_popup = popupmenu_create(mainwin->window, reply_popup_entries, n_menu_entries,
921 "<ReplyPopup>", mainwin);
922 gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
923 GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), mainwin);
924 mainwin->toolbar->reply_popup = reply_popup;
927 mainwin->toolbar->replysender_btn = item;
928 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
929 mainwin->toolbar->replysender_btn,
930 _("Reply to Sender"), NULL);
931 gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->replysender_btn),
932 "button_press_event",
933 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
935 n_menu_entries = sizeof(replysender_popup_entries) /
936 sizeof(replysender_popup_entries[0]);
937 replysender_popup = popupmenu_create(mainwin->window,
938 replysender_popup_entries, n_menu_entries,
939 "<ReplySenderPopup>", mainwin);
940 gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
941 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), mainwin);
942 mainwin->toolbar->replysender_popup = replysender_popup;
945 mainwin->toolbar->replyall_btn = item;
946 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
947 mainwin->toolbar->replyall_btn,
948 _("Reply to All"), NULL);
949 gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->replyall_btn),
950 "button_press_event",
951 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
953 n_menu_entries = sizeof(replyall_popup_entries) /
954 sizeof(replyall_popup_entries[0]);
955 replyall_popup = popupmenu_create(mainwin->window,
956 replyall_popup_entries, n_menu_entries,
957 "<ReplyAllPopup>", mainwin);
958 gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
959 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), mainwin);
960 mainwin->toolbar->replyall_popup = replyall_popup;
963 mainwin->toolbar->fwd_btn = item;
964 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
965 mainwin->toolbar->fwd_btn,
966 _("Forward Message"), NULL);
967 gtk_signal_connect(GTK_OBJECT(mainwin->toolbar->fwd_btn),
968 "button_press_event",
969 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
971 n_menu_entries = sizeof(fwd_popup_entries) /
972 sizeof(fwd_popup_entries[0]);
973 fwd_popup = popupmenu_create(mainwin->window,
974 fwd_popup_entries, n_menu_entries,
975 "<ForwardPopup>", mainwin);
976 gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
977 GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), mainwin);
978 mainwin->toolbar->fwd_popup = fwd_popup;
981 mainwin->toolbar->delete_btn = item;
982 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
983 mainwin->toolbar->delete_btn,
984 _("Delete Message"), NULL);
987 mainwin->toolbar->exec_btn = item;
988 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
989 mainwin->toolbar->exec_btn,
993 mainwin->toolbar->next_btn = item;
994 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
995 mainwin->toolbar->next_btn,
996 _("Goto Next Message"), NULL);
999 syl_action = g_new0(ToolbarSylpheedActions, 1);
1000 syl_action->widget = item;
1001 syl_action->name = g_strdup(toolbar_item->text);
1003 mainwin->toolbar->syl_action = g_slist_append(mainwin->toolbar->syl_action,
1005 gtk_widget_show(item);
1012 mainwin->toolbar->toolbar = toolbar;
1014 activate_compose_button(mainwin->toolbar,
1015 prefs_common.toolbar_style,
1016 mainwin->toolbar->compose_btn_type);
1018 gtk_widget_show_all(toolbar);