Use custom get_default_font_size() and _name()
[claws.git] / src / toolbar.c
blob51092b9f0e27c5a77fb611e17ba042b82e0664af
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2022 the Claws Mail team and 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 3 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, see <http://www.gnu.org/licenses/>.
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #include "claws-features.h"
22 #endif
24 #include "defs.h"
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <dirent.h>
31 #include <sys/stat.h>
32 #include <math.h>
33 #include <setjmp.h>
35 #include "main.h"
36 #include "mainwindow.h"
37 #include "summaryview.h"
38 #include "compose.h"
39 #include "utils.h"
40 #include "xml.h"
41 #include "mgutils.h"
42 #include "prefs_gtk.h"
43 #include "codeconv.h"
44 #include "stock_pixmap.h"
45 #include "manage_window.h"
46 #include "gtkutils.h"
47 #include "toolbar.h"
48 #include "menu.h"
49 #include "inc.h"
50 #include "action.h"
51 #include "prefs_actions.h"
52 #include "prefs_common.h"
53 #include "prefs_toolbar.h"
54 #include "alertpanel.h"
55 #include "imap.h"
56 #include "account.h"
57 #include "send_message.h"
58 #ifndef USE_ALT_ADDRBOOK
59 #include "addressbook.h"
60 #else
61 #include "addressbook-dbus.h"
62 #endif
64 /* elements */
65 #define TOOLBAR_TAG_INDEX "toolbar"
66 #define TOOLBAR_TAG_ITEM "item"
67 #define TOOLBAR_TAG_SEPARATOR "separator"
69 #define TOOLBAR_ICON_FILE "file"
70 #define TOOLBAR_ICON_TEXT "text"
71 #define TOOLBAR_ICON_ACTION "action"
73 static void toolbar_init(Toolbar * toolbar);
74 static gboolean toolbar_is_duplicate (gint action,
75 ToolbarType source);
76 static void toolbar_parse_item (XMLFile *file,
77 ToolbarType source, gboolean *rewrite);
79 static gint toolbar_ret_val_from_text (const gchar *text);
80 static gchar *toolbar_ret_text_from_val (gint val);
82 typedef struct _DefaultToolbar DefaultToolbar;
83 struct _DefaultToolbar {
84 gint action;
86 static void toolbar_set_default_generic(ToolbarType toolbar_type,
87 DefaultToolbar *default_toolbar);
89 static void toolbar_style (ToolbarType type,
90 guint action,
91 gpointer data);
93 static MainWindow *get_mainwin (gpointer data);
94 static void activate_compose_button (Toolbar *toolbar,
95 ToolbarStyle style,
96 ComposeButtonType type);
98 /* toolbar callbacks */
99 static void toolbar_reply (gpointer data,
100 guint action);
102 static void toolbar_learn (gpointer data,
103 guint action);
105 static void toolbar_delete_dup (gpointer data,
106 guint action);
108 static void toolbar_trash_cb (GtkWidget *widget,
109 gpointer data);
111 static void toolbar_delete_cb (GtkWidget *widget,
112 gpointer data);
114 static void toolbar_delete_dup_cb (GtkWidget *widget,
116 gpointer data);
118 static void toolbar_compose_cb (GtkWidget *widget,
119 gpointer data);
121 static void toolbar_learn_cb (GtkWidget *widget,
122 gpointer data);
124 static void toolbar_reply_cb (GtkWidget *widget,
125 gpointer data);
127 static void toolbar_reply_to_all_cb (GtkWidget *widget,
128 gpointer data);
130 static void toolbar_reply_to_list_cb (GtkWidget *widget,
131 gpointer data);
133 static void toolbar_reply_to_sender_cb (GtkWidget *widget,
134 gpointer data);
136 static void toolbar_forward_cb (GtkWidget *widget,
137 gpointer data);
139 static void toolbar_prev_unread_cb (GtkWidget *widget,
140 gpointer data);
141 static void toolbar_next_unread_cb (GtkWidget *widget,
142 gpointer data);
144 static void toolbar_ignore_thread_cb (GtkWidget *widget,
145 gpointer data);
147 static void toolbar_watch_thread_cb (GtkWidget *widget,
148 gpointer data);
150 static void toolbar_mark_cb (GtkWidget *widget,
151 gpointer data);
153 static void toolbar_unmark_cb (GtkWidget *widget,
154 gpointer data);
156 static void toolbar_lock_cb (GtkWidget *widget,
157 gpointer data);
159 static void toolbar_unlock_cb (GtkWidget *widget,
160 gpointer data);
162 static void toolbar_all_read_cb (GtkWidget *widget,
163 gpointer data);
165 static void toolbar_all_unread_cb (GtkWidget *widget,
166 gpointer data);
168 static void toolbar_read_cb (GtkWidget *widget,
169 gpointer data);
171 static void toolbar_unread_cb (GtkWidget *widget,
172 gpointer data);
174 static void toolbar_run_processing_cb (GtkWidget *widget,
175 gpointer data);
177 static void toolbar_print_cb (GtkWidget *widget,
178 gpointer data);
180 static void toolbar_actions_execute_cb (GtkWidget *widget,
181 gpointer data);
182 static void toolbar_plugins_execute_cb (GtkWidget *widget,
183 gpointer data);
186 static void toolbar_send_cb (GtkWidget *widget,
187 gpointer data);
188 static void toolbar_send_later_cb (GtkWidget *widget,
189 gpointer data);
190 static void toolbar_draft_cb (GtkWidget *widget,
191 gpointer data);
192 static void toolbar_close_cb (GtkWidget *widget,
193 gpointer data);
194 static void toolbar_preferences_cb (GtkWidget *widget,
195 gpointer data);
196 static void toolbar_open_mail_cb (GtkWidget *widget,
197 gpointer data);
198 static void toolbar_insert_cb (GtkWidget *widget,
199 gpointer data);
200 static void toolbar_attach_cb (GtkWidget *widget,
201 gpointer data);
202 static void toolbar_sig_cb (GtkWidget *widget,
203 gpointer data);
204 static void toolbar_ext_editor_cb (GtkWidget *widget,
205 gpointer data);
206 static void toolbar_linewrap_current_cb (GtkWidget *widget,
207 gpointer data);
208 static void toolbar_linewrap_all_cb (GtkWidget *widget,
209 gpointer data);
210 static void toolbar_addrbook_cb (GtkWidget *widget,
211 gpointer data);
212 #ifdef USE_ENCHANT
213 static void toolbar_check_spelling_cb (GtkWidget *widget,
214 gpointer data);
215 #endif
216 static void toolbar_cancel_inc_cb (GtkWidget *widget,
217 gpointer data);
218 static void toolbar_cancel_send_cb (GtkWidget *widget,
219 gpointer data);
220 static void toolbar_cancel_all_cb (GtkWidget *widget,
221 gpointer data);
223 struct {
224 gchar *index_str;
225 const gchar *descr;
226 } toolbar_text [] = {
227 { "A_RECEIVE_ALL", N_("Receive Mail from all Accounts") },
228 { "A_RECEIVE_CUR", N_("Receive Mail from current Account") },
229 { "A_SEND_QUEUED", N_("Send Queued Messages") },
230 { "A_COMPOSE_EMAIL", N_("Compose Email") },
231 { "A_COMPOSE_NEWS", N_("Compose News") },
232 { "A_REPLY_MESSAGE", N_("Reply to Message") },
233 { "A_REPLY_SENDER", N_("Reply to Sender") },
234 { "A_REPLY_ALL", N_("Reply to All") },
235 { "A_REPLY_ML", N_("Reply to Mailing-list") },
236 { "A_OPEN_MAIL", N_("Open email") },
237 { "A_FORWARD", N_("Forward Message") },
238 { "A_TRASH", N_("Trash Message") },
239 { "A_DELETE_REAL", N_("Delete Message") },
240 { "A_DELETE_DUP", N_("Delete duplicate messages") },
241 { "A_EXECUTE", N_("Execute") },
242 { "A_GOTO_PREV", N_("Go to Previous Unread Message") },
243 { "A_GOTO_NEXT", N_("Go to Next Unread Message") },
245 { "A_IGNORE_THREAD", N_("Ignore thread") },
246 { "A_WATCH_THREAD", N_("Watch thread") },
247 { "A_MARK", N_("Mark Message") },
248 { "A_UNMARK", N_("Unmark Message") },
249 { "A_LOCK", N_("Lock Message") },
250 { "A_UNLOCK", N_("Unlock Message") },
251 { "A_ALL_READ", N_("Mark all Messages as read") },
252 { "A_ALL_UNREAD", N_("Mark all Messages as unread") },
253 { "A_READ", N_("Mark Message as read") },
254 { "A_UNREAD", N_("Mark Message as unread") },
255 { "A_RUN_PROCESSING", N_("Run folder processing rules") },
257 { "A_PRINT", N_("Print") },
258 { "A_LEARN_SPAM", N_("Learn Spam or Ham") },
259 { "A_GO_FOLDERS", N_("Open folder/Go to folder list") },
260 { "A_PREFERENCES", N_("Preferences") },
262 { "A_SEND", N_("Send Message") },
263 { "A_SEND_LATER", N_("Put into queue folder and send later") },
264 { "A_DRAFT", N_("Save to draft folder") },
265 { "A_INSERT", N_("Insert file") },
266 { "A_ATTACH", N_("Attach file") },
267 { "A_SIG", N_("Insert signature") },
268 { "A_REP_SIG", N_("Replace signature") },
269 { "A_EXTEDITOR", N_("Edit with external editor") },
270 { "A_LINEWRAP_CURRENT", N_("Wrap long lines of current paragraph") },
271 { "A_LINEWRAP_ALL", N_("Wrap all long lines") },
272 { "A_ADDRBOOK", N_("Address book") },
273 #ifdef USE_ENCHANT
274 { "A_CHECK_SPELLING", N_("Check spelling") },
275 #endif
276 { "A_PRIVACY_SIGN", N_("Sign") },
277 { "A_PRIVACY_ENCRYPT", N_("Encrypt") },
278 { "A_CLAWS_ACTIONS", N_("Claws Mail Actions Feature") },
279 { "A_CANCEL_INC", N_("Cancel receiving") },
280 { "A_CANCEL_SEND", N_("Cancel sending") },
281 { "A_CANCEL_ALL", N_("Cancel receiving/sending") },
282 { "A_CLOSE", N_("Close window") },
283 { "A_SEPARATOR", N_("Separator") },
284 { "A_CLAWS_PLUGINS", N_("Claws Mail Plugins") }
287 /* migration table: support reading toolbar configuration files with
288 old action names and converting them to current action names,
289 see toolbar_parse_item(), which makes uses of this alias table.
291 struct {
292 const gchar *old_name;
293 const gchar *current_name;
294 } toolbar_migration [] = {
295 { "A_SYL_ACTIONS", "A_CLAWS_ACTIONS" },
296 { "A_SENDL", "A_SEND_LATER" },
297 { NULL, NULL }
300 /* struct holds configuration files and a list of
301 * currently active toolbar items
302 * TOOLBAR_MAIN, TOOLBAR_COMPOSE and TOOLBAR_MSGVIEW
303 * give us an index
305 struct {
306 const gchar *conf_file;
307 GSList *item_list;
308 } toolbar_config[NUM_TOOLBARS] = {
309 { "toolbar_main.xml", NULL},
310 { "toolbar_compose.xml", NULL},
311 { "toolbar_msgview.xml", NULL}
314 gint toolbar_ret_val_from_descr(const gchar *descr)
316 gint i;
318 for (i = 0; i < N_ACTION_VAL; i++) {
319 if (g_utf8_collate(gettext(toolbar_text[i].descr), descr) == 0)
320 return i;
323 return -1;
326 gchar *toolbar_ret_descr_from_val(gint val)
328 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
330 return gettext(toolbar_text[val].descr);
333 static gint toolbar_ret_val_from_text(const gchar *text)
335 gint i;
337 for (i = 0; i < N_ACTION_VAL; i++) {
338 if (g_utf8_collate(toolbar_text[i].index_str, text) == 0)
339 return i;
342 return -1;
345 static gchar *toolbar_ret_text_from_val(gint val)
347 cm_return_val_if_fail(val >=0 && val < N_ACTION_VAL, NULL);
349 return toolbar_text[val].index_str;
352 static gboolean toolbar_is_duplicate(gint action, ToolbarType source)
354 GSList *cur;
356 if ((action == A_SEPARATOR) || (action == A_CLAWS_ACTIONS) || (action == A_CLAWS_PLUGINS))
357 return FALSE;
359 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
360 ToolbarItem *item = (ToolbarItem*) cur->data;
362 if (item->index == action)
363 return TRUE;
365 return FALSE;
368 /* depending on toolbar type this function
369 returns a list of available toolbar events being
370 displayed by prefs_toolbar
372 GList *toolbar_get_action_items(ToolbarType source)
374 GList *items = NULL;
375 gint i = 0;
377 if (source == TOOLBAR_MAIN) {
378 gint main_items[] = {
379 A_RECEIVE_ALL, A_RECEIVE_CUR, A_SEND_QUEUED,
380 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
381 A_REPLY_ALL, A_REPLY_ML, A_OPEN_MAIL, A_FORWARD,
382 A_TRASH, A_DELETE_REAL, A_DELETE_DUP, A_EXECUTE,
383 A_GOTO_PREV, A_GOTO_NEXT, A_IGNORE_THREAD, A_WATCH_THREAD,
384 A_MARK, A_UNMARK, A_LOCK, A_UNLOCK,
385 A_ALL_READ, A_ALL_UNREAD, A_READ, A_UNREAD,
386 A_RUN_PROCESSING,
387 A_PRINT, A_ADDRBOOK, A_LEARN_SPAM, A_GO_FOLDERS,
388 A_CANCEL_INC, A_CANCEL_SEND, A_CANCEL_ALL, A_PREFERENCES };
390 for (i = 0; i < sizeof main_items / sizeof main_items[0]; i++) {
391 items = g_list_append(items, gettext(toolbar_text[main_items[i]].descr));
394 else if (source == TOOLBAR_COMPOSE) {
395 gint comp_items[] = {
396 A_SEND, A_SEND_LATER, A_DRAFT,
397 A_INSERT, A_ATTACH, A_SIG,
398 A_REP_SIG, A_EXTEDITOR, A_LINEWRAP_CURRENT,
399 A_LINEWRAP_ALL, A_ADDRBOOK,
400 #ifdef USE_ENCHANT
401 A_CHECK_SPELLING,
402 #endif
403 A_PRIVACY_SIGN, A_PRIVACY_ENCRYPT,
404 A_CLOSE };
406 for (i = 0; i < sizeof comp_items / sizeof comp_items[0]; i++)
407 items = g_list_append(items, gettext(toolbar_text[comp_items[i]].descr));
409 else if (source == TOOLBAR_MSGVIEW) {
410 gint msgv_items[] = {
411 A_COMPOSE_EMAIL, A_REPLY_MESSAGE, A_REPLY_SENDER,
412 A_REPLY_ALL, A_REPLY_ML, A_FORWARD,
413 A_TRASH, A_DELETE_REAL, A_GOTO_PREV, A_GOTO_NEXT,
414 A_ADDRBOOK, A_LEARN_SPAM, A_CLOSE };
416 for (i = 0; i < sizeof msgv_items / sizeof msgv_items[0]; i++)
417 items = g_list_append(items, gettext(toolbar_text[msgv_items[i]].descr));
420 return items;
423 static void toolbar_parse_item(XMLFile *file, ToolbarType source, gboolean *rewrite)
425 GList *attr;
426 gchar *name, *value;
427 ToolbarItem *item = NULL;
429 g_return_if_fail(rewrite != NULL);
431 attr = xml_get_current_tag_attr(file);
432 item = g_new0(ToolbarItem, 1);
433 while( attr ) {
434 name = ((XMLAttr *)attr->data)->name;
435 value = ((XMLAttr *)attr->data)->value;
437 if (g_utf8_collate(name, TOOLBAR_ICON_FILE) == 0)
438 item->file = g_strdup (value);
439 else if (g_utf8_collate(name, TOOLBAR_ICON_TEXT) == 0)
440 item->text = g_strdup (*value ? gettext(value):"");
441 else if (g_utf8_collate(name, TOOLBAR_ICON_ACTION) == 0)
442 item->index = toolbar_ret_val_from_text(value);
444 if ((item->index == -1) && !strcmp(value, "A_DELETE")) {
445 /* switch button */
446 item->index = A_TRASH;
447 g_free(item->file);
448 item->file = g_strdup("trash_btn");
449 g_free(item->text);
450 item->text = g_strdup(C_("Toolbar", "Trash"));
451 *rewrite = TRUE;
453 if (!strcmp(item->file, "mail") && !strcmp(value, "A_DRAFT")) {
454 /* switch icon file */
455 g_free(item->file);
456 item->file = g_strdup("mail_draft");
457 *rewrite = TRUE;
459 if (item->index == -1) {
460 /* item not found in table: try migrating old action names to current ones */
461 gint i;
463 /* replace action name */
464 for (i = 0; toolbar_migration[i].old_name != NULL; i++) {
465 if (g_utf8_collate(value, toolbar_migration[i].old_name) == 0) {
466 item->index = toolbar_ret_val_from_text(toolbar_migration[i].current_name);
467 if (item->index != -1) {
468 *rewrite = TRUE;
469 debug_print("toolbar_parse_item: migrating action label from '%s' to '%s'\n",
470 value, toolbar_migration[i].current_name);
471 break;
476 if ((item->index == -1) && !rewrite)
477 g_warning("toolbar_parse_item: unrecognized action name '%s'", value);
479 attr = g_list_next(attr);
481 if (item->index != -1) {
482 if (!toolbar_is_duplicate(item->index, source)) {
483 toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list,
484 item);
485 } else {
486 toolbar_item_destroy(item);
488 } else {
489 toolbar_item_destroy(item);
493 const gchar *toolbar_get_short_text(int action) {
494 switch(action) {
495 case A_RECEIVE_ALL: return _("Get Mail");
496 case A_RECEIVE_CUR: return _("Get");
497 case A_SEND_QUEUED: return _("Send");
498 case A_COMPOSE_EMAIL: return C_("Toolbar", "Compose");
499 case A_COMPOSE_NEWS: return C_("Toolbar", "Compose");
500 case A_REPLY_MESSAGE: return _("Reply");
501 case A_REPLY_SENDER: return C_("Toolbar", "Sender");
502 case A_REPLY_ALL: return _("All");
503 case A_REPLY_ML: return _("List");
504 case A_OPEN_MAIL: return _("Open");
505 case A_FORWARD: return _("Forward");
506 case A_TRASH: return C_("Toolbar", "Trash");
507 case A_DELETE_REAL: return _("Delete");
508 case A_DELETE_DUP: return _("Delete duplicates");
509 case A_EXECUTE: return _("Execute");
510 case A_GOTO_PREV: return _("Prev");
511 case A_GOTO_NEXT: return _("Next");
513 case A_IGNORE_THREAD: return _("Ignore thread");
514 case A_WATCH_THREAD: return _("Watch thread");
515 case A_MARK: return _("Mark");
516 case A_UNMARK: return _("Unmark");
517 case A_LOCK: return _("Lock");
518 case A_UNLOCK: return _("Unlock");
519 case A_ALL_READ: return _("All read");
520 case A_ALL_UNREAD: return _("All unread");
521 case A_READ: return _("Read");
522 case A_UNREAD: return _("Unread");
523 case A_RUN_PROCESSING: return _("Run proc. rules");
525 case A_PRINT: return _("Print");
526 case A_LEARN_SPAM: return _("Spam");
527 case A_GO_FOLDERS: return _("Folders");
528 case A_PREFERENCES: return _("Preferences");
530 case A_SEND: return _("Send");
531 case A_SEND_LATER: return _("Send later");
532 case A_DRAFT: return _("Draft");
533 case A_INSERT: return _("Insert");
534 case A_ATTACH: return _("Attach");
535 case A_SIG: return _("Insert sig.");
536 case A_REP_SIG: return _("Replace sig.");
537 case A_EXTEDITOR: return _("Edit");
538 case A_LINEWRAP_CURRENT:return _("Wrap para.");
539 case A_LINEWRAP_ALL: return _("Wrap all");
540 case A_ADDRBOOK: return _("Address");
541 #ifdef USE_ENCHANT
542 case A_CHECK_SPELLING: return _("Check spelling");
543 #endif
544 case A_PRIVACY_SIGN: return _("Sign");
545 case A_PRIVACY_ENCRYPT: return _("Encrypt");
547 case A_CANCEL_INC: return _("Stop");
548 case A_CANCEL_SEND: return _("Stop");
549 case A_CANCEL_ALL: return _("Stop all");
550 case A_CLOSE: return _("Close");
551 default: return "";
555 gint toolbar_get_icon(int action) {
556 switch(action) {
557 case A_RECEIVE_ALL: return STOCK_PIXMAP_MAIL_RECEIVE_ALL;
558 case A_RECEIVE_CUR: return STOCK_PIXMAP_MAIL_RECEIVE;
559 case A_SEND_QUEUED: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
560 case A_COMPOSE_EMAIL: return STOCK_PIXMAP_MAIL_COMPOSE;
561 case A_COMPOSE_NEWS: return STOCK_PIXMAP_NEWS_COMPOSE;
562 case A_REPLY_MESSAGE: return STOCK_PIXMAP_MAIL_REPLY;
563 case A_REPLY_SENDER: return STOCK_PIXMAP_MAIL_REPLY_TO_AUTHOR;
564 case A_REPLY_ALL: return STOCK_PIXMAP_MAIL_REPLY_TO_ALL;
565 case A_REPLY_ML: return STOCK_PIXMAP_MAIL_REPLY_TO_LIST;
566 case A_OPEN_MAIL: return STOCK_PIXMAP_OPEN_MAIL;
567 case A_FORWARD: return STOCK_PIXMAP_MAIL_FORWARD;
568 case A_TRASH: return STOCK_PIXMAP_TRASH;
569 case A_DELETE_REAL: return STOCK_PIXMAP_DELETE;
570 case A_DELETE_DUP: return STOCK_PIXMAP_DELETE_DUP;
571 case A_EXECUTE: return STOCK_PIXMAP_EXEC;
572 case A_GOTO_PREV: return STOCK_PIXMAP_UP_ARROW;
573 case A_GOTO_NEXT: return STOCK_PIXMAP_DOWN_ARROW;
575 case A_IGNORE_THREAD: return STOCK_PIXMAP_MARK_IGNORETHREAD;
576 case A_WATCH_THREAD: return STOCK_PIXMAP_MARK_WATCHTHREAD;
577 case A_MARK: return STOCK_PIXMAP_MARK_MARK;
578 case A_UNMARK: return STOCK_PIXMAP_MARK_UNMARK;
579 case A_LOCK: return STOCK_PIXMAP_MARK_LOCKED;
580 case A_UNLOCK: return STOCK_PIXMAP_MARK_UNLOCKED;
581 case A_ALL_READ: return STOCK_PIXMAP_MARK_ALLREAD;
582 case A_ALL_UNREAD: return STOCK_PIXMAP_MARK_ALLUNREAD;
583 case A_READ: return STOCK_PIXMAP_MARK_READ;
584 case A_UNREAD: return STOCK_PIXMAP_MARK_UNREAD;
585 case A_RUN_PROCESSING: return STOCK_PIXMAP_DIR_OPEN;
587 case A_PRINT: return STOCK_PIXMAP_PRINTER_BTN;
588 case A_LEARN_SPAM: return STOCK_PIXMAP_SPAM_BTN;
589 case A_GO_FOLDERS: return STOCK_PIXMAP_GO_FOLDERS;
590 case A_PREFERENCES: return STOCK_PIXMAP_PREFERENCES;
592 case A_SEND: return STOCK_PIXMAP_MAIL_SEND;
593 case A_SEND_LATER: return STOCK_PIXMAP_MAIL_SEND_QUEUE;
594 case A_DRAFT: return STOCK_PIXMAP_MAIL_DRAFT;
595 case A_INSERT: return STOCK_PIXMAP_INSERT_FILE;
596 case A_ATTACH: return STOCK_PIXMAP_MAIL_ATTACH;
597 case A_SIG: return STOCK_PIXMAP_MAIL_SIGN;
598 case A_REP_SIG: return STOCK_PIXMAP_MAIL_SIGN;
599 case A_EXTEDITOR: return STOCK_PIXMAP_EDIT_EXTERN;
600 case A_LINEWRAP_CURRENT:return STOCK_PIXMAP_LINEWRAP_CURRENT;
601 case A_LINEWRAP_ALL: return STOCK_PIXMAP_LINEWRAP_ALL;
602 case A_ADDRBOOK: return STOCK_PIXMAP_ADDRESS_BOOK;
603 #ifdef USE_ENCHANT
604 case A_CHECK_SPELLING: return STOCK_PIXMAP_CHECK_SPELLING;
605 #endif
606 case A_PRIVACY_SIGN: return STOCK_PIXMAP_MAIL_PRIVACY_SIGNED;
607 case A_PRIVACY_ENCRYPT: return STOCK_PIXMAP_MAIL_PRIVACY_ENCRYPTED;
609 case A_CANCEL_INC: return STOCK_PIXMAP_CANCEL;
610 case A_CANCEL_SEND: return STOCK_PIXMAP_CANCEL;
611 case A_CANCEL_ALL: return STOCK_PIXMAP_CANCEL;
612 case A_CLOSE: return STOCK_PIXMAP_CLOSE;
613 default: return -1;
617 static void toolbar_set_default_generic(ToolbarType toolbar_type, DefaultToolbar *default_toolbar)
619 gint i;
621 g_return_if_fail(default_toolbar != NULL);
623 for (i = 0; default_toolbar[i].action != N_ACTION_VAL; i++) {
625 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
627 if (default_toolbar[i].action != A_SEPARATOR) {
628 gchar *file = NULL;
629 gint icon;
631 icon = toolbar_get_icon(default_toolbar[i].action);
632 if (icon > -1) {
633 file = stock_pixmap_get_name((StockPixmap)icon);
635 toolbar_item->file = g_strdup(file);
636 toolbar_item->index = default_toolbar[i].action;
637 toolbar_item->text = g_strdup(toolbar_get_short_text(default_toolbar[i].action));
638 } else {
639 toolbar_item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
640 toolbar_item->index = A_SEPARATOR;
643 if (toolbar_item->index != -1) {
644 if (!toolbar_is_duplicate(toolbar_item->index, toolbar_type)) {
645 toolbar_config[toolbar_type].item_list =
646 g_slist_append(toolbar_config[toolbar_type].item_list, toolbar_item);
647 } else {
648 toolbar_item_destroy(toolbar_item);
650 } else {
651 toolbar_item_destroy(toolbar_item);
656 void toolbar_set_default(ToolbarType source)
658 DefaultToolbar default_toolbar_main[] = {
659 #ifdef GENERIC_UMPC
660 { A_GO_FOLDERS},
661 { A_OPEN_MAIL},
662 { A_SEPARATOR},
663 #endif
664 { A_RECEIVE_ALL},
665 { A_SEPARATOR},
666 { A_SEND_QUEUED},
667 { A_COMPOSE_EMAIL},
668 { A_SEPARATOR},
669 { A_REPLY_MESSAGE},
670 #ifndef GENERIC_UMPC
671 { A_REPLY_ALL},
672 { A_REPLY_SENDER},
673 #endif
674 { A_FORWARD},
675 { A_SEPARATOR},
676 { A_TRASH},
677 #ifndef GENERIC_UMPC
678 { A_LEARN_SPAM},
679 #endif
680 { A_SEPARATOR},
681 { A_GOTO_NEXT},
682 { N_ACTION_VAL}
684 DefaultToolbar default_toolbar_compose[] = {
685 #ifdef GENERIC_UMPC
686 { A_CLOSE},
687 { A_SEPARATOR},
688 #endif
689 { A_SEND},
690 { A_SEND_LATER},
691 { A_DRAFT},
692 { A_SEPARATOR},
693 #ifndef GENERIC_UMPC
694 { A_INSERT},
695 #endif
696 { A_ATTACH},
697 { A_SEPARATOR},
698 { A_ADDRBOOK},
699 { N_ACTION_VAL}
702 DefaultToolbar default_toolbar_msgview[] = {
703 #ifdef GENERIC_UMPC
704 { A_CLOSE},
705 { A_SEPARATOR},
706 #endif
707 { A_REPLY_MESSAGE},
708 { A_REPLY_ALL},
709 { A_REPLY_SENDER},
710 { A_FORWARD},
711 { A_SEPARATOR},
712 { A_TRASH},
713 #ifndef GENERIC_UMPC
714 { A_LEARN_SPAM},
715 #endif
716 { A_GOTO_NEXT},
717 { N_ACTION_VAL}
720 if (source == TOOLBAR_MAIN)
721 toolbar_set_default_generic(TOOLBAR_MAIN, default_toolbar_main);
722 else if (source == TOOLBAR_COMPOSE)
723 toolbar_set_default_generic(TOOLBAR_COMPOSE, default_toolbar_compose);
724 else if (source == TOOLBAR_MSGVIEW)
725 toolbar_set_default_generic(TOOLBAR_MSGVIEW, default_toolbar_msgview);
728 void toolbar_save_config_file(ToolbarType source)
730 GSList *cur;
731 FILE *fp;
732 PrefFile *pfile;
733 gchar *fileSpec = NULL;
735 debug_print("save Toolbar Configuration to %s\n", toolbar_config[source].conf_file);
737 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
738 pfile = prefs_write_open(fileSpec);
739 if( pfile ) {
740 fp = pfile->fp;
741 if (fprintf(fp, "<?xml version=\"1.0\" encoding=\"%s\" ?>\n", CS_INTERNAL) < 0)
742 goto fail;
744 if (fprintf(fp, "<%s>\n", TOOLBAR_TAG_INDEX) < 0)
745 goto fail;
747 for (cur = toolbar_config[source].item_list; cur != NULL; cur = cur->next) {
748 ToolbarItem *toolbar_item = (ToolbarItem*) cur->data;
750 if (toolbar_item->index != A_SEPARATOR) {
751 if (fprintf(fp, "\t<%s %s=\"%s\" %s=\"",
752 TOOLBAR_TAG_ITEM,
753 TOOLBAR_ICON_FILE, toolbar_item->file,
754 TOOLBAR_ICON_TEXT) < 0)
755 goto fail;
756 if (xml_file_put_escape_str(fp, toolbar_item->text) < 0)
757 goto fail;
758 if (fprintf(fp, "\" %s=\"%s\"/>\n",
759 TOOLBAR_ICON_ACTION,
760 toolbar_ret_text_from_val(toolbar_item->index)) < 0)
761 goto fail;
762 } else {
763 if (fprintf(fp, "\t<%s/>\n", TOOLBAR_TAG_SEPARATOR) < 0)
764 goto fail;
768 if (fprintf(fp, "</%s>\n", TOOLBAR_TAG_INDEX) < 0)
769 goto fail;
771 g_free( fileSpec );
772 if (prefs_file_close (pfile) < 0 )
773 g_warning("failed to write toolbar configuration to file");
774 return;
776 fail:
777 FILE_OP_ERROR(fileSpec, "fprintf");
778 g_free(fileSpec);
779 prefs_file_close_revert (pfile);
780 } else {
781 g_free(fileSpec);
782 g_warning("failed to open toolbar configuration file for writing");
786 void toolbar_read_config_file(ToolbarType source)
788 XMLFile *file = NULL;
789 gchar *fileSpec = NULL;
790 jmp_buf jumper;
791 gboolean rewrite = FALSE;
793 debug_print("read Toolbar Configuration from %s\n", toolbar_config[source].conf_file);
795 fileSpec = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, toolbar_config[source].conf_file, NULL );
796 file = xml_open_file(fileSpec);
797 g_free(fileSpec);
799 toolbar_clear_list(source);
801 if (file) {
802 if ((setjmp(jumper))
803 || (xml_get_dtd(file))
804 || (xml_parse_next_tag(file))
805 || (!xml_compare_tag(file, TOOLBAR_TAG_INDEX))) {
806 xml_close_file(file);
807 return;
810 for (;;) {
811 if (!file->level)
812 break;
813 /* Get item tag */
814 if (xml_parse_next_tag(file))
815 longjmp(jumper, 1);
817 /* Get next tag (icon, icon_text or icon_action) */
818 if (xml_compare_tag(file, TOOLBAR_TAG_ITEM)) {
819 toolbar_parse_item(file, source, &rewrite);
820 } else if (xml_compare_tag(file, TOOLBAR_TAG_SEPARATOR)) {
821 ToolbarItem *item = g_new0(ToolbarItem, 1);
823 item->file = g_strdup(TOOLBAR_TAG_SEPARATOR);
824 item->index = A_SEPARATOR;
825 toolbar_config[source].item_list =
826 g_slist_append(toolbar_config[source].item_list, item);
830 xml_close_file(file);
831 if (rewrite) {
832 debug_print("toolbar_read_config_file: rewriting toolbar\n");
833 toolbar_save_config_file(source);
837 if ((!file) || (g_slist_length(toolbar_config[source].item_list) == 0)) {
839 if (source == TOOLBAR_MAIN)
840 toolbar_set_default(TOOLBAR_MAIN);
841 else if (source == TOOLBAR_COMPOSE)
842 toolbar_set_default(TOOLBAR_COMPOSE);
843 else if (source == TOOLBAR_MSGVIEW)
844 toolbar_set_default(TOOLBAR_MSGVIEW);
845 else {
846 g_warning("refusing to write unknown Toolbar Configuration number %d", source);
847 return;
850 toolbar_save_config_file(source);
855 * clears list of toolbar items read from configuration files
857 void toolbar_clear_list(ToolbarType source)
859 while (toolbar_config[source].item_list != NULL) {
860 ToolbarItem *item = (ToolbarItem*) toolbar_config[source].item_list->data;
862 toolbar_config[source].item_list =
863 g_slist_remove(toolbar_config[source].item_list, item);
865 toolbar_item_destroy(item);
867 g_slist_free(toolbar_config[source].item_list);
872 * return list of Toolbar items
874 GSList *toolbar_get_list(ToolbarType source)
876 GSList *list = NULL;
878 if ((source == TOOLBAR_MAIN) || (source == TOOLBAR_COMPOSE) || (source == TOOLBAR_MSGVIEW))
879 list = toolbar_config[source].item_list;
881 return list;
884 void toolbar_set_list_item(ToolbarItem *t_item, ToolbarType source)
886 ToolbarItem *toolbar_item = g_new0(ToolbarItem, 1);
888 toolbar_item->file = g_strdup(t_item->file);
889 toolbar_item->text = g_strdup(t_item->text);
890 toolbar_item->index = t_item->index;
892 toolbar_config[source].item_list =
893 g_slist_append(toolbar_config[source].item_list,
894 toolbar_item);
897 static void toolbar_action_execute(GtkWidget *widget,
898 GSList *action_list,
899 gpointer data,
900 gint source)
902 GSList *cur;
903 gint i = 0;
905 for (cur = action_list; cur != NULL; cur = cur->next) {
906 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
908 if (widget == act->widget) {
909 i = prefs_actions_find_by_name(act->name);
911 if (i != -1)
912 break;
916 if (i != -1)
917 actions_execute(data, i, widget, source);
918 else
919 g_warning("error: did not find Action to execute");
922 gboolean toolbar_check_action_btns(ToolbarType type)
924 GSList *temp, *curr, *list = toolbar_config[type].item_list;
925 gboolean modified = FALSE;
927 curr = list;
928 while (curr != NULL) {
929 ToolbarItem *toolbar_item = (ToolbarItem *) curr->data;
930 temp = curr;
931 curr = curr->next;
933 if (toolbar_item->index != A_CLAWS_ACTIONS)
934 continue;
936 if (prefs_actions_find_by_name(toolbar_item->text) == -1) {
937 list = g_slist_delete_link(list, temp);
938 g_free(toolbar_item->file);
939 g_free(toolbar_item->text);
940 g_free(toolbar_item);
941 modified = TRUE;
945 return modified;
948 #define CLAWS_SET_TOOL_ITEM_TIP(widget,tip) { \
949 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), tip); \
952 #define CLAWS_SET_ARROW_TIP(widget,tip) { \
953 gtk_menu_tool_button_set_arrow_tooltip_text(GTK_MENU_TOOL_BUTTON(widget), tip); \
956 static void activate_compose_button (Toolbar *toolbar,
957 ToolbarStyle style,
958 ComposeButtonType type)
960 if ((!toolbar->compose_mail_btn))
961 return;
963 if (type == COMPOSEBUTTON_NEWS) {
964 gtk_tool_button_set_icon_widget(
965 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
966 toolbar->compose_news_icon);
967 #ifndef GENERIC_UMPC
968 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose News message"));
969 #endif
970 gtk_widget_show(toolbar->compose_news_icon);
971 } else {
972 gtk_tool_button_set_icon_widget(
973 GTK_TOOL_BUTTON(toolbar->compose_mail_btn),
974 toolbar->compose_mail_icon);
975 #ifndef GENERIC_UMPC
976 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->compose_mail_btn), _("Compose Email"));
977 #endif
978 gtk_widget_show(toolbar->compose_mail_icon);
980 toolbar->compose_btn_type = type;
983 void toolbar_set_compose_button(Toolbar *toolbar,
984 ComposeButtonType compose_btn_type)
986 if (toolbar->compose_btn_type != compose_btn_type)
987 activate_compose_button(toolbar,
988 prefs_common.toolbar_style,
989 compose_btn_type);
992 static void activate_learn_button (Toolbar *toolbar,
993 ToolbarStyle style,
994 LearnButtonType type)
996 if ((!toolbar->learn_spam_btn))
997 return;
999 if (type == LEARN_SPAM) {
1000 gtk_tool_button_set_icon_widget(
1001 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
1002 toolbar->learn_spam_icon);
1003 gtk_tool_button_set_label(
1004 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
1005 _("Spam"));
1006 #ifndef GENERIC_UMPC
1007 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn spam"));
1008 #endif
1009 gtk_widget_show(toolbar->learn_spam_icon);
1010 } else {
1011 gtk_tool_button_set_icon_widget(
1012 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
1013 toolbar->learn_ham_icon);
1014 gtk_tool_button_set_label(
1015 GTK_TOOL_BUTTON(toolbar->learn_spam_btn),
1016 _("Ham"));
1017 #ifndef GENERIC_UMPC
1018 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(toolbar->learn_spam_btn), _("Learn ham"));
1019 #endif
1020 gtk_widget_show(toolbar->learn_ham_icon);
1022 toolbar->learn_btn_type = type;
1025 void toolbar_set_learn_button(Toolbar *toolbar,
1026 LearnButtonType learn_btn_type)
1028 if (toolbar->learn_btn_type != learn_btn_type)
1029 activate_learn_button(toolbar,
1030 prefs_common.toolbar_style,
1031 learn_btn_type);
1034 void toolbar_toggle(guint action, gpointer data)
1036 MainWindow *mainwin = (MainWindow*)data;
1037 const GList *list;
1038 const GList *cur;
1040 cm_return_if_fail(mainwin != NULL);
1042 toolbar_style(TOOLBAR_MAIN, action, mainwin);
1044 list = compose_get_compose_list();
1045 for (cur = list; cur != NULL; cur = cur->next) {
1046 toolbar_style(TOOLBAR_COMPOSE, action, cur->data);
1048 list = messageview_get_msgview_list();
1049 for (cur = list; cur != NULL; cur = cur->next) {
1050 toolbar_style(TOOLBAR_MSGVIEW, action, cur->data);
1055 void toolbar_set_style(GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action)
1057 switch ((ToolbarStyle)action) {
1058 case TOOLBAR_NONE:
1059 gtk_widget_hide(handlebox_wid);
1060 break;
1061 case TOOLBAR_ICON:
1062 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1063 GTK_TOOLBAR_ICONS);
1064 break;
1065 case TOOLBAR_TEXT:
1066 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1067 GTK_TOOLBAR_TEXT);
1068 break;
1069 case TOOLBAR_BOTH:
1070 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1071 GTK_TOOLBAR_BOTH);
1072 break;
1073 case TOOLBAR_BOTH_HORIZ:
1074 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar_wid),
1075 GTK_TOOLBAR_BOTH_HORIZ);
1076 break;
1077 default:
1078 return;
1081 prefs_common.toolbar_style = (ToolbarStyle)action;
1082 gtk_widget_set_size_request(handlebox_wid, 1, -1);
1084 if (prefs_common.toolbar_style != TOOLBAR_NONE) {
1085 gtk_widget_show(handlebox_wid);
1086 gtk_widget_queue_resize(handlebox_wid);
1090 * Change the style of toolbar
1092 static void toolbar_style(ToolbarType type, guint action, gpointer data)
1094 GtkWidget *handlebox_wid;
1095 GtkWidget *toolbar_wid;
1096 MainWindow *mainwin = (MainWindow*)data;
1097 Compose *compose = (Compose*)data;
1098 MessageView *msgview = (MessageView*)data;
1100 cm_return_if_fail(data != NULL);
1102 switch (type) {
1103 case TOOLBAR_MAIN:
1104 handlebox_wid = mainwin->handlebox;
1105 toolbar_wid = mainwin->toolbar->toolbar;
1106 break;
1107 case TOOLBAR_COMPOSE:
1108 handlebox_wid = compose->handlebox;
1109 toolbar_wid = compose->toolbar->toolbar;
1110 break;
1111 case TOOLBAR_MSGVIEW:
1112 handlebox_wid = msgview->handlebox;
1113 toolbar_wid = msgview->toolbar->toolbar;
1114 break;
1115 default:
1117 return;
1119 toolbar_set_style(toolbar_wid, handlebox_wid, action);
1122 /* Toolbar handling */
1123 static void toolbar_inc_cb(GtkWidget *widget,
1124 gpointer data)
1126 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1127 MainWindow *mainwin;
1129 cm_return_if_fail(toolbar_item != NULL);
1131 switch (toolbar_item->type) {
1132 case TOOLBAR_MAIN:
1133 mainwin = (MainWindow*)toolbar_item->parent;
1134 inc_mail_cb(mainwin, 0, NULL);
1135 break;
1136 default:
1137 break;
1141 static void toolbar_inc_all_cb(GtkWidget *widget,
1142 gpointer data)
1144 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1145 MainWindow *mainwin;
1147 cm_return_if_fail(toolbar_item != NULL);
1149 switch (toolbar_item->type) {
1150 case TOOLBAR_MAIN:
1151 mainwin = (MainWindow*)toolbar_item->parent;
1152 inc_all_account_mail_cb(mainwin, 0, NULL);
1153 break;
1154 default:
1155 break;
1159 static void toolbar_send_queued_cb(GtkWidget *widget,gpointer data)
1161 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1162 MainWindow *mainwin;
1164 cm_return_if_fail(toolbar_item != NULL);
1166 switch (toolbar_item->type) {
1167 case TOOLBAR_MAIN:
1168 mainwin = (MainWindow*)toolbar_item->parent;
1169 send_queue_cb(mainwin, 0, NULL);
1170 break;
1171 default:
1172 break;
1176 static void toolbar_exec_cb(GtkWidget *widget,
1177 gpointer data)
1179 MainWindow *mainwin = get_mainwin(data);
1181 cm_return_if_fail(mainwin != NULL);
1182 summary_execute(mainwin->summaryview);
1186 * Delete current/selected(s) message(s)
1188 static void toolbar_trash_cb(GtkWidget *widget, gpointer data)
1190 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1191 MainWindow *mainwin;
1193 cm_return_if_fail(toolbar_item != NULL);
1194 cm_return_if_fail(toolbar_item->parent);
1196 switch (toolbar_item->type) {
1197 case TOOLBAR_MSGVIEW:
1198 messageview_delete((MessageView *)toolbar_item->parent);
1199 break;
1200 case TOOLBAR_MAIN:
1201 mainwin = (MainWindow *)toolbar_item->parent;
1202 summary_delete_trash(mainwin->summaryview);
1203 break;
1204 default:
1205 debug_print("toolbar event not supported\n");
1206 break;
1211 * Delete current/selected(s) message(s)
1213 static void toolbar_delete_cb(GtkWidget *widget, gpointer data)
1215 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1216 MainWindow *mainwin;
1218 cm_return_if_fail(toolbar_item != NULL);
1219 cm_return_if_fail(toolbar_item->parent);
1221 switch (toolbar_item->type) {
1222 case TOOLBAR_MSGVIEW:
1223 messageview_delete((MessageView *)toolbar_item->parent);
1224 break;
1225 case TOOLBAR_MAIN:
1226 mainwin = (MainWindow *)toolbar_item->parent;
1227 summary_delete(mainwin->summaryview);
1228 break;
1229 default:
1230 debug_print("toolbar event not supported\n");
1231 break;
1235 static void toolbar_delete_dup(gpointer data, guint all)
1237 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1238 MainWindow *mainwin = NULL;
1240 cm_return_if_fail(toolbar_item != NULL);
1242 switch (toolbar_item->type) {
1243 case TOOLBAR_MAIN:
1244 mainwin = (MainWindow*)toolbar_item->parent;
1245 if (all)
1246 mainwindow_delete_duplicated_all(mainwin);
1247 else
1248 mainwindow_delete_duplicated(mainwin);
1249 break;
1250 case TOOLBAR_COMPOSE:
1251 case TOOLBAR_MSGVIEW:
1252 break;
1253 default:
1254 debug_print("toolbar event not supported\n");
1255 return;
1259 static void toolbar_delete_dup_cb(GtkWidget *widget, gpointer data)
1261 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1262 MainWindow *mainwin = NULL;
1264 cm_return_if_fail(toolbar_item != NULL);
1266 switch (toolbar_item->type) {
1267 case TOOLBAR_MAIN:
1268 mainwin = (MainWindow*)toolbar_item->parent;
1269 mainwindow_delete_duplicated(mainwin);
1270 break;
1271 case TOOLBAR_COMPOSE:
1272 case TOOLBAR_MSGVIEW:
1273 break;
1274 default:
1275 return;
1280 * Compose new message
1282 static void toolbar_compose_cb(GtkWidget *widget, gpointer data)
1284 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1285 MainWindow *mainwin;
1286 MessageView *msgview;
1288 cm_return_if_fail(toolbar_item != NULL);
1290 switch (toolbar_item->type) {
1291 case TOOLBAR_MAIN:
1292 mainwin = (MainWindow*)toolbar_item->parent;
1293 if (mainwin->toolbar->compose_btn_type == COMPOSEBUTTON_NEWS)
1294 compose_news_cb(mainwin, 0, NULL);
1295 else
1296 compose_mail_cb(mainwin, 0, NULL);
1297 break;
1298 case TOOLBAR_MSGVIEW:
1299 msgview = (MessageView*)toolbar_item->parent;
1300 compose_new_with_folderitem(NULL,
1301 msgview->msginfo->folder, NULL);
1302 break;
1303 default:
1304 debug_print("toolbar event not supported\n");
1308 static void toolbar_learn(gpointer data, guint as_spam)
1310 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1311 MainWindow *mainwin;
1312 MessageView *msgview;
1314 cm_return_if_fail(toolbar_item != NULL);
1316 switch (toolbar_item->type) {
1317 case TOOLBAR_MAIN:
1318 mainwin = (MainWindow*)toolbar_item->parent;
1319 if (as_spam)
1320 mainwindow_learn(mainwin, TRUE);
1321 else
1322 mainwindow_learn(mainwin, FALSE);
1323 break;
1324 case TOOLBAR_MSGVIEW:
1325 msgview = (MessageView*)toolbar_item->parent;
1326 if (as_spam)
1327 messageview_learn(msgview, TRUE);
1328 else
1329 messageview_learn(msgview, FALSE);
1330 break;
1331 default:
1332 debug_print("toolbar event not supported\n");
1336 static void toolbar_learn_cb(GtkWidget *widget, gpointer data)
1338 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1339 MainWindow *mainwin;
1340 MessageView *msgview;
1342 cm_return_if_fail(toolbar_item != NULL);
1344 switch (toolbar_item->type) {
1345 case TOOLBAR_MAIN:
1346 mainwin = (MainWindow*)toolbar_item->parent;
1347 if (mainwin->toolbar->learn_btn_type == LEARN_SPAM)
1348 mainwindow_learn(mainwin, TRUE);
1349 else
1350 mainwindow_learn(mainwin, FALSE);
1351 break;
1352 case TOOLBAR_MSGVIEW:
1353 msgview = (MessageView*)toolbar_item->parent;
1354 if (msgview->toolbar->learn_btn_type == LEARN_SPAM)
1355 messageview_learn(msgview, TRUE);
1356 else
1357 messageview_learn(msgview, FALSE);
1358 break;
1359 default:
1360 debug_print("toolbar event not supported\n");
1366 * Reply Message
1368 static void toolbar_reply_cb(GtkWidget *widget, gpointer data)
1370 toolbar_reply(data, (prefs_common.reply_with_quote ?
1371 COMPOSE_REPLY_WITH_QUOTE : COMPOSE_REPLY_WITHOUT_QUOTE));
1376 * Reply message to Sender and All recipients
1378 static void toolbar_reply_to_all_cb(GtkWidget *widget, gpointer data)
1380 toolbar_reply(data,
1381 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_ALL_WITH_QUOTE
1382 : COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE));
1387 * Reply to Mailing List
1389 static void toolbar_reply_to_list_cb(GtkWidget *widget, gpointer data)
1391 toolbar_reply(data,
1392 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_LIST_WITH_QUOTE
1393 : COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE));
1398 * Reply to sender of message
1400 static void toolbar_reply_to_sender_cb(GtkWidget *widget, gpointer data)
1402 toolbar_reply(data,
1403 (prefs_common.reply_with_quote ? COMPOSE_REPLY_TO_SENDER_WITH_QUOTE
1404 : COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE));
1408 * Open addressbook
1410 static void toolbar_addrbook_cb(GtkWidget *widget, gpointer data)
1412 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1413 Compose *compose;
1415 cm_return_if_fail(toolbar_item != NULL);
1417 switch (toolbar_item->type) {
1418 case TOOLBAR_MAIN:
1419 case TOOLBAR_MSGVIEW:
1420 compose = NULL;
1421 break;
1422 case TOOLBAR_COMPOSE:
1423 compose = (Compose *)toolbar_item->parent;
1424 break;
1425 default:
1426 return;
1428 #ifndef USE_ALT_ADDRBOOK
1429 addressbook_open(compose);
1430 #else
1431 GError* error = NULL;
1432 addressbook_connect_signals(compose);
1433 addressbook_dbus_open(TRUE, &error);
1434 if (error) {
1435 g_warning("%s", error->message);
1436 g_error_free(error);
1438 #endif
1443 * Forward current/selected(s) message(s)
1445 static void toolbar_forward_cb(GtkWidget *widget, gpointer data)
1447 toolbar_reply(data, (COMPOSE_FORWARD));
1451 * Goto Prev Unread Message
1453 static void toolbar_prev_unread_cb(GtkWidget *widget, gpointer data)
1455 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1456 MainWindow *mainwin;
1457 MessageView *msgview;
1459 cm_return_if_fail(toolbar_item != NULL);
1461 switch (toolbar_item->type) {
1462 case TOOLBAR_MAIN:
1463 mainwin = (MainWindow*)toolbar_item->parent;
1464 summary_select_prev_unread(mainwin->summaryview);
1465 break;
1467 case TOOLBAR_MSGVIEW:
1468 msgview = (MessageView*)toolbar_item->parent;
1469 msgview->updating = TRUE;
1470 summary_select_prev_unread(msgview->mainwin->summaryview);
1471 msgview->updating = FALSE;
1473 if (msgview->deferred_destroy) {
1474 debug_print("messageview got away!\n");
1475 messageview_destroy(msgview);
1476 return;
1479 /* Now we need to update the messageview window */
1480 if (msgview->mainwin->summaryview->selected) {
1481 #ifndef GENERIC_UMPC
1482 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1484 if (msginfo)
1485 messageview_show(msgview, msginfo,
1486 msgview->all_headers);
1487 #endif
1488 } else {
1489 gtk_widget_destroy(msgview->window);
1491 break;
1492 default:
1493 debug_print("toolbar event not supported\n");
1498 * Goto Next Unread Message
1500 static void toolbar_next_unread_cb(GtkWidget *widget, gpointer data)
1502 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1503 MainWindow *mainwin;
1504 MessageView *msgview;
1506 cm_return_if_fail(toolbar_item != NULL);
1508 switch (toolbar_item->type) {
1509 case TOOLBAR_MAIN:
1510 mainwin = (MainWindow*)toolbar_item->parent;
1511 summary_select_next_unread(mainwin->summaryview);
1512 break;
1514 case TOOLBAR_MSGVIEW:
1515 msgview = (MessageView*)toolbar_item->parent;
1516 msgview->updating = TRUE;
1517 summary_select_next_unread(msgview->mainwin->summaryview);
1518 msgview->updating = FALSE;
1520 if (msgview->deferred_destroy) {
1521 debug_print("messageview got away!\n");
1522 messageview_destroy(msgview);
1523 return;
1526 /* Now we need to update the messageview window */
1527 if (msgview->mainwin->summaryview->selected) {
1528 #ifndef GENERIC_UMPC
1529 MsgInfo * msginfo = summary_get_selected_msg(msgview->mainwin->summaryview);
1531 if (msginfo)
1532 messageview_show(msgview, msginfo,
1533 msgview->all_headers);
1534 #endif
1535 } else {
1536 gtk_widget_destroy(msgview->window);
1538 break;
1539 default:
1540 debug_print("toolbar event not supported\n");
1544 static void toolbar_ignore_thread_cb(GtkWidget *widget, gpointer data)
1546 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1547 MainWindow *mainwin;
1549 cm_return_if_fail(toolbar_item != NULL);
1551 switch (toolbar_item->type) {
1552 case TOOLBAR_MAIN:
1553 mainwin = (MainWindow *) toolbar_item->parent;
1554 summary_toggle_ignore_thread(mainwin->summaryview);
1555 break;
1556 case TOOLBAR_MSGVIEW:
1557 /* TODO: see toolbar_next_unread_cb() if you need
1558 * this in the message view */
1559 break;
1560 default:
1561 debug_print("toolbar event not supported\n");
1562 break;
1566 static void toolbar_watch_thread_cb(GtkWidget *widget, gpointer data)
1568 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1569 MainWindow *mainwin;
1571 cm_return_if_fail(toolbar_item != NULL);
1573 switch (toolbar_item->type) {
1574 case TOOLBAR_MAIN:
1575 mainwin = (MainWindow *) toolbar_item->parent;
1576 summary_toggle_watch_thread(mainwin->summaryview);
1577 break;
1578 case TOOLBAR_MSGVIEW:
1579 /* TODO: see toolbar_next_unread_cb() if you need
1580 * this in the message view */
1581 break;
1582 default:
1583 debug_print("toolbar event not supported\n");
1584 break;
1588 static void toolbar_mark_cb(GtkWidget *widget, gpointer data)
1590 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1591 MainWindow *mainwin;
1593 cm_return_if_fail(toolbar_item != NULL);
1595 switch (toolbar_item->type) {
1596 case TOOLBAR_MAIN:
1597 mainwin = (MainWindow *) toolbar_item->parent;
1598 summary_mark(mainwin->summaryview);
1599 break;
1600 case TOOLBAR_MSGVIEW:
1601 /* TODO: see toolbar_next_unread_cb() if you need
1602 * this in the message view */
1603 break;
1604 default:
1605 debug_print("toolbar event not supported\n");
1606 break;
1610 static void toolbar_unmark_cb(GtkWidget *widget, gpointer data)
1612 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1613 MainWindow *mainwin;
1615 cm_return_if_fail(toolbar_item != NULL);
1617 switch (toolbar_item->type) {
1618 case TOOLBAR_MAIN:
1619 mainwin = (MainWindow *) toolbar_item->parent;
1620 summary_unmark(mainwin->summaryview);
1621 break;
1622 case TOOLBAR_MSGVIEW:
1623 /* TODO: see toolbar_next_unread_cb() if you need
1624 * this in the message view */
1625 break;
1626 default:
1627 debug_print("toolbar event not supported\n");
1628 break;
1632 static void toolbar_lock_cb(GtkWidget *widget, gpointer data)
1634 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1635 MainWindow *mainwin;
1637 cm_return_if_fail(toolbar_item != NULL);
1639 switch (toolbar_item->type) {
1640 case TOOLBAR_MAIN:
1641 mainwin = (MainWindow *) toolbar_item->parent;
1642 summary_msgs_lock(mainwin->summaryview);
1643 break;
1644 case TOOLBAR_MSGVIEW:
1645 /* TODO: see toolbar_next_unread_cb() if you need
1646 * this in the message view */
1647 break;
1648 default:
1649 debug_print("toolbar event not supported\n");
1650 break;
1654 static void toolbar_unlock_cb(GtkWidget *widget, gpointer data)
1656 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1657 MainWindow *mainwin;
1659 cm_return_if_fail(toolbar_item != NULL);
1661 switch (toolbar_item->type) {
1662 case TOOLBAR_MAIN:
1663 mainwin = (MainWindow *) toolbar_item->parent;
1664 summary_msgs_unlock(mainwin->summaryview);
1665 break;
1666 case TOOLBAR_MSGVIEW:
1667 /* TODO: see toolbar_next_unread_cb() if you need
1668 * this in the message view */
1669 break;
1670 default:
1671 debug_print("toolbar event not supported\n");
1672 break;
1676 static void toolbar_all_read_cb(GtkWidget *widget, gpointer data)
1678 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1679 MainWindow *mainwin;
1681 cm_return_if_fail(toolbar_item != NULL);
1683 switch (toolbar_item->type) {
1684 case TOOLBAR_MAIN:
1685 mainwin = (MainWindow *) toolbar_item->parent;
1686 summary_mark_all_read(mainwin->summaryview, TRUE);
1687 break;
1688 case TOOLBAR_MSGVIEW:
1689 /* TODO: see toolbar_next_unread_cb() if you need
1690 * this in the message view */
1691 break;
1692 default:
1693 debug_print("toolbar event not supported\n");
1694 break;
1698 static void toolbar_all_unread_cb(GtkWidget *widget, gpointer data)
1700 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1701 MainWindow *mainwin;
1703 cm_return_if_fail(toolbar_item != NULL);
1705 switch (toolbar_item->type) {
1706 case TOOLBAR_MAIN:
1707 mainwin = (MainWindow *) toolbar_item->parent;
1708 summary_mark_all_unread(mainwin->summaryview, TRUE);
1709 break;
1710 case TOOLBAR_MSGVIEW:
1711 /* TODO: see toolbar_next_unread_cb() if you need
1712 * this in the message view */
1713 break;
1714 default:
1715 debug_print("toolbar event not supported\n");
1716 break;
1720 static void toolbar_read_cb(GtkWidget *widget, gpointer data)
1722 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1723 MainWindow *mainwin;
1725 cm_return_if_fail(toolbar_item != NULL);
1727 switch (toolbar_item->type) {
1728 case TOOLBAR_MAIN:
1729 mainwin = (MainWindow *) toolbar_item->parent;
1730 summary_mark_as_read(mainwin->summaryview);
1731 break;
1732 case TOOLBAR_MSGVIEW:
1733 /* TODO: see toolbar_next_unread_cb() if you need
1734 * this in the message view */
1735 break;
1736 default:
1737 debug_print("toolbar event not supported\n");
1738 break;
1742 static void toolbar_unread_cb(GtkWidget *widget, gpointer data)
1744 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1745 MainWindow *mainwin;
1747 cm_return_if_fail(toolbar_item != NULL);
1749 switch (toolbar_item->type) {
1750 case TOOLBAR_MAIN:
1751 mainwin = (MainWindow *) toolbar_item->parent;
1752 summary_mark_as_unread(mainwin->summaryview);
1753 break;
1754 case TOOLBAR_MSGVIEW:
1755 /* TODO: see toolbar_next_unread_cb() if you need
1756 * this in the message view */
1757 break;
1758 default:
1759 debug_print("toolbar event not supported\n");
1760 break;
1764 static void toolbar_run_processing_cb(GtkWidget *widget, gpointer data)
1766 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1767 MainWindow *mainwin;
1768 FolderItem *item;
1770 cm_return_if_fail(toolbar_item != NULL);
1772 switch (toolbar_item->type) {
1773 case TOOLBAR_MAIN:
1774 mainwin = (MainWindow *) toolbar_item->parent;
1775 item = mainwin->summaryview->folder_item;
1776 cm_return_if_fail(item != NULL);
1777 item->processing_pending = TRUE;
1778 folder_item_apply_processing(item);
1779 item->processing_pending = FALSE;
1780 break;
1781 default:
1782 debug_print("toolbar event not supported\n");
1783 break;
1787 static void toolbar_cancel_inc_cb(GtkWidget *widget, gpointer data)
1789 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1791 cm_return_if_fail(toolbar_item != NULL);
1792 inc_cancel_all();
1793 imap_cancel_all();
1796 static void toolbar_cancel_send_cb(GtkWidget *widget, gpointer data)
1798 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1800 cm_return_if_fail(toolbar_item != NULL);
1801 send_cancel();
1804 static void toolbar_cancel_all_cb(GtkWidget *widget, gpointer data)
1806 toolbar_cancel_inc_cb(widget, data);
1807 toolbar_cancel_send_cb(widget, data);
1810 static void toolbar_print_cb(GtkWidget *widget, gpointer data)
1812 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1813 MainWindow *mainwin;
1815 cm_return_if_fail(toolbar_item != NULL);
1817 switch (toolbar_item->type) {
1818 case TOOLBAR_MAIN:
1819 mainwin = (MainWindow *) toolbar_item->parent;
1820 summary_print(mainwin->summaryview);
1821 break;
1822 case TOOLBAR_MSGVIEW:
1823 /* TODO: see toolbar_next_unread_cb() if you need
1824 * this in the message view */
1825 break;
1826 default:
1827 debug_print("toolbar event not supported\n");
1828 break;
1832 static void toolbar_send_cb(GtkWidget *widget, gpointer data)
1834 compose_toolbar_cb(A_SEND, data);
1837 static void toolbar_send_later_cb(GtkWidget *widget, gpointer data)
1839 compose_toolbar_cb(A_SEND_LATER, data);
1842 static void toolbar_draft_cb(GtkWidget *widget, gpointer data)
1844 compose_toolbar_cb(A_DRAFT, data);
1847 static void toolbar_close_cb(GtkWidget *widget, gpointer data)
1849 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1850 MainWindow *mainwin;
1851 MessageView *messageview;
1852 Compose *compose;
1854 cm_return_if_fail(toolbar_item != NULL);
1856 switch (toolbar_item->type) {
1857 case TOOLBAR_MAIN:
1858 mainwin = (MainWindow *) toolbar_item->parent;
1859 app_will_exit(NULL, mainwin);
1860 break;
1861 case TOOLBAR_MSGVIEW:
1862 messageview = (MessageView *)toolbar_item->parent;
1863 messageview_destroy(messageview);
1864 break;
1865 case TOOLBAR_COMPOSE:
1866 compose = (Compose *)toolbar_item->parent;
1867 compose_close_toolbar(compose);
1868 break;
1872 static void toolbar_preferences_cb(GtkWidget *widget, gpointer data)
1874 prefs_gtk_open();
1877 static void toolbar_open_mail_cb(GtkWidget *widget, gpointer data)
1879 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1880 MainWindow *mainwin;
1882 cm_return_if_fail(toolbar_item != NULL);
1884 switch (toolbar_item->type) {
1885 case TOOLBAR_MAIN:
1886 mainwin = (MainWindow *) toolbar_item->parent;
1887 summary_open_row(NULL, mainwin->summaryview);
1888 break;
1889 case TOOLBAR_MSGVIEW:
1890 debug_print("toolbar event not supported\n");
1891 break;
1892 case TOOLBAR_COMPOSE:
1893 debug_print("toolbar event not supported\n");
1894 break;
1898 static void toolbar_insert_cb(GtkWidget *widget, gpointer data)
1900 compose_toolbar_cb(A_INSERT, data);
1903 static void toolbar_attach_cb(GtkWidget *widget, gpointer data)
1905 compose_toolbar_cb(A_ATTACH, data);
1908 static void toolbar_sig_cb(GtkWidget *widget, gpointer data)
1910 compose_toolbar_cb(A_SIG, data);
1913 static void toolbar_replace_sig_cb(GtkWidget *widget, gpointer data)
1915 compose_toolbar_cb(A_REP_SIG, data);
1918 static void toolbar_ext_editor_cb(GtkWidget *widget, gpointer data)
1920 compose_toolbar_cb(A_EXTEDITOR, data);
1923 static void toolbar_linewrap_current_cb(GtkWidget *widget, gpointer data)
1925 compose_toolbar_cb(A_LINEWRAP_CURRENT, data);
1928 static void toolbar_linewrap_all_cb(GtkWidget *widget, gpointer data)
1930 compose_toolbar_cb(A_LINEWRAP_ALL, data);
1933 #ifdef USE_ENCHANT
1934 static void toolbar_check_spelling_cb(GtkWidget *widget, gpointer data)
1936 compose_toolbar_cb(A_CHECK_SPELLING, data);
1938 #endif
1940 static void toolbar_privacy_sign_cb(GtkWidget *widget, gpointer data)
1942 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1943 Compose *compose = (Compose *)toolbar_item->parent;
1944 gboolean state = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget));
1946 cm_return_if_fail(compose != NULL);
1947 compose_use_signing(compose, state);
1950 /* Any time the toggle button gets toggled, we want to update its tooltip. */
1951 static void toolbar_privacy_sign_toggled_cb(GtkWidget *widget, gpointer data)
1953 gboolean state = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget));
1955 if (state)
1956 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), _("Message will be signed"));
1957 else
1958 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), _("Message will not be signed"));
1961 static void toolbar_privacy_encrypt_cb(GtkWidget *widget, gpointer data)
1963 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1964 Compose *compose = (Compose *)toolbar_item->parent;
1965 gboolean state = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget));
1967 cm_return_if_fail(compose != NULL);
1968 compose_use_encryption(compose, state);
1971 /* Any time the toggle button gets toggled, we want to update its tooltip. */
1972 static void toolbar_privacy_encrypt_toggled_cb(GtkWidget *widget, gpointer data)
1974 gboolean state = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(widget));
1976 if (state)
1977 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), _("Message will be encrypted"));
1978 else
1979 gtk_tool_item_set_tooltip_text(GTK_TOOL_ITEM(widget), _("Message will not be encrypted"));
1983 * Execute actions from toolbar
1985 static void toolbar_actions_execute_cb(GtkWidget *widget, gpointer data)
1987 ToolbarItem *toolbar_item = (ToolbarItem*)data;
1988 GSList *action_list;
1989 MainWindow *mainwin;
1990 Compose *compose;
1991 MessageView *msgview;
1992 gpointer parent = toolbar_item->parent;
1994 cm_return_if_fail(toolbar_item != NULL);
1996 switch (toolbar_item->type) {
1997 case TOOLBAR_MAIN:
1998 mainwin = (MainWindow*)parent;
1999 action_list = mainwin->toolbar->action_list;
2000 break;
2001 case TOOLBAR_COMPOSE:
2002 compose = (Compose*)parent;
2003 action_list = compose->toolbar->action_list;
2004 break;
2005 case TOOLBAR_MSGVIEW:
2006 msgview = (MessageView*)parent;
2007 action_list = msgview->toolbar->action_list;
2008 break;
2009 default:
2010 debug_print("toolbar event not supported\n");
2011 return;
2013 toolbar_action_execute(widget, action_list, parent, toolbar_item->type);
2016 static void toolbar_plugins_execute_cb(GtkWidget *widget, gpointer data)
2018 ToolbarItem *toolbar_item = data;
2019 prefs_toolbar_execute_plugin_item(toolbar_item->parent, toolbar_item->type, toolbar_item->text);
2022 static MainWindow *get_mainwin(gpointer data)
2024 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2025 MainWindow *mainwin = NULL;
2026 MessageView *msgview;
2028 cm_return_val_if_fail(toolbar_item != NULL, NULL);
2030 switch(toolbar_item->type) {
2031 case TOOLBAR_MAIN:
2032 mainwin = (MainWindow*)toolbar_item->parent;
2033 break;
2034 case TOOLBAR_MSGVIEW:
2035 msgview = (MessageView*)toolbar_item->parent;
2036 mainwin = (MainWindow*)msgview->mainwin;
2037 break;
2038 default:
2039 break;
2042 return mainwin;
2045 static void toolbar_go_folders_cb(GtkWidget *widget, gpointer data)
2047 ToolbarItem *toolbar_item = (ToolbarItem*)data;
2048 MainWindow *mainwin = NULL;
2049 switch(toolbar_item->type) {
2050 case TOOLBAR_MAIN:
2051 mainwin = (MainWindow*)toolbar_item->parent;
2052 break;
2053 default:
2054 g_warning("wrong toolbar type");
2055 return;
2058 if (!mainwin->in_folder) {
2059 FolderItem *item = folderview_get_selected_item(mainwin->folderview);
2060 if (item) {
2061 folderview_select(mainwin->folderview, item);
2063 } else {
2064 folderview_grab_focus(mainwin->folderview);
2065 mainwindow_exit_folder(mainwin);
2069 static void toolbar_buttons_cb(GtkWidget *widget,
2070 ToolbarItem *item)
2072 gint num_items;
2073 gint i;
2074 struct {
2075 gint index;
2076 void (*func)(GtkWidget *widget, gpointer data);
2077 } callbacks[] = {
2078 { A_RECEIVE_ALL, toolbar_inc_all_cb },
2079 { A_RECEIVE_CUR, toolbar_inc_cb },
2080 { A_SEND_QUEUED, toolbar_send_queued_cb },
2081 { A_COMPOSE_EMAIL, toolbar_compose_cb },
2082 { A_COMPOSE_NEWS, toolbar_compose_cb },
2083 { A_REPLY_MESSAGE, toolbar_reply_cb },
2084 { A_REPLY_SENDER, toolbar_reply_to_sender_cb },
2085 { A_REPLY_ALL, toolbar_reply_to_all_cb },
2086 { A_REPLY_ML, toolbar_reply_to_list_cb },
2087 { A_FORWARD, toolbar_forward_cb },
2088 { A_TRASH, toolbar_trash_cb },
2089 { A_DELETE_REAL, toolbar_delete_cb },
2090 { A_EXECUTE, toolbar_exec_cb },
2091 { A_GOTO_PREV, toolbar_prev_unread_cb },
2092 { A_GOTO_NEXT, toolbar_next_unread_cb },
2093 { A_IGNORE_THREAD, toolbar_ignore_thread_cb },
2094 { A_WATCH_THREAD, toolbar_watch_thread_cb },
2095 { A_MARK, toolbar_mark_cb },
2096 { A_UNMARK, toolbar_unmark_cb },
2097 { A_LOCK, toolbar_lock_cb },
2098 { A_UNLOCK, toolbar_unlock_cb },
2099 { A_ALL_READ, toolbar_all_read_cb },
2100 { A_ALL_UNREAD, toolbar_all_unread_cb },
2101 { A_READ, toolbar_read_cb },
2102 { A_UNREAD, toolbar_unread_cb },
2103 { A_RUN_PROCESSING, toolbar_run_processing_cb },
2104 { A_PRINT, toolbar_print_cb },
2105 { A_LEARN_SPAM, toolbar_learn_cb },
2106 { A_DELETE_DUP, toolbar_delete_dup_cb },
2107 { A_GO_FOLDERS, toolbar_go_folders_cb },
2109 { A_SEND, toolbar_send_cb },
2110 { A_SEND_LATER, toolbar_send_later_cb },
2111 { A_DRAFT, toolbar_draft_cb },
2112 { A_OPEN_MAIL, toolbar_open_mail_cb },
2113 { A_CLOSE, toolbar_close_cb },
2114 { A_PREFERENCES, toolbar_preferences_cb },
2115 { A_INSERT, toolbar_insert_cb },
2116 { A_ATTACH, toolbar_attach_cb },
2117 { A_SIG, toolbar_sig_cb },
2118 { A_REP_SIG, toolbar_replace_sig_cb },
2119 { A_EXTEDITOR, toolbar_ext_editor_cb },
2120 { A_LINEWRAP_CURRENT, toolbar_linewrap_current_cb },
2121 { A_LINEWRAP_ALL, toolbar_linewrap_all_cb },
2122 { A_ADDRBOOK, toolbar_addrbook_cb },
2123 #ifdef USE_ENCHANT
2124 { A_CHECK_SPELLING, toolbar_check_spelling_cb },
2125 #endif
2126 { A_PRIVACY_SIGN, toolbar_privacy_sign_cb },
2127 { A_PRIVACY_ENCRYPT, toolbar_privacy_encrypt_cb },
2128 { A_CLAWS_ACTIONS, toolbar_actions_execute_cb },
2129 { A_CANCEL_INC, toolbar_cancel_inc_cb },
2130 { A_CANCEL_SEND, toolbar_cancel_send_cb },
2131 { A_CANCEL_ALL, toolbar_cancel_all_cb },
2132 { A_CLAWS_PLUGINS, toolbar_plugins_execute_cb },
2135 num_items = sizeof(callbacks)/sizeof(callbacks[0]);
2137 for (i = 0; i < num_items; i++) {
2138 if (callbacks[i].index == item->index) {
2139 callbacks[i].func(widget, item);
2140 return;
2144 #ifndef GENERIC_UMPC
2145 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
2146 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
2147 gtk_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
2148 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
2149 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
2150 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
2151 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2152 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
2153 tooltip); \
2156 #define TOOLBAR_TOGGLE_ITEM(item,icon,text,tooltip) { \
2157 item = GTK_WIDGET(gtk_toggle_tool_button_new()); \
2158 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(item), icon); \
2159 gtk_tool_button_set_label(GTK_TOOL_BUTTON(item), text); \
2160 gtk_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
2161 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
2162 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
2163 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
2164 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2165 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
2166 tooltip); \
2169 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
2170 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
2171 GList *gchild = NULL; \
2172 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
2173 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
2174 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
2175 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
2176 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2177 CLAWS_SET_TOOL_ITEM_TIP(GTK_TOOL_ITEM(item), \
2178 tooltip); \
2179 CLAWS_SET_ARROW_TIP(GTK_MENU_TOOL_BUTTON(item), menutip); \
2180 child = gtk_bin_get_child(GTK_BIN(item)); \
2181 gchild = gtk_container_get_children( \
2182 GTK_CONTAINER(child)); \
2183 btn = (GtkWidget *)gchild->data; \
2184 gtk_widget_set_can_focus(btn, FALSE); \
2185 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
2186 gtk_widget_set_can_focus(arr, FALSE); \
2187 g_list_free(gchild); \
2188 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
2189 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
2190 g_list_free(gchild); \
2193 #else
2195 #define TOOLBAR_ITEM(item,icon,text,tooltip) { \
2196 item = GTK_WIDGET(gtk_tool_button_new(icon, text)); \
2197 gtk_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
2198 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
2199 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
2200 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
2201 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2204 #define TOOLBAR_TOGGLE_ITEM(item,icon,text,tooltip) { \
2205 item = GTK_WIDGET(gtk_toggle_tool_button_new()); \
2206 gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(item), icon); \
2207 gtk_tool_button_set_label(GTK_TOOL_BUTTON(item), text); \
2208 gtk_widget_set_can_focus(gtk_bin_get_child(GTK_BIN(item)), FALSE); \
2209 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
2210 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
2211 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
2212 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2215 #define TOOLBAR_MENUITEM(item,icon,text,tooltip,menutip) { \
2216 GtkWidget *child = NULL, *btn = NULL, *arr = NULL; \
2217 GList *gchild = NULL; \
2218 item = GTK_WIDGET(gtk_menu_tool_button_new(icon, text)); \
2219 gtk_tool_item_set_homogeneous(GTK_TOOL_ITEM(item), FALSE); \
2220 gtk_tool_item_set_is_important(GTK_TOOL_ITEM(item), TRUE); \
2221 g_signal_connect (G_OBJECT(item), "clicked", G_CALLBACK(toolbar_buttons_cb), toolbar_item); \
2222 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1); \
2223 child = gtk_bin_get_child(GTK_BIN(item)); \
2224 gchild = gtk_container_get_children( \
2225 GTK_CONTAINER(child)); \
2226 btn = (GtkWidget *)gchild->data; \
2227 gtk_widget_set_can_focus(btn, FALSE); \
2228 arr = (GtkWidget *)(gchild->next?gchild->next->data:NULL); \
2229 gtk_widget_set_can_focus(arr, FALSE); \
2230 g_list_free(gchild); \
2231 gchild = gtk_container_get_children(GTK_CONTAINER(arr)); \
2232 gtk_widget_set_size_request(GTK_WIDGET(gchild->data), 9, -1); \
2233 g_list_free(gchild); \
2235 #endif
2237 #define ADD_MENU_ITEM(name,cb,data) { \
2238 item = gtk_menu_item_new_with_mnemonic(name); \
2239 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); \
2240 g_signal_connect(G_OBJECT(item), "activate", \
2241 G_CALLBACK(cb), \
2242 toolbar_item); \
2243 g_object_set_data(G_OBJECT(item), "int-value", GINT_TO_POINTER(data)); \
2244 gtk_widget_show(item); \
2247 #ifndef GENERIC_UMPC
2248 static void toolbar_reply_menu_cb(GtkWidget *widget, gpointer data)
2250 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
2251 ToolbarItem *toolbar_item = (ToolbarItem *)data;
2253 toolbar_reply(toolbar_item, GPOINTER_TO_INT(int_value));
2256 static void toolbar_delete_dup_menu_cb(GtkWidget *widget, gpointer data)
2258 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
2259 ToolbarItem *toolbar_item = (ToolbarItem *)data;
2261 toolbar_delete_dup(toolbar_item, GPOINTER_TO_INT(int_value));
2263 #endif
2265 static void toolbar_learn_menu_cb(GtkWidget *widget, gpointer data)
2267 gpointer int_value = g_object_get_data(G_OBJECT(widget), "int-value");
2268 ToolbarItem *toolbar_item = (ToolbarItem *)data;
2270 toolbar_learn(toolbar_item, GPOINTER_TO_INT(int_value));
2275 * Create a new toolbar with specified type
2276 * if a callback list is passed it will be used before the
2277 * common callback list
2279 Toolbar *toolbar_create(ToolbarType type,
2280 GtkWidget *container,
2281 gpointer data)
2283 ToolbarItem *toolbar_item;
2285 GtkWidget *toolbar;
2286 GtkWidget *icon_wid = NULL;
2287 GtkWidget *icon_news;
2288 GtkWidget *icon_ham;
2289 GtkWidget *item;
2290 ToolbarClawsActions *action_item;
2291 GSList *cur;
2292 GSList *toolbar_list;
2293 Toolbar *toolbar_data;
2294 GtkWidget *menu;
2295 toolbar_read_config_file(type);
2296 toolbar_list = toolbar_get_list(type);
2298 toolbar_data = g_new0(Toolbar, 1);
2300 toolbar = gtk_toolbar_new();
2302 gtk_orientable_set_orientation(GTK_ORIENTABLE(toolbar), GTK_ORIENTATION_HORIZONTAL);
2304 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH);
2305 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(toolbar), TRUE);
2306 gtk_widget_set_hexpand(toolbar, TRUE);
2308 for (cur = toolbar_list; cur != NULL; cur = cur->next) {
2310 if (g_ascii_strcasecmp(((ToolbarItem*)cur->data)->file, TOOLBAR_TAG_SEPARATOR) == 0) {
2311 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), gtk_separator_tool_item_new(), -1);
2312 continue;
2315 toolbar_item = g_new0(ToolbarItem, 1);
2316 toolbar_item->index = ((ToolbarItem*)cur->data)->index;
2317 toolbar_item->file = g_strdup(((ToolbarItem*)cur->data)->file);
2318 toolbar_item->text = g_strdup(((ToolbarItem*)cur->data)->text);
2319 toolbar_item->parent = data;
2320 toolbar_item->type = type;
2322 /* collect toolbar items in list to keep track */
2323 toolbar_data->item_list =
2324 g_slist_append(toolbar_data->item_list,
2325 toolbar_item);
2326 icon_wid = stock_pixmap_widget(stock_pixmap_get_icon(toolbar_item->file));
2328 switch (toolbar_item->index) {
2330 case A_GO_FOLDERS:
2331 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to folder list"));
2332 toolbar_data->folders_btn = item;
2333 break;
2334 case A_RECEIVE_ALL:
2335 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2336 _("Receive Mail from all Accounts"),
2337 _("Receive Mail from selected Account"));
2338 toolbar_data->getall_btn = item;
2339 break;
2340 case A_RECEIVE_CUR:
2341 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Receive Mail from current Account"));
2342 toolbar_data->get_btn = item;
2343 break;
2344 case A_SEND_QUEUED:
2345 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Queued Messages"));
2346 toolbar_data->send_btn = item;
2347 break;
2348 case A_CLOSE:
2349 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Close window"));
2350 toolbar_data->close_window_btn = item;
2351 break;
2352 case A_PREFERENCES:
2353 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open preferences"));
2354 toolbar_data->preferences_btn = item;
2355 break;
2356 case A_OPEN_MAIL:
2357 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Open email"));
2358 toolbar_data->open_mail_btn = item;
2359 break;
2360 case A_COMPOSE_EMAIL:
2361 #ifndef GENERIC_UMPC
2362 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2363 _("Compose Email"),
2364 _("Compose with selected Account"));
2365 toolbar_data->compose_mail_btn = item;
2366 toolbar_data->compose_mail_icon = icon_wid;
2367 g_object_ref_sink(toolbar_data->compose_mail_icon);
2369 icon_news = stock_pixmap_widget(STOCK_PIXMAP_NEWS_COMPOSE);
2370 toolbar_data->compose_news_icon = icon_news;
2371 g_object_ref_sink(toolbar_data->compose_news_icon);
2372 #else
2373 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2374 _("Compose Email"));
2375 toolbar_data->compose_mail_btn = item;
2376 toolbar_data->compose_mail_icon = icon_wid;
2378 icon_news = stock_pixmap_widget(STOCK_PIXMAP_NEWS_COMPOSE);
2379 toolbar_data->compose_news_icon = icon_news;
2380 #endif
2381 break;
2382 case A_LEARN_SPAM:
2383 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2384 _("Spam"),
2385 _("Learn as..."));
2386 toolbar_data->learn_spam_btn = item;
2387 toolbar_data->learn_spam_icon = icon_wid;
2388 g_object_ref_sink(toolbar_data->learn_spam_icon);
2390 icon_ham = stock_pixmap_widget(STOCK_PIXMAP_HAM_BTN);
2391 toolbar_data->learn_ham_icon = icon_ham;
2392 g_object_ref_sink(toolbar_data->learn_ham_icon);
2394 menu = gtk_menu_new();
2395 ADD_MENU_ITEM(_("Learn as _Spam"), toolbar_learn_menu_cb, TRUE);
2396 ADD_MENU_ITEM(_("Learn as _Ham"), toolbar_learn_menu_cb, FALSE);
2397 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->learn_spam_btn), menu);
2398 break;
2399 case A_DELETE_DUP:
2400 #ifndef GENERIC_UMPC
2401 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2402 _("Delete duplicates"),
2403 _("Delete duplicates options"));
2404 toolbar_data->delete_dup_btn = item;
2406 menu = gtk_menu_new();
2407 ADD_MENU_ITEM(_("Delete duplicates in selected folder"), toolbar_delete_dup_menu_cb, FALSE);
2408 ADD_MENU_ITEM(_("Delete duplicates in all folders"), toolbar_delete_dup_menu_cb, TRUE);
2409 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->delete_dup_btn), menu);
2410 #else
2411 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete duplicates"));
2412 toolbar_data->delete_dup_btn = item;
2413 #endif
2414 break;
2415 case A_REPLY_MESSAGE:
2416 #ifndef GENERIC_UMPC
2417 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2418 _("Reply to Message"),
2419 _("Reply to Message options"));
2420 toolbar_data->reply_btn = item;
2422 menu = gtk_menu_new();
2423 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITH_QUOTE);
2424 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_WITHOUT_QUOTE);
2425 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->reply_btn), menu);
2426 #else
2427 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2428 _("Reply to Message"));
2429 toolbar_data->reply_btn = item;
2430 #endif
2431 break;
2432 case A_REPLY_SENDER:
2433 #ifndef GENERIC_UMPC
2434 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2435 _("Reply to Sender"),
2436 _("Reply to Sender options"));
2437 toolbar_data->replysender_btn = item;
2439 menu = gtk_menu_new();
2440 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITH_QUOTE);
2441 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_SENDER_WITHOUT_QUOTE);
2442 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replysender_btn), menu);
2443 #else
2444 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2445 _("Reply to Sender"));
2446 toolbar_data->replysender_btn = item;
2447 #endif
2448 break;
2449 case A_REPLY_ALL:
2450 #ifndef GENERIC_UMPC
2451 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2452 _("Reply to All"),
2453 _("Reply to All options"));
2454 toolbar_data->replyall_btn = item;
2456 menu = gtk_menu_new();
2457 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITH_QUOTE);
2458 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE);
2459 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replyall_btn), menu);
2460 #else
2461 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2462 _("Reply to All"));
2463 toolbar_data->replyall_btn = item;
2464 #endif
2465 break;
2466 case A_REPLY_ML:
2467 #ifndef GENERIC_UMPC
2468 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2469 _("Reply to Mailing-list"),
2470 _("Reply to Mailing-list options"));
2471 toolbar_data->replylist_btn = item;
2473 menu = gtk_menu_new();
2474 ADD_MENU_ITEM(_("_Reply with quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITH_QUOTE);
2475 ADD_MENU_ITEM(_("Reply without _quote"), toolbar_reply_menu_cb, COMPOSE_REPLY_TO_LIST_WITHOUT_QUOTE);
2476 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->replylist_btn), menu);
2477 #else
2478 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2479 _("Reply to Mailing-list"));
2480 toolbar_data->replylist_btn = item;
2481 #endif
2482 break;
2483 case A_FORWARD:
2484 #ifndef GENERIC_UMPC
2485 TOOLBAR_MENUITEM(item,icon_wid,toolbar_item->text,
2486 _("Forward Message"),
2487 _("Forward Message options"));
2488 toolbar_data->fwd_btn = item;
2490 menu = gtk_menu_new();
2491 ADD_MENU_ITEM(_("_Forward"), toolbar_reply_menu_cb, COMPOSE_FORWARD_INLINE);
2492 ADD_MENU_ITEM(_("For_ward as attachment"), toolbar_reply_menu_cb, COMPOSE_FORWARD_AS_ATTACH);
2493 ADD_MENU_ITEM(_("Redirec_t"), toolbar_reply_menu_cb, COMPOSE_REDIRECT);
2494 gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(toolbar_data->fwd_btn), menu);
2495 #else
2496 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2497 _("Forward Message"));
2498 toolbar_data->fwd_btn = item;
2499 #endif
2500 break;
2501 case A_TRASH:
2502 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Trash Message"));
2503 toolbar_data->trash_btn = item;
2504 break;
2505 case A_DELETE_REAL:
2506 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Delete Message"));
2507 toolbar_data->delete_btn = item;
2508 break;
2509 case A_EXECUTE:
2510 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Execute"));
2511 toolbar_data->exec_btn = item;
2512 break;
2513 case A_GOTO_PREV:
2514 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Previous Unread Message"));
2515 toolbar_data->prev_btn = item;
2516 break;
2517 case A_GOTO_NEXT:
2518 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Go to Next Unread Message"));
2519 toolbar_data->next_btn = item;
2520 break;
2522 /* Compose Toolbar */
2523 case A_SEND:
2524 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Send Message"));
2525 toolbar_data->send_btn = item;
2526 break;
2527 case A_SEND_LATER:
2528 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Put into queue folder and send later"));
2529 toolbar_data->sendl_btn = item;
2530 break;
2531 case A_DRAFT:
2532 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Save to draft folder"));
2533 toolbar_data->draft_btn = item;
2534 break;
2535 case A_INSERT:
2536 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert file"));
2537 toolbar_data->insert_btn = item;
2538 break;
2539 case A_ATTACH:
2540 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Attach file"));
2541 toolbar_data->attach_btn = item;
2542 break;
2543 case A_SIG:
2544 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Insert signature"));
2545 toolbar_data->sig_btn = item;
2546 break;
2547 case A_REP_SIG:
2548 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Replace signature"));
2549 toolbar_data->repsig_btn = item;
2550 break;
2551 case A_EXTEDITOR:
2552 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Edit with external editor"));
2553 toolbar_data->exteditor_btn = item;
2554 break;
2555 case A_LINEWRAP_CURRENT:
2556 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap long lines of current paragraph"));
2557 toolbar_data->linewrap_current_btn = item;
2558 break;
2559 case A_LINEWRAP_ALL:
2560 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Wrap all long lines"));
2561 toolbar_data->linewrap_all_btn = item;
2562 break;
2563 case A_ADDRBOOK:
2564 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Address book"));
2565 toolbar_data->addrbook_btn = item;
2566 break;
2567 #ifdef USE_ENCHANT
2568 case A_CHECK_SPELLING:
2569 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Check spelling"));
2570 toolbar_data->spellcheck_btn = item;
2571 break;
2572 #endif
2573 case A_PRIVACY_SIGN:
2574 TOOLBAR_TOGGLE_ITEM(item,icon_wid,toolbar_item->text,_("Sign"));
2575 g_signal_connect (G_OBJECT(item), "toggled",
2576 G_CALLBACK(toolbar_privacy_sign_toggled_cb), NULL);
2577 /* Call the "toggled" handler to set correct tooltip. */
2578 toolbar_privacy_sign_toggled_cb(item, NULL);
2579 toolbar_data->privacy_sign_btn = item;
2580 break;
2581 case A_PRIVACY_ENCRYPT:
2582 TOOLBAR_TOGGLE_ITEM(item,icon_wid,toolbar_item->text,_("Encrypt"));
2583 g_signal_connect (G_OBJECT(item), "toggled",
2584 G_CALLBACK(toolbar_privacy_encrypt_toggled_cb), NULL);
2585 /* Call the "toggled" handler to set correct tooltip. */
2586 toolbar_privacy_encrypt_toggled_cb(item, NULL);
2587 toolbar_data->privacy_encrypt_btn = item;
2588 break;
2590 case A_CLAWS_ACTIONS:
2591 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,toolbar_item->text);
2592 action_item = g_new0(ToolbarClawsActions, 1);
2593 action_item->widget = item;
2594 action_item->name = g_strdup(toolbar_item->text);
2596 toolbar_data->action_list =
2597 g_slist_append(toolbar_data->action_list,
2598 action_item);
2599 break;
2600 case A_CANCEL_INC:
2601 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving"));
2602 toolbar_data->cancel_inc_btn = item;
2603 break;
2604 case A_CANCEL_SEND:
2605 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel sending"));
2606 toolbar_data->cancel_send_btn = item;
2607 break;
2608 case A_CANCEL_ALL:
2609 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,_("Cancel receiving/sending"));
2610 toolbar_data->cancel_all_btn = item;
2611 break;
2612 case A_CLAWS_PLUGINS:
2613 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text, toolbar_item->text);
2614 break;
2615 default:
2616 TOOLBAR_ITEM(item,icon_wid,toolbar_item->text,
2617 toolbar_ret_descr_from_val(toolbar_item->index));
2618 /* find and set the tool tip text */
2619 break;
2623 toolbar_data->toolbar = toolbar;
2625 gtk_widget_show_all(toolbar);
2627 if (type == TOOLBAR_MAIN) {
2628 #ifdef GENERIC_UMPC
2629 MainWindow *mainwin = mainwindow_get_mainwindow();
2630 GtkWidget *progressbar = gtk_progress_bar_new();
2631 item = GTK_WIDGET(gtk_tool_item_new());
2632 gtk_container_add (GTK_CONTAINER (item), progressbar);
2633 gtk_widget_show(item);
2634 gtk_widget_set_size_request(progressbar, 84, -1);
2635 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), GTK_TOOL_ITEM(item), -1);
2636 mainwin->progressbar = progressbar;
2637 #endif
2638 activate_compose_button(toolbar_data,
2639 prefs_common.toolbar_style,
2640 toolbar_data->compose_btn_type);
2642 if (type != TOOLBAR_COMPOSE)
2643 activate_learn_button(toolbar_data, prefs_common.toolbar_style,
2644 LEARN_SPAM);
2646 gtk_container_add(GTK_CONTAINER(container), toolbar);
2647 gtk_container_set_border_width(GTK_CONTAINER(container), 0);
2649 return toolbar_data;
2653 * Free toolbar structures
2656 #define UNREF_ICON(icon) if (toolbar->icon != NULL) \
2657 g_object_unref(toolbar->icon)
2659 void toolbar_destroy(Toolbar * toolbar)
2661 UNREF_ICON(compose_mail_icon);
2662 UNREF_ICON(compose_news_icon);
2663 UNREF_ICON(learn_spam_icon);
2664 UNREF_ICON(learn_ham_icon);
2665 TOOLBAR_DESTROY_ITEMS(toolbar->item_list);
2666 TOOLBAR_DESTROY_ACTIONS(toolbar->action_list);
2669 #undef UNREF_ICON
2671 void toolbar_item_destroy(ToolbarItem *item)
2673 cm_return_if_fail(item != NULL);
2675 if (item->file)
2676 g_free(item->file);
2677 if (item->text)
2678 g_free(item->text);
2679 g_free(item);
2682 void toolbar_update(ToolbarType type, gpointer data)
2684 Toolbar *toolbar_data;
2685 GtkWidget *handlebox;
2686 MainWindow *mainwin = (MainWindow*)data;
2687 Compose *compose = (Compose*)data;
2688 MessageView *msgview = (MessageView*)data;
2690 #ifndef GENERIC_UMPC
2691 switch(type) {
2692 case TOOLBAR_MAIN:
2693 toolbar_data = mainwin->toolbar;
2694 handlebox = mainwin->handlebox;
2695 break;
2696 case TOOLBAR_COMPOSE:
2697 toolbar_data = compose->toolbar;
2698 handlebox = compose->handlebox;
2699 break;
2700 case TOOLBAR_MSGVIEW:
2701 toolbar_data = msgview->toolbar;
2702 handlebox = msgview->handlebox;
2703 break;
2704 default:
2705 return;
2708 gtk_container_remove(GTK_CONTAINER(handlebox),
2709 GTK_WIDGET(toolbar_data->toolbar));
2711 toolbar_init(toolbar_data);
2712 toolbar_data = toolbar_create(type, handlebox, data);
2713 #else
2714 switch(type) {
2715 case TOOLBAR_MAIN:
2716 toolbar_data = mainwin->toolbar;
2717 handlebox = mainwin->window;
2718 break;
2719 case TOOLBAR_COMPOSE:
2720 toolbar_data = compose->toolbar;
2721 handlebox = compose->window;
2722 break;
2723 case TOOLBAR_MSGVIEW:
2724 toolbar_data = msgview->toolbar;
2725 handlebox = msgview->window;
2726 break;
2727 default:
2728 return;
2730 toolbar_init(toolbar_data);
2731 toolbar_data = toolbar_create(type, handlebox, data);
2732 #endif
2734 switch(type) {
2735 case TOOLBAR_MAIN:
2736 mainwin->toolbar = toolbar_data;
2737 break;
2738 case TOOLBAR_COMPOSE:
2739 compose->toolbar = toolbar_data;
2740 break;
2741 case TOOLBAR_MSGVIEW:
2742 msgview->toolbar = toolbar_data;
2743 break;
2746 toolbar_style(type, prefs_common.toolbar_style, data);
2748 if (type == TOOLBAR_MAIN) {
2749 toolbar_main_set_sensitive((MainWindow*)data);
2750 account_set_menu_only_toolbar();
2754 #define GTK_BUTTON_SET_SENSITIVE(widget,sensitive) { \
2755 gtk_widget_set_sensitive(widget, sensitive); \
2758 void toolbar_main_set_sensitive(gpointer data)
2760 SensitiveCondMask state;
2761 gboolean sensitive;
2762 MainWindow *mainwin = (MainWindow*)data;
2763 Toolbar *toolbar = mainwin->toolbar;
2764 GSList *cur;
2765 GSList *entry_list = NULL;
2767 typedef struct _Entry Entry;
2768 struct _Entry {
2769 GtkWidget *widget;
2770 SensitiveCondMask cond;
2771 gboolean empty;
2774 #define SET_WIDGET_COND(w, ...) \
2775 do { \
2776 Entry *e = g_new0(Entry, 1); \
2777 e->widget = w; \
2778 e->cond = main_window_get_mask(__VA_ARGS__, -1); \
2779 entry_list = g_slist_append(entry_list, e); \
2780 } while (0)
2782 /* match all bit flags */
2784 if (toolbar->get_btn)
2785 SET_WIDGET_COND(toolbar->get_btn,
2786 M_HAVE_ACCOUNT, M_UNLOCKED, M_HAVE_RETRIEVABLE_ACCOUNT);
2788 if (toolbar->getall_btn) {
2789 SET_WIDGET_COND(toolbar->getall_btn,
2790 M_HAVE_ACCOUNT, M_UNLOCKED, M_HAVE_ANY_RETRIEVABLE_ACCOUNT);
2792 if (toolbar->send_btn) {
2793 SET_WIDGET_COND(toolbar->send_btn,
2794 M_HAVE_QUEUED_MAILS);
2796 if (toolbar->compose_mail_btn) {
2797 SET_WIDGET_COND(toolbar->compose_mail_btn,
2798 M_HAVE_ACCOUNT);
2800 if (toolbar->close_window_btn) {
2801 SET_WIDGET_COND(toolbar->close_window_btn,
2802 M_UNLOCKED);
2804 if (toolbar->open_mail_btn) {
2805 SET_WIDGET_COND(toolbar->open_mail_btn,
2806 M_TARGET_EXIST, M_SUMMARY_ISLIST);
2808 if (toolbar->reply_btn) {
2809 SET_WIDGET_COND(toolbar->reply_btn,
2810 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2812 if (toolbar->replyall_btn) {
2813 SET_WIDGET_COND(toolbar->replyall_btn,
2814 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2816 if (toolbar->replylist_btn) {
2817 SET_WIDGET_COND(toolbar->replylist_btn,
2818 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2820 if (toolbar->replysender_btn) {
2821 SET_WIDGET_COND(toolbar->replysender_btn,
2822 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2824 if (toolbar->fwd_btn) {
2825 SET_WIDGET_COND(toolbar->fwd_btn,
2826 M_HAVE_ACCOUNT, M_TARGET_EXIST, M_SUMMARY_ISLIST);
2829 if (prefs_common.next_unread_msg_dialog == NEXTUNREADMSGDIALOG_ASSUME_NO) {
2830 SET_WIDGET_COND(toolbar->next_btn, M_MSG_EXIST, M_SUMMARY_ISLIST);
2831 } else {
2832 SET_WIDGET_COND(toolbar->next_btn, -1);
2835 if (toolbar->trash_btn)
2836 SET_WIDGET_COND(toolbar->trash_btn,
2837 M_TARGET_EXIST, M_ALLOW_DELETE, M_NOT_NEWS);
2839 if (toolbar->delete_btn)
2840 SET_WIDGET_COND(toolbar->delete_btn,
2841 M_TARGET_EXIST, M_ALLOW_DELETE);
2843 if (toolbar->delete_dup_btn)
2844 SET_WIDGET_COND(toolbar->delete_dup_btn,
2845 M_MSG_EXIST, M_ALLOW_DELETE, M_SUMMARY_ISLIST);
2847 if (toolbar->exec_btn)
2848 SET_WIDGET_COND(toolbar->exec_btn,
2849 M_DELAY_EXEC);
2851 if (toolbar->learn_spam_btn)
2852 SET_WIDGET_COND(toolbar->learn_spam_btn,
2853 M_TARGET_EXIST, M_CAN_LEARN_SPAM, M_SUMMARY_ISLIST);
2855 if (toolbar->cancel_inc_btn)
2856 SET_WIDGET_COND(toolbar->cancel_inc_btn,
2857 M_INC_ACTIVE);
2859 if (toolbar->cancel_send_btn)
2860 SET_WIDGET_COND(toolbar->cancel_send_btn,
2861 M_SEND_ACTIVE);
2863 for (cur = toolbar->action_list; cur != NULL; cur = cur->next) {
2864 ToolbarClawsActions *act = (ToolbarClawsActions*)cur->data;
2866 SET_WIDGET_COND(act->widget, M_TARGET_EXIST, M_UNLOCKED);
2869 state = main_window_get_current_state(mainwin);
2871 for (cur = entry_list; cur != NULL; cur = cur->next) {
2872 Entry *e = (Entry*) cur->data;
2874 if (e->widget != NULL) {
2875 sensitive = ((e->cond & state) == e->cond);
2876 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2880 while (entry_list != NULL) {
2881 Entry *e = (Entry*) entry_list->data;
2883 entry_list = g_slist_remove(entry_list, e);
2884 g_free(e);
2887 /* match any bit flags */
2889 if (toolbar->cancel_all_btn)
2890 SET_WIDGET_COND(toolbar->cancel_all_btn,
2891 M_INC_ACTIVE, M_SEND_ACTIVE);
2893 for (cur = entry_list; cur != NULL; cur = cur->next) {
2894 Entry *e = (Entry*) cur->data;
2896 if (e->widget != NULL) {
2897 sensitive = ((e->cond & state) != 0);
2898 GTK_BUTTON_SET_SENSITIVE(e->widget, sensitive);
2902 while (entry_list != NULL) {
2903 Entry *e = (Entry*) entry_list->data;
2905 entry_list = g_slist_remove(entry_list, e);
2906 g_free(e);
2909 g_slist_free(entry_list);
2911 activate_compose_button(toolbar,
2912 prefs_common.toolbar_style,
2913 toolbar->compose_btn_type);
2915 #undef SET_WIDGET_COND
2918 void toolbar_comp_set_sensitive(gpointer data, gboolean sensitive)
2920 Compose *compose = (Compose*)data;
2921 GSList *items = compose->toolbar->action_list;
2923 if (compose->toolbar->send_btn)
2924 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->send_btn, sensitive);
2925 if (compose->toolbar->sendl_btn)
2926 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sendl_btn, sensitive);
2927 if (compose->toolbar->draft_btn )
2928 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->draft_btn , sensitive);
2929 if (compose->toolbar->insert_btn )
2930 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->insert_btn , sensitive);
2931 if (compose->toolbar->attach_btn)
2932 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->attach_btn, sensitive);
2933 if (compose->toolbar->sig_btn)
2934 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->sig_btn, sensitive);
2935 if (compose->toolbar->repsig_btn)
2936 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->repsig_btn, sensitive);
2937 if (compose->toolbar->exteditor_btn)
2938 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->exteditor_btn, sensitive);
2939 if (compose->toolbar->linewrap_current_btn)
2940 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_current_btn, sensitive);
2941 if (compose->toolbar->linewrap_all_btn)
2942 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->linewrap_all_btn, sensitive);
2943 if (compose->toolbar->addrbook_btn)
2944 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->addrbook_btn, sensitive);
2945 #ifdef USE_ENCHANT
2946 if (compose->toolbar->spellcheck_btn)
2947 GTK_BUTTON_SET_SENSITIVE(compose->toolbar->spellcheck_btn, sensitive);
2948 #endif
2949 for (; items != NULL; items = g_slist_next(items)) {
2950 ToolbarClawsActions *item = (ToolbarClawsActions *)items->data;
2951 GTK_BUTTON_SET_SENSITIVE(item->widget, sensitive);
2956 * Initialize toolbar structure
2958 static void toolbar_init(Toolbar * toolbar)
2961 toolbar->toolbar = NULL;
2962 toolbar->folders_btn = NULL;
2963 toolbar->get_btn = NULL;
2964 toolbar->getall_btn = NULL;
2965 toolbar->send_btn = NULL;
2966 toolbar->compose_mail_btn = NULL;
2967 toolbar->compose_mail_icon = NULL;
2968 toolbar->compose_news_icon = NULL;
2969 toolbar->reply_btn = NULL;
2970 toolbar->replysender_btn = NULL;
2971 toolbar->replyall_btn = NULL;
2972 toolbar->replylist_btn = NULL;
2973 toolbar->fwd_btn = NULL;
2974 toolbar->trash_btn = NULL;
2975 toolbar->delete_btn = NULL;
2976 toolbar->delete_dup_btn = NULL;
2977 toolbar->prev_btn = NULL;
2978 toolbar->next_btn = NULL;
2979 toolbar->exec_btn = NULL;
2980 toolbar->separator = NULL;
2981 toolbar->learn_spam_btn = NULL;
2982 toolbar->learn_spam_icon = NULL;
2983 toolbar->learn_ham_icon = NULL;
2984 toolbar->cancel_inc_btn = NULL;
2985 toolbar->cancel_send_btn = NULL;
2986 toolbar->cancel_all_btn = NULL;
2988 /* compose buttons */
2989 toolbar->sendl_btn = NULL;
2990 toolbar->draft_btn = NULL;
2991 toolbar->insert_btn = NULL;
2992 toolbar->attach_btn = NULL;
2993 toolbar->sig_btn = NULL;
2994 toolbar->repsig_btn = NULL;
2995 toolbar->exteditor_btn = NULL;
2996 toolbar->linewrap_current_btn = NULL;
2997 toolbar->linewrap_all_btn = NULL;
2998 toolbar->addrbook_btn = NULL;
3000 toolbar->open_mail_btn = NULL;
3001 toolbar->close_window_btn = NULL;
3002 toolbar->preferences_btn = NULL;
3003 toolbar->action_list = NULL;
3004 toolbar->item_list = NULL;
3005 #ifdef USE_ENCHANT
3006 toolbar->spellcheck_btn = NULL;
3007 #endif
3009 toolbar->privacy_sign_btn = NULL;
3010 toolbar->privacy_encrypt_btn = NULL;
3012 toolbar_destroy(toolbar);
3017 static void toolbar_reply(gpointer data, guint action)
3019 ToolbarItem *toolbar_item = (ToolbarItem*)data;
3020 MainWindow *mainwin;
3021 MessageView *msgview;
3022 GSList *msginfo_list = NULL;
3023 gboolean msg_is_selected = FALSE;
3024 gboolean msg_is_opened = FALSE;
3026 cm_return_if_fail(toolbar_item != NULL);
3028 switch (toolbar_item->type) {
3029 case TOOLBAR_MAIN:
3030 mainwin = (MainWindow*)toolbar_item->parent;
3031 msginfo_list = summary_get_selection(mainwin->summaryview);
3032 msgview = (MessageView*)mainwin->messageview;
3033 msg_is_opened = summary_has_opened_message(mainwin->summaryview);
3034 msg_is_selected = summary_is_opened_message_selected(mainwin->summaryview);
3035 break;
3036 case TOOLBAR_MSGVIEW:
3037 msgview = (MessageView*)toolbar_item->parent;
3038 cm_return_if_fail(msgview != NULL);
3039 msginfo_list = g_slist_append(msginfo_list, msgview->msginfo);
3040 msg_is_opened = TRUE;
3041 msg_is_selected = TRUE;
3042 break;
3043 default:
3044 return;
3047 cm_return_if_fail(msgview != NULL);
3048 cm_return_if_fail(msginfo_list != NULL);
3049 if (!msg_is_opened) {
3050 compose_reply_from_messageview(NULL, msginfo_list, action);
3051 } else if (msg_is_selected) {
3052 compose_reply_from_messageview(msgview, msginfo_list, action);
3053 } else {
3054 compose_reply_from_messageview(msgview, NULL, action);
3056 g_slist_free(msginfo_list);
3058 /* TODO: update reply state ion summaryview */
3062 /* exported functions */
3064 void inc_mail_cb(gpointer data, guint action, GtkWidget *widget)
3066 MainWindow *mainwin = (MainWindow*)data;
3068 inc_mail(mainwin, prefs_common.newmail_notify_manu);
3071 void inc_all_account_mail_cb(gpointer data, guint action, GtkWidget *widget)
3073 MainWindow *mainwin = (MainWindow*)data;
3075 inc_all_account_mail(mainwin, FALSE, FALSE, prefs_common.newmail_notify_manu);
3078 void send_queue_cb(gpointer data, guint action, GtkWidget *widget)
3080 GList *list;
3081 gboolean found;
3082 gboolean got_error = FALSE;
3083 gchar *errstr = NULL;
3085 if (prefs_common.work_offline)
3086 if (alertpanel(_("Offline warning"),
3087 _("You're working offline. Override?"),
3088 NULL, _("_No"), NULL, _("_Yes"),
3089 NULL, NULL, ALERTFOCUS_FIRST) != G_ALERTALTERNATE)
3090 return;
3092 /* ask for confirmation before sending queued messages only
3093 in online mode and if there is at least one message queued
3094 in any of the folder queue
3096 if (prefs_common.confirm_send_queued_messages) {
3097 found = FALSE;
3098 /* check if there's a queued message */
3099 for (list = folder_get_list(); !found && list != NULL; list = list->next) {
3100 Folder *folder = list->data;
3102 found = !procmsg_queue_is_empty(folder->queue);
3104 /* if necessary, ask for confirmation before sending */
3105 if (found && !prefs_common.work_offline) {
3106 if (alertpanel(_("Send queued messages"),
3107 _("Send all queued messages?"),
3108 NULL, _("_Cancel"), NULL, _("_Send"),
3109 NULL, NULL, ALERTFOCUS_FIRST) != G_ALERTALTERNATE)
3110 return;
3114 for (list = folder_get_list(); list != NULL; list = list->next) {
3115 Folder *folder = list->data;
3117 if (folder->queue) {
3118 if (procmsg_send_queue(folder->queue,
3119 prefs_common.savemsg,
3120 &errstr) < 0)
3121 got_error = TRUE;
3124 if (got_error) {
3125 if (!errstr)
3126 alertpanel_error_log(_("Some errors occurred while "
3127 "sending queued messages."));
3128 else {
3129 alertpanel_error_log(_("Some errors occurred "
3130 "while sending queued messages:\n%s"), errstr);
3131 g_free(errstr);
3136 void compose_mail_cb(gpointer data, guint action, GtkWidget *widget)
3138 MainWindow *mainwin = (MainWindow*)data;
3139 PrefsAccount *ac = NULL;
3140 FolderItem *item = mainwin->summaryview->folder_item;
3141 GList * list;
3142 GList * cur;
3144 if (item) {
3145 ac = account_find_from_item(item);
3146 if (ac && ac->protocol != A_NNTP && ac->protocol != A_IMAP4) {
3147 compose_new_with_folderitem(ac, item, NULL); /* CLAWS */
3148 return;
3153 * CLAWS - use current account
3155 if (cur_account && (cur_account->protocol != A_NNTP)) {
3156 compose_new_with_folderitem(cur_account, item, NULL);
3157 return;
3161 * CLAWS - just get the first one
3163 list = account_get_list();
3164 for (cur = list ; cur != NULL ; cur = g_list_next(cur)) {
3165 ac = (PrefsAccount *) cur->data;
3166 if (ac->protocol != A_NNTP) {
3167 compose_new_with_folderitem(ac, item, NULL);
3168 return;
3173 void compose_news_cb(gpointer data, guint action, GtkWidget *widget)
3175 MainWindow *mainwin = (MainWindow*)data;
3176 PrefsAccount * ac = NULL;
3177 GList * list;
3178 GList * cur;
3180 if (mainwin->summaryview->folder_item) {
3181 ac = mainwin->summaryview->folder_item->folder->account;
3182 if (ac && ac->protocol == A_NNTP) {
3183 compose_new_with_folderitem(ac,
3184 mainwin->summaryview->folder_item, NULL);
3185 return;
3189 list = account_get_list();
3190 for(cur = list ; cur != NULL ; cur = g_list_next(cur)) {
3191 ac = (PrefsAccount *) cur->data;
3192 if (ac->protocol == A_NNTP) {
3193 compose_new_with_folderitem(ac,
3194 mainwin->summaryview->folder_item, NULL);
3195 return;