root/trunk/src/tmut-msg-view.c

Revision 73 (checked in by pvanhoof, 10 months ago)

2008-01-28 Philip Van Hoof <pvanhoof@gnome.org>

        • Adapted TMut to the latest Tinymail API changes in trunk.
Line 
1 /* TMut
2  * Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with self library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #if HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <glib/gi18n-lib.h>
25
26 #include "tmut-header-view.h"
27 #include "tmut-tny-gtk-msg-view.h"
28 #include "tmut-msg-view.h"
29 #include "tmut-msg-creator.h"
30
31 #include "tmut-shell-window.h"
32 #include "tmut-shell-child.h"
33
34
35 static GObjectClass *parent_class = NULL;
36
37 typedef struct _TMutMsgViewPriv TMutMsgViewPriv;
38
39 struct _TMutMsgViewPriv {
40         TMutShellWindow *shell;
41         TnyMsgView *msg_view;
42         GtkScrolledWindow *sw;
43         TnyAccountStore *account_store;
44 };
45
46 #define TMUT_MSG_VIEW_GET_PRIVATE(o) \
47         (G_TYPE_INSTANCE_GET_PRIVATE ((o), TMUT_TYPE_MSG_VIEW, TMutMsgViewPriv))
48
49
50
51
52 void 
53 tmut_msg_view_on_reply_activated (GObject *sender, TMutMsgView *self)
54 {
55         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
56         TnyMsg *msg = tny_msg_view_get_msg (priv->msg_view);
57         TMutMsgCreator *view = tmut_msg_creator_new ();
58
59         if (priv->account_store)
60                 tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (view), priv->account_store);
61
62         tmut_msg_creator_set_reply_msg (view, msg);
63         gtk_widget_show (GTK_WIDGET (view));
64
65         tmut_shell_window_set_child (
66                 tmut_shell_child_get_window (TMUT_SHELL_CHILD (self)),
67                 TMUT_SHELL_CHILD (view), NULL);
68
69         g_object_unref (msg);
70
71         return;
72 }
73
74
75 void 
76 tmut_msg_view_on_forward_activated (GObject *sender, TMutMsgView *self)
77 {
78         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
79         TnyMsg *msg = tny_msg_view_get_msg (priv->msg_view);
80         TMutMsgCreator *view = tmut_msg_creator_new ();
81
82         if (priv->account_store)
83                 tny_account_store_view_set_account_store (TNY_ACCOUNT_STORE_VIEW (view), priv->account_store);
84
85         tmut_msg_creator_set_forward_msg (view, msg);
86         gtk_widget_show (GTK_WIDGET (view));
87
88         tmut_shell_window_set_child (
89                 tmut_shell_child_get_window (TMUT_SHELL_CHILD (self)),
90                 TMUT_SHELL_CHILD (view), NULL);
91
92         g_object_unref (msg);
93
94         return;
95         return;
96 }
97
98
99 static void
100 tmut_msg_view_create_menu_default (TMutMsgView *self)
101 {
102         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
103         GtkWidget *hbox, *reply_button, *forward_button;
104
105         hbox = gtk_hbox_new (FALSE, 0);
106         reply_button = gtk_button_new_with_label (_("Reply"));
107         forward_button = gtk_button_new_with_label (_("Forward"));
108
109         gtk_widget_show (hbox);
110         gtk_widget_show (reply_button);
111         gtk_widget_show (forward_button);
112
113         gtk_box_pack_start (GTK_BOX (self), hbox, FALSE, TRUE, 0);
114         gtk_box_pack_start (GTK_BOX (hbox), reply_button, TRUE, TRUE, 0);
115         gtk_box_pack_start (GTK_BOX (hbox), forward_button, TRUE, TRUE, 0);
116
117         g_signal_connect (G_OBJECT (reply_button), "clicked",
118                 G_CALLBACK (tmut_msg_view_on_reply_activated), self);
119         g_signal_connect (G_OBJECT (forward_button), "clicked",
120                 G_CALLBACK (tmut_msg_view_on_forward_activated), self);
121
122         return;
123 }
124
125
126 static void
127 tmut_msg_view_set_unavailable (TnyMsgView *self)
128 {
129         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
130         tny_msg_view_set_unavailable (priv->msg_view);
131         return;
132 }
133
134 static TnyMsg*
135 tmut_msg_view_get_msg (TnyMsgView *self)
136 {
137         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
138         return tny_msg_view_get_msg (priv->msg_view);
139 }
140
141 static void
142 tmut_msg_view_set_msg (TnyMsgView *self, TnyMsg *msg)
143 {
144         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
145
146         tny_msg_view_set_msg (priv->msg_view, msg);
147
148         return;
149 }
150
151 static void
152 tmut_msg_view_clear (TnyMsgView *self)
153 {
154         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
155
156         tny_msg_view_clear (priv->msg_view);
157
158         return;
159 }
160
161 static TnyMsgView*
162 tmut_msg_view_create_new_inline_viewer (TnyMsgView *self)
163 {
164         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
165
166         /* This should not be a window, but the decorated one, as it has to be
167            embeddable within a window. So we even decorate this one as usual. */
168
169         return tny_msg_view_create_new_inline_viewer (priv->msg_view);
170 }
171
172 static TnyMimePartView*
173 tmut_msg_view_create_mime_part_view_for (TnyMsgView *self, TnyMimePart *part)
174 {
175         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
176
177         return tny_msg_view_create_mime_part_view_for (priv->msg_view, part);
178 }
179
180 static void
181 tmut_msg_view_mp_clear (TnyMimePartView *self)
182 {
183         tny_msg_view_clear (TNY_MSG_VIEW (self));
184
185         return;
186 }
187
188 static void
189 tmut_msg_view_mp_set_part (TnyMimePartView *self, TnyMimePart *part)
190 {
191         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
192
193         tny_mime_part_view_set_part (TNY_MIME_PART_VIEW (priv->msg_view), part);
194
195         return;
196 }
197
198 static TnyMimePart*
199 tmut_msg_view_mp_get_part (TnyMimePartView *self)
200 {
201         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
202
203         return tny_mime_part_view_get_part (TNY_MIME_PART_VIEW (priv->msg_view));
204 }
205
206 /**
207  * tmut_msg_view_set_view:
208  * @self: a #TnyGtkMsgView instance
209  * @view: a #TnyMsgView to decorate
210  *
211  * Set the @view to decorate with @self
212  **/
213 void 
214 tmut_msg_view_set_view (TMutMsgView *self, TnyMsgView *view)
215 {
216         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
217
218         if (priv->msg_view)
219                 gtk_container_remove (GTK_CONTAINER (priv->sw), GTK_WIDGET (priv->msg_view));
220         priv->msg_view = view;
221         gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (priv->sw),
222                         GTK_WIDGET (view));
223         gtk_widget_show (GTK_WIDGET (priv->msg_view));
224
225         return;
226 }
227
228 /**
229  * tmut_msg_view_new:
230  * Create a GtkWindow that implements #TnyMsgView
231  *
232  * Return value: a new #TnyMsgView instance implemented for Gtk+
233  **/
234 TnyMsgView*
235 tmut_msg_view_new (TnyAccountStore *account_store)
236 {
237         TMutMsgView *self = g_object_new (TMUT_TYPE_MSG_VIEW, NULL);
238         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
239
240         if (account_store)
241                 priv->account_store = TNY_ACCOUNT_STORE (g_object_ref (account_store));
242
243         return TNY_MSG_VIEW (self);
244 }
245
246
247 static void
248 tmut_msg_view_instance_init (GTypeInstance *instance, gpointer g_class)
249 {
250         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (instance);
251
252         priv->account_store = NULL;
253         priv->msg_view = NULL;
254         priv->sw = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
255         gtk_widget_show (GTK_WIDGET (priv->sw));
256         gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->sw),
257                 GTK_SHADOW_NONE);
258         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->sw),
259                 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
260         gtk_box_pack_start (GTK_BOX (instance), GTK_WIDGET (priv->sw), TRUE, TRUE, 0);
261
262         TMUT_MSG_VIEW_GET_CLASS (instance)->create_menu ((TMutMsgView *) instance);
263
264         tmut_msg_view_set_view (TMUT_MSG_VIEW (instance),
265                 tmut_tny_gtk_msg_view_new ());
266
267         return;
268 }
269
270 static void
271 tmut_msg_view_finalize (GObject *object)
272 {
273         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (object);
274
275         if (priv->account_store)
276                 g_object_unref (priv->account_store);
277
278         (*parent_class->finalize) (object);
279
280         return;
281 }
282
283
284 TMutShellWindow*
285 tmut_msg_view_get_window (TMutShellChild *self)
286 {
287         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
288         return priv->shell;
289 }
290
291 void 
292 tmut_msg_view_set_window (TMutShellChild *self, TMutShellWindow *window)
293 {
294         TMutMsgViewPriv *priv = TMUT_MSG_VIEW_GET_PRIVATE (self);
295         priv->shell = window;
296 }
297
298 static void
299 tmut_shell_child_init (gpointer g, gpointer iface_data)
300 {
301         TMutShellChildIface *klass = (TMutShellChildIface *)g;
302
303         klass->get_window= tmut_msg_view_get_window;
304         klass->set_window= tmut_msg_view_set_window;
305
306         return;
307 }
308
309 static TnyHeaderView*
310 tmut_msg_view_create_header_view (TnyGtkMsgView *self)
311 {
312         return tmut_header_view_new ();
313 }
314
315 static void
316 tmut_msg_view_class_init (TMutMsgViewClass *class)
317 {
318         GObjectClass *object_class;
319
320         parent_class = g_type_class_peek_parent (class);
321         object_class = (GObjectClass*) class;
322
323         object_class->finalize = tmut_msg_view_finalize;
324
325         class->create_menu= tmut_msg_view_create_menu_default;
326
327         g_type_class_add_private (object_class, sizeof (TMutMsgViewPriv));
328
329         return;
330 }
331
332
333 static void
334 tny_msg_view_init (gpointer g, gpointer iface_data)
335 {
336         TnyMsgViewIface *klass = (TnyMsgViewIface *)g;
337
338         klass->get_msg= tmut_msg_view_get_msg;
339         klass->set_msg= tmut_msg_view_set_msg;
340         klass->set_unavailable= tmut_msg_view_set_unavailable;
341         klass->clear= tmut_msg_view_clear;
342         klass->create_mime_part_view_for= tmut_msg_view_create_mime_part_view_for;
343         klass->create_new_inline_viewer= tmut_msg_view_create_new_inline_viewer;
344
345         return;
346 }
347
348 static void
349 tny_mime_part_view_init (gpointer g, gpointer iface_data)
350 {
351         TnyMimePartViewIface *klass = (TnyMimePartViewIface *)g;
352
353         klass->get_part= tmut_msg_view_mp_get_part;
354         klass->set_part= tmut_msg_view_mp_set_part;
355         klass->clear= tmut_msg_view_mp_clear;
356
357         return;
358 }
359
360 GType
361 tmut_msg_view_get_type (void)
362 {
363         static GType type = 0;
364
365         if (G_UNLIKELY(type == 0))
366         {
367                 static const GTypeInfo info =
368                 {
369                   sizeof (TMutMsgViewClass),
370                   NULL,   /* base_init */
371                   NULL,   /* base_finalize */
372                   (GClassInitFunc) tmut_msg_view_class_init,   /* class_init */
373                   NULL,   /* class_finalize */
374                   NULL,   /* class_data */
375                   sizeof (TMutMsgView),
376                   0,      /* n_preallocs */
377                   tmut_msg_view_instance_init,    /* instance_init */
378                   NULL
379                 };
380
381                 static const GInterfaceInfo tmut_shell_child_info =
382                 {
383                   (GInterfaceInitFunc) tmut_shell_child_init, /* interface_init */
384                   NULL,         /* interface_finalize */
385                   NULL          /* interface_data */
386                 };
387
388                 static const GInterfaceInfo tny_msg_view_info =
389                 {
390                   (GInterfaceInitFunc) tny_msg_view_init, /* interface_init */
391                   NULL,         /* interface_finalize */
392                   NULL          /* interface_data */
393                 };
394
395                 static const GInterfaceInfo tny_mime_part_view_info =
396                 {
397                   (GInterfaceInitFunc) tny_mime_part_view_init, /* interface_init */
398                   NULL,         /* interface_finalize */
399                   NULL          /* interface_data */
400                 };
401
402                 type = g_type_register_static (GTK_TYPE_VBOX,
403                         "TMutMsgView",
404                         &info, 0);
405
406                 g_type_add_interface_static (type, TNY_TYPE_MIME_PART_VIEW,
407                         &tny_mime_part_view_info);
408
409                 g_type_add_interface_static (type, TNY_TYPE_MSG_VIEW,
410                         &tny_msg_view_info);
411
412                 g_type_add_interface_static (type, TMUT_TYPE_SHELL_CHILD,
413                         &tmut_shell_child_info);
414
415         }
416
417         return type;
418 }
Note: See TracBrowser for help on using the browser.