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"
54 #include "prefs_actions.h"
55 #include "prefs_common.h"
56 #include "prefs_toolbar.h"
57 #include "alertpanel.h"
60 #define TOOLBAR_TAG_INDEX "toolbar"
61 #define TOOLBAR_TAG_ITEM "item"
62 #define TOOLBAR_TAG_SEPARATOR "separator"
64 #define TOOLBAR_ICON_FILE "file"
65 #define TOOLBAR_ICON_TEXT "text"
66 #define TOOLBAR_ICON_ACTION "action"
68 gboolean toolbar_is_duplicate (gint action,
70 static void toolbar_parse_item (XMLFile *file,
73 static gint toolbar_ret_val_from_text (const gchar *text);
74 static gchar *toolbar_ret_text_from_val (gint val);
76 static void toolbar_set_default_main (void);
77 static void toolbar_set_default_compose (void);
78 static void toolbar_set_default_msgview (void);
80 static void toolbar_style (ToolbarType type,
84 static GtkWidget *get_window_widget (ToolbarType type,
86 static MainWindow *get_mainwin (gpointer data);
87 static void activate_compose_button (Toolbar *toolbar,
89 ComposeButtonType type);
91 /* toolbar callbacks */
92 static void toolbar_reply (gpointer data,
94 static void toolbar_delete_cb (GtkWidget *widget,
97 static void toolbar_compose_cb (GtkWidget *widget,
100 static void toolbar_reply_cb (GtkWidget *widget,
103 static void toolbar_reply_to_all_cb (GtkWidget *widget,
106 static void toolbar_reply_to_list_cb (GtkWidget *widget,
109 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
112 static void toolbar_forward_cb (GtkWidget *widget,
115 static void toolbar_next_unread_cb (GtkWidget *widget,
118 static void toolbar_ignore_thread_cb (GtkWidget *widget,
121 static void toolbar_print_cb (GtkWidget *widget,
124 static void toolbar_actions_execute_cb (GtkWidget *widget,
128 static void toolbar_send_cb (GtkWidget *widget,
130 static void toolbar_send_later_cb (GtkWidget *widget,
132 static void toolbar_draft_cb (GtkWidget *widget,
134 static void toolbar_insert_cb (GtkWidget *widget,
136 static void toolbar_attach_cb (GtkWidget *widget,
138 static void toolbar_sig_cb (GtkWidget *widget,
140 static void toolbar_ext_editor_cb (GtkWidget *widget,
142 static void toolbar_linewrap_cb (GtkWidget *widget,
144 static void toolbar_addrbook_cb (GtkWidget *widget,
147 static void toolbar_popup_cb (gpointer data,
153 } toolbar_text [] = {
154 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
155 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
156 { "A_SEND_QUEUED", N_("Send Queued Message(s)") },
157 { "A_COMPOSE_EMAIL", N_("Compose Email") },
158 { "A_COMPOSE_NEWS", N_("Compose News") },
159 { "A_REPLY_MESSAGE", N_("Reply to Message") },
160 { "A_REPLY_SENDER", N_("Reply to Sender") },
161 { "A_REPLY_ALL", N_("Reply to All") },
162 { "A_REPLY_ML", N_("Reply to Mailing-list") },
163 { "A_FORWARD", N_("Forward Message") },
164 { "A_DELETE", N_("Delete Message") },
165 { "A_EXECUTE", N_("Execute") },
166 { "A_GOTO_NEXT", N_("Goto Next Message") },
167 { "A_IGNORE_THREAD", N_("Ignore thread") },
168 { "A_PRINT", N_("Print") },
170 { "A_SEND", N_("Send Message") },
171 { "A_SENDL", N_("Put into queue folder and send later") },
172 { "A_DRAFT", N_("Save to draft folder") },
173 { "A_INSERT", N_("Insert file") },
174 { "A_ATTACH", N_("Attach file") },
175 { "A_SIG", N_("Insert signature") },
176 { "A_EXTEDITOR", N_("Edit with external editor") },
177 { "A_LINEWRAP", N_("Wrap all long lines") },
178 { "A_ADDRBOOK", N_("Address book") },
180 { "A_SYL_ACTIONS", N_("Sylpheed Actions Feature") },
181 { "A_SEPARATOR", "Separator" }
184 /* struct holds configuration files and a list of
185 * currently active toolbar items
186 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
190 const gchar *conf_file;
192 } toolbar_config[3] = {
193 { "toolbar_main.xml", NULL},
194 { "toolbar_compose.xml", NULL},
195 { "toolbar_msgview.xml", NULL}
198 static GtkItemFactoryEntry reply_popup_entries[] =
200 {N_("/Reply with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
201 {N_("/_Reply without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
203 static GtkItemFactoryEntry replyall_popup_entries[] =
205 {N_("/Reply to all with _quote"), "<shift>A", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
206 {N_("/_Reply to all without quote"), "a", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
208 static GtkItemFactoryEntry replylist_popup_entries[] =
210 {N_("/Reply to list with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
211 {N_("/_Reply to list without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
213 static GtkItemFactoryEntry replysender_popup_entries[] =
215 {N_("/Reply to sender with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
216 {N_("/_Reply to sender without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
218 static GtkItemFactoryEntry fwd_popup_entries[] =
220 {N_("/_Forward message (inline style)"), "f", toolbar_popup_cb, COMPOSE_FORWARD_INLINE, NULL},
221 {N_("/Forward message as _attachment"), "<shift>F", toolbar_popup_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
225 gint toolbar_ret_val_from_descr(const gchar *descr)
229 for (i = 0; i < N_ACTION_VAL; i++) {
230 if (g_strcasecmp(gettext(toolbar_text[i].descr), descr) == 0)
237 gchar *toolbar_ret_descr_from_val(gint val)
239 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
241 return gettext(toolbar_text[val].descr);
244 static gint toolbar_ret_val_from_text(const gchar *text)
248 for (i = 0; i < N_ACTION_VAL; i++) {
249 if (g_strcasecmp(toolbar_text[i].index_str, text) == 0)
256 static gchar *toolbar_ret_text_from_val(gint val)
258 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
260 return toolbar_text[val].index_str;
263 gboolean toolbar_is_duplicate(gint action, ToolbarType source)
267 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
270 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
271 ToolbarItem *item = (ToolbarItem*) cur->data;
273 if (item->index == action)
279 /* depending on toolbar type this function
280 returns a list of available toolbar events being
281 displayed by prefs_toolbar
283 GList *toolbar_get_action_items(ToolbarType source)
288 if (source == TOOLBAR_MAIN) {
289 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
290 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
291 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
292 A_DELETE, A_EXECUTE, A_GOTO_NEXT,
293 A_IGNORE_THREAD, A_PRINT,
294 A_ADDRBOOK, A_SYL_ACTIONS };
296 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
297 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
298 if (main_items[i] == A_PRINT) {
299 g_print("$$$ descr %s, trans %s\n",
300 toolbar_text[main_items[i]].descr,
301 gettext(toolbar_text[main_items[i]].descr));
305 else if (source == TOOLBAR_COMPOSE) {
306 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
307 A_INSERT, A_ATTACH, A_SIG,
308 A_EXTEDITOR, A_LINEWRAP, A_ADDRBOOK,
311 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
312 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
314 else if (source == TOOLBAR_MSGVIEW) {
315 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
316 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
317 A_DELETE, A_GOTO_NEXT, A_ADDRBOOK,
320 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
321 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
327 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
331 ToolbarItem *item = NULL;
333 attr = xml_get_current_tag_attr(file);
334 item = g_new0(ToolbarItem, 1);
336 name = ((XMLAttr *)attr->data)->name;
337 value = ((XMLAttr *)attr->data)->value;
339 if (g_strcasecmp(name, TOOLBAR_ICON_FILE) == 0)
340 item->file = g_strdup (value);
341 else if (g_strcasecmp(name, TOOLBAR_ICON_TEXT) == 0)
342 item->text = g_strdup (value);
343 else if (g_strcasecmp(name, TOOLBAR_ICON_ACTION) == 0)
344 item->index = toolbar_ret_val_from_text(value);
346 attr = g_list_next(attr);
348 if (item->index != -1) {
350 if (!toolbar_is_duplicate(item->index, source))
351 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
356 static void toolbar_set_default_main(void)
362 } default_toolbar[] = {
363 { A_RECEIVE_CUR, STOCK_PIXMAP_MAIL_RECEIVE, _("Get") },
364 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get All") },
365 { A_SEPARATOR, 0, ("") },
366 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
367 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Email") },
368 { A_SEPARATOR, 0, ("") },
369 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
370 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
371 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
372 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
373 { A_SEPARATOR, 0, ("") },
374 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
375 { A_EXECUTE, STOCK_PIXMAP_EXEC, _("Execute") },
376 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
381 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
383 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
385 if (default_toolbar[i].action != A_SEPARATOR) {
387 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
389 toolbar_item->file = g_strdup(file);
390 toolbar_item->index = default_toolbar[i].action;
391 toolbar_item->text = g_strdup(default_toolbar[i].text);
394 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
395 toolbar_item->index = A_SEPARATOR;
398 if (toolbar_item->index != -1) {
399 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
400 toolbar_config[TOOLBAR_MAIN].item_list =
401 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
406 static void toolbar_set_default_compose(void)
412 } default_toolbar[] = {
413 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
414 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
415 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
416 { A_SEPARATOR, 0, ("") },
417 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
418 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
419 { A_SIG, STOCK_PIXMAP_MAIL_SIGN, _("Signature") },
420 { A_SEPARATOR, 0, ("") },
421 { A_EXTEDITOR, STOCK_PIXMAP_EDIT_EXTERN, _("Editor") },
422 { A_LINEWRAP, STOCK_PIXMAP_LINEWRAP, _("Linewrap") },
423 { A_SEPARATOR, 0, ("") },
424 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
429 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
431 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
433 if (default_toolbar[i].action != A_SEPARATOR) {
435 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
437 toolbar_item->file = g_strdup(file);
438 toolbar_item->index = default_toolbar[i].action;
439 toolbar_item->text = g_strdup(default_toolbar[i].text);
442 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
443 toolbar_item->index = A_SEPARATOR;
446 if (toolbar_item->index != -1) {
447 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
448 toolbar_config[TOOLBAR_COMPOSE].item_list =
449 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
454 static void toolbar_set_default_msgview(void)
460 } default_toolbar[] = {
461 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
462 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
463 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
464 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
465 { A_SEPARATOR, 0, ("") },
466 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
467 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
472 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
474 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
476 if (default_toolbar[i].action != A_SEPARATOR) {
478 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
480 toolbar_item->file = g_strdup(file);
481 toolbar_item->index = default_toolbar[i].action;
482 toolbar_item->text = g_strdup(default_toolbar[i].text);
485 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
486 toolbar_item->index = A_SEPARATOR;
489 if (toolbar_item->index != -1) {
490 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
491 toolbar_config[TOOLBAR_MSGVIEW].item_list =
492 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
497 void toolbar_set_default(ToolbarType source)
499 if (source == TOOLBAR_MAIN)
500 toolbar_set_default_main();
501 else if (source == TOOLBAR_COMPOSE)
502 toolbar_set_default_compose();
503 else if (source == TOOLBAR_MSGVIEW)
504 toolbar_set_default_msgview();
507 void toolbar_save_config_file(ToolbarType source)
512 gchar *fileSpec = NULL;
514 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
516 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
517 pfile = prefs_write_open(fileSpec);
521 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
522 conv_get_current_charset_str());
524 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
526 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
527 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
529 if (toolbar_item->index != A_SEPARATOR)
530 fprintf(fp, "\t<%s %s=\"%s\" %s=\"%s\" %s=\"%s\"/>\n",
532 TOOLBAR_ICON_FILE, toolbar_item->file,
533 TOOLBAR_ICON_TEXT, toolbar_item->text,
535 toolbar_ret_text_from_val(toolbar_item->index));
537 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
540 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
542 if (prefs_file_close (pfile) < 0 )
543 g_warning("failed to write toolbar configuration to file\n");
545 g_warning("failed to open toolbar configuration file for writing\n");
548 void toolbar_read_config_file(ToolbarType source)
550 XMLFile *file = NULL;
551 gchar *fileSpec = NULL;
556 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
558 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
559 file = xml_open_file(fileSpec);
562 toolbar_clear_list(source);
566 || (xml_get_dtd(file))
567 || (xml_parse_next_tag(file))
568 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
569 xml_close_file(file);
573 attr = xml_get_current_tag_attr(file);
580 if (xml_parse_next_tag(file))
583 /* Get next tag (icon, icon_text or icon_action) */
584 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
585 toolbar_parse_item(file, source);
586 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
587 ToolbarItem *item = g_new0(ToolbarItem, 1);
589 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
590 item->index = A_SEPARATOR;
591 toolbar_config[source].item_list =
592 g_slist_append(toolbar_config[source].item_list, item);
596 xml_close_file(file);
599 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
601 if (source == TOOLBAR_MAIN)
602 toolbar_set_default(TOOLBAR_MAIN);
603 else if (source == TOOLBAR_COMPOSE)
604 toolbar_set_default(TOOLBAR_COMPOSE);
605 else if (source == TOOLBAR_MSGVIEW)
606 toolbar_set_default(TOOLBAR_MSGVIEW);
608 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
612 toolbar_save_config_file(source);
617 * clears list of toolbar items read from configuration files
619 void toolbar_clear_list(ToolbarType source)
621 while (toolbar_config[source].item_list != NULL) {
622 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
624 toolbar_config[source].item_list =
625 g_slist_remove(toolbar_config[source].item_list, item);
633 g_slist_free(toolbar_config[source].item_list);
638 * return list of Toolbar items
640 GSList *toolbar_get_list(ToolbarType source)
644 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
645 list = toolbar_config[source].item_list;
650 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
652 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
654 toolbar_item->file = g_strdup(t_item->file);
655 toolbar_item->text = g_strdup(t_item->text);
656 toolbar_item->index = t_item->index;
658 toolbar_config[source].item_list =
659 g_slist_append(toolbar_config[source].item_list,
663 void toolbar_action_execute(GtkWidget *widget,
669 gchar *action, *action_p;
670 gboolean found = FALSE;
673 for (cur = action_list; cur != NULL; cur = cur->next) {
674 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
676 if (widget == act->widget) {
678 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
679 action = g_strdup((gchar*)lop->data);
681 action_p = strstr(action, ": ");
683 if (g_strcasecmp(act->name, action) == 0) {
697 actions_execute(data, i, widget, source);
699 g_warning ("Error: did not find Sylpheed Action to execute");
702 static void activate_compose_button (Toolbar *toolbar,
704 ComposeButtonType type)
706 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
709 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
710 : toolbar->compose_news_btn);
711 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
712 : toolbar->compose_mail_btn);
713 toolbar->compose_btn_type = type;
716 void toolbar_set_compose_button(Toolbar *toolbar,
717 ComposeButtonType compose_btn_type)
719 if (toolbar->compose_btn_type != compose_btn_type)
720 activate_compose_button(toolbar,
721 prefs_common.toolbar_style,
725 void toolbar_toggle(guint action, gpointer data)
727 MainWindow *mainwin = (MainWindow*)data;
731 g_return_if_fail(mainwin != NULL);
733 toolbar_style(TOOLBAR_MAIN, action, mainwin);
735 list = compose_get_compose_list();
736 for (cur = list; cur != NULL; cur = cur->next) {
737 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
739 list = messageview_get_msgview_list();
740 for (cur = list; cur != NULL; cur = cur->next) {
741 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
746 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
748 switch ((ToolbarStyle)action) {
750 gtk_widget_hide(handlebox_wid);
753 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
757 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
761 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
768 prefs_common.toolbar_style = (ToolbarStyle)action;
769 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
770 gtk_widget_show(handlebox_wid);
771 gtk_widget_queue_resize(handlebox_wid);
775 * Change the style of toolbar
777 static void toolbar_style(ToolbarType type, guint action, gpointer data)
779 GtkWidget *handlebox_wid;
780 GtkWidget *toolbar_wid;
781 MainWindow *mainwin = (MainWindow*)data;
782 Compose *compose = (Compose*)data;
783 MessageView *msgview = (MessageView*)data;
785 g_return_if_fail(data != NULL);
789 handlebox_wid = mainwin->handlebox;
790 toolbar_wid = mainwin->toolbar->toolbar;
792 case TOOLBAR_COMPOSE:
793 handlebox_wid = compose->handlebox;
794 toolbar_wid = compose->toolbar->toolbar;
796 case TOOLBAR_MSGVIEW:
797 handlebox_wid = msgview->handlebox;
798 toolbar_wid = msgview->toolbar->toolbar;
804 toolbar_set_style(toolbar_wid, handlebox_wid, action);
807 /* Toolbar handling */
808 static void toolbar_inc_cb(GtkWidget *widget,
811 ToolbarItem *toolbar_item = (ToolbarItem*)data;
814 g_return_if_fail(toolbar_item != NULL);
816 switch (toolbar_item->type) {
818 mainwin = (MainWindow*)toolbar_item->parent;
819 inc_mail_cb(mainwin, 0, NULL);
826 static void toolbar_inc_all_cb(GtkWidget *widget,
829 ToolbarItem *toolbar_item = (ToolbarItem*)data;
832 g_return_if_fail(toolbar_item != NULL);
834 switch (toolbar_item->type) {
836 mainwin = (MainWindow*)toolbar_item->parent;
837 inc_all_account_mail_cb(mainwin, 0, NULL);
844 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
846 ToolbarItem *toolbar_item = (ToolbarItem*)data;
849 g_return_if_fail(toolbar_item != NULL);
851 switch (toolbar_item->type) {
853 mainwin = (MainWindow*)toolbar_item->parent;
854 send_queue_cb(mainwin, 0, NULL);
861 static void toolbar_exec_cb(GtkWidget *widget,
864 MainWindow *mainwin = get_mainwin(data);
866 g_return_if_fail(mainwin != NULL);
867 summary_execute(mainwin->summaryview);
872 /* popup callback functions */
873 static void toolbar_reply_popup_cb(GtkWidget *widget,
874 GdkEventButton *event,
877 Toolbar *toolbar_data = (Toolbar*)data;
881 if (event->button == 3) {
882 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
883 gtk_menu_popup(GTK_MENU(toolbar_data->reply_popup), NULL, NULL,
884 menu_button_position, widget,
885 event->button, event->time);
889 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
891 ToolbarItem *toolbar_item = (ToolbarItem*)data;
893 GtkWidget *reply_btn;
895 MessageView *msgview;
897 g_return_if_fail(toolbar_item != NULL);
899 switch(toolbar_item->type) {
901 mainwin = (MainWindow*)toolbar_item->parent;
902 reply_btn = mainwin->toolbar->reply_btn;
903 window = mainwin->window;
905 case TOOLBAR_MSGVIEW:
906 msgview = (MessageView*)toolbar_item->parent;
907 reply_btn = msgview->toolbar->reply_btn;
908 window = msgview->window;
914 gtk_button_set_relief(GTK_BUTTON(reply_btn), GTK_RELIEF_NONE);
915 manage_window_focus_in(window, NULL, NULL);
918 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
920 Toolbar *toolbar_data = (Toolbar*)data;
924 if (event->button == 3) {
925 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
926 gtk_menu_popup(GTK_MENU(toolbar_data->replyall_popup), NULL, NULL,
927 menu_button_position, widget,
928 event->button, event->time);
932 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
934 ToolbarItem *toolbar_item = (ToolbarItem*)data;
936 GtkWidget *replyall_btn;
938 MessageView *msgview;
940 g_return_if_fail(toolbar_item != NULL);
942 switch(toolbar_item->type) {
944 mainwin = (MainWindow*)toolbar_item->parent;
945 replyall_btn = mainwin->toolbar->replyall_btn;
946 window = mainwin->window;
948 case TOOLBAR_MSGVIEW:
949 msgview = (MessageView*)toolbar_item->parent;
950 replyall_btn = msgview->toolbar->replyall_btn;
951 window = msgview->window;
957 gtk_button_set_relief(GTK_BUTTON(replyall_btn), GTK_RELIEF_NONE);
958 manage_window_focus_in(window, NULL, NULL);
961 static void toolbar_reply_to_list_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
963 Toolbar *toolbar_data = (Toolbar*)data;
965 if (event->button == 3) {
966 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
967 gtk_menu_popup(GTK_MENU(toolbar_data->replylist_popup), NULL, NULL,
968 menu_button_position, widget,
969 event->button, event->time);
973 static void toolbar_reply_to_list_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
975 ToolbarItem *toolbar_item = (ToolbarItem*)data;
976 gpointer parent = toolbar_item->parent;
978 GtkWidget *replylist_btn;
981 g_return_if_fail(toolbar_item != NULL);
983 switch(toolbar_item->type) {
985 replylist_btn = ((MainWindow*)parent)->toolbar->replylist_btn;
986 window = ((MainWindow*)parent)->window;
988 case TOOLBAR_MSGVIEW:
989 replylist_btn = ((MessageView*)parent)->toolbar->replylist_btn;
990 window = ((MessageView*)parent)->window;
996 gtk_button_set_relief(GTK_BUTTON(replylist_btn), GTK_RELIEF_NONE);
997 manage_window_focus_in(window, NULL, NULL);
1000 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1002 Toolbar *toolbar_data = (Toolbar*)data;
1004 if (event->button == 3) {
1005 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1006 gtk_menu_popup(GTK_MENU(toolbar_data->replysender_popup), NULL, NULL,
1007 menu_button_position, widget,
1008 event->button, event->time);
1012 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
1014 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1015 gpointer parent = toolbar_item->parent;
1017 GtkWidget *replysender_btn;
1019 g_return_if_fail(toolbar_item != NULL);
1021 switch(toolbar_item->type) {
1023 replysender_btn = ((MainWindow*)parent)->toolbar->replysender_btn;
1024 window = ((MainWindow*)parent)->window;
1026 case TOOLBAR_MSGVIEW:
1027 replysender_btn = ((MessageView*)parent)->toolbar->replysender_btn;
1028 window = ((MessageView*)parent)->window;
1034 gtk_button_set_relief(GTK_BUTTON(replysender_btn), GTK_RELIEF_NONE);
1035 manage_window_focus_in(window, NULL, NULL);
1038 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1040 Toolbar *toolbar_data = (Toolbar*)data;
1042 if (event->button == 3) {
1043 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1044 gtk_menu_popup(GTK_MENU(toolbar_data->fwd_popup), NULL, NULL,
1045 menu_button_position, widget,
1046 event->button, event->time);
1050 static void toolbar_forward_popup_closed_cb (GtkMenuShell *menu_shell,
1053 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1054 gpointer parent = toolbar_item->parent;
1058 g_return_if_fail(toolbar_item != NULL);
1060 switch(toolbar_item->type) {
1062 fwd_btn = ((MainWindow*)parent)->toolbar->fwd_btn;
1063 window = ((MainWindow*)parent)->window;
1065 case TOOLBAR_MSGVIEW:
1066 fwd_btn = ((MessageView*)parent)->toolbar->fwd_btn;
1067 window = ((MessageView*)parent)->window;
1073 gtk_button_set_relief(GTK_BUTTON(fwd_btn), GTK_RELIEF_NONE);
1074 manage_window_focus_in(window, NULL, NULL);
1078 * Delete current/selected(s) message(s)
1080 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1082 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1083 MainWindow *mainwin;
1084 MessageView *msgview;
1086 g_return_if_fail(toolbar_item != NULL);
1088 switch (toolbar_item->type) {
1089 case TOOLBAR_MSGVIEW:
1090 msgview = (MessageView*)toolbar_item->parent;
1091 messageview_delete(msgview);
1094 mainwin = (MainWindow*)toolbar_item->parent;
1095 summary_delete(mainwin->summaryview);
1098 debug_print("toolbar event not supported\n");
1105 * Compose new message
1107 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1109 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1110 MainWindow *mainwin;
1111 MessageView *msgview;
1113 g_return_if_fail(toolbar_item != NULL);
1115 switch (toolbar_item->type) {
1117 mainwin = (MainWindow*)toolbar_item->parent;
1118 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1119 compose_news_cb(mainwin, 0, NULL);
1121 compose_mail_cb(mainwin, 0, NULL);
1123 case TOOLBAR_MSGVIEW:
1124 msgview = (MessageView*)toolbar_item->parent;
1125 compose_new_with_folderitem(NULL,
1126 msgview->msginfo->folder);
1129 debug_print("toolbar event not supported\n");
1133 static void toolbar_popup_cb(gpointer data, guint action, GtkWidget *widget)
1135 toolbar_reply(data, action);
1142 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1144 toolbar_reply(data, prefs_common.reply_with_quote ?
1145 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1150 * Reply message to Sender and All recipients
1152 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1155 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1156 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1161 * Reply to Mailing List
1163 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1166 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1167 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1172 * Reply to sender of message
1174 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1177 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1178 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1184 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1186 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1189 g_return_if_fail(toolbar_item != NULL);
1191 switch (toolbar_item->type) {
1193 case TOOLBAR_MSGVIEW:
1196 case TOOLBAR_COMPOSE:
1197 compose = (Compose *)toolbar_item->parent;
1202 addressbook_open(compose);
1207 * Forward current/selected(s) message(s)
1209 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1211 toolbar_reply(data, COMPOSE_FORWARD);
1216 * Goto Next Unread Message
1218 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1220 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1221 MainWindow *mainwin;
1222 MessageView *msgview;
1224 g_return_if_fail(toolbar_item != NULL);
1226 switch (toolbar_item->type) {
1228 mainwin = (MainWindow*)toolbar_item->parent;
1229 summary_select_next_unread(mainwin->summaryview);
1232 case TOOLBAR_MSGVIEW:
1233 msgview = (MessageView*)toolbar_item->parent;
1234 summary_select_next_unread(msgview->mainwin->summaryview);
1236 /* Now we need to update the messageview window */
1237 if (msgview->mainwin->summaryview->selected) {
1238 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1240 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1241 msgview->mainwin->summaryview->selected);
1243 messageview_show(msgview, msginfo,
1244 msgview->all_headers);
1246 gtk_widget_destroy(msgview->window);
1250 debug_print("toolbar event not supported\n");
1254 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1256 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1257 MainWindow *mainwin;
1259 g_return_if_fail(toolbar_item != NULL);
1261 switch (toolbar_item->type) {
1263 mainwin = (MainWindow *) toolbar_item->parent;
1264 summary_toggle_ignore_thread(mainwin->summaryview);
1266 case TOOLBAR_MSGVIEW:
1267 /* TODO: see toolbar_next_unread_cb() if you need
1268 * this in the message view */
1271 debug_print("toolbar event not supported\n");
1276 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1278 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1279 MainWindow *mainwin;
1281 g_return_if_fail(toolbar_item != NULL);
1283 switch (toolbar_item->type) {
1285 mainwin = (MainWindow *) toolbar_item->parent;
1286 summary_print(mainwin->summaryview);
1288 case TOOLBAR_MSGVIEW:
1289 /* TODO: see toolbar_next_unread_cb() if you need
1290 * this in the message view */
1293 debug_print("toolbar event not supported\n");
1298 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1300 compose_toolbar_cb(A_SEND, data);
1303 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1305 compose_toolbar_cb(A_SENDL, data);
1308 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1310 compose_toolbar_cb(A_DRAFT, data);
1313 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1315 compose_toolbar_cb(A_INSERT, data);
1318 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1320 compose_toolbar_cb(A_ATTACH, data);
1323 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1325 compose_toolbar_cb(A_SIG, data);
1328 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1330 compose_toolbar_cb(A_EXTEDITOR, data);
1333 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
1335 compose_toolbar_cb(A_LINEWRAP, data);
1339 * Execute actions from toolbar
1341 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1343 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1344 GSList *action_list;
1345 MainWindow *mainwin;
1347 MessageView *msgview;
1348 gpointer parent = toolbar_item->parent;
1350 g_return_if_fail(toolbar_item != NULL);
1352 switch (toolbar_item->type) {
1354 mainwin = (MainWindow*)parent;
1355 action_list = mainwin->toolbar->action_list;
1357 case TOOLBAR_COMPOSE:
1358 compose = (Compose*)parent;
1359 action_list = compose->toolbar->action_list;
1361 case TOOLBAR_MSGVIEW:
1362 msgview = (MessageView*)parent;
1363 action_list = msgview->toolbar->action_list;
1366 debug_print("toolbar event not supported\n");
1369 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1372 static MainWindow *get_mainwin(gpointer data)
1374 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1375 MainWindow *mainwin = NULL;
1376 MessageView *msgview;
1378 g_return_val_if_fail(toolbar_item != NULL, NULL);
1380 switch(toolbar_item->type) {
1382 mainwin = (MainWindow*)toolbar_item->parent;
1384 case TOOLBAR_MSGVIEW:
1385 msgview = (MessageView*)toolbar_item->parent;
1386 mainwin = (MainWindow*)msgview->mainwin;
1395 static GtkWidget *get_window_widget(ToolbarType type, gpointer data)
1397 MainWindow *mainwin;
1398 MessageView *msgview;
1402 mainwin = (MainWindow*)data;
1403 return mainwin->window;
1405 case TOOLBAR_MSGVIEW:
1406 msgview = (MessageView*)data;
1407 return msgview->vbox;
1415 static void toolbar_buttons_cb(GtkWidget *widget,
1422 void (*func)(GtkWidget *widget, gpointer data);
1424 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1425 { A_RECEIVE_CUR, toolbar_inc_cb },
1426 { A_SEND_QUEUED, toolbar_send_queued_cb },
1427 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1428 { A_COMPOSE_NEWS, toolbar_compose_cb },
1429 { A_REPLY_MESSAGE, toolbar_reply_cb },
1430 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1431 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1432 { A_REPLY_ML, toolbar_reply_to_list_cb },
1433 { A_FORWARD, toolbar_forward_cb },
1434 { A_DELETE, toolbar_delete_cb },
1435 { A_EXECUTE, toolbar_exec_cb },
1436 { A_GOTO_NEXT, toolbar_next_unread_cb },
1437 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1438 { A_PRINT, toolbar_print_cb },
1440 { A_SEND, toolbar_send_cb },
1441 { A_SENDL, toolbar_send_later_cb },
1442 { A_DRAFT, toolbar_draft_cb },
1443 { A_INSERT, toolbar_insert_cb },
1444 { A_ATTACH, toolbar_attach_cb },
1445 { A_SIG, toolbar_sig_cb },
1446 { A_EXTEDITOR, toolbar_ext_editor_cb },
1447 { A_LINEWRAP, toolbar_linewrap_cb },
1448 { A_ADDRBOOK, toolbar_addrbook_cb },
1450 { A_SYL_ACTIONS, toolbar_actions_execute_cb }
1453 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1455 for (i = 0; i < num_items; i++) {
1456 if (callbacks[i].index == item->index) {
1457 callbacks[i].func(widget, item);
1464 * Create a new toolbar with specified type
1465 * if a callback list is passed it will be used before the
1466 * common callback list
1468 Toolbar *toolbar_create(ToolbarType type,
1469 GtkWidget *container,
1472 ToolbarItem *toolbar_item;
1475 GtkWidget *icon_wid = NULL;
1476 GtkWidget *icon_news;
1478 GtkWidget *item_news;
1479 GtkWidget *window_wid;
1481 guint n_menu_entries;
1482 GtkWidget *reply_popup;
1483 GtkWidget *replyall_popup;
1484 GtkWidget *replylist_popup;
1485 GtkWidget *replysender_popup;
1486 GtkWidget *fwd_popup;
1488 GtkTooltips *toolbar_tips;
1489 ToolbarSylpheedActions *action_item;
1491 GSList *toolbar_list;
1492 Toolbar *toolbar_data;
1495 toolbar_tips = gtk_tooltips_new();
1497 toolbar_read_config_file(type);
1498 toolbar_list = toolbar_get_list(type);
1500 toolbar_data = g_new0(Toolbar, 1);
1502 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1504 gtk_container_add(GTK_CONTAINER(container), toolbar);
1505 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1506 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1507 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1508 GTK_TOOLBAR_SPACE_LINE);
1510 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1512 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1513 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1517 toolbar_item = g_new0(ToolbarItem, 1);
1518 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1519 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1520 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1521 toolbar_item->parent = data;
1522 toolbar_item->type = type;
1524 /* collect toolbar items in list to keep track */
1525 toolbar_data->item_list =
1526 g_slist_append(toolbar_data->item_list,
1529 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1530 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1534 icon_wid, toolbar_buttons_cb,
1537 switch (toolbar_item->index) {
1540 toolbar_data->getall_btn = item;
1541 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1542 toolbar_data->getall_btn,
1543 _("Receive Mail on all Accounts"), NULL);
1546 toolbar_data->get_btn = item;
1547 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1548 toolbar_data->get_btn,
1549 _("Receive Mail on current Account"), NULL);
1552 toolbar_data->send_btn = item;
1553 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1554 toolbar_data->send_btn,
1555 _("Send Queued Message(s)"), NULL);
1557 case A_COMPOSE_EMAIL:
1558 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1559 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1563 icon_news, toolbar_buttons_cb,
1565 toolbar_data->compose_mail_btn = item;
1566 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1567 toolbar_data->compose_mail_btn,
1568 _("Compose Email"), NULL);
1569 toolbar_data->compose_news_btn = item_news;
1570 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1571 toolbar_data->compose_news_btn,
1572 _("Compose News"), NULL);
1574 case A_REPLY_MESSAGE:
1575 toolbar_data->reply_btn = item;
1576 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1577 toolbar_data->reply_btn,
1578 _("Reply to Message"), NULL);
1579 gtk_signal_connect(GTK_OBJECT(toolbar_data->reply_btn),
1580 "button_press_event",
1581 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
1583 n_menu_entries = sizeof(reply_popup_entries) /
1584 sizeof(reply_popup_entries[0]);
1586 window_wid = get_window_widget(type, data);
1587 reply_popup = popupmenu_create(window_wid,
1588 reply_popup_entries, n_menu_entries,
1589 "<ReplyPopup>", (gpointer)toolbar_item);
1591 gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
1592 GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), toolbar_item);
1593 toolbar_data->reply_popup = reply_popup;
1595 case A_REPLY_SENDER:
1596 toolbar_data->replysender_btn = item;
1597 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1598 toolbar_data->replysender_btn,
1599 _("Reply to Sender"), NULL);
1600 gtk_signal_connect(GTK_OBJECT(toolbar_data->replysender_btn),
1601 "button_press_event",
1602 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
1604 n_menu_entries = sizeof(replysender_popup_entries) /
1605 sizeof(replysender_popup_entries[0]);
1607 window_wid = get_window_widget(type, data);
1608 replysender_popup = popupmenu_create(window_wid,
1609 replysender_popup_entries, n_menu_entries,
1610 "<ReplySenderPopup>", (gpointer)toolbar_item);
1612 gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
1613 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), toolbar_item);
1614 toolbar_data->replysender_popup = replysender_popup;
1617 toolbar_data->replyall_btn = item;
1618 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1619 toolbar_data->replyall_btn,
1620 _("Reply to All"), NULL);
1621 gtk_signal_connect(GTK_OBJECT(toolbar_data->replyall_btn),
1622 "button_press_event",
1623 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
1625 n_menu_entries = sizeof(replyall_popup_entries) /
1626 sizeof(replyall_popup_entries[0]);
1628 window_wid = get_window_widget(type, data);
1629 replyall_popup = popupmenu_create(window_wid,
1630 replyall_popup_entries, n_menu_entries,
1631 "<ReplyAllPopup>", (gpointer)toolbar_item);
1633 gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
1634 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), toolbar_item);
1635 toolbar_data->replyall_popup = replyall_popup;
1638 toolbar_data->replylist_btn = item;
1639 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1640 toolbar_data->replylist_btn,
1641 _("Reply to Mailing-list"), NULL);
1642 gtk_signal_connect(GTK_OBJECT(toolbar_data->replylist_btn),
1643 "button_press_event",
1644 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_cb),
1646 n_menu_entries = sizeof(replylist_popup_entries) /
1647 sizeof(replylist_popup_entries[0]);
1649 window_wid = get_window_widget(type, data);
1650 replylist_popup = popupmenu_create(window_wid,
1651 replylist_popup_entries, n_menu_entries,
1652 "<ReplyMlPopup>", (gpointer)toolbar_item);
1654 gtk_signal_connect(GTK_OBJECT(replylist_popup), "selection_done",
1655 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_closed_cb), toolbar_item);
1656 toolbar_data->replylist_popup = replylist_popup;
1659 toolbar_data->fwd_btn = item;
1660 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1661 toolbar_data->fwd_btn,
1662 _("Forward Message"), NULL);
1663 gtk_signal_connect(GTK_OBJECT(toolbar_data->fwd_btn),
1664 "button_press_event",
1665 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
1667 n_menu_entries = sizeof(fwd_popup_entries) /
1668 sizeof(fwd_popup_entries[0]);
1670 window_wid = get_window_widget(type, data);
1671 fwd_popup = popupmenu_create(window_wid,
1672 fwd_popup_entries, n_menu_entries,
1673 "<ForwardPopup>", (gpointer)toolbar_item);
1675 gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
1676 GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), toolbar_item);
1677 toolbar_data->fwd_popup = fwd_popup;
1680 toolbar_data->delete_btn = item;
1681 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1682 toolbar_data->delete_btn,
1683 _("Delete Message"), NULL);
1686 toolbar_data->exec_btn = item;
1687 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1688 toolbar_data->exec_btn,
1689 _("Execute"), NULL);
1692 toolbar_data->next_btn = item;
1693 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1694 toolbar_data->next_btn,
1695 _("Goto Next Message"), NULL);
1698 /* Compose Toolbar */
1700 toolbar_data->send_btn = item;
1701 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1702 toolbar_data->send_btn,
1703 _("Send Message"), NULL);
1706 toolbar_data->sendl_btn = item;
1707 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1708 toolbar_data->sendl_btn,
1709 _("Put into queue folder and send later"), NULL);
1712 toolbar_data->draft_btn = item;
1713 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1714 toolbar_data->draft_btn,
1715 _("Save to draft folder"), NULL);
1718 toolbar_data->insert_btn = item;
1719 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1720 toolbar_data->insert_btn,
1721 _("Insert file"), NULL);
1724 toolbar_data->attach_btn = item;
1725 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1726 toolbar_data->attach_btn,
1727 _("Attach file"), NULL);
1730 toolbar_data->sig_btn = item;
1731 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1732 toolbar_data->sig_btn,
1733 _("Insert signature"), NULL);
1736 toolbar_data->exteditor_btn = item;
1737 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1738 toolbar_data->exteditor_btn,
1739 _("Edit with external editor"), NULL);
1742 toolbar_data->linewrap_btn = item;
1743 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1744 toolbar_data->linewrap_btn,
1745 _("Wrap all long lines"), NULL);
1748 toolbar_data->addrbook_btn = item;
1749 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1750 toolbar_data->addrbook_btn,
1751 _("Address book"), NULL);
1755 action_item = g_new0(ToolbarSylpheedActions, 1);
1756 action_item->widget = item;
1757 action_item->name = g_strdup(toolbar_item->text);
1759 toolbar_data->action_list =
1760 g_slist_append(toolbar_data->action_list,
1763 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1765 action_item->name, NULL);
1767 gtk_widget_show(item);
1770 /* find and set the tool tip text */
1771 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1773 toolbar_ret_descr_from_val
1774 (toolbar_item->index),
1780 toolbar_data->toolbar = toolbar;
1781 if (type == TOOLBAR_MAIN)
1782 activate_compose_button(toolbar_data,
1783 prefs_common.toolbar_style,
1784 toolbar_data->compose_btn_type);
1786 gtk_widget_show_all(toolbar);
1788 return toolbar_data;
1792 * Free toolbar structures
1794 void toolbar_destroy(Toolbar * toolbar) {
1796 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1797 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1800 void toolbar_update(ToolbarType type, gpointer data)
1802 Toolbar *toolbar_data;
1803 GtkWidget *handlebox;
1804 MainWindow *mainwin = (MainWindow*)data;
1805 Compose *compose = (Compose*)data;
1806 MessageView *msgview = (MessageView*)data;
1810 toolbar_data = mainwin->toolbar;
1811 handlebox = mainwin->handlebox;
1813 case TOOLBAR_COMPOSE:
1814 toolbar_data = compose->toolbar;
1815 handlebox = compose->handlebox;
1817 case TOOLBAR_MSGVIEW:
1818 toolbar_data = msgview->toolbar;
1819 handlebox = msgview->handlebox;
1825 gtk_container_remove(GTK_CONTAINER(handlebox),
1826 GTK_WIDGET(toolbar_data->toolbar));
1828 toolbar_init(toolbar_data);
1829 toolbar_data = toolbar_create(type, handlebox, data);
1832 mainwin->toolbar = toolbar_data;
1834 case TOOLBAR_COMPOSE:
1835 compose->toolbar = toolbar_data;
1837 case TOOLBAR_MSGVIEW:
1838 msgview->toolbar = toolbar_data;
1842 toolbar_style(type, prefs_common.toolbar_style, data);
1844 if (type == TOOLBAR_MAIN)
1845 toolbar_main_set_sensitive((MainWindow*)data);
1848 void toolbar_main_set_sensitive(gpointer data)
1850 SensitiveCond state;
1852 MainWindow *mainwin = (MainWindow*)data;
1853 Toolbar *toolbar = mainwin->toolbar;
1855 GSList *entry_list = NULL;
1857 typedef struct _Entry Entry;
1864 #define SET_WIDGET_COND(w, c) \
1866 Entry *e = g_new0(Entry, 1); \
1869 entry_list = g_slist_append(entry_list, e); \
1872 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1873 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1874 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1875 SET_WIDGET_COND(toolbar->reply_btn,
1876 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1877 SET_WIDGET_COND(toolbar->replyall_btn,
1878 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1879 SET_WIDGET_COND(toolbar->replylist_btn,
1880 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1881 SET_WIDGET_COND(toolbar->replysender_btn,
1882 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1883 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1885 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1886 SET_WIDGET_COND(toolbar->delete_btn,
1887 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1888 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1890 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
1891 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1893 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1896 #undef SET_WIDGET_COND
1898 state = main_window_get_current_state(mainwin);
1900 for (cur = entry_list; cur != NULL; cur = cur->next) {
1901 Entry *e = (Entry*) cur->data;
1903 if (e->widget != NULL) {
1904 sensitive = ((e->cond & state) == e->cond);
1905 gtk_widget_set_sensitive(e->widget, sensitive);
1909 while (entry_list != NULL) {
1910 Entry *e = (Entry*) entry_list->data;
1914 entry_list = g_slist_remove(entry_list, e);
1917 g_slist_free(entry_list);
1919 activate_compose_button(toolbar,
1920 prefs_common.toolbar_style,
1921 toolbar->compose_btn_type);
1924 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1926 Compose *compose = (Compose*)data;
1927 GSList *items = compose->toolbar->action_list;
1929 if (compose->toolbar->send_btn)
1930 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1931 if (compose->toolbar->sendl_btn)
1932 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1933 if (compose->toolbar->draft_btn )
1934 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1935 if (compose->toolbar->insert_btn )
1936 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1937 if (compose->toolbar->attach_btn)
1938 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1939 if (compose->toolbar->sig_btn)
1940 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1941 if (compose->toolbar->exteditor_btn)
1942 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1943 if (compose->toolbar->linewrap_btn)
1944 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
1945 if (compose->toolbar->addrbook_btn)
1946 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1947 for (; items != NULL; items = g_slist_next(items)) {
1948 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1949 gtk_widget_set_sensitive(item->widget, sensitive);
1954 * Initialize toolbar structure
1956 void toolbar_init(Toolbar * toolbar) {
1958 toolbar->toolbar = NULL;
1959 toolbar->get_btn = NULL;
1960 toolbar->getall_btn = NULL;
1961 toolbar->send_btn = NULL;
1962 toolbar->compose_mail_btn = NULL;
1963 toolbar->compose_news_btn = NULL;
1964 toolbar->reply_btn = NULL;
1965 toolbar->replysender_btn = NULL;
1966 toolbar->replyall_btn = NULL;
1967 toolbar->replylist_btn = NULL;
1968 toolbar->fwd_btn = NULL;
1969 toolbar->delete_btn = NULL;
1970 toolbar->next_btn = NULL;
1971 toolbar->exec_btn = NULL;
1973 /* compose buttons */
1974 toolbar->sendl_btn = NULL;
1975 toolbar->draft_btn = NULL;
1976 toolbar->insert_btn = NULL;
1977 toolbar->attach_btn = NULL;
1978 toolbar->sig_btn = NULL;
1979 toolbar->exteditor_btn = NULL;
1980 toolbar->linewrap_btn = NULL;
1981 toolbar->addrbook_btn = NULL;
1983 toolbar_destroy(toolbar);
1988 static void toolbar_reply(gpointer data, guint action)
1990 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1991 MainWindow *mainwin;
1992 MessageView *msgview;
1993 GSList *msginfo_list = NULL;
1996 g_return_if_fail(toolbar_item != NULL);
1998 switch (toolbar_item->type) {
2000 mainwin = (MainWindow*)toolbar_item->parent;
2001 msginfo_list = summary_get_selection(mainwin->summaryview);
2002 msgview = (MessageView*)mainwin->messageview;
2004 case TOOLBAR_MSGVIEW:
2005 msgview = (MessageView*)toolbar_item->parent;
2006 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2012 g_return_if_fail(msgview != NULL);
2013 body = messageview_get_selection(msgview);
2015 g_return_if_fail(msginfo_list != NULL);
2016 compose_reply_mode((ComposeMode)action, msginfo_list, body);
2019 g_slist_free(msginfo_list);
2021 /* TODO: update reply state ion summaryview */
2025 /* exported functions */
2027 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2029 MainWindow *mainwin = (MainWindow*)data;
2031 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2034 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2036 MainWindow *mainwin = (MainWindow*)data;
2038 inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
2041 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2045 if (prefs_common.work_offline)
2046 if (alertpanel(_("Offline warning"),
2047 _("You're working offline. Override?"),
2048 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
2051 for (list = folder_get_list(); list != NULL; list = list->next) {
2052 Folder *folder = list->data;
2054 if (folder->queue) {
2055 procmsg_send_queue(folder->queue, prefs_common.savemsg);
2056 folder_item_scan(folder->queue);
2061 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2063 MainWindow *mainwin = (MainWindow*)data;
2064 PrefsAccount *ac = NULL;
2065 FolderItem *item = mainwin->summaryview->folder_item;
2070 ac = account_find_from_item(item);
2071 if (ac && ac->protocol != A_NNTP) {
2072 compose_new_with_folderitem(ac, item); /* CLAWS */
2078 * CLAWS - use current account
2080 if (cur_account && (cur_account->protocol != A_NNTP)) {
2081 compose_new_with_folderitem(cur_account, item);
2086 * CLAWS - just get the first one
2088 list = account_get_list();
2089 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2090 ac = (PrefsAccount *) cur->data;
2091 if (ac->protocol != A_NNTP) {
2092 compose_new_with_folderitem(ac, item);
2098 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2100 MainWindow *mainwin = (MainWindow*)data;
2101 PrefsAccount * ac = NULL;
2105 if (mainwin->summaryview->folder_item) {
2106 ac = mainwin->summaryview->folder_item->folder->account;
2107 if (ac && ac->protocol == A_NNTP) {
2109 mainwin->summaryview->folder_item->path,
2115 list = account_get_list();
2116 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2117 ac = (PrefsAccount *) cur->data;
2118 if (ac->protocol == A_NNTP) {
2119 compose_new(ac, NULL, NULL);