2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2003 Hiroyuki Yamamoto and the Sylpheed-Claws team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * General functions for accessing address book files.
39 #include "mainwindow.h"
40 #include "summaryview.h"
45 #include "prefs_gtk.h"
47 #include "stock_pixmap.h"
48 #include "manage_window.h"
53 #include "prefs_actions.h"
54 #include "prefs_common.h"
55 #include "prefs_toolbar.h"
56 #include "alertpanel.h"
59 #define TOOLBAR_TAG_INDEX "toolbar"
60 #define TOOLBAR_TAG_ITEM "item"
61 #define TOOLBAR_TAG_SEPARATOR "separator"
63 #define TOOLBAR_ICON_FILE "file"
64 #define TOOLBAR_ICON_TEXT "text"
65 #define TOOLBAR_ICON_ACTION "action"
67 gboolean toolbar_is_duplicate (gint action,
69 static void toolbar_parse_item (XMLFile *file,
72 static gint toolbar_ret_val_from_text (const gchar *text);
73 static gchar *toolbar_ret_text_from_val (gint val);
75 static void toolbar_set_default_main (void);
76 static void toolbar_set_default_compose (void);
77 static void toolbar_set_default_msgview (void);
79 static void toolbar_style (ToolbarType type,
83 static GtkWidget *get_window_widget (ToolbarType type,
85 static MainWindow *get_mainwin (gpointer data);
86 static void activate_compose_button (Toolbar *toolbar,
88 ComposeButtonType type);
90 /* toolbar callbacks */
91 static void toolbar_reply (gpointer data,
93 static void toolbar_delete_cb (GtkWidget *widget,
96 static void toolbar_compose_cb (GtkWidget *widget,
99 static void toolbar_reply_cb (GtkWidget *widget,
102 static void toolbar_reply_to_all_cb (GtkWidget *widget,
105 static void toolbar_reply_to_list_cb (GtkWidget *widget,
108 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
111 static void toolbar_forward_cb (GtkWidget *widget,
114 static void toolbar_next_unread_cb (GtkWidget *widget,
117 static void toolbar_actions_execute_cb (GtkWidget *widget,
121 static void toolbar_send_cb (GtkWidget *widget,
123 static void toolbar_send_later_cb (GtkWidget *widget,
125 static void toolbar_draft_cb (GtkWidget *widget,
127 static void toolbar_insert_cb (GtkWidget *widget,
129 static void toolbar_attach_cb (GtkWidget *widget,
131 static void toolbar_sig_cb (GtkWidget *widget,
133 static void toolbar_ext_editor_cb (GtkWidget *widget,
135 static void toolbar_linewrap_cb (GtkWidget *widget,
137 static void toolbar_addrbook_cb (GtkWidget *widget,
140 static void toolbar_popup_cb (gpointer data,
146 } toolbar_text [] = {
147 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
148 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
149 { "A_SEND_QUEUED", N_("Send Queued Message(s)") },
150 { "A_COMPOSE_EMAIL", N_("Compose Email") },
151 { "A_COMPOSE_NEWS", N_("Compose News") },
152 { "A_REPLY_MESSAGE", N_("Reply to Message") },
153 { "A_REPLY_SENDER", N_("Reply to Sender") },
154 { "A_REPLY_ALL", N_("Reply to All") },
155 { "A_REPLY_ML", N_("Reply to Mailing-list") },
156 { "A_FORWARD", N_("Forward Message") },
157 { "A_DELETE", N_("Delete Message") },
158 { "A_EXECUTE", N_("Execute") },
159 { "A_GOTO_NEXT", N_("Goto Next Message") },
161 { "A_SEND", N_("Send Message") },
162 { "A_SENDL", N_("Put into queue folder and send later") },
163 { "A_DRAFT", N_("Save to draft folder") },
164 { "A_INSERT", N_("Insert file") },
165 { "A_ATTACH", N_("Attach file") },
166 { "A_SIG", N_("Insert signature") },
167 { "A_EXTEDITOR", N_("Edit with external editor") },
168 { "A_LINEWRAP", N_("Wrap all long lines") },
169 { "A_ADDRBOOK", N_("Address book") },
171 { "A_SYL_ACTIONS", N_("Sylpheed Actions Feature") },
172 { "A_SEPARATOR", "Separator" }
175 /* struct holds configuration files and a list of
176 * currently active toolbar items
177 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
181 const gchar *conf_file;
183 } toolbar_config[3] = {
184 { "toolbar_main.xml", NULL},
185 { "toolbar_compose.xml", NULL},
186 { "toolbar_msgview.xml", NULL}
189 static GtkItemFactoryEntry reply_popup_entries[] =
191 {N_("/Reply with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
192 {N_("/_Reply without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
194 static GtkItemFactoryEntry replyall_popup_entries[] =
196 {N_("/Reply to all with _quote"), "<shift>A", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
197 {N_("/_Reply to all without quote"), "a", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
199 static GtkItemFactoryEntry replylist_popup_entries[] =
201 {N_("/Reply to list with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
202 {N_("/_Reply to list without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
204 static GtkItemFactoryEntry replysender_popup_entries[] =
206 {N_("/Reply to sender with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
207 {N_("/_Reply to sender without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
209 static GtkItemFactoryEntry fwd_popup_entries[] =
211 {N_("/_Forward message (inline style)"), "f", toolbar_popup_cb, COMPOSE_FORWARD_INLINE, NULL},
212 {N_("/Forward message as _attachment"), "<shift>F", toolbar_popup_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
216 gint toolbar_ret_val_from_descr(const gchar *descr)
220 for (i = 0; i < N_ACTION_VAL; i++) {
221 if (g_strcasecmp(gettext(toolbar_text[i].descr), descr) == 0)
228 gchar *toolbar_ret_descr_from_val(gint val)
230 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
232 return gettext(toolbar_text[val].descr);
235 static gint toolbar_ret_val_from_text(const gchar *text)
239 for (i = 0; i < N_ACTION_VAL; i++) {
240 if (g_strcasecmp(toolbar_text[i].index_str, text) == 0)
247 static gchar *toolbar_ret_text_from_val(gint val)
249 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
251 return toolbar_text[val].index_str;
254 gboolean toolbar_is_duplicate(gint action, ToolbarType source)
258 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
261 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
262 ToolbarItem *item = (ToolbarItem*) cur->data;
264 if (item->index == action)
270 /* depending on toolbar type this function
271 returns a list of available toolbar events being
272 displayed by prefs_toolbar
274 GList *toolbar_get_action_items(ToolbarType source)
279 if (source == TOOLBAR_MAIN) {
280 gint main_items[14] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
281 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
282 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
283 A_DELETE, A_EXECUTE, A_GOTO_NEXT,
284 A_ADDRBOOK, A_SYL_ACTIONS };
286 for (i = 0; i < sizeof(main_items)/sizeof(main_items[0]); i++)
287 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
289 else if (source == TOOLBAR_COMPOSE) {
290 gint comp_items[10] = { A_SEND, A_SENDL, A_DRAFT,
291 A_INSERT, A_ATTACH, A_SIG,
292 A_EXTEDITOR, A_LINEWRAP, A_ADDRBOOK,
295 for (i = 0; i < sizeof(comp_items)/sizeof(comp_items[0]); i++)
296 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
298 else if (source == TOOLBAR_MSGVIEW) {
299 gint msgv_items[10] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
300 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
301 A_DELETE, A_GOTO_NEXT, A_ADDRBOOK,
304 for (i = 0; i < sizeof(msgv_items)/sizeof(msgv_items[0]); i++)
305 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
311 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
315 ToolbarItem *item = NULL;
317 attr = xml_get_current_tag_attr(file);
318 item = g_new0(ToolbarItem, 1);
320 name = ((XMLAttr *)attr->data)->name;
321 value = ((XMLAttr *)attr->data)->value;
323 if (g_strcasecmp(name, TOOLBAR_ICON_FILE) == 0)
324 item->file = g_strdup (value);
325 else if (g_strcasecmp(name, TOOLBAR_ICON_TEXT) == 0)
326 item->text = g_strdup (value);
327 else if (g_strcasecmp(name, TOOLBAR_ICON_ACTION) == 0)
328 item->index = toolbar_ret_val_from_text(value);
330 attr = g_list_next(attr);
332 if (item->index != -1) {
334 if (!toolbar_is_duplicate(item->index, source))
335 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
340 static void toolbar_set_default_main(void)
346 } default_toolbar[] = {
347 { A_RECEIVE_CUR, STOCK_PIXMAP_MAIL_RECEIVE, _("Get") },
348 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get All") },
349 { A_SEPARATOR, 0, ("") },
350 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
351 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Email") },
352 { A_SEPARATOR, 0, ("") },
353 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
354 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
355 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
356 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
357 { A_SEPARATOR, 0, ("") },
358 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
359 { A_EXECUTE, STOCK_PIXMAP_EXEC, _("Execute") },
360 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
365 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
367 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
369 if (default_toolbar[i].action != A_SEPARATOR) {
371 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
373 toolbar_item->file = g_strdup(file);
374 toolbar_item->index = default_toolbar[i].action;
375 toolbar_item->text = g_strdup(default_toolbar[i].text);
378 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
379 toolbar_item->index = A_SEPARATOR;
382 if (toolbar_item->index != -1) {
383 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
384 toolbar_config[TOOLBAR_MAIN].item_list =
385 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
390 static void toolbar_set_default_compose(void)
396 } default_toolbar[] = {
397 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
398 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
399 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
400 { A_SEPARATOR, 0, ("") },
401 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
402 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
403 { A_SIG, STOCK_PIXMAP_MAIL_SIGN, _("Signature") },
404 { A_SEPARATOR, 0, ("") },
405 { A_EXTEDITOR, STOCK_PIXMAP_EDIT_EXTERN, _("Editor") },
406 { A_LINEWRAP, STOCK_PIXMAP_LINEWRAP, _("Linewrap") },
407 { A_SEPARATOR, 0, ("") },
408 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
413 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
415 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
417 if (default_toolbar[i].action != A_SEPARATOR) {
419 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
421 toolbar_item->file = g_strdup(file);
422 toolbar_item->index = default_toolbar[i].action;
423 toolbar_item->text = g_strdup(default_toolbar[i].text);
426 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
427 toolbar_item->index = A_SEPARATOR;
430 if (toolbar_item->index != -1) {
431 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
432 toolbar_config[TOOLBAR_COMPOSE].item_list =
433 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
438 static void toolbar_set_default_msgview(void)
444 } default_toolbar[] = {
445 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
446 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
447 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
448 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
449 { A_SEPARATOR, 0, ("") },
450 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
451 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
456 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
458 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
460 if (default_toolbar[i].action != A_SEPARATOR) {
462 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
464 toolbar_item->file = g_strdup(file);
465 toolbar_item->index = default_toolbar[i].action;
466 toolbar_item->text = g_strdup(default_toolbar[i].text);
469 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
470 toolbar_item->index = A_SEPARATOR;
473 if (toolbar_item->index != -1) {
474 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
475 toolbar_config[TOOLBAR_MSGVIEW].item_list =
476 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
481 void toolbar_set_default(ToolbarType source)
483 if (source == TOOLBAR_MAIN)
484 toolbar_set_default_main();
485 else if (source == TOOLBAR_COMPOSE)
486 toolbar_set_default_compose();
487 else if (source == TOOLBAR_MSGVIEW)
488 toolbar_set_default_msgview();
491 void toolbar_save_config_file(ToolbarType source)
496 gchar *fileSpec = NULL;
498 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
500 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
501 pfile = prefs_write_open(fileSpec);
505 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
506 conv_get_current_charset_str());
508 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
510 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
511 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
513 if (toolbar_item->index != A_SEPARATOR)
514 fprintf(fp, "\t<%s %s=\"%s\" %s=\"%s\" %s=\"%s\"/>\n",
516 TOOLBAR_ICON_FILE, toolbar_item->file,
517 TOOLBAR_ICON_TEXT, toolbar_item->text,
519 toolbar_ret_text_from_val(toolbar_item->index));
521 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
524 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
526 if (prefs_file_close (pfile) < 0 )
527 g_warning("failed to write toolbar configuration to file\n");
529 g_warning("failed to open toolbar configuration file for writing\n");
532 void toolbar_read_config_file(ToolbarType source)
534 XMLFile *file = NULL;
535 gchar *fileSpec = NULL;
540 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
542 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
543 file = xml_open_file(fileSpec);
546 toolbar_clear_list(source);
550 || (xml_get_dtd(file))
551 || (xml_parse_next_tag(file))
552 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
553 xml_close_file(file);
557 attr = xml_get_current_tag_attr(file);
564 if (xml_parse_next_tag(file))
567 /* Get next tag (icon, icon_text or icon_action) */
568 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
569 toolbar_parse_item(file, source);
570 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
571 ToolbarItem *item = g_new0(ToolbarItem, 1);
573 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
574 item->index = A_SEPARATOR;
575 toolbar_config[source].item_list =
576 g_slist_append(toolbar_config[source].item_list, item);
580 xml_close_file(file);
583 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
585 if (source == TOOLBAR_MAIN)
586 toolbar_set_default(TOOLBAR_MAIN);
587 else if (source == TOOLBAR_COMPOSE)
588 toolbar_set_default(TOOLBAR_COMPOSE);
589 else if (source == TOOLBAR_MSGVIEW)
590 toolbar_set_default(TOOLBAR_MSGVIEW);
592 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
596 toolbar_save_config_file(source);
601 * clears list of toolbar items read from configuration files
603 void toolbar_clear_list(ToolbarType source)
605 while (toolbar_config[source].item_list != NULL) {
606 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
608 toolbar_config[source].item_list =
609 g_slist_remove(toolbar_config[source].item_list, item);
617 g_slist_free(toolbar_config[source].item_list);
622 * return list of Toolbar items
624 GSList *toolbar_get_list(ToolbarType source)
628 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
629 list = toolbar_config[source].item_list;
634 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
636 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
638 toolbar_item->file = g_strdup(t_item->file);
639 toolbar_item->text = g_strdup(t_item->text);
640 toolbar_item->index = t_item->index;
642 toolbar_config[source].item_list =
643 g_slist_append(toolbar_config[source].item_list,
647 void toolbar_action_execute(GtkWidget *widget,
653 gchar *action, *action_p;
654 gboolean found = FALSE;
657 for (cur = action_list; cur != NULL; cur = cur->next) {
658 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
660 if (widget == act->widget) {
662 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
663 action = g_strdup((gchar*)lop->data);
665 action_p = strstr(action, ": ");
667 if (g_strcasecmp(act->name, action) == 0) {
681 actions_execute(data, i, widget, source);
683 g_warning ("Error: did not find Sylpheed Action to execute");
686 static void activate_compose_button (Toolbar *toolbar,
688 ComposeButtonType type)
690 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
693 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
694 : toolbar->compose_news_btn);
695 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
696 : toolbar->compose_mail_btn);
697 toolbar->compose_btn_type = type;
700 void toolbar_set_compose_button(Toolbar *toolbar,
701 ComposeButtonType compose_btn_type)
703 if (toolbar->compose_btn_type != compose_btn_type)
704 activate_compose_button(toolbar,
705 prefs_common.toolbar_style,
709 void toolbar_toggle(guint action, gpointer data)
711 MainWindow *mainwin = (MainWindow*)data;
715 g_return_if_fail(mainwin != NULL);
717 toolbar_style(TOOLBAR_MAIN, action, mainwin);
719 list = compose_get_compose_list();
720 for (cur = list; cur != NULL; cur = cur->next) {
721 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
723 list = messageview_get_msgview_list();
724 for (cur = list; cur != NULL; cur = cur->next) {
725 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
730 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
732 switch ((ToolbarStyle)action) {
734 gtk_widget_hide(handlebox_wid);
737 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
741 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
745 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
752 prefs_common.toolbar_style = (ToolbarStyle)action;
753 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
754 gtk_widget_show(handlebox_wid);
755 gtk_widget_queue_resize(handlebox_wid);
759 * Change the style of toolbar
761 static void toolbar_style(ToolbarType type, guint action, gpointer data)
763 GtkWidget *handlebox_wid;
764 GtkWidget *toolbar_wid;
765 MainWindow *mainwin = (MainWindow*)data;
766 Compose *compose = (Compose*)data;
767 MessageView *msgview = (MessageView*)data;
769 g_return_if_fail(data != NULL);
773 handlebox_wid = mainwin->handlebox;
774 toolbar_wid = mainwin->toolbar->toolbar;
776 case TOOLBAR_COMPOSE:
777 handlebox_wid = compose->handlebox;
778 toolbar_wid = compose->toolbar->toolbar;
780 case TOOLBAR_MSGVIEW:
781 handlebox_wid = msgview->handlebox;
782 toolbar_wid = msgview->toolbar->toolbar;
788 toolbar_set_style(toolbar_wid, handlebox_wid, action);
791 /* Toolbar handling */
792 static void toolbar_inc_cb(GtkWidget *widget,
795 ToolbarItem *toolbar_item = (ToolbarItem*)data;
798 g_return_if_fail(toolbar_item != NULL);
800 switch (toolbar_item->type) {
802 mainwin = (MainWindow*)toolbar_item->parent;
803 inc_mail_cb(mainwin, 0, NULL);
810 static void toolbar_inc_all_cb(GtkWidget *widget,
813 ToolbarItem *toolbar_item = (ToolbarItem*)data;
816 g_return_if_fail(toolbar_item != NULL);
818 switch (toolbar_item->type) {
820 mainwin = (MainWindow*)toolbar_item->parent;
821 inc_all_account_mail_cb(mainwin, 0, NULL);
828 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
830 ToolbarItem *toolbar_item = (ToolbarItem*)data;
833 g_return_if_fail(toolbar_item != NULL);
835 switch (toolbar_item->type) {
837 mainwin = (MainWindow*)toolbar_item->parent;
838 send_queue_cb(mainwin, 0, NULL);
845 static void toolbar_exec_cb(GtkWidget *widget,
848 MainWindow *mainwin = get_mainwin(data);
850 g_return_if_fail(mainwin != NULL);
851 summary_execute(mainwin->summaryview);
856 /* popup callback functions */
857 static void toolbar_reply_popup_cb(GtkWidget *widget,
858 GdkEventButton *event,
861 Toolbar *toolbar_data = (Toolbar*)data;
865 if (event->button == 3) {
866 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
867 gtk_menu_popup(GTK_MENU(toolbar_data->reply_popup), NULL, NULL,
868 menu_button_position, widget,
869 event->button, event->time);
873 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
875 ToolbarItem *toolbar_item = (ToolbarItem*)data;
877 GtkWidget *reply_btn;
879 MessageView *msgview;
881 g_return_if_fail(toolbar_item != NULL);
883 switch(toolbar_item->type) {
885 mainwin = (MainWindow*)toolbar_item->parent;
886 reply_btn = mainwin->toolbar->reply_btn;
887 window = mainwin->window;
889 case TOOLBAR_MSGVIEW:
890 msgview = (MessageView*)toolbar_item->parent;
891 reply_btn = msgview->toolbar->reply_btn;
892 window = msgview->window;
898 gtk_button_set_relief(GTK_BUTTON(reply_btn), GTK_RELIEF_NONE);
899 manage_window_focus_in(window, NULL, NULL);
902 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
904 Toolbar *toolbar_data = (Toolbar*)data;
908 if (event->button == 3) {
909 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
910 gtk_menu_popup(GTK_MENU(toolbar_data->replyall_popup), NULL, NULL,
911 menu_button_position, widget,
912 event->button, event->time);
916 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
918 ToolbarItem *toolbar_item = (ToolbarItem*)data;
920 GtkWidget *replyall_btn;
922 MessageView *msgview;
924 g_return_if_fail(toolbar_item != NULL);
926 switch(toolbar_item->type) {
928 mainwin = (MainWindow*)toolbar_item->parent;
929 replyall_btn = mainwin->toolbar->replyall_btn;
930 window = mainwin->window;
932 case TOOLBAR_MSGVIEW:
933 msgview = (MessageView*)toolbar_item->parent;
934 replyall_btn = msgview->toolbar->replyall_btn;
935 window = msgview->window;
941 gtk_button_set_relief(GTK_BUTTON(replyall_btn), GTK_RELIEF_NONE);
942 manage_window_focus_in(window, NULL, NULL);
945 static void toolbar_reply_to_list_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
947 Toolbar *toolbar_data = (Toolbar*)data;
949 if (event->button == 3) {
950 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
951 gtk_menu_popup(GTK_MENU(toolbar_data->replylist_popup), NULL, NULL,
952 menu_button_position, widget,
953 event->button, event->time);
957 static void toolbar_reply_to_list_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
959 ToolbarItem *toolbar_item = (ToolbarItem*)data;
960 gpointer parent = toolbar_item->parent;
962 GtkWidget *replylist_btn;
965 g_return_if_fail(toolbar_item != NULL);
967 switch(toolbar_item->type) {
969 replylist_btn = ((MainWindow*)parent)->toolbar->replylist_btn;
970 window = ((MainWindow*)parent)->window;
972 case TOOLBAR_MSGVIEW:
973 replylist_btn = ((MessageView*)parent)->toolbar->replylist_btn;
974 window = ((MessageView*)parent)->window;
980 gtk_button_set_relief(GTK_BUTTON(replylist_btn), GTK_RELIEF_NONE);
981 manage_window_focus_in(window, NULL, NULL);
984 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
986 Toolbar *toolbar_data = (Toolbar*)data;
988 if (event->button == 3) {
989 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
990 gtk_menu_popup(GTK_MENU(toolbar_data->replysender_popup), NULL, NULL,
991 menu_button_position, widget,
992 event->button, event->time);
996 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
998 ToolbarItem *toolbar_item = (ToolbarItem*)data;
999 gpointer parent = toolbar_item->parent;
1001 GtkWidget *replysender_btn;
1003 g_return_if_fail(toolbar_item != NULL);
1005 switch(toolbar_item->type) {
1007 replysender_btn = ((MainWindow*)parent)->toolbar->replysender_btn;
1008 window = ((MainWindow*)parent)->window;
1010 case TOOLBAR_MSGVIEW:
1011 replysender_btn = ((MessageView*)parent)->toolbar->replysender_btn;
1012 window = ((MessageView*)parent)->window;
1018 gtk_button_set_relief(GTK_BUTTON(replysender_btn), GTK_RELIEF_NONE);
1019 manage_window_focus_in(window, NULL, NULL);
1022 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1024 Toolbar *toolbar_data = (Toolbar*)data;
1026 if (event->button == 3) {
1027 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1028 gtk_menu_popup(GTK_MENU(toolbar_data->fwd_popup), NULL, NULL,
1029 menu_button_position, widget,
1030 event->button, event->time);
1034 static void toolbar_forward_popup_closed_cb (GtkMenuShell *menu_shell,
1037 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1038 gpointer parent = toolbar_item->parent;
1042 g_return_if_fail(toolbar_item != NULL);
1044 switch(toolbar_item->type) {
1046 fwd_btn = ((MainWindow*)parent)->toolbar->fwd_btn;
1047 window = ((MainWindow*)parent)->window;
1049 case TOOLBAR_MSGVIEW:
1050 fwd_btn = ((MessageView*)parent)->toolbar->fwd_btn;
1051 window = ((MessageView*)parent)->window;
1057 gtk_button_set_relief(GTK_BUTTON(fwd_btn), GTK_RELIEF_NONE);
1058 manage_window_focus_in(window, NULL, NULL);
1062 * Delete current/selected(s) message(s)
1064 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1066 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1067 MainWindow *mainwin;
1068 MessageView *msgview;
1070 g_return_if_fail(toolbar_item != NULL);
1072 switch (toolbar_item->type) {
1073 case TOOLBAR_MSGVIEW:
1074 msgview = (MessageView*)toolbar_item->parent;
1075 messageview_delete(msgview);
1078 mainwin = (MainWindow*)toolbar_item->parent;
1079 summary_delete(mainwin->summaryview);
1082 debug_print("toolbar event not supported\n");
1089 * Compose new message
1091 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1093 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1094 MainWindow *mainwin;
1095 MessageView *msgview;
1097 g_return_if_fail(toolbar_item != NULL);
1099 switch (toolbar_item->type) {
1101 mainwin = (MainWindow*)toolbar_item->parent;
1102 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1103 compose_news_cb(mainwin, 0, NULL);
1105 compose_mail_cb(mainwin, 0, NULL);
1107 case TOOLBAR_MSGVIEW:
1108 msgview = (MessageView*)toolbar_item->parent;
1109 compose_new_with_folderitem(NULL,
1110 msgview->msginfo->folder);
1113 debug_print("toolbar event not supported\n");
1117 static void toolbar_popup_cb(gpointer data, guint action, GtkWidget *widget)
1119 toolbar_reply(data, action);
1126 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1128 toolbar_reply(data, prefs_common.reply_with_quote ?
1129 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1134 * Reply message to Sender and All recipients
1136 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1139 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1140 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1145 * Reply to Mailing List
1147 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1150 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1151 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1156 * Reply to sender of message
1158 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1161 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1162 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1168 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1170 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1173 g_return_if_fail(toolbar_item != NULL);
1175 switch (toolbar_item->type) {
1177 case TOOLBAR_MSGVIEW:
1180 case TOOLBAR_COMPOSE:
1181 compose = (Compose *)toolbar_item->parent;
1186 addressbook_open(compose);
1191 * Forward current/selected(s) message(s)
1193 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1195 toolbar_reply(data, COMPOSE_FORWARD);
1200 * Goto Next Unread Message
1202 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1204 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1205 MainWindow *mainwin;
1206 MessageView *msgview;
1208 g_return_if_fail(toolbar_item != NULL);
1210 switch (toolbar_item->type) {
1212 mainwin = (MainWindow*)toolbar_item->parent;
1213 summary_select_next_unread(mainwin->summaryview);
1216 case TOOLBAR_MSGVIEW:
1217 msgview = (MessageView*)toolbar_item->parent;
1219 * TODO: Check if summaryview stay in the same place when this message view was created
1220 * if summary have other message select the next will be based on message selected in summaryview
1222 summary_select_next_unread(msgview->mainwin->summaryview);
1224 /** Now we need to update the messageview window */
1225 if (msgview->mainwin->summaryview->selected) {
1226 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1228 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1229 msgview->mainwin->summaryview->selected);
1231 messageview_show(msgview, msginfo,
1232 msgview->all_headers);
1234 gtk_widget_destroy(msgview->window);
1238 debug_print("toolbar event not supported\n");
1242 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1244 compose_toolbar_cb(A_SEND, data);
1247 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1249 compose_toolbar_cb(A_SENDL, data);
1252 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1254 compose_toolbar_cb(A_DRAFT, data);
1257 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1259 compose_toolbar_cb(A_INSERT, data);
1262 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1264 compose_toolbar_cb(A_ATTACH, data);
1267 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1269 compose_toolbar_cb(A_SIG, data);
1272 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1274 compose_toolbar_cb(A_EXTEDITOR, data);
1277 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
1279 compose_toolbar_cb(A_LINEWRAP, data);
1283 * Execute actions from toolbar
1285 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1287 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1288 GSList *action_list;
1289 MainWindow *mainwin;
1291 MessageView *msgview;
1292 gpointer parent = toolbar_item->parent;
1294 g_return_if_fail(toolbar_item != NULL);
1296 switch (toolbar_item->type) {
1298 mainwin = (MainWindow*)parent;
1299 action_list = mainwin->toolbar->action_list;
1301 case TOOLBAR_COMPOSE:
1302 compose = (Compose*)parent;
1303 action_list = compose->toolbar->action_list;
1305 case TOOLBAR_MSGVIEW:
1306 msgview = (MessageView*)parent;
1307 action_list = msgview->toolbar->action_list;
1310 debug_print("toolbar event not supported\n");
1313 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1316 static MainWindow *get_mainwin(gpointer data)
1318 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1319 MainWindow *mainwin = NULL;
1320 MessageView *msgview;
1322 g_return_val_if_fail(toolbar_item != NULL, NULL);
1324 switch(toolbar_item->type) {
1326 mainwin = (MainWindow*)toolbar_item->parent;
1328 case TOOLBAR_MSGVIEW:
1329 msgview = (MessageView*)toolbar_item->parent;
1330 mainwin = (MainWindow*)msgview->mainwin;
1339 static GtkWidget *get_window_widget(ToolbarType type, gpointer data)
1341 MainWindow *mainwin;
1342 MessageView *msgview;
1346 mainwin = (MainWindow*)data;
1347 return mainwin->window;
1349 case TOOLBAR_MSGVIEW:
1350 msgview = (MessageView*)data;
1351 return msgview->vbox;
1359 static void toolbar_buttons_cb(GtkWidget *widget,
1366 void (*func)(GtkWidget *widget, gpointer data);
1368 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1369 { A_RECEIVE_CUR, toolbar_inc_cb },
1370 { A_SEND_QUEUED, toolbar_send_queued_cb },
1371 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1372 { A_COMPOSE_NEWS, toolbar_compose_cb },
1373 { A_REPLY_MESSAGE, toolbar_reply_cb },
1374 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1375 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1376 { A_REPLY_ML, toolbar_reply_to_list_cb },
1377 { A_FORWARD, toolbar_forward_cb },
1378 { A_DELETE, toolbar_delete_cb },
1379 { A_EXECUTE, toolbar_exec_cb },
1380 { A_GOTO_NEXT, toolbar_next_unread_cb },
1382 { A_SEND, toolbar_send_cb },
1383 { A_SENDL, toolbar_send_later_cb },
1384 { A_DRAFT, toolbar_draft_cb },
1385 { A_INSERT, toolbar_insert_cb },
1386 { A_ATTACH, toolbar_attach_cb },
1387 { A_SIG, toolbar_sig_cb },
1388 { A_EXTEDITOR, toolbar_ext_editor_cb },
1389 { A_LINEWRAP, toolbar_linewrap_cb },
1390 { A_ADDRBOOK, toolbar_addrbook_cb },
1392 { A_SYL_ACTIONS, toolbar_actions_execute_cb }
1395 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1397 for (i = 0; i < num_items; i++) {
1398 if (callbacks[i].index == item->index) {
1399 callbacks[i].func(widget, item);
1406 * Create a new toolbar with specified type
1407 * if a callback list is passed it will be used before the
1408 * common callback list
1410 Toolbar *toolbar_create(ToolbarType type,
1411 GtkWidget *container,
1414 ToolbarItem *toolbar_item;
1417 GtkWidget *icon_wid = NULL;
1418 GtkWidget *icon_news;
1420 GtkWidget *item_news;
1421 GtkWidget *window_wid;
1423 guint n_menu_entries;
1424 GtkWidget *reply_popup;
1425 GtkWidget *replyall_popup;
1426 GtkWidget *replylist_popup;
1427 GtkWidget *replysender_popup;
1428 GtkWidget *fwd_popup;
1430 GtkTooltips *toolbar_tips;
1431 ToolbarSylpheedActions *action_item;
1433 GSList *toolbar_list;
1434 Toolbar *toolbar_data;
1437 toolbar_tips = gtk_tooltips_new();
1439 toolbar_read_config_file(type);
1440 toolbar_list = toolbar_get_list(type);
1442 toolbar_data = g_new0(Toolbar, 1);
1444 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1446 gtk_container_add(GTK_CONTAINER(container), toolbar);
1447 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1448 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1449 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1450 GTK_TOOLBAR_SPACE_LINE);
1452 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1454 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1455 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1459 toolbar_item = g_new0(ToolbarItem, 1);
1460 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1461 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1462 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1463 toolbar_item->parent = data;
1464 toolbar_item->type = type;
1466 /* collect toolbar items in list to keep track */
1467 toolbar_data->item_list =
1468 g_slist_append(toolbar_data->item_list,
1471 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1472 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1476 icon_wid, toolbar_buttons_cb,
1479 switch (toolbar_item->index) {
1482 toolbar_data->getall_btn = item;
1483 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1484 toolbar_data->getall_btn,
1485 _("Receive Mail on all Accounts"), NULL);
1488 toolbar_data->get_btn = item;
1489 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1490 toolbar_data->get_btn,
1491 _("Receive Mail on current Account"), NULL);
1494 toolbar_data->send_btn = item;
1495 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1496 toolbar_data->send_btn,
1497 _("Send Queued Message(s)"), NULL);
1499 case A_COMPOSE_EMAIL:
1500 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1501 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1505 icon_news, toolbar_buttons_cb,
1507 toolbar_data->compose_mail_btn = item;
1508 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1509 toolbar_data->compose_mail_btn,
1510 _("Compose Email"), NULL);
1511 toolbar_data->compose_news_btn = item_news;
1512 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1513 toolbar_data->compose_news_btn,
1514 _("Compose News"), NULL);
1516 case A_REPLY_MESSAGE:
1517 toolbar_data->reply_btn = item;
1518 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1519 toolbar_data->reply_btn,
1520 _("Reply to Message"), NULL);
1521 gtk_signal_connect(GTK_OBJECT(toolbar_data->reply_btn),
1522 "button_press_event",
1523 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
1525 n_menu_entries = sizeof(reply_popup_entries) /
1526 sizeof(reply_popup_entries[0]);
1528 window_wid = get_window_widget(type, data);
1529 reply_popup = popupmenu_create(window_wid,
1530 reply_popup_entries, n_menu_entries,
1531 "<ReplyPopup>", (gpointer)toolbar_item);
1533 gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
1534 GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), toolbar_item);
1535 toolbar_data->reply_popup = reply_popup;
1537 case A_REPLY_SENDER:
1538 toolbar_data->replysender_btn = item;
1539 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1540 toolbar_data->replysender_btn,
1541 _("Reply to Sender"), NULL);
1542 gtk_signal_connect(GTK_OBJECT(toolbar_data->replysender_btn),
1543 "button_press_event",
1544 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
1546 n_menu_entries = sizeof(replysender_popup_entries) /
1547 sizeof(replysender_popup_entries[0]);
1549 window_wid = get_window_widget(type, data);
1550 replysender_popup = popupmenu_create(window_wid,
1551 replysender_popup_entries, n_menu_entries,
1552 "<ReplySenderPopup>", (gpointer)toolbar_item);
1554 gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
1555 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), toolbar_item);
1556 toolbar_data->replysender_popup = replysender_popup;
1559 toolbar_data->replyall_btn = item;
1560 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1561 toolbar_data->replyall_btn,
1562 _("Reply to All"), NULL);
1563 gtk_signal_connect(GTK_OBJECT(toolbar_data->replyall_btn),
1564 "button_press_event",
1565 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
1567 n_menu_entries = sizeof(replyall_popup_entries) /
1568 sizeof(replyall_popup_entries[0]);
1570 window_wid = get_window_widget(type, data);
1571 replyall_popup = popupmenu_create(window_wid,
1572 replyall_popup_entries, n_menu_entries,
1573 "<ReplyAllPopup>", (gpointer)toolbar_item);
1575 gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
1576 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), toolbar_item);
1577 toolbar_data->replyall_popup = replyall_popup;
1580 toolbar_data->replylist_btn = item;
1581 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1582 toolbar_data->replylist_btn,
1583 _("Reply to Mailing-list"), NULL);
1584 gtk_signal_connect(GTK_OBJECT(toolbar_data->replylist_btn),
1585 "button_press_event",
1586 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_cb),
1588 n_menu_entries = sizeof(replylist_popup_entries) /
1589 sizeof(replylist_popup_entries[0]);
1591 window_wid = get_window_widget(type, data);
1592 replylist_popup = popupmenu_create(window_wid,
1593 replylist_popup_entries, n_menu_entries,
1594 "<ReplyMlPopup>", (gpointer)toolbar_item);
1596 gtk_signal_connect(GTK_OBJECT(replylist_popup), "selection_done",
1597 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_closed_cb), toolbar_item);
1598 toolbar_data->replylist_popup = replylist_popup;
1601 toolbar_data->fwd_btn = item;
1602 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1603 toolbar_data->fwd_btn,
1604 _("Forward Message"), NULL);
1605 gtk_signal_connect(GTK_OBJECT(toolbar_data->fwd_btn),
1606 "button_press_event",
1607 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
1609 n_menu_entries = sizeof(fwd_popup_entries) /
1610 sizeof(fwd_popup_entries[0]);
1612 window_wid = get_window_widget(type, data);
1613 fwd_popup = popupmenu_create(window_wid,
1614 fwd_popup_entries, n_menu_entries,
1615 "<ForwardPopup>", (gpointer)toolbar_item);
1617 gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
1618 GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), toolbar_item);
1619 toolbar_data->fwd_popup = fwd_popup;
1622 toolbar_data->delete_btn = item;
1623 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1624 toolbar_data->delete_btn,
1625 _("Delete Message"), NULL);
1628 toolbar_data->exec_btn = item;
1629 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1630 toolbar_data->exec_btn,
1631 _("Execute"), NULL);
1634 toolbar_data->next_btn = item;
1635 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1636 toolbar_data->next_btn,
1637 _("Goto Next Message"), NULL);
1640 /* Compose Toolbar */
1642 toolbar_data->send_btn = item;
1643 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1644 toolbar_data->send_btn,
1645 _("Send Message"), NULL);
1648 toolbar_data->sendl_btn = item;
1649 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1650 toolbar_data->sendl_btn,
1651 _("Put into queue folder and send later"), NULL);
1654 toolbar_data->draft_btn = item;
1655 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1656 toolbar_data->draft_btn,
1657 _("Save to draft folder"), NULL);
1660 toolbar_data->insert_btn = item;
1661 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1662 toolbar_data->insert_btn,
1663 _("Insert file"), NULL);
1666 toolbar_data->attach_btn = item;
1667 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1668 toolbar_data->attach_btn,
1669 _("Attach file"), NULL);
1672 toolbar_data->sig_btn = item;
1673 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1674 toolbar_data->sig_btn,
1675 _("Insert signature"), NULL);
1678 toolbar_data->exteditor_btn = item;
1679 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1680 toolbar_data->exteditor_btn,
1681 _("Edit with external editor"), NULL);
1684 toolbar_data->linewrap_btn = item;
1685 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1686 toolbar_data->linewrap_btn,
1687 _("Wrap all long lines"), NULL);
1690 toolbar_data->addrbook_btn = item;
1691 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1692 toolbar_data->addrbook_btn,
1693 _("Address book"), NULL);
1697 action_item = g_new0(ToolbarSylpheedActions, 1);
1698 action_item->widget = item;
1699 action_item->name = g_strdup(toolbar_item->text);
1701 toolbar_data->action_list =
1702 g_slist_append(toolbar_data->action_list,
1705 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1707 action_item->name, NULL);
1709 gtk_widget_show(item);
1716 toolbar_data->toolbar = toolbar;
1717 if (type == TOOLBAR_MAIN)
1718 activate_compose_button(toolbar_data,
1719 prefs_common.toolbar_style,
1720 toolbar_data->compose_btn_type);
1722 gtk_widget_show_all(toolbar);
1724 return toolbar_data;
1728 * Free toolbar structures
1730 void toolbar_destroy(Toolbar * toolbar) {
1732 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1733 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1736 void toolbar_update(ToolbarType type, gpointer data)
1738 Toolbar *toolbar_data;
1739 GtkWidget *handlebox;
1740 MainWindow *mainwin = (MainWindow*)data;
1741 Compose *compose = (Compose*)data;
1742 MessageView *msgview = (MessageView*)data;
1746 toolbar_data = mainwin->toolbar;
1747 handlebox = mainwin->handlebox;
1749 case TOOLBAR_COMPOSE:
1750 toolbar_data = compose->toolbar;
1751 handlebox = compose->handlebox;
1753 case TOOLBAR_MSGVIEW:
1754 toolbar_data = msgview->toolbar;
1755 handlebox = msgview->handlebox;
1761 gtk_container_remove(GTK_CONTAINER(handlebox),
1762 GTK_WIDGET(toolbar_data->toolbar));
1764 toolbar_init(toolbar_data);
1765 toolbar_data = toolbar_create(type, handlebox, data);
1768 mainwin->toolbar = toolbar_data;
1770 case TOOLBAR_COMPOSE:
1771 compose->toolbar = toolbar_data;
1773 case TOOLBAR_MSGVIEW:
1774 msgview->toolbar = toolbar_data;
1778 toolbar_style(type, prefs_common.toolbar_style, data);
1780 if (type == TOOLBAR_MAIN)
1781 toolbar_main_set_sensitive((MainWindow*)data);
1784 void toolbar_main_set_sensitive(gpointer data)
1786 SensitiveCond state;
1788 MainWindow *mainwin = (MainWindow*)data;
1789 Toolbar *toolbar = mainwin->toolbar;
1791 GSList *entry_list = NULL;
1793 typedef struct _Entry Entry;
1800 #define SET_WIDGET_COND(w, c) \
1802 Entry *e = g_new0(Entry, 1); \
1805 entry_list = g_slist_append(entry_list, e); \
1808 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1809 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1810 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1811 SET_WIDGET_COND(toolbar->reply_btn,
1812 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1813 SET_WIDGET_COND(toolbar->replyall_btn,
1814 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1815 SET_WIDGET_COND(toolbar->replylist_btn,
1816 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1817 SET_WIDGET_COND(toolbar->replysender_btn,
1818 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1819 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1821 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1822 SET_WIDGET_COND(toolbar->delete_btn,
1823 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1824 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1826 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
1827 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1829 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1832 #undef SET_WIDGET_COND
1834 state = main_window_get_current_state(mainwin);
1836 for (cur = entry_list; cur != NULL; cur = cur->next) {
1837 Entry *e = (Entry*) cur->data;
1839 if (e->widget != NULL) {
1840 sensitive = ((e->cond & state) == e->cond);
1841 gtk_widget_set_sensitive(e->widget, sensitive);
1845 while (entry_list != NULL) {
1846 Entry *e = (Entry*) entry_list->data;
1850 entry_list = g_slist_remove(entry_list, e);
1853 g_slist_free(entry_list);
1855 activate_compose_button(toolbar,
1856 prefs_common.toolbar_style,
1857 toolbar->compose_btn_type);
1860 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1862 Compose *compose = (Compose*)data;
1863 GSList *items = compose->toolbar->action_list;
1865 if (compose->toolbar->send_btn)
1866 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1867 if (compose->toolbar->sendl_btn)
1868 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1869 if (compose->toolbar->draft_btn )
1870 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1871 if (compose->toolbar->insert_btn )
1872 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1873 if (compose->toolbar->attach_btn)
1874 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1875 if (compose->toolbar->sig_btn)
1876 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1877 if (compose->toolbar->exteditor_btn)
1878 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1879 if (compose->toolbar->linewrap_btn)
1880 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
1881 if (compose->toolbar->addrbook_btn)
1882 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1883 for (; items != NULL; items = g_slist_next(items)) {
1884 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1885 gtk_widget_set_sensitive(item->widget, sensitive);
1890 * Initialize toolbar structure
1892 void toolbar_init(Toolbar * toolbar) {
1894 toolbar->toolbar = NULL;
1895 toolbar->get_btn = NULL;
1896 toolbar->getall_btn = NULL;
1897 toolbar->send_btn = NULL;
1898 toolbar->compose_mail_btn = NULL;
1899 toolbar->compose_news_btn = NULL;
1900 toolbar->reply_btn = NULL;
1901 toolbar->replysender_btn = NULL;
1902 toolbar->replyall_btn = NULL;
1903 toolbar->replylist_btn = NULL;
1904 toolbar->fwd_btn = NULL;
1905 toolbar->delete_btn = NULL;
1906 toolbar->next_btn = NULL;
1907 toolbar->exec_btn = NULL;
1909 /* compose buttons */
1910 toolbar->sendl_btn = NULL;
1911 toolbar->draft_btn = NULL;
1912 toolbar->insert_btn = NULL;
1913 toolbar->attach_btn = NULL;
1914 toolbar->sig_btn = NULL;
1915 toolbar->exteditor_btn = NULL;
1916 toolbar->linewrap_btn = NULL;
1917 toolbar->addrbook_btn = NULL;
1919 toolbar_destroy(toolbar);
1924 static void toolbar_reply(gpointer data, guint action)
1926 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1927 MainWindow *mainwin;
1928 MessageView *msgview;
1929 GSList *msginfo_list = NULL;
1932 g_return_if_fail(toolbar_item != NULL);
1934 switch (toolbar_item->type) {
1936 mainwin = (MainWindow*)toolbar_item->parent;
1937 msginfo_list = summary_get_selection(mainwin->summaryview);
1938 msgview = (MessageView*)mainwin->messageview;
1940 case TOOLBAR_MSGVIEW:
1941 msgview = (MessageView*)toolbar_item->parent;
1942 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
1948 g_return_if_fail(msgview != NULL);
1949 body = messageview_get_selection(msgview);
1951 g_return_if_fail(msginfo_list != NULL);
1952 compose_reply_mode((ComposeMode)action, msginfo_list, body);
1955 g_slist_free(msginfo_list);
1957 /* TODO: update reply state ion summaryview */
1961 /* exported functions */
1963 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
1965 MainWindow *mainwin = (MainWindow*)data;
1967 inc_mail(mainwin, prefs_common.newmail_notify_manu);
1970 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
1972 MainWindow *mainwin = (MainWindow*)data;
1974 inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
1977 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
1981 if (prefs_common.work_offline)
1982 if (alertpanel(_("Offline warning"),
1983 _("You're working offline. Override?"),
1984 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1987 for (list = folder_get_list(); list != NULL; list = list->next) {
1988 Folder *folder = list->data;
1990 if (folder->queue) {
1991 if (procmsg_send_queue
1992 (folder->queue, prefs_common.savemsg) < 0)
1993 alertpanel_error(_("Some errors occurred while sending queued messages."));
1994 folder_item_scan(folder->queue);
1999 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2001 MainWindow *mainwin = (MainWindow*)data;
2002 PrefsAccount *ac = NULL;
2003 FolderItem *item = mainwin->summaryview->folder_item;
2008 ac = account_find_from_item(item);
2009 if (ac && ac->protocol != A_NNTP) {
2010 compose_new_with_folderitem(ac, item); /* CLAWS */
2016 * CLAWS - use current account
2018 if (cur_account && (cur_account->protocol != A_NNTP)) {
2019 compose_new_with_folderitem(cur_account, item);
2024 * CLAWS - just get the first one
2026 list = account_get_list();
2027 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2028 ac = (PrefsAccount *) cur->data;
2029 if (ac->protocol != A_NNTP) {
2030 compose_new_with_folderitem(ac, item);
2036 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2038 MainWindow *mainwin = (MainWindow*)data;
2039 PrefsAccount * ac = NULL;
2043 if (mainwin->summaryview->folder_item) {
2044 ac = mainwin->summaryview->folder_item->folder->account;
2045 if (ac && ac->protocol == A_NNTP) {
2047 mainwin->summaryview->folder_item->path,
2053 list = account_get_list();
2054 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2055 ac = (PrefsAccount *) cur->data;
2056 if (ac->protocol == A_NNTP) {
2057 compose_new(ac, NULL, NULL);