2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001 Hiroyuki Yamamoto
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_delete_cb (GtkWidget *widget,
93 static void toolbar_compose_cb (GtkWidget *widget,
96 static void toolbar_reply_cb (GtkWidget *widget,
99 static void toolbar_reply_to_all_cb (GtkWidget *widget,
102 static void toolbar_reply_to_list_cb (GtkWidget *widget,
105 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
108 static void toolbar_forward_cb (GtkWidget *widget,
111 static void toolbar_next_unread_cb (GtkWidget *widget,
114 static void toolbar_actions_execute_cb (GtkWidget *widget,
118 static void toolbar_send_cb (GtkWidget *widget,
120 static void toolbar_send_later_cb (GtkWidget *widget,
122 static void toolbar_draft_cb (GtkWidget *widget,
124 static void toolbar_insert_cb (GtkWidget *widget,
126 static void toolbar_attach_cb (GtkWidget *widget,
128 static void toolbar_sig_cb (GtkWidget *widget,
130 static void toolbar_ext_editor_cb (GtkWidget *widget,
132 static void toolbar_linewrap_cb (GtkWidget *widget,
134 static void toolbar_addrbook_cb (GtkWidget *widget,
137 static void toolbar_popup_cb (gpointer data,
143 } toolbar_text [] = {
144 { "A_RECEIVE_ALL", N_("Receive Mail on all Accounts") },
145 { "A_RECEIVE_CUR", N_("Receive Mail on current Account") },
146 { "A_SEND_QUEUED", N_("Send Queued Message(s)") },
147 { "A_COMPOSE_EMAIL", N_("Compose Email") },
148 { "A_COMPOSE_NEWS", N_("Compose News") },
149 { "A_REPLY_MESSAGE", N_("Reply to Message") },
150 { "A_REPLY_SENDER", N_("Reply to Sender") },
151 { "A_REPLY_ALL", N_("Reply to All") },
152 { "A_REPLY_ML", N_("Reply to Mailing-list") },
153 { "A_FORWARD", N_("Forward Message") },
154 { "A_DELETE", N_("Delete Message") },
155 { "A_EXECUTE", N_("Execute") },
156 { "A_GOTO_NEXT", N_("Goto Next Message") },
158 { "A_SEND", N_("Send Message") },
159 { "A_SENDL", N_("Put into queue folder and send later") },
160 { "A_DRAFT", N_("Save to draft folder") },
161 { "A_INSERT", N_("Insert file") },
162 { "A_ATTACH", N_("Attach file") },
163 { "A_SIG", N_("Insert signature") },
164 { "A_EXTEDITOR", N_("Edit with external editor") },
165 { "A_LINEWRAP", N_("Wrap all long lines") },
166 { "A_ADDRBOOK", N_("Address book") },
168 { "A_SYL_ACTIONS", N_("Sylpheed Actions Feature") },
169 { "A_SEPARATOR", N_("Separator") }
172 /* struct holds configuration files and a list of
173 * currently active toolbar items
174 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
178 const gchar *conf_file;
180 } toolbar_config[3] = {
181 { "toolbar_main.xml", NULL},
182 { "toolbar_compose.xml", NULL},
183 { "toolbar_msgview.xml", NULL}
186 static GtkItemFactoryEntry reply_popup_entries[] =
188 {N_("/Reply with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITH_QUOTE, NULL},
189 {N_("/_Reply without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_WITHOUT_QUOTE, NULL}
191 static GtkItemFactoryEntry replyall_popup_entries[] =
193 {N_("/Reply to all with _quote"), "<shift>A", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE, NULL},
194 {N_("/_Reply to all without quote"), "a", toolbar_popup_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE, NULL}
196 static GtkItemFactoryEntry replylist_popup_entries[] =
198 {N_("/Reply to list with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE, NULL},
199 {N_("/_Reply to list without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE, NULL}
201 static GtkItemFactoryEntry replysender_popup_entries[] =
203 {N_("/Reply to sender with _quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE, NULL},
204 {N_("/_Reply to sender without quote"), NULL, toolbar_popup_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE, NULL}
206 static GtkItemFactoryEntry fwd_popup_entries[] =
208 {N_("/_Forward message (inline style)"), "f", toolbar_popup_cb, COMPOSE_FORWARD_INLINE, NULL},
209 {N_("/Forward message as _attachment"), "<shift>F", toolbar_popup_cb, COMPOSE_FORWARD_AS_ATTACH, NULL}
213 gint toolbar_ret_val_from_descr(const gchar *descr)
217 for (i = 0; i < N_ACTION_VAL; i++) {
218 if (g_strcasecmp(gettext(toolbar_text[i].descr), descr) == 0)
225 gchar *toolbar_ret_descr_from_val(gint val)
227 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
229 return gettext(toolbar_text[val].descr);
232 static gint toolbar_ret_val_from_text(const gchar *text)
236 for (i = 0; i < N_ACTION_VAL; i++) {
237 if (g_strcasecmp(toolbar_text[i].index_str, text) == 0)
244 static gchar *toolbar_ret_text_from_val(gint val)
246 g_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
248 return toolbar_text[val].index_str;
251 gboolean toolbar_is_duplicate(gint action, ToolbarType source)
255 if ((action == A_SEPARATOR) || (action == A_SYL_ACTIONS))
258 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
259 ToolbarItem *item = (ToolbarItem*) cur->data;
261 if (item->index == action)
267 /* depending on toolbar type this function
268 returns a list of available toolbar events being
269 displayed by prefs_toolbar
271 GList *toolbar_get_action_items(ToolbarType source)
276 if (source == TOOLBAR_MAIN) {
277 gint main_items[14] = { A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
278 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
279 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
280 A_DELETE, A_EXECUTE, A_GOTO_NEXT,
281 A_ADDRBOOK, A_SYL_ACTIONS };
283 for (i = 0; i < sizeof(main_items)/sizeof(main_items[0]); i++)
284 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
286 else if (source == TOOLBAR_COMPOSE) {
287 gint comp_items[10] = { A_SEND, A_SENDL, A_DRAFT,
288 A_INSERT, A_ATTACH, A_SIG,
289 A_EXTEDITOR, A_LINEWRAP, A_ADDRBOOK,
292 for (i = 0; i < sizeof(comp_items)/sizeof(comp_items[0]); i++)
293 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
295 else if (source == TOOLBAR_MSGVIEW) {
296 gint msgv_items[10] = { A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
297 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
298 A_DELETE, A_GOTO_NEXT, A_ADDRBOOK,
301 for (i = 0; i < sizeof(msgv_items)/sizeof(msgv_items[0]); i++)
302 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
308 static void toolbar_parse_item(XMLFile *file, ToolbarType source)
312 ToolbarItem *item = NULL;
314 attr = xml_get_current_tag_attr(file);
315 item = g_new0(ToolbarItem, 1);
317 name = ((XMLAttr *)attr->data)->name;
318 value = ((XMLAttr *)attr->data)->value;
320 if (g_strcasecmp(name, TOOLBAR_ICON_FILE) == 0)
321 item->file = g_strdup (value);
322 else if (g_strcasecmp(name, TOOLBAR_ICON_TEXT) == 0)
323 item->text = g_strdup (value);
324 else if (g_strcasecmp(name, TOOLBAR_ICON_ACTION) == 0)
325 item->index = toolbar_ret_val_from_text(value);
327 attr = g_list_next(attr);
329 if (item->index != -1) {
331 if (!toolbar_is_duplicate(item->index, source))
332 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
337 static void toolbar_set_default_main(void)
343 } default_toolbar[] = {
344 { A_RECEIVE_CUR, STOCK_PIXMAP_MAIL_RECEIVE, _("Get") },
345 { A_RECEIVE_ALL, STOCK_PIXMAP_MAIL_RECEIVE_ALL, _("Get All") },
346 { A_SEPARATOR, 0, ("") },
347 { A_SEND_QUEUED, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send") },
348 { A_COMPOSE_EMAIL, STOCK_PIXMAP_MAIL_COMPOSE, _("Email") },
349 { A_SEPARATOR, 0, ("") },
350 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
351 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
352 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
353 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
354 { A_SEPARATOR, 0, ("") },
355 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
356 { A_EXECUTE, STOCK_PIXMAP_EXEC, _("Execute") },
357 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
362 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
364 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
366 if (default_toolbar[i].action != A_SEPARATOR) {
368 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
370 toolbar_item->file = g_strdup(file);
371 toolbar_item->index = default_toolbar[i].action;
372 toolbar_item->text = g_strdup(default_toolbar[i].text);
375 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
376 toolbar_item->index = A_SEPARATOR;
379 if (toolbar_item->index != -1) {
380 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MAIN))
381 toolbar_config[TOOLBAR_MAIN].item_list =
382 g_slist_append(toolbar_config[TOOLBAR_MAIN].item_list, toolbar_item);
387 static void toolbar_set_default_compose(void)
393 } default_toolbar[] = {
394 { A_SEND, STOCK_PIXMAP_MAIL_SEND, _("Send") },
395 { A_SENDL, STOCK_PIXMAP_MAIL_SEND_QUEUE, _("Send later") },
396 { A_DRAFT, STOCK_PIXMAP_MAIL, _("Draft") },
397 { A_SEPARATOR, 0, ("") },
398 { A_INSERT, STOCK_PIXMAP_INSERT_FILE, _("Insert") },
399 { A_ATTACH, STOCK_PIXMAP_MAIL_ATTACH, _("Attach") },
400 { A_SIG, STOCK_PIXMAP_MAIL_SIGN, _("Signature") },
401 { A_SEPARATOR, 0, ("") },
402 { A_EXTEDITOR, STOCK_PIXMAP_EDIT_EXTERN, _("Editor") },
403 { A_LINEWRAP, STOCK_PIXMAP_LINEWRAP, _("Linewrap") },
404 { A_SEPARATOR, 0, ("") },
405 { A_ADDRBOOK, STOCK_PIXMAP_ADDRESS_BOOK, _("Address") }
410 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
412 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
414 if (default_toolbar[i].action != A_SEPARATOR) {
416 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
418 toolbar_item->file = g_strdup(file);
419 toolbar_item->index = default_toolbar[i].action;
420 toolbar_item->text = g_strdup(default_toolbar[i].text);
423 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
424 toolbar_item->index = A_SEPARATOR;
427 if (toolbar_item->index != -1) {
428 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_COMPOSE))
429 toolbar_config[TOOLBAR_COMPOSE].item_list =
430 g_slist_append(toolbar_config[TOOLBAR_COMPOSE].item_list, toolbar_item);
435 static void toolbar_set_default_msgview(void)
441 } default_toolbar[] = {
442 { A_REPLY_MESSAGE, STOCK_PIXMAP_MAIL_REPLY, _("Reply") },
443 { A_REPLY_ALL, STOCK_PIXMAP_MAIL_REPLY_TO_ALL, _("All") },
444 { A_REPLY_SENDER, STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR, _("Sender") },
445 { A_FORWARD, STOCK_PIXMAP_MAIL_FORWARD, _("Forward") },
446 { A_SEPARATOR, 0, ("") },
447 { A_DELETE, STOCK_PIXMAP_CLOSE, _("Delete") },
448 { A_GOTO_NEXT, STOCK_PIXMAP_DOWN_ARROW, _("Next") }
453 for (i = 0; i < sizeof(default_toolbar) / sizeof(default_toolbar[0]); i++) {
455 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
457 if (default_toolbar[i].action != A_SEPARATOR) {
459 gchar *file = stock_pixmap_get_name((StockPixmap)default_toolbar[i].icon);
461 toolbar_item->file = g_strdup(file);
462 toolbar_item->index = default_toolbar[i].action;
463 toolbar_item->text = g_strdup(default_toolbar[i].text);
466 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
467 toolbar_item->index = A_SEPARATOR;
470 if (toolbar_item->index != -1) {
471 if ( !toolbar_is_duplicate(toolbar_item->index, TOOLBAR_MSGVIEW))
472 toolbar_config[TOOLBAR_MSGVIEW].item_list =
473 g_slist_append(toolbar_config[TOOLBAR_MSGVIEW].item_list, toolbar_item);
478 void toolbar_set_default(ToolbarType source)
480 if (source == TOOLBAR_MAIN)
481 toolbar_set_default_main();
482 else if (source == TOOLBAR_COMPOSE)
483 toolbar_set_default_compose();
484 else if (source == TOOLBAR_MSGVIEW)
485 toolbar_set_default_msgview();
488 void toolbar_save_config_file(ToolbarType source)
493 gchar *fileSpec = NULL;
495 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
497 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
498 pfile = prefs_write_open(fileSpec);
502 fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n",
503 conv_get_current_charset_str());
505 fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX);
507 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
508 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
510 if (toolbar_item->index != A_SEPARATOR)
511 fprintf(fp, "\t<%s %s=\"%s\" %s=\"%s\" %s=\"%s\"/>\n",
513 TOOLBAR_ICON_FILE, toolbar_item->file,
514 TOOLBAR_ICON_TEXT, toolbar_item->text,
516 toolbar_ret_text_from_val(toolbar_item->index));
518 fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR);
521 fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX);
523 if (prefs_file_close (pfile) < 0 )
524 g_warning("failed to write toolbar configuration to file\n");
526 g_warning("failed to open toolbar configuration file for writing\n");
529 void toolbar_read_config_file(ToolbarType source)
531 XMLFile *file = NULL;
532 gchar *fileSpec = NULL;
537 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
539 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
540 file = xml_open_file(fileSpec);
543 toolbar_clear_list(source);
547 || (xml_get_dtd(file))
548 || (xml_parse_next_tag(file))
549 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
550 xml_close_file(file);
554 attr = xml_get_current_tag_attr(file);
561 if (xml_parse_next_tag(file))
564 /* Get next tag (icon, icon_text or icon_action) */
565 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
566 toolbar_parse_item(file, source);
567 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
568 ToolbarItem *item = g_new0(ToolbarItem, 1);
570 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
571 item->index = A_SEPARATOR;
572 toolbar_config[source].item_list =
573 g_slist_append(toolbar_config[source].item_list, item);
577 xml_close_file(file);
580 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
582 if (source == TOOLBAR_MAIN)
583 toolbar_set_default(TOOLBAR_MAIN);
584 else if (source == TOOLBAR_COMPOSE)
585 toolbar_set_default(TOOLBAR_COMPOSE);
586 else if (source == TOOLBAR_MSGVIEW)
587 toolbar_set_default(TOOLBAR_MSGVIEW);
589 g_warning("failed to write Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
593 toolbar_save_config_file(source);
598 * clears list of toolbar items read from configuration files
600 void toolbar_clear_list(ToolbarType source)
602 while (toolbar_config[source].item_list != NULL) {
603 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
605 toolbar_config[source].item_list =
606 g_slist_remove(toolbar_config[source].item_list, item);
614 g_slist_free(toolbar_config[source].item_list);
619 * return list of Toolbar items
621 GSList *toolbar_get_list(ToolbarType source)
625 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
626 list = toolbar_config[source].item_list;
631 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
633 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
635 toolbar_item->file = g_strdup(t_item->file);
636 toolbar_item->text = g_strdup(t_item->text);
637 toolbar_item->index = t_item->index;
639 toolbar_config[source].item_list =
640 g_slist_append(toolbar_config[source].item_list,
644 void toolbar_action_execute(GtkWidget *widget,
650 gchar *action, *action_p;
651 gboolean found = FALSE;
654 for (cur = action_list; cur != NULL; cur = cur->next) {
655 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
657 if (widget == act->widget) {
659 for (lop = prefs_common.actions_list; lop != NULL; lop = lop->next) {
660 action = g_strdup((gchar*)lop->data);
662 action_p = strstr(action, ": ");
664 if (g_strcasecmp(act->name, action) == 0) {
678 actions_execute(data, i, widget, source);
680 g_warning ("Error: did not find Sylpheed Action to execute");
683 static void activate_compose_button (Toolbar *toolbar,
685 ComposeButtonType type)
687 if ((!toolbar->compose_mail_btn) || (!toolbar->compose_news_btn))
690 gtk_widget_hide(type == COMPOSEBUTTON_NEWS ? toolbar->compose_mail_btn
691 : toolbar->compose_news_btn);
692 gtk_widget_show(type == COMPOSEBUTTON_NEWS ? toolbar->compose_news_btn
693 : toolbar->compose_mail_btn);
694 toolbar->compose_btn_type = type;
697 void toolbar_set_compose_button(Toolbar *toolbar,
698 ComposeButtonType compose_btn_type)
700 if (toolbar->compose_btn_type != compose_btn_type)
701 activate_compose_button(toolbar,
702 prefs_common.toolbar_style,
706 void toolbar_toggle(guint action, gpointer data)
708 MainWindow *mainwin = (MainWindow*)data;
712 g_return_if_fail(mainwin != NULL);
714 toolbar_style(TOOLBAR_MAIN, action, mainwin);
716 list = compose_get_compose_list();
717 for (cur = list; cur != NULL; cur = cur->next) {
718 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
720 list = messageview_get_msgview_list();
721 for (cur = list; cur != NULL; cur = cur->next) {
722 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
727 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
729 switch ((ToolbarStyle)action) {
731 gtk_widget_hide(handlebox_wid);
734 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
738 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
742 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
749 prefs_common.toolbar_style = (ToolbarStyle)action;
750 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
751 gtk_widget_show(handlebox_wid);
752 gtk_widget_queue_resize(handlebox_wid);
756 * Change the style of toolbar
758 static void toolbar_style(ToolbarType type, guint action, gpointer data)
760 GtkWidget *handlebox_wid;
761 GtkWidget *toolbar_wid;
762 MainWindow *mainwin = (MainWindow*)data;
763 Compose *compose = (Compose*)data;
764 MessageView *msgview = (MessageView*)data;
766 g_return_if_fail(data != NULL);
770 handlebox_wid = mainwin->handlebox;
771 toolbar_wid = mainwin->toolbar->toolbar;
773 case TOOLBAR_COMPOSE:
774 handlebox_wid = compose->handlebox;
775 toolbar_wid = compose->toolbar->toolbar;
777 case TOOLBAR_MSGVIEW:
778 handlebox_wid = msgview->handlebox;
779 toolbar_wid = msgview->toolbar->toolbar;
785 toolbar_set_style(toolbar_wid, handlebox_wid, action);
788 /* Toolbar handling */
789 static void toolbar_inc_cb(GtkWidget *widget,
792 ToolbarItem *toolbar_item = (ToolbarItem*)data;
795 g_return_if_fail(toolbar_item != NULL);
797 switch (toolbar_item->type) {
799 mainwin = (MainWindow*)toolbar_item->parent;
800 inc_mail_cb(mainwin, 0, NULL);
807 static void toolbar_inc_all_cb(GtkWidget *widget,
810 ToolbarItem *toolbar_item = (ToolbarItem*)data;
813 g_return_if_fail(toolbar_item != NULL);
815 switch (toolbar_item->type) {
817 mainwin = (MainWindow*)toolbar_item->parent;
818 inc_all_account_mail_cb(mainwin, 0, NULL);
825 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
827 ToolbarItem *toolbar_item = (ToolbarItem*)data;
830 g_return_if_fail(toolbar_item != NULL);
832 switch (toolbar_item->type) {
834 mainwin = (MainWindow*)toolbar_item->parent;
835 send_queue_cb(mainwin, 0, NULL);
842 static void toolbar_exec_cb(GtkWidget *widget,
845 MainWindow *mainwin = get_mainwin(data);
847 g_return_if_fail(mainwin != NULL);
848 summary_execute(mainwin->summaryview);
853 /* popup callback functions */
854 static void toolbar_reply_popup_cb(GtkWidget *widget,
855 GdkEventButton *event,
858 Toolbar *toolbar_data = (Toolbar*)data;
862 if (event->button == 3) {
863 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
864 gtk_menu_popup(GTK_MENU(toolbar_data->reply_popup), NULL, NULL,
865 menu_button_position, widget,
866 event->button, event->time);
870 static void toolbar_reply_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
872 ToolbarItem *toolbar_item = (ToolbarItem*)data;
874 GtkWidget *reply_btn;
876 MessageView *msgview;
878 g_return_if_fail(toolbar_item != NULL);
880 switch(toolbar_item->type) {
882 mainwin = (MainWindow*)toolbar_item->parent;
883 reply_btn = mainwin->toolbar->reply_btn;
884 window = mainwin->window;
886 case TOOLBAR_MSGVIEW:
887 msgview = (MessageView*)toolbar_item->parent;
888 reply_btn = msgview->toolbar->reply_btn;
889 window = msgview->window;
895 gtk_button_set_relief(GTK_BUTTON(reply_btn), GTK_RELIEF_NONE);
896 manage_window_focus_in(window, NULL, NULL);
899 static void toolbar_reply_to_all_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
901 Toolbar *toolbar_data = (Toolbar*)data;
905 if (event->button == 3) {
906 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
907 gtk_menu_popup(GTK_MENU(toolbar_data->replyall_popup), NULL, NULL,
908 menu_button_position, widget,
909 event->button, event->time);
913 static void toolbar_reply_to_all_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
915 ToolbarItem *toolbar_item = (ToolbarItem*)data;
917 GtkWidget *replyall_btn;
919 MessageView *msgview;
921 g_return_if_fail(toolbar_item != NULL);
923 switch(toolbar_item->type) {
925 mainwin = (MainWindow*)toolbar_item->parent;
926 replyall_btn = mainwin->toolbar->replyall_btn;
927 window = mainwin->window;
929 case TOOLBAR_MSGVIEW:
930 msgview = (MessageView*)toolbar_item->parent;
931 replyall_btn = msgview->toolbar->replyall_btn;
932 window = msgview->window;
938 gtk_button_set_relief(GTK_BUTTON(replyall_btn), GTK_RELIEF_NONE);
939 manage_window_focus_in(window, NULL, NULL);
942 static void toolbar_reply_to_list_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
944 Toolbar *toolbar_data = (Toolbar*)data;
946 if (event->button == 3) {
947 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
948 gtk_menu_popup(GTK_MENU(toolbar_data->replylist_popup), NULL, NULL,
949 menu_button_position, widget,
950 event->button, event->time);
954 static void toolbar_reply_to_list_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
956 ToolbarItem *toolbar_item = (ToolbarItem*)data;
957 gpointer parent = toolbar_item->parent;
959 GtkWidget *replylist_btn;
962 g_return_if_fail(toolbar_item != NULL);
964 switch(toolbar_item->type) {
966 replylist_btn = ((MainWindow*)parent)->toolbar->replylist_btn;
967 window = ((MainWindow*)parent)->window;
969 case TOOLBAR_MSGVIEW:
970 replylist_btn = ((MessageView*)parent)->toolbar->replylist_btn;
971 window = ((MessageView*)parent)->window;
977 gtk_button_set_relief(GTK_BUTTON(replylist_btn), GTK_RELIEF_NONE);
978 manage_window_focus_in(window, NULL, NULL);
981 static void toolbar_reply_to_sender_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
983 Toolbar *toolbar_data = (Toolbar*)data;
985 if (event->button == 3) {
986 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
987 gtk_menu_popup(GTK_MENU(toolbar_data->replysender_popup), NULL, NULL,
988 menu_button_position, widget,
989 event->button, event->time);
993 static void toolbar_reply_to_sender_popup_closed_cb(GtkMenuShell *menu_shell, gpointer data)
995 ToolbarItem *toolbar_item = (ToolbarItem*)data;
996 gpointer parent = toolbar_item->parent;
998 GtkWidget *replysender_btn;
1000 g_return_if_fail(toolbar_item != NULL);
1002 switch(toolbar_item->type) {
1004 replysender_btn = ((MainWindow*)parent)->toolbar->replysender_btn;
1005 window = ((MainWindow*)parent)->window;
1007 case TOOLBAR_MSGVIEW:
1008 replysender_btn = ((MessageView*)parent)->toolbar->replysender_btn;
1009 window = ((MessageView*)parent)->window;
1015 gtk_button_set_relief(GTK_BUTTON(replysender_btn), GTK_RELIEF_NONE);
1016 manage_window_focus_in(window, NULL, NULL);
1019 static void toolbar_forward_popup_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
1021 Toolbar *toolbar_data = (Toolbar*)data;
1023 if (event->button == 3) {
1024 gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NORMAL);
1025 gtk_menu_popup(GTK_MENU(toolbar_data->fwd_popup), NULL, NULL,
1026 menu_button_position, widget,
1027 event->button, event->time);
1031 static void toolbar_forward_popup_closed_cb (GtkMenuShell *menu_shell,
1034 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1035 gpointer parent = toolbar_item->parent;
1039 g_return_if_fail(toolbar_item != NULL);
1041 switch(toolbar_item->type) {
1043 fwd_btn = ((MainWindow*)parent)->toolbar->fwd_btn;
1044 window = ((MainWindow*)parent)->window;
1046 case TOOLBAR_MSGVIEW:
1047 fwd_btn = ((MessageView*)parent)->toolbar->fwd_btn;
1048 window = ((MessageView*)parent)->window;
1054 gtk_button_set_relief(GTK_BUTTON(fwd_btn), GTK_RELIEF_NONE);
1055 manage_window_focus_in(window, NULL, NULL);
1059 * Delete current/selected(s) message(s)
1061 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1063 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1064 MainWindow *mainwin;
1065 MessageView *msgview;
1067 g_return_if_fail(toolbar_item != NULL);
1069 switch (toolbar_item->type) {
1070 case TOOLBAR_MSGVIEW:
1071 msgview = (MessageView*)toolbar_item->parent;
1072 /* make sure the selected msg in summaryview is
1073 the one we are asked to delete */
1074 delete_msgview_cb(msgview, 0, widget);
1077 mainwin = (MainWindow*)toolbar_item->parent;
1078 summary_delete(mainwin->summaryview);
1081 debug_print("toolbar event not supported\n");
1088 * Compose new message
1090 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1092 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1093 MainWindow *mainwin;
1094 MessageView *msgview;
1096 g_return_if_fail(toolbar_item != NULL);
1098 switch (toolbar_item->type) {
1100 mainwin = (MainWindow*)toolbar_item->parent;
1101 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1102 compose_news_cb(mainwin, 0, NULL);
1104 compose_mail_cb(mainwin, 0, NULL);
1106 case TOOLBAR_MSGVIEW:
1107 msgview = (MessageView*)toolbar_item->parent;
1108 compose_new_with_folderitem(NULL,
1109 msgview->msginfo->folder);
1112 debug_print("toolbar event not supported\n");
1116 static void toolbar_popup_cb(gpointer data, guint action, GtkWidget *widget)
1118 MainWindow *mainwin = get_mainwin(data);
1120 g_return_if_fail(mainwin != NULL);
1121 reply_cb(mainwin, action, widget);
1128 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1130 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1131 MainWindow *mainwin;
1132 MessageView *msgview;
1134 g_return_if_fail(toolbar_item != NULL);
1136 switch (toolbar_item->type) {
1138 mainwin = (MainWindow*)toolbar_item->parent;
1139 if (prefs_common.default_reply_list)
1141 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1142 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE,
1146 prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE
1147 : COMPOSE_REPLY_WITHOUT_QUOTE,
1150 case TOOLBAR_MSGVIEW:
1151 msgview = (MessageView*)toolbar_item->parent;
1152 compose_reply(msgview->msginfo,
1153 prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE
1154 : COMPOSE_REPLY_WITHOUT_QUOTE,
1155 FALSE, FALSE, FALSE, NULL);
1158 debug_print("toolbar event not supported\n");
1164 * Reply message to Sender and All recipients
1166 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1168 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1169 MainWindow *mainwin;
1170 MessageView *msgview;
1172 g_return_if_fail(toolbar_item != NULL);
1174 switch (toolbar_item->type) {
1176 mainwin = (MainWindow*)toolbar_item->parent;
1178 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1179 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE,
1182 case TOOLBAR_MSGVIEW:
1183 msgview = (MessageView*)toolbar_item->parent;
1184 compose_reply(msgview->msginfo,
1185 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1186 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE,
1187 TRUE, FALSE, FALSE, NULL);
1190 debug_print("toolbar event not supported\n");
1196 * Reply to Mailing List
1198 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1200 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1201 MainWindow *mainwin;
1202 MessageView *msgview;
1204 g_return_if_fail(toolbar_item != NULL);
1206 switch (toolbar_item->type) {
1208 mainwin = (MainWindow*)toolbar_item->parent;
1210 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1211 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE,
1214 case TOOLBAR_MSGVIEW:
1215 msgview = (MessageView*)toolbar_item->parent;
1216 compose_reply(msgview->msginfo,
1217 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1218 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE,
1219 FALSE, TRUE, FALSE, NULL);
1222 debug_print("toolbar event not supported\n");
1228 * Reply to sender of message
1230 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1232 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1233 MainWindow *mainwin;
1234 MessageView *msgview;
1236 g_return_if_fail(toolbar_item != NULL);
1238 switch (toolbar_item->type) {
1240 mainwin = (MainWindow*)toolbar_item->parent;
1242 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1243 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE,
1246 case TOOLBAR_MSGVIEW:
1247 msgview = (MessageView*)toolbar_item->parent;
1248 compose_reply(msgview->msginfo,
1249 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1250 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE,
1251 FALSE, FALSE, FALSE, NULL);
1254 debug_print("toolbar event not supported\n\n");
1261 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1263 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1266 g_return_if_fail(toolbar_item != NULL);
1268 switch (toolbar_item->type) {
1270 case TOOLBAR_MSGVIEW:
1273 case TOOLBAR_COMPOSE:
1274 compose = (Compose *)toolbar_item->parent;
1279 addressbook_open(compose);
1284 * Forward current/selected(s) message(s)
1286 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1288 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1289 MainWindow *mainwin;
1291 g_return_if_fail(toolbar_item != NULL);
1293 switch (toolbar_item->type) {
1295 mainwin = (MainWindow*)toolbar_item->parent;
1296 if (prefs_common.forward_as_attachment)
1297 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
1299 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1303 debug_print("toolbar event not supported\n");
1309 * Goto Next Unread Message
1311 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1313 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1314 MainWindow *mainwin;
1315 MessageView *msgview;
1317 g_return_if_fail(toolbar_item != NULL);
1319 switch (toolbar_item->type) {
1321 mainwin = (MainWindow*)toolbar_item->parent;
1322 summary_select_next_unread(mainwin->summaryview);
1325 case TOOLBAR_MSGVIEW:
1326 msgview = (MessageView*)toolbar_item->parent;
1328 * TODO: Check if summaryview stay in the same place when this message view was created
1329 * if summary have other message select the next will be based on message selected in summaryview
1331 summary_select_next_unread(msgview->mainwin->summaryview);
1333 /** Now we need to update the messageview window */
1334 if (msgview->mainwin->summaryview->selected) {
1335 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1337 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1338 msgview->mainwin->summaryview->selected);
1340 messageview_show(msgview, msginfo,
1341 msgview->all_headers);
1343 gtk_widget_destroy(msgview->window);
1347 debug_print("toolbar event not supported\n");
1351 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1353 compose_toolbar_cb(A_SEND, data);
1356 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1358 compose_toolbar_cb(A_SENDL, data);
1361 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1363 compose_toolbar_cb(A_DRAFT, data);
1366 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1368 compose_toolbar_cb(A_INSERT, data);
1371 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1373 compose_toolbar_cb(A_ATTACH, data);
1376 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1378 compose_toolbar_cb(A_SIG, data);
1381 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1383 compose_toolbar_cb(A_EXTEDITOR, data);
1386 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
1388 compose_toolbar_cb(A_LINEWRAP, data);
1392 * Execute actions from toolbar
1394 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1396 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1397 GSList *action_list;
1398 MainWindow *mainwin;
1400 MessageView *msgview;
1401 gpointer parent = toolbar_item->parent;
1403 g_return_if_fail(toolbar_item != NULL);
1405 switch (toolbar_item->type) {
1407 mainwin = (MainWindow*)parent;
1408 action_list = mainwin->toolbar->action_list;
1410 case TOOLBAR_COMPOSE:
1411 compose = (Compose*)parent;
1412 action_list = compose->toolbar->action_list;
1414 case TOOLBAR_MSGVIEW:
1415 msgview = (MessageView*)parent;
1416 action_list = msgview->toolbar->action_list;
1419 debug_print("toolbar event not supported\n");
1422 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1425 static MainWindow *get_mainwin(gpointer data)
1427 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1428 MainWindow *mainwin = NULL;
1429 MessageView *msgview;
1431 g_return_val_if_fail(toolbar_item != NULL, NULL);
1433 switch(toolbar_item->type) {
1435 mainwin = (MainWindow*)toolbar_item->parent;
1437 case TOOLBAR_MSGVIEW:
1438 msgview = (MessageView*)toolbar_item->parent;
1439 mainwin = (MainWindow*)msgview->mainwin;
1448 static GtkWidget *get_window_widget(ToolbarType type, gpointer data)
1450 MainWindow *mainwin;
1451 MessageView *msgview;
1455 mainwin = (MainWindow*)data;
1456 return mainwin->window;
1458 case TOOLBAR_MSGVIEW:
1459 msgview = (MessageView*)data;
1460 return msgview->vbox;
1468 static void toolbar_buttons_cb(GtkWidget *widget,
1475 void (*func)(GtkWidget *widget, gpointer data);
1477 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1478 { A_RECEIVE_CUR, toolbar_inc_cb },
1479 { A_SEND_QUEUED, toolbar_send_queued_cb },
1480 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1481 { A_COMPOSE_NEWS, toolbar_compose_cb },
1482 { A_REPLY_MESSAGE, toolbar_reply_cb },
1483 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1484 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1485 { A_REPLY_ML, toolbar_reply_to_list_cb },
1486 { A_FORWARD, toolbar_forward_cb },
1487 { A_DELETE, toolbar_delete_cb },
1488 { A_EXECUTE, toolbar_exec_cb },
1489 { A_GOTO_NEXT, toolbar_next_unread_cb },
1491 { A_SEND, toolbar_send_cb },
1492 { A_SENDL, toolbar_send_later_cb },
1493 { A_DRAFT, toolbar_draft_cb },
1494 { A_INSERT, toolbar_insert_cb },
1495 { A_ATTACH, toolbar_attach_cb },
1496 { A_SIG, toolbar_sig_cb },
1497 { A_EXTEDITOR, toolbar_ext_editor_cb },
1498 { A_LINEWRAP, toolbar_linewrap_cb },
1499 { A_ADDRBOOK, toolbar_addrbook_cb },
1501 { A_SYL_ACTIONS, toolbar_actions_execute_cb }
1504 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1506 for (i = 0; i < num_items; i++) {
1507 if (callbacks[i].index == item->index) {
1508 callbacks[i].func(widget, item);
1515 * Create a new toolbar with specified type
1516 * if a callback list is passed it will be used before the
1517 * common callback list
1519 Toolbar *toolbar_create(ToolbarType type,
1520 GtkWidget *container,
1523 ToolbarItem *toolbar_item;
1526 GtkWidget *icon_wid = NULL;
1527 GtkWidget *icon_news;
1529 GtkWidget *item_news;
1530 GtkWidget *window_wid;
1532 guint n_menu_entries;
1533 GtkWidget *reply_popup;
1534 GtkWidget *replyall_popup;
1535 GtkWidget *replylist_popup;
1536 GtkWidget *replysender_popup;
1537 GtkWidget *fwd_popup;
1539 GtkTooltips *toolbar_tips;
1540 ToolbarSylpheedActions *action_item;
1542 GSList *toolbar_list;
1543 Toolbar *toolbar_data;
1546 toolbar_tips = gtk_tooltips_new();
1548 toolbar_read_config_file(type);
1549 toolbar_list = toolbar_get_list(type);
1551 toolbar_data = g_new0(Toolbar, 1);
1553 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1555 gtk_container_add(GTK_CONTAINER(container), toolbar);
1556 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1557 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1558 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1559 GTK_TOOLBAR_SPACE_LINE);
1561 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1563 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1564 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1568 toolbar_item = g_new0(ToolbarItem, 1);
1569 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1570 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1571 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1572 toolbar_item->parent = data;
1573 toolbar_item->type = type;
1575 /* collect toolbar items in list to keep track */
1576 toolbar_data->item_list =
1577 g_slist_append(toolbar_data->item_list,
1580 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1581 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1585 icon_wid, toolbar_buttons_cb,
1588 switch (toolbar_item->index) {
1591 toolbar_data->getall_btn = item;
1592 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1593 toolbar_data->getall_btn,
1594 _("Receive Mail on all Accounts"), NULL);
1597 toolbar_data->get_btn = item;
1598 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1599 toolbar_data->get_btn,
1600 _("Receive Mail on current Account"), NULL);
1603 toolbar_data->send_btn = item;
1604 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1605 toolbar_data->send_btn,
1606 _("Send Queued Message(s)"), NULL);
1608 case A_COMPOSE_EMAIL:
1609 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1610 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1614 icon_news, toolbar_buttons_cb,
1616 toolbar_data->compose_mail_btn = item;
1617 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1618 toolbar_data->compose_mail_btn,
1619 _("Compose Email"), NULL);
1620 toolbar_data->compose_news_btn = item_news;
1621 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1622 toolbar_data->compose_news_btn,
1623 _("Compose News"), NULL);
1625 case A_REPLY_MESSAGE:
1626 toolbar_data->reply_btn = item;
1627 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1628 toolbar_data->reply_btn,
1629 _("Reply to Message"), NULL);
1630 gtk_signal_connect(GTK_OBJECT(toolbar_data->reply_btn),
1631 "button_press_event",
1632 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
1634 n_menu_entries = sizeof(reply_popup_entries) /
1635 sizeof(reply_popup_entries[0]);
1637 window_wid = get_window_widget(type, data);
1638 reply_popup = popupmenu_create(window_wid,
1639 reply_popup_entries, n_menu_entries,
1640 "<ReplyPopup>", (gpointer)toolbar_item);
1642 gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
1643 GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), toolbar_item);
1644 toolbar_data->reply_popup = reply_popup;
1646 case A_REPLY_SENDER:
1647 toolbar_data->replysender_btn = item;
1648 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1649 toolbar_data->replysender_btn,
1650 _("Reply to Sender"), NULL);
1651 gtk_signal_connect(GTK_OBJECT(toolbar_data->replysender_btn),
1652 "button_press_event",
1653 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
1655 n_menu_entries = sizeof(replysender_popup_entries) /
1656 sizeof(replysender_popup_entries[0]);
1658 window_wid = get_window_widget(type, data);
1659 replysender_popup = popupmenu_create(window_wid,
1660 replysender_popup_entries, n_menu_entries,
1661 "<ReplySenderPopup>", (gpointer)toolbar_item);
1663 gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
1664 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), toolbar_item);
1665 toolbar_data->replysender_popup = replysender_popup;
1668 toolbar_data->replyall_btn = item;
1669 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1670 toolbar_data->replyall_btn,
1671 _("Reply to All"), NULL);
1672 gtk_signal_connect(GTK_OBJECT(toolbar_data->replyall_btn),
1673 "button_press_event",
1674 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
1676 n_menu_entries = sizeof(replyall_popup_entries) /
1677 sizeof(replyall_popup_entries[0]);
1679 window_wid = get_window_widget(type, data);
1680 replyall_popup = popupmenu_create(window_wid,
1681 replyall_popup_entries, n_menu_entries,
1682 "<ReplyAllPopup>", (gpointer)toolbar_item);
1684 gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
1685 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), toolbar_item);
1686 toolbar_data->replyall_popup = replyall_popup;
1689 toolbar_data->replylist_btn = item;
1690 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1691 toolbar_data->replylist_btn,
1692 _("Reply to Mailing-list"), NULL);
1693 gtk_signal_connect(GTK_OBJECT(toolbar_data->replylist_btn),
1694 "button_press_event",
1695 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_cb),
1697 n_menu_entries = sizeof(replylist_popup_entries) /
1698 sizeof(replylist_popup_entries[0]);
1700 window_wid = get_window_widget(type, data);
1701 replylist_popup = popupmenu_create(window_wid,
1702 replylist_popup_entries, n_menu_entries,
1703 "<ReplyMlPopup>", (gpointer)toolbar_item);
1705 gtk_signal_connect(GTK_OBJECT(replylist_popup), "selection_done",
1706 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_closed_cb), toolbar_item);
1707 toolbar_data->replylist_popup = replylist_popup;
1710 toolbar_data->fwd_btn = item;
1711 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1712 toolbar_data->fwd_btn,
1713 _("Forward Message"), NULL);
1714 gtk_signal_connect(GTK_OBJECT(toolbar_data->fwd_btn),
1715 "button_press_event",
1716 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
1718 n_menu_entries = sizeof(fwd_popup_entries) /
1719 sizeof(fwd_popup_entries[0]);
1721 window_wid = get_window_widget(type, data);
1722 fwd_popup = popupmenu_create(window_wid,
1723 fwd_popup_entries, n_menu_entries,
1724 "<ForwardPopup>", (gpointer)toolbar_item);
1726 gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
1727 GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), toolbar_item);
1728 toolbar_data->fwd_popup = fwd_popup;
1731 toolbar_data->delete_btn = item;
1732 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1733 toolbar_data->delete_btn,
1734 _("Delete Message"), NULL);
1737 toolbar_data->exec_btn = item;
1738 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1739 toolbar_data->exec_btn,
1740 _("Execute"), NULL);
1743 toolbar_data->next_btn = item;
1744 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1745 toolbar_data->next_btn,
1746 _("Goto Next Message"), NULL);
1749 /* Compose Toolbar */
1751 toolbar_data->send_btn = item;
1752 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1753 toolbar_data->send_btn,
1754 _("Send Message"), NULL);
1757 toolbar_data->sendl_btn = item;
1758 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1759 toolbar_data->sendl_btn,
1760 _("Put into queue folder and send later"), NULL);
1763 toolbar_data->draft_btn = item;
1764 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1765 toolbar_data->draft_btn,
1766 _("Save to draft folder"), NULL);
1769 toolbar_data->insert_btn = item;
1770 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1771 toolbar_data->insert_btn,
1772 _("Insert file"), NULL);
1775 toolbar_data->attach_btn = item;
1776 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1777 toolbar_data->attach_btn,
1778 _("Attach file"), NULL);
1781 toolbar_data->sig_btn = item;
1782 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1783 toolbar_data->sig_btn,
1784 _("Insert signature"), NULL);
1787 toolbar_data->exteditor_btn = item;
1788 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1789 toolbar_data->exteditor_btn,
1790 _("Edit with external editor"), NULL);
1793 toolbar_data->linewrap_btn = item;
1794 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1795 toolbar_data->linewrap_btn,
1796 _("Wrap all long lines"), NULL);
1799 toolbar_data->addrbook_btn = item;
1800 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1801 toolbar_data->addrbook_btn,
1802 _("Address book"), NULL);
1806 action_item = g_new0(ToolbarSylpheedActions, 1);
1807 action_item->widget = item;
1808 action_item->name = g_strdup(toolbar_item->text);
1810 toolbar_data->action_list =
1811 g_slist_append(toolbar_data->action_list,
1814 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1816 action_item->name, NULL);
1818 gtk_widget_show(item);
1825 toolbar_data->toolbar = toolbar;
1826 if (type == TOOLBAR_MAIN)
1827 activate_compose_button(toolbar_data,
1828 prefs_common.toolbar_style,
1829 toolbar_data->compose_btn_type);
1831 gtk_widget_show_all(toolbar);
1833 return toolbar_data;
1837 * Free toolbar structures
1839 void toolbar_destroy(Toolbar * toolbar) {
1841 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1842 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1845 void toolbar_update(ToolbarType type, gpointer data)
1847 Toolbar *toolbar_data;
1848 GtkWidget *handlebox;
1849 MainWindow *mainwin = (MainWindow*)data;
1850 Compose *compose = (Compose*)data;
1851 MessageView *msgview = (MessageView*)data;
1855 toolbar_data = mainwin->toolbar;
1856 handlebox = mainwin->handlebox;
1858 case TOOLBAR_COMPOSE:
1859 toolbar_data = compose->toolbar;
1860 handlebox = compose->handlebox;
1862 case TOOLBAR_MSGVIEW:
1863 toolbar_data = msgview->toolbar;
1864 handlebox = msgview->handlebox;
1870 gtk_container_remove(GTK_CONTAINER(handlebox),
1871 GTK_WIDGET(toolbar_data->toolbar));
1873 toolbar_init(toolbar_data);
1874 toolbar_data = toolbar_create(type, handlebox, data);
1877 mainwin->toolbar = toolbar_data;
1879 case TOOLBAR_COMPOSE:
1880 compose->toolbar = toolbar_data;
1882 case TOOLBAR_MSGVIEW:
1883 msgview->toolbar = toolbar_data;
1887 toolbar_style(type, prefs_common.toolbar_style, data);
1889 if (type == TOOLBAR_MAIN)
1890 toolbar_main_set_sensitive((MainWindow*)data);
1893 void toolbar_main_set_sensitive(gpointer data)
1895 SensitiveCond state;
1897 MainWindow *mainwin = (MainWindow*)data;
1898 Toolbar *toolbar = mainwin->toolbar;
1900 GSList *entry_list = NULL;
1902 typedef struct _Entry Entry;
1909 #define SET_WIDGET_COND(w, c) \
1911 Entry *e = g_new0(Entry, 1); \
1914 entry_list = g_slist_append(entry_list, e); \
1917 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1918 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1919 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1920 SET_WIDGET_COND(toolbar->reply_btn,
1921 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1922 SET_WIDGET_COND(toolbar->replyall_btn,
1923 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1924 SET_WIDGET_COND(toolbar->replylist_btn,
1925 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1926 SET_WIDGET_COND(toolbar->replysender_btn,
1927 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1928 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1930 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1931 SET_WIDGET_COND(toolbar->delete_btn,
1932 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1933 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1935 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
1936 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1938 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1941 #undef SET_WIDGET_COND
1943 state = main_window_get_current_state(mainwin);
1945 for (cur = entry_list; cur != NULL; cur = cur->next) {
1946 Entry *e = (Entry*) cur->data;
1948 if (e->widget != NULL) {
1949 sensitive = ((e->cond & state) == e->cond);
1950 gtk_widget_set_sensitive(e->widget, sensitive);
1954 while (entry_list != NULL) {
1955 Entry *e = (Entry*) entry_list->data;
1959 entry_list = g_slist_remove(entry_list, e);
1962 g_slist_free(entry_list);
1964 activate_compose_button(toolbar,
1965 prefs_common.toolbar_style,
1966 toolbar->compose_btn_type);
1969 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1971 Compose *compose = (Compose*)data;
1972 GSList *items = compose->toolbar->action_list;
1974 if (compose->toolbar->send_btn)
1975 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1976 if (compose->toolbar->sendl_btn)
1977 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1978 if (compose->toolbar->draft_btn )
1979 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1980 if (compose->toolbar->insert_btn )
1981 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1982 if (compose->toolbar->attach_btn)
1983 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1984 if (compose->toolbar->sig_btn)
1985 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1986 if (compose->toolbar->exteditor_btn)
1987 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1988 if (compose->toolbar->linewrap_btn)
1989 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
1990 if (compose->toolbar->addrbook_btn)
1991 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
1992 for (; items != NULL; items = g_slist_next(items)) {
1993 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
1994 gtk_widget_set_sensitive(item->widget, sensitive);
1999 * Initialize toolbar structure
2001 void toolbar_init(Toolbar * toolbar) {
2003 toolbar->toolbar = NULL;
2004 toolbar->get_btn = NULL;
2005 toolbar->getall_btn = NULL;
2006 toolbar->send_btn = NULL;
2007 toolbar->compose_mail_btn = NULL;
2008 toolbar->compose_news_btn = NULL;
2009 toolbar->reply_btn = NULL;
2010 toolbar->replysender_btn = NULL;
2011 toolbar->replyall_btn = NULL;
2012 toolbar->replylist_btn = NULL;
2013 toolbar->fwd_btn = NULL;
2014 toolbar->delete_btn = NULL;
2015 toolbar->next_btn = NULL;
2016 toolbar->exec_btn = NULL;
2018 /* compose buttons */
2019 toolbar->sendl_btn = NULL;
2020 toolbar->draft_btn = NULL;
2021 toolbar->insert_btn = NULL;
2022 toolbar->attach_btn = NULL;
2023 toolbar->sig_btn = NULL;
2024 toolbar->exteditor_btn = NULL;
2025 toolbar->linewrap_btn = NULL;
2026 toolbar->addrbook_btn = NULL;
2028 toolbar_destroy(toolbar);
2031 /* exported functions */
2033 void delete_msgview_cb(gpointer data, guint action, GtkWidget *widget)
2035 MessageView *msgview = (MessageView*)data;
2037 if (msgview->mainwin->summaryview->selected) {
2038 SummaryView *summaryview = msgview->mainwin->summaryview;
2039 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
2040 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
2041 summaryview->selected);
2042 if (msginfo->msgnum != msgview->msginfo->msgnum) {
2043 alertpanel_error(_("Message already removed from folder."));
2048 summary_delete(msgview->mainwin->summaryview);
2050 if (msgview->mainwin->summaryview->selected) {
2051 SummaryView *summaryview = msgview->mainwin->summaryview;
2052 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
2053 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
2054 summaryview->selected);
2055 messageview_show(msgview, msginfo,
2056 msgview->all_headers);
2058 toolbar_clear_list(TOOLBAR_MSGVIEW);
2059 toolbar_destroy(msgview->toolbar);
2060 gtk_widget_destroy(msgview->window);
2064 void reply_cb(gpointer data, guint action, GtkWidget *widget)
2066 MainWindow *mainwin = (MainWindow*)data;
2068 g_return_if_fail(mainwin != NULL);
2070 summary_reply(mainwin->summaryview, (ComposeMode)action);
2073 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2075 MainWindow *mainwin = (MainWindow*)data;
2077 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2080 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2082 MainWindow *mainwin = (MainWindow*)data;
2084 inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
2087 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2091 if (prefs_common.work_offline)
2092 if (alertpanel(_("Offline warning"),
2093 _("You're working offline. Override?"),
2094 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
2097 for (list = folder_get_list(); list != NULL; list = list->next) {
2098 Folder *folder = list->data;
2100 if (folder->queue) {
2101 if (procmsg_send_queue
2102 (folder->queue, prefs_common.savemsg) < 0)
2103 alertpanel_error(_("Some errors occurred while sending queued messages."));
2104 folder_item_scan(folder->queue);
2105 folder_update_item(folder->queue, TRUE);
2110 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2112 MainWindow *mainwin = (MainWindow*)data;
2113 PrefsAccount *ac = NULL;
2114 FolderItem *item = mainwin->summaryview->folder_item;
2119 ac = account_find_from_item(item);
2120 if (ac && ac->protocol != A_NNTP) {
2121 compose_new_with_folderitem(ac, item); /* CLAWS */
2127 * CLAWS - use current account
2129 if (cur_account && (cur_account->protocol != A_NNTP)) {
2130 compose_new_with_folderitem(cur_account, item);
2135 * CLAWS - just get the first one
2137 list = account_get_list();
2138 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2139 ac = (PrefsAccount *) cur->data;
2140 if (ac->protocol != A_NNTP) {
2141 compose_new_with_folderitem(ac, item);
2147 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2149 MainWindow *mainwin = (MainWindow*)data;
2150 PrefsAccount * ac = NULL;
2154 if (mainwin->summaryview->folder_item) {
2155 ac = mainwin->summaryview->folder_item->folder->account;
2156 if (ac && ac->protocol == A_NNTP) {
2158 mainwin->summaryview->folder_item->path,
2164 list = account_get_list();
2165 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2166 ac = (PrefsAccount *) cur->data;
2167 if (ac->protocol == A_NNTP) {
2168 compose_new(ac, NULL, NULL);