/* TMut * Copyright (C) 2006-2007 Philip Van Hoof * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with self library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #if HAVE_CONFIG_H #include "config.h" #endif #include #include "tmut-shell-window.h" static GObjectClass *parent_class = NULL; typedef struct _TMutShellWindowPriv TMutShellWindowPriv; typedef struct { TMutShellChild *child; const gchar *instruction; } ChildSet; struct _TMutShellWindowPriv { GtkWidget *vbox; GtkLabel *instruction_label; GtkProgressBar *progress_bar; GList *childs; ChildSet *current; }; #define TMUT_SHELL_WINDOW_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), TMUT_TYPE_SHELL_WINDOW, TMutShellWindowPriv)) static void tmut_shell_window_set_child_default (TMutShellWindow *self, TMutShellChild *child, const gchar *instruction) { TMutShellWindowPriv *priv = TMUT_SHELL_WINDOW_GET_PRIVATE (self); ChildSet *set = g_slice_new0 (ChildSet); if (priv->current && priv->current->child) gtk_container_remove (GTK_CONTAINER (priv->vbox), GTK_WIDGET (priv->current->child)); set->child = g_object_ref (child); set->instruction = instruction; priv->childs = g_list_prepend (priv->childs, set); /* A */ priv->current = set; gtk_box_pack_start (GTK_BOX (priv->vbox), GTK_WIDGET (set->child), TRUE, TRUE, 0); if (set->instruction) { gtk_label_set_text (priv->instruction_label, set->instruction); gtk_widget_show (GTK_WIDGET (priv->instruction_label)); } else gtk_widget_hide (GTK_WIDGET (priv->instruction_label)); tmut_shell_child_set_window (set->child, self); return; } static void tmut_shell_window_back_default (TMutShellWindow *self) { TMutShellWindowPriv *priv = TMUT_SHELL_WINDOW_GET_PRIVATE (self); GList *first = NULL; gint cnt = g_list_length (priv->childs); if (cnt > 1) { if (priv->current && priv->current->child) { gtk_container_remove (GTK_CONTAINER (priv->vbox), GTK_WIDGET (priv->current->child)); if (G_IS_OBJECT (priv->current->child)) g_object_unref (priv->current->child); /* A */ } priv->childs = g_list_remove (priv->childs, priv->current); first = g_list_first (priv->childs); g_slice_free (ChildSet, priv->current); priv->current = first->data; gtk_box_pack_start (GTK_BOX (priv->vbox), GTK_WIDGET (priv->current->child), TRUE, TRUE, 0); if (priv->current->instruction) { gtk_label_set_text (priv->instruction_label, priv->current->instruction); gtk_widget_show (GTK_WIDGET (priv->instruction_label)); } else gtk_widget_hide (GTK_WIDGET (priv->instruction_label)); } } static void on_back_clicked (GtkButton *button, gpointer user_data) { tmut_shell_window_back ((TMutShellWindow *) user_data); return; } /** * tmut_shell_window_new: * Create a GtkWindow that implements #TnyShellWindow * * Return value: a new #TnyShellWindow instance implemented for Gtk+ **/ TMutShellWindow * tmut_shell_window_new (void) { TMutShellWindow *self = g_object_new (TMUT_TYPE_SHELL_WINDOW, NULL); return TMUT_SHELL_WINDOW (self); } static GtkProgress* tmut_shell_window_get_progress_default (TMutShellWindow *self) { TMutShellWindowPriv *priv = TMUT_SHELL_WINDOW_GET_PRIVATE (self); return GTK_PROGRESS (priv->progress_bar); } static void tmut_shell_window_instantiate_default (TMutShellWindow *instance) { TMutShellWindowPriv *priv = TMUT_SHELL_WINDOW_GET_PRIVATE (instance); GtkWidget *hbox, *vvbox, *back_button; priv->vbox = gtk_vbox_new (FALSE, 0); hbox = gtk_hbox_new (FALSE, 0); vvbox = gtk_vbox_new (FALSE, 0); back_button = gtk_button_new_with_label (_("<")); priv->progress_bar = GTK_PROGRESS_BAR (gtk_progress_bar_new ()); priv->instruction_label = GTK_LABEL (gtk_label_new ("")); gtk_widget_show (GTK_WIDGET (priv->progress_bar)); gtk_widget_show (back_button); gtk_widget_hide (GTK_WIDGET (priv->instruction_label)); gtk_widget_show (priv->vbox); gtk_widget_show (hbox); gtk_widget_show (vvbox); gtk_misc_set_alignment (GTK_MISC (priv->instruction_label), 0, 0); gtk_box_pack_start (GTK_BOX (priv->vbox), GTK_WIDGET (hbox), FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (vvbox), TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vvbox), GTK_WIDGET (priv->progress_bar), TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vvbox), GTK_WIDGET (priv->instruction_label), FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (back_button), FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (instance), GTK_WIDGET (priv->vbox)); g_signal_connect (G_OBJECT (back_button), "clicked", G_CALLBACK (on_back_clicked), instance); } GtkProgress* tmut_shell_window_get_progress (TMutShellWindow *self) { return TMUT_SHELL_WINDOW_GET_CLASS (self)->get_progress (self); } void tmut_shell_window_back (TMutShellWindow *self) { TMUT_SHELL_WINDOW_GET_CLASS (self)->back (self); return; } void tmut_shell_window_set_child (TMutShellWindow *self, TMutShellChild *child, const gchar *instruction) { TMUT_SHELL_WINDOW_GET_CLASS (self)->set_child (self, child, instruction); return; } static void tmut_shell_window_instance_init (GTypeInstance *instance, gpointer g_class) { if (TMUT_SHELL_WINDOW_GET_CLASS (instance)->instantiate) TMUT_SHELL_WINDOW_GET_CLASS (instance)->instantiate ((TMutShellWindow *) instance); return; } static void foreach_childset (gpointer data, gpointer user_data) { ChildSet *set = (ChildSet *) data; g_object_unref (set->child); g_slice_free (ChildSet, set); return; } static void tmut_shell_window_finalize (GObject *object) { TMutShellWindowPriv *priv = TMUT_SHELL_WINDOW_GET_PRIVATE (object); if (priv->childs) { g_list_foreach (priv->childs, foreach_childset, NULL); g_list_free (priv->childs); priv->childs = NULL; } (*parent_class->finalize) (object); return; } static void tmut_shell_window_class_init (TMutShellWindowClass *class) { GObjectClass *object_class; parent_class = g_type_class_peek_parent (class); object_class = (GObjectClass*) class; class->back= tmut_shell_window_back_default; class->set_child= tmut_shell_window_set_child_default; class->get_progress= tmut_shell_window_get_progress_default; class->instantiate= tmut_shell_window_instantiate_default; object_class->finalize = tmut_shell_window_finalize; g_type_class_add_private (object_class, sizeof (TMutShellWindowPriv)); return; } GType tmut_shell_window_get_type (void) { static GType type = 0; if (G_UNLIKELY(type == 0)) { static const GTypeInfo info = { sizeof (TMutShellWindowClass), NULL, /* base_init */ NULL, /* base_finalize */ (GClassInitFunc) tmut_shell_window_class_init, /* class_init */ NULL, /* class_finalize */ NULL, /* class_data */ sizeof (TMutShellWindow), 0, /* n_preallocs */ tmut_shell_window_instance_init, /* instance_init */ NULL }; type = g_type_register_static (GTK_TYPE_WINDOW, "TMutShellWindow", &info, 0); } return type; }