Statistics
| Revision:

root / src / messageview.c @ 2821

History | View | Annotate | Download (29 kB)

1 1 hiro
/*
2 1 hiro
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 2042 hiro
 * Copyright (C) 1999-2008 Hiroyuki Yamamoto
4 1 hiro
 *
5 1 hiro
 * This program is free software; you can redistribute it and/or modify
6 1 hiro
 * it under the terms of the GNU General Public License as published by
7 1 hiro
 * the Free Software Foundation; either version 2 of the License, or
8 1 hiro
 * (at your option) any later version.
9 1 hiro
 *
10 1 hiro
 * This program is distributed in the hope that it will be useful,
11 1 hiro
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 1 hiro
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 1 hiro
 * GNU General Public License for more details.
14 1 hiro
 *
15 1 hiro
 * You should have received a copy of the GNU General Public License
16 1 hiro
 * along with this program; if not, write to the Free Software
17 1 hiro
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 1 hiro
 */
19 1 hiro
20 1 hiro
#include "defs.h"
21 1 hiro
22 1 hiro
#include <glib.h>
23 92 hiro
#include <glib/gi18n.h>
24 1 hiro
#include <gdk/gdkkeysyms.h>
25 154 hiro
#include <gtk/gtknotebook.h>
26 1 hiro
#include <gtk/gtkvbox.h>
27 1 hiro
#include <gtk/gtkcontainer.h>
28 1 hiro
#include <gtk/gtkwindow.h>
29 1 hiro
#include <gtk/gtktextview.h>
30 1 hiro
#include <gtk/gtkmenu.h>
31 1 hiro
#include <gtk/gtkmenuitem.h>
32 237 hiro
#include <gtk/gtkcheckmenuitem.h>
33 237 hiro
#include <gtk/gtkstatusbar.h>
34 1 hiro
#include <stdio.h>
35 1 hiro
#include <ctype.h>
36 1 hiro
#include <string.h>
37 1 hiro
38 1 hiro
#include "main.h"
39 1 hiro
#include "messageview.h"
40 1 hiro
#include "message_search.h"
41 1 hiro
#include "headerview.h"
42 1 hiro
#include "textview.h"
43 1 hiro
#include "imageview.h"
44 1 hiro
#include "mimeview.h"
45 1 hiro
#include "menu.h"
46 1 hiro
#include "about.h"
47 1 hiro
#include "filesel.h"
48 1 hiro
#include "sourcewindow.h"
49 1 hiro
#include "addressbook.h"
50 1 hiro
#include "alertpanel.h"
51 1 hiro
#include "inputdialog.h"
52 1 hiro
#include "manage_window.h"
53 1386 hiro
#include "printing.h"
54 1 hiro
#include "procmsg.h"
55 1 hiro
#include "procheader.h"
56 1 hiro
#include "procmime.h"
57 1 hiro
#include "account.h"
58 1 hiro
#include "action.h"
59 1 hiro
#include "prefs_common.h"
60 1 hiro
#include "prefs_account.h"
61 1 hiro
#include "prefs_filter.h"
62 547 hiro
#include "filter.h"
63 1 hiro
#include "gtkutils.h"
64 1 hiro
#include "utils.h"
65 1 hiro
#include "rfc2015.h"
66 1 hiro
67 1 hiro
static GList *messageview_list = NULL;
68 1 hiro
69 154 hiro
static void messageview_change_view_type(MessageView                *messageview,
70 154 hiro
                                         MessageType                 type);
71 976 hiro
static void messageview_set_menu_state        (MessageView                *messageview);
72 976 hiro
73 1399 hiro
static void messageview_set_encoding_menu
74 1399 hiro
                                        (MessageView                *messageview);
75 1399 hiro
76 316 hiro
static gint messageview_delete_cb        (GtkWidget                *widget,
77 316 hiro
                                         GdkEventAny                *event,
78 154 hiro
                                         MessageView                *messageview);
79 154 hiro
static void messageview_size_allocate_cb(GtkWidget                *widget,
80 154 hiro
                                         GtkAllocation                *allocation);
81 154 hiro
static void messageview_switch_page_cb        (GtkNotebook                *notebook,
82 154 hiro
                                         GtkNotebookPage        *page,
83 154 hiro
                                         guint                         page_num,
84 154 hiro
                                         MessageView                *messageview);
85 154 hiro
static gboolean key_pressed                (GtkWidget                *widget,
86 154 hiro
                                         GdkEventKey                *event,
87 154 hiro
                                         MessageView                *messageview);
88 1 hiro
89 1 hiro
static void save_as_cb                        (gpointer         data,
90 1 hiro
                                         guint                 action,
91 1 hiro
                                         GtkWidget        *widget);
92 1420 hiro
#if GTK_CHECK_VERSION(2, 10, 0)
93 1420 hiro
static void page_setup_cb                (gpointer         data,
94 1420 hiro
                                         guint                 action,
95 1420 hiro
                                         GtkWidget        *widget);
96 1420 hiro
#endif
97 1 hiro
static void print_cb                        (gpointer         data,
98 1 hiro
                                         guint                 action,
99 1 hiro
                                         GtkWidget        *widget);
100 1 hiro
static void close_cb                        (gpointer         data,
101 1 hiro
                                         guint                 action,
102 1 hiro
                                         GtkWidget        *widget);
103 1 hiro
static void copy_cb                        (gpointer         data,
104 1 hiro
                                         guint                 action,
105 1 hiro
                                         GtkWidget        *widget);
106 1 hiro
static void allsel_cb                        (gpointer         data,
107 1 hiro
                                         guint                 action,
108 1 hiro
                                         GtkWidget        *widget);
109 1 hiro
static void search_cb                        (gpointer         data,
110 1 hiro
                                         guint                 action,
111 1 hiro
                                         GtkWidget        *widget);
112 1 hiro
113 1 hiro
static void set_charset_cb                (gpointer         data,
114 1 hiro
                                         guint                 action,
115 1 hiro
                                         GtkWidget        *widget);
116 1 hiro
static void view_source_cb                (gpointer         data,
117 1 hiro
                                         guint                 action,
118 1 hiro
                                         GtkWidget        *widget);
119 1 hiro
static void show_all_header_cb                (gpointer         data,
120 1 hiro
                                         guint                 action,
121 1 hiro
                                         GtkWidget        *widget);
122 1 hiro
123 1 hiro
static void compose_cb                        (gpointer         data,
124 1 hiro
                                         guint                 action,
125 1 hiro
                                         GtkWidget        *widget);
126 1 hiro
static void reply_cb                        (gpointer         data,
127 1 hiro
                                         guint                 action,
128 1 hiro
                                         GtkWidget        *widget);
129 1 hiro
static void reedit_cb                        (gpointer         data,
130 1 hiro
                                         guint                 action,
131 1 hiro
                                         GtkWidget        *widget);
132 1 hiro
133 1 hiro
static void addressbook_open_cb                (gpointer         data,
134 1 hiro
                                         guint                 action,
135 1 hiro
                                         GtkWidget        *widget);
136 1 hiro
static void add_address_cb                (gpointer         data,
137 1 hiro
                                         guint                 action,
138 1 hiro
                                         GtkWidget        *widget);
139 1 hiro
static void create_filter_cb                (gpointer         data,
140 1 hiro
                                         guint                 action,
141 1 hiro
                                         GtkWidget        *widget);
142 1 hiro
143 1 hiro
static void about_cb                        (gpointer         data,
144 1 hiro
                                         guint                 action,
145 1 hiro
                                         GtkWidget        *widget);
146 1 hiro
147 1 hiro
static GtkItemFactoryEntry msgview_entries[] =
148 1 hiro
{
149 1 hiro
        {N_("/_File"),                        NULL, NULL, 0, "<Branch>"},
150 1 hiro
        {N_("/_File/_Save as..."),        NULL, save_as_cb, 0, NULL},
151 1420 hiro
        {N_("/_File/---"),                NULL, NULL, 0, "<Separator>"},
152 1420 hiro
#if GTK_CHECK_VERSION(2, 10, 0)
153 1420 hiro
        {N_("/_File/Page set_up..."),        NULL, page_setup_cb, 0, NULL},
154 1420 hiro
#endif
155 1 hiro
        {N_("/_File/_Print..."),        NULL, print_cb, 0, NULL},
156 1 hiro
        {N_("/_File/---"),                NULL, NULL, 0, "<Separator>"},
157 1 hiro
        {N_("/_File/_Close"),                NULL, close_cb, 0, NULL},
158 1 hiro
159 1 hiro
        {N_("/_Edit"),                        NULL, NULL, 0, "<Branch>"},
160 1 hiro
        {N_("/_Edit/_Copy"),                NULL, copy_cb, 0, NULL},
161 1 hiro
        {N_("/_Edit/Select _all"),        NULL, allsel_cb, 0, NULL},
162 1 hiro
        {N_("/_Edit/---"),                NULL, NULL, 0, "<Separator>"},
163 1 hiro
        {N_("/_Edit/_Find in current message..."),
164 1 hiro
                                        NULL, search_cb, 0, NULL},
165 1 hiro
166 1 hiro
        {N_("/_View"),                        NULL, NULL, 0, "<Branch>"},
167 1 hiro
168 175 hiro
#define ENC_SEPARATOR \
169 175 hiro
        {N_("/_View/Character _encoding/---"),        NULL, NULL, 0, "<Separator>"}
170 175 hiro
#define ENC_ACTION(action) \
171 175 hiro
        NULL, set_charset_cb, action, "/View/Character encoding/Auto detect"
172 1 hiro
173 175 hiro
        {N_("/_View/Character _encoding"),        NULL, NULL, 0, "<Branch>"},
174 175 hiro
        {N_("/_View/Character _encoding/_Auto detect"),
175 1 hiro
                                        NULL, set_charset_cb, C_AUTO, "<RadioItem>"},
176 175 hiro
        ENC_SEPARATOR,
177 175 hiro
        {N_("/_View/Character _encoding/7bit ascii (US-ASC_II)"),
178 175 hiro
         ENC_ACTION(C_US_ASCII)},
179 1 hiro
180 175 hiro
        {N_("/_View/Character _encoding/Unicode (_UTF-8)"),
181 175 hiro
         ENC_ACTION(C_UTF_8)},
182 175 hiro
        ENC_SEPARATOR,
183 175 hiro
        {N_("/_View/Character _encoding/Western European (ISO-8859-_1)"),
184 175 hiro
         ENC_ACTION(C_ISO_8859_1)},
185 175 hiro
        {N_("/_View/Character _encoding/Western European (ISO-8859-15)"),
186 175 hiro
         ENC_ACTION(C_ISO_8859_15)},
187 864 hiro
        {N_("/_View/Character _encoding/Western European (Windows-1252)"),
188 864 hiro
         ENC_ACTION(C_WINDOWS_1252)},
189 175 hiro
        ENC_SEPARATOR,
190 175 hiro
        {N_("/_View/Character _encoding/Central European (ISO-8859-_2)"),
191 175 hiro
         ENC_ACTION(C_ISO_8859_2)},
192 175 hiro
        ENC_SEPARATOR,
193 175 hiro
        {N_("/_View/Character _encoding/_Baltic (ISO-8859-13)"),
194 175 hiro
         ENC_ACTION(C_ISO_8859_13)},
195 175 hiro
        {N_("/_View/Character _encoding/Baltic (ISO-8859-_4)"),
196 175 hiro
         ENC_ACTION(C_ISO_8859_4)},
197 1103 hiro
        {N_("/_View/Character _encoding/Baltic (Windows-1257)"),
198 1103 hiro
         ENC_ACTION(C_WINDOWS_1257)},
199 175 hiro
        ENC_SEPARATOR,
200 175 hiro
        {N_("/_View/Character _encoding/Greek (ISO-8859-_7)"),
201 175 hiro
         ENC_ACTION(C_ISO_8859_7)},
202 175 hiro
        ENC_SEPARATOR,
203 949 hiro
        {N_("/_View/Character _encoding/Arabic (ISO-8859-_6)"),
204 949 hiro
         ENC_ACTION(C_ISO_8859_6)},
205 949 hiro
        {N_("/_View/Character _encoding/Arabic (Windows-1256)"),
206 949 hiro
         ENC_ACTION(C_CP1256)},
207 949 hiro
        ENC_SEPARATOR,
208 312 hiro
        {N_("/_View/Character _encoding/Hebrew (ISO-8859-_8)"),
209 312 hiro
         ENC_ACTION(C_ISO_8859_8)},
210 312 hiro
        {N_("/_View/Character _encoding/Hebrew (Windows-1255)"),
211 312 hiro
         ENC_ACTION(C_CP1255)},
212 312 hiro
        ENC_SEPARATOR,
213 175 hiro
        {N_("/_View/Character _encoding/Turkish (ISO-8859-_9)"),
214 175 hiro
         ENC_ACTION(C_ISO_8859_9)},
215 175 hiro
        ENC_SEPARATOR,
216 175 hiro
        {N_("/_View/Character _encoding/Cyrillic (ISO-8859-_5)"),
217 175 hiro
         ENC_ACTION(C_ISO_8859_5)},
218 175 hiro
        {N_("/_View/Character _encoding/Cyrillic (KOI8-_R)"),
219 175 hiro
         ENC_ACTION(C_KOI8_R)},
220 175 hiro
        {N_("/_View/Character _encoding/Cyrillic (KOI8-U)"),
221 175 hiro
         ENC_ACTION(C_KOI8_U)},
222 175 hiro
        {N_("/_View/Character _encoding/Cyrillic (Windows-1251)"),
223 175 hiro
         ENC_ACTION(C_CP1251)},
224 175 hiro
        ENC_SEPARATOR,
225 175 hiro
        {N_("/_View/Character _encoding/Japanese (ISO-2022-_JP)"),
226 175 hiro
         ENC_ACTION(C_ISO_2022_JP)},
227 175 hiro
        {N_("/_View/Character _encoding/Japanese (ISO-2022-JP-2)"),
228 175 hiro
         ENC_ACTION(C_ISO_2022_JP_2)},
229 175 hiro
        {N_("/_View/Character _encoding/Japanese (_EUC-JP)"),
230 175 hiro
         ENC_ACTION(C_EUC_JP)},
231 175 hiro
        {N_("/_View/Character _encoding/Japanese (_Shift__JIS)"),
232 175 hiro
         ENC_ACTION(C_SHIFT_JIS)},
233 175 hiro
        ENC_SEPARATOR,
234 175 hiro
        {N_("/_View/Character _encoding/Simplified Chinese (_GB2312)"),
235 175 hiro
         ENC_ACTION(C_GB2312)},
236 211 hiro
        {N_("/_View/Character _encoding/Simplified Chinese (GBK)"),
237 211 hiro
         ENC_ACTION(C_GBK)},
238 175 hiro
        {N_("/_View/Character _encoding/Traditional Chinese (_Big5)"),
239 175 hiro
         ENC_ACTION(C_BIG5)},
240 175 hiro
        {N_("/_View/Character _encoding/Traditional Chinese (EUC-_TW)"),
241 175 hiro
         ENC_ACTION(C_EUC_TW)},
242 175 hiro
        {N_("/_View/Character _encoding/Chinese (ISO-2022-_CN)"),
243 175 hiro
         ENC_ACTION(C_ISO_2022_CN)},
244 175 hiro
        ENC_SEPARATOR,
245 175 hiro
        {N_("/_View/Character _encoding/Korean (EUC-_KR)"),
246 175 hiro
         ENC_ACTION(C_EUC_KR)},
247 175 hiro
        {N_("/_View/Character _encoding/Korean (ISO-2022-KR)"),
248 175 hiro
         ENC_ACTION(C_ISO_2022_KR)},
249 175 hiro
        ENC_SEPARATOR,
250 175 hiro
        {N_("/_View/Character _encoding/Thai (TIS-620)"),
251 175 hiro
         ENC_ACTION(C_TIS_620)},
252 175 hiro
        {N_("/_View/Character _encoding/Thai (Windows-874)"),
253 175 hiro
         ENC_ACTION(C_WINDOWS_874)},
254 1 hiro
255 175 hiro
#undef ENC_SEPARATOR
256 175 hiro
#undef ENC_ACTION
257 1 hiro
258 1 hiro
        {N_("/_View/---"),                NULL, NULL, 0, "<Separator>"},
259 1 hiro
        {N_("/_View/Mess_age source"),        NULL, view_source_cb, 0, NULL},
260 1147 hiro
        {N_("/_View/All _headers"),
261 1038 hiro
                                        NULL, show_all_header_cb, 0, "<ToggleItem>"},
262 1 hiro
263 1 hiro
        {N_("/_Message"),                NULL, NULL, 0, "<Branch>"},
264 1 hiro
        {N_("/_Message/Compose _new message"),
265 1 hiro
                                        NULL, compose_cb, 0, NULL},
266 1 hiro
        {N_("/_Message/---"),                NULL, NULL, 0, "<Separator>"},
267 1 hiro
        {N_("/_Message/_Reply"),        NULL, reply_cb, COMPOSE_REPLY, NULL},
268 1 hiro
        {N_("/_Message/Repl_y to/_all"),
269 1 hiro
                                        NULL, reply_cb, COMPOSE_REPLY_TO_ALL, NULL},
270 1 hiro
        {N_("/_Message/Repl_y to/_sender"),
271 1 hiro
                                        NULL, reply_cb, COMPOSE_REPLY_TO_SENDER, NULL},
272 1 hiro
        {N_("/_Message/Repl_y to/mailing _list"),
273 1 hiro
                                        NULL, reply_cb, COMPOSE_REPLY_TO_LIST, NULL},
274 1 hiro
        {N_("/_Message/---"),                NULL, NULL, 0, "<Separator>"},
275 1 hiro
        {N_("/_Message/_Forward"),        NULL, reply_cb, COMPOSE_FORWARD, NULL},
276 1 hiro
        {N_("/_Message/For_ward as attachment"),
277 1 hiro
                                        NULL, reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
278 1 hiro
        {N_("/_Message/Redirec_t"),        NULL, reply_cb, COMPOSE_REDIRECT, NULL},
279 1 hiro
        {N_("/_Message/---"),                NULL, NULL, 0, "<Separator>"},
280 1 hiro
        {N_("/_Message/Re-_edit"),        NULL, reedit_cb, 0, NULL},
281 1 hiro
282 1 hiro
        {N_("/_Tools"),                        NULL, NULL, 0, "<Branch>"},
283 1 hiro
        {N_("/_Tools/_Address book"),        NULL, addressbook_open_cb, 0, NULL},
284 1 hiro
        {N_("/_Tools/Add sender to address boo_k"),
285 1 hiro
                                        NULL, add_address_cb, 0, NULL},
286 1 hiro
        {N_("/_Tools/---"),                NULL, NULL, 0, "<Separator>"},
287 1 hiro
        {N_("/_Tools/_Create filter rule"),
288 1 hiro
                                        NULL, NULL, 0, "<Branch>"},
289 1 hiro
        {N_("/_Tools/_Create filter rule/_Automatically"),
290 547 hiro
                                        NULL, create_filter_cb, FLT_BY_AUTO, NULL},
291 1 hiro
        {N_("/_Tools/_Create filter rule/by _From"),
292 547 hiro
                                        NULL, create_filter_cb, FLT_BY_FROM, NULL},
293 1 hiro
        {N_("/_Tools/_Create filter rule/by _To"),
294 547 hiro
                                        NULL, create_filter_cb, FLT_BY_TO, NULL},
295 1 hiro
        {N_("/_Tools/_Create filter rule/by _Subject"),
296 547 hiro
                                        NULL, create_filter_cb, FLT_BY_SUBJECT, NULL},
297 952 hiro
#ifndef G_OS_WIN32
298 1 hiro
        {N_("/_Tools/---"),                NULL, NULL, 0, "<Separator>"},
299 1 hiro
        {N_("/_Tools/Actio_ns"),        NULL, NULL, 0, "<Branch>"},
300 952 hiro
#endif
301 1 hiro
302 1 hiro
        {N_("/_Help"),                        NULL, NULL, 0, "<Branch>"},
303 1 hiro
        {N_("/_Help/_About"),                NULL, about_cb, 0, NULL}
304 1 hiro
};
305 1 hiro
306 1 hiro
307 1 hiro
MessageView *messageview_create(void)
308 1 hiro
{
309 1 hiro
        MessageView *messageview;
310 1 hiro
        GtkWidget *vbox;
311 154 hiro
        GtkWidget *notebook;
312 1 hiro
        HeaderView *headerview;
313 1 hiro
        TextView *textview;
314 1 hiro
        MimeView *mimeview;
315 1 hiro
316 1 hiro
        debug_print(_("Creating message view...\n"));
317 1 hiro
        messageview = g_new0(MessageView, 1);
318 1 hiro
319 1 hiro
        messageview->type = MVIEW_TEXT;
320 1 hiro
321 1 hiro
        headerview = headerview_create();
322 1 hiro
323 1 hiro
        textview = textview_create();
324 1 hiro
        textview->messageview = messageview;
325 1 hiro
326 1 hiro
        mimeview = mimeview_create();
327 1 hiro
        mimeview->textview = textview_create();
328 1 hiro
        mimeview->textview->messageview = messageview;
329 1 hiro
        mimeview->imageview = imageview_create();
330 1 hiro
        mimeview->imageview->messageview = messageview;
331 1 hiro
        mimeview->messageview = messageview;
332 1 hiro
333 154 hiro
        notebook = gtk_notebook_new();
334 154 hiro
        gtk_notebook_set_show_border(GTK_NOTEBOOK(notebook), FALSE);
335 154 hiro
        gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
336 154 hiro
        gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE);
337 154 hiro
        gtk_widget_show(notebook);
338 154 hiro
339 154 hiro
        gtk_container_add(GTK_CONTAINER(notebook), GTK_WIDGET_PTR(textview));
340 154 hiro
        gtk_notebook_set_tab_label_text
341 154 hiro
                (GTK_NOTEBOOK(notebook), GTK_WIDGET_PTR(textview), _("Text"));
342 154 hiro
343 154 hiro
        gtk_container_add(GTK_CONTAINER(notebook), GTK_WIDGET_PTR(mimeview));
344 154 hiro
        gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(notebook),
345 154 hiro
                                        GTK_WIDGET_PTR(mimeview),
346 154 hiro
                                        _("Attachments"));
347 154 hiro
348 154 hiro
        gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
349 154 hiro
        gtk_widget_show_all(notebook);
350 154 hiro
351 1 hiro
        vbox = gtk_vbox_new(FALSE, 0);
352 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
353 1 hiro
                           FALSE, FALSE, 0);
354 154 hiro
        gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
355 1 hiro
        gtk_widget_show(vbox);
356 1 hiro
357 1 hiro
        /* to remove without destroyed */
358 1 hiro
        gtk_widget_ref(GTK_WIDGET_PTR(mimeview->textview));
359 1 hiro
        gtk_widget_ref(GTK_WIDGET_PTR(mimeview->imageview));
360 1 hiro
361 154 hiro
        g_signal_connect(G_OBJECT(notebook), "switch_page",
362 154 hiro
                         G_CALLBACK(messageview_switch_page_cb), messageview);
363 154 hiro
364 1 hiro
        messageview->vbox        = vbox;
365 154 hiro
        messageview->notebook    = notebook;
366 154 hiro
367 1 hiro
        messageview->new_window  = FALSE;
368 1 hiro
        messageview->window      = NULL;
369 1 hiro
        messageview->window_vbox = NULL;
370 154 hiro
        messageview->body_vbox   = NULL;
371 154 hiro
372 1 hiro
        messageview->headerview  = headerview;
373 1 hiro
        messageview->textview    = textview;
374 1 hiro
        messageview->mimeview    = mimeview;
375 1 hiro
376 1 hiro
        messageview->statusbar     = NULL;
377 1 hiro
        messageview->statusbar_cid = 0;
378 1 hiro
379 154 hiro
        messageview->current_page = 0;
380 154 hiro
381 1 hiro
        return messageview;
382 1 hiro
}
383 1 hiro
384 1 hiro
MessageView *messageview_create_with_new_window(void)
385 1 hiro
{
386 1 hiro
        MessageView *msgview;
387 1 hiro
        GtkWidget *window;
388 1 hiro
        GtkWidget *window_vbox;
389 1 hiro
        GtkWidget *body_vbox;
390 1227 hiro
        GtkWidget *vspacer;
391 1 hiro
        GtkWidget *menubar;
392 1 hiro
        GtkItemFactory *ifactory;
393 1 hiro
        GtkWidget *statusbar;
394 1 hiro
        guint n_menu_entries;
395 1 hiro
396 1 hiro
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
397 676 hiro
        gtk_window_set_title(GTK_WINDOW(window), _("Message View - Sylpheed"));
398 1 hiro
        gtk_window_set_wmclass(GTK_WINDOW(window), "message_view", "Sylpheed");
399 1 hiro
        gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
400 1 hiro
        gtk_widget_set_size_request(window, prefs_common.msgwin_width,
401 1 hiro
                                    prefs_common.msgwin_height);
402 1 hiro
403 1 hiro
        msgview = messageview_create();
404 1 hiro
405 1 hiro
        window_vbox = gtk_vbox_new(FALSE, 0);
406 1 hiro
        gtk_container_add(GTK_CONTAINER(window), window_vbox);
407 1 hiro
408 1 hiro
        g_signal_connect(G_OBJECT(window), "size_allocate",
409 1 hiro
                         G_CALLBACK(messageview_size_allocate_cb),
410 1 hiro
                         msgview);
411 316 hiro
        g_signal_connect(G_OBJECT(window), "delete_event",
412 316 hiro
                         G_CALLBACK(messageview_delete_cb), msgview);
413 1 hiro
        g_signal_connect(G_OBJECT(window), "key_press_event",
414 1 hiro
                         G_CALLBACK(key_pressed), msgview);
415 1 hiro
        MANAGE_WINDOW_SIGNALS_CONNECT(window);
416 1 hiro
417 1 hiro
        n_menu_entries = sizeof(msgview_entries) / sizeof (msgview_entries[0]);
418 1 hiro
        menubar = menubar_create(window, msgview_entries, n_menu_entries,
419 1 hiro
                                 "<MessageView>", msgview);
420 1 hiro
#if 0
421 1 hiro
        menu_factory_copy_rc("<Main>", "<MessageView>");
422 1 hiro
#endif
423 1 hiro
        gtk_box_pack_start(GTK_BOX(window_vbox), menubar, FALSE, TRUE, 0);
424 1 hiro
425 1227 hiro
        vspacer = gtk_vbox_new(FALSE, 0);
426 1227 hiro
        gtk_box_pack_start(GTK_BOX(window_vbox), vspacer, FALSE, TRUE,
427 1227 hiro
                           BORDER_WIDTH);
428 1227 hiro
429 1 hiro
        body_vbox = gtk_vbox_new(FALSE, BORDER_WIDTH);
430 1 hiro
        gtk_box_pack_start(GTK_BOX(window_vbox), body_vbox, TRUE, TRUE, 0);
431 1 hiro
432 1 hiro
        gtk_box_pack_start(GTK_BOX(body_vbox), GTK_WIDGET_PTR(msgview),
433 1 hiro
                           TRUE, TRUE, 0);
434 1 hiro
        gtk_widget_grab_focus(msgview->textview->text);
435 1 hiro
436 1 hiro
        statusbar = gtk_statusbar_new();
437 1 hiro
        gtk_box_pack_end(GTK_BOX(body_vbox), statusbar, FALSE, FALSE, 0);
438 1 hiro
        msgview->statusbar = statusbar;
439 1 hiro
        msgview->statusbar_cid = gtk_statusbar_get_context_id
440 1 hiro
                (GTK_STATUSBAR(statusbar), "Message View");
441 1 hiro
442 1 hiro
        msgview->new_window = TRUE;
443 1 hiro
        msgview->window = window;
444 1 hiro
        msgview->window_vbox = window_vbox;
445 1 hiro
        msgview->body_vbox = body_vbox;
446 976 hiro
        msgview->menubar = menubar;
447 976 hiro
        msgview->menu_locked = FALSE;
448 1 hiro
        msgview->visible = TRUE;
449 1 hiro
450 1399 hiro
        gtk_widget_show_all(window);
451 1399 hiro
452 1 hiro
        messageview_init(msgview);
453 1 hiro
454 1399 hiro
        messageview_set_encoding_menu(msgview);
455 1399 hiro
456 1 hiro
        ifactory = gtk_item_factory_from_widget(menubar);
457 952 hiro
#ifndef G_OS_WIN32
458 1 hiro
        action_update_msgview_menu(ifactory, msgview);
459 952 hiro
#endif
460 1 hiro
461 1 hiro
        messageview_list = g_list_append(messageview_list, msgview);
462 1 hiro
463 1 hiro
        return msgview;
464 1 hiro
}
465 1 hiro
466 1 hiro
void messageview_init(MessageView *messageview)
467 1 hiro
{
468 1 hiro
        headerview_init(messageview->headerview);
469 1 hiro
        textview_init(messageview->textview);
470 1 hiro
        mimeview_init(messageview->mimeview);
471 1 hiro
        /* messageview_set_font(messageview); */
472 1 hiro
}
473 1 hiro
474 1 hiro
GList *messageview_get_window_list(void)
475 1 hiro
{
476 1 hiro
        return messageview_list;
477 1 hiro
}
478 1 hiro
479 1 hiro
gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
480 1 hiro
                      gboolean all_headers)
481 1 hiro
{
482 1 hiro
        gchar *file;
483 1 hiro
        MimeInfo *mimeinfo;
484 1 hiro
485 1 hiro
        g_return_val_if_fail(msginfo != NULL, -1);
486 1 hiro
487 1 hiro
        mimeinfo = procmime_scan_message(msginfo);
488 1 hiro
        if (!mimeinfo) {
489 1 hiro
                messageview_change_view_type(messageview, MVIEW_TEXT);
490 1 hiro
                textview_show_error(messageview->textview);
491 1 hiro
                return -1;
492 1 hiro
        }
493 1 hiro
494 1 hiro
        file = procmsg_get_message_file_path(msginfo);
495 1 hiro
        if (!file) {
496 1 hiro
                g_warning("can't get message file path.\n");
497 1 hiro
                procmime_mimeinfo_free_all(mimeinfo);
498 1 hiro
                messageview_change_view_type(messageview, MVIEW_TEXT);
499 1 hiro
                textview_show_error(messageview->textview);
500 1 hiro
                return -1;
501 1 hiro
        }
502 1 hiro
503 1 hiro
        if (messageview->msginfo != msginfo) {
504 1 hiro
                procmsg_msginfo_free(messageview->msginfo);
505 1 hiro
                messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
506 20 hiro
                if (!messageview->msginfo)
507 20 hiro
                        messageview->msginfo = procmsg_msginfo_copy(msginfo);
508 1 hiro
        }
509 676 hiro
510 676 hiro
        if (messageview->window && msginfo->subject) {
511 676 hiro
                gchar *title;
512 676 hiro
513 676 hiro
                title = g_strconcat(msginfo->subject, " - Sylpheed", NULL);
514 676 hiro
                gtk_window_set_title(GTK_WINDOW(messageview->window), title);
515 676 hiro
                g_free(title);
516 676 hiro
        }
517 1 hiro
        headerview_show(messageview->headerview, messageview->msginfo);
518 1 hiro
519 1 hiro
        textview_set_all_headers(messageview->textview, all_headers);
520 1 hiro
        textview_set_all_headers(messageview->mimeview->textview, all_headers);
521 1 hiro
522 1 hiro
        if (mimeinfo->mime_type != MIME_TEXT &&
523 1947 hiro
            (prefs_common.html_only_as_attach ||
524 1947 hiro
             mimeinfo->mime_type != MIME_TEXT_HTML)) {
525 1 hiro
                messageview_change_view_type(messageview, MVIEW_MIME);
526 1 hiro
                mimeview_show_message(messageview->mimeview, mimeinfo, file);
527 1 hiro
        } else {
528 1 hiro
                messageview_change_view_type(messageview, MVIEW_TEXT);
529 1 hiro
                textview_show_message(messageview->textview, mimeinfo, file);
530 1 hiro
                procmime_mimeinfo_free_all(mimeinfo);
531 1 hiro
        }
532 1 hiro
533 976 hiro
        if (messageview->new_window)
534 976 hiro
                messageview_set_menu_state(messageview);
535 976 hiro
536 1 hiro
        g_free(file);
537 1 hiro
538 1 hiro
        return 0;
539 1 hiro
}
540 1 hiro
541 1 hiro
static void messageview_change_view_type(MessageView *messageview,
542 1 hiro
                                         MessageType type)
543 1 hiro
{
544 154 hiro
        GtkWidget *notebook = messageview->notebook;
545 1 hiro
546 1 hiro
        if (messageview->type == type) return;
547 1 hiro
548 1 hiro
        if (type == MVIEW_MIME) {
549 154 hiro
                gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), TRUE);
550 154 hiro
                gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook),
551 154 hiro
                                              messageview->current_page);
552 1 hiro
        } else if (type == MVIEW_TEXT) {
553 154 hiro
                gint current_page = messageview->current_page;
554 1 hiro
555 154 hiro
                gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
556 154 hiro
                gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
557 154 hiro
                messageview->current_page = current_page;
558 154 hiro
                mimeview_clear(messageview->mimeview);
559 1 hiro
        } else
560 1 hiro
                return;
561 1 hiro
562 1 hiro
        messageview->type = type;
563 1 hiro
}
564 1 hiro
565 976 hiro
static void messageview_set_menu_state(MessageView *messageview)
566 976 hiro
{
567 976 hiro
        GtkItemFactory *ifactory;
568 976 hiro
        GtkWidget *menuitem;
569 976 hiro
570 976 hiro
        messageview->menu_locked = TRUE;
571 1921 hiro
572 976 hiro
        ifactory = gtk_item_factory_from_widget(messageview->menubar);
573 976 hiro
        menuitem = gtk_item_factory_get_widget
574 1147 hiro
                (ifactory, "/View/All headers");
575 976 hiro
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
576 976 hiro
                                       messageview->textview->show_all_headers);
577 1921 hiro
578 1921 hiro
        if (messageview->msginfo &&
579 1921 hiro
            FOLDER_ITEM_IS_SENT_FOLDER(messageview->msginfo->folder))
580 1921 hiro
                menu_set_sensitive(ifactory, "/Message/Re-edit", TRUE);
581 1921 hiro
        else
582 1921 hiro
                menu_set_sensitive(ifactory, "/Message/Re-edit", FALSE);
583 1921 hiro
584 976 hiro
        messageview->menu_locked = FALSE;
585 976 hiro
}
586 976 hiro
587 1399 hiro
static void messageview_set_encoding_menu(MessageView *messageview)
588 1399 hiro
{
589 1399 hiro
        GtkItemFactoryEntry *entry;
590 1399 hiro
        GtkItemFactory *ifactory;
591 1399 hiro
        CharSet encoding;
592 1399 hiro
        gchar *path, *p, *q;
593 1399 hiro
        GtkWidget *item;
594 1399 hiro
595 1399 hiro
        encoding = conv_get_charset_from_str(prefs_common.force_charset);
596 1399 hiro
        ifactory = gtk_item_factory_from_widget(messageview->menubar);
597 1399 hiro
598 1399 hiro
        for (entry = msgview_entries; entry->callback != view_source_cb;
599 1399 hiro
             entry++) {
600 1399 hiro
                if (entry->callback == set_charset_cb &&
601 1399 hiro
                    (CharSet)entry->callback_action == encoding) {
602 1399 hiro
                        p = q = path = g_strdup(entry->path);
603 1399 hiro
                        while (*p) {
604 1399 hiro
                                if (*p == '_') {
605 1399 hiro
                                        if (p[1] == '_') {
606 1399 hiro
                                                p++;
607 1399 hiro
                                                *q++ = '_';
608 1399 hiro
                                        }
609 1399 hiro
                                } else
610 1399 hiro
                                        *q++ = *p;
611 1399 hiro
                                p++;
612 1399 hiro
                        }
613 1399 hiro
                        *q = '\0';
614 1399 hiro
                        item = gtk_item_factory_get_item(ifactory, path);
615 1399 hiro
                        gtk_widget_activate(item);
616 1399 hiro
                        g_free(path);
617 1399 hiro
                        break;
618 1399 hiro
                }
619 1399 hiro
        }
620 1399 hiro
}
621 1399 hiro
622 1 hiro
void messageview_clear(MessageView *messageview)
623 1 hiro
{
624 1 hiro
        procmsg_msginfo_free(messageview->msginfo);
625 1 hiro
        messageview->msginfo = NULL;
626 1 hiro
        messageview_change_view_type(messageview, MVIEW_TEXT);
627 1 hiro
        headerview_clear(messageview->headerview);
628 1 hiro
        textview_clear(messageview->textview);
629 1 hiro
        mimeview_clear(messageview->mimeview);
630 1 hiro
}
631 1 hiro
632 1 hiro
void messageview_destroy(MessageView *messageview)
633 1 hiro
{
634 154 hiro
        GtkWidget *textview  = GTK_WIDGET_PTR(messageview->mimeview->textview);
635 1 hiro
        GtkWidget *imageview = GTK_WIDGET_PTR(messageview->mimeview->imageview);
636 1 hiro
637 1 hiro
        messageview_list = g_list_remove(messageview_list, messageview);
638 1 hiro
639 1 hiro
        headerview_destroy(messageview->headerview);
640 1 hiro
        textview_destroy(messageview->textview);
641 1 hiro
        mimeview_destroy(messageview->mimeview);
642 1 hiro
643 1 hiro
        procmsg_msginfo_free(messageview->msginfo);
644 1 hiro
645 316 hiro
        if (messageview->window)
646 316 hiro
                gtk_widget_destroy(messageview->window);
647 316 hiro
648 1 hiro
        g_free(messageview);
649 1 hiro
650 1 hiro
        gtk_widget_unref(textview);
651 1 hiro
        gtk_widget_unref(imageview);
652 1 hiro
}
653 1 hiro
654 1 hiro
void messageview_quote_color_set(void)
655 1 hiro
{
656 1 hiro
}
657 1 hiro
658 1 hiro
void messageview_set_font(MessageView *messageview)
659 1 hiro
{
660 1 hiro
        textview_set_font(messageview->textview, NULL);
661 1 hiro
}
662 1 hiro
663 1 hiro
TextView *messageview_get_current_textview(MessageView *messageview)
664 1 hiro
{
665 1 hiro
        TextView *text = NULL;
666 1 hiro
667 1 hiro
        if (messageview->type == MVIEW_TEXT)
668 1 hiro
                text = messageview->textview;
669 1 hiro
        else if (messageview->type == MVIEW_MIME) {
670 1 hiro
                if (gtk_notebook_get_current_page
671 154 hiro
                        (GTK_NOTEBOOK(messageview->notebook)) == 0)
672 1 hiro
                        text = messageview->textview;
673 1 hiro
                else if (messageview->mimeview->type == MIMEVIEW_TEXT)
674 1 hiro
                        text = messageview->mimeview->textview;
675 1 hiro
        }
676 1 hiro
677 1 hiro
        return text;
678 1 hiro
}
679 1 hiro
680 1 hiro
MimeInfo *messageview_get_selected_mime_part(MessageView *messageview)
681 1 hiro
{
682 1 hiro
        if (messageview->type == MVIEW_MIME)
683 1 hiro
                return mimeview_get_selected_part(messageview->mimeview);
684 1 hiro
685 1 hiro
        return NULL;
686 1 hiro
}
687 1 hiro
688 1 hiro
void messageview_copy_clipboard(MessageView *messageview)
689 1 hiro
{
690 1 hiro
        TextView *text;
691 1 hiro
692 1 hiro
        text = messageview_get_current_textview(messageview);
693 1 hiro
        if (text) {
694 1 hiro
                GtkTextView *textview = GTK_TEXT_VIEW(text->text);
695 1 hiro
                GtkTextBuffer *buffer;
696 1 hiro
                GtkClipboard *clipboard;
697 1 hiro
698 1 hiro
                buffer = gtk_text_view_get_buffer(textview);
699 1 hiro
                clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
700 1 hiro
                gtk_text_buffer_copy_clipboard(buffer, clipboard);
701 1 hiro
        }
702 1 hiro
}
703 1 hiro
704 1 hiro
void messageview_select_all(MessageView *messageview)
705 1 hiro
{
706 1 hiro
        TextView *text;
707 1 hiro
708 1 hiro
        text = messageview_get_current_textview(messageview);
709 130 hiro
        if (text) {
710 130 hiro
                GtkTextView *textview = GTK_TEXT_VIEW(text->text);
711 130 hiro
                GtkTextBuffer *buffer;
712 130 hiro
                GtkTextIter start, end;
713 130 hiro
714 130 hiro
                buffer = gtk_text_view_get_buffer(textview);
715 130 hiro
                gtk_text_buffer_get_bounds(buffer, &start, &end);
716 130 hiro
                gtk_text_buffer_select_range(buffer, &start, &end);
717 130 hiro
        }
718 1 hiro
}
719 1 hiro
720 1 hiro
void messageview_set_position(MessageView *messageview, gint pos)
721 1 hiro
{
722 1 hiro
        textview_set_position(messageview->textview, pos);
723 1 hiro
}
724 1 hiro
725 1 hiro
gboolean messageview_search_string(MessageView *messageview, const gchar *str,
726 1 hiro
                                   gboolean case_sens)
727 1 hiro
{
728 1 hiro
        return textview_search_string(messageview->textview, str, case_sens);
729 1 hiro
        return FALSE;
730 1 hiro
}
731 1 hiro
732 1 hiro
gboolean messageview_search_string_backward(MessageView *messageview,
733 1 hiro
                                            const gchar *str,
734 1 hiro
                                            gboolean case_sens)
735 1 hiro
{
736 1 hiro
        return textview_search_string_backward(messageview->textview,
737 1 hiro
                                               str, case_sens);
738 1 hiro
        return FALSE;
739 1 hiro
}
740 1 hiro
741 1 hiro
gboolean messageview_is_visible(MessageView *messageview)
742 1 hiro
{
743 1 hiro
        return messageview->visible;
744 1 hiro
}
745 1 hiro
746 1 hiro
void messageview_save_as(MessageView *messageview)
747 1 hiro
{
748 1 hiro
        gchar *filename = NULL;
749 1 hiro
        MsgInfo *msginfo;
750 1 hiro
        gchar *src, *dest;
751 1 hiro
752 1 hiro
        if (!messageview->msginfo) return;
753 1 hiro
        msginfo = messageview->msginfo;
754 1 hiro
755 1 hiro
        if (msginfo->subject) {
756 1 hiro
                Xstrdup_a(filename, msginfo->subject, return);
757 1 hiro
                subst_for_filename(filename);
758 1 hiro
        }
759 128 hiro
760 128 hiro
        dest = filesel_save_as(filename);
761 1 hiro
        if (!dest) return;
762 1 hiro
763 1 hiro
        src = procmsg_get_message_file(msginfo);
764 1 hiro
        if (copy_file(src, dest, TRUE) < 0) {
765 1 hiro
                alertpanel_error(_("Can't save the file `%s'."),
766 1 hiro
                                 g_basename(dest));
767 1 hiro
        }
768 1 hiro
        g_free(src);
769 128 hiro
770 128 hiro
        g_free(dest);
771 1 hiro
}
772 1 hiro
773 316 hiro
static gint messageview_delete_cb(GtkWidget *widget, GdkEventAny *event,
774 316 hiro
                                  MessageView *messageview)
775 1 hiro
{
776 1 hiro
        messageview_destroy(messageview);
777 316 hiro
        return TRUE;
778 1 hiro
}
779 1 hiro
780 1 hiro
static void messageview_size_allocate_cb(GtkWidget *widget,
781 1 hiro
                                         GtkAllocation *allocation)
782 1 hiro
{
783 1 hiro
        g_return_if_fail(allocation != NULL);
784 1 hiro
785 1 hiro
        prefs_common.msgwin_width  = allocation->width;
786 1 hiro
        prefs_common.msgwin_height = allocation->height;
787 1 hiro
}
788 1 hiro
789 154 hiro
static void messageview_switch_page_cb(GtkNotebook *notebook,
790 154 hiro
                                       GtkNotebookPage *page, guint page_num,
791 154 hiro
                                       MessageView *messageview)
792 154 hiro
{
793 154 hiro
        messageview->current_page = page_num;
794 154 hiro
}
795 154 hiro
796 1 hiro
static gboolean key_pressed(GtkWidget *widget, GdkEventKey *event,
797 1 hiro
                            MessageView *messageview)
798 1 hiro
{
799 316 hiro
        if (event && event->keyval == GDK_Escape && messageview->window) {
800 316 hiro
                messageview_destroy(messageview);
801 316 hiro
                return TRUE;
802 316 hiro
        }
803 1 hiro
        return FALSE;
804 1 hiro
}
805 1 hiro
806 1 hiro
static void save_as_cb(gpointer data, guint action, GtkWidget *widget)
807 1 hiro
{
808 1 hiro
        MessageView *messageview = (MessageView *)data;
809 1 hiro
        messageview_save_as(messageview);
810 1 hiro
}
811 1 hiro
812 1420 hiro
#if GTK_CHECK_VERSION(2, 10, 0)
813 1420 hiro
static void page_setup_cb(gpointer data, guint action, GtkWidget *widget)
814 1420 hiro
{
815 1420 hiro
        printing_page_setup_gtk();
816 1420 hiro
}
817 1420 hiro
#endif
818 1420 hiro
819 1 hiro
static void print_cb(gpointer data, guint action, GtkWidget *widget)
820 1 hiro
{
821 1 hiro
        MessageView *messageview = (MessageView *)data;
822 1 hiro
823 1 hiro
        if (!messageview->msginfo) return;
824 1 hiro
825 1386 hiro
        printing_print_message(messageview->msginfo,
826 1386 hiro
                               messageview->textview->show_all_headers);
827 1 hiro
}
828 1 hiro
829 1 hiro
static void close_cb(gpointer data, guint action, GtkWidget *widget)
830 1 hiro
{
831 1 hiro
        MessageView *messageview = (MessageView *)data;
832 316 hiro
        messageview_destroy(messageview);
833 1 hiro
}
834 1 hiro
835 1 hiro
static void copy_cb(gpointer data, guint action, GtkWidget *widget)
836 1 hiro
{
837 1 hiro
        MessageView *messageview = (MessageView *)data;
838 1 hiro
        messageview_copy_clipboard(messageview);
839 1 hiro
}
840 1 hiro
841 1 hiro
static void allsel_cb(gpointer data, guint action, GtkWidget *widget)
842 1 hiro
{
843 1 hiro
        MessageView *messageview = (MessageView *)data;
844 1 hiro
        messageview_select_all(messageview);
845 1 hiro
}
846 1 hiro
847 1 hiro
static void search_cb(gpointer data, guint action, GtkWidget *widget)
848 1 hiro
{
849 1 hiro
        MessageView *messageview = (MessageView *)data;
850 1 hiro
        message_search(messageview);
851 1 hiro
}
852 1 hiro
853 1 hiro
static void set_charset_cb(gpointer data, guint action, GtkWidget *widget)
854 1 hiro
{
855 1 hiro
        MessageView *messageview = (MessageView *)data;
856 1 hiro
        const gchar *charset;
857 1 hiro
858 1 hiro
        if (GTK_CHECK_MENU_ITEM(widget)->active) {
859 1 hiro
                charset = conv_get_charset_str((CharSet)action);
860 1 hiro
                g_free(messageview->forced_charset);
861 1 hiro
                messageview->forced_charset = g_strdup(charset);
862 1399 hiro
                if (messageview->msginfo)
863 1399 hiro
                        messageview_show(messageview, messageview->msginfo,
864 1399 hiro
                                         FALSE);
865 1 hiro
        }
866 1 hiro
}
867 1 hiro
868 1 hiro
static void view_source_cb(gpointer data, guint action, GtkWidget *widget)
869 1 hiro
{
870 1 hiro
        MessageView *messageview = (MessageView *)data;
871 1 hiro
        SourceWindow *srcwin;
872 1 hiro
873 1 hiro
        if (!messageview->msginfo) return;
874 1 hiro
875 1 hiro
        srcwin = source_window_create();
876 1 hiro
        source_window_show_msg(srcwin, messageview->msginfo);
877 1 hiro
        source_window_show(srcwin);
878 1 hiro
}
879 1 hiro
880 1 hiro
static void show_all_header_cb(gpointer data, guint action, GtkWidget *widget)
881 1 hiro
{
882 1 hiro
        MessageView *messageview = (MessageView *)data;
883 1 hiro
        MsgInfo *msginfo = messageview->msginfo;
884 1 hiro
885 1 hiro
        if (!msginfo) return;
886 976 hiro
        if (messageview->menu_locked) return;
887 976 hiro
888 1 hiro
        messageview->msginfo = NULL;
889 1 hiro
        messageview_show(messageview, msginfo,
890 1 hiro
                         GTK_CHECK_MENU_ITEM(widget)->active);
891 1 hiro
        procmsg_msginfo_free(msginfo);
892 1 hiro
}
893 1 hiro
894 1 hiro
static void compose_cb(gpointer data, guint action, GtkWidget *widget)
895 1 hiro
{
896 1 hiro
        MessageView *messageview = (MessageView *)data;
897 1 hiro
        PrefsAccount *ac = NULL;
898 1 hiro
        FolderItem *item = NULL;
899 1 hiro
900 1 hiro
        if (messageview->msginfo)
901 1 hiro
                item = messageview->msginfo->folder;
902 1 hiro
903 1 hiro
        if (item) {
904 1 hiro
                ac = account_find_from_item(item);
905 1 hiro
                if (ac && ac->protocol == A_NNTP &&
906 1 hiro
                    FOLDER_TYPE(item->folder) == F_NEWS) {
907 1 hiro
                        compose_new(ac, item, item->path, NULL);
908 1 hiro
                        return;
909 1 hiro
                }
910 1 hiro
        }
911 1 hiro
912 1 hiro
        compose_new(ac, item, NULL, NULL);
913 1 hiro
}
914 1 hiro
915 1 hiro
static void reply_cb(gpointer data, guint action, GtkWidget *widget)
916 1 hiro
{
917 1 hiro
        MessageView *messageview = (MessageView *)data;
918 1 hiro
        GSList *mlist = NULL;
919 1 hiro
        MsgInfo *msginfo;
920 1 hiro
        gchar *text = NULL;
921 1 hiro
        ComposeMode mode = (ComposeMode)action;
922 1399 hiro
        gchar *prev_force_charset;
923 1 hiro
924 1 hiro
        msginfo = messageview->msginfo;
925 1 hiro
        mlist = g_slist_append(NULL, msginfo);
926 1 hiro
927 130 hiro
        text = gtkut_text_view_get_selection
928 130 hiro
                (GTK_TEXT_VIEW(messageview->textview->text));
929 1 hiro
        if (text && *text == '\0') {
930 1 hiro
                g_free(text);
931 1 hiro
                text = NULL;
932 1 hiro
        }
933 1 hiro
934 1 hiro
        if (!COMPOSE_QUOTE_MODE(mode))
935 1 hiro
                mode |= prefs_common.reply_with_quote
936 1 hiro
                        ? COMPOSE_WITH_QUOTE : COMPOSE_WITHOUT_QUOTE;
937 1 hiro
938 1399 hiro
        prev_force_charset = prefs_common.force_charset;
939 1399 hiro
        prefs_common.force_charset = messageview->forced_charset;
940 1399 hiro
941 1 hiro
        switch (COMPOSE_MODE(mode)) {
942 1 hiro
        case COMPOSE_REPLY:
943 1 hiro
        case COMPOSE_REPLY_TO_SENDER:
944 1 hiro
        case COMPOSE_REPLY_TO_ALL:
945 1 hiro
        case COMPOSE_REPLY_TO_LIST:
946 1 hiro
                compose_reply(msginfo, msginfo->folder, mode, text);
947 1 hiro
                break;
948 1 hiro
        case COMPOSE_FORWARD:
949 1 hiro
                compose_forward(mlist, msginfo->folder, FALSE, text);
950 1 hiro
                break;
951 1 hiro
        case COMPOSE_FORWARD_AS_ATTACH:
952 1 hiro
                compose_forward(mlist, msginfo->folder, TRUE, NULL);
953 1 hiro
                break;
954 1 hiro
        case COMPOSE_REDIRECT:
955 1 hiro
                compose_redirect(msginfo, msginfo->folder);
956 1 hiro
                break;
957 1 hiro
        default:
958 1 hiro
                g_warning("messageview.c: reply_cb(): invalid mode: %d\n",
959 1 hiro
                          mode);
960 1 hiro
        }
961 1 hiro
962 1399 hiro
        prefs_common.force_charset = prev_force_charset;
963 1399 hiro
964 1 hiro
        /* summary_set_marks_selected(summaryview); */
965 1 hiro
        g_free(text);
966 1 hiro
        g_slist_free(mlist);
967 1 hiro
}
968 1 hiro
969 1 hiro
static void reedit_cb(gpointer data, guint action, GtkWidget *widget)
970 1 hiro
{
971 1 hiro
        MessageView *messageview = (MessageView *)data;
972 1 hiro
        MsgInfo *msginfo;
973 1 hiro
974 1 hiro
        if (!messageview->msginfo) return;
975 1 hiro
        msginfo = messageview->msginfo;
976 1 hiro
        if (!msginfo->folder) return;
977 1 hiro
        if (msginfo->folder->stype != F_OUTBOX &&
978 1 hiro
            msginfo->folder->stype != F_DRAFT &&
979 1 hiro
            msginfo->folder->stype != F_QUEUE) return;
980 1 hiro
981 1 hiro
        compose_reedit(msginfo);
982 1 hiro
}
983 1 hiro
984 1 hiro
static void addressbook_open_cb(gpointer data, guint action, GtkWidget *widget)
985 1 hiro
{
986 1 hiro
        addressbook_open(NULL);
987 1 hiro
}
988 1 hiro
989 1 hiro
static void add_address_cb(gpointer data, guint action, GtkWidget *widget)
990 1 hiro
{
991 1 hiro
        MessageView *messageview = (MessageView *)data;
992 1 hiro
        MsgInfo *msginfo;
993 1 hiro
        gchar *from;
994 1 hiro
995 1 hiro
        if (!messageview->msginfo) return;
996 1 hiro
        msginfo = messageview->msginfo;
997 1 hiro
        Xstrdup_a(from, msginfo->from, return);
998 1 hiro
        eliminate_address_comment(from);
999 1 hiro
        extract_address(from);
1000 1 hiro
        addressbook_add_contact(msginfo->fromname, from, NULL);
1001 1 hiro
}
1002 1 hiro
1003 1 hiro
static void create_filter_cb(gpointer data, guint action, GtkWidget *widget)
1004 1 hiro
{
1005 1 hiro
        MessageView *messageview = (MessageView *)data;
1006 1 hiro
        gchar *header = NULL;
1007 1 hiro
        gchar *key = NULL;
1008 1 hiro
1009 1 hiro
        if (!messageview->msginfo) return;
1010 1 hiro
1011 547 hiro
        filter_get_keyword_from_msg(messageview->msginfo, &header, &key,
1012 547 hiro
                                    (FilterCreateType)action);
1013 2042 hiro
        prefs_filter_open(messageview->msginfo, header, key);
1014 1 hiro
1015 1 hiro
        g_free(header);
1016 1 hiro
        g_free(key);
1017 1 hiro
}
1018 1 hiro
1019 1 hiro
static void about_cb(gpointer data, guint action, GtkWidget *widget)
1020 1 hiro
{
1021 1 hiro
        about_show();
1022 1 hiro
}