* remove unneeded files
[modest] / src / modest-viewer-window.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
31 #include "modest-ui.h"
32 #include "widgets/modest-msg-view.h"
33 #include "modest-viewer-window.h"
34
35
36 /* 'private'/'protected' functions */
37 static void                      modest_viewer_window_class_init    (ModestViewerWindowClass *klass);
38 static void                      modest_viewer_window_init          (ModestViewerWindow *obj);
39 static void                      modest_viewer_window_finalize      (GObject *obj);
40
41 /* list my signals */
42 enum {
43         LAST_SIGNAL
44 };
45
46 typedef struct _ModestViewerWindowPrivate ModestViewerWindowPrivate;
47 struct _ModestViewerWindowPrivate {
48         ModestMsgView *msg_view;
49         gpointer      user_data;
50 };
51 #define MODEST_VIEWER_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
52                                                   MODEST_TYPE_VIEWER_WINDOW, \
53                                                   ModestViewerWindowPrivate))
54 /* globals */
55 static GtkWindowClass *parent_class = NULL;
56
57
58 GType
59 modest_viewer_window_get_type (void)
60 {
61         static GType my_type = 0;
62         if (!my_type) {
63                 static const GTypeInfo my_info = {
64                         sizeof(ModestViewerWindowClass),
65                         NULL,           /* base init */
66                         NULL,           /* base finalize */
67                         (GClassInitFunc) modest_viewer_window_class_init,
68                         NULL,           /* class finalize */
69                         NULL,           /* class data */
70                         sizeof(ModestViewerWindow),
71                         1,              /* n_preallocs */
72                         (GInstanceInitFunc) modest_viewer_window_init,
73                 };
74                 my_type = g_type_register_static (GTK_TYPE_WINDOW,
75                                                   "ModestViewerWindow",
76                                                   &my_info, 0);
77         }
78         return my_type;
79 }
80
81 static void
82 modest_viewer_window_class_init (ModestViewerWindowClass *klass)
83 {
84         GObjectClass *gobject_class;
85         gobject_class = (GObjectClass*) klass;
86
87         parent_class            = g_type_class_peek_parent (klass);
88         gobject_class->finalize = modest_viewer_window_finalize;
89
90         g_type_class_add_private (gobject_class, sizeof(ModestViewerWindowPrivate));
91
92         /* signal definitions go here, e.g.: */
93 /*      signals[MY_SIGNAL_1] = */
94 /*              g_signal_new ("my_signal_1",....); */
95 /*      signals[MY_SIGNAL_2] = */
96 /*              g_signal_new ("my_signal_2",....); */
97 /*      etc. */
98 }
99
100
101 static void
102 modest_viewer_window_init (ModestViewerWindow *obj)
103 {
104         ModestViewerWindowPrivate *priv = MODEST_VIEWER_WINDOW_GET_PRIVATE(obj);
105
106         priv->user_data = NULL;
107         priv->msg_view = NULL;
108 }
109
110
111 static void
112 modest_viewer_window_finalize (GObject *obj)
113 {
114         ModestViewerWindowPrivate *priv;
115
116         priv = MODEST_VIEWER_WINDOW_GET_PRIVATE(obj);
117                 
118         if (priv->user_data)
119                 g_free(priv->user_data);
120
121         G_OBJECT_CLASS(parent_class)->finalize (obj);
122 }
123
124
125 GtkWidget*
126 modest_viewer_window_new (ModestUI *ui, TnyMsgIface *msg)
127 {
128         GObject *self;
129         ModestViewerWindowPrivate *priv;
130         GtkWidget *w;
131         gpointer data;
132         GtkWidget *msg_view;
133
134         self = G_OBJECT(g_object_new(MODEST_TYPE_VIEWER_WINDOW, NULL));
135         priv = MODEST_VIEWER_WINDOW_GET_PRIVATE(self);
136
137         msg_view = modest_msg_view_new(msg);
138
139         data = NULL;
140         w = GTK_WIDGET(modest_ui_new_viewer_window(ui, msg_view, msg, &data));
141         if (!w)
142                 return NULL;
143         if (!data)
144                 g_message("viewer window user data is emtpy");
145
146         gtk_container_add(GTK_CONTAINER(self), w);
147         priv->user_data = data;
148         priv->msg_view = MODEST_MSG_VIEW(msg_view);
149
150         return GTK_WIDGET(self);
151 }
152
153
154 /*
155  * return user defined data from a ModestViewerWindow instance
156  * like e.g. a refernce to a GladeXML*
157  */
158 gpointer
159 modest_viewer_window_get_data(ModestViewerWindow *viewer_win)
160 {
161         ModestViewerWindowPrivate *priv;
162
163         g_return_val_if_fail (viewer_win, NULL);
164
165         priv = MODEST_VIEWER_WINDOW_GET_PRIVATE(viewer_win);
166
167         return priv->user_data;
168 }
169
170
171 ModestMsgView*
172 modest_viewer_window_get_tiny_msg_view(ModestViewerWindow *viewer_win)
173 {
174         ModestViewerWindowPrivate *priv;
175
176         g_return_val_if_fail (viewer_win, NULL);
177         
178         priv = MODEST_VIEWER_WINDOW_GET_PRIVATE(viewer_win);
179
180         return priv->msg_view;
181 }