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 MainWindow *get_mainwin (gpointer data);
85 static void activate_compose_button (Toolbar *toolbar,
87 ComposeButtonType type);
89 /* toolbar callbacks */
90 static void toolbar_reply (gpointer data,
92 static void toolbar_delete_cb (GtkWidget *widget,
95 static void toolbar_compose_cb (GtkWidget *widget,
98 static void toolbar_reply_cb (GtkWidget *widget,
101 static void toolbar_reply_to_all_cb (GtkWidget *widget,
104 static void toolbar_reply_to_list_cb (GtkWidget *widget,
107 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
110 static void toolbar_forward_cb (GtkWidget *widget,
113 static void toolbar_next_unread_cb (GtkWidget *widget,
116 static void toolbar_ignore_thread_cb (GtkWidget *widget,
119 static void toolbar_print_cb (GtkWidget *widget,
122 static void toolbar_actions_execute_cb (GtkWidget *widget,
126 static void toolbar_send_cb (GtkWidget *widget,
128 static void toolbar_send_later_cb (GtkWidget *widget,
130 static void toolbar_draft_cb (GtkWidget *widget,
132 static void toolbar_insert_cb (GtkWidget *widget,
134 static void toolbar_attach_cb (GtkWidget *widget,
136 static void toolbar_sig_cb (GtkWidget *widget,
138 static void toolbar_ext_editor_cb (GtkWidget *widget,
140 static void toolbar_linewrap_current_cb (GtkWidget *widget,
142 static void toolbar_linewrap_all_cb (GtkWidget *widget,
144 static void toolbar_addrbook_cb (GtkWidget *widget,
147 static void toolbar_check_spelling_cb (GtkWidget *widget,
154 } toolbar_text [] = {
155 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
156 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
157 { "A_SEND_QUEUED", N_("Send Queued Message(s)") },
158 { "A_COMPOSE_EMAIL", N_("Compose Email") },
159 { "A_COMPOSE_NEWS", N_("Compose News") },
160 { "A_REPLY_MESSAGE", N_("Reply to Message") },
161 { "A_REPLY_SENDER", N_("Reply to Sender") },
162 { "A_REPLY_ALL", N_("Reply to All") },
163 { "A_REPLY_ML", N_("Reply to Mailing-list") },
164 { "A_FORWARD", N_("Forward Message") },
165 { "A_DELETE", N_("Delete Message") },
166 { "A_EXECUTE", N_("Execute") },
167 { "A_GOTO_NEXT", N_("Goto Next Message") },
168 { "A_IGNORE_THREAD", N_("Ignore thread") },
169 { "A_PRINT", N_("Print") },
171 { "A_SEND", N_("Send Message") },
172 { "A_SENDL", N_("Put into queue folder and send later") },
173 { "A_DRAFT", N_("Save to draft folder") },
174 { "A_INSERT", N_("Insert file") },
175 { "A_ATTACH", N_("Attach file") },
176 { "A_SIG", N_("Insert signature") },
177 { "A_EXTEDITOR", N_("Edit with external editor") },
178 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
179 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
180 { "A_ADDRBOOK", N_("Address book") },
182 { "A_CHECK_SPELLING", N_("Check spelling") },
184 { "A_SYL_ACTIONS", N_("Sylpheed Actions Feature") },
185 { "A_SEPARATOR", "Separator" }
188 /* struct holds configuration files and a list of
189 * currently active toolbar items
190 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
194 const gchar *conf_file;
196 } toolbar_config[3] = {
197 { "toolbar_main.xml", NULL},
198 { "toolbar_compose.xml", NULL},
199 { "toolbar_msgview.xml", NULL}
202 static GtkItemFactoryEntry reply_entries[] =
204 {N_("/Reply with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITH_QUOTE, NULL},
205 {N_("/_Reply without quote"), NULL, toolbar_reply, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
207 static GtkItemFactoryEntry replyall_entries[] =
209 {N_("/Reply to all with _quote"), "<shift>A", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
210 {N_("/_Reply to all without quote"), "a", toolbar_reply, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
212 static GtkItemFactoryEntry replylist_entries[] =
214 {N_("/Reply to list with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
215 {N_("/_Reply to list without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
217 static GtkItemFactoryEntry replysender_entries[] =
219 {N_("/Reply to sender with _quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
220 {N_("/_Reply to sender without quote"), NULL, toolbar_reply, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
222 static GtkItemFactoryEntry forward_entries[] =
224 {N_("/_Forward"), "f", toolbar_reply, COMPOSE_FORWARD_INLINE, NULL},
225 {N_("/For_ward as attachment"), "<shift>F", toolbar_reply, COMPOSE_FORWARD_AS_ATTACH, NULL},
226 {N_("/Redirec_t"), NULL, toolbar_reply, COMPOSE_REDIRECT, 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_CURRENT,
314 A_LINEWRAP_ALL, A_ADDRBOOK,
320 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
321 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
323 else if (source == TOOLBAR_MSGVIEW) {
324 gint msgv_items[] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
325 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
326 A_DELETE, A_GOTO_NEXT, A_ADDRBOOK,
329 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
330 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
336 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
340 ToolbarItem *item = NULL;
342 attr = xml_get_current_tag_attr(file);
343 item = g_new0(ToolbarItem, 1);
345 name = ((XMLAttr *)attr->data)->name;
346 value = ((XMLAttr *)attr->data)->value;
348 if (g_strcasecmp(name, TOOLBAR_ICON_FILE) == 0)
349 item->file = g_strdup (value);
350 else if (g_strcasecmp(name, TOOLBAR_ICON_TEXT) == 0)
351 item->text = g_strdup (value);
352 else if (g_strcasecmp(name, TOOLBAR_ICON_ACTION) == 0)
353 item->index = toolbar_ret_val_from_text(value);
355 attr = g_list_next(attr);
357 if (item->index != -1) {
359 if (!toolbar_is_duplicate(item->index, source))
360 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
365 static void toolbar_set_default_main(void)
371 } default_toolbar[] = {
372 { A_RECEIVE_CUR, STOCK_PIXMAP_MAIL_RECEIVE, _("Get") },
373 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get All") },
374 { A_SEPARATOR, 0, ("") },
375 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
376 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Email") },
377 { A_SEPARATOR, 0, ("") },
378 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
379 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
380 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
381 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
382 { A_SEPARATOR, 0, ("") },
383 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
384 { A_EXECUTE, STOCK_PIXMAP_EXEC, _("Execute") },
385 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
390 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
392 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
394 if (default_toolbar[i].action != A_SEPARATOR) {
396 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
398 toolbar_item->file = g_strdup(file);
399 toolbar_item->index = default_toolbar[i].action;
400 toolbar_item->text = g_strdup(default_toolbar[i].text);
403 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
404 toolbar_item->index = A_SEPARATOR;
407 if (toolbar_item->index != -1) {
408 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
409 toolbar_config[TOOLBAR_MAIN].item_list =
410 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
415 static void toolbar_set_default_compose(void)
421 } default_toolbar[] = {
422 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
423 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
424 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
425 { A_SEPARATOR, 0, ("") },
426 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
427 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
428 { A_SIG, STOCK_PIXMAP_MAIL_SIGN, _("Signature") },
429 { A_SEPARATOR, 0, ("") },
430 { A_EXTEDITOR, STOCK_PIXMAP_EDIT_EXTERN, _("Editor") },
431 { A_LINEWRAP_CURRENT, STOCK_PIXMAP_LINEWRAP_CURRENT, _("Wrap paragraph") },
432 { A_LINEWRAP_ALL, STOCK_PIXMAP_LINEWRAP_ALL, _("Wrap all") },
433 { A_SEPARATOR, 0, ("") },
434 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
439 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
441 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
443 if (default_toolbar[i].action != A_SEPARATOR) {
445 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
447 toolbar_item->file = g_strdup(file);
448 toolbar_item->index = default_toolbar[i].action;
449 toolbar_item->text = g_strdup(default_toolbar[i].text);
452 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
453 toolbar_item->index = A_SEPARATOR;
456 if (toolbar_item->index != -1) {
457 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
458 toolbar_config[TOOLBAR_COMPOSE].item_list =
459 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
464 static void toolbar_set_default_msgview(void)
470 } default_toolbar[] = {
471 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
472 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
473 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
474 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
475 { A_SEPARATOR, 0, ("") },
476 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
477 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
482 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
484 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
486 if (default_toolbar[i].action != A_SEPARATOR) {
488 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
490 toolbar_item->file = g_strdup(file);
491 toolbar_item->index = default_toolbar[i].action;
492 toolbar_item->text = g_strdup(default_toolbar[i].text);
495 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
496 toolbar_item->index = A_SEPARATOR;
499 if (toolbar_item->index != -1) {
500 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
501 toolbar_config[TOOLBAR_MSGVIEW].item_list =
502 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
507 void toolbar_set_default(ToolbarType source)
509 if (source == TOOLBAR_MAIN)
510 toolbar_set_default_main();
511 else if (source == TOOLBAR_COMPOSE)
512 toolbar_set_default_compose();
513 else if (source == TOOLBAR_MSGVIEW)
514 toolbar_set_default_msgview();
517 void toolbar_save_config_file(ToolbarType source)
522 gchar *fileSpec = NULL;
524 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
526 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
527 pfile = prefs_write_open(fileSpec);
531 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
532 conv_get_current_charset_str());
534 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
536 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
537 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
539 if (toolbar_item->index != A_SEPARATOR) {
540 fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
542 TOOLBAR_ICON_FILE, toolbar_item->file,
544 xml_file_put_escape_str(fp, toolbar_item->text);
545 fprintf(fp, "\" %s=\"%s\"/>\n",
547 toolbar_ret_text_from_val(toolbar_item->index));
549 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
553 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
555 if (prefs_file_close (pfile) < 0 )
556 g_warning("failed to write toolbar configuration to file\n");
558 g_warning("failed to open toolbar configuration file for writing\n");
561 void toolbar_read_config_file(ToolbarType source)
563 XMLFile *file = NULL;
564 gchar *fileSpec = NULL;
569 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
571 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
572 file = xml_open_file(fileSpec);
575 toolbar_clear_list(source);
579 || (xml_get_dtd(file))
580 || (xml_parse_next_tag(file))
581 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
582 xml_close_file(file);
586 attr = xml_get_current_tag_attr(file);
593 if (xml_parse_next_tag(file))
596 /* Get next tag (icon, icon_text or icon_action) */
597 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
598 toolbar_parse_item(file, source);
599 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
600 ToolbarItem *item = g_new0(ToolbarItem, 1);
602 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
603 item->index = A_SEPARATOR;
604 toolbar_config[source].item_list =
605 g_slist_append(toolbar_config[source].item_list, item);
609 xml_close_file(file);
612 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
614 if (source == TOOLBAR_MAIN)
615 toolbar_set_default(TOOLBAR_MAIN);
616 else if (source == TOOLBAR_COMPOSE)
617 toolbar_set_default(TOOLBAR_COMPOSE);
618 else if (source == TOOLBAR_MSGVIEW)
619 toolbar_set_default(TOOLBAR_MSGVIEW);
621 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
625 toolbar_save_config_file(source);
630 * clears list of toolbar items read from configuration files
632 void toolbar_clear_list(ToolbarType source)
634 while (toolbar_config[source].item_list != NULL) {
635 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
637 toolbar_config[source].item_list =
638 g_slist_remove(toolbar_config[source].item_list, item);
646 g_slist_free(toolbar_config[source].item_list);
651 * return list of Toolbar items
653 GSList *toolbar_get_list(ToolbarType source)
657 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
658 list = toolbar_config[source].item_list;
663 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
665 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
667 toolbar_item->file = g_strdup(t_item->file);
668 toolbar_item->text = g_strdup(t_item->text);
669 toolbar_item->index = t_item->index;
671 toolbar_config[source].item_list =
672 g_slist_append(toolbar_config[source].item_list,
676 void toolbar_action_execute(GtkWidget *widget,
682 gchar *action, *action_p;
683 gboolean found = FALSE;
686 for (cur = action_list; cur != NULL; cur = cur->next) {
687 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
689 if (widget == act->widget) {
691 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
692 action = g_strdup((gchar*)lop->data);
694 action_p = strstr(action, ": ");
696 if (g_strcasecmp(act->name, action) == 0) {
710 actions_execute(data, i, widget, source);
712 g_warning ("Error: did not find Sylpheed Action to execute");
715 static void activate_compose_button (Toolbar *toolbar,
717 ComposeButtonType type)
719 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
722 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
723 : toolbar->compose_news_btn);
724 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
725 : toolbar->compose_mail_btn);
726 toolbar->compose_btn_type = type;
729 void toolbar_set_compose_button(Toolbar *toolbar,
730 ComposeButtonType compose_btn_type)
732 if (toolbar->compose_btn_type != compose_btn_type)
733 activate_compose_button(toolbar,
734 prefs_common.toolbar_style,
738 void toolbar_toggle(guint action, gpointer data)
740 MainWindow *mainwin = (MainWindow*)data;
744 g_return_if_fail(mainwin != NULL);
746 toolbar_style(TOOLBAR_MAIN, action, mainwin);
748 list = compose_get_compose_list();
749 for (cur = list; cur != NULL; cur = cur->next) {
750 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
752 list = messageview_get_msgview_list();
753 for (cur = list; cur != NULL; cur = cur->next) {
754 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
759 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
761 switch ((ToolbarStyle)action) {
763 gtk_widget_hide(handlebox_wid);
766 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
770 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
774 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
781 prefs_common.toolbar_style = (ToolbarStyle)action;
782 gtk_widget_set_usize(handlebox_wid, 1, -1);
784 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
785 gtk_widget_show(handlebox_wid);
786 gtk_widget_queue_resize(handlebox_wid);
790 * Change the style of toolbar
792 static void toolbar_style(ToolbarType type, guint action, gpointer data)
794 GtkWidget *handlebox_wid;
795 GtkWidget *toolbar_wid;
796 MainWindow *mainwin = (MainWindow*)data;
797 Compose *compose = (Compose*)data;
798 MessageView *msgview = (MessageView*)data;
800 g_return_if_fail(data != NULL);
804 handlebox_wid = mainwin->handlebox;
805 toolbar_wid = mainwin->toolbar->toolbar;
807 case TOOLBAR_COMPOSE:
808 handlebox_wid = compose->handlebox;
809 toolbar_wid = compose->toolbar->toolbar;
811 case TOOLBAR_MSGVIEW:
812 handlebox_wid = msgview->handlebox;
813 toolbar_wid = msgview->toolbar->toolbar;
819 toolbar_set_style(toolbar_wid, handlebox_wid, action);
822 /* Toolbar handling */
823 static void toolbar_inc_cb(GtkWidget *widget,
826 ToolbarItem *toolbar_item = (ToolbarItem*)data;
829 g_return_if_fail(toolbar_item != NULL);
831 switch (toolbar_item->type) {
833 mainwin = (MainWindow*)toolbar_item->parent;
834 inc_mail_cb(mainwin, 0, NULL);
841 static void toolbar_inc_all_cb(GtkWidget *widget,
844 ToolbarItem *toolbar_item = (ToolbarItem*)data;
847 g_return_if_fail(toolbar_item != NULL);
849 switch (toolbar_item->type) {
851 mainwin = (MainWindow*)toolbar_item->parent;
852 inc_all_account_mail_cb(mainwin, 0, NULL);
859 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
861 ToolbarItem *toolbar_item = (ToolbarItem*)data;
864 g_return_if_fail(toolbar_item != NULL);
866 switch (toolbar_item->type) {
868 mainwin = (MainWindow*)toolbar_item->parent;
869 send_queue_cb(mainwin, 0, NULL);
876 static void toolbar_exec_cb(GtkWidget *widget,
879 MainWindow *mainwin = get_mainwin(data);
881 g_return_if_fail(mainwin != NULL);
882 summary_execute(mainwin->summaryview);
886 * Delete current/selected(s) message(s)
888 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
890 ToolbarItem *toolbar_item = (ToolbarItem*)data;
893 g_return_if_fail(toolbar_item != NULL);
894 g_return_if_fail(toolbar_item->parent);
896 switch (toolbar_item->type) {
897 case TOOLBAR_MSGVIEW:
898 messageview_delete((MessageView *)toolbar_item->parent);
901 mainwin = (MainWindow *)toolbar_item->parent;
902 summary_delete(mainwin->summaryview);
905 debug_print("toolbar event not supported\n");
912 * Compose new message
914 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
916 ToolbarItem *toolbar_item = (ToolbarItem*)data;
918 MessageView *msgview;
920 g_return_if_fail(toolbar_item != NULL);
922 switch (toolbar_item->type) {
924 mainwin = (MainWindow*)toolbar_item->parent;
925 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
926 compose_news_cb(mainwin, 0, NULL);
928 compose_mail_cb(mainwin, 0, NULL);
930 case TOOLBAR_MSGVIEW:
931 msgview = (MessageView*)toolbar_item->parent;
932 compose_new_with_folderitem(NULL,
933 msgview->msginfo->folder);
936 debug_print("toolbar event not supported\n");
944 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
946 toolbar_reply(data, prefs_common.reply_with_quote ?
947 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
952 * Reply message to Sender and All recipients
954 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
957 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
958 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
963 * Reply to Mailing List
965 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
968 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
969 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
974 * Reply to sender of message
976 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
979 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
980 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
986 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
988 ToolbarItem *toolbar_item = (ToolbarItem*)data;
991 g_return_if_fail(toolbar_item != NULL);
993 switch (toolbar_item->type) {
995 case TOOLBAR_MSGVIEW:
998 case TOOLBAR_COMPOSE:
999 compose = (Compose *)toolbar_item->parent;
1004 addressbook_open(compose);
1009 * Forward current/selected(s) message(s)
1011 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1013 toolbar_reply(data, COMPOSE_FORWARD);
1018 * Goto Next Unread Message
1020 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1022 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1023 MainWindow *mainwin;
1024 MessageView *msgview;
1026 g_return_if_fail(toolbar_item != NULL);
1028 switch (toolbar_item->type) {
1030 mainwin = (MainWindow*)toolbar_item->parent;
1031 summary_select_next_unread(mainwin->summaryview);
1034 case TOOLBAR_MSGVIEW:
1035 msgview = (MessageView*)toolbar_item->parent;
1036 summary_select_next_unread(msgview->mainwin->summaryview);
1038 /* Now we need to update the messageview window */
1039 if (msgview->mainwin->summaryview->selected) {
1040 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1042 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1043 msgview->mainwin->summaryview->selected);
1045 messageview_show(msgview, msginfo,
1046 msgview->all_headers);
1048 gtk_widget_destroy(msgview->window);
1052 debug_print("toolbar event not supported\n");
1056 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1058 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1059 MainWindow *mainwin;
1061 g_return_if_fail(toolbar_item != NULL);
1063 switch (toolbar_item->type) {
1065 mainwin = (MainWindow *) toolbar_item->parent;
1066 summary_toggle_ignore_thread(mainwin->summaryview);
1068 case TOOLBAR_MSGVIEW:
1069 /* TODO: see toolbar_next_unread_cb() if you need
1070 * this in the message view */
1073 debug_print("toolbar event not supported\n");
1078 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1080 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1081 MainWindow *mainwin;
1083 g_return_if_fail(toolbar_item != NULL);
1085 switch (toolbar_item->type) {
1087 mainwin = (MainWindow *) toolbar_item->parent;
1088 summary_print(mainwin->summaryview);
1090 case TOOLBAR_MSGVIEW:
1091 /* TODO: see toolbar_next_unread_cb() if you need
1092 * this in the message view */
1095 debug_print("toolbar event not supported\n");
1100 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1102 compose_toolbar_cb(A_SEND, data);
1105 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1107 compose_toolbar_cb(A_SENDL, data);
1110 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1112 compose_toolbar_cb(A_DRAFT, data);
1115 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1117 compose_toolbar_cb(A_INSERT, data);
1120 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1122 compose_toolbar_cb(A_ATTACH, data);
1125 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1127 compose_toolbar_cb(A_SIG, data);
1130 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1132 compose_toolbar_cb(A_EXTEDITOR, data);
1135 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1137 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1140 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1142 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1146 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1148 compose_toolbar_cb(A_CHECK_SPELLING, data);
1152 * Execute actions from toolbar
1154 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1156 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1157 GSList *action_list;
1158 MainWindow *mainwin;
1160 MessageView *msgview;
1161 gpointer parent = toolbar_item->parent;
1163 g_return_if_fail(toolbar_item != NULL);
1165 switch (toolbar_item->type) {
1167 mainwin = (MainWindow*)parent;
1168 action_list = mainwin->toolbar->action_list;
1170 case TOOLBAR_COMPOSE:
1171 compose = (Compose*)parent;
1172 action_list = compose->toolbar->action_list;
1174 case TOOLBAR_MSGVIEW:
1175 msgview = (MessageView*)parent;
1176 action_list = msgview->toolbar->action_list;
1179 debug_print("toolbar event not supported\n");
1182 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1185 static MainWindow *get_mainwin(gpointer data)
1187 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1188 MainWindow *mainwin = NULL;
1189 MessageView *msgview;
1191 g_return_val_if_fail(toolbar_item != NULL, NULL);
1193 switch(toolbar_item->type) {
1195 mainwin = (MainWindow*)toolbar_item->parent;
1197 case TOOLBAR_MSGVIEW:
1198 msgview = (MessageView*)toolbar_item->parent;
1199 mainwin = (MainWindow*)msgview->mainwin;
1208 static void toolbar_buttons_cb(GtkWidget *widget,
1215 void (*func)(GtkWidget *widget, gpointer data);
1217 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1218 { A_RECEIVE_CUR, toolbar_inc_cb },
1219 { A_SEND_QUEUED, toolbar_send_queued_cb },
1220 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1221 { A_COMPOSE_NEWS, toolbar_compose_cb },
1222 { A_REPLY_MESSAGE, toolbar_reply_cb },
1223 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1224 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1225 { A_REPLY_ML, toolbar_reply_to_list_cb },
1226 { A_FORWARD, toolbar_forward_cb },
1227 { A_DELETE, toolbar_delete_cb },
1228 { A_EXECUTE, toolbar_exec_cb },
1229 { A_GOTO_NEXT, toolbar_next_unread_cb },
1230 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
1231 { A_PRINT, toolbar_print_cb },
1233 { A_SEND, toolbar_send_cb },
1234 { A_SENDL, toolbar_send_later_cb },
1235 { A_DRAFT, toolbar_draft_cb },
1236 { A_INSERT, toolbar_insert_cb },
1237 { A_ATTACH, toolbar_attach_cb },
1238 { A_SIG, toolbar_sig_cb },
1239 { A_EXTEDITOR, toolbar_ext_editor_cb },
1240 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
1241 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
1242 { A_ADDRBOOK, toolbar_addrbook_cb },
1244 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
1246 { A_SYL_ACTIONS, toolbar_actions_execute_cb }
1249 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1251 for (i = 0; i < num_items; i++) {
1252 if (callbacks[i].index == item->index) {
1253 callbacks[i].func(widget, item);
1260 * Create a new toolbar with specified type
1261 * if a callback list is passed it will be used before the
1262 * common callback list
1264 Toolbar *toolbar_create(ToolbarType type,
1265 GtkWidget *container,
1268 ToolbarItem *toolbar_item;
1271 GtkWidget *icon_wid = NULL;
1272 GtkWidget *icon_news;
1274 GtkWidget *item_news;
1276 guint n_menu_entries;
1277 ComboButton *reply_combo;
1278 ComboButton *replyall_combo;
1279 ComboButton *replylist_combo;
1280 ComboButton *replysender_combo;
1281 ComboButton *fwd_combo;
1283 GtkTooltips *toolbar_tips;
1284 ToolbarSylpheedActions *action_item;
1286 GSList *toolbar_list;
1287 Toolbar *toolbar_data;
1290 toolbar_tips = gtk_tooltips_new();
1292 toolbar_read_config_file(type);
1293 toolbar_list = toolbar_get_list(type);
1295 toolbar_data = g_new0(Toolbar, 1);
1297 toolbar = gtk_toolbar_new();
1298 gtk_container_add(GTK_CONTAINER(container), toolbar);
1299 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1300 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar), GTK_ORIENTATION_HORIZONTAL);
1301 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
1303 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1305 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1306 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1310 toolbar_item = g_new0(ToolbarItem, 1);
1311 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1312 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1313 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1314 toolbar_item->parent = data;
1315 toolbar_item->type = type;
1317 /* collect toolbar items in list to keep track */
1318 toolbar_data->item_list =
1319 g_slist_append(toolbar_data->item_list,
1322 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1323 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1327 icon_wid, G_CALLBACK(toolbar_buttons_cb),
1330 switch (toolbar_item->index) {
1333 toolbar_data->getall_btn = item;
1334 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1335 toolbar_data->getall_btn,
1336 _("Receive Mail on all Accounts"), NULL);
1339 toolbar_data->get_btn = item;
1340 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1341 toolbar_data->get_btn,
1342 _("Receive Mail on current Account"), NULL);
1345 toolbar_data->send_btn = item;
1346 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1347 toolbar_data->send_btn,
1348 _("Send Queued Message(s)"), NULL);
1350 case A_COMPOSE_EMAIL:
1351 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1352 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1356 icon_news, G_CALLBACK(toolbar_buttons_cb),
1358 toolbar_data->compose_mail_btn = item;
1359 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1360 toolbar_data->compose_mail_btn,
1361 _("Compose Email"), NULL);
1362 toolbar_data->compose_news_btn = item_news;
1363 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1364 toolbar_data->compose_news_btn,
1365 _("Compose News"), NULL);
1367 case A_REPLY_MESSAGE:
1368 toolbar_data->reply_btn = item;
1369 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1370 toolbar_data->reply_btn,
1371 _("Reply to Message"), NULL);
1372 n_menu_entries = sizeof(reply_entries) /
1373 sizeof(reply_entries[0]);
1374 reply_combo = gtkut_combo_button_create(toolbar_data->reply_btn,
1375 reply_entries, n_menu_entries,
1376 "<Reply>", (gpointer)toolbar_item);
1377 gtk_button_set_relief(GTK_BUTTON(reply_combo->arrow),
1379 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1380 GTK_WIDGET_PTR(reply_combo),
1381 _("Reply to Message"), "Reply");
1382 toolbar_data->reply_combo = reply_combo;
1384 case A_REPLY_SENDER:
1385 toolbar_data->replysender_btn = item;
1386 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1387 toolbar_data->replysender_btn,
1388 _("Reply to Sender"), NULL);
1389 n_menu_entries = sizeof(replysender_entries) /
1390 sizeof(replysender_entries[0]);
1391 replysender_combo = gtkut_combo_button_create(toolbar_data->replysender_btn,
1392 replysender_entries, n_menu_entries,
1393 "<ReplySender>", (gpointer)toolbar_item);
1394 gtk_button_set_relief(GTK_BUTTON(replysender_combo->arrow),
1396 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1397 GTK_WIDGET_PTR(replysender_combo),
1398 _("Reply to Sender"), "ReplySender");
1399 toolbar_data->replysender_combo = replysender_combo;
1402 toolbar_data->replyall_btn = item;
1403 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1404 toolbar_data->replyall_btn,
1405 _("Reply to All"), NULL);
1406 n_menu_entries = sizeof(replyall_entries) /
1407 sizeof(replyall_entries[0]);
1408 replyall_combo = gtkut_combo_button_create(toolbar_data->replyall_btn,
1409 replyall_entries, n_menu_entries,
1410 "<ReplyAll>", (gpointer)toolbar_item);
1411 gtk_button_set_relief(GTK_BUTTON(replyall_combo->arrow),
1413 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1414 GTK_WIDGET_PTR(replyall_combo),
1415 _("Reply to All"), "ReplyAll");
1416 toolbar_data->replyall_combo = replyall_combo;
1419 toolbar_data->replylist_btn = item;
1420 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1421 toolbar_data->replylist_btn,
1422 _("Reply to Mailing-list"), NULL);
1423 n_menu_entries = sizeof(replylist_entries) /
1424 sizeof(replylist_entries[0]);
1425 replylist_combo = gtkut_combo_button_create(toolbar_data->replylist_btn,
1426 replylist_entries, n_menu_entries,
1427 "<ReplyList>", (gpointer)toolbar_item);
1428 gtk_button_set_relief(GTK_BUTTON(replylist_combo->arrow),
1430 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1431 GTK_WIDGET_PTR(replylist_combo),
1432 _("Reply to Mailing-list"), "ReplyList");
1433 toolbar_data->replylist_combo = replylist_combo;
1436 toolbar_data->fwd_btn = item;
1437 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1438 toolbar_data->fwd_btn,
1439 _("Forward Message"), NULL);
1440 n_menu_entries = sizeof(forward_entries) /
1441 sizeof(forward_entries[0]);
1442 fwd_combo = gtkut_combo_button_create(toolbar_data->fwd_btn,
1443 forward_entries, n_menu_entries,
1444 "<Forward>", (gpointer)toolbar_item);
1445 gtk_button_set_relief(GTK_BUTTON(fwd_combo->arrow),
1447 gtk_toolbar_append_widget(GTK_TOOLBAR(toolbar),
1448 GTK_WIDGET_PTR(fwd_combo),
1449 _("Forward Message"), "Fwd");
1450 toolbar_data->fwd_combo = fwd_combo;
1453 toolbar_data->delete_btn = item;
1454 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1455 toolbar_data->delete_btn,
1456 _("Delete Message"), NULL);
1459 toolbar_data->exec_btn = item;
1460 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1461 toolbar_data->exec_btn,
1462 _("Execute"), NULL);
1465 toolbar_data->next_btn = item;
1466 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1467 toolbar_data->next_btn,
1468 _("Goto Next Message"), NULL);
1471 /* Compose Toolbar */
1473 toolbar_data->send_btn = item;
1474 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1475 toolbar_data->send_btn,
1476 _("Send Message"), NULL);
1479 toolbar_data->sendl_btn = item;
1480 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1481 toolbar_data->sendl_btn,
1482 _("Put into queue folder and send later"), NULL);
1485 toolbar_data->draft_btn = item;
1486 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1487 toolbar_data->draft_btn,
1488 _("Save to draft folder"), NULL);
1491 toolbar_data->insert_btn = item;
1492 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1493 toolbar_data->insert_btn,
1494 _("Insert file"), NULL);
1497 toolbar_data->attach_btn = item;
1498 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1499 toolbar_data->attach_btn,
1500 _("Attach file"), NULL);
1503 toolbar_data->sig_btn = item;
1504 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1505 toolbar_data->sig_btn,
1506 _("Insert signature"), NULL);
1509 toolbar_data->exteditor_btn = item;
1510 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1511 toolbar_data->exteditor_btn,
1512 _("Edit with external editor"), NULL);
1514 case A_LINEWRAP_CURRENT:
1515 toolbar_data->linewrap_current_btn = item;
1516 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1517 toolbar_data->linewrap_current_btn,
1518 _("Wrap long lines of current paragraph"), NULL);
1520 case A_LINEWRAP_ALL:
1521 toolbar_data->linewrap_all_btn = item;
1522 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1523 toolbar_data->linewrap_all_btn,
1524 _("Wrap all long lines"), NULL);
1527 toolbar_data->addrbook_btn = item;
1528 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1529 toolbar_data->addrbook_btn,
1530 _("Address book"), NULL);
1533 case A_CHECK_SPELLING:
1534 toolbar_data->spellcheck_btn = item;
1535 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1536 toolbar_data->spellcheck_btn,
1537 _("Check spelling"), NULL);
1542 action_item = g_new0(ToolbarSylpheedActions, 1);
1543 action_item->widget = item;
1544 action_item->name = g_strdup(toolbar_item->text);
1546 toolbar_data->action_list =
1547 g_slist_append(toolbar_data->action_list,
1550 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1552 action_item->name, NULL);
1554 gtk_widget_show(item);
1557 /* find and set the tool tip text */
1558 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1560 toolbar_ret_descr_from_val
1561 (toolbar_item->index),
1567 toolbar_data->toolbar = toolbar;
1568 if (type == TOOLBAR_MAIN)
1569 activate_compose_button(toolbar_data,
1570 prefs_common.toolbar_style,
1571 toolbar_data->compose_btn_type);
1573 gtk_widget_show_all(toolbar);
1575 return toolbar_data;
1579 * Free toolbar structures
1581 void toolbar_destroy(Toolbar * toolbar) {
1583 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1584 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1587 void toolbar_update(ToolbarType type, gpointer data)
1589 Toolbar *toolbar_data;
1590 GtkWidget *handlebox;
1591 MainWindow *mainwin = (MainWindow*)data;
1592 Compose *compose = (Compose*)data;
1593 MessageView *msgview = (MessageView*)data;
1597 toolbar_data = mainwin->toolbar;
1598 handlebox = mainwin->handlebox;
1600 case TOOLBAR_COMPOSE:
1601 toolbar_data = compose->toolbar;
1602 handlebox = compose->handlebox;
1604 case TOOLBAR_MSGVIEW:
1605 toolbar_data = msgview->toolbar;
1606 handlebox = msgview->handlebox;
1612 gtk_container_remove(GTK_CONTAINER(handlebox),
1613 GTK_WIDGET(toolbar_data->toolbar));
1615 toolbar_init(toolbar_data);
1616 toolbar_data = toolbar_create(type, handlebox, data);
1619 mainwin->toolbar = toolbar_data;
1621 case TOOLBAR_COMPOSE:
1622 compose->toolbar = toolbar_data;
1624 case TOOLBAR_MSGVIEW:
1625 msgview->toolbar = toolbar_data;
1629 toolbar_style(type, prefs_common.toolbar_style, data);
1631 if (type == TOOLBAR_MAIN)
1632 toolbar_main_set_sensitive((MainWindow*)data);
1635 void toolbar_main_set_sensitive(gpointer data)
1637 SensitiveCond state;
1639 MainWindow *mainwin = (MainWindow*)data;
1640 Toolbar *toolbar = mainwin->toolbar;
1642 GSList *entry_list = NULL;
1644 typedef struct _Entry Entry;
1651 #define SET_WIDGET_COND(w, c) \
1653 Entry *e = g_new0(Entry, 1); \
1656 entry_list = g_slist_append(entry_list, e); \
1659 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1660 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1661 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1662 SET_WIDGET_COND(toolbar->reply_btn,
1663 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1664 if (toolbar->reply_btn)
1665 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->reply_combo),
1666 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1667 SET_WIDGET_COND(toolbar->replyall_btn,
1668 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1669 if (toolbar->replyall_btn)
1670 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replyall_combo),
1671 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1672 SET_WIDGET_COND(toolbar->replylist_btn,
1673 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1674 if (toolbar->replylist_btn)
1675 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replylist_combo),
1676 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1677 SET_WIDGET_COND(toolbar->replysender_btn,
1678 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1679 if (toolbar->replysender_btn)
1680 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->replysender_combo),
1681 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1682 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1683 if (toolbar->fwd_btn)
1684 SET_WIDGET_COND(GTK_WIDGET_PTR(toolbar->fwd_combo),
1685 M_HAVE_ACCOUNT|M_TARGET_EXIST);
1687 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
1688 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1690 SET_WIDGET_COND(toolbar->next_btn, 0);
1693 SET_WIDGET_COND(toolbar->delete_btn,
1694 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1695 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1697 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
1698 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1700 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1703 #undef SET_WIDGET_COND
1705 state = main_window_get_current_state(mainwin);
1707 for (cur = entry_list; cur != NULL; cur = cur->next) {
1708 Entry *e = (Entry*) cur->data;
1710 if (e->widget != NULL) {
1711 sensitive = ((e->cond & state) == e->cond);
1712 gtk_widget_set_sensitive(e->widget, sensitive);
1716 while (entry_list != NULL) {
1717 Entry *e = (Entry*) entry_list->data;
1721 entry_list = g_slist_remove(entry_list, e);
1724 g_slist_free(entry_list);
1726 activate_compose_button(toolbar,
1727 prefs_common.toolbar_style,
1728 toolbar->compose_btn_type);
1731 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1733 Compose *compose = (Compose*)data;
1734 GSList *items = compose->toolbar->action_list;
1736 if (compose->toolbar->send_btn)
1737 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1738 if (compose->toolbar->sendl_btn)
1739 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1740 if (compose->toolbar->draft_btn )
1741 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1742 if (compose->toolbar->insert_btn )
1743 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1744 if (compose->toolbar->attach_btn)
1745 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1746 if (compose->toolbar->sig_btn)
1747 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1748 if (compose->toolbar->exteditor_btn)
1749 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1750 if (compose->toolbar->linewrap_current_btn)
1751 gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, sensitive);
1752 if (compose->toolbar->linewrap_all_btn)
1753 gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
1754 if (compose->toolbar->addrbook_btn)
1755 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1757 if (compose->toolbar->spellcheck_btn)
1758 gtk_widget_set_sensitive(compose->toolbar->spellcheck_btn, sensitive);
1760 for (; items != NULL; items = g_slist_next(items)) {
1761 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1762 gtk_widget_set_sensitive(item->widget, sensitive);
1767 * Initialize toolbar structure
1769 void toolbar_init(Toolbar * toolbar) {
1771 toolbar->toolbar = NULL;
1772 toolbar->get_btn = NULL;
1773 toolbar->getall_btn = NULL;
1774 toolbar->send_btn = NULL;
1775 toolbar->compose_mail_btn = NULL;
1776 toolbar->compose_news_btn = NULL;
1777 toolbar->reply_btn = NULL;
1778 toolbar->replysender_btn = NULL;
1779 toolbar->replyall_btn = NULL;
1780 toolbar->replylist_btn = NULL;
1781 toolbar->fwd_btn = NULL;
1782 toolbar->delete_btn = NULL;
1783 toolbar->next_btn = NULL;
1784 toolbar->exec_btn = NULL;
1786 /* compose buttons */
1787 toolbar->sendl_btn = NULL;
1788 toolbar->draft_btn = NULL;
1789 toolbar->insert_btn = NULL;
1790 toolbar->attach_btn = NULL;
1791 toolbar->sig_btn = NULL;
1792 toolbar->exteditor_btn = NULL;
1793 toolbar->linewrap_current_btn = NULL;
1794 toolbar->linewrap_all_btn = NULL;
1795 toolbar->addrbook_btn = NULL;
1797 toolbar->spellcheck_btn = NULL;
1800 toolbar_destroy(toolbar);
1805 static void toolbar_reply(gpointer data, guint action)
1807 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1808 MainWindow *mainwin;
1809 MessageView *msgview;
1810 GSList *msginfo_list = NULL;
1813 g_return_if_fail(toolbar_item != NULL);
1815 switch (toolbar_item->type) {
1817 mainwin = (MainWindow*)toolbar_item->parent;
1818 msginfo_list = summary_get_selection(mainwin->summaryview);
1819 msgview = (MessageView*)mainwin->messageview;
1821 case TOOLBAR_MSGVIEW:
1822 msgview = (MessageView*)toolbar_item->parent;
1823 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
1829 g_return_if_fail(msgview != NULL);
1830 body = messageview_get_selection(msgview);
1832 g_return_if_fail(msginfo_list != NULL);
1833 compose_reply_mode((ComposeMode)action, msginfo_list, body);
1836 g_slist_free(msginfo_list);
1838 /* TODO: update reply state ion summaryview */
1842 /* exported functions */
1844 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
1846 MainWindow *mainwin = (MainWindow*)data;
1848 inc_mail(mainwin, prefs_common.newmail_notify_manu);
1851 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
1853 MainWindow *mainwin = (MainWindow*)data;
1855 inc_all_account_mail(mainwin, FALSE, prefs_common.newmail_notify_manu);
1858 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
1862 if (prefs_common.work_offline)
1863 if (alertpanel(_("Offline warning"),
1864 _("You're working offline. Override?"),
1865 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1868 for (list = folder_get_list(); list != NULL; list = list->next) {
1869 Folder *folder = list->data;
1871 if (folder->queue) {
1872 procmsg_send_queue(folder->queue, prefs_common.savemsg);
1873 folder_item_scan(folder->queue);
1878 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
1880 MainWindow *mainwin = (MainWindow*)data;
1881 PrefsAccount *ac = NULL;
1882 FolderItem *item = mainwin->summaryview->folder_item;
1887 ac = account_find_from_item(item);
1888 if (ac && ac->protocol != A_NNTP) {
1889 compose_new_with_folderitem(ac, item); /* CLAWS */
1895 * CLAWS - use current account
1897 if (cur_account && (cur_account->protocol != A_NNTP)) {
1898 compose_new_with_folderitem(cur_account, item);
1903 * CLAWS - just get the first one
1905 list = account_get_list();
1906 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
1907 ac = (PrefsAccount *) cur->data;
1908 if (ac->protocol != A_NNTP) {
1909 compose_new_with_folderitem(ac, item);
1915 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
1917 MainWindow *mainwin = (MainWindow*)data;
1918 PrefsAccount * ac = NULL;
1922 if (mainwin->summaryview->folder_item) {
1923 ac = mainwin->summaryview->folder_item->folder->account;
1924 if (ac && ac->protocol == A_NNTP) {
1926 mainwin->summaryview->folder_item->path,
1932 list = account_get_list();
1933 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
1934 ac = (PrefsAccount *) cur->data;
1935 if (ac->protocol == A_NNTP) {
1936 compose_new(ac, NULL, NULL);