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"
44 #include "prefs_gtk.h"
46 #include "stock_pixmap.h"
47 #include "manage_window.h"
52 #include "prefs_actions.h"
53 #include "prefs_common.h"
54 #include "prefs_toolbar.h"
55 #include "alertpanel.h"
58 #define TOOLBAR_TAG_INDEX "toolbar"
59 #define TOOLBAR_TAG_ITEM "item"
60 #define TOOLBAR_TAG_SEPARATOR "separator"
62 #define TOOLBAR_ICON_FILE "file"
63 #define TOOLBAR_ICON_TEXT "text"
64 #define TOOLBAR_ICON_ACTION "action"
66 gboolean toolbar_is_duplicate (gint action,
68 static void toolbar_parse_item (XMLFile *file,
71 static gint toolbar_ret_val_from_text (const gchar *text);
72 static gchar *toolbar_ret_text_from_val (gint val);
74 static void toolbar_set_default_main (void);
75 static void toolbar_set_default_compose (void);
76 static void toolbar_set_default_msgview (void);
78 static void toolbar_style (ToolbarType type,
82 static GtkWidget *get_window_widget (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_actions_execute_cb (GtkWidget *widget,
120 static void toolbar_send_cb (GtkWidget *widget,
122 static void toolbar_send_later_cb (GtkWidget *widget,
124 static void toolbar_draft_cb (GtkWidget *widget,
126 static void toolbar_insert_cb (GtkWidget *widget,
128 static void toolbar_attach_cb (GtkWidget *widget,
130 static void toolbar_sig_cb (GtkWidget *widget,
132 static void toolbar_ext_editor_cb (GtkWidget *widget,
134 static void toolbar_linewrap_cb (GtkWidget *widget,
136 static void toolbar_addrbook_cb (GtkWidget *widget,
139 static void toolbar_popup_cb (gpointer data,
145 } toolbar_text [] = {
146 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
147 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
148 { "A_SEND_QUEUED", N_("Send Queued Message(s)") },
149 { "A_COMPOSE_EMAIL", N_("Compose Email") },
150 { "A_COMPOSE_NEWS", N_("Compose News") },
151 { "A_REPLY_MESSAGE", N_("Reply to Message") },
152 { "A_REPLY_SENDER", N_("Reply to Sender") },
153 { "A_REPLY_ALL", N_("Reply to All") },
154 { "A_REPLY_ML", N_("Reply to Mailing-list") },
155 { "A_FORWARD", N_("Forward Message") },
156 { "A_DELETE", N_("Delete Message") },
157 { "A_EXECUTE", N_("Execute") },
158 { "A_GOTO_NEXT", N_("Goto Next Message") },
160 { "A_SEND", N_("Send Message") },
161 { "A_SENDL", N_("Put into queue folder and send later") },
162 { "A_DRAFT", N_("Save to draft folder") },
163 { "A_INSERT", N_("Insert file") },
164 { "A_ATTACH", N_("Attach file") },
165 { "A_SIG", N_("Insert signature") },
166 { "A_EXTEDITOR", N_("Edit with external editor") },
167 { "A_LINEWRAP", N_("Wrap all long lines") },
168 { "A_ADDRBOOK", N_("Address book") },
170 { "A_SYL_ACTIONS", N_("Sylpheed Actions Feature") },
171 { "A_SEPARATOR", "Separator" }
174 /* struct holds configuration files and a list of
175 * currently active toolbar items
176 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
180 const gchar *conf_file;
182 } toolbar_config[3] = {
183 { "toolbar_main.xml", NULL},
184 { "toolbar_compose.xml", NULL},
185 { "toolbar_msgview.xml", NULL}
188 static GtkItemFactoryEntry reply_popup_entries[] =
190 {N_("/Reply with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
191 {N_("/_Reply without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
193 static GtkItemFactoryEntry replyall_popup_entries[] =
195 {N_("/Reply to all with _quote"), "<shift>A", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
196 {N_("/_Reply to all without quote"), "a", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
198 static GtkItemFactoryEntry replylist_popup_entries[] =
200 {N_("/Reply to list with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
201 {N_("/_Reply to list without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
203 static GtkItemFactoryEntry replysender_popup_entries[] =
205 {N_("/Reply to sender with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
206 {N_("/_Reply to sender without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
208 static GtkItemFactoryEntry fwd_popup_entries[] =
210 {N_("/_Forward message (inline style)"), "f", toolbar_popup_cb, COMPOSE_FORWARD_INLINE, NULL},
211 {N_("/Forward message as _attachment"), "<shift>F", toolbar_popup_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
215 gint toolbar_ret_val_from_descr(const gchar *descr)
219 for (i = 0; i < N_ACTION_VAL; i++) {
220 if (g_strcasecmp(gettext(toolbar_text[i].descr), descr) == 0)
227 gchar *toolbar_ret_descr_from_val(gint val)
229 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
231 return gettext(toolbar_text[val].descr);
234 static gint toolbar_ret_val_from_text(const gchar *text)
238 for (i = 0; i < N_ACTION_VAL; i++) {
239 if (g_strcasecmp(toolbar_text[i].index_str, text) == 0)
246 static gchar *toolbar_ret_text_from_val(gint val)
248 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
250 return toolbar_text[val].index_str;
253 gboolean toolbar_is_duplicate(gint action, ToolbarType source)
257 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
260 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
261 ToolbarItem *item = (ToolbarItem*) cur->data;
263 if (item->index == action)
269 /* depending on toolbar type this function
270 returns a list of available toolbar events being
271 displayed by prefs_toolbar
273 GList *toolbar_get_action_items(ToolbarType source)
278 if (source == TOOLBAR_MAIN) {
279 gint main_items[14] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
280 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
281 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
282 A_DELETE, A_EXECUTE, A_GOTO_NEXT,
283 A_ADDRBOOK, A_SYL_ACTIONS };
285 for (i = 0; i < sizeof(main_items)/sizeof(main_items[0]); i++)
286 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
288 else if (source == TOOLBAR_COMPOSE) {
289 gint comp_items[10] = { A_SEND, A_SENDL, A_DRAFT,
290 A_INSERT, A_ATTACH, A_SIG,
291 A_EXTEDITOR, A_LINEWRAP, A_ADDRBOOK,
294 for (i = 0; i < sizeof(comp_items)/sizeof(comp_items[0]); i++)
295 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
297 else if (source == TOOLBAR_MSGVIEW) {
298 gint msgv_items[10] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
299 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
300 A_DELETE, A_GOTO_NEXT, A_ADDRBOOK,
303 for (i = 0; i < sizeof(msgv_items)/sizeof(msgv_items[0]); i++)
304 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
310 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
314 ToolbarItem *item = NULL;
316 attr = xml_get_current_tag_attr(file);
317 item = g_new0(ToolbarItem, 1);
319 name = ((XMLAttr *)attr->data)->name;
320 value = ((XMLAttr *)attr->data)->value;
322 if (g_strcasecmp(name, TOOLBAR_ICON_FILE) == 0)
323 item->file = g_strdup (value);
324 else if (g_strcasecmp(name, TOOLBAR_ICON_TEXT) == 0)
325 item->text = g_strdup (value);
326 else if (g_strcasecmp(name, TOOLBAR_ICON_ACTION) == 0)
327 item->index = toolbar_ret_val_from_text(value);
329 attr = g_list_next(attr);
331 if (item->index != -1) {
333 if (!toolbar_is_duplicate(item->index, source))
334 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
339 static void toolbar_set_default_main(void)
345 } default_toolbar[] = {
346 { A_RECEIVE_CUR, STOCK_PIXMAP_MAIL_RECEIVE, _("Get") },
347 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get All") },
348 { A_SEPARATOR, 0, ("") },
349 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
350 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Email") },
351 { A_SEPARATOR, 0, ("") },
352 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
353 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
354 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
355 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
356 { A_SEPARATOR, 0, ("") },
357 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
358 { A_EXECUTE, STOCK_PIXMAP_EXEC, _("Execute") },
359 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
364 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
366 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
368 if (default_toolbar[i].action != A_SEPARATOR) {
370 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
372 toolbar_item->file = g_strdup(file);
373 toolbar_item->index = default_toolbar[i].action;
374 toolbar_item->text = g_strdup(default_toolbar[i].text);
377 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
378 toolbar_item->index = A_SEPARATOR;
381 if (toolbar_item->index != -1) {
382 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
383 toolbar_config[TOOLBAR_MAIN].item_list =
384 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
389 static void toolbar_set_default_compose(void)
395 } default_toolbar[] = {
396 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
397 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
398 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
399 { A_SEPARATOR, 0, ("") },
400 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
401 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
402 { A_SIG, STOCK_PIXMAP_MAIL_SIGN, _("Signature") },
403 { A_SEPARATOR, 0, ("") },
404 { A_EXTEDITOR, STOCK_PIXMAP_EDIT_EXTERN, _("Editor") },
405 { A_LINEWRAP, STOCK_PIXMAP_LINEWRAP, _("Linewrap") },
406 { A_SEPARATOR, 0, ("") },
407 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
412 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
414 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
416 if (default_toolbar[i].action != A_SEPARATOR) {
418 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
420 toolbar_item->file = g_strdup(file);
421 toolbar_item->index = default_toolbar[i].action;
422 toolbar_item->text = g_strdup(default_toolbar[i].text);
425 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
426 toolbar_item->index = A_SEPARATOR;
429 if (toolbar_item->index != -1) {
430 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
431 toolbar_config[TOOLBAR_COMPOSE].item_list =
432 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
437 static void toolbar_set_default_msgview(void)
443 } default_toolbar[] = {
444 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
445 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
446 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
447 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
448 { A_SEPARATOR, 0, ("") },
449 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
450 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
455 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
457 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
459 if (default_toolbar[i].action != A_SEPARATOR) {
461 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
463 toolbar_item->file = g_strdup(file);
464 toolbar_item->index = default_toolbar[i].action;
465 toolbar_item->text = g_strdup(default_toolbar[i].text);
468 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
469 toolbar_item->index = A_SEPARATOR;
472 if (toolbar_item->index != -1) {
473 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
474 toolbar_config[TOOLBAR_MSGVIEW].item_list =
475 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
480 void toolbar_set_default(ToolbarType source)
482 if (source == TOOLBAR_MAIN)
483 toolbar_set_default_main();
484 else if (source == TOOLBAR_COMPOSE)
485 toolbar_set_default_compose();
486 else if (source == TOOLBAR_MSGVIEW)
487 toolbar_set_default_msgview();
490 void toolbar_save_config_file(ToolbarType source)
495 gchar *fileSpec = NULL;
497 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
499 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
500 pfile = prefs_write_open(fileSpec);
504 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
505 conv_get_current_charset_str());
507 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
509 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
510 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
512 if (toolbar_item->index != A_SEPARATOR)
513 fprintf(fp, "\t<%s %s=\"%s\" %s=\"%s\" %s=\"%s\"/>\n",
515 TOOLBAR_ICON_FILE, toolbar_item->file,
516 TOOLBAR_ICON_TEXT, toolbar_item->text,
518 toolbar_ret_text_from_val(toolbar_item->index));
520 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
523 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
525 if (prefs_file_close (pfile) < 0 )
526 g_warning("failed to write toolbar configuration to file\n");
528 g_warning("failed to open toolbar configuration file for writing\n");
531 void toolbar_read_config_file(ToolbarType source)
533 XMLFile *file = NULL;
534 gchar *fileSpec = NULL;
539 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
541 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
542 file = xml_open_file(fileSpec);
545 toolbar_clear_list(source);
549 || (xml_get_dtd(file))
550 || (xml_parse_next_tag(file))
551 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
552 xml_close_file(file);
556 attr = xml_get_current_tag_attr(file);
563 if (xml_parse_next_tag(file))
566 /* Get next tag (icon, icon_text or icon_action) */
567 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
568 toolbar_parse_item(file, source);
569 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
570 ToolbarItem *item = g_new0(ToolbarItem, 1);
572 item->file = g_strdup(toolbar_ret_descr_from_val(A_SEPARATOR));
573 item->index = A_SEPARATOR;
574 toolbar_config[source].item_list =
575 g_slist_append(toolbar_config[source].item_list, item);
579 xml_close_file(file);
582 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
584 if (source == TOOLBAR_MAIN)
585 toolbar_set_default(TOOLBAR_MAIN);
586 else if (source == TOOLBAR_COMPOSE)
587 toolbar_set_default(TOOLBAR_COMPOSE);
588 else if (source == TOOLBAR_MSGVIEW)
589 toolbar_set_default(TOOLBAR_MSGVIEW);
591 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
595 toolbar_save_config_file(source);
600 * clears list of toolbar items read from configuration files
602 void toolbar_clear_list(ToolbarType source)
604 while (toolbar_config[source].item_list != NULL) {
605 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
607 toolbar_config[source].item_list =
608 g_slist_remove(toolbar_config[source].item_list, item);
616 g_slist_free(toolbar_config[source].item_list);
621 * return list of Toolbar items
623 GSList *toolbar_get_list(ToolbarType source)
627 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
628 list = toolbar_config[source].item_list;
633 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
635 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
637 toolbar_item->file = g_strdup(t_item->file);
638 toolbar_item->text = g_strdup(t_item->text);
639 toolbar_item->index = t_item->index;
641 toolbar_config[source].item_list =
642 g_slist_append(toolbar_config[source].item_list,
646 void toolbar_action_execute(GtkWidget *widget,
652 gchar *action, *action_p;
653 gboolean found = FALSE;
656 for (cur = action_list; cur != NULL; cur = cur->next) {
657 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
659 if (widget == act->widget) {
661 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
662 action = g_strdup((gchar*)lop->data);
664 action_p = strstr(action, ": ");
666 if (g_strcasecmp(act->name, action) == 0) {
680 actions_execute(data, i, widget, source);
682 g_warning ("Error: did not find Sylpheed Action to execute");
685 static void activate_compose_button (Toolbar *toolbar,
687 ComposeButtonType type)
689 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
692 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
693 : toolbar->compose_news_btn);
694 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
695 : toolbar->compose_mail_btn);
696 toolbar->compose_btn_type = type;
699 void toolbar_set_compose_button(Toolbar *toolbar,
700 ComposeButtonType compose_btn_type)
702 if (toolbar->compose_btn_type != compose_btn_type)
703 activate_compose_button(toolbar,
704 prefs_common.toolbar_style,
708 void toolbar_toggle(guint action, gpointer data)
710 MainWindow *mainwin = (MainWindow*)data;
714 g_return_if_fail(mainwin != NULL);
716 toolbar_style(TOOLBAR_MAIN, action, mainwin);
718 list = compose_get_compose_list();
719 for (cur = list; cur != NULL; cur = cur->next) {
720 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
722 list = messageview_get_msgview_list();
723 for (cur = list; cur != NULL; cur = cur->next) {
724 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
729 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
731 switch ((ToolbarStyle)action) {
733 gtk_widget_hide(handlebox_wid);
736 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
740 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
744 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
751 prefs_common.toolbar_style = (ToolbarStyle)action;
752 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
753 gtk_widget_show(handlebox_wid);
754 gtk_widget_queue_resize(handlebox_wid);
758 * Change the style of toolbar
760 static void toolbar_style(ToolbarType type, guint action, gpointer data)
762 GtkWidget *handlebox_wid;
763 GtkWidget *toolbar_wid;
764 MainWindow *mainwin = (MainWindow*)data;
765 Compose *compose = (Compose*)data;
766 MessageView *msgview = (MessageView*)data;
768 g_return_if_fail(data != NULL);
772 handlebox_wid = mainwin->handlebox;
773 toolbar_wid = mainwin->toolbar->toolbar;
775 case TOOLBAR_COMPOSE:
776 handlebox_wid = compose->handlebox;
777 toolbar_wid = compose->toolbar->toolbar;
779 case TOOLBAR_MSGVIEW:
780 handlebox_wid = msgview->handlebox;
781 toolbar_wid = msgview->toolbar->toolbar;
787 toolbar_set_style(toolbar_wid, handlebox_wid, action);
790 /* Toolbar handling */
791 static void toolbar_inc_cb(GtkWidget *widget,
794 ToolbarItem *toolbar_item = (ToolbarItem*)data;
797 g_return_if_fail(toolbar_item != NULL);
799 switch (toolbar_item->type) {
801 mainwin = (MainWindow*)toolbar_item->parent;
802 inc_mail_cb(mainwin, 0, NULL);
809 static void toolbar_inc_all_cb(GtkWidget *widget,
812 ToolbarItem *toolbar_item = (ToolbarItem*)data;
815 g_return_if_fail(toolbar_item != NULL);
817 switch (toolbar_item->type) {
819 mainwin = (MainWindow*)toolbar_item->parent;
820 inc_all_account_mail_cb(mainwin, 0, NULL);
827 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
829 ToolbarItem *toolbar_item = (ToolbarItem*)data;
832 g_return_if_fail(toolbar_item != NULL);
834 switch (toolbar_item->type) {
836 mainwin = (MainWindow*)toolbar_item->parent;
837 send_queue_cb(mainwin, 0, NULL);
844 static void toolbar_exec_cb(GtkWidget *widget,
847 MainWindow *mainwin = get_mainwin(data);
849 g_return_if_fail(mainwin != NULL);
850 summary_execute(mainwin->summaryview);
855 /* popup callback functions */
856 static void toolbar_reply_popup_cb(GtkWidget *widget,
857 GdkEventButton *event,
860 Toolbar *toolbar_data = (Toolbar*)data;
864 if (event->button == 3) {
865 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
866 gtk_menu_popup(GTK_MENU(toolbar_data->reply_popup), NULL, NULL,
867 menu_button_position, widget,
868 event->button, event->time);
872 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
874 ToolbarItem *toolbar_item = (ToolbarItem*)data;
876 GtkWidget *reply_btn;
878 MessageView *msgview;
880 g_return_if_fail(toolbar_item != NULL);
882 switch(toolbar_item->type) {
884 mainwin = (MainWindow*)toolbar_item->parent;
885 reply_btn = mainwin->toolbar->reply_btn;
886 window = mainwin->window;
888 case TOOLBAR_MSGVIEW:
889 msgview = (MessageView*)toolbar_item->parent;
890 reply_btn = msgview->toolbar->reply_btn;
891 window = msgview->window;
897 gtk_button_set_relief(GTK_BUTTON(reply_btn), GTK_RELIEF_NONE);
898 manage_window_focus_in(window, NULL, NULL);
901 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
903 Toolbar *toolbar_data = (Toolbar*)data;
907 if (event->button == 3) {
908 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
909 gtk_menu_popup(GTK_MENU(toolbar_data->replyall_popup), NULL, NULL,
910 menu_button_position, widget,
911 event->button, event->time);
915 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
917 ToolbarItem *toolbar_item = (ToolbarItem*)data;
919 GtkWidget *replyall_btn;
921 MessageView *msgview;
923 g_return_if_fail(toolbar_item != NULL);
925 switch(toolbar_item->type) {
927 mainwin = (MainWindow*)toolbar_item->parent;
928 replyall_btn = mainwin->toolbar->replyall_btn;
929 window = mainwin->window;
931 case TOOLBAR_MSGVIEW:
932 msgview = (MessageView*)toolbar_item->parent;
933 replyall_btn = msgview->toolbar->replyall_btn;
934 window = msgview->window;
940 gtk_button_set_relief(GTK_BUTTON(replyall_btn), GTK_RELIEF_NONE);
941 manage_window_focus_in(window, NULL, NULL);
944 static void toolbar_reply_to_list_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
946 Toolbar *toolbar_data = (Toolbar*)data;
948 if (event->button == 3) {
949 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
950 gtk_menu_popup(GTK_MENU(toolbar_data->replylist_popup), NULL, NULL,
951 menu_button_position, widget,
952 event->button, event->time);
956 static void toolbar_reply_to_list_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
958 ToolbarItem *toolbar_item = (ToolbarItem*)data;
959 gpointer parent = toolbar_item->parent;
961 GtkWidget *replylist_btn;
964 g_return_if_fail(toolbar_item != NULL);
966 switch(toolbar_item->type) {
968 replylist_btn = ((MainWindow*)parent)->toolbar->replylist_btn;
969 window = ((MainWindow*)parent)->window;
971 case TOOLBAR_MSGVIEW:
972 replylist_btn = ((MessageView*)parent)->toolbar->replylist_btn;
973 window = ((MessageView*)parent)->window;
979 gtk_button_set_relief(GTK_BUTTON(replylist_btn), GTK_RELIEF_NONE);
980 manage_window_focus_in(window, NULL, NULL);
983 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
985 Toolbar *toolbar_data = (Toolbar*)data;
987 if (event->button == 3) {
988 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
989 gtk_menu_popup(GTK_MENU(toolbar_data->replysender_popup), NULL, NULL,
990 menu_button_position, widget,
991 event->button, event->time);
995 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
997 ToolbarItem *toolbar_item = (ToolbarItem*)data;
998 gpointer parent = toolbar_item->parent;
1000 GtkWidget *replysender_btn;
1002 g_return_if_fail(toolbar_item != NULL);
1004 switch(toolbar_item->type) {
1006 replysender_btn = ((MainWindow*)parent)->toolbar->replysender_btn;
1007 window = ((MainWindow*)parent)->window;
1009 case TOOLBAR_MSGVIEW:
1010 replysender_btn = ((MessageView*)parent)->toolbar->replysender_btn;
1011 window = ((MessageView*)parent)->window;
1017 gtk_button_set_relief(GTK_BUTTON(replysender_btn), GTK_RELIEF_NONE);
1018 manage_window_focus_in(window, NULL, NULL);
1021 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1023 Toolbar *toolbar_data = (Toolbar*)data;
1025 if (event->button == 3) {
1026 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1027 gtk_menu_popup(GTK_MENU(toolbar_data->fwd_popup), NULL, NULL,
1028 menu_button_position, widget,
1029 event->button, event->time);
1033 static void toolbar_forward_popup_closed_cb (GtkMenuShell *menu_shell,
1036 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1037 gpointer parent = toolbar_item->parent;
1041 g_return_if_fail(toolbar_item != NULL);
1043 switch(toolbar_item->type) {
1045 fwd_btn = ((MainWindow*)parent)->toolbar->fwd_btn;
1046 window = ((MainWindow*)parent)->window;
1048 case TOOLBAR_MSGVIEW:
1049 fwd_btn = ((MessageView*)parent)->toolbar->fwd_btn;
1050 window = ((MessageView*)parent)->window;
1056 gtk_button_set_relief(GTK_BUTTON(fwd_btn), GTK_RELIEF_NONE);
1057 manage_window_focus_in(window, NULL, NULL);
1061 * Delete current/selected(s) message(s)
1063 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1065 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1066 MainWindow *mainwin;
1067 MessageView *msgview;
1069 g_return_if_fail(toolbar_item != NULL);
1071 switch (toolbar_item->type) {
1072 case TOOLBAR_MSGVIEW:
1073 msgview = (MessageView*)toolbar_item->parent;
1074 /* make sure the selected msg in summaryview is
1075 the one we are asked to delete */
1076 delete_msgview_cb(msgview, 0, widget);
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;
1220 * TODO: Check if summaryview stay in the same place when this message view was created
1221 * if summary have other message select the next will be based on message selected in summaryview
1223 summary_select_next_unread(msgview->mainwin->summaryview);
1225 /** Now we need to update the messageview window */
1226 if (msgview->mainwin->summaryview->selected) {
1227 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1229 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1230 msgview->mainwin->summaryview->selected);
1232 messageview_show(msgview, msginfo,
1233 msgview->all_headers);
1235 gtk_widget_destroy(msgview->window);
1239 debug_print("toolbar event not supported\n");
1243 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1245 compose_toolbar_cb(A_SEND, data);
1248 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1250 compose_toolbar_cb(A_SENDL, data);
1253 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1255 compose_toolbar_cb(A_DRAFT, data);
1258 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1260 compose_toolbar_cb(A_INSERT, data);
1263 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1265 compose_toolbar_cb(A_ATTACH, data);
1268 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1270 compose_toolbar_cb(A_SIG, data);
1273 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1275 compose_toolbar_cb(A_EXTEDITOR, data);
1278 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
1280 compose_toolbar_cb(A_LINEWRAP, data);
1284 * Execute actions from toolbar
1286 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1288 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1289 GSList *action_list;
1290 MainWindow *mainwin;
1292 MessageView *msgview;
1293 gpointer parent = toolbar_item->parent;
1295 g_return_if_fail(toolbar_item != NULL);
1297 switch (toolbar_item->type) {
1299 mainwin = (MainWindow*)parent;
1300 action_list = mainwin->toolbar->action_list;
1302 case TOOLBAR_COMPOSE:
1303 compose = (Compose*)parent;
1304 action_list = compose->toolbar->action_list;
1306 case TOOLBAR_MSGVIEW:
1307 msgview = (MessageView*)parent;
1308 action_list = msgview->toolbar->action_list;
1311 debug_print("toolbar event not supported\n");
1314 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1317 static MainWindow *get_mainwin(gpointer data)
1319 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1320 MainWindow *mainwin = NULL;
1321 MessageView *msgview;
1323 g_return_val_if_fail(toolbar_item != NULL, NULL);
1325 switch(toolbar_item->type) {
1327 mainwin = (MainWindow*)toolbar_item->parent;
1329 case TOOLBAR_MSGVIEW:
1330 msgview = (MessageView*)toolbar_item->parent;
1331 mainwin = (MainWindow*)msgview->mainwin;
1340 static GtkWidget *get_window_widget(ToolbarType type, gpointer data)
1342 MainWindow *mainwin;
1343 MessageView *msgview;
1347 mainwin = (MainWindow*)data;
1348 return mainwin->window;
1350 case TOOLBAR_MSGVIEW:
1351 msgview = (MessageView*)data;
1352 return msgview->vbox;
1360 static void toolbar_buttons_cb(GtkWidget *widget,
1367 void (*func)(GtkWidget *widget, gpointer data);
1369 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1370 { A_RECEIVE_CUR, toolbar_inc_cb },
1371 { A_SEND_QUEUED, toolbar_send_queued_cb },
1372 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1373 { A_COMPOSE_NEWS, toolbar_compose_cb },
1374 { A_REPLY_MESSAGE, toolbar_reply_cb },
1375 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1376 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1377 { A_REPLY_ML, toolbar_reply_to_list_cb },
1378 { A_FORWARD, toolbar_forward_cb },
1379 { A_DELETE, toolbar_delete_cb },
1380 { A_EXECUTE, toolbar_exec_cb },
1381 { A_GOTO_NEXT, toolbar_next_unread_cb },
1383 { A_SEND, toolbar_send_cb },
1384 { A_SENDL, toolbar_send_later_cb },
1385 { A_DRAFT, toolbar_draft_cb },
1386 { A_INSERT, toolbar_insert_cb },
1387 { A_ATTACH, toolbar_attach_cb },
1388 { A_SIG, toolbar_sig_cb },
1389 { A_EXTEDITOR, toolbar_ext_editor_cb },
1390 { A_LINEWRAP, toolbar_linewrap_cb },
1391 { A_ADDRBOOK, toolbar_addrbook_cb },
1393 { A_SYL_ACTIONS, toolbar_actions_execute_cb }
1396 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1398 for (i = 0; i < num_items; i++) {
1399 if (callbacks[i].index == item->index) {
1400 callbacks[i].func(widget, item);
1407 * Create a new toolbar with specified type
1408 * if a callback list is passed it will be used before the
1409 * common callback list
1411 Toolbar *toolbar_create(ToolbarType type,
1412 GtkWidget *container,
1415 ToolbarItem *toolbar_item;
1418 GtkWidget *icon_wid = NULL;
1419 GtkWidget *icon_news;
1421 GtkWidget *item_news;
1422 GtkWidget *window_wid;
1424 guint n_menu_entries;
1425 GtkWidget *reply_popup;
1426 GtkWidget *replyall_popup;
1427 GtkWidget *replylist_popup;
1428 GtkWidget *replysender_popup;
1429 GtkWidget *fwd_popup;
1431 GtkTooltips *toolbar_tips;
1432 ToolbarSylpheedActions *action_item;
1434 GSList *toolbar_list;
1435 Toolbar *toolbar_data;
1438 toolbar_tips = gtk_tooltips_new();
1440 toolbar_read_config_file(type);
1441 toolbar_list = toolbar_get_list(type);
1443 toolbar_data = g_new0(Toolbar, 1);
1445 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1447 gtk_container_add(GTK_CONTAINER(container), toolbar);
1448 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1449 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1450 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1451 GTK_TOOLBAR_SPACE_LINE);
1453 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1455 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1456 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1460 toolbar_item = g_new0(ToolbarItem, 1);
1461 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1462 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1463 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1464 toolbar_item->parent = data;
1465 toolbar_item->type = type;
1467 /* collect toolbar items in list to keep track */
1468 toolbar_data->item_list =
1469 g_slist_append(toolbar_data->item_list,
1472 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1473 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1477 icon_wid, toolbar_buttons_cb,
1480 switch (toolbar_item->index) {
1483 toolbar_data->getall_btn = item;
1484 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1485 toolbar_data->getall_btn,
1486 _("Receive Mail on all Accounts"), NULL);
1489 toolbar_data->get_btn = item;
1490 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1491 toolbar_data->get_btn,
1492 _("Receive Mail on current Account"), NULL);
1495 toolbar_data->send_btn = item;
1496 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1497 toolbar_data->send_btn,
1498 _("Send Queued Message(s)"), NULL);
1500 case A_COMPOSE_EMAIL:
1501 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1502 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1506 icon_news, toolbar_buttons_cb,
1508 toolbar_data->compose_mail_btn = item;
1509 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1510 toolbar_data->compose_mail_btn,
1511 _("Compose Email"), NULL);
1512 toolbar_data->compose_news_btn = item_news;
1513 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1514 toolbar_data->compose_news_btn,
1515 _("Compose News"), NULL);
1517 case A_REPLY_MESSAGE:
1518 toolbar_data->reply_btn = item;
1519 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1520 toolbar_data->reply_btn,
1521 _("Reply to Message"), NULL);
1522 gtk_signal_connect(GTK_OBJECT(toolbar_data->reply_btn),
1523 "button_press_event",
1524 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
1526 n_menu_entries = sizeof(reply_popup_entries) /
1527 sizeof(reply_popup_entries[0]);
1529 window_wid = get_window_widget(type, data);
1530 reply_popup = popupmenu_create(window_wid,
1531 reply_popup_entries, n_menu_entries,
1532 "<ReplyPopup>", (gpointer)toolbar_item);
1534 gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
1535 GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), toolbar_item);
1536 toolbar_data->reply_popup = reply_popup;
1538 case A_REPLY_SENDER:
1539 toolbar_data->replysender_btn = item;
1540 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1541 toolbar_data->replysender_btn,
1542 _("Reply to Sender"), NULL);
1543 gtk_signal_connect(GTK_OBJECT(toolbar_data->replysender_btn),
1544 "button_press_event",
1545 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
1547 n_menu_entries = sizeof(replysender_popup_entries) /
1548 sizeof(replysender_popup_entries[0]);
1550 window_wid = get_window_widget(type, data);
1551 replysender_popup = popupmenu_create(window_wid,
1552 replysender_popup_entries, n_menu_entries,
1553 "<ReplySenderPopup>", (gpointer)toolbar_item);
1555 gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
1556 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), toolbar_item);
1557 toolbar_data->replysender_popup = replysender_popup;
1560 toolbar_data->replyall_btn = item;
1561 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1562 toolbar_data->replyall_btn,
1563 _("Reply to All"), NULL);
1564 gtk_signal_connect(GTK_OBJECT(toolbar_data->replyall_btn),
1565 "button_press_event",
1566 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
1568 n_menu_entries = sizeof(replyall_popup_entries) /
1569 sizeof(replyall_popup_entries[0]);
1571 window_wid = get_window_widget(type, data);
1572 replyall_popup = popupmenu_create(window_wid,
1573 replyall_popup_entries, n_menu_entries,
1574 "<ReplyAllPopup>", (gpointer)toolbar_item);
1576 gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
1577 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), toolbar_item);
1578 toolbar_data->replyall_popup = replyall_popup;
1581 toolbar_data->replylist_btn = item;
1582 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1583 toolbar_data->replylist_btn,
1584 _("Reply to Mailing-list"), NULL);
1585 gtk_signal_connect(GTK_OBJECT(toolbar_data->replylist_btn),
1586 "button_press_event",
1587 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_cb),
1589 n_menu_entries = sizeof(replylist_popup_entries) /
1590 sizeof(replylist_popup_entries[0]);
1592 window_wid = get_window_widget(type, data);
1593 replylist_popup = popupmenu_create(window_wid,
1594 replylist_popup_entries, n_menu_entries,
1595 "<ReplyMlPopup>", (gpointer)toolbar_item);
1597 gtk_signal_connect(GTK_OBJECT(replylist_popup), "selection_done",
1598 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_closed_cb), toolbar_item);
1599 toolbar_data->replylist_popup = replylist_popup;
1602 toolbar_data->fwd_btn = item;
1603 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1604 toolbar_data->fwd_btn,
1605 _("Forward Message"), NULL);
1606 gtk_signal_connect(GTK_OBJECT(toolbar_data->fwd_btn),
1607 "button_press_event",
1608 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
1610 n_menu_entries = sizeof(fwd_popup_entries) /
1611 sizeof(fwd_popup_entries[0]);
1613 window_wid = get_window_widget(type, data);
1614 fwd_popup = popupmenu_create(window_wid,
1615 fwd_popup_entries, n_menu_entries,
1616 "<ForwardPopup>", (gpointer)toolbar_item);
1618 gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
1619 GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), toolbar_item);
1620 toolbar_data->fwd_popup = fwd_popup;
1623 toolbar_data->delete_btn = item;
1624 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1625 toolbar_data->delete_btn,
1626 _("Delete Message"), NULL);
1629 toolbar_data->exec_btn = item;
1630 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1631 toolbar_data->exec_btn,
1632 _("Execute"), NULL);
1635 toolbar_data->next_btn = item;
1636 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1637 toolbar_data->next_btn,
1638 _("Goto Next Message"), NULL);
1641 /* Compose Toolbar */
1643 toolbar_data->send_btn = item;
1644 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1645 toolbar_data->send_btn,
1646 _("Send Message"), NULL);
1649 toolbar_data->sendl_btn = item;
1650 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1651 toolbar_data->sendl_btn,
1652 _("Put into queue folder and send later"), NULL);
1655 toolbar_data->draft_btn = item;
1656 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1657 toolbar_data->draft_btn,
1658 _("Save to draft folder"), NULL);
1661 toolbar_data->insert_btn = item;
1662 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1663 toolbar_data->insert_btn,
1664 _("Insert file"), NULL);
1667 toolbar_data->attach_btn = item;
1668 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1669 toolbar_data->attach_btn,
1670 _("Attach file"), NULL);
1673 toolbar_data->sig_btn = item;
1674 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1675 toolbar_data->sig_btn,
1676 _("Insert signature"), NULL);
1679 toolbar_data->exteditor_btn = item;
1680 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1681 toolbar_data->exteditor_btn,
1682 _("Edit with external editor"), NULL);
1685 toolbar_data->linewrap_btn = item;
1686 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1687 toolbar_data->linewrap_btn,
1688 _("Wrap all long lines"), NULL);
1691 toolbar_data->addrbook_btn = item;
1692 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1693 toolbar_data->addrbook_btn,
1694 _("Address book"), NULL);
1698 action_item = g_new0(ToolbarSylpheedActions, 1);
1699 action_item->widget = item;
1700 action_item->name = g_strdup(toolbar_item->text);
1702 toolbar_data->action_list =
1703 g_slist_append(toolbar_data->action_list,
1706 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1708 action_item->name, NULL);
1710 gtk_widget_show(item);
1717 toolbar_data->toolbar = toolbar;
1718 if (type == TOOLBAR_MAIN)
1719 activate_compose_button(toolbar_data,
1720 prefs_common.toolbar_style,
1721 toolbar_data->compose_btn_type);
1723 gtk_widget_show_all(toolbar);
1725 return toolbar_data;
1729 * Free toolbar structures
1731 void toolbar_destroy(Toolbar * toolbar) {
1733 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1734 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1737 void toolbar_update(ToolbarType type, gpointer data)
1739 Toolbar *toolbar_data;
1740 GtkWidget *handlebox;
1741 MainWindow *mainwin = (MainWindow*)data;
1742 Compose *compose = (Compose*)data;
1743 MessageView *msgview = (MessageView*)data;
1747 toolbar_data = mainwin->toolbar;
1748 handlebox = mainwin->handlebox;
1750 case TOOLBAR_COMPOSE:
1751 toolbar_data = compose->toolbar;
1752 handlebox = compose->handlebox;
1754 case TOOLBAR_MSGVIEW:
1755 toolbar_data = msgview->toolbar;
1756 handlebox = msgview->handlebox;
1762 gtk_container_remove(GTK_CONTAINER(handlebox),
1763 GTK_WIDGET(toolbar_data->toolbar));
1765 toolbar_init(toolbar_data);
1766 toolbar_data = toolbar_create(type, handlebox, data);
1769 mainwin->toolbar = toolbar_data;
1771 case TOOLBAR_COMPOSE:
1772 compose->toolbar = toolbar_data;
1774 case TOOLBAR_MSGVIEW:
1775 msgview->toolbar = toolbar_data;
1779 toolbar_style(type, prefs_common.toolbar_style, data);
1781 if (type == TOOLBAR_MAIN)
1782 toolbar_main_set_sensitive((MainWindow*)data);
1785 void toolbar_main_set_sensitive(gpointer data)
1787 SensitiveCond state;
1789 MainWindow *mainwin = (MainWindow*)data;
1790 Toolbar *toolbar = mainwin->toolbar;
1792 GSList *entry_list = NULL;
1794 typedef struct _Entry Entry;
1801 #define SET_WIDGET_COND(w, c) \
1803 Entry *e = g_new0(Entry, 1); \
1806 entry_list = g_slist_append(entry_list, e); \
1809 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1810 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1811 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1812 SET_WIDGET_COND(toolbar->reply_btn,
1813 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1814 SET_WIDGET_COND(toolbar->replyall_btn,
1815 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1816 SET_WIDGET_COND(toolbar->replylist_btn,
1817 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1818 SET_WIDGET_COND(toolbar->replysender_btn,
1819 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1820 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1822 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1823 SET_WIDGET_COND(toolbar->delete_btn,
1824 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1825 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1827 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
1828 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1830 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1833 #undef SET_WIDGET_COND
1835 state = main_window_get_current_state(mainwin);
1837 for (cur = entry_list; cur != NULL; cur = cur->next) {
1838 Entry *e = (Entry*) cur->data;
1840 if (e->widget != NULL) {
1841 sensitive = ((e->cond & state) == e->cond);
1842 gtk_widget_set_sensitive(e->widget, sensitive);
1846 while (entry_list != NULL) {
1847 Entry *e = (Entry*) entry_list->data;
1851 entry_list = g_slist_remove(entry_list, e);
1854 g_slist_free(entry_list);
1856 activate_compose_button(toolbar,
1857 prefs_common.toolbar_style,
1858 toolbar->compose_btn_type);
1861 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1863 Compose *compose = (Compose*)data;
1864 GSList *items = compose->toolbar->action_list;
1866 if (compose->toolbar->send_btn)
1867 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1868 if (compose->toolbar->sendl_btn)
1869 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1870 if (compose->toolbar->draft_btn )
1871 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1872 if (compose->toolbar->insert_btn )
1873 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1874 if (compose->toolbar->attach_btn)
1875 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1876 if (compose->toolbar->sig_btn)
1877 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1878 if (compose->toolbar->exteditor_btn)
1879 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1880 if (compose->toolbar->linewrap_btn)
1881 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
1882 if (compose->toolbar->addrbook_btn)
1883 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1884 for (; items != NULL; items = g_slist_next(items)) {
1885 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1886 gtk_widget_set_sensitive(item->widget, sensitive);
1891 * Initialize toolbar structure
1893 void toolbar_init(Toolbar * toolbar) {
1895 toolbar->toolbar = NULL;
1896 toolbar->get_btn = NULL;
1897 toolbar->getall_btn = NULL;
1898 toolbar->send_btn = NULL;
1899 toolbar->compose_mail_btn = NULL;
1900 toolbar->compose_news_btn = NULL;
1901 toolbar->reply_btn = NULL;
1902 toolbar->replysender_btn = NULL;
1903 toolbar->replyall_btn = NULL;
1904 toolbar->replylist_btn = NULL;
1905 toolbar->fwd_btn = NULL;
1906 toolbar->delete_btn = NULL;
1907 toolbar->next_btn = NULL;
1908 toolbar->exec_btn = NULL;
1910 /* compose buttons */
1911 toolbar->sendl_btn = NULL;
1912 toolbar->draft_btn = NULL;
1913 toolbar->insert_btn = NULL;
1914 toolbar->attach_btn = NULL;
1915 toolbar->sig_btn = NULL;
1916 toolbar->exteditor_btn = NULL;
1917 toolbar->linewrap_btn = NULL;
1918 toolbar->addrbook_btn = NULL;
1920 toolbar_destroy(toolbar);
1923 /* exported functions */
1925 void delete_msgview_cb(gpointer data, guint action, GtkWidget *widget)
1927 MessageView *msgview = (MessageView*)data;
1929 if (msgview->mainwin->summaryview->selected) {
1930 SummaryView *summaryview = msgview->mainwin->summaryview;
1931 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
1932 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
1933 summaryview->selected);
1934 if (msginfo->msgnum != msgview->msginfo->msgnum) {
1935 alertpanel_error(_("Message already removed from folder."));
1940 summary_delete(msgview->mainwin->summaryview);
1942 if (msgview->mainwin->summaryview->selected) {
1943 SummaryView *summaryview = msgview->mainwin->summaryview;
1944 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
1945 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
1946 summaryview->selected);
1947 messageview_show(msgview, msginfo,
1948 msgview->all_headers);
1950 toolbar_clear_list(TOOLBAR_MSGVIEW);
1951 toolbar_destroy(msgview->toolbar);
1952 gtk_widget_destroy(msgview->window);
1956 void toolbar_menu_reply(ToolbarType type, gpointer data, guint action)
1960 g_return_if_fail(data != NULL);
1962 item = g_new0(ToolbarItem, 1);
1963 item->parent = data;
1965 toolbar_reply(item, action);
1969 static void toolbar_reply(gpointer data, guint action)
1971 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1972 MainWindow *mainwin;
1973 MessageView *msgview;
1974 SummaryView *summaryview;
1976 MsgInfo *msginfo = NULL;
1979 switch (toolbar_item->type) {
1981 mainwin = (MainWindow*)toolbar_item->parent;
1982 summaryview = mainwin->summaryview;
1983 msginfo = gtk_ctree_node_get_row_data(GTK_CTREE(summaryview->ctree),
1984 summaryview->selected);
1985 msgview = mainwin->summaryview->messageview;
1986 sel = GTK_CLIST(summaryview->ctree)->selection;
1988 case TOOLBAR_MSGVIEW:
1989 msgview = (MessageView*)toolbar_item->parent;
1990 summaryview = msgview->mainwin->summaryview;
1991 msginfo = msgview->msginfo;
1997 g_return_if_fail (msginfo != NULL);
1998 g_return_if_fail (summaryview != NULL);
2000 text = gtkut_editable_get_selection
2001 (GTK_EDITABLE(msgview->textview->text));
2003 if (!text && msgview->type == MVIEW_MIME
2004 && msgview->mimeview->type == MIMEVIEW_TEXT
2005 && msgview->mimeview->textview
2006 && !msgview->mimeview->textview->default_text) {
2007 text = gtkut_editable_get_selection
2008 (GTK_EDITABLE(msgview->mimeview->textview->text));
2013 compose_reply(msginfo, prefs_common.reply_with_quote,
2014 FALSE, prefs_common.default_reply_list, FALSE, text);
2016 case COMPOSE_REPLY_WITH_QUOTE:
2017 compose_reply(msginfo, TRUE, FALSE, prefs_common.default_reply_list, FALSE, text);
2019 case COMPOSE_REPLY_WITHOUT_QUOTE:
2020 compose_reply(msginfo, FALSE, FALSE, prefs_common.default_reply_list, FALSE, NULL);
2022 case COMPOSE_REPLY_TO_SENDER:
2023 compose_reply(msginfo, prefs_common.reply_with_quote,
2024 FALSE, FALSE, TRUE, text);
2026 case COMPOSE_FOLLOWUP_AND_REPLY_TO:
2027 compose_followup_and_reply_to(msginfo,
2028 prefs_common.reply_with_quote,
2029 FALSE, FALSE, text);
2031 case COMPOSE_REPLY_TO_SENDER_WITH_QUOTE:
2032 compose_reply(msginfo, TRUE, FALSE, FALSE, TRUE, text);
2034 case COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE:
2035 compose_reply(msginfo, FALSE, FALSE, FALSE, TRUE, NULL);
2037 case COMPOSE_REPLY_TO_ALL:
2038 compose_reply(msginfo, prefs_common.reply_with_quote,
2039 TRUE, FALSE, FALSE, text);
2041 case COMPOSE_REPLY_TO_ALL_WITH_QUOTE:
2042 compose_reply(msginfo, TRUE, TRUE, FALSE, FALSE, text);
2044 case COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE:
2045 compose_reply(msginfo, FALSE, TRUE, FALSE, FALSE, NULL);
2047 case COMPOSE_REPLY_TO_LIST:
2048 compose_reply(msginfo, prefs_common.reply_with_quote,
2049 FALSE, TRUE, FALSE, text);
2051 case COMPOSE_REPLY_TO_LIST_WITH_QUOTE:
2052 compose_reply(msginfo, TRUE, FALSE, TRUE, FALSE, text);
2054 case COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE:
2055 compose_reply(msginfo, FALSE, FALSE, TRUE, FALSE, NULL);
2057 case COMPOSE_FORWARD:
2058 if (prefs_common.forward_as_attachment) {
2059 toolbar_reply(data, COMPOSE_FORWARD_AS_ATTACH);
2062 toolbar_reply(data, COMPOSE_FORWARD_INLINE);
2066 case COMPOSE_FORWARD_INLINE:
2067 /* check if we reply to more than one Message */
2068 if (sel && !sel->next && toolbar_item->type == TOOLBAR_MAIN) {
2069 compose_forward(NULL, msginfo, FALSE, text);
2071 } else if (sel == NULL && toolbar_item->type == TOOLBAR_MSGVIEW) {
2072 compose_forward(NULL, msginfo, FALSE, text);
2075 /* more messages FALL THROUGH */
2076 case COMPOSE_FORWARD_AS_ATTACH:
2078 GSList *msginfo_list = NULL;
2079 /* check if we reply to more than one Message */
2081 for ( ; sel != NULL; sel = sel->next)
2083 g_slist_append(msginfo_list,
2084 gtk_ctree_node_get_row_data(GTK_CTREE(summaryview->ctree),
2085 GTK_CTREE_NODE(sel->data)));
2087 /* invoked from messageview */
2088 msginfo_list = g_slist_append(msginfo_list, msginfo);
2091 compose_forward_multiple(NULL, msginfo_list);
2092 g_slist_free(msginfo_list);
2096 case COMPOSE_REDIRECT:
2097 compose_redirect(NULL, msginfo);
2100 g_warning("toolbar_reply(): invalid action: %d\n", action);
2103 summary_set_marks_selected(summaryview);
2108 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2110 MainWindow *mainwin = (MainWindow*)data;
2112 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2115 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2117 MainWindow *mainwin = (MainWindow*)data;
2119 inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
2122 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2126 if (prefs_common.work_offline)
2127 if (alertpanel(_("Offline warning"),
2128 _("You're working offline. Override?"),
2129 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
2132 for (list = folder_get_list(); list != NULL; list = list->next) {
2133 Folder *folder = list->data;
2135 if (folder->queue) {
2136 if (procmsg_send_queue
2137 (folder->queue, prefs_common.savemsg) < 0)
2138 alertpanel_error(_("Some errors occurred while sending queued messages."));
2139 folder_item_scan(folder->queue);
2144 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2146 MainWindow *mainwin = (MainWindow*)data;
2147 PrefsAccount *ac = NULL;
2148 FolderItem *item = mainwin->summaryview->folder_item;
2153 ac = account_find_from_item(item);
2154 if (ac && ac->protocol != A_NNTP) {
2155 compose_new_with_folderitem(ac, item); /* CLAWS */
2161 * CLAWS - use current account
2163 if (cur_account && (cur_account->protocol != A_NNTP)) {
2164 compose_new_with_folderitem(cur_account, item);
2169 * CLAWS - just get the first one
2171 list = account_get_list();
2172 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2173 ac = (PrefsAccount *) cur->data;
2174 if (ac->protocol != A_NNTP) {
2175 compose_new_with_folderitem(ac, item);
2181 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2183 MainWindow *mainwin = (MainWindow*)data;
2184 PrefsAccount * ac = NULL;
2188 if (mainwin->summaryview->folder_item) {
2189 ac = mainwin->summaryview->folder_item->folder->account;
2190 if (ac && ac->protocol == A_NNTP) {
2192 mainwin->summaryview->folder_item->path,
2198 list = account_get_list();
2199 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2200 ac = (PrefsAccount *) cur->data;
2201 if (ac->protocol == A_NNTP) {
2202 compose_new(ac, NULL, NULL);