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_current_cb (GtkWidget *widget,
144 static void toolbar_linewrap_all_cb (GtkWidget *widget,
146 static void toolbar_addrbook_cb (GtkWidget *widget,
149 static void toolbar_check_spelling_cb (GtkWidget *widget,
152 static void toolbar_popup_cb (gpointer data,
158 } toolbar_text [] = {
159 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
160 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
161 { "A_SEND_QUEUED", N_("Send Queued Message(s)") },
162 { "A_COMPOSE_EMAIL", N_("Compose Email") },
163 { "A_COMPOSE_NEWS", N_("Compose News") },
164 { "A_REPLY_MESSAGE", N_("Reply to Message") },
165 { "A_REPLY_SENDER", N_("Reply to Sender") },
166 { "A_REPLY_ALL", N_("Reply to All") },
167 { "A_REPLY_ML", N_("Reply to Mailing-list") },
168 { "A_FORWARD", N_("Forward Message") },
169 { "A_DELETE", N_("Delete Message") },
170 { "A_EXECUTE", N_("Execute") },
171 { "A_GOTO_NEXT", N_("Goto Next Message") },
172 { "A_IGNORE_THREAD", N_("Ignore thread") },
173 { "A_PRINT", N_("Print") },
175 { "A_SEND", N_("Send Message") },
176 { "A_SENDL", N_("Put into queue folder and send later") },
177 { "A_DRAFT", N_("Save to draft folder") },
178 { "A_INSERT", N_("Insert file") },
179 { "A_ATTACH", N_("Attach file") },
180 { "A_SIG", N_("Insert signature") },
181 { "A_EXTEDITOR", N_("Edit with external editor") },
182 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
183 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
184 { "A_ADDRBOOK", N_("Address book") },
186 { "A_CHECK_SPELLING", N_("Check spelling") },
188 { "A_SYL_ACTIONS", N_("Sylpheed Actions Feature") },
189 { "A_SEPARATOR", "Separator" }
192 /* struct holds configuration files and a list of
193 * currently active toolbar items
194 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
198 const gchar *conf_file;
200 } toolbar_config[3] = {
201 { "toolbar_main.xml", NULL},
202 { "toolbar_compose.xml", NULL},
203 { "toolbar_msgview.xml", NULL}
206 static GtkItemFactoryEntry reply_entries[] =
208 {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
209 {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
211 static GtkItemFactoryEntry replyall_entries[] =
213 {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
214 {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
216 static GtkItemFactoryEntry replylist_entries[] =
218 {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
219 {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
221 static GtkItemFactoryEntry replysender_entries[] =
223 {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
224 {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
226 static GtkItemFactoryEntry forward_entries[] =
228 {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
229 {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
230 {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, NULL}
234 gint toolbar_ret_val_from_descr(const gchar *descr)
238 for (i = 0; i < N_ACTION_VAL; i++) {
239 if (g_strcasecmp(gettext(toolbar_text[i].descr), descr) == 0)
246 gchar *toolbar_ret_descr_from_val(gint val)
248 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
250 return gettext(toolbar_text[val].descr);
253 static gint toolbar_ret_val_from_text(const gchar *text)
257 for (i = 0; i < N_ACTION_VAL; i++) {
258 if (g_strcasecmp(toolbar_text[i].index_str, text) == 0)
265 static gchar *toolbar_ret_text_from_val(gint val)
267 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
269 return toolbar_text[val].index_str;
272 gboolean toolbar_is_duplicate(gint action, ToolbarType source)
276 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
279 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
280 ToolbarItem *item = (ToolbarItem*) cur->data;
282 if (item->index == action)
288 /* depending on toolbar type this function
289 returns a list of available toolbar events being
290 displayed by prefs_toolbar
292 GList *toolbar_get_action_items(ToolbarType source)
297 if (source == TOOLBAR_MAIN) {
298 gint main_items[] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
299 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
300 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
301 A_DELETE, A_EXECUTE, A_GOTO_NEXT,
302 A_IGNORE_THREAD, A_PRINT,
303 A_ADDRBOOK, A_SYL_ACTIONS };
305 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
306 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
307 if (main_items[i] == A_PRINT) {
308 g_print("$$$ descr %s, trans %s\n",
309 toolbar_text[main_items[i]].descr,
310 gettext(toolbar_text[main_items[i]].descr));
314 else if (source == TOOLBAR_COMPOSE) {
315 gint comp_items[] = { A_SEND, A_SENDL, A_DRAFT,
316 A_INSERT, A_ATTACH, A_SIG,
317 A_EXTEDITOR, A_LINEWRAP_CURRENT,
318 A_LINEWRAP_ALL, A_ADDRBOOK,
324 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
325 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
327 else if (source == TOOLBAR_MSGVIEW) {
328 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
329 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
330 A_DELETE, A_GOTO_NEXT, A_ADDRBOOK,
333 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
334 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
340 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
344 ToolbarItem *item = NULL;
346 attr = xml_get_current_tag_attr(file);
347 item = g_new0(ToolbarItem, 1);
349 name = ((XMLAttr *)attr->data)->name;
350 value = ((XMLAttr *)attr->data)->value;
352 if (g_strcasecmp(name, TOOLBAR_ICON_FILE) == 0)
353 item->file = g_strdup (value);
354 else if (g_strcasecmp(name, TOOLBAR_ICON_TEXT) == 0)
355 item->text = g_strdup (value);
356 else if (g_strcasecmp(name, TOOLBAR_ICON_ACTION) == 0)
357 item->index = toolbar_ret_val_from_text(value);
359 attr = g_list_next(attr);
361 if (item->index != -1) {
363 if (!toolbar_is_duplicate(item->index, source))
364 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
369 static void toolbar_set_default_main(void)
375 } default_toolbar[] = {
376 { A_RECEIVE_CUR, STOCK_PIXMAP_MAIL_RECEIVE, _("Get") },
377 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get All") },
378 { A_SEPARATOR, 0, ("") },
379 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
380 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Email") },
381 { A_SEPARATOR, 0, ("") },
382 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
383 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
384 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
385 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
386 { A_SEPARATOR, 0, ("") },
387 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
388 { A_EXECUTE, STOCK_PIXMAP_EXEC, _("Execute") },
389 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
394 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
396 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
398 if (default_toolbar[i].action != A_SEPARATOR) {
400 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
402 toolbar_item->file = g_strdup(file);
403 toolbar_item->index = default_toolbar[i].action;
404 toolbar_item->text = g_strdup(default_toolbar[i].text);
407 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
408 toolbar_item->index = A_SEPARATOR;
411 if (toolbar_item->index != -1) {
412 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
413 toolbar_config[TOOLBAR_MAIN].item_list =
414 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
419 static void toolbar_set_default_compose(void)
425 } default_toolbar[] = {
426 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
427 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
428 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
429 { A_SEPARATOR, 0, ("") },
430 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
431 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
432 { A_SIG, STOCK_PIXMAP_MAIL_SIGN, _("Signature") },
433 { A_SEPARATOR, 0, ("") },
434 { A_EXTEDITOR, STOCK_PIXMAP_EDIT_EXTERN, _("Editor") },
435 { A_LINEWRAP_CURRENT, STOCK_PIXMAP_LINEWRAP_CURRENT, _("Wrap paragraph") },
436 { A_LINEWRAP_ALL, STOCK_PIXMAP_LINEWRAP_ALL, _("Wrap all") },
437 { A_SEPARATOR, 0, ("") },
438 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
443 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
445 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
447 if (default_toolbar[i].action != A_SEPARATOR) {
449 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
451 toolbar_item->file = g_strdup(file);
452 toolbar_item->index = default_toolbar[i].action;
453 toolbar_item->text = g_strdup(default_toolbar[i].text);
456 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
457 toolbar_item->index = A_SEPARATOR;
460 if (toolbar_item->index != -1) {
461 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
462 toolbar_config[TOOLBAR_COMPOSE].item_list =
463 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
468 static void toolbar_set_default_msgview(void)
474 } default_toolbar[] = {
475 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
476 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
477 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
478 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
479 { A_SEPARATOR, 0, ("") },
480 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
481 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
486 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
488 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
490 if (default_toolbar[i].action != A_SEPARATOR) {
492 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
494 toolbar_item->file = g_strdup(file);
495 toolbar_item->index = default_toolbar[i].action;
496 toolbar_item->text = g_strdup(default_toolbar[i].text);
499 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
500 toolbar_item->index = A_SEPARATOR;
503 if (toolbar_item->index != -1) {
504 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
505 toolbar_config[TOOLBAR_MSGVIEW].item_list =
506 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
511 void toolbar_set_default(ToolbarType source)
513 if (source == TOOLBAR_MAIN)
514 toolbar_set_default_main();
515 else if (source == TOOLBAR_COMPOSE)
516 toolbar_set_default_compose();
517 else if (source == TOOLBAR_MSGVIEW)
518 toolbar_set_default_msgview();
521 void toolbar_save_config_file(ToolbarType source)
526 gchar *fileSpec = NULL;
528 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
530 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
531 pfile = prefs_write_open(fileSpec);
535 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
536 conv_get_current_charset_str());
538 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
540 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
541 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
544 if (toolbar_item->index != A_SEPARATOR) {
545 fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
547 TOOLBAR_ICON_FILE, toolbar_item->file,
549 xml_file_put_escape_str(fp, toolbar_item->text);
550 fprintf(fp, "\" %s=\"%s\"/>\n",
552 toolbar_ret_text_from_val(toolbar_item->index));
554 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
558 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
560 if (prefs_file_close (pfile) < 0 )
561 g_warning("failed to write toolbar configuration to file\n");
563 g_warning("failed to open toolbar configuration file for writing\n");
566 void toolbar_read_config_file(ToolbarType source)
568 XMLFile *file = NULL;
569 gchar *fileSpec = NULL;
574 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
576 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
577 file = xml_open_file(fileSpec);
580 toolbar_clear_list(source);
584 || (xml_get_dtd(file))
585 || (xml_parse_next_tag(file))
586 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
587 xml_close_file(file);
591 attr = xml_get_current_tag_attr(file);
598 if (xml_parse_next_tag(file))
601 /* Get next tag (icon, icon_text or icon_action) */
602 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
603 toolbar_parse_item(file, source);
604 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
605 ToolbarItem *item = g_new0(ToolbarItem, 1);
607 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
608 item->index = A_SEPARATOR;
609 toolbar_config[source].item_list =
610 g_slist_append(toolbar_config[source].item_list, item);
614 xml_close_file(file);
617 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
619 if (source == TOOLBAR_MAIN)
620 toolbar_set_default(TOOLBAR_MAIN);
621 else if (source == TOOLBAR_COMPOSE)
622 toolbar_set_default(TOOLBAR_COMPOSE);
623 else if (source == TOOLBAR_MSGVIEW)
624 toolbar_set_default(TOOLBAR_MSGVIEW);
626 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
630 toolbar_save_config_file(source);
635 * clears list of toolbar items read from configuration files
637 void toolbar_clear_list(ToolbarType source)
639 while (toolbar_config[source].item_list != NULL) {
640 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
642 toolbar_config[source].item_list =
643 g_slist_remove(toolbar_config[source].item_list, item);
651 g_slist_free(toolbar_config[source].item_list);
656 * return list of Toolbar items
658 GSList *toolbar_get_list(ToolbarType source)
662 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
663 list = toolbar_config[source].item_list;
668 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
670 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
672 toolbar_item->file = g_strdup(t_item->file);
673 toolbar_item->text = g_strdup(t_item->text);
674 toolbar_item->index = t_item->index;
676 toolbar_config[source].item_list =
677 g_slist_append(toolbar_config[source].item_list,
681 void toolbar_action_execute(GtkWidget *widget,
687 gchar *action, *action_p;
688 gboolean found = FALSE;
691 for (cur = action_list; cur != NULL; cur = cur->next) {
692 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
694 if (widget == act->widget) {
696 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
697 action = g_strdup((gchar*)lop->data);
699 action_p = strstr(action, ": ");
701 if (g_strcasecmp(act->name, action) == 0) {
715 actions_execute(data, i, widget, source);
717 g_warning ("Error: did not find Sylpheed Action to execute");
720 static void activate_compose_button (Toolbar *toolbar,
722 ComposeButtonType type)
724 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
727 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
728 : toolbar->compose_news_btn);
729 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
730 : toolbar->compose_mail_btn);
731 toolbar->compose_btn_type = type;
734 void toolbar_set_compose_button(Toolbar *toolbar,
735 ComposeButtonType compose_btn_type)
737 if (toolbar->compose_btn_type != compose_btn_type)
738 activate_compose_button(toolbar,
739 prefs_common.toolbar_style,
743 void toolbar_toggle(guint action, gpointer data)
745 MainWindow *mainwin = (MainWindow*)data;
749 g_return_if_fail(mainwin != NULL);
751 toolbar_style(TOOLBAR_MAIN, action, mainwin);
753 list = compose_get_compose_list();
754 for (cur = list; cur != NULL; cur = cur->next) {
755 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
757 list = messageview_get_msgview_list();
758 for (cur = list; cur != NULL; cur = cur->next) {
759 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
764 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
766 switch ((ToolbarStyle)action) {
768 gtk_widget_hide(handlebox_wid);
771 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
775 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
779 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
786 prefs_common.toolbar_style = (ToolbarStyle)action;
787 gtk_widget_set_usize(handlebox_wid, 1, -1);
789 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
790 gtk_widget_show(handlebox_wid);
791 gtk_widget_queue_resize(handlebox_wid);
795 * Change the style of toolbar
797 static void toolbar_style(ToolbarType type, guint action, gpointer data)
799 GtkWidget *handlebox_wid;
800 GtkWidget *toolbar_wid;
801 MainWindow *mainwin = (MainWindow*)data;
802 Compose *compose = (Compose*)data;
803 MessageView *msgview = (MessageView*)data;
805 g_return_if_fail(data != NULL);
809 handlebox_wid = mainwin->handlebox;
810 toolbar_wid = mainwin->toolbar->toolbar;
812 case TOOLBAR_COMPOSE:
813 handlebox_wid = compose->handlebox;
814 toolbar_wid = compose->toolbar->toolbar;
816 case TOOLBAR_MSGVIEW:
817 handlebox_wid = msgview->handlebox;
818 toolbar_wid = msgview->toolbar->toolbar;
824 toolbar_set_style(toolbar_wid, handlebox_wid, action);
827 /* Toolbar handling */
828 static void toolbar_inc_cb(GtkWidget *widget,
831 ToolbarItem *toolbar_item = (ToolbarItem*)data;
834 g_return_if_fail(toolbar_item != NULL);
836 switch (toolbar_item->type) {
838 mainwin = (MainWindow*)toolbar_item->parent;
839 inc_mail_cb(mainwin, 0, NULL);
846 static void toolbar_inc_all_cb(GtkWidget *widget,
849 ToolbarItem *toolbar_item = (ToolbarItem*)data;
852 g_return_if_fail(toolbar_item != NULL);
854 switch (toolbar_item->type) {
856 mainwin = (MainWindow*)toolbar_item->parent;
857 inc_all_account_mail_cb(mainwin, 0, NULL);
864 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
866 ToolbarItem *toolbar_item = (ToolbarItem*)data;
869 g_return_if_fail(toolbar_item != NULL);
871 switch (toolbar_item->type) {
873 mainwin = (MainWindow*)toolbar_item->parent;
874 send_queue_cb(mainwin, 0, NULL);
881 static void toolbar_exec_cb(GtkWidget *widget,
884 MainWindow *mainwin = get_mainwin(data);
886 g_return_if_fail(mainwin != NULL);
887 summary_execute(mainwin->summaryview);
891 * Delete current/selected(s) message(s)
893 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
895 ToolbarItem *toolbar_item = (ToolbarItem*)data;
898 g_return_if_fail(toolbar_item != NULL);
899 g_return_if_fail(toolbar_item->parent);
901 switch (toolbar_item->type) {
902 case TOOLBAR_MSGVIEW:
903 messageview_delete((MessageView *)toolbar_item->parent);
906 mainwin = (MainWindow *)toolbar_item->parent;
907 summary_delete(mainwin->summaryview);
910 debug_print("toolbar event not supported\n");
917 * Compose new message
919 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
921 ToolbarItem *toolbar_item = (ToolbarItem*)data;
923 MessageView *msgview;
925 g_return_if_fail(toolbar_item != NULL);
927 switch (toolbar_item->type) {
929 mainwin = (MainWindow*)toolbar_item->parent;
930 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
931 compose_news_cb(mainwin, 0, NULL);
933 compose_mail_cb(mainwin, 0, NULL);
935 case TOOLBAR_MSGVIEW:
936 msgview = (MessageView*)toolbar_item->parent;
937 compose_new_with_folderitem(NULL,
938 msgview->msginfo->folder);
941 debug_print("toolbar event not supported\n");
945 static void toolbar_popup_cb(gpointer data, guint action, GtkWidget *widget)
947 toolbar_reply(data, action);
954 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
956 toolbar_reply(data, prefs_common.reply_with_quote ?
957 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
962 * Reply message to Sender and All recipients
964 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
967 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
968 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
973 * Reply to Mailing List
975 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
978 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
979 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
984 * Reply to sender of message
986 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
989 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
990 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
996 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
998 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1001 g_return_if_fail(toolbar_item != NULL);
1003 switch (toolbar_item->type) {
1005 case TOOLBAR_MSGVIEW:
1008 case TOOLBAR_COMPOSE:
1009 compose = (Compose *)toolbar_item->parent;
1014 addressbook_open(compose);
1019 * Forward current/selected(s) message(s)
1021 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1023 toolbar_reply(data, COMPOSE_FORWARD);
1028 * Goto Next Unread Message
1030 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1032 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1033 MainWindow *mainwin;
1034 MessageView *msgview;
1036 g_return_if_fail(toolbar_item != NULL);
1038 switch (toolbar_item->type) {
1040 mainwin = (MainWindow*)toolbar_item->parent;
1041 summary_select_next_unread(mainwin->summaryview);
1044 case TOOLBAR_MSGVIEW:
1045 msgview = (MessageView*)toolbar_item->parent;
1046 summary_select_next_unread(msgview->mainwin->summaryview);
1048 /* Now we need to update the messageview window */
1049 if (msgview->mainwin->summaryview->selected) {
1050 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1052 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1053 msgview->mainwin->summaryview->selected);
1055 messageview_show(msgview, msginfo,
1056 msgview->all_headers);
1058 gtk_widget_destroy(msgview->window);
1062 debug_print("toolbar event not supported\n");
1066 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1068 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1069 MainWindow *mainwin;
1071 g_return_if_fail(toolbar_item != NULL);
1073 switch (toolbar_item->type) {
1075 mainwin = (MainWindow *) toolbar_item->parent;
1076 summary_toggle_ignore_thread(mainwin->summaryview);
1078 case TOOLBAR_MSGVIEW:
1079 /* TODO: see toolbar_next_unread_cb() if you need
1080 * this in the message view */
1083 debug_print("toolbar event not supported\n");
1088 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1090 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1091 MainWindow *mainwin;
1093 g_return_if_fail(toolbar_item != NULL);
1095 switch (toolbar_item->type) {
1097 mainwin = (MainWindow *) toolbar_item->parent;
1098 summary_print(mainwin->summaryview);
1100 case TOOLBAR_MSGVIEW:
1101 /* TODO: see toolbar_next_unread_cb() if you need
1102 * this in the message view */
1105 debug_print("toolbar event not supported\n");
1110 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1112 compose_toolbar_cb(A_SEND, data);
1115 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1117 compose_toolbar_cb(A_SENDL, data);
1120 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1122 compose_toolbar_cb(A_DRAFT, data);
1125 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1127 compose_toolbar_cb(A_INSERT, data);
1130 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1132 compose_toolbar_cb(A_ATTACH, data);
1135 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1137 compose_toolbar_cb(A_SIG, data);
1140 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1142 compose_toolbar_cb(A_EXTEDITOR, data);
1145 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1147 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1150 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1152 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1156 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1158 compose_toolbar_cb(A_CHECK_SPELLING, data);
1162 * Execute actions from toolbar
1164 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1166 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1167 GSList *action_list;
1168 MainWindow *mainwin;
1170 MessageView *msgview;
1171 gpointer parent = toolbar_item->parent;
1173 g_return_if_fail(toolbar_item != NULL);
1175 switch (toolbar_item->type) {
1177 mainwin = (MainWindow*)parent;
1178 action_list = mainwin->toolbar->action_list;
1180 case TOOLBAR_COMPOSE:
1181 compose = (Compose*)parent;
1182 action_list = compose->toolbar->action_list;
1184 case TOOLBAR_MSGVIEW:
1185 msgview = (MessageView*)parent;
1186 action_list = msgview->toolbar->action_list;
1189 debug_print("toolbar event not supported\n");
1192 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1195 static MainWindow *get_mainwin(gpointer data)
1197 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1198 MainWindow *mainwin = NULL;
1199 MessageView *msgview;
1201 g_return_val_if_fail(toolbar_item != NULL, NULL);
1203 switch(toolbar_item->type) {
1205 mainwin = (MainWindow*)toolbar_item->parent;
1207 case TOOLBAR_MSGVIEW:
1208 msgview = (MessageView*)toolbar_item->parent;
1209 mainwin = (MainWindow*)msgview->mainwin;
1218 static GtkWidget *get_window_widget(ToolbarType type, gpointer data)
1220 MainWindow *mainwin;
1221 MessageView *msgview;
1225 mainwin = (MainWindow*)data;
1226 return mainwin->window;
1228 case TOOLBAR_MSGVIEW:
1229 msgview = (MessageView*)data;
1230 return msgview->vbox;
1238 static void toolbar_buttons_cb(GtkWidget *widget,
1245 void (*func)(GtkWidget *widget, gpointer data);
1247 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1248 { A_RECEIVE_CUR, toolbar_inc_cb },
1249 { A_SEND_QUEUED, toolbar_send_queued_cb },
1250 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1251 { A_COMPOSE_NEWS, toolbar_compose_cb },
1252 { A_REPLY_MESSAGE, toolbar_reply_cb },
1253 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1254 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1255 { A_REPLY_ML, toolbar_reply_to_list_cb },
1256 { A_FORWARD, toolbar_forward_cb },
1257 { A_DELETE, toolbar_delete_cb },
1258 { A_EXECUTE, toolbar_exec_cb },
1259 { A_GOTO_NEXT, toolbar_next_unread_cb },
1260 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1261 { A_PRINT, toolbar_print_cb },
1263 { A_SEND, toolbar_send_cb },
1264 { A_SENDL, toolbar_send_later_cb },
1265 { A_DRAFT, toolbar_draft_cb },
1266 { A_INSERT, toolbar_insert_cb },
1267 { A_ATTACH, toolbar_attach_cb },
1268 { A_SIG, toolbar_sig_cb },
1269 { A_EXTEDITOR, toolbar_ext_editor_cb },
1270 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1271 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1272 { A_ADDRBOOK, toolbar_addrbook_cb },
1274 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1276 { A_SYL_ACTIONS, toolbar_actions_execute_cb }
1279 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1281 for (i = 0; i < num_items; i++) {
1282 if (callbacks[i].index == item->index) {
1283 callbacks[i].func(widget, item);
1290 * Create a new toolbar with specified type
1291 * if a callback list is passed it will be used before the
1292 * common callback list
1294 Toolbar *toolbar_create(ToolbarType type,
1295 GtkWidget *container,
1298 ToolbarItem *toolbar_item;
1301 GtkWidget *icon_wid = NULL;
1302 GtkWidget *icon_news;
1304 GtkWidget *item_news;
1305 GtkWidget *window_wid;
1307 guint n_menu_entries;
1308 ComboButton *reply_combo;
1309 ComboButton *replyall_combo;
1310 ComboButton *replylist_combo;
1311 ComboButton *replysender_combo;
1312 ComboButton *fwd_combo;
1314 GtkTooltips *toolbar_tips;
1315 ToolbarSylpheedActions *action_item;
1317 GSList *toolbar_list;
1318 Toolbar *toolbar_data;
1321 toolbar_tips = gtk_tooltips_new();
1323 toolbar_read_config_file(type);
1324 toolbar_list = toolbar_get_list(type);
1326 toolbar_data = g_new0(Toolbar, 1);
1328 toolbar = gtk_toolbar_new();
1329 gtk_container_add(GTK_CONTAINER(container), toolbar);
1330 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1331 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1332 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1334 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1336 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1337 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1341 toolbar_item = g_new0(ToolbarItem, 1);
1342 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1343 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1344 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1345 toolbar_item->parent = data;
1346 toolbar_item->type = type;
1348 /* collect toolbar items in list to keep track */
1349 toolbar_data->item_list =
1350 g_slist_append(toolbar_data->item_list,
1353 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1354 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1358 icon_wid, G_CALLBACK(toolbar_buttons_cb),
1361 switch (toolbar_item->index) {
1364 toolbar_data->getall_btn = item;
1365 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1366 toolbar_data->getall_btn,
1367 _("Receive Mail on all Accounts"), NULL);
1370 toolbar_data->get_btn = item;
1371 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1372 toolbar_data->get_btn,
1373 _("Receive Mail on current Account"), NULL);
1376 toolbar_data->send_btn = item;
1377 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1378 toolbar_data->send_btn,
1379 _("Send Queued Message(s)"), NULL);
1381 case A_COMPOSE_EMAIL:
1382 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1383 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1387 icon_news, G_CALLBACK(toolbar_buttons_cb),
1389 toolbar_data->compose_mail_btn = item;
1390 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1391 toolbar_data->compose_mail_btn,
1392 _("Compose Email"), NULL);
1393 toolbar_data->compose_news_btn = item_news;
1394 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1395 toolbar_data->compose_news_btn,
1396 _("Compose News"), NULL);
1398 case A_REPLY_MESSAGE:
1399 toolbar_data->reply_btn = item;
1400 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1401 toolbar_data->reply_btn,
1402 _("Reply to Message"), NULL);
1403 n_menu_entries = sizeof(reply_entries) /
1404 sizeof(replysender_entries[0]);
1405 reply_combo = gtkut_combo_button_create(toolbar_data->reply_btn,
1406 reply_entries, n_menu_entries,
1407 "<Reply>", (gpointer)toolbar_item);
1408 gtk_button_set_relief(GTK_BUTTON(reply_combo->arrow),
1410 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1411 GTK_WIDGET_PTR(reply_combo),
1412 _("Reply to Message"), "Reply");
1413 toolbar_data->reply_combo = reply_combo;
1415 case A_REPLY_SENDER:
1416 toolbar_data->replysender_btn = item;
1417 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1418 toolbar_data->replysender_btn,
1419 _("Reply to Sender"), NULL);
1420 n_menu_entries = sizeof(replysender_entries) /
1421 sizeof(replysender_entries[0]);
1422 replysender_combo = gtkut_combo_button_create(toolbar_data->replysender_btn,
1423 replysender_entries, n_menu_entries,
1424 "<ReplySender>", (gpointer)toolbar_item);
1425 gtk_button_set_relief(GTK_BUTTON(replysender_combo->arrow),
1427 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1428 GTK_WIDGET_PTR(replysender_combo),
1429 _("Reply to Sender"), "ReplySender");
1430 toolbar_data->replysender_combo = replysender_combo;
1433 toolbar_data->replyall_btn = item;
1434 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1435 toolbar_data->replyall_btn,
1436 _("Reply to All"), NULL);
1437 n_menu_entries = sizeof(replyall_entries) /
1438 sizeof(replyall_entries[0]);
1439 replyall_combo = gtkut_combo_button_create(toolbar_data->replyall_btn,
1440 replyall_entries, n_menu_entries,
1441 "<ReplyAll>", (gpointer)toolbar_item);
1442 gtk_button_set_relief(GTK_BUTTON(replyall_combo->arrow),
1444 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1445 GTK_WIDGET_PTR(replyall_combo),
1446 _("Reply to All"), "ReplyAll");
1447 toolbar_data->replyall_combo = replyall_combo;
1450 toolbar_data->replylist_btn = item;
1451 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1452 toolbar_data->replylist_btn,
1453 _("Reply to Mailing-list"), NULL);
1454 n_menu_entries = sizeof(replylist_entries) /
1455 sizeof(replylist_entries[0]);
1456 replylist_combo = gtkut_combo_button_create(toolbar_data->replylist_btn,
1457 replylist_entries, n_menu_entries,
1458 "<ReplyList>", (gpointer)toolbar_item);
1459 gtk_button_set_relief(GTK_BUTTON(replylist_combo->arrow),
1461 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1462 GTK_WIDGET_PTR(replylist_combo),
1463 _("Reply to Mailing-list"), "ReplyList");
1464 toolbar_data->replylist_combo = replylist_combo;
1467 toolbar_data->fwd_btn = item;
1468 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1469 toolbar_data->fwd_btn,
1470 _("Forward Message"), NULL);
1471 n_menu_entries = sizeof(forward_entries) /
1472 sizeof(forward_entries[0]);
1473 fwd_combo = gtkut_combo_button_create(toolbar_data->fwd_btn,
1474 forward_entries, n_menu_entries,
1475 "<Forward>", (gpointer)toolbar_item);
1476 gtk_button_set_relief(GTK_BUTTON(fwd_combo->arrow),
1478 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1479 GTK_WIDGET_PTR(fwd_combo),
1480 _("Forward Message"), "Fwd");
1481 toolbar_data->fwd_combo = fwd_combo;
1484 toolbar_data->delete_btn = item;
1485 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1486 toolbar_data->delete_btn,
1487 _("Delete Message"), NULL);
1490 toolbar_data->exec_btn = item;
1491 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1492 toolbar_data->exec_btn,
1493 _("Execute"), NULL);
1496 toolbar_data->next_btn = item;
1497 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1498 toolbar_data->next_btn,
1499 _("Goto Next Message"), NULL);
1502 /* Compose Toolbar */
1504 toolbar_data->send_btn = item;
1505 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1506 toolbar_data->send_btn,
1507 _("Send Message"), NULL);
1510 toolbar_data->sendl_btn = item;
1511 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1512 toolbar_data->sendl_btn,
1513 _("Put into queue folder and send later"), NULL);
1516 toolbar_data->draft_btn = item;
1517 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1518 toolbar_data->draft_btn,
1519 _("Save to draft folder"), NULL);
1522 toolbar_data->insert_btn = item;
1523 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1524 toolbar_data->insert_btn,
1525 _("Insert file"), NULL);
1528 toolbar_data->attach_btn = item;
1529 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1530 toolbar_data->attach_btn,
1531 _("Attach file"), NULL);
1534 toolbar_data->sig_btn = item;
1535 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1536 toolbar_data->sig_btn,
1537 _("Insert signature"), NULL);
1540 toolbar_data->exteditor_btn = item;
1541 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1542 toolbar_data->exteditor_btn,
1543 _("Edit with external editor"), NULL);
1545 case A_LINEWRAP_CURRENT:
1546 toolbar_data->linewrap_current_btn = item;
1547 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1548 toolbar_data->linewrap_current_btn,
1549 _("Wrap long lines of current paragraph"), NULL);
1551 case A_LINEWRAP_ALL:
1552 toolbar_data->linewrap_all_btn = item;
1553 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1554 toolbar_data->linewrap_all_btn,
1555 _("Wrap all long lines"), NULL);
1558 toolbar_data->addrbook_btn = item;
1559 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1560 toolbar_data->addrbook_btn,
1561 _("Address book"), NULL);
1564 case A_CHECK_SPELLING:
1565 toolbar_data->spellcheck_btn = item;
1566 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1567 toolbar_data->spellcheck_btn,
1568 _("Check spelling"), NULL);
1573 action_item = g_new0(ToolbarSylpheedActions, 1);
1574 action_item->widget = item;
1575 action_item->name = g_strdup(toolbar_item->text);
1577 toolbar_data->action_list =
1578 g_slist_append(toolbar_data->action_list,
1581 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1583 action_item->name, NULL);
1585 gtk_widget_show(item);
1588 /* find and set the tool tip text */
1589 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1591 toolbar_ret_descr_from_val
1592 (toolbar_item->index),
1598 toolbar_data->toolbar = toolbar;
1599 if (type == TOOLBAR_MAIN)
1600 activate_compose_button(toolbar_data,
1601 prefs_common.toolbar_style,
1602 toolbar_data->compose_btn_type);
1604 gtk_widget_show_all(toolbar);
1606 return toolbar_data;
1610 * Free toolbar structures
1612 void toolbar_destroy(Toolbar * toolbar) {
1614 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1615 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1618 void toolbar_update(ToolbarType type, gpointer data)
1620 Toolbar *toolbar_data;
1621 GtkWidget *handlebox;
1622 MainWindow *mainwin = (MainWindow*)data;
1623 Compose *compose = (Compose*)data;
1624 MessageView *msgview = (MessageView*)data;
1628 toolbar_data = mainwin->toolbar;
1629 handlebox = mainwin->handlebox;
1631 case TOOLBAR_COMPOSE:
1632 toolbar_data = compose->toolbar;
1633 handlebox = compose->handlebox;
1635 case TOOLBAR_MSGVIEW:
1636 toolbar_data = msgview->toolbar;
1637 handlebox = msgview->handlebox;
1643 gtk_container_remove(GTK_CONTAINER(handlebox),
1644 GTK_WIDGET(toolbar_data->toolbar));
1646 toolbar_init(toolbar_data);
1647 toolbar_data = toolbar_create(type, handlebox, data);
1650 mainwin->toolbar = toolbar_data;
1652 case TOOLBAR_COMPOSE:
1653 compose->toolbar = toolbar_data;
1655 case TOOLBAR_MSGVIEW:
1656 msgview->toolbar = toolbar_data;
1660 toolbar_style(type, prefs_common.toolbar_style, data);
1662 if (type == TOOLBAR_MAIN)
1663 toolbar_main_set_sensitive((MainWindow*)data);
1666 void toolbar_main_set_sensitive(gpointer data)
1668 SensitiveCond state;
1670 MainWindow *mainwin = (MainWindow*)data;
1671 Toolbar *toolbar = mainwin->toolbar;
1673 GSList *entry_list = NULL;
1675 typedef struct _Entry Entry;
1682 #define SET_WIDGET_COND(w, c) \
1684 Entry *e = g_new0(Entry, 1); \
1687 entry_list = g_slist_append(entry_list, e); \
1690 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1691 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1692 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1693 SET_WIDGET_COND(toolbar->reply_btn,
1694 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1695 if (toolbar->reply_btn)
1696 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->reply_combo),
1697 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1698 SET_WIDGET_COND(toolbar->replyall_btn,
1699 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1700 if (toolbar->replyall_btn)
1701 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replyall_combo),
1702 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1703 SET_WIDGET_COND(toolbar->replylist_btn,
1704 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1705 if (toolbar->replylist_btn)
1706 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replylist_combo),
1707 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1708 SET_WIDGET_COND(toolbar->replysender_btn,
1709 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1710 if (toolbar->replysender_btn)
1711 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replysender_combo),
1712 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1713 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1714 if (toolbar->fwd_btn)
1715 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->fwd_combo),
1716 M_HAVE_ACCOUNT|M_TARGET_EXIST);
1718 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1719 SET_WIDGET_COND(toolbar->delete_btn,
1720 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1721 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1723 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
1724 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1726 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1729 #undef SET_WIDGET_COND
1731 state = main_window_get_current_state(mainwin);
1733 for (cur = entry_list; cur != NULL; cur = cur->next) {
1734 Entry *e = (Entry*) cur->data;
1736 if (e->widget != NULL) {
1737 sensitive = ((e->cond & state) == e->cond);
1738 gtk_widget_set_sensitive(e->widget, sensitive);
1742 while (entry_list != NULL) {
1743 Entry *e = (Entry*) entry_list->data;
1747 entry_list = g_slist_remove(entry_list, e);
1750 g_slist_free(entry_list);
1752 activate_compose_button(toolbar,
1753 prefs_common.toolbar_style,
1754 toolbar->compose_btn_type);
1757 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1759 Compose *compose = (Compose*)data;
1760 GSList *items = compose->toolbar->action_list;
1762 if (compose->toolbar->send_btn)
1763 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1764 if (compose->toolbar->sendl_btn)
1765 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1766 if (compose->toolbar->draft_btn )
1767 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1768 if (compose->toolbar->insert_btn )
1769 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1770 if (compose->toolbar->attach_btn)
1771 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1772 if (compose->toolbar->sig_btn)
1773 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1774 if (compose->toolbar->exteditor_btn)
1775 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1776 if (compose->toolbar->linewrap_current_btn)
1777 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
1778 if (compose->toolbar->linewrap_all_btn)
1779 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
1780 if (compose->toolbar->addrbook_btn)
1781 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1783 if (compose->toolbar->spellcheck_btn)
1784 gtk_widget_set_sensitive(compose->toolbar->spellcheck_btn, sensitive);
1786 for (; items != NULL; items = g_slist_next(items)) {
1787 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1788 gtk_widget_set_sensitive(item->widget, sensitive);
1793 * Initialize toolbar structure
1795 void toolbar_init(Toolbar * toolbar) {
1797 toolbar->toolbar = NULL;
1798 toolbar->get_btn = NULL;
1799 toolbar->getall_btn = NULL;
1800 toolbar->send_btn = NULL;
1801 toolbar->compose_mail_btn = NULL;
1802 toolbar->compose_news_btn = NULL;
1803 toolbar->reply_btn = NULL;
1804 toolbar->replysender_btn = NULL;
1805 toolbar->replyall_btn = NULL;
1806 toolbar->replylist_btn = NULL;
1807 toolbar->fwd_btn = NULL;
1808 toolbar->delete_btn = NULL;
1809 toolbar->next_btn = NULL;
1810 toolbar->exec_btn = NULL;
1812 /* compose buttons */
1813 toolbar->sendl_btn = NULL;
1814 toolbar->draft_btn = NULL;
1815 toolbar->insert_btn = NULL;
1816 toolbar->attach_btn = NULL;
1817 toolbar->sig_btn = NULL;
1818 toolbar->exteditor_btn = NULL;
1819 toolbar->linewrap_current_btn = NULL;
1820 toolbar->linewrap_all_btn = NULL;
1821 toolbar->addrbook_btn = NULL;
1823 toolbar->spellcheck_btn = NULL;
1826 toolbar_destroy(toolbar);
1831 static void toolbar_reply(gpointer data, guint action)
1833 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1834 MainWindow *mainwin;
1835 MessageView *msgview;
1836 GSList *msginfo_list = NULL;
1839 g_return_if_fail(toolbar_item != NULL);
1841 switch (toolbar_item->type) {
1843 mainwin = (MainWindow*)toolbar_item->parent;
1844 msginfo_list = summary_get_selection(mainwin->summaryview);
1845 msgview = (MessageView*)mainwin->messageview;
1847 case TOOLBAR_MSGVIEW:
1848 msgview = (MessageView*)toolbar_item->parent;
1849 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
1855 g_return_if_fail(msgview != NULL);
1856 body = messageview_get_selection(msgview);
1858 g_return_if_fail(msginfo_list != NULL);
1859 compose_reply_mode((ComposeMode)action, msginfo_list, body);
1862 g_slist_free(msginfo_list);
1864 /* TODO: update reply state ion summaryview */
1868 /* exported functions */
1870 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
1872 MainWindow *mainwin = (MainWindow*)data;
1874 inc_mail(mainwin, prefs_common.newmail_notify_manu);
1877 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
1879 MainWindow *mainwin = (MainWindow*)data;
1881 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
1884 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
1888 if (prefs_common.work_offline)
1889 if (alertpanel(_("Offline warning"),
1890 _("You're working offline. Override?"),
1891 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1894 for (list = folder_get_list(); list != NULL; list = list->next) {
1895 Folder *folder = list->data;
1897 if (folder->queue) {
1898 procmsg_send_queue(folder->queue, prefs_common.savemsg);
1899 folder_item_scan(folder->queue);
1904 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
1906 MainWindow *mainwin = (MainWindow*)data;
1907 PrefsAccount *ac = NULL;
1908 FolderItem *item = mainwin->summaryview->folder_item;
1913 ac = account_find_from_item(item);
1914 if (ac && ac->protocol != A_NNTP) {
1915 compose_new_with_folderitem(ac, item); /* CLAWS */
1921 * CLAWS - use current account
1923 if (cur_account && (cur_account->protocol != A_NNTP)) {
1924 compose_new_with_folderitem(cur_account, item);
1929 * CLAWS - just get the first one
1931 list = account_get_list();
1932 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
1933 ac = (PrefsAccount *) cur->data;
1934 if (ac->protocol != A_NNTP) {
1935 compose_new_with_folderitem(ac, item);
1941 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
1943 MainWindow *mainwin = (MainWindow*)data;
1944 PrefsAccount * ac = NULL;
1948 if (mainwin->summaryview->folder_item) {
1949 ac = mainwin->summaryview->folder_item->folder->account;
1950 if (ac && ac->protocol == A_NNTP) {
1952 mainwin->summaryview->folder_item->path,
1958 list = account_get_list();
1959 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
1960 ac = (PrefsAccount *) cur->data;
1961 if (ac->protocol == A_NNTP) {
1962 compose_new(ac, NULL, NULL);