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_check_spelling_cb (GtkWidget *widget,
150 static void toolbar_popup_cb (gpointer data,
156 } toolbar_text [] = {
157 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
158 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
159 { "A_SEND_QUEUED", N_("Send Queued Message(s)") },
160 { "A_COMPOSE_EMAIL", N_("Compose Email") },
161 { "A_COMPOSE_NEWS", N_("Compose News") },
162 { "A_REPLY_MESSAGE", N_("Reply to Message") },
163 { "A_REPLY_SENDER", N_("Reply to Sender") },
164 { "A_REPLY_ALL", N_("Reply to All") },
165 { "A_REPLY_ML", N_("Reply to Mailing-list") },
166 { "A_FORWARD", N_("Forward Message") },
167 { "A_DELETE", N_("Delete Message") },
168 { "A_EXECUTE", N_("Execute") },
169 { "A_GOTO_NEXT", N_("Goto Next Message") },
170 { "A_IGNORE_THREAD", N_("Ignore thread") },
171 { "A_PRINT", N_("Print") },
173 { "A_SEND", N_("Send Message") },
174 { "A_SENDL", N_("Put into queue folder and send later") },
175 { "A_DRAFT", N_("Save to draft folder") },
176 { "A_INSERT", N_("Insert file") },
177 { "A_ATTACH", N_("Attach file") },
178 { "A_SIG", N_("Insert signature") },
179 { "A_EXTEDITOR", N_("Edit with external editor") },
180 { "A_LINEWRAP", N_("Wrap all long lines") },
181 { "A_ADDRBOOK", N_("Address book") },
183 { "A_CHECK_SPELLING",N_("Check spelling") },
185 { "A_SYL_ACTIONS", N_("Sylpheed Actions Feature") },
186 { "A_SEPARATOR", "Separator" }
189 /* struct holds configuration files and a list of
190 * currently active toolbar items
191 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
195 const gchar *conf_file;
197 } toolbar_config[3] = {
198 { "toolbar_main.xml", NULL},
199 { "toolbar_compose.xml", NULL},
200 { "toolbar_msgview.xml", NULL}
203 static GtkItemFactoryEntry reply_popup_entries[] =
205 {N_("/Reply with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
206 {N_("/_Reply without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
208 static GtkItemFactoryEntry replyall_popup_entries[] =
210 {N_("/Reply to all with _quote"), "<shift>A", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
211 {N_("/_Reply to all without quote"), "a", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
213 static GtkItemFactoryEntry replylist_popup_entries[] =
215 {N_("/Reply to list with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
216 {N_("/_Reply to list without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
218 static GtkItemFactoryEntry replysender_popup_entries[] =
220 {N_("/Reply to sender with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
221 {N_("/_Reply to sender without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
223 static GtkItemFactoryEntry fwd_popup_entries[] =
225 {N_("/_Forward message (inline style)"), "f", toolbar_popup_cb, COMPOSE_FORWARD_INLINE, NULL},
226 {N_("/Forward message as _attachment"), "<shift>F", toolbar_popup_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
230 gint toolbar_ret_val_from_descr(const gchar *descr)
234 for (i = 0; i < N_ACTION_VAL; i++) {
235 if (g_strcasecmp(gettext(toolbar_text[i].descr), descr) == 0)
242 gchar *toolbar_ret_descr_from_val(gint val)
244 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
246 return gettext(toolbar_text[val].descr);
249 static gint toolbar_ret_val_from_text(const gchar *text)
253 for (i = 0; i < N_ACTION_VAL; i++) {
254 if (g_strcasecmp(toolbar_text[i].index_str, text) == 0)
261 static gchar *toolbar_ret_text_from_val(gint val)
263 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
265 return toolbar_text[val].index_str;
268 gboolean toolbar_is_duplicate(gint action, ToolbarType source)
272 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
275 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
276 ToolbarItem *item = (ToolbarItem*) cur->data;
278 if (item->index == action)
284 /* depending on toolbar type this function
285 returns a list of available toolbar events being
286 displayed by prefs_toolbar
288 GList *toolbar_get_action_items(ToolbarType source)
293 if (source == TOOLBAR_MAIN) {
294 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
295 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
296 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
297 A_DELETE, A_EXECUTE, A_GOTO_NEXT,
298 A_IGNORE_THREAD, A_PRINT,
299 A_ADDRBOOK, A_SYL_ACTIONS };
301 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
302 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
303 if (main_items[i] == A_PRINT) {
304 g_print("$$$ descr %s, trans %s\n",
305 toolbar_text[main_items[i]].descr,
306 gettext(toolbar_text[main_items[i]].descr));
310 else if (source == TOOLBAR_COMPOSE) {
311 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
312 A_INSERT, A_ATTACH, A_SIG,
313 A_EXTEDITOR, A_LINEWRAP, A_ADDRBOOK,
319 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
320 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
322 else if (source == TOOLBAR_MSGVIEW) {
323 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
324 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
325 A_DELETE, A_GOTO_NEXT, A_ADDRBOOK,
328 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
329 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
335 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
339 ToolbarItem *item = NULL;
341 attr = xml_get_current_tag_attr(file);
342 item = g_new0(ToolbarItem, 1);
344 name = ((XMLAttr *)attr->data)->name;
345 value = ((XMLAttr *)attr->data)->value;
347 if (g_strcasecmp(name, TOOLBAR_ICON_FILE) == 0)
348 item->file = g_strdup (value);
349 else if (g_strcasecmp(name, TOOLBAR_ICON_TEXT) == 0)
350 item->text = g_strdup (value);
351 else if (g_strcasecmp(name, TOOLBAR_ICON_ACTION) == 0)
352 item->index = toolbar_ret_val_from_text(value);
354 attr = g_list_next(attr);
356 if (item->index != -1) {
358 if (!toolbar_is_duplicate(item->index, source))
359 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
364 static void toolbar_set_default_main(void)
370 } default_toolbar[] = {
371 { A_RECEIVE_CUR, STOCK_PIXMAP_MAIL_RECEIVE, _("Get") },
372 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get All") },
373 { A_SEPARATOR, 0, ("") },
374 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
375 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Email") },
376 { A_SEPARATOR, 0, ("") },
377 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
378 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
379 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
380 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
381 { A_SEPARATOR, 0, ("") },
382 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
383 { A_EXECUTE, STOCK_PIXMAP_EXEC, _("Execute") },
384 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
389 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
391 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
393 if (default_toolbar[i].action != A_SEPARATOR) {
395 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
397 toolbar_item->file = g_strdup(file);
398 toolbar_item->index = default_toolbar[i].action;
399 toolbar_item->text = g_strdup(default_toolbar[i].text);
402 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
403 toolbar_item->index = A_SEPARATOR;
406 if (toolbar_item->index != -1) {
407 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
408 toolbar_config[TOOLBAR_MAIN].item_list =
409 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
414 static void toolbar_set_default_compose(void)
420 } default_toolbar[] = {
421 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
422 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
423 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
424 { A_SEPARATOR, 0, ("") },
425 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
426 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
427 { A_SIG, STOCK_PIXMAP_MAIL_SIGN, _("Signature") },
428 { A_SEPARATOR, 0, ("") },
429 { A_EXTEDITOR, STOCK_PIXMAP_EDIT_EXTERN, _("Editor") },
430 { A_LINEWRAP, STOCK_PIXMAP_LINEWRAP, _("Linewrap") },
431 { A_SEPARATOR, 0, ("") },
432 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
437 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
439 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
441 if (default_toolbar[i].action != A_SEPARATOR) {
443 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
445 toolbar_item->file = g_strdup(file);
446 toolbar_item->index = default_toolbar[i].action;
447 toolbar_item->text = g_strdup(default_toolbar[i].text);
450 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
451 toolbar_item->index = A_SEPARATOR;
454 if (toolbar_item->index != -1) {
455 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
456 toolbar_config[TOOLBAR_COMPOSE].item_list =
457 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
462 static void toolbar_set_default_msgview(void)
468 } default_toolbar[] = {
469 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
470 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
471 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
472 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
473 { A_SEPARATOR, 0, ("") },
474 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
475 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
480 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
482 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
484 if (default_toolbar[i].action != A_SEPARATOR) {
486 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
488 toolbar_item->file = g_strdup(file);
489 toolbar_item->index = default_toolbar[i].action;
490 toolbar_item->text = g_strdup(default_toolbar[i].text);
493 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
494 toolbar_item->index = A_SEPARATOR;
497 if (toolbar_item->index != -1) {
498 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
499 toolbar_config[TOOLBAR_MSGVIEW].item_list =
500 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
505 void toolbar_set_default(ToolbarType source)
507 if (source == TOOLBAR_MAIN)
508 toolbar_set_default_main();
509 else if (source == TOOLBAR_COMPOSE)
510 toolbar_set_default_compose();
511 else if (source == TOOLBAR_MSGVIEW)
512 toolbar_set_default_msgview();
515 void toolbar_save_config_file(ToolbarType source)
520 gchar *fileSpec = NULL;
522 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
524 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
525 pfile = prefs_write_open(fileSpec);
529 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
530 conv_get_current_charset_str());
532 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
534 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
535 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
537 if (toolbar_item->index != A_SEPARATOR)
538 fprintf(fp, "\t<%s %s=\"%s\" %s=\"%s\" %s=\"%s\"/>\n",
540 TOOLBAR_ICON_FILE, toolbar_item->file,
541 TOOLBAR_ICON_TEXT, toolbar_item->text,
543 toolbar_ret_text_from_val(toolbar_item->index));
545 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
548 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
550 if (prefs_file_close (pfile) < 0 )
551 g_warning("failed to write toolbar configuration to file\n");
553 g_warning("failed to open toolbar configuration file for writing\n");
556 void toolbar_read_config_file(ToolbarType source)
558 XMLFile *file = NULL;
559 gchar *fileSpec = NULL;
564 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
566 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
567 file = xml_open_file(fileSpec);
570 toolbar_clear_list(source);
574 || (xml_get_dtd(file))
575 || (xml_parse_next_tag(file))
576 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
577 xml_close_file(file);
581 attr = xml_get_current_tag_attr(file);
588 if (xml_parse_next_tag(file))
591 /* Get next tag (icon, icon_text or icon_action) */
592 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
593 toolbar_parse_item(file, source);
594 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
595 ToolbarItem *item = g_new0(ToolbarItem, 1);
597 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
598 item->index = A_SEPARATOR;
599 toolbar_config[source].item_list =
600 g_slist_append(toolbar_config[source].item_list, item);
604 xml_close_file(file);
607 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
609 if (source == TOOLBAR_MAIN)
610 toolbar_set_default(TOOLBAR_MAIN);
611 else if (source == TOOLBAR_COMPOSE)
612 toolbar_set_default(TOOLBAR_COMPOSE);
613 else if (source == TOOLBAR_MSGVIEW)
614 toolbar_set_default(TOOLBAR_MSGVIEW);
616 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
620 toolbar_save_config_file(source);
625 * clears list of toolbar items read from configuration files
627 void toolbar_clear_list(ToolbarType source)
629 while (toolbar_config[source].item_list != NULL) {
630 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
632 toolbar_config[source].item_list =
633 g_slist_remove(toolbar_config[source].item_list, item);
641 g_slist_free(toolbar_config[source].item_list);
646 * return list of Toolbar items
648 GSList *toolbar_get_list(ToolbarType source)
652 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
653 list = toolbar_config[source].item_list;
658 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
660 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
662 toolbar_item->file = g_strdup(t_item->file);
663 toolbar_item->text = g_strdup(t_item->text);
664 toolbar_item->index = t_item->index;
666 toolbar_config[source].item_list =
667 g_slist_append(toolbar_config[source].item_list,
671 void toolbar_action_execute(GtkWidget *widget,
677 gchar *action, *action_p;
678 gboolean found = FALSE;
681 for (cur = action_list; cur != NULL; cur = cur->next) {
682 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
684 if (widget == act->widget) {
686 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
687 action = g_strdup((gchar*)lop->data);
689 action_p = strstr(action, ": ");
691 if (g_strcasecmp(act->name, action) == 0) {
705 actions_execute(data, i, widget, source);
707 g_warning ("Error: did not find Sylpheed Action to execute");
710 static void activate_compose_button (Toolbar *toolbar,
712 ComposeButtonType type)
714 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
717 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
718 : toolbar->compose_news_btn);
719 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
720 : toolbar->compose_mail_btn);
721 toolbar->compose_btn_type = type;
724 void toolbar_set_compose_button(Toolbar *toolbar,
725 ComposeButtonType compose_btn_type)
727 if (toolbar->compose_btn_type != compose_btn_type)
728 activate_compose_button(toolbar,
729 prefs_common.toolbar_style,
733 void toolbar_toggle(guint action, gpointer data)
735 MainWindow *mainwin = (MainWindow*)data;
739 g_return_if_fail(mainwin != NULL);
741 toolbar_style(TOOLBAR_MAIN, action, mainwin);
743 list = compose_get_compose_list();
744 for (cur = list; cur != NULL; cur = cur->next) {
745 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
747 list = messageview_get_msgview_list();
748 for (cur = list; cur != NULL; cur = cur->next) {
749 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
754 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
756 switch ((ToolbarStyle)action) {
758 gtk_widget_hide(handlebox_wid);
761 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
765 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
769 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
776 prefs_common.toolbar_style = (ToolbarStyle)action;
777 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
778 gtk_widget_show(handlebox_wid);
779 gtk_widget_queue_resize(handlebox_wid);
783 * Change the style of toolbar
785 static void toolbar_style(ToolbarType type, guint action, gpointer data)
787 GtkWidget *handlebox_wid;
788 GtkWidget *toolbar_wid;
789 MainWindow *mainwin = (MainWindow*)data;
790 Compose *compose = (Compose*)data;
791 MessageView *msgview = (MessageView*)data;
793 g_return_if_fail(data != NULL);
797 handlebox_wid = mainwin->handlebox;
798 toolbar_wid = mainwin->toolbar->toolbar;
800 case TOOLBAR_COMPOSE:
801 handlebox_wid = compose->handlebox;
802 toolbar_wid = compose->toolbar->toolbar;
804 case TOOLBAR_MSGVIEW:
805 handlebox_wid = msgview->handlebox;
806 toolbar_wid = msgview->toolbar->toolbar;
812 toolbar_set_style(toolbar_wid, handlebox_wid, action);
815 /* Toolbar handling */
816 static void toolbar_inc_cb(GtkWidget *widget,
819 ToolbarItem *toolbar_item = (ToolbarItem*)data;
822 g_return_if_fail(toolbar_item != NULL);
824 switch (toolbar_item->type) {
826 mainwin = (MainWindow*)toolbar_item->parent;
827 inc_mail_cb(mainwin, 0, NULL);
834 static void toolbar_inc_all_cb(GtkWidget *widget,
837 ToolbarItem *toolbar_item = (ToolbarItem*)data;
840 g_return_if_fail(toolbar_item != NULL);
842 switch (toolbar_item->type) {
844 mainwin = (MainWindow*)toolbar_item->parent;
845 inc_all_account_mail_cb(mainwin, 0, NULL);
852 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
854 ToolbarItem *toolbar_item = (ToolbarItem*)data;
857 g_return_if_fail(toolbar_item != NULL);
859 switch (toolbar_item->type) {
861 mainwin = (MainWindow*)toolbar_item->parent;
862 send_queue_cb(mainwin, 0, NULL);
869 static void toolbar_exec_cb(GtkWidget *widget,
872 MainWindow *mainwin = get_mainwin(data);
874 g_return_if_fail(mainwin != NULL);
875 summary_execute(mainwin->summaryview);
880 /* popup callback functions */
881 static void toolbar_reply_popup_cb(GtkWidget *widget,
882 GdkEventButton *event,
885 Toolbar *toolbar_data = (Toolbar*)data;
889 if (event->button == 3) {
890 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
891 gtk_menu_popup(GTK_MENU(toolbar_data->reply_popup), NULL, NULL,
892 menu_button_position, widget,
893 event->button, event->time);
897 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
899 ToolbarItem *toolbar_item = (ToolbarItem*)data;
901 GtkWidget *reply_btn;
903 MessageView *msgview;
905 g_return_if_fail(toolbar_item != NULL);
907 switch(toolbar_item->type) {
909 mainwin = (MainWindow*)toolbar_item->parent;
910 reply_btn = mainwin->toolbar->reply_btn;
911 window = mainwin->window;
913 case TOOLBAR_MSGVIEW:
914 msgview = (MessageView*)toolbar_item->parent;
915 reply_btn = msgview->toolbar->reply_btn;
916 window = msgview->window;
922 gtk_button_set_relief(GTK_BUTTON(reply_btn), GTK_RELIEF_NONE);
923 manage_window_focus_in(window, NULL, NULL);
926 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
928 Toolbar *toolbar_data = (Toolbar*)data;
932 if (event->button == 3) {
933 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
934 gtk_menu_popup(GTK_MENU(toolbar_data->replyall_popup), NULL, NULL,
935 menu_button_position, widget,
936 event->button, event->time);
940 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
942 ToolbarItem *toolbar_item = (ToolbarItem*)data;
944 GtkWidget *replyall_btn;
946 MessageView *msgview;
948 g_return_if_fail(toolbar_item != NULL);
950 switch(toolbar_item->type) {
952 mainwin = (MainWindow*)toolbar_item->parent;
953 replyall_btn = mainwin->toolbar->replyall_btn;
954 window = mainwin->window;
956 case TOOLBAR_MSGVIEW:
957 msgview = (MessageView*)toolbar_item->parent;
958 replyall_btn = msgview->toolbar->replyall_btn;
959 window = msgview->window;
965 gtk_button_set_relief(GTK_BUTTON(replyall_btn), GTK_RELIEF_NONE);
966 manage_window_focus_in(window, NULL, NULL);
969 static void toolbar_reply_to_list_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
971 Toolbar *toolbar_data = (Toolbar*)data;
973 if (event->button == 3) {
974 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
975 gtk_menu_popup(GTK_MENU(toolbar_data->replylist_popup), NULL, NULL,
976 menu_button_position, widget,
977 event->button, event->time);
981 static void toolbar_reply_to_list_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
983 ToolbarItem *toolbar_item = (ToolbarItem*)data;
984 gpointer parent = toolbar_item->parent;
986 GtkWidget *replylist_btn;
989 g_return_if_fail(toolbar_item != NULL);
991 switch(toolbar_item->type) {
993 replylist_btn = ((MainWindow*)parent)->toolbar->replylist_btn;
994 window = ((MainWindow*)parent)->window;
996 case TOOLBAR_MSGVIEW:
997 replylist_btn = ((MessageView*)parent)->toolbar->replylist_btn;
998 window = ((MessageView*)parent)->window;
1004 gtk_button_set_relief(GTK_BUTTON(replylist_btn), GTK_RELIEF_NONE);
1005 manage_window_focus_in(window, NULL, NULL);
1008 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1010 Toolbar *toolbar_data = (Toolbar*)data;
1012 if (event->button == 3) {
1013 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1014 gtk_menu_popup(GTK_MENU(toolbar_data->replysender_popup), NULL, NULL,
1015 menu_button_position, widget,
1016 event->button, event->time);
1020 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
1022 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1023 gpointer parent = toolbar_item->parent;
1025 GtkWidget *replysender_btn;
1027 g_return_if_fail(toolbar_item != NULL);
1029 switch(toolbar_item->type) {
1031 replysender_btn = ((MainWindow*)parent)->toolbar->replysender_btn;
1032 window = ((MainWindow*)parent)->window;
1034 case TOOLBAR_MSGVIEW:
1035 replysender_btn = ((MessageView*)parent)->toolbar->replysender_btn;
1036 window = ((MessageView*)parent)->window;
1042 gtk_button_set_relief(GTK_BUTTON(replysender_btn), GTK_RELIEF_NONE);
1043 manage_window_focus_in(window, NULL, NULL);
1046 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1048 Toolbar *toolbar_data = (Toolbar*)data;
1050 if (event->button == 3) {
1051 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1052 gtk_menu_popup(GTK_MENU(toolbar_data->fwd_popup), NULL, NULL,
1053 menu_button_position, widget,
1054 event->button, event->time);
1058 static void toolbar_forward_popup_closed_cb (GtkMenuShell *menu_shell,
1061 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1062 gpointer parent = toolbar_item->parent;
1066 g_return_if_fail(toolbar_item != NULL);
1068 switch(toolbar_item->type) {
1070 fwd_btn = ((MainWindow*)parent)->toolbar->fwd_btn;
1071 window = ((MainWindow*)parent)->window;
1073 case TOOLBAR_MSGVIEW:
1074 fwd_btn = ((MessageView*)parent)->toolbar->fwd_btn;
1075 window = ((MessageView*)parent)->window;
1081 gtk_button_set_relief(GTK_BUTTON(fwd_btn), GTK_RELIEF_NONE);
1082 manage_window_focus_in(window, NULL, NULL);
1086 * Delete current/selected(s) message(s)
1088 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1090 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1091 MainWindow *mainwin;
1092 MessageView *msgview;
1094 g_return_if_fail(toolbar_item != NULL);
1096 switch (toolbar_item->type) {
1097 case TOOLBAR_MSGVIEW:
1098 msgview = (MessageView*)toolbar_item->parent;
1099 messageview_delete(msgview);
1102 mainwin = (MainWindow*)toolbar_item->parent;
1103 summary_delete(mainwin->summaryview);
1106 debug_print("toolbar event not supported\n");
1113 * Compose new message
1115 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1117 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1118 MainWindow *mainwin;
1119 MessageView *msgview;
1121 g_return_if_fail(toolbar_item != NULL);
1123 switch (toolbar_item->type) {
1125 mainwin = (MainWindow*)toolbar_item->parent;
1126 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1127 compose_news_cb(mainwin, 0, NULL);
1129 compose_mail_cb(mainwin, 0, NULL);
1131 case TOOLBAR_MSGVIEW:
1132 msgview = (MessageView*)toolbar_item->parent;
1133 compose_new_with_folderitem(NULL,
1134 msgview->msginfo->folder);
1137 debug_print("toolbar event not supported\n");
1141 static void toolbar_popup_cb(gpointer data, guint action, GtkWidget *widget)
1143 toolbar_reply(data, action);
1150 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1152 toolbar_reply(data, prefs_common.reply_with_quote ?
1153 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1158 * Reply message to Sender and All recipients
1160 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1163 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1164 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1169 * Reply to Mailing List
1171 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1174 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1175 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1180 * Reply to sender of message
1182 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1185 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1186 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1192 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1194 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1197 g_return_if_fail(toolbar_item != NULL);
1199 switch (toolbar_item->type) {
1201 case TOOLBAR_MSGVIEW:
1204 case TOOLBAR_COMPOSE:
1205 compose = (Compose *)toolbar_item->parent;
1210 addressbook_open(compose);
1215 * Forward current/selected(s) message(s)
1217 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1219 toolbar_reply(data, COMPOSE_FORWARD);
1224 * Goto Next Unread Message
1226 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1228 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1229 MainWindow *mainwin;
1230 MessageView *msgview;
1232 g_return_if_fail(toolbar_item != NULL);
1234 switch (toolbar_item->type) {
1236 mainwin = (MainWindow*)toolbar_item->parent;
1237 summary_select_next_unread(mainwin->summaryview);
1240 case TOOLBAR_MSGVIEW:
1241 msgview = (MessageView*)toolbar_item->parent;
1242 summary_select_next_unread(msgview->mainwin->summaryview);
1244 /* Now we need to update the messageview window */
1245 if (msgview->mainwin->summaryview->selected) {
1246 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1248 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1249 msgview->mainwin->summaryview->selected);
1251 messageview_show(msgview, msginfo,
1252 msgview->all_headers);
1254 gtk_widget_destroy(msgview->window);
1258 debug_print("toolbar event not supported\n");
1262 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1264 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1265 MainWindow *mainwin;
1267 g_return_if_fail(toolbar_item != NULL);
1269 switch (toolbar_item->type) {
1271 mainwin = (MainWindow *) toolbar_item->parent;
1272 summary_toggle_ignore_thread(mainwin->summaryview);
1274 case TOOLBAR_MSGVIEW:
1275 /* TODO: see toolbar_next_unread_cb() if you need
1276 * this in the message view */
1279 debug_print("toolbar event not supported\n");
1284 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1286 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1287 MainWindow *mainwin;
1289 g_return_if_fail(toolbar_item != NULL);
1291 switch (toolbar_item->type) {
1293 mainwin = (MainWindow *) toolbar_item->parent;
1294 summary_print(mainwin->summaryview);
1296 case TOOLBAR_MSGVIEW:
1297 /* TODO: see toolbar_next_unread_cb() if you need
1298 * this in the message view */
1301 debug_print("toolbar event not supported\n");
1306 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1308 compose_toolbar_cb(A_SEND, data);
1311 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1313 compose_toolbar_cb(A_SENDL, data);
1316 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1318 compose_toolbar_cb(A_DRAFT, data);
1321 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1323 compose_toolbar_cb(A_INSERT, data);
1326 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1328 compose_toolbar_cb(A_ATTACH, data);
1331 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1333 compose_toolbar_cb(A_SIG, data);
1336 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1338 compose_toolbar_cb(A_EXTEDITOR, data);
1341 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
1343 compose_toolbar_cb(A_LINEWRAP, data);
1347 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1349 compose_toolbar_cb(A_CHECK_SPELLING, data);
1353 * Execute actions from toolbar
1355 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1357 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1358 GSList *action_list;
1359 MainWindow *mainwin;
1361 MessageView *msgview;
1362 gpointer parent = toolbar_item->parent;
1364 g_return_if_fail(toolbar_item != NULL);
1366 switch (toolbar_item->type) {
1368 mainwin = (MainWindow*)parent;
1369 action_list = mainwin->toolbar->action_list;
1371 case TOOLBAR_COMPOSE:
1372 compose = (Compose*)parent;
1373 action_list = compose->toolbar->action_list;
1375 case TOOLBAR_MSGVIEW:
1376 msgview = (MessageView*)parent;
1377 action_list = msgview->toolbar->action_list;
1380 debug_print("toolbar event not supported\n");
1383 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1386 static MainWindow *get_mainwin(gpointer data)
1388 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1389 MainWindow *mainwin = NULL;
1390 MessageView *msgview;
1392 g_return_val_if_fail(toolbar_item != NULL, NULL);
1394 switch(toolbar_item->type) {
1396 mainwin = (MainWindow*)toolbar_item->parent;
1398 case TOOLBAR_MSGVIEW:
1399 msgview = (MessageView*)toolbar_item->parent;
1400 mainwin = (MainWindow*)msgview->mainwin;
1409 static GtkWidget *get_window_widget(ToolbarType type, gpointer data)
1411 MainWindow *mainwin;
1412 MessageView *msgview;
1416 mainwin = (MainWindow*)data;
1417 return mainwin->window;
1419 case TOOLBAR_MSGVIEW:
1420 msgview = (MessageView*)data;
1421 return msgview->vbox;
1429 static void toolbar_buttons_cb(GtkWidget *widget,
1436 void (*func)(GtkWidget *widget, gpointer data);
1438 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1439 { A_RECEIVE_CUR, toolbar_inc_cb },
1440 { A_SEND_QUEUED, toolbar_send_queued_cb },
1441 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1442 { A_COMPOSE_NEWS, toolbar_compose_cb },
1443 { A_REPLY_MESSAGE, toolbar_reply_cb },
1444 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1445 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1446 { A_REPLY_ML, toolbar_reply_to_list_cb },
1447 { A_FORWARD, toolbar_forward_cb },
1448 { A_DELETE, toolbar_delete_cb },
1449 { A_EXECUTE, toolbar_exec_cb },
1450 { A_GOTO_NEXT, toolbar_next_unread_cb },
1451 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1452 { A_PRINT, toolbar_print_cb },
1454 { A_SEND, toolbar_send_cb },
1455 { A_SENDL, toolbar_send_later_cb },
1456 { A_DRAFT, toolbar_draft_cb },
1457 { A_INSERT, toolbar_insert_cb },
1458 { A_ATTACH, toolbar_attach_cb },
1459 { A_SIG, toolbar_sig_cb },
1460 { A_EXTEDITOR, toolbar_ext_editor_cb },
1461 { A_LINEWRAP, toolbar_linewrap_cb },
1462 { A_ADDRBOOK, toolbar_addrbook_cb },
1464 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1466 { A_SYL_ACTIONS, toolbar_actions_execute_cb }
1469 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1471 for (i = 0; i < num_items; i++) {
1472 if (callbacks[i].index == item->index) {
1473 callbacks[i].func(widget, item);
1480 * Create a new toolbar with specified type
1481 * if a callback list is passed it will be used before the
1482 * common callback list
1484 Toolbar *toolbar_create(ToolbarType type,
1485 GtkWidget *container,
1488 ToolbarItem *toolbar_item;
1491 GtkWidget *icon_wid = NULL;
1492 GtkWidget *icon_news;
1494 GtkWidget *item_news;
1495 GtkWidget *window_wid;
1497 guint n_menu_entries;
1498 GtkWidget *reply_popup;
1499 GtkWidget *replyall_popup;
1500 GtkWidget *replylist_popup;
1501 GtkWidget *replysender_popup;
1502 GtkWidget *fwd_popup;
1504 GtkTooltips *toolbar_tips;
1505 ToolbarSylpheedActions *action_item;
1507 GSList *toolbar_list;
1508 Toolbar *toolbar_data;
1511 toolbar_tips = gtk_tooltips_new();
1513 toolbar_read_config_file(type);
1514 toolbar_list = toolbar_get_list(type);
1516 toolbar_data = g_new0(Toolbar, 1);
1518 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1520 gtk_container_add(GTK_CONTAINER(container), toolbar);
1521 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1522 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1523 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1524 GTK_TOOLBAR_SPACE_LINE);
1526 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1528 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1529 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1533 toolbar_item = g_new0(ToolbarItem, 1);
1534 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1535 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1536 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1537 toolbar_item->parent = data;
1538 toolbar_item->type = type;
1540 /* collect toolbar items in list to keep track */
1541 toolbar_data->item_list =
1542 g_slist_append(toolbar_data->item_list,
1545 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1546 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1550 icon_wid, toolbar_buttons_cb,
1553 switch (toolbar_item->index) {
1556 toolbar_data->getall_btn = item;
1557 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1558 toolbar_data->getall_btn,
1559 _("Receive Mail on all Accounts"), NULL);
1562 toolbar_data->get_btn = item;
1563 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1564 toolbar_data->get_btn,
1565 _("Receive Mail on current Account"), NULL);
1568 toolbar_data->send_btn = item;
1569 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1570 toolbar_data->send_btn,
1571 _("Send Queued Message(s)"), NULL);
1573 case A_COMPOSE_EMAIL:
1574 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1575 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1579 icon_news, toolbar_buttons_cb,
1581 toolbar_data->compose_mail_btn = item;
1582 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1583 toolbar_data->compose_mail_btn,
1584 _("Compose Email"), NULL);
1585 toolbar_data->compose_news_btn = item_news;
1586 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1587 toolbar_data->compose_news_btn,
1588 _("Compose News"), NULL);
1590 case A_REPLY_MESSAGE:
1591 toolbar_data->reply_btn = item;
1592 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1593 toolbar_data->reply_btn,
1594 _("Reply to Message"), NULL);
1595 gtk_signal_connect(GTK_OBJECT(toolbar_data->reply_btn),
1596 "button_press_event",
1597 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
1599 n_menu_entries = sizeof(reply_popup_entries) /
1600 sizeof(reply_popup_entries[0]);
1602 window_wid = get_window_widget(type, data);
1603 reply_popup = popupmenu_create(window_wid,
1604 reply_popup_entries, n_menu_entries,
1605 "<ReplyPopup>", (gpointer)toolbar_item);
1607 gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
1608 GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), toolbar_item);
1609 toolbar_data->reply_popup = reply_popup;
1611 case A_REPLY_SENDER:
1612 toolbar_data->replysender_btn = item;
1613 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1614 toolbar_data->replysender_btn,
1615 _("Reply to Sender"), NULL);
1616 gtk_signal_connect(GTK_OBJECT(toolbar_data->replysender_btn),
1617 "button_press_event",
1618 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
1620 n_menu_entries = sizeof(replysender_popup_entries) /
1621 sizeof(replysender_popup_entries[0]);
1623 window_wid = get_window_widget(type, data);
1624 replysender_popup = popupmenu_create(window_wid,
1625 replysender_popup_entries, n_menu_entries,
1626 "<ReplySenderPopup>", (gpointer)toolbar_item);
1628 gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
1629 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), toolbar_item);
1630 toolbar_data->replysender_popup = replysender_popup;
1633 toolbar_data->replyall_btn = item;
1634 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1635 toolbar_data->replyall_btn,
1636 _("Reply to All"), NULL);
1637 gtk_signal_connect(GTK_OBJECT(toolbar_data->replyall_btn),
1638 "button_press_event",
1639 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
1641 n_menu_entries = sizeof(replyall_popup_entries) /
1642 sizeof(replyall_popup_entries[0]);
1644 window_wid = get_window_widget(type, data);
1645 replyall_popup = popupmenu_create(window_wid,
1646 replyall_popup_entries, n_menu_entries,
1647 "<ReplyAllPopup>", (gpointer)toolbar_item);
1649 gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
1650 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), toolbar_item);
1651 toolbar_data->replyall_popup = replyall_popup;
1654 toolbar_data->replylist_btn = item;
1655 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1656 toolbar_data->replylist_btn,
1657 _("Reply to Mailing-list"), NULL);
1658 gtk_signal_connect(GTK_OBJECT(toolbar_data->replylist_btn),
1659 "button_press_event",
1660 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_cb),
1662 n_menu_entries = sizeof(replylist_popup_entries) /
1663 sizeof(replylist_popup_entries[0]);
1665 window_wid = get_window_widget(type, data);
1666 replylist_popup = popupmenu_create(window_wid,
1667 replylist_popup_entries, n_menu_entries,
1668 "<ReplyMlPopup>", (gpointer)toolbar_item);
1670 gtk_signal_connect(GTK_OBJECT(replylist_popup), "selection_done",
1671 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_closed_cb), toolbar_item);
1672 toolbar_data->replylist_popup = replylist_popup;
1675 toolbar_data->fwd_btn = item;
1676 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1677 toolbar_data->fwd_btn,
1678 _("Forward Message"), NULL);
1679 gtk_signal_connect(GTK_OBJECT(toolbar_data->fwd_btn),
1680 "button_press_event",
1681 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
1683 n_menu_entries = sizeof(fwd_popup_entries) /
1684 sizeof(fwd_popup_entries[0]);
1686 window_wid = get_window_widget(type, data);
1687 fwd_popup = popupmenu_create(window_wid,
1688 fwd_popup_entries, n_menu_entries,
1689 "<ForwardPopup>", (gpointer)toolbar_item);
1691 gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
1692 GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), toolbar_item);
1693 toolbar_data->fwd_popup = fwd_popup;
1696 toolbar_data->delete_btn = item;
1697 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1698 toolbar_data->delete_btn,
1699 _("Delete Message"), NULL);
1702 toolbar_data->exec_btn = item;
1703 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1704 toolbar_data->exec_btn,
1705 _("Execute"), NULL);
1708 toolbar_data->next_btn = item;
1709 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1710 toolbar_data->next_btn,
1711 _("Goto Next Message"), NULL);
1714 /* Compose Toolbar */
1716 toolbar_data->send_btn = item;
1717 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1718 toolbar_data->send_btn,
1719 _("Send Message"), NULL);
1722 toolbar_data->sendl_btn = item;
1723 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1724 toolbar_data->sendl_btn,
1725 _("Put into queue folder and send later"), NULL);
1728 toolbar_data->draft_btn = item;
1729 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1730 toolbar_data->draft_btn,
1731 _("Save to draft folder"), NULL);
1734 toolbar_data->insert_btn = item;
1735 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1736 toolbar_data->insert_btn,
1737 _("Insert file"), NULL);
1740 toolbar_data->attach_btn = item;
1741 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1742 toolbar_data->attach_btn,
1743 _("Attach file"), NULL);
1746 toolbar_data->sig_btn = item;
1747 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1748 toolbar_data->sig_btn,
1749 _("Insert signature"), NULL);
1752 toolbar_data->exteditor_btn = item;
1753 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1754 toolbar_data->exteditor_btn,
1755 _("Edit with external editor"), NULL);
1758 toolbar_data->linewrap_btn = item;
1759 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1760 toolbar_data->linewrap_btn,
1761 _("Wrap all long lines"), NULL);
1764 toolbar_data->addrbook_btn = item;
1765 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1766 toolbar_data->addrbook_btn,
1767 _("Address book"), NULL);
1770 case A_CHECK_SPELLING:
1771 toolbar_data->spellcheck_btn = item;
1772 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1773 toolbar_data->spellcheck_btn,
1774 _("Check spelling"), NULL);
1779 action_item = g_new0(ToolbarSylpheedActions, 1);
1780 action_item->widget = item;
1781 action_item->name = g_strdup(toolbar_item->text);
1783 toolbar_data->action_list =
1784 g_slist_append(toolbar_data->action_list,
1787 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1789 action_item->name, NULL);
1791 gtk_widget_show(item);
1794 /* find and set the tool tip text */
1795 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1797 toolbar_ret_descr_from_val
1798 (toolbar_item->index),
1804 toolbar_data->toolbar = toolbar;
1805 if (type == TOOLBAR_MAIN)
1806 activate_compose_button(toolbar_data,
1807 prefs_common.toolbar_style,
1808 toolbar_data->compose_btn_type);
1810 gtk_widget_show_all(toolbar);
1812 return toolbar_data;
1816 * Free toolbar structures
1818 void toolbar_destroy(Toolbar * toolbar) {
1820 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1821 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1824 void toolbar_update(ToolbarType type, gpointer data)
1826 Toolbar *toolbar_data;
1827 GtkWidget *handlebox;
1828 MainWindow *mainwin = (MainWindow*)data;
1829 Compose *compose = (Compose*)data;
1830 MessageView *msgview = (MessageView*)data;
1834 toolbar_data = mainwin->toolbar;
1835 handlebox = mainwin->handlebox;
1837 case TOOLBAR_COMPOSE:
1838 toolbar_data = compose->toolbar;
1839 handlebox = compose->handlebox;
1841 case TOOLBAR_MSGVIEW:
1842 toolbar_data = msgview->toolbar;
1843 handlebox = msgview->handlebox;
1849 gtk_container_remove(GTK_CONTAINER(handlebox),
1850 GTK_WIDGET(toolbar_data->toolbar));
1852 toolbar_init(toolbar_data);
1853 toolbar_data = toolbar_create(type, handlebox, data);
1856 mainwin->toolbar = toolbar_data;
1858 case TOOLBAR_COMPOSE:
1859 compose->toolbar = toolbar_data;
1861 case TOOLBAR_MSGVIEW:
1862 msgview->toolbar = toolbar_data;
1866 toolbar_style(type, prefs_common.toolbar_style, data);
1868 if (type == TOOLBAR_MAIN)
1869 toolbar_main_set_sensitive((MainWindow*)data);
1872 void toolbar_main_set_sensitive(gpointer data)
1874 SensitiveCond state;
1876 MainWindow *mainwin = (MainWindow*)data;
1877 Toolbar *toolbar = mainwin->toolbar;
1879 GSList *entry_list = NULL;
1881 typedef struct _Entry Entry;
1888 #define SET_WIDGET_COND(w, c) \
1890 Entry *e = g_new0(Entry, 1); \
1893 entry_list = g_slist_append(entry_list, e); \
1896 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1897 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1898 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1899 SET_WIDGET_COND(toolbar->reply_btn,
1900 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1901 SET_WIDGET_COND(toolbar->replyall_btn,
1902 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1903 SET_WIDGET_COND(toolbar->replylist_btn,
1904 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1905 SET_WIDGET_COND(toolbar->replysender_btn,
1906 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1907 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1909 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1910 SET_WIDGET_COND(toolbar->delete_btn,
1911 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1912 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1914 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
1915 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1917 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1920 #undef SET_WIDGET_COND
1922 state = main_window_get_current_state(mainwin);
1924 for (cur = entry_list; cur != NULL; cur = cur->next) {
1925 Entry *e = (Entry*) cur->data;
1927 if (e->widget != NULL) {
1928 sensitive = ((e->cond & state) == e->cond);
1929 gtk_widget_set_sensitive(e->widget, sensitive);
1933 while (entry_list != NULL) {
1934 Entry *e = (Entry*) entry_list->data;
1938 entry_list = g_slist_remove(entry_list, e);
1941 g_slist_free(entry_list);
1943 activate_compose_button(toolbar,
1944 prefs_common.toolbar_style,
1945 toolbar->compose_btn_type);
1948 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1950 Compose *compose = (Compose*)data;
1951 GSList *items = compose->toolbar->action_list;
1953 if (compose->toolbar->send_btn)
1954 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1955 if (compose->toolbar->sendl_btn)
1956 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1957 if (compose->toolbar->draft_btn )
1958 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1959 if (compose->toolbar->insert_btn )
1960 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1961 if (compose->toolbar->attach_btn)
1962 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1963 if (compose->toolbar->sig_btn)
1964 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1965 if (compose->toolbar->exteditor_btn)
1966 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1967 if (compose->toolbar->linewrap_btn)
1968 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
1969 if (compose->toolbar->addrbook_btn)
1970 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1972 if (compose->toolbar->spellcheck_btn)
1973 gtk_widget_set_sensitive(compose->toolbar->spellcheck_btn, sensitive);
1975 for (; items != NULL; items = g_slist_next(items)) {
1976 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1977 gtk_widget_set_sensitive(item->widget, sensitive);
1982 * Initialize toolbar structure
1984 void toolbar_init(Toolbar * toolbar) {
1986 toolbar->toolbar = NULL;
1987 toolbar->get_btn = NULL;
1988 toolbar->getall_btn = NULL;
1989 toolbar->send_btn = NULL;
1990 toolbar->compose_mail_btn = NULL;
1991 toolbar->compose_news_btn = NULL;
1992 toolbar->reply_btn = NULL;
1993 toolbar->replysender_btn = NULL;
1994 toolbar->replyall_btn = NULL;
1995 toolbar->replylist_btn = NULL;
1996 toolbar->fwd_btn = NULL;
1997 toolbar->delete_btn = NULL;
1998 toolbar->next_btn = NULL;
1999 toolbar->exec_btn = NULL;
2001 /* compose buttons */
2002 toolbar->sendl_btn = NULL;
2003 toolbar->draft_btn = NULL;
2004 toolbar->insert_btn = NULL;
2005 toolbar->attach_btn = NULL;
2006 toolbar->sig_btn = NULL;
2007 toolbar->exteditor_btn = NULL;
2008 toolbar->linewrap_btn = NULL;
2009 toolbar->addrbook_btn = NULL;
2011 toolbar->spellcheck_btn = NULL;
2014 toolbar_destroy(toolbar);
2019 static void toolbar_reply(gpointer data, guint action)
2021 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2022 MainWindow *mainwin;
2023 MessageView *msgview;
2024 GSList *msginfo_list = NULL;
2027 g_return_if_fail(toolbar_item != NULL);
2029 switch (toolbar_item->type) {
2031 mainwin = (MainWindow*)toolbar_item->parent;
2032 msginfo_list = summary_get_selection(mainwin->summaryview);
2033 msgview = (MessageView*)mainwin->messageview;
2035 case TOOLBAR_MSGVIEW:
2036 msgview = (MessageView*)toolbar_item->parent;
2037 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
2043 g_return_if_fail(msgview != NULL);
2044 body = messageview_get_selection(msgview);
2046 g_return_if_fail(msginfo_list != NULL);
2047 compose_reply_mode((ComposeMode)action, msginfo_list, body);
2050 g_slist_free(msginfo_list);
2052 /* TODO: update reply state ion summaryview */
2056 /* exported functions */
2058 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2060 MainWindow *mainwin = (MainWindow*)data;
2062 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2065 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2067 MainWindow *mainwin = (MainWindow*)data;
2069 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
2072 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2076 if (prefs_common.work_offline)
2077 if (alertpanel(_("Offline warning"),
2078 _("You're working offline. Override?"),
2079 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
2082 for (list = folder_get_list(); list != NULL; list = list->next) {
2083 Folder *folder = list->data;
2085 if (folder->queue) {
2086 procmsg_send_queue(folder->queue, prefs_common.savemsg);
2087 folder_item_scan(folder->queue);
2092 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2094 MainWindow *mainwin = (MainWindow*)data;
2095 PrefsAccount *ac = NULL;
2096 FolderItem *item = mainwin->summaryview->folder_item;
2101 ac = account_find_from_item(item);
2102 if (ac && ac->protocol != A_NNTP) {
2103 compose_new_with_folderitem(ac, item); /* CLAWS */
2109 * CLAWS - use current account
2111 if (cur_account && (cur_account->protocol != A_NNTP)) {
2112 compose_new_with_folderitem(cur_account, item);
2117 * CLAWS - just get the first one
2119 list = account_get_list();
2120 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2121 ac = (PrefsAccount *) cur->data;
2122 if (ac->protocol != A_NNTP) {
2123 compose_new_with_folderitem(ac, item);
2129 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2131 MainWindow *mainwin = (MainWindow*)data;
2132 PrefsAccount * ac = NULL;
2136 if (mainwin->summaryview->folder_item) {
2137 ac = mainwin->summaryview->folder_item->folder->account;
2138 if (ac && ac->protocol == A_NNTP) {
2140 mainwin->summaryview->folder_item->path,
2146 list = account_get_list();
2147 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2148 ac = (PrefsAccount *) cur->data;
2149 if (ac->protocol == A_NNTP) {
2150 compose_new(ac, NULL, NULL);