1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
31 /* modest-window-mgr.c */
33 #include "modest-window-mgr.h"
34 /* include other impl specific header files */
36 /* 'private'/'protected' functions */
37 static void modest_window_mgr_class_init (ModestWindowMgrClass *klass);
38 static void modest_window_mgr_init (ModestWindowMgr *obj);
39 static void modest_window_mgr_finalize (GObject *obj);
45 LAST_WINDOW_CLOSED_SIGNAL,
49 typedef struct _ModestWindowMgrPrivate ModestWindowMgrPrivate;
50 struct _ModestWindowMgrPrivate {
54 #define MODEST_WINDOW_MGR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
55 MODEST_TYPE_WINDOW_MGR, \
56 ModestWindowMgrPrivate))
58 static GObjectClass *parent_class = NULL;
60 static guint signals[LAST_SIGNAL] = {0};
63 modest_window_mgr_get_type (void)
65 static GType my_type = 0;
67 static const GTypeInfo my_info = {
68 sizeof(ModestWindowMgrClass),
70 NULL, /* base finalize */
71 (GClassInitFunc) modest_window_mgr_class_init,
72 NULL, /* class finalize */
73 NULL, /* class data */
74 sizeof(ModestWindowMgr),
76 (GInstanceInitFunc) modest_window_mgr_init,
78 my_type = g_type_register_static (G_TYPE_OBJECT,
86 modest_window_mgr_class_init (ModestWindowMgrClass *klass)
88 GObjectClass *gobject_class;
89 gobject_class = (GObjectClass*) klass;
91 parent_class = g_type_class_peek_parent (klass);
92 gobject_class->finalize = modest_window_mgr_finalize;
94 g_type_class_add_private (gobject_class, sizeof(ModestWindowMgrPrivate));
96 signals[LAST_WINDOW_CLOSED_SIGNAL] =
97 g_signal_new ("last_window_closed",
98 G_TYPE_FROM_CLASS(gobject_class),
100 G_STRUCT_OFFSET(ModestWindowMgrClass, last_window_closed),
102 g_cclosure_marshal_VOID__VOID,
107 modest_window_mgr_init (ModestWindowMgr *obj)
109 ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE(obj);
110 priv->open_windows = NULL;
114 modest_window_mgr_finalize (GObject *obj)
116 ModestWindowMgrPrivate *priv = MODEST_WINDOW_MGR_GET_PRIVATE(obj);
117 g_slist_free (priv->open_windows);
118 priv->open_windows = NULL;
122 modest_window_mgr_new (void)
124 return G_OBJECT(g_object_new(MODEST_TYPE_WINDOW_MGR, NULL));
127 /* insert many other interesting function implementations */
128 /* such as modest_window_mgr_do_something, or modest_window_mgr_has_foo */
131 modest_window_mgr_register (ModestWindowMgr *self, GObject *win,
132 ModestWindowType type,
135 ModestOpenWindow *openwin = NULL;
136 ModestWindowMgrPrivate *priv;
138 g_return_val_if_fail (self, FALSE);
139 g_return_val_if_fail (type==MODEST_MAIN_WINDOW || type==MODEST_EDIT_WINDOW
140 || type == MODEST_VIEW_WINDOW, FALSE);
142 priv = MODEST_WINDOW_MGR_GET_PRIVATE(self);
144 openwin = g_new (ModestOpenWindow, 1);
146 openwin->type = type;
147 openwin->id = window_id;
149 priv->open_windows = g_slist_prepend (priv->open_windows, openwin);
157 modest_window_mgr_unregister (ModestWindowMgr *self, GObject *win)
159 ModestWindowMgrPrivate *priv;
161 gboolean found = FALSE;
163 g_return_val_if_fail (self, FALSE);
164 g_return_val_if_fail (win, FALSE);
166 priv = MODEST_WINDOW_MGR_GET_PRIVATE(self);
168 cursor = priv->open_windows;
170 if (((ModestOpenWindow*)cursor->data)->win == win) {
171 priv->open_windows = g_slist_delete_link (priv->open_windows,
176 cursor = cursor->next;
179 guint win_num = g_slist_length (priv->open_windows);
181 g_signal_emit (self, signals[LAST_WINDOW_CLOSED_SIGNAL],
190 modest_window_mgr_find_by_type (ModestWindowMgr *self, ModestWindowType type)
192 ModestWindowMgrPrivate *priv;
195 g_return_val_if_fail (self, NULL);
197 priv = MODEST_WINDOW_MGR_GET_PRIVATE(self);
198 cursor = priv->open_windows;
200 ModestOpenWindow *openwin = (ModestOpenWindow*)cursor->data;
201 if (openwin->type == type)
203 cursor = cursor->next;
211 modest_window_mgr_find_by_id (ModestWindowMgr *self, gint window_id)
213 ModestWindowMgrPrivate *priv;
216 g_return_val_if_fail (self, NULL);
218 priv = MODEST_WINDOW_MGR_GET_PRIVATE(self);
219 cursor = priv->open_windows;
221 ModestOpenWindow *openwin = (ModestOpenWindow*)cursor->data;
222 if (openwin->id == window_id)
224 cursor = cursor->next;