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_actions_execute_cb (GtkWidget *widget,
122 static void toolbar_send_cb (GtkWidget *widget,
124 static void toolbar_send_later_cb (GtkWidget *widget,
126 static void toolbar_draft_cb (GtkWidget *widget,
128 static void toolbar_insert_cb (GtkWidget *widget,
130 static void toolbar_attach_cb (GtkWidget *widget,
132 static void toolbar_sig_cb (GtkWidget *widget,
134 static void toolbar_ext_editor_cb (GtkWidget *widget,
136 static void toolbar_linewrap_cb (GtkWidget *widget,
138 static void toolbar_addrbook_cb (GtkWidget *widget,
141 static void toolbar_popup_cb (gpointer data,
147 } toolbar_text [] = {
148 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
149 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
150 { "A_SEND_QUEUED", N_("Send Queued Message(s)") },
151 { "A_COMPOSE_EMAIL", N_("Compose Email") },
152 { "A_COMPOSE_NEWS", N_("Compose News") },
153 { "A_REPLY_MESSAGE", N_("Reply to Message") },
154 { "A_REPLY_SENDER", N_("Reply to Sender") },
155 { "A_REPLY_ALL", N_("Reply to All") },
156 { "A_REPLY_ML", N_("Reply to Mailing-list") },
157 { "A_FORWARD", N_("Forward Message") },
158 { "A_DELETE", N_("Delete Message") },
159 { "A_EXECUTE", N_("Execute") },
160 { "A_GOTO_NEXT", N_("Goto Next Message") },
162 { "A_SEND", N_("Send Message") },
163 { "A_SENDL", N_("Put into queue folder and send later") },
164 { "A_DRAFT", N_("Save to draft folder") },
165 { "A_INSERT", N_("Insert file") },
166 { "A_ATTACH", N_("Attach file") },
167 { "A_SIG", N_("Insert signature") },
168 { "A_EXTEDITOR", N_("Edit with external editor") },
169 { "A_LINEWRAP", N_("Wrap all long lines") },
170 { "A_ADDRBOOK", N_("Address book") },
172 { "A_SYL_ACTIONS", N_("Sylpheed Actions Feature") },
173 { "A_SEPARATOR", "Separator" }
176 /* struct holds configuration files and a list of
177 * currently active toolbar items
178 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
182 const gchar *conf_file;
184 } toolbar_config[3] = {
185 { "toolbar_main.xml", NULL},
186 { "toolbar_compose.xml", NULL},
187 { "toolbar_msgview.xml", NULL}
190 static GtkItemFactoryEntry reply_popup_entries[] =
192 {N_("/Reply with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
193 {N_("/_Reply without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
195 static GtkItemFactoryEntry replyall_popup_entries[] =
197 {N_("/Reply to all with _quote"), "<shift>A", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
198 {N_("/_Reply to all without quote"), "a", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
200 static GtkItemFactoryEntry replylist_popup_entries[] =
202 {N_("/Reply to list with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
203 {N_("/_Reply to list without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
205 static GtkItemFactoryEntry replysender_popup_entries[] =
207 {N_("/Reply to sender with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
208 {N_("/_Reply to sender without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
210 static GtkItemFactoryEntry fwd_popup_entries[] =
212 {N_("/_Forward message (inline style)"), "f", toolbar_popup_cb, COMPOSE_FORWARD_INLINE, NULL},
213 {N_("/Forward message as _attachment"), "<shift>F", toolbar_popup_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
217 gint toolbar_ret_val_from_descr(const gchar *descr)
221 for (i = 0; i < N_ACTION_VAL; i++) {
222 if (g_strcasecmp(gettext(toolbar_text[i].descr), descr) == 0)
229 gchar *toolbar_ret_descr_from_val(gint val)
231 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
233 return gettext(toolbar_text[val].descr);
236 static gint toolbar_ret_val_from_text(const gchar *text)
240 for (i = 0; i < N_ACTION_VAL; i++) {
241 if (g_strcasecmp(toolbar_text[i].index_str, text) == 0)
248 static gchar *toolbar_ret_text_from_val(gint val)
250 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
252 return toolbar_text[val].index_str;
255 gboolean toolbar_is_duplicate(gint action, ToolbarType source)
259 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
262 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
263 ToolbarItem *item = (ToolbarItem*) cur->data;
265 if (item->index == action)
271 /* depending on toolbar type this function
272 returns a list of available toolbar events being
273 displayed by prefs_toolbar
275 GList *toolbar_get_action_items(ToolbarType source)
280 if (source == TOOLBAR_MAIN) {
281 gint main_items[14] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
282 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
283 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
284 A_DELETE, A_EXECUTE, A_GOTO_NEXT,
285 A_ADDRBOOK, A_SYL_ACTIONS };
287 for (i = 0; i < sizeof(main_items)/sizeof(main_items[0]); i++)
288 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
290 else if (source == TOOLBAR_COMPOSE) {
291 gint comp_items[10] = { A_SEND, A_SENDL, A_DRAFT,
292 A_INSERT, A_ATTACH, A_SIG,
293 A_EXTEDITOR, A_LINEWRAP, A_ADDRBOOK,
296 for (i = 0; i < sizeof(comp_items)/sizeof(comp_items[0]); i++)
297 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
299 else if (source == TOOLBAR_MSGVIEW) {
300 gint msgv_items[10] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
301 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
302 A_DELETE, A_GOTO_NEXT, A_ADDRBOOK,
305 for (i = 0; i < sizeof(msgv_items)/sizeof(msgv_items[0]); i++)
306 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
312 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
316 ToolbarItem *item = NULL;
318 attr = xml_get_current_tag_attr(file);
319 item = g_new0(ToolbarItem, 1);
321 name = ((XMLAttr *)attr->data)->name;
322 value = ((XMLAttr *)attr->data)->value;
324 if (g_strcasecmp(name, TOOLBAR_ICON_FILE) == 0)
325 item->file = g_strdup (value);
326 else if (g_strcasecmp(name, TOOLBAR_ICON_TEXT) == 0)
327 item->text = g_strdup (value);
328 else if (g_strcasecmp(name, TOOLBAR_ICON_ACTION) == 0)
329 item->index = toolbar_ret_val_from_text(value);
331 attr = g_list_next(attr);
333 if (item->index != -1) {
335 if (!toolbar_is_duplicate(item->index, source))
336 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
341 static void toolbar_set_default_main(void)
347 } default_toolbar[] = {
348 { A_RECEIVE_CUR, STOCK_PIXMAP_MAIL_RECEIVE, _("Get") },
349 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get All") },
350 { A_SEPARATOR, 0, ("") },
351 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
352 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Email") },
353 { A_SEPARATOR, 0, ("") },
354 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
355 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
356 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
357 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
358 { A_SEPARATOR, 0, ("") },
359 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
360 { A_EXECUTE, STOCK_PIXMAP_EXEC, _("Execute") },
361 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
366 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
368 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
370 if (default_toolbar[i].action != A_SEPARATOR) {
372 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
374 toolbar_item->file = g_strdup(file);
375 toolbar_item->index = default_toolbar[i].action;
376 toolbar_item->text = g_strdup(default_toolbar[i].text);
379 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
380 toolbar_item->index = A_SEPARATOR;
383 if (toolbar_item->index != -1) {
384 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
385 toolbar_config[TOOLBAR_MAIN].item_list =
386 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
391 static void toolbar_set_default_compose(void)
397 } default_toolbar[] = {
398 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
399 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
400 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
401 { A_SEPARATOR, 0, ("") },
402 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
403 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
404 { A_SIG, STOCK_PIXMAP_MAIL_SIGN, _("Signature") },
405 { A_SEPARATOR, 0, ("") },
406 { A_EXTEDITOR, STOCK_PIXMAP_EDIT_EXTERN, _("Editor") },
407 { A_LINEWRAP, STOCK_PIXMAP_LINEWRAP, _("Linewrap") },
408 { A_SEPARATOR, 0, ("") },
409 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
414 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
416 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
418 if (default_toolbar[i].action != A_SEPARATOR) {
420 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
422 toolbar_item->file = g_strdup(file);
423 toolbar_item->index = default_toolbar[i].action;
424 toolbar_item->text = g_strdup(default_toolbar[i].text);
427 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
428 toolbar_item->index = A_SEPARATOR;
431 if (toolbar_item->index != -1) {
432 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
433 toolbar_config[TOOLBAR_COMPOSE].item_list =
434 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
439 static void toolbar_set_default_msgview(void)
445 } default_toolbar[] = {
446 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
447 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
448 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
449 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
450 { A_SEPARATOR, 0, ("") },
451 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
452 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
457 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
459 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
461 if (default_toolbar[i].action != A_SEPARATOR) {
463 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
465 toolbar_item->file = g_strdup(file);
466 toolbar_item->index = default_toolbar[i].action;
467 toolbar_item->text = g_strdup(default_toolbar[i].text);
470 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
471 toolbar_item->index = A_SEPARATOR;
474 if (toolbar_item->index != -1) {
475 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
476 toolbar_config[TOOLBAR_MSGVIEW].item_list =
477 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
482 void toolbar_set_default(ToolbarType source)
484 if (source == TOOLBAR_MAIN)
485 toolbar_set_default_main();
486 else if (source == TOOLBAR_COMPOSE)
487 toolbar_set_default_compose();
488 else if (source == TOOLBAR_MSGVIEW)
489 toolbar_set_default_msgview();
492 void toolbar_save_config_file(ToolbarType source)
497 gchar *fileSpec = NULL;
499 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
501 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
502 pfile = prefs_write_open(fileSpec);
506 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
507 conv_get_current_charset_str());
509 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
511 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
512 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
514 if (toolbar_item->index != A_SEPARATOR)
515 fprintf(fp, "\t<%s %s=\"%s\" %s=\"%s\" %s=\"%s\"/>\n",
517 TOOLBAR_ICON_FILE, toolbar_item->file,
518 TOOLBAR_ICON_TEXT, toolbar_item->text,
520 toolbar_ret_text_from_val(toolbar_item->index));
522 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
525 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
527 if (prefs_file_close (pfile) < 0 )
528 g_warning("failed to write toolbar configuration to file\n");
530 g_warning("failed to open toolbar configuration file for writing\n");
533 void toolbar_read_config_file(ToolbarType source)
535 XMLFile *file = NULL;
536 gchar *fileSpec = NULL;
541 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
543 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
544 file = xml_open_file(fileSpec);
547 toolbar_clear_list(source);
551 || (xml_get_dtd(file))
552 || (xml_parse_next_tag(file))
553 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
554 xml_close_file(file);
558 attr = xml_get_current_tag_attr(file);
565 if (xml_parse_next_tag(file))
568 /* Get next tag (icon, icon_text or icon_action) */
569 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
570 toolbar_parse_item(file, source);
571 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
572 ToolbarItem *item = g_new0(ToolbarItem, 1);
574 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
575 item->index = A_SEPARATOR;
576 toolbar_config[source].item_list =
577 g_slist_append(toolbar_config[source].item_list, item);
581 xml_close_file(file);
584 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
586 if (source == TOOLBAR_MAIN)
587 toolbar_set_default(TOOLBAR_MAIN);
588 else if (source == TOOLBAR_COMPOSE)
589 toolbar_set_default(TOOLBAR_COMPOSE);
590 else if (source == TOOLBAR_MSGVIEW)
591 toolbar_set_default(TOOLBAR_MSGVIEW);
593 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
597 toolbar_save_config_file(source);
602 * clears list of toolbar items read from configuration files
604 void toolbar_clear_list(ToolbarType source)
606 while (toolbar_config[source].item_list != NULL) {
607 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
609 toolbar_config[source].item_list =
610 g_slist_remove(toolbar_config[source].item_list, item);
618 g_slist_free(toolbar_config[source].item_list);
623 * return list of Toolbar items
625 GSList *toolbar_get_list(ToolbarType source)
629 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
630 list = toolbar_config[source].item_list;
635 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
637 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
639 toolbar_item->file = g_strdup(t_item->file);
640 toolbar_item->text = g_strdup(t_item->text);
641 toolbar_item->index = t_item->index;
643 toolbar_config[source].item_list =
644 g_slist_append(toolbar_config[source].item_list,
648 void toolbar_action_execute(GtkWidget *widget,
654 gchar *action, *action_p;
655 gboolean found = FALSE;
658 for (cur = action_list; cur != NULL; cur = cur->next) {
659 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
661 if (widget == act->widget) {
663 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
664 action = g_strdup((gchar*)lop->data);
666 action_p = strstr(action, ": ");
668 if (g_strcasecmp(act->name, action) == 0) {
682 actions_execute(data, i, widget, source);
684 g_warning ("Error: did not find Sylpheed Action to execute");
687 static void activate_compose_button (Toolbar *toolbar,
689 ComposeButtonType type)
691 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
694 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
695 : toolbar->compose_news_btn);
696 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
697 : toolbar->compose_mail_btn);
698 toolbar->compose_btn_type = type;
701 void toolbar_set_compose_button(Toolbar *toolbar,
702 ComposeButtonType compose_btn_type)
704 if (toolbar->compose_btn_type != compose_btn_type)
705 activate_compose_button(toolbar,
706 prefs_common.toolbar_style,
710 void toolbar_toggle(guint action, gpointer data)
712 MainWindow *mainwin = (MainWindow*)data;
716 g_return_if_fail(mainwin != NULL);
718 toolbar_style(TOOLBAR_MAIN, action, mainwin);
720 list = compose_get_compose_list();
721 for (cur = list; cur != NULL; cur = cur->next) {
722 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
724 list = messageview_get_msgview_list();
725 for (cur = list; cur != NULL; cur = cur->next) {
726 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
731 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
733 switch ((ToolbarStyle)action) {
735 gtk_widget_hide(handlebox_wid);
738 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
742 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
746 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
753 prefs_common.toolbar_style = (ToolbarStyle)action;
754 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
755 gtk_widget_show(handlebox_wid);
756 gtk_widget_queue_resize(handlebox_wid);
760 * Change the style of toolbar
762 static void toolbar_style(ToolbarType type, guint action, gpointer data)
764 GtkWidget *handlebox_wid;
765 GtkWidget *toolbar_wid;
766 MainWindow *mainwin = (MainWindow*)data;
767 Compose *compose = (Compose*)data;
768 MessageView *msgview = (MessageView*)data;
770 g_return_if_fail(data != NULL);
774 handlebox_wid = mainwin->handlebox;
775 toolbar_wid = mainwin->toolbar->toolbar;
777 case TOOLBAR_COMPOSE:
778 handlebox_wid = compose->handlebox;
779 toolbar_wid = compose->toolbar->toolbar;
781 case TOOLBAR_MSGVIEW:
782 handlebox_wid = msgview->handlebox;
783 toolbar_wid = msgview->toolbar->toolbar;
789 toolbar_set_style(toolbar_wid, handlebox_wid, action);
792 /* Toolbar handling */
793 static void toolbar_inc_cb(GtkWidget *widget,
796 ToolbarItem *toolbar_item = (ToolbarItem*)data;
799 g_return_if_fail(toolbar_item != NULL);
801 switch (toolbar_item->type) {
803 mainwin = (MainWindow*)toolbar_item->parent;
804 inc_mail_cb(mainwin, 0, NULL);
811 static void toolbar_inc_all_cb(GtkWidget *widget,
814 ToolbarItem *toolbar_item = (ToolbarItem*)data;
817 g_return_if_fail(toolbar_item != NULL);
819 switch (toolbar_item->type) {
821 mainwin = (MainWindow*)toolbar_item->parent;
822 inc_all_account_mail_cb(mainwin, 0, NULL);
829 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
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 send_queue_cb(mainwin, 0, NULL);
846 static void toolbar_exec_cb(GtkWidget *widget,
849 MainWindow *mainwin = get_mainwin(data);
851 g_return_if_fail(mainwin != NULL);
852 summary_execute(mainwin->summaryview);
857 /* popup callback functions */
858 static void toolbar_reply_popup_cb(GtkWidget *widget,
859 GdkEventButton *event,
862 Toolbar *toolbar_data = (Toolbar*)data;
866 if (event->button == 3) {
867 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
868 gtk_menu_popup(GTK_MENU(toolbar_data->reply_popup), NULL, NULL,
869 menu_button_position, widget,
870 event->button, event->time);
874 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
876 ToolbarItem *toolbar_item = (ToolbarItem*)data;
878 GtkWidget *reply_btn;
880 MessageView *msgview;
882 g_return_if_fail(toolbar_item != NULL);
884 switch(toolbar_item->type) {
886 mainwin = (MainWindow*)toolbar_item->parent;
887 reply_btn = mainwin->toolbar->reply_btn;
888 window = mainwin->window;
890 case TOOLBAR_MSGVIEW:
891 msgview = (MessageView*)toolbar_item->parent;
892 reply_btn = msgview->toolbar->reply_btn;
893 window = msgview->window;
899 gtk_button_set_relief(GTK_BUTTON(reply_btn), GTK_RELIEF_NONE);
900 manage_window_focus_in(window, NULL, NULL);
903 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
905 Toolbar *toolbar_data = (Toolbar*)data;
909 if (event->button == 3) {
910 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
911 gtk_menu_popup(GTK_MENU(toolbar_data->replyall_popup), NULL, NULL,
912 menu_button_position, widget,
913 event->button, event->time);
917 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
919 ToolbarItem *toolbar_item = (ToolbarItem*)data;
921 GtkWidget *replyall_btn;
923 MessageView *msgview;
925 g_return_if_fail(toolbar_item != NULL);
927 switch(toolbar_item->type) {
929 mainwin = (MainWindow*)toolbar_item->parent;
930 replyall_btn = mainwin->toolbar->replyall_btn;
931 window = mainwin->window;
933 case TOOLBAR_MSGVIEW:
934 msgview = (MessageView*)toolbar_item->parent;
935 replyall_btn = msgview->toolbar->replyall_btn;
936 window = msgview->window;
942 gtk_button_set_relief(GTK_BUTTON(replyall_btn), GTK_RELIEF_NONE);
943 manage_window_focus_in(window, NULL, NULL);
946 static void toolbar_reply_to_list_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
948 Toolbar *toolbar_data = (Toolbar*)data;
950 if (event->button == 3) {
951 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
952 gtk_menu_popup(GTK_MENU(toolbar_data->replylist_popup), NULL, NULL,
953 menu_button_position, widget,
954 event->button, event->time);
958 static void toolbar_reply_to_list_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
960 ToolbarItem *toolbar_item = (ToolbarItem*)data;
961 gpointer parent = toolbar_item->parent;
963 GtkWidget *replylist_btn;
966 g_return_if_fail(toolbar_item != NULL);
968 switch(toolbar_item->type) {
970 replylist_btn = ((MainWindow*)parent)->toolbar->replylist_btn;
971 window = ((MainWindow*)parent)->window;
973 case TOOLBAR_MSGVIEW:
974 replylist_btn = ((MessageView*)parent)->toolbar->replylist_btn;
975 window = ((MessageView*)parent)->window;
981 gtk_button_set_relief(GTK_BUTTON(replylist_btn), GTK_RELIEF_NONE);
982 manage_window_focus_in(window, NULL, NULL);
985 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
987 Toolbar *toolbar_data = (Toolbar*)data;
989 if (event->button == 3) {
990 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
991 gtk_menu_popup(GTK_MENU(toolbar_data->replysender_popup), NULL, NULL,
992 menu_button_position, widget,
993 event->button, event->time);
997 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
999 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1000 gpointer parent = toolbar_item->parent;
1002 GtkWidget *replysender_btn;
1004 g_return_if_fail(toolbar_item != NULL);
1006 switch(toolbar_item->type) {
1008 replysender_btn = ((MainWindow*)parent)->toolbar->replysender_btn;
1009 window = ((MainWindow*)parent)->window;
1011 case TOOLBAR_MSGVIEW:
1012 replysender_btn = ((MessageView*)parent)->toolbar->replysender_btn;
1013 window = ((MessageView*)parent)->window;
1019 gtk_button_set_relief(GTK_BUTTON(replysender_btn), GTK_RELIEF_NONE);
1020 manage_window_focus_in(window, NULL, NULL);
1023 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1025 Toolbar *toolbar_data = (Toolbar*)data;
1027 if (event->button == 3) {
1028 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1029 gtk_menu_popup(GTK_MENU(toolbar_data->fwd_popup), NULL, NULL,
1030 menu_button_position, widget,
1031 event->button, event->time);
1035 static void toolbar_forward_popup_closed_cb (GtkMenuShell *menu_shell,
1038 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1039 gpointer parent = toolbar_item->parent;
1043 g_return_if_fail(toolbar_item != NULL);
1045 switch(toolbar_item->type) {
1047 fwd_btn = ((MainWindow*)parent)->toolbar->fwd_btn;
1048 window = ((MainWindow*)parent)->window;
1050 case TOOLBAR_MSGVIEW:
1051 fwd_btn = ((MessageView*)parent)->toolbar->fwd_btn;
1052 window = ((MessageView*)parent)->window;
1058 gtk_button_set_relief(GTK_BUTTON(fwd_btn), GTK_RELIEF_NONE);
1059 manage_window_focus_in(window, NULL, NULL);
1063 * Delete current/selected(s) message(s)
1065 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1067 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1068 MainWindow *mainwin;
1069 MessageView *msgview;
1071 g_return_if_fail(toolbar_item != NULL);
1073 switch (toolbar_item->type) {
1074 case TOOLBAR_MSGVIEW:
1075 msgview = (MessageView*)toolbar_item->parent;
1076 messageview_delete(msgview);
1079 mainwin = (MainWindow*)toolbar_item->parent;
1080 summary_delete(mainwin->summaryview);
1083 debug_print("toolbar event not supported\n");
1090 * Compose new message
1092 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1094 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1095 MainWindow *mainwin;
1096 MessageView *msgview;
1098 g_return_if_fail(toolbar_item != NULL);
1100 switch (toolbar_item->type) {
1102 mainwin = (MainWindow*)toolbar_item->parent;
1103 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1104 compose_news_cb(mainwin, 0, NULL);
1106 compose_mail_cb(mainwin, 0, NULL);
1108 case TOOLBAR_MSGVIEW:
1109 msgview = (MessageView*)toolbar_item->parent;
1110 compose_new_with_folderitem(NULL,
1111 msgview->msginfo->folder);
1114 debug_print("toolbar event not supported\n");
1118 static void toolbar_popup_cb(gpointer data, guint action, GtkWidget *widget)
1120 toolbar_reply(data, action);
1127 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1129 toolbar_reply(data, prefs_common.reply_with_quote ?
1130 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE);
1135 * Reply message to Sender and All recipients
1137 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1140 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1141 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
1146 * Reply to Mailing List
1148 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1151 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1152 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
1157 * Reply to sender of message
1159 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1162 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1163 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
1169 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1171 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1174 g_return_if_fail(toolbar_item != NULL);
1176 switch (toolbar_item->type) {
1178 case TOOLBAR_MSGVIEW:
1181 case TOOLBAR_COMPOSE:
1182 compose = (Compose *)toolbar_item->parent;
1187 addressbook_open(compose);
1192 * Forward current/selected(s) message(s)
1194 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1196 toolbar_reply(data, COMPOSE_FORWARD);
1201 * Goto Next Unread Message
1203 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1205 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1206 MainWindow *mainwin;
1207 MessageView *msgview;
1209 g_return_if_fail(toolbar_item != NULL);
1211 switch (toolbar_item->type) {
1213 mainwin = (MainWindow*)toolbar_item->parent;
1214 summary_select_next_unread(mainwin->summaryview);
1217 case TOOLBAR_MSGVIEW:
1218 msgview = (MessageView*)toolbar_item->parent;
1219 summary_select_next_unread(msgview->mainwin->summaryview);
1221 /* Now we need to update the messageview window */
1222 if (msgview->mainwin->summaryview->selected) {
1223 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1225 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1226 msgview->mainwin->summaryview->selected);
1228 messageview_show(msgview, msginfo,
1229 msgview->all_headers);
1231 gtk_widget_destroy(msgview->window);
1235 debug_print("toolbar event not supported\n");
1239 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1241 compose_toolbar_cb(A_SEND, data);
1244 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1246 compose_toolbar_cb(A_SENDL, data);
1249 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1251 compose_toolbar_cb(A_DRAFT, data);
1254 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1256 compose_toolbar_cb(A_INSERT, data);
1259 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1261 compose_toolbar_cb(A_ATTACH, data);
1264 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1266 compose_toolbar_cb(A_SIG, data);
1269 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1271 compose_toolbar_cb(A_EXTEDITOR, data);
1274 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
1276 compose_toolbar_cb(A_LINEWRAP, data);
1280 * Execute actions from toolbar
1282 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1284 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1285 GSList *action_list;
1286 MainWindow *mainwin;
1288 MessageView *msgview;
1289 gpointer parent = toolbar_item->parent;
1291 g_return_if_fail(toolbar_item != NULL);
1293 switch (toolbar_item->type) {
1295 mainwin = (MainWindow*)parent;
1296 action_list = mainwin->toolbar->action_list;
1298 case TOOLBAR_COMPOSE:
1299 compose = (Compose*)parent;
1300 action_list = compose->toolbar->action_list;
1302 case TOOLBAR_MSGVIEW:
1303 msgview = (MessageView*)parent;
1304 action_list = msgview->toolbar->action_list;
1307 debug_print("toolbar event not supported\n");
1310 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1313 static MainWindow *get_mainwin(gpointer data)
1315 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1316 MainWindow *mainwin = NULL;
1317 MessageView *msgview;
1319 g_return_val_if_fail(toolbar_item != NULL, NULL);
1321 switch(toolbar_item->type) {
1323 mainwin = (MainWindow*)toolbar_item->parent;
1325 case TOOLBAR_MSGVIEW:
1326 msgview = (MessageView*)toolbar_item->parent;
1327 mainwin = (MainWindow*)msgview->mainwin;
1336 static GtkWidget *get_window_widget(ToolbarType type, gpointer data)
1338 MainWindow *mainwin;
1339 MessageView *msgview;
1343 mainwin = (MainWindow*)data;
1344 return mainwin->window;
1346 case TOOLBAR_MSGVIEW:
1347 msgview = (MessageView*)data;
1348 return msgview->vbox;
1356 static void toolbar_buttons_cb(GtkWidget *widget,
1363 void (*func)(GtkWidget *widget, gpointer data);
1365 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1366 { A_RECEIVE_CUR, toolbar_inc_cb },
1367 { A_SEND_QUEUED, toolbar_send_queued_cb },
1368 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1369 { A_COMPOSE_NEWS, toolbar_compose_cb },
1370 { A_REPLY_MESSAGE, toolbar_reply_cb },
1371 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1372 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1373 { A_REPLY_ML, toolbar_reply_to_list_cb },
1374 { A_FORWARD, toolbar_forward_cb },
1375 { A_DELETE, toolbar_delete_cb },
1376 { A_EXECUTE, toolbar_exec_cb },
1377 { A_GOTO_NEXT, toolbar_next_unread_cb },
1379 { A_SEND, toolbar_send_cb },
1380 { A_SENDL, toolbar_send_later_cb },
1381 { A_DRAFT, toolbar_draft_cb },
1382 { A_INSERT, toolbar_insert_cb },
1383 { A_ATTACH, toolbar_attach_cb },
1384 { A_SIG, toolbar_sig_cb },
1385 { A_EXTEDITOR, toolbar_ext_editor_cb },
1386 { A_LINEWRAP, toolbar_linewrap_cb },
1387 { A_ADDRBOOK, toolbar_addrbook_cb },
1389 { A_SYL_ACTIONS, toolbar_actions_execute_cb }
1392 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1394 for (i = 0; i < num_items; i++) {
1395 if (callbacks[i].index == item->index) {
1396 callbacks[i].func(widget, item);
1403 * Create a new toolbar with specified type
1404 * if a callback list is passed it will be used before the
1405 * common callback list
1407 Toolbar *toolbar_create(ToolbarType type,
1408 GtkWidget *container,
1411 ToolbarItem *toolbar_item;
1414 GtkWidget *icon_wid = NULL;
1415 GtkWidget *icon_news;
1417 GtkWidget *item_news;
1418 GtkWidget *window_wid;
1420 guint n_menu_entries;
1421 GtkWidget *reply_popup;
1422 GtkWidget *replyall_popup;
1423 GtkWidget *replylist_popup;
1424 GtkWidget *replysender_popup;
1425 GtkWidget *fwd_popup;
1427 GtkTooltips *toolbar_tips;
1428 ToolbarSylpheedActions *action_item;
1430 GSList *toolbar_list;
1431 Toolbar *toolbar_data;
1434 toolbar_tips = gtk_tooltips_new();
1436 toolbar_read_config_file(type);
1437 toolbar_list = toolbar_get_list(type);
1439 toolbar_data = g_new0(Toolbar, 1);
1441 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1443 gtk_container_add(GTK_CONTAINER(container), toolbar);
1444 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1445 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1446 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1447 GTK_TOOLBAR_SPACE_LINE);
1449 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1451 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1452 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1456 toolbar_item = g_new0(ToolbarItem, 1);
1457 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1458 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1459 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1460 toolbar_item->parent = data;
1461 toolbar_item->type = type;
1463 /* collect toolbar items in list to keep track */
1464 toolbar_data->item_list =
1465 g_slist_append(toolbar_data->item_list,
1468 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1469 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1473 icon_wid, toolbar_buttons_cb,
1476 switch (toolbar_item->index) {
1479 toolbar_data->getall_btn = item;
1480 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1481 toolbar_data->getall_btn,
1482 _("Receive Mail on all Accounts"), NULL);
1485 toolbar_data->get_btn = item;
1486 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1487 toolbar_data->get_btn,
1488 _("Receive Mail on current Account"), NULL);
1491 toolbar_data->send_btn = item;
1492 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1493 toolbar_data->send_btn,
1494 _("Send Queued Message(s)"), NULL);
1496 case A_COMPOSE_EMAIL:
1497 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1498 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1502 icon_news, toolbar_buttons_cb,
1504 toolbar_data->compose_mail_btn = item;
1505 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1506 toolbar_data->compose_mail_btn,
1507 _("Compose Email"), NULL);
1508 toolbar_data->compose_news_btn = item_news;
1509 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1510 toolbar_data->compose_news_btn,
1511 _("Compose News"), NULL);
1513 case A_REPLY_MESSAGE:
1514 toolbar_data->reply_btn = item;
1515 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1516 toolbar_data->reply_btn,
1517 _("Reply to Message"), NULL);
1518 gtk_signal_connect(GTK_OBJECT(toolbar_data->reply_btn),
1519 "button_press_event",
1520 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
1522 n_menu_entries = sizeof(reply_popup_entries) /
1523 sizeof(reply_popup_entries[0]);
1525 window_wid = get_window_widget(type, data);
1526 reply_popup = popupmenu_create(window_wid,
1527 reply_popup_entries, n_menu_entries,
1528 "<ReplyPopup>", (gpointer)toolbar_item);
1530 gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
1531 GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), toolbar_item);
1532 toolbar_data->reply_popup = reply_popup;
1534 case A_REPLY_SENDER:
1535 toolbar_data->replysender_btn = item;
1536 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1537 toolbar_data->replysender_btn,
1538 _("Reply to Sender"), NULL);
1539 gtk_signal_connect(GTK_OBJECT(toolbar_data->replysender_btn),
1540 "button_press_event",
1541 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
1543 n_menu_entries = sizeof(replysender_popup_entries) /
1544 sizeof(replysender_popup_entries[0]);
1546 window_wid = get_window_widget(type, data);
1547 replysender_popup = popupmenu_create(window_wid,
1548 replysender_popup_entries, n_menu_entries,
1549 "<ReplySenderPopup>", (gpointer)toolbar_item);
1551 gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
1552 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), toolbar_item);
1553 toolbar_data->replysender_popup = replysender_popup;
1556 toolbar_data->replyall_btn = item;
1557 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1558 toolbar_data->replyall_btn,
1559 _("Reply to All"), NULL);
1560 gtk_signal_connect(GTK_OBJECT(toolbar_data->replyall_btn),
1561 "button_press_event",
1562 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
1564 n_menu_entries = sizeof(replyall_popup_entries) /
1565 sizeof(replyall_popup_entries[0]);
1567 window_wid = get_window_widget(type, data);
1568 replyall_popup = popupmenu_create(window_wid,
1569 replyall_popup_entries, n_menu_entries,
1570 "<ReplyAllPopup>", (gpointer)toolbar_item);
1572 gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
1573 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), toolbar_item);
1574 toolbar_data->replyall_popup = replyall_popup;
1577 toolbar_data->replylist_btn = item;
1578 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1579 toolbar_data->replylist_btn,
1580 _("Reply to Mailing-list"), NULL);
1581 gtk_signal_connect(GTK_OBJECT(toolbar_data->replylist_btn),
1582 "button_press_event",
1583 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_cb),
1585 n_menu_entries = sizeof(replylist_popup_entries) /
1586 sizeof(replylist_popup_entries[0]);
1588 window_wid = get_window_widget(type, data);
1589 replylist_popup = popupmenu_create(window_wid,
1590 replylist_popup_entries, n_menu_entries,
1591 "<ReplyMlPopup>", (gpointer)toolbar_item);
1593 gtk_signal_connect(GTK_OBJECT(replylist_popup), "selection_done",
1594 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_closed_cb), toolbar_item);
1595 toolbar_data->replylist_popup = replylist_popup;
1598 toolbar_data->fwd_btn = item;
1599 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1600 toolbar_data->fwd_btn,
1601 _("Forward Message"), NULL);
1602 gtk_signal_connect(GTK_OBJECT(toolbar_data->fwd_btn),
1603 "button_press_event",
1604 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
1606 n_menu_entries = sizeof(fwd_popup_entries) /
1607 sizeof(fwd_popup_entries[0]);
1609 window_wid = get_window_widget(type, data);
1610 fwd_popup = popupmenu_create(window_wid,
1611 fwd_popup_entries, n_menu_entries,
1612 "<ForwardPopup>", (gpointer)toolbar_item);
1614 gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
1615 GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), toolbar_item);
1616 toolbar_data->fwd_popup = fwd_popup;
1619 toolbar_data->delete_btn = item;
1620 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1621 toolbar_data->delete_btn,
1622 _("Delete Message"), NULL);
1625 toolbar_data->exec_btn = item;
1626 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1627 toolbar_data->exec_btn,
1628 _("Execute"), NULL);
1631 toolbar_data->next_btn = item;
1632 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1633 toolbar_data->next_btn,
1634 _("Goto Next Message"), NULL);
1637 /* Compose Toolbar */
1639 toolbar_data->send_btn = item;
1640 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1641 toolbar_data->send_btn,
1642 _("Send Message"), NULL);
1645 toolbar_data->sendl_btn = item;
1646 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1647 toolbar_data->sendl_btn,
1648 _("Put into queue folder and send later"), NULL);
1651 toolbar_data->draft_btn = item;
1652 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1653 toolbar_data->draft_btn,
1654 _("Save to draft folder"), NULL);
1657 toolbar_data->insert_btn = item;
1658 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1659 toolbar_data->insert_btn,
1660 _("Insert file"), NULL);
1663 toolbar_data->attach_btn = item;
1664 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1665 toolbar_data->attach_btn,
1666 _("Attach file"), NULL);
1669 toolbar_data->sig_btn = item;
1670 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1671 toolbar_data->sig_btn,
1672 _("Insert signature"), NULL);
1675 toolbar_data->exteditor_btn = item;
1676 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1677 toolbar_data->exteditor_btn,
1678 _("Edit with external editor"), NULL);
1681 toolbar_data->linewrap_btn = item;
1682 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1683 toolbar_data->linewrap_btn,
1684 _("Wrap all long lines"), NULL);
1687 toolbar_data->addrbook_btn = item;
1688 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1689 toolbar_data->addrbook_btn,
1690 _("Address book"), NULL);
1694 action_item = g_new0(ToolbarSylpheedActions, 1);
1695 action_item->widget = item;
1696 action_item->name = g_strdup(toolbar_item->text);
1698 toolbar_data->action_list =
1699 g_slist_append(toolbar_data->action_list,
1702 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1704 action_item->name, NULL);
1706 gtk_widget_show(item);
1713 toolbar_data->toolbar = toolbar;
1714 if (type == TOOLBAR_MAIN)
1715 activate_compose_button(toolbar_data,
1716 prefs_common.toolbar_style,
1717 toolbar_data->compose_btn_type);
1719 gtk_widget_show_all(toolbar);
1721 return toolbar_data;
1725 * Free toolbar structures
1727 void toolbar_destroy(Toolbar * toolbar) {
1729 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1730 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1733 void toolbar_update(ToolbarType type, gpointer data)
1735 Toolbar *toolbar_data;
1736 GtkWidget *handlebox;
1737 MainWindow *mainwin = (MainWindow*)data;
1738 Compose *compose = (Compose*)data;
1739 MessageView *msgview = (MessageView*)data;
1743 toolbar_data = mainwin->toolbar;
1744 handlebox = mainwin->handlebox;
1746 case TOOLBAR_COMPOSE:
1747 toolbar_data = compose->toolbar;
1748 handlebox = compose->handlebox;
1750 case TOOLBAR_MSGVIEW:
1751 toolbar_data = msgview->toolbar;
1752 handlebox = msgview->handlebox;
1758 gtk_container_remove(GTK_CONTAINER(handlebox),
1759 GTK_WIDGET(toolbar_data->toolbar));
1761 toolbar_init(toolbar_data);
1762 toolbar_data = toolbar_create(type, handlebox, data);
1765 mainwin->toolbar = toolbar_data;
1767 case TOOLBAR_COMPOSE:
1768 compose->toolbar = toolbar_data;
1770 case TOOLBAR_MSGVIEW:
1771 msgview->toolbar = toolbar_data;
1775 toolbar_style(type, prefs_common.toolbar_style, data);
1777 if (type == TOOLBAR_MAIN)
1778 toolbar_main_set_sensitive((MainWindow*)data);
1781 void toolbar_main_set_sensitive(gpointer data)
1783 SensitiveCond state;
1785 MainWindow *mainwin = (MainWindow*)data;
1786 Toolbar *toolbar = mainwin->toolbar;
1788 GSList *entry_list = NULL;
1790 typedef struct _Entry Entry;
1797 #define SET_WIDGET_COND(w, c) \
1799 Entry *e = g_new0(Entry, 1); \
1802 entry_list = g_slist_append(entry_list, e); \
1805 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1806 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1807 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1808 SET_WIDGET_COND(toolbar->reply_btn,
1809 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1810 SET_WIDGET_COND(toolbar->replyall_btn,
1811 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1812 SET_WIDGET_COND(toolbar->replylist_btn,
1813 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1814 SET_WIDGET_COND(toolbar->replysender_btn,
1815 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1816 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1818 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1819 SET_WIDGET_COND(toolbar->delete_btn,
1820 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1821 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1823 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
1824 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1826 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1829 #undef SET_WIDGET_COND
1831 state = main_window_get_current_state(mainwin);
1833 for (cur = entry_list; cur != NULL; cur = cur->next) {
1834 Entry *e = (Entry*) cur->data;
1836 if (e->widget != NULL) {
1837 sensitive = ((e->cond & state) == e->cond);
1838 gtk_widget_set_sensitive(e->widget, sensitive);
1842 while (entry_list != NULL) {
1843 Entry *e = (Entry*) entry_list->data;
1847 entry_list = g_slist_remove(entry_list, e);
1850 g_slist_free(entry_list);
1852 activate_compose_button(toolbar,
1853 prefs_common.toolbar_style,
1854 toolbar->compose_btn_type);
1857 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1859 Compose *compose = (Compose*)data;
1860 GSList *items = compose->toolbar->action_list;
1862 if (compose->toolbar->send_btn)
1863 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1864 if (compose->toolbar->sendl_btn)
1865 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1866 if (compose->toolbar->draft_btn )
1867 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1868 if (compose->toolbar->insert_btn )
1869 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1870 if (compose->toolbar->attach_btn)
1871 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1872 if (compose->toolbar->sig_btn)
1873 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1874 if (compose->toolbar->exteditor_btn)
1875 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1876 if (compose->toolbar->linewrap_btn)
1877 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
1878 if (compose->toolbar->addrbook_btn)
1879 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1880 for (; items != NULL; items = g_slist_next(items)) {
1881 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1882 gtk_widget_set_sensitive(item->widget, sensitive);
1887 * Initialize toolbar structure
1889 void toolbar_init(Toolbar * toolbar) {
1891 toolbar->toolbar = NULL;
1892 toolbar->get_btn = NULL;
1893 toolbar->getall_btn = NULL;
1894 toolbar->send_btn = NULL;
1895 toolbar->compose_mail_btn = NULL;
1896 toolbar->compose_news_btn = NULL;
1897 toolbar->reply_btn = NULL;
1898 toolbar->replysender_btn = NULL;
1899 toolbar->replyall_btn = NULL;
1900 toolbar->replylist_btn = NULL;
1901 toolbar->fwd_btn = NULL;
1902 toolbar->delete_btn = NULL;
1903 toolbar->next_btn = NULL;
1904 toolbar->exec_btn = NULL;
1906 /* compose buttons */
1907 toolbar->sendl_btn = NULL;
1908 toolbar->draft_btn = NULL;
1909 toolbar->insert_btn = NULL;
1910 toolbar->attach_btn = NULL;
1911 toolbar->sig_btn = NULL;
1912 toolbar->exteditor_btn = NULL;
1913 toolbar->linewrap_btn = NULL;
1914 toolbar->addrbook_btn = NULL;
1916 toolbar_destroy(toolbar);
1921 static void toolbar_reply(gpointer data, guint action)
1923 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1924 MainWindow *mainwin;
1925 MessageView *msgview;
1926 GSList *msginfo_list = NULL;
1929 g_return_if_fail(toolbar_item != NULL);
1931 switch (toolbar_item->type) {
1933 mainwin = (MainWindow*)toolbar_item->parent;
1934 msginfo_list = summary_get_selection(mainwin->summaryview);
1935 msgview = (MessageView*)mainwin->messageview;
1937 case TOOLBAR_MSGVIEW:
1938 msgview = (MessageView*)toolbar_item->parent;
1939 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
1945 g_return_if_fail(msgview != NULL);
1946 body = messageview_get_selection(msgview);
1948 g_return_if_fail(msginfo_list != NULL);
1949 compose_reply_mode((ComposeMode)action, msginfo_list, body);
1952 g_slist_free(msginfo_list);
1954 /* TODO: update reply state ion summaryview */
1958 /* exported functions */
1960 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
1962 MainWindow *mainwin = (MainWindow*)data;
1964 inc_mail(mainwin, prefs_common.newmail_notify_manu);
1967 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
1969 MainWindow *mainwin = (MainWindow*)data;
1971 inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
1974 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
1978 if (prefs_common.work_offline)
1979 if (alertpanel(_("Offline warning"),
1980 _("You're working offline. Override?"),
1981 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
1984 for (list = folder_get_list(); list != NULL; list = list->next) {
1985 Folder *folder = list->data;
1987 if (folder->queue) {
1988 procmsg_send_queue(folder->queue, prefs_common.savemsg);
1989 folder_item_scan(folder->queue);
1994 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
1996 MainWindow *mainwin = (MainWindow*)data;
1997 PrefsAccount *ac = NULL;
1998 FolderItem *item = mainwin->summaryview->folder_item;
2003 ac = account_find_from_item(item);
2004 if (ac && ac->protocol != A_NNTP) {
2005 compose_new_with_folderitem(ac, item); /* CLAWS */
2011 * CLAWS - use current account
2013 if (cur_account && (cur_account->protocol != A_NNTP)) {
2014 compose_new_with_folderitem(cur_account, item);
2019 * CLAWS - just get the first one
2021 list = account_get_list();
2022 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2023 ac = (PrefsAccount *) cur->data;
2024 if (ac->protocol != A_NNTP) {
2025 compose_new_with_folderitem(ac, item);
2031 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2033 MainWindow *mainwin = (MainWindow*)data;
2034 PrefsAccount * ac = NULL;
2038 if (mainwin->summaryview->folder_item) {
2039 ac = mainwin->summaryview->folder_item->folder->account;
2040 if (ac && ac->protocol == A_NNTP) {
2042 mainwin->summaryview->folder_item->path,
2048 list = account_get_list();
2049 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2050 ac = (PrefsAccount *) cur->data;
2051 if (ac->protocol == A_NNTP) {
2052 compose_new(ac, NULL, NULL);