Refactoring of mail header view.
[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 GtkAdjustment*
47 modest_msg_view_get_vadjustment (ModestMsgView *self)
48 {
49         return MODEST_MSG_VIEW_GET_IFACE (self)->get_vadjustment_func (self);
50 }
51
52 GtkAdjustment*
53 modest_msg_view_get_hadjustment (ModestMsgView *self)
54 {
55         return MODEST_MSG_VIEW_GET_IFACE (self)->get_hadjustment_func (self);
56 }
57
58 void
59 modest_msg_view_set_vadjustment (ModestMsgView *self, GtkAdjustment *vadj)
60 {
61         MODEST_MSG_VIEW_GET_IFACE (self)->set_vadjustment_func (self, vadj);
62 }
63
64 void
65 modest_msg_view_set_hadjustment (ModestMsgView *self, GtkAdjustment *hadj)
66 {
67         MODEST_MSG_VIEW_GET_IFACE (self)->set_hadjustment_func (self, hadj);
68 }
69
70 void
71 modest_msg_view_set_shadow_type (ModestMsgView *self, GtkShadowType type)
72 {
73         MODEST_MSG_VIEW_GET_IFACE (self)->set_shadow_type_func (self, type);
74 }
75
76 GtkShadowType
77 modest_msg_view_get_shadow_type (ModestMsgView *self)
78 {
79         return MODEST_MSG_VIEW_GET_IFACE (self)->get_shadow_type_func (self);
80 }
81
82 TnyHeaderFlags
83 modest_msg_view_get_priority (ModestMsgView *self)
84 {
85         return MODEST_MSG_VIEW_GET_IFACE (self)->get_priority_func (self);
86 }
87
88 void
89 modest_msg_view_set_priority (ModestMsgView *self, TnyHeaderFlags flags)
90 {
91         MODEST_MSG_VIEW_GET_IFACE (self)->set_priority_func (self, flags);
92 }
93
94 void
95 modest_msg_view_set_view_images (ModestMsgView *self, gboolean view_images)
96 {
97         MODEST_MSG_VIEW_GET_IFACE (self)->set_view_images_func (self, view_images);
98 }
99
100 TnyList*
101 modest_msg_view_get_selected_attachments (ModestMsgView *self)
102 {
103         return MODEST_MSG_VIEW_GET_IFACE (self)->get_selected_attachments_func (self);
104 }
105
106 TnyList*
107 modest_msg_view_get_attachments (ModestMsgView *self)
108 {
109         return MODEST_MSG_VIEW_GET_IFACE (self)->get_attachments_func (self);
110 }
111
112 void
113 modest_msg_view_grab_focus (ModestMsgView *self)
114 {
115         MODEST_MSG_VIEW_GET_IFACE (self)->grab_focus_func (self);
116 }
117
118 void
119 modest_msg_view_remove_attachment (ModestMsgView *self, TnyMimePart *attachment)
120 {
121         MODEST_MSG_VIEW_GET_IFACE (self)->remove_attachment_func (self, attachment);
122 }
123
124 static void
125 modest_msg_view_base_init (gpointer g_class)
126 {
127         static gboolean initialized = FALSE;
128
129         if (!initialized) {
130                 
131                 signals[ATTACHMENT_CLICKED_SIGNAL] =
132                         g_signal_new ("attachment_clicked",
133                                       MODEST_TYPE_MSG_VIEW,
134                                       G_SIGNAL_RUN_FIRST,
135                                       G_STRUCT_OFFSET(ModestMsgViewIface, attachment_clicked),
136                                       NULL, NULL,
137                                       g_cclosure_marshal_VOID__OBJECT,
138                                       G_TYPE_NONE, 1, G_TYPE_OBJECT);
139                 
140                 signals[RECPT_ACTIVATED_SIGNAL] =
141                         g_signal_new ("recpt_activated",
142                                       MODEST_TYPE_MSG_VIEW,
143                                       G_SIGNAL_RUN_FIRST,
144                                       G_STRUCT_OFFSET(ModestMsgViewIface, recpt_activated),
145                                       NULL, NULL,
146                                       g_cclosure_marshal_VOID__STRING,
147                                       G_TYPE_NONE, 1, G_TYPE_STRING);
148                 
149                 signals[LINK_CONTEXTUAL_SIGNAL] =
150                         g_signal_new ("link_contextual",
151                                       MODEST_TYPE_MSG_VIEW,
152                                       G_SIGNAL_RUN_FIRST,
153                                       G_STRUCT_OFFSET(ModestMsgViewIface, link_contextual),
154                                       NULL, NULL,
155                                       g_cclosure_marshal_VOID__STRING,
156                                       G_TYPE_NONE, 1, G_TYPE_STRING);
157                 
158                 signals[FETCH_IMAGE_SIGNAL] =
159                         g_signal_new ("fetch_image",
160                                       MODEST_TYPE_MSG_VIEW,
161                                       G_SIGNAL_ACTION | G_SIGNAL_RUN_LAST,
162                                       G_STRUCT_OFFSET(ModestMsgViewIface, fetch_image),
163                                       NULL, NULL,
164                                       modest_marshal_BOOLEAN__STRING_OBJECT,
165                                       G_TYPE_BOOLEAN, 2, G_TYPE_STRING, G_TYPE_OBJECT);
166                 
167                 signals[SHOW_DETAILS_SIGNAL] =
168                         g_signal_new ("show_details",
169                                       MODEST_TYPE_MSG_VIEW,
170                                       G_SIGNAL_RUN_FIRST,
171                                       G_STRUCT_OFFSET(ModestMsgViewIface, show_details),
172                                       NULL, NULL,
173                                       g_cclosure_marshal_VOID__VOID,
174                                       G_TYPE_NONE, 0);
175                 
176                 initialized = TRUE;
177         }
178 }
179
180 GType
181 modest_msg_view_get_type (void)
182 {
183         static GType my_type = 0;
184         if (!my_type) {
185                 static const GTypeInfo my_info = {
186                         sizeof(ModestMsgViewIface),
187                         modest_msg_view_base_init,   /* base init */
188                         NULL,           /* base finalize */
189                         NULL,           /* class_init */
190                         NULL,           /* class finalize */
191                         NULL,           /* class data */
192                         0,
193                         0,              /* n_preallocs */
194                         NULL,           /* instance_init */
195                         NULL
196                 };
197
198                 my_type = g_type_register_static (G_TYPE_INTERFACE,
199                                                   "ModestMsgView",
200                                                   &my_info, 0);
201
202                 g_type_interface_add_prerequisite (my_type,
203                                                    MODEST_TYPE_ZOOMABLE);
204                 g_type_interface_add_prerequisite (my_type,
205                                                    MODEST_TYPE_ISEARCH_VIEW);
206                 g_type_interface_add_prerequisite (my_type,
207                                                    TNY_TYPE_MIME_PART_VIEW);
208                 g_type_interface_add_prerequisite (my_type,
209                                                    MODEST_TYPE_MIME_PART_VIEW);
210
211         }
212         return my_type;
213 }