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_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", "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_ret_descr_from_val(A_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 = get_mainwin(data);
1133 g_return_if_fail(toolbar_item != NULL);
1135 switch (toolbar_item->type) {
1137 mainwin = (MainWindow*)toolbar_item->parent;
1138 if (prefs_common.default_reply_list)
1140 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1141 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE,
1145 prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE
1146 : COMPOSE_REPLY_WITHOUT_QUOTE,
1149 case TOOLBAR_MSGVIEW:
1150 if (prefs_common.default_reply_list)
1152 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1153 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE,
1157 prefs_common.reply_with_quote ? COMPOSE_REPLY_WITH_QUOTE
1158 : COMPOSE_REPLY_WITHOUT_QUOTE,
1162 debug_print("toolbar event not supported\n");
1168 * Reply message to Sender and All recipients
1170 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1172 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1173 MainWindow *mainwin;
1174 MessageView *msgview;
1176 g_return_if_fail(toolbar_item != NULL);
1178 switch (toolbar_item->type) {
1180 mainwin = (MainWindow*)toolbar_item->parent;
1182 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1183 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE,
1186 case TOOLBAR_MSGVIEW:
1187 msgview = (MessageView*)toolbar_item->parent;
1188 compose_reply(msgview->msginfo,
1189 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1190 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE,
1191 TRUE, FALSE, FALSE, NULL);
1194 debug_print("toolbar event not supported\n");
1200 * Reply to Mailing List
1202 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1204 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1205 MainWindow *mainwin;
1206 MessageView *msgview;
1208 g_return_if_fail(toolbar_item != NULL);
1210 switch (toolbar_item->type) {
1212 mainwin = (MainWindow*)toolbar_item->parent;
1214 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1215 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE,
1218 case TOOLBAR_MSGVIEW:
1219 msgview = (MessageView*)toolbar_item->parent;
1220 compose_reply(msgview->msginfo,
1221 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1222 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE,
1223 FALSE, TRUE, FALSE, NULL);
1226 debug_print("toolbar event not supported\n");
1232 * Reply to sender of message
1234 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1236 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1237 MainWindow *mainwin;
1238 MessageView *msgview;
1240 g_return_if_fail(toolbar_item != NULL);
1242 switch (toolbar_item->type) {
1244 mainwin = (MainWindow*)toolbar_item->parent;
1246 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1247 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE,
1250 case TOOLBAR_MSGVIEW:
1251 msgview = (MessageView*)toolbar_item->parent;
1252 compose_reply(msgview->msginfo,
1253 prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1254 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE,
1255 FALSE, FALSE, FALSE, NULL);
1258 debug_print("toolbar event not supported\n\n");
1265 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1267 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1270 g_return_if_fail(toolbar_item != NULL);
1272 switch (toolbar_item->type) {
1274 case TOOLBAR_MSGVIEW:
1277 case TOOLBAR_COMPOSE:
1278 compose = (Compose *)toolbar_item->parent;
1283 addressbook_open(compose);
1288 * Forward current/selected(s) message(s)
1290 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1292 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1293 MainWindow *mainwin = get_mainwin(data);
1295 g_return_if_fail(toolbar_item != NULL);
1297 switch (toolbar_item->type) {
1299 mainwin = (MainWindow*)toolbar_item->parent;
1300 if (prefs_common.forward_as_attachment)
1301 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
1303 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1306 case TOOLBAR_MSGVIEW:
1307 if (prefs_common.forward_as_attachment)
1308 reply_cb(mainwin, COMPOSE_FORWARD_AS_ATTACH, NULL);
1310 reply_cb(mainwin, COMPOSE_FORWARD, NULL);
1314 debug_print("toolbar event not supported\n");
1320 * Goto Next Unread Message
1322 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1324 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1325 MainWindow *mainwin;
1326 MessageView *msgview;
1328 g_return_if_fail(toolbar_item != NULL);
1330 switch (toolbar_item->type) {
1332 mainwin = (MainWindow*)toolbar_item->parent;
1333 summary_select_next_unread(mainwin->summaryview);
1336 case TOOLBAR_MSGVIEW:
1337 msgview = (MessageView*)toolbar_item->parent;
1339 * TODO: Check if summaryview stay in the same place when this message view was created
1340 * if summary have other message select the next will be based on message selected in summaryview
1342 summary_select_next_unread(msgview->mainwin->summaryview);
1344 /** Now we need to update the messageview window */
1345 if (msgview->mainwin->summaryview->selected) {
1346 GtkCTree *ctree = GTK_CTREE(msgview->mainwin->summaryview->ctree);
1348 MsgInfo * msginfo = gtk_ctree_node_get_row_data(ctree,
1349 msgview->mainwin->summaryview->selected);
1351 messageview_show(msgview, msginfo,
1352 msgview->all_headers);
1354 gtk_widget_destroy(msgview->window);
1358 debug_print("toolbar event not supported\n");
1362 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1364 compose_toolbar_cb(A_SEND, data);
1367 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1369 compose_toolbar_cb(A_SENDL, data);
1372 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1374 compose_toolbar_cb(A_DRAFT, data);
1377 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1379 compose_toolbar_cb(A_INSERT, data);
1382 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1384 compose_toolbar_cb(A_ATTACH, data);
1387 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1389 compose_toolbar_cb(A_SIG, data);
1392 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1394 compose_toolbar_cb(A_EXTEDITOR, data);
1397 static void toolbar_linewrap_cb(GtkWidget *widget, gpointer data)
1399 compose_toolbar_cb(A_LINEWRAP, data);
1403 * Execute actions from toolbar
1405 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1407 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1408 GSList *action_list;
1409 MainWindow *mainwin;
1411 MessageView *msgview;
1412 gpointer parent = toolbar_item->parent;
1414 g_return_if_fail(toolbar_item != NULL);
1416 switch (toolbar_item->type) {
1418 mainwin = (MainWindow*)parent;
1419 action_list = mainwin->toolbar->action_list;
1421 case TOOLBAR_COMPOSE:
1422 compose = (Compose*)parent;
1423 action_list = compose->toolbar->action_list;
1425 case TOOLBAR_MSGVIEW:
1426 msgview = (MessageView*)parent;
1427 action_list = msgview->toolbar->action_list;
1430 debug_print("toolbar event not supported\n");
1433 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
1436 static MainWindow *get_mainwin(gpointer data)
1438 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1439 MainWindow *mainwin = NULL;
1440 MessageView *msgview;
1442 g_return_val_if_fail(toolbar_item != NULL, NULL);
1444 switch(toolbar_item->type) {
1446 mainwin = (MainWindow*)toolbar_item->parent;
1448 case TOOLBAR_MSGVIEW:
1449 msgview = (MessageView*)toolbar_item->parent;
1450 mainwin = (MainWindow*)msgview->mainwin;
1459 static GtkWidget *get_window_widget(ToolbarType type, gpointer data)
1461 MainWindow *mainwin;
1462 MessageView *msgview;
1466 mainwin = (MainWindow*)data;
1467 return mainwin->window;
1469 case TOOLBAR_MSGVIEW:
1470 msgview = (MessageView*)data;
1471 return msgview->vbox;
1479 static void toolbar_buttons_cb(GtkWidget *widget,
1486 void (*func)(GtkWidget *widget, gpointer data);
1488 { A_RECEIVE_ALL, toolbar_inc_all_cb },
1489 { A_RECEIVE_CUR, toolbar_inc_cb },
1490 { A_SEND_QUEUED, toolbar_send_queued_cb },
1491 { A_COMPOSE_EMAIL, toolbar_compose_cb },
1492 { A_COMPOSE_NEWS, toolbar_compose_cb },
1493 { A_REPLY_MESSAGE, toolbar_reply_cb },
1494 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
1495 { A_REPLY_ALL, toolbar_reply_to_all_cb },
1496 { A_REPLY_ML, toolbar_reply_to_list_cb },
1497 { A_FORWARD, toolbar_forward_cb },
1498 { A_DELETE, toolbar_delete_cb },
1499 { A_EXECUTE, toolbar_exec_cb },
1500 { A_GOTO_NEXT, toolbar_next_unread_cb },
1502 { A_SEND, toolbar_send_cb },
1503 { A_SENDL, toolbar_send_later_cb },
1504 { A_DRAFT, toolbar_draft_cb },
1505 { A_INSERT, toolbar_insert_cb },
1506 { A_ATTACH, toolbar_attach_cb },
1507 { A_SIG, toolbar_sig_cb },
1508 { A_EXTEDITOR, toolbar_ext_editor_cb },
1509 { A_LINEWRAP, toolbar_linewrap_cb },
1510 { A_ADDRBOOK, toolbar_addrbook_cb },
1512 { A_SYL_ACTIONS, toolbar_actions_execute_cb }
1515 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
1517 for (i = 0; i < num_items; i++) {
1518 if (callbacks[i].index == item->index) {
1519 callbacks[i].func(widget, item);
1526 * Create a new toolbar with specified type
1527 * if a callback list is passed it will be used before the
1528 * common callback list
1530 Toolbar *toolbar_create(ToolbarType type,
1531 GtkWidget *container,
1534 ToolbarItem *toolbar_item;
1537 GtkWidget *icon_wid = NULL;
1538 GtkWidget *icon_news;
1540 GtkWidget *item_news;
1541 GtkWidget *window_wid;
1543 guint n_menu_entries;
1544 GtkWidget *reply_popup;
1545 GtkWidget *replyall_popup;
1546 GtkWidget *replylist_popup;
1547 GtkWidget *replysender_popup;
1548 GtkWidget *fwd_popup;
1550 GtkTooltips *toolbar_tips;
1551 ToolbarSylpheedActions *action_item;
1553 GSList *toolbar_list;
1554 Toolbar *toolbar_data;
1557 toolbar_tips = gtk_tooltips_new();
1559 toolbar_read_config_file(type);
1560 toolbar_list = toolbar_get_list(type);
1562 toolbar_data = g_new0(Toolbar, 1);
1564 toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL,
1566 gtk_container_add(GTK_CONTAINER(container), toolbar);
1567 gtk_container_set_border_width(GTK_CONTAINER(container), 2);
1568 gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolbar), GTK_RELIEF_NONE);
1569 gtk_toolbar_set_space_style(GTK_TOOLBAR(toolbar),
1570 GTK_TOOLBAR_SPACE_LINE);
1572 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
1574 if (g_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
1575 gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
1579 toolbar_item = g_new0(ToolbarItem, 1);
1580 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
1581 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
1582 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
1583 toolbar_item->parent = data;
1584 toolbar_item->type = type;
1586 /* collect toolbar items in list to keep track */
1587 toolbar_data->item_list =
1588 g_slist_append(toolbar_data->item_list,
1591 icon_wid = stock_pixmap_widget(container, stock_pixmap_get_icon(toolbar_item->file));
1592 item = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1596 icon_wid, toolbar_buttons_cb,
1599 switch (toolbar_item->index) {
1602 toolbar_data->getall_btn = item;
1603 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1604 toolbar_data->getall_btn,
1605 _("Receive Mail on all Accounts"), NULL);
1608 toolbar_data->get_btn = item;
1609 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1610 toolbar_data->get_btn,
1611 _("Receive Mail on current Account"), NULL);
1614 toolbar_data->send_btn = item;
1615 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1616 toolbar_data->send_btn,
1617 _("Send Queued Message(s)"), NULL);
1619 case A_COMPOSE_EMAIL:
1620 icon_news = stock_pixmap_widget(container, STOCK_PIXMAP_NEWS_COMPOSE);
1621 item_news = gtk_toolbar_append_item(GTK_TOOLBAR(toolbar),
1625 icon_news, toolbar_buttons_cb,
1627 toolbar_data->compose_mail_btn = item;
1628 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1629 toolbar_data->compose_mail_btn,
1630 _("Compose Email"), NULL);
1631 toolbar_data->compose_news_btn = item_news;
1632 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1633 toolbar_data->compose_news_btn,
1634 _("Compose News"), NULL);
1636 case A_REPLY_MESSAGE:
1637 toolbar_data->reply_btn = item;
1638 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1639 toolbar_data->reply_btn,
1640 _("Reply to Message"), NULL);
1641 gtk_signal_connect(GTK_OBJECT(toolbar_data->reply_btn),
1642 "button_press_event",
1643 GTK_SIGNAL_FUNC(toolbar_reply_popup_cb),
1645 n_menu_entries = sizeof(reply_popup_entries) /
1646 sizeof(reply_popup_entries[0]);
1648 window_wid = get_window_widget(type, data);
1649 reply_popup = popupmenu_create(window_wid,
1650 reply_popup_entries, n_menu_entries,
1651 "<ReplyPopup>", (gpointer)toolbar_item);
1653 gtk_signal_connect(GTK_OBJECT(reply_popup), "selection_done",
1654 GTK_SIGNAL_FUNC(toolbar_reply_popup_closed_cb), toolbar_item);
1655 toolbar_data->reply_popup = reply_popup;
1657 case A_REPLY_SENDER:
1658 toolbar_data->replysender_btn = item;
1659 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1660 toolbar_data->replysender_btn,
1661 _("Reply to Sender"), NULL);
1662 gtk_signal_connect(GTK_OBJECT(toolbar_data->replysender_btn),
1663 "button_press_event",
1664 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_cb),
1666 n_menu_entries = sizeof(replysender_popup_entries) /
1667 sizeof(replysender_popup_entries[0]);
1669 window_wid = get_window_widget(type, data);
1670 replysender_popup = popupmenu_create(window_wid,
1671 replysender_popup_entries, n_menu_entries,
1672 "<ReplySenderPopup>", (gpointer)toolbar_item);
1674 gtk_signal_connect(GTK_OBJECT(replysender_popup), "selection_done",
1675 GTK_SIGNAL_FUNC(toolbar_reply_to_sender_popup_closed_cb), toolbar_item);
1676 toolbar_data->replysender_popup = replysender_popup;
1679 toolbar_data->replyall_btn = item;
1680 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1681 toolbar_data->replyall_btn,
1682 _("Reply to All"), NULL);
1683 gtk_signal_connect(GTK_OBJECT(toolbar_data->replyall_btn),
1684 "button_press_event",
1685 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_cb),
1687 n_menu_entries = sizeof(replyall_popup_entries) /
1688 sizeof(replyall_popup_entries[0]);
1690 window_wid = get_window_widget(type, data);
1691 replyall_popup = popupmenu_create(window_wid,
1692 replyall_popup_entries, n_menu_entries,
1693 "<ReplyAllPopup>", (gpointer)toolbar_item);
1695 gtk_signal_connect(GTK_OBJECT(replyall_popup), "selection_done",
1696 GTK_SIGNAL_FUNC(toolbar_reply_to_all_popup_closed_cb), toolbar_item);
1697 toolbar_data->replyall_popup = replyall_popup;
1700 toolbar_data->replylist_btn = item;
1701 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1702 toolbar_data->replylist_btn,
1703 _("Reply to Mailing-list"), NULL);
1704 gtk_signal_connect(GTK_OBJECT(toolbar_data->replylist_btn),
1705 "button_press_event",
1706 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_cb),
1708 n_menu_entries = sizeof(replylist_popup_entries) /
1709 sizeof(replylist_popup_entries[0]);
1711 window_wid = get_window_widget(type, data);
1712 replylist_popup = popupmenu_create(window_wid,
1713 replylist_popup_entries, n_menu_entries,
1714 "<ReplyMlPopup>", (gpointer)toolbar_item);
1716 gtk_signal_connect(GTK_OBJECT(replylist_popup), "selection_done",
1717 GTK_SIGNAL_FUNC(toolbar_reply_to_list_popup_closed_cb), toolbar_item);
1718 toolbar_data->replylist_popup = replylist_popup;
1721 toolbar_data->fwd_btn = item;
1722 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1723 toolbar_data->fwd_btn,
1724 _("Forward Message"), NULL);
1725 gtk_signal_connect(GTK_OBJECT(toolbar_data->fwd_btn),
1726 "button_press_event",
1727 GTK_SIGNAL_FUNC(toolbar_forward_popup_cb),
1729 n_menu_entries = sizeof(fwd_popup_entries) /
1730 sizeof(fwd_popup_entries[0]);
1732 window_wid = get_window_widget(type, data);
1733 fwd_popup = popupmenu_create(window_wid,
1734 fwd_popup_entries, n_menu_entries,
1735 "<ForwardPopup>", (gpointer)toolbar_item);
1737 gtk_signal_connect(GTK_OBJECT(fwd_popup), "selection_done",
1738 GTK_SIGNAL_FUNC(toolbar_forward_popup_closed_cb), toolbar_item);
1739 toolbar_data->fwd_popup = fwd_popup;
1742 toolbar_data->delete_btn = item;
1743 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1744 toolbar_data->delete_btn,
1745 _("Delete Message"), NULL);
1748 toolbar_data->exec_btn = item;
1749 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1750 toolbar_data->exec_btn,
1751 _("Execute"), NULL);
1754 toolbar_data->next_btn = item;
1755 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1756 toolbar_data->next_btn,
1757 _("Goto Next Message"), NULL);
1760 /* Compose Toolbar */
1762 toolbar_data->send_btn = item;
1763 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1764 toolbar_data->send_btn,
1765 _("Send Message"), NULL);
1768 toolbar_data->sendl_btn = item;
1769 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1770 toolbar_data->sendl_btn,
1771 _("Put into queue folder and send later"), NULL);
1774 toolbar_data->draft_btn = item;
1775 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1776 toolbar_data->draft_btn,
1777 _("Save to draft folder"), NULL);
1780 toolbar_data->insert_btn = item;
1781 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1782 toolbar_data->insert_btn,
1783 _("Insert file"), NULL);
1786 toolbar_data->attach_btn = item;
1787 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1788 toolbar_data->attach_btn,
1789 _("Attach file"), NULL);
1792 toolbar_data->sig_btn = item;
1793 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1794 toolbar_data->sig_btn,
1795 _("Insert signature"), NULL);
1798 toolbar_data->exteditor_btn = item;
1799 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1800 toolbar_data->exteditor_btn,
1801 _("Edit with external editor"), NULL);
1804 toolbar_data->linewrap_btn = item;
1805 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1806 toolbar_data->linewrap_btn,
1807 _("Wrap all long lines"), NULL);
1810 toolbar_data->addrbook_btn = item;
1811 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1812 toolbar_data->addrbook_btn,
1813 _("Address book"), NULL);
1817 action_item = g_new0(ToolbarSylpheedActions, 1);
1818 action_item->widget = item;
1819 action_item->name = g_strdup(toolbar_item->text);
1821 toolbar_data->action_list =
1822 g_slist_append(toolbar_data->action_list,
1825 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tips),
1827 action_item->name, NULL);
1829 gtk_widget_show(item);
1836 toolbar_data->toolbar = toolbar;
1837 if (type == TOOLBAR_MAIN)
1838 activate_compose_button(toolbar_data,
1839 prefs_common.toolbar_style,
1840 toolbar_data->compose_btn_type);
1842 gtk_widget_show_all(toolbar);
1844 return toolbar_data;
1848 * Free toolbar structures
1850 void toolbar_destroy(Toolbar * toolbar) {
1852 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
1853 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
1856 void toolbar_update(ToolbarType type, gpointer data)
1858 Toolbar *toolbar_data;
1859 GtkWidget *handlebox;
1860 MainWindow *mainwin = (MainWindow*)data;
1861 Compose *compose = (Compose*)data;
1862 MessageView *msgview = (MessageView*)data;
1866 toolbar_data = mainwin->toolbar;
1867 handlebox = mainwin->handlebox;
1869 case TOOLBAR_COMPOSE:
1870 toolbar_data = compose->toolbar;
1871 handlebox = compose->handlebox;
1873 case TOOLBAR_MSGVIEW:
1874 toolbar_data = msgview->toolbar;
1875 handlebox = msgview->handlebox;
1881 gtk_container_remove(GTK_CONTAINER(handlebox),
1882 GTK_WIDGET(toolbar_data->toolbar));
1884 toolbar_init(toolbar_data);
1885 toolbar_data = toolbar_create(type, handlebox, data);
1888 mainwin->toolbar = toolbar_data;
1890 case TOOLBAR_COMPOSE:
1891 compose->toolbar = toolbar_data;
1893 case TOOLBAR_MSGVIEW:
1894 msgview->toolbar = toolbar_data;
1898 toolbar_style(type, prefs_common.toolbar_style, data);
1900 if (type == TOOLBAR_MAIN)
1901 toolbar_main_set_sensitive((MainWindow*)data);
1904 void toolbar_main_set_sensitive(gpointer data)
1906 SensitiveCond state;
1908 MainWindow *mainwin = (MainWindow*)data;
1909 Toolbar *toolbar = mainwin->toolbar;
1911 GSList *entry_list = NULL;
1913 typedef struct _Entry Entry;
1920 #define SET_WIDGET_COND(w, c) \
1922 Entry *e = g_new0(Entry, 1); \
1925 entry_list = g_slist_append(entry_list, e); \
1928 SET_WIDGET_COND(toolbar->get_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1929 SET_WIDGET_COND(toolbar->getall_btn, M_HAVE_ACCOUNT|M_UNLOCKED);
1930 SET_WIDGET_COND(toolbar->compose_news_btn, M_HAVE_ACCOUNT);
1931 SET_WIDGET_COND(toolbar->reply_btn,
1932 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1933 SET_WIDGET_COND(toolbar->replyall_btn,
1934 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1935 SET_WIDGET_COND(toolbar->replylist_btn,
1936 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1937 SET_WIDGET_COND(toolbar->replysender_btn,
1938 M_HAVE_ACCOUNT|M_SINGLE_TARGET_EXIST);
1939 SET_WIDGET_COND(toolbar->fwd_btn, M_HAVE_ACCOUNT|M_TARGET_EXIST);
1941 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST);
1942 SET_WIDGET_COND(toolbar->delete_btn,
1943 M_TARGET_EXIST|M_ALLOW_DELETE|M_UNLOCKED);
1944 SET_WIDGET_COND(toolbar->exec_btn, M_DELAY_EXEC);
1946 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
1947 ToolbarSylpheedActions *act = (ToolbarSylpheedActions*)cur->data;
1949 SET_WIDGET_COND(act->widget, M_TARGET_EXIST|M_UNLOCKED);
1952 #undef SET_WIDGET_COND
1954 state = main_window_get_current_state(mainwin);
1956 for (cur = entry_list; cur != NULL; cur = cur->next) {
1957 Entry *e = (Entry*) cur->data;
1959 if (e->widget != NULL) {
1960 sensitive = ((e->cond & state) == e->cond);
1961 gtk_widget_set_sensitive(e->widget, sensitive);
1965 while (entry_list != NULL) {
1966 Entry *e = (Entry*) entry_list->data;
1970 entry_list = g_slist_remove(entry_list, e);
1973 g_slist_free(entry_list);
1975 activate_compose_button(toolbar,
1976 prefs_common.toolbar_style,
1977 toolbar->compose_btn_type);
1980 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
1982 Compose *compose = (Compose*)data;
1983 GSList *items = compose->toolbar->action_list;
1985 if (compose->toolbar->send_btn)
1986 gtk_widget_set_sensitive(compose->toolbar->send_btn, sensitive);
1987 if (compose->toolbar->sendl_btn)
1988 gtk_widget_set_sensitive(compose->toolbar->sendl_btn, sensitive);
1989 if (compose->toolbar->draft_btn )
1990 gtk_widget_set_sensitive(compose->toolbar->draft_btn , sensitive);
1991 if (compose->toolbar->insert_btn )
1992 gtk_widget_set_sensitive(compose->toolbar->insert_btn , sensitive);
1993 if (compose->toolbar->attach_btn)
1994 gtk_widget_set_sensitive(compose->toolbar->attach_btn, sensitive);
1995 if (compose->toolbar->sig_btn)
1996 gtk_widget_set_sensitive(compose->toolbar->sig_btn, sensitive);
1997 if (compose->toolbar->exteditor_btn)
1998 gtk_widget_set_sensitive(compose->toolbar->exteditor_btn, sensitive);
1999 if (compose->toolbar->linewrap_btn)
2000 gtk_widget_set_sensitive(compose->toolbar->linewrap_btn, sensitive);
2001 if (compose->toolbar->addrbook_btn)
2002 gtk_widget_set_sensitive(compose->toolbar->addrbook_btn, sensitive);
2003 for (; items != NULL; items = g_slist_next(items)) {
2004 ToolbarSylpheedActions *item = (ToolbarSylpheedActions *)items->data;
2005 gtk_widget_set_sensitive(item->widget, sensitive);
2010 * Initialize toolbar structure
2012 void toolbar_init(Toolbar * toolbar) {
2014 toolbar->toolbar = NULL;
2015 toolbar->get_btn = NULL;
2016 toolbar->getall_btn = NULL;
2017 toolbar->send_btn = NULL;
2018 toolbar->compose_mail_btn = NULL;
2019 toolbar->compose_news_btn = NULL;
2020 toolbar->reply_btn = NULL;
2021 toolbar->replysender_btn = NULL;
2022 toolbar->replyall_btn = NULL;
2023 toolbar->replylist_btn = NULL;
2024 toolbar->fwd_btn = NULL;
2025 toolbar->delete_btn = NULL;
2026 toolbar->next_btn = NULL;
2027 toolbar->exec_btn = NULL;
2029 /* compose buttons */
2030 toolbar->sendl_btn = NULL;
2031 toolbar->draft_btn = NULL;
2032 toolbar->insert_btn = NULL;
2033 toolbar->attach_btn = NULL;
2034 toolbar->sig_btn = NULL;
2035 toolbar->exteditor_btn = NULL;
2036 toolbar->linewrap_btn = NULL;
2037 toolbar->addrbook_btn = NULL;
2039 toolbar_destroy(toolbar);
2042 /* exported functions */
2044 void delete_msgview_cb(gpointer data, guint action, GtkWidget *widget)
2046 MessageView *msgview = (MessageView*)data;
2048 if (msgview->mainwin->summaryview->selected) {
2049 SummaryView *summaryview = msgview->mainwin->summaryview;
2050 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
2051 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
2052 summaryview->selected);
2053 if (msginfo->msgnum != msgview->msginfo->msgnum) {
2054 alertpanel_error(_("Message already removed from folder."));
2059 summary_delete(msgview->mainwin->summaryview);
2061 if (msgview->mainwin->summaryview->selected) {
2062 SummaryView *summaryview = msgview->mainwin->summaryview;
2063 GtkCTree *ctree = GTK_CTREE(summaryview->ctree);
2064 MsgInfo *msginfo = gtk_ctree_node_get_row_data(ctree,
2065 summaryview->selected);
2066 messageview_show(msgview, msginfo,
2067 msgview->all_headers);
2069 toolbar_clear_list(TOOLBAR_MSGVIEW);
2070 toolbar_destroy(msgview->toolbar);
2071 gtk_widget_destroy(msgview->window);
2075 void reply_cb(gpointer data, guint action, GtkWidget *widget)
2077 MainWindow *mainwin = (MainWindow*)data;
2079 g_return_if_fail(mainwin != NULL);
2081 summary_reply(mainwin->summaryview, (ComposeMode)action);
2084 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
2086 MainWindow *mainwin = (MainWindow*)data;
2088 inc_mail(mainwin, prefs_common.newmail_notify_manu);
2091 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
2093 MainWindow *mainwin = (MainWindow*)data;
2095 inc_all_account_mail(mainwin, prefs_common.newmail_notify_manu);
2098 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
2102 if (prefs_common.work_offline)
2103 if (alertpanel(_("Offline warning"),
2104 _("You're working offline. Override?"),
2105 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
2108 for (list = folder_get_list(); list != NULL; list = list->next) {
2109 Folder *folder = list->data;
2111 if (folder->queue) {
2112 if (procmsg_send_queue
2113 (folder->queue, prefs_common.savemsg) < 0)
2114 alertpanel_error(_("Some errors occurred while sending queued messages."));
2115 folder_item_scan(folder->queue);
2120 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
2122 MainWindow *mainwin = (MainWindow*)data;
2123 PrefsAccount *ac = NULL;
2124 FolderItem *item = mainwin->summaryview->folder_item;
2129 ac = account_find_from_item(item);
2130 if (ac && ac->protocol != A_NNTP) {
2131 compose_new_with_folderitem(ac, item); /* CLAWS */
2137 * CLAWS - use current account
2139 if (cur_account && (cur_account->protocol != A_NNTP)) {
2140 compose_new_with_folderitem(cur_account, item);
2145 * CLAWS - just get the first one
2147 list = account_get_list();
2148 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2149 ac = (PrefsAccount *) cur->data;
2150 if (ac->protocol != A_NNTP) {
2151 compose_new_with_folderitem(ac, item);
2157 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
2159 MainWindow *mainwin = (MainWindow*)data;
2160 PrefsAccount * ac = NULL;
2164 if (mainwin->summaryview->folder_item) {
2165 ac = mainwin->summaryview->folder_item->folder->account;
2166 if (ac && ac->protocol == A_NNTP) {
2168 mainwin->summaryview->folder_item->path,
2174 list = account_get_list();
2175 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
2176 ac = (PrefsAccount *) cur->data;
2177 if (ac->protocol == A_NNTP) {
2178 compose_new(ac, NULL, NULL);