root/trunk/src/tmut-shell-window.c

Revision 73 (checked in by pvanhoof, 9 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
21 #if HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <glib/gi18n-lib.h>
26
27 #include "tmut-shell-window.h"
28
29 static GObjectClass *parent_class = NULL;
30
31 typedef struct _TMutShellWindowPriv TMutShellWindowPriv;
32
33 typedef struct {
34         TMutShellChild *child;
35         const gchar *instruction;
36 } ChildSet;
37
38 struct _TMutShellWindowPriv {
39         GtkWidget *vbox;
40         GtkLabel *instruction_label;
41         GtkProgressBar *progress_bar;
42         GList *childs;
43         ChildSet *current;
44 };
45
46 #define TMUT_SHELL_WINDOW_GET_PRIVATE(o) \
47         (G_TYPE_INSTANCE_GET_PRIVATE ((o), TMUT_TYPE_SHELL_WINDOW, TMutShellWindowPriv))
48
49
50 static void
51 tmut_shell_window_set_child_default (TMutShellWindow *self, TMutShellChild *child, const gchar *instruction)
52 {
53         TMutShellWindowPriv *priv = TMUT_SHELL_WINDOW_GET_PRIVATE (self);
54         ChildSet *set = g_slice_new0 (ChildSet);
55
56         if (priv->current && priv->current->child)
57                 gtk_container_remove (GTK_CONTAINER (priv->vbox), GTK_WIDGET (priv->current->child));
58
59         set->child = g_object_ref (child);
60         set->instruction = instruction;
61
62         priv->childs = g_list_prepend (priv->childs, set); /* A */
63         priv->current = set;
64
65         gtk_box_pack_start (GTK_BOX (priv->vbox), GTK_WIDGET (set->child),
66                 TRUE, TRUE, 0);
67
68         if (set->instruction) {
69                 gtk_label_set_text (priv->instruction_label, set->instruction);
70                 gtk_widget_show (GTK_WIDGET (priv->instruction_label));
71         } else
72                 gtk_widget_hide (GTK_WIDGET (priv->instruction_label));
73
74         tmut_shell_child_set_window (set->child, self);
75
76         return;
77 }
78
79
80 static void
81 tmut_shell_window_back_default (TMutShellWindow *self)
82 {
83         TMutShellWindowPriv *priv = TMUT_SHELL_WINDOW_GET_PRIVATE (self);
84         GList *first = NULL;
85         gint cnt = g_list_length (priv->childs);
86
87         if (cnt > 1)
88         {
89                 if (priv->current && priv->current->child) {
90                         gtk_container_remove (GTK_CONTAINER (priv->vbox), GTK_WIDGET (priv->current->child));
91                         if (G_IS_OBJECT (priv->current->child))
92                                 g_object_unref (priv->current->child); /* A */
93                 }
94                 priv->childs = g_list_remove (priv->childs, priv->current);
95
96                 first = g_list_first (priv->childs);
97                
98                 g_slice_free (ChildSet, priv->current);
99                 priv->current = first->data;
100                 gtk_box_pack_start (GTK_BOX (priv->vbox), GTK_WIDGET (priv->current->child),
101                         TRUE, TRUE, 0);
102
103                 if (priv->current->instruction) {
104                         gtk_label_set_text (priv->instruction_label, priv->current->instruction);
105                         gtk_widget_show (GTK_WIDGET (priv->instruction_label));
106                 } else
107                         gtk_widget_hide (GTK_WIDGET (priv->instruction_label));
108
109                 }
110 }
111
112 static void
113 on_back_clicked (GtkButton *button, gpointer user_data)
114 {
115         tmut_shell_window_back ((TMutShellWindow *) user_data);
116         return;
117 }
118
119
120 /**
121  * tmut_shell_window_new:
122  * Create a GtkWindow that implements #TnyShellWindow
123  *
124  * Return value: a new #TnyShellWindow instance implemented for Gtk+
125  **/
126 TMutShellWindow *
127 tmut_shell_window_new (void)
128 {
129         TMutShellWindow *self = g_object_new (TMUT_TYPE_SHELL_WINDOW, NULL);
130
131         return TMUT_SHELL_WINDOW (self);
132 }
133
134
135 static GtkProgress*
136 tmut_shell_window_get_progress_default (TMutShellWindow *self)
137 {
138         TMutShellWindowPriv *priv = TMUT_SHELL_WINDOW_GET_PRIVATE (self);
139
140         return GTK_PROGRESS (priv->progress_bar);
141 }
142
143
144 static void
145 tmut_shell_window_instantiate_default (TMutShellWindow *instance)
146 {
147         TMutShellWindowPriv *priv = TMUT_SHELL_WINDOW_GET_PRIVATE (instance);
148
149         GtkWidget *hbox, *vvbox, *back_button;
150
151         priv->vbox = gtk_vbox_new (FALSE, 0);
152         hbox = gtk_hbox_new (FALSE, 0);
153         vvbox = gtk_vbox_new (FALSE, 0);
154         back_button = gtk_button_new_with_label (_("<"));
155         priv->progress_bar = GTK_PROGRESS_BAR (gtk_progress_bar_new ());
156         priv->instruction_label = GTK_LABEL (gtk_label_new (""));
157
158         gtk_widget_show (GTK_WIDGET (priv->progress_bar));
159         gtk_widget_show (back_button);
160         gtk_widget_hide (GTK_WIDGET (priv->instruction_label));
161         gtk_widget_show (priv->vbox);
162         gtk_widget_show (hbox);
163         gtk_widget_show (vvbox);
164
165         gtk_misc_set_alignment (GTK_MISC (priv->instruction_label), 0, 0);
166
167         gtk_box_pack_start (GTK_BOX (priv->vbox), GTK_WIDGET (hbox),
168                 FALSE, FALSE, 0);
169         gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (vvbox),
170                 TRUE, TRUE, 0);
171         gtk_box_pack_start (GTK_BOX (vvbox), GTK_WIDGET (priv->progress_bar),
172                 TRUE, TRUE, 0);
173         gtk_box_pack_start (GTK_BOX (vvbox), GTK_WIDGET (priv->instruction_label),
174                 FALSE, FALSE, 0);
175         gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (back_button),
176                 FALSE, FALSE, 0);
177
178         gtk_container_add (GTK_CONTAINER (instance), GTK_WIDGET (priv->vbox));
179
180         g_signal_connect (G_OBJECT (back_button), "clicked",
181                 G_CALLBACK (on_back_clicked), instance);
182 }
183
184 GtkProgress*
185 tmut_shell_window_get_progress (TMutShellWindow *self)
186 {
187         return TMUT_SHELL_WINDOW_GET_CLASS (self)->get_progress (self);
188 }
189
190 void 
191 tmut_shell_window_back (TMutShellWindow *self)
192 {
193         TMUT_SHELL_WINDOW_GET_CLASS (self)->back (self);
194         return;
195 }
196
197 void 
198 tmut_shell_window_set_child (TMutShellWindow *self, TMutShellChild *child, const gchar *instruction)
199 {
200         TMUT_SHELL_WINDOW_GET_CLASS (self)->set_child (self, child, instruction);
201         return;
202 }
203
204 static void
205 tmut_shell_window_instance_init (GTypeInstance *instance, gpointer g_class)
206 {
207         if (TMUT_SHELL_WINDOW_GET_CLASS (instance)->instantiate)
208                 TMUT_SHELL_WINDOW_GET_CLASS (instance)->instantiate ((TMutShellWindow *) instance);
209
210         return;
211 }
212
213 static void
214 foreach_childset (gpointer data, gpointer user_data)
215 {
216         ChildSet *set = (ChildSet *) data;
217         g_object_unref (set->child);
218         g_slice_free (ChildSet, set);
219         return;
220 }
221
222 static void
223 tmut_shell_window_finalize (GObject *object)
224 {
225         TMutShellWindowPriv *priv = TMUT_SHELL_WINDOW_GET_PRIVATE (object);
226
227         if (priv->childs) {
228                 g_list_foreach (priv->childs, foreach_childset, NULL);
229                 g_list_free (priv->childs);
230                 priv->childs = NULL;
231         }
232
233         (*parent_class->finalize) (object);
234
235         return;
236 }
237
238
239 static void
240 tmut_shell_window_class_init (TMutShellWindowClass *class)
241 {
242         GObjectClass *object_class;
243
244         parent_class = g_type_class_peek_parent (class);
245         object_class = (GObjectClass*) class;
246
247         class->back= tmut_shell_window_back_default;
248         class->set_child= tmut_shell_window_set_child_default;
249         class->get_progress= tmut_shell_window_get_progress_default;
250         class->instantiate= tmut_shell_window_instantiate_default;
251
252         object_class->finalize = tmut_shell_window_finalize;
253
254         g_type_class_add_private (object_class, sizeof (TMutShellWindowPriv));
255
256         return;
257 }
258
259 GType
260 tmut_shell_window_get_type (void)
261 {
262         static GType type = 0;
263
264         if (G_UNLIKELY(type == 0))
265         {
266                 static const GTypeInfo info =
267                 {
268                   sizeof (TMutShellWindowClass),
269                   NULL,   /* base_init */
270                   NULL,   /* base_finalize */
271                   (GClassInitFunc) tmut_shell_window_class_init,   /* class_init */
272                   NULL,   /* class_finalize */
273                   NULL,   /* class_data */
274                   sizeof (TMutShellWindow),
275                   0,      /* n_preallocs */
276                   tmut_shell_window_instance_init,    /* instance_init */
277                   NULL
278                 };
279
280                 type = g_type_register_static (GTK_TYPE_WINDOW,
281                         "TMutShellWindow",
282                         &info, 0);
283         }
284
285         return type;
286 }
Note: See TracBrowser for help on using the browser.