aboutsummaryrefslogtreecommitdiffstats
path: root/mail/message-browser.c
blob: 3a471b24e9f8f927bc3c1cf86f2bbde2e95e50cc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 *  Authors: Jeffrey Stedfast <fejj@ximian.com>
 *
 *  Copyright 2001 Ximian, Inc. (www.ximian.com)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gal/util/e-util.h>

#include "message-browser.h"

#include "mail.h"
#include "mail-callbacks.h"
#include "mail-tools.h"
#include "message-list.h"
#include "mail-ops.h"
#include "mail-vfolder.h"
#include "mail-autofilter.h"
#include "mail-mlist-magic.h"
#include "mail-mt.h"

#include "mail-local.h"
#include "mail-config.h"

#define d(x) x

#define MINIMUM_WIDTH  600
#define MINIMUM_HEIGHT 400

#define PARENT_TYPE (gnome_app_get_type ())

/* Size of the window last time it was changed.  */
static GtkAllocation last_allocation = { 0, 0 };

static GnomeAppClass *message_browser_parent_class;

static void
message_browser_destroy (GtkObject *object)
{
    MessageBrowser *message_browser;
    
    message_browser = MESSAGE_BROWSER (object);
    
    gtk_object_unref (GTK_OBJECT (message_browser->fb));
    
    gtk_widget_destroy (GTK_WIDGET (message_browser));
}

static void
message_browser_class_init (GtkObjectClass *object_class)
{
    object_class->destroy = message_browser_destroy;
    
    message_browser_parent_class = gtk_type_class (PARENT_TYPE);
}

static void
message_browser_init (GtkObject *object)
{
    
}

static void
message_browser_close (GtkWidget *menuitem, gpointer user_data)
{
    gtk_widget_destroy (GTK_WIDGET (user_data));
}

static void
message_browser_reply_to_sender (GtkWidget *widget, gpointer user_data)
{
    MessageBrowser *mb = MESSAGE_BROWSER (user_data);
    
    reply_to_sender (NULL, mb->fb);
}

static void
message_browser_reply_to_all (GtkWidget *widget, gpointer user_data)
{
    MessageBrowser *mb = MESSAGE_BROWSER (user_data);
    
    reply_to_all (NULL, mb->fb);
}

static void
message_browser_forward_msg (GtkWidget *widget, gpointer user_data)
{
    MessageBrowser *mb = MESSAGE_BROWSER (user_data);
    
    forward_attached (NULL, mb->fb);
}

static void
message_browser_print_msg (GtkWidget *widget, gpointer user_data)
{
    MessageBrowser *mb = MESSAGE_BROWSER (user_data);
    
    mail_print_msg (mb->fb->mail_display);
}

static void
message_browser_delete_msg (GtkWidget *button, gpointer user_data)
{
    MessageBrowser *mb = MESSAGE_BROWSER (user_data);
    
    delete_msg (NULL, mb->fb);
}

static void
message_browser_next_msg (GtkWidget *button, gpointer user_data)
{
    MessageBrowser *mb = MESSAGE_BROWSER (user_data);
    
    next_msg (NULL, mb->fb);
}

static void
message_browser_prev_msg (GtkWidget *button, gpointer user_data)
{
    MessageBrowser *mb = MESSAGE_BROWSER (user_data);
    
    previous_msg (NULL, mb->fb);
}

static void
message_browser_message_selected (MessageList *ml, const char *uid, MessageBrowser *mb)
{
    CamelMimeMessage *message;
    char *subject = NULL;
    
    g_warning ("got 'message_selected' event");
    
    message = mb->fb->mail_display->current_message;
    
    if (message)
        subject = (char *) camel_mime_message_get_subject (message);
    
    gtk_window_set_title (GTK_WINDOW (mb), subject ? subject : "");
}

static void
message_browser_folder_loaded (FolderBrowser *fb, const char *uri, MessageBrowser *mb)
{
    const char *uid = gtk_object_get_data (GTK_OBJECT (mb), "uid");
    
    g_warning ("got 'folder_loaded' event");
    
    gtk_signal_connect (GTK_OBJECT (fb->message_list), "message_selected",
                message_browser_message_selected, mb);
    
    message_list_select_uid (fb->message_list, uid);
}

static GnomeUIInfo message_browser_toolbar [] = {
    
    /*GNOMEUIINFO_ITEM_STOCK (N_("Save"), N_("Save this message"),
      save_msg, GNOME_STOCK_PIXMAP_SAVE),*/
    
    GNOMEUIINFO_ITEM_STOCK (N_("Reply"), N_("Reply to the sender of this message"),
                message_browser_reply_to_sender, GNOME_STOCK_PIXMAP_MAIL_RPL),
    
    GNOMEUIINFO_ITEM_STOCK (N_("Reply to All"), N_("Reply to all recipients of this message"),
                message_browser_reply_to_all, GNOME_STOCK_PIXMAP_MAIL_RPL),
    
    GNOMEUIINFO_ITEM_STOCK (N_("Forward"), N_("Forward this message"),
                message_browser_forward_msg, GNOME_STOCK_PIXMAP_MAIL_FWD),
    
    GNOMEUIINFO_SEPARATOR,
    
    GNOMEUIINFO_ITEM_STOCK (N_("Print"), N_("Print the selected message"),
                message_browser_print_msg, GNOME_STOCK_PIXMAP_PRINT),
    
    GNOMEUIINFO_ITEM_STOCK (N_("Delete"), N_("Delete this message"),
                message_browser_delete_msg, GNOME_STOCK_PIXMAP_TRASH),
    
    GNOMEUIINFO_SEPARATOR,
    
    GNOMEUIINFO_ITEM_STOCK (N_("Previous"), N_("Previous message"),
                message_browser_prev_msg, GNOME_STOCK_PIXMAP_BACK),
    
    GNOMEUIINFO_ITEM_STOCK (N_("Next"), N_("Next message"),
                message_browser_next_msg, GNOME_STOCK_PIXMAP_FORWARD),
    
    GNOMEUIINFO_END
};

static GnomeUIInfo file_menu[] = {
    /*GNOMEUIINFO_MENU_SAVE_ITEM (save, NULL),*/
    /*GNOMEUIINFO_MENU_SAVE_AS_ITEM (save_as, NULL),*/
    /*GNOMEUIINFO_SEPARATOR,*/
    GNOMEUIINFO_MENU_CLOSE_ITEM (message_browser_close, NULL),
    GNOMEUIINFO_END
};

static GnomeUIInfo view_menu[] =
{
    GNOMEUIINFO_END
};

static GnomeUIInfo message_browser_menubar[] =
{
    GNOMEUIINFO_MENU_FILE_TREE (file_menu),
    GNOMEUIINFO_MENU_VIEW_TREE (view_menu),
    GNOMEUIINFO_END
};

static void
set_default_size (GtkWidget *widget)
{
    int width, height;
    
    width  = MAX (MINIMUM_WIDTH, last_allocation.width);
    height = MAX (MINIMUM_HEIGHT, last_allocation.height);
    
    gtk_window_set_default_size (GTK_WINDOW (widget), width, height);
}

GtkWidget *
message_browser_new (const GNOME_Evolution_Shell shell, const char *uri, const char *uid)
{
    GtkWidget *toolbar, *vbox;
    MessageBrowser *new;
    FolderBrowser *fb;
    
    new = gtk_type_new (message_browser_get_type ());
    
    gnome_app_construct (GNOME_APP (new), "Evolution", "");
    
    gtk_object_set_data_full (GTK_OBJECT (new), "uid", g_strdup (uid), g_free);
    
    toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);
    gnome_app_fill_toolbar_with_data (GTK_TOOLBAR (toolbar),
                      message_browser_toolbar,
                      NULL, new);
    
    gnome_app_set_toolbar (GNOME_APP (new), GTK_TOOLBAR (toolbar));
    gnome_app_create_menus (GNOME_APP (new), message_browser_menubar);
    
    fb = FOLDER_BROWSER (folder_browser_new (shell));
    new->fb = fb;
    
    /* some evil hackery action... */
    vbox = gtk_vbox_new (TRUE, 0);
    gtk_widget_ref (GTK_WIDGET (fb->mail_display));
    gtk_widget_reparent (GTK_WIDGET (fb->mail_display), vbox);
    gtk_widget_show (GTK_WIDGET (fb->mail_display));
    gtk_widget_show (vbox);
    
    gnome_app_set_contents (GNOME_APP (new), vbox);
    gtk_widget_grab_focus (GTK_WIDGET (MAIL_DISPLAY (fb->mail_display)->html));
    
    set_default_size (GTK_WIDGET (new));
    
    /* more evil hackery... */
    gtk_signal_connect (GTK_OBJECT (fb), "folder_loaded",
                message_browser_folder_loaded, new);
    
    folder_browser_set_uri (fb, uri);
    
    return GTK_WIDGET (new);
}


E_MAKE_TYPE (message_browser, "MessageBrowser", MessageBrowser, message_browser_class_init,
         message_browser_init, PARENT_TYPE);