bcbf561e170132c5d27fbd7197961d955a458865
[modest] / src / widgets / modest-msg-view.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include <config.h>
31
32 #include <widgets/modest-msg-view.h>
33 #include <widgets/modest-isearch-view.h>
34 #include <modest-marshal.h>
35
36 enum {
37         ATTACHMENT_CLICKED_SIGNAL,
38         RECPT_ACTIVATED_SIGNAL,
39         LINK_CONTEXTUAL_SIGNAL,
40         FETCH_IMAGE_SIGNAL,
41         SHOW_DETAILS_SIGNAL,
42         LAST_SIGNAL
43 };
44 static guint signals[LAST_SIGNAL] = {0};
45
46 void
47 modest_msg_view_set_msg_with_other_body (ModestMsgView *self, TnyMsg *msg, TnyMimePart *part)
48 {
49         return MODEST_MSG_VIEW_GET_IFACE (self)->set_msg_with_other_body_func (self, msg, part);
50 }
51
52 GtkAdjustment*
53 modest_msg_view_get_vadjustment (ModestMsgView *self)
54 {
55         return MODEST_MSG_VIEW_GET_IFACE (self)->get_vadjustment_func (self);
56 }
57
58 GtkAdjustment*
59 modest_msg_view_get_hadjustment (ModestMsgView *self)
60 {
61         return MODEST_MSG_VIEW_GET_IFACE (self)->get_hadjustment_func (self);
62 }
63
64 void
65 modest_msg_view_set_vadjustment (ModestMsgView *self, GtkAdjustment *vadj)
66 {
67         MODEST_MSG_VIEW_GET_IFACE (self)->set_vadjustment_func (self, vadj);
68 }
69
70 void
71 modest_msg_view_set_hadjustment (ModestMsgView *self, GtkAdjustment *hadj)
72 {
73         MODEST_MSG_VIEW_GET_IFACE (self)->set_hadjustment_func (self, hadj);
74 }
75
76 void
77 modest_msg_view_set_shadow_type (ModestMsgView *self, GtkShadowType type)
78 {
79         MODEST_MSG_VIEW_GET_IFACE (self)->set_shadow_type_func (self, type);
80 }
81
82 GtkShadowType
83 modest_msg_view_get_shadow_type (ModestMsgView *self)
84 {
85         return MODEST_MSG_VIEW_GET_IFACE (self)->get_shadow_type_func (self);
86 }
87
88 TnyHeaderFlags
89 modest_msg_view_get_priority (ModestMsgView *self)
90 {
91         return MODEST_MSG_VIEW_GET_IFACE (self)->get_priority_func (self);
92 }
93
94 void
95 modest_msg_view_set_priority (ModestMsgView *self, TnyHeaderFlags flags)
96 {
97         MODEST_MSG_VIEW_GET_IFACE (self)->set_priority_func (self, flags);
98 }
99
100 void
101 modest_msg_view_set_view_images (ModestMsgView *self, gboolean view_images)
102 {
103         MODEST_MSG_VIEW_GET_IFACE (self)->set_view_images_func (self, view_images);
104 }
105
106 TnyList*
107 modest_msg_view_get_selected_attachments (ModestMsgView *self)
108 {
109         return MODEST_MSG_VIEW_GET_IFACE (self)->get_selected_attachments_func (self);
110 }
111
112 TnyList*
113 modest_msg_view_get_attachments (ModestMsgView *self)
114 {
115         return MODEST_MSG_VIEW_GET_IFACE (self)->get_attachments_func (self);
116 }
117
118 void
119 modest_msg_view_grab_focus (ModestMsgView *self)
120 {
121         MODEST_MSG_VIEW_GET_IFACE (self)->grab_focus_func (self);
122 }
123
124 void
125 modest_msg_view_remove_attachment (ModestMsgView *self, TnyMimePart *attachment)
126 {
127         MODEST_MSG_VIEW_GET_IFACE (self)->remove_attachment_func (self, attachment);
128 }
129
130 void
131 modest_msg_view_set_branding (ModestMsgView *self, const gchar *brand_name, const GdkPixbuf *brand_icon)
132 {
133         MODEST_MSG_VIEW_GET_IFACE (self)->set_branding_func (self, brand_name, brand_icon);
134 }
135
136 void
137 modest_msg_view_request_fetch_images (ModestMsgView *self)
138 {
139         MODEST_MSG_VIEW_GET_IFACE (self)->request_fetch_images_func (self);
140 }
141
142 gboolean
143 modest_msg_view_has_blocked_external_images (ModestMsgView *self)
144 {
145         return MODEST_MSG_VIEW_GET_IFACE (self)->has_blocked_external_images_func (self);
146 }
147
148 static void
149 modest_msg_view_base_init (gpointer g_class)
150 {
151         static gboolean initialized = FALSE;
152
153         if (!initialized) {
154                 
155                 signals[ATTACHMENT_CLICKED_SIGNAL] =
156                         g_signal_new ("attachment_clicked",
157                                       MODEST_TYPE_MSG_VIEW,
158                                       G_SIGNAL_RUN_FIRST,
159                                       G_STRUCT_OFFSET(ModestMsgViewIface, attachment_clicked),
160                                       NULL, NULL,
161                                       g_cclosure_marshal_VOID__OBJECT,
162                                       G_TYPE_NONE, 1, G_TYPE_OBJECT);
163                 
164                 signals[RECPT_ACTIVATED_SIGNAL] =
165                         g_signal_new ("recpt_activated",
166                                       MODEST_TYPE_MSG_VIEW,
167                                       G_SIGNAL_RUN_FIRST,
168                                       G_STRUCT_OFFSET(ModestMsgViewIface, recpt_activated),
169                                       NULL, NULL,
170                                       g_cclosure_marshal_VOID__STRING,
171                                       G_TYPE_NONE, 1, G_TYPE_STRING);
172                 
173                 signals[LINK_CONTEXTUAL_SIGNAL] =
174                         g_signal_new ("link_contextual",
175                                       MODEST_TYPE_MSG_VIEW,
176                                       G_SIGNAL_RUN_FIRST,
177                                       G_STRUCT_OFFSET(ModestMsgViewIface, link_contextual),
178                                       NULL, NULL,
179                                       g_cclosure_marshal_VOID__STRING,
180                                       G_TYPE_NONE, 1, G_TYPE_STRING);
181                 
182                 signals[FETCH_IMAGE_SIGNAL] =
183                         g_signal_new ("fetch_image",
184                                       MODEST_TYPE_MSG_VIEW,
185                                       G_SIGNAL_ACTION | G_SIGNAL_RUN_LAST,
186                                       G_STRUCT_OFFSET(ModestMsgViewIface, fetch_image),
187                                       NULL, NULL,
188                                       modest_marshal_BOOLEAN__STRING_OBJECT,
189                                       G_TYPE_BOOLEAN, 2, G_TYPE_STRING, G_TYPE_OBJECT);
190                 
191                 signals[SHOW_DETAILS_SIGNAL] =
192                         g_signal_new ("show_details",
193                                       MODEST_TYPE_MSG_VIEW,
194                                       G_SIGNAL_RUN_FIRST,
195                                       G_STRUCT_OFFSET(ModestMsgViewIface, show_details),
196                                       NULL, NULL,
197                                       g_cclosure_marshal_VOID__VOID,
198                                       G_TYPE_NONE, 0);
199                 
200                 initialized = TRUE;
201         }
202 }
203
204 GType
205 modest_msg_view_get_type (void)
206 {
207         static GType my_type = 0;
208         if (!my_type) {
209                 static const GTypeInfo my_info = {
210                         sizeof(ModestMsgViewIface),
211                         modest_msg_view_base_init,   /* base init */
212                         NULL,           /* base finalize */
213                         NULL,           /* class_init */
214                         NULL,           /* class finalize */
215                         NULL,           /* class data */
216                         0,
217                         0,              /* n_preallocs */
218                         NULL,           /* instance_init */
219                         NULL
220                 };
221
222                 my_type = g_type_register_static (G_TYPE_INTERFACE,
223                                                   "ModestMsgView",
224                                                   &my_info, 0);
225
226                 g_type_interface_add_prerequisite (my_type,
227                                                    MODEST_TYPE_ZOOMABLE);
228                 g_type_interface_add_prerequisite (my_type,
229                                                    MODEST_TYPE_ISEARCH_VIEW);
230                 g_type_interface_add_prerequisite (my_type,
231                                                    TNY_TYPE_MIME_PART_VIEW);
232                 g_type_interface_add_prerequisite (my_type,
233                                                    TNY_TYPE_HEADER_VIEW);
234                 g_type_interface_add_prerequisite (my_type,
235                                                    MODEST_TYPE_MIME_PART_VIEW);
236
237         }
238         return my_type;
239 }