[network-manager-netbook] Inherit the applet widget from GtkNotebook



commit 8121368a6a79d56b367ca94a9a9c733ac0d67e51
Author: Tambet Ingo <tambet gmail com>
Date:   Fri Dec 11 09:42:12 2009 +0200

    Inherit the applet widget from GtkNotebook
    
    Makes it easier to switch pages for "Add new conneciton" etc, than show/hide
    widgets of a GtkBox.

 src/nmn-applet.c         |   30 +++++++++++++++---------------
 src/nmn-applet.h         |    4 ++--
 src/nmn-new-connection.c |   26 +++++++++++++++++++++++++-
 src/nmn-new-connection.h |    3 +++
 4 files changed, 45 insertions(+), 18 deletions(-)
---
diff --git a/src/nmn-applet.c b/src/nmn-applet.c
index f06c199..b6229d5 100644
--- a/src/nmn-applet.c
+++ b/src/nmn-applet.c
@@ -30,7 +30,7 @@
 #include "nmn-model.h"
 #include "nmn-list.h"
 
-G_DEFINE_TYPE (NmnApplet, nmn_applet, GTK_TYPE_VBOX)
+G_DEFINE_TYPE (NmnApplet, nmn_applet, GTK_TYPE_NOTEBOOK)
 
 enum {
     PROP_0,
@@ -61,6 +61,11 @@ typedef struct {
     gboolean disposed;
 } NmnAppletPrivate;
 
+enum {
+    PAGE_NETWORKS       = 0,
+    PAGE_ADD_CONNECTION = 1,
+};
+
 static void add_new_connection_hide (GtkWidget *widget, gpointer user_data);
 static void wifi_toggle_set_sensitive (NmnModel *model, GtkWidget *widget, gboolean suggested);
 
@@ -319,38 +324,31 @@ enable_network_setup (NmnApplet *applet)
     offline_toggled (priv->model, nmn_model_offline_mode_get_active (priv->model), applet);
 }
 
-/* add new connection button */
-
 static void
 add_new_connection_show (GtkButton *button,
                          gpointer user_data)
 {
-    NmnAppletPrivate *priv = GET_PRIVATE (user_data);
-
-    gtk_widget_hide (priv->pane);
-    gtk_widget_show (priv->new_dialog);
+    gtk_notebook_set_current_page (GTK_NOTEBOOK (user_data), PAGE_ADD_CONNECTION);
 }
 
 static void
 add_new_connection_hide (GtkWidget *widget,
                          gpointer user_data)
 {
-    NmnAppletPrivate *priv = GET_PRIVATE (user_data);
-
-    gtk_widget_hide (priv->new_dialog);
-    gtk_widget_show (priv->pane);
+    gtk_notebook_set_current_page (GTK_NOTEBOOK (user_data), PAGE_NETWORKS);
 }
 
+/* add new connection button */
+
 static void
 add_new_connection_setup (NmnApplet *applet)
 {
     NmnAppletPrivate *priv = GET_PRIVATE (applet);
 
     priv->new_dialog = nmn_new_connection_create (priv->model);
-    gtk_box_pack_end (GTK_BOX (applet), priv->new_dialog, TRUE, TRUE, 0);
+    gtk_notebook_append_page (GTK_NOTEBOOK (applet), priv->new_dialog, NULL);
     gtk_widget_modify_bg (priv->new_dialog, GTK_STATE_NORMAL, &gtk_widget_get_style (priv->new_dialog)->white);
-    g_signal_connect (priv->new_dialog, "hide", G_CALLBACK (add_new_connection_hide), applet);
-
+    g_signal_connect (priv->new_dialog, "close", G_CALLBACK (add_new_connection_hide), applet);
     g_signal_connect (priv->add_new_connection, "clicked", G_CALLBACK (add_new_connection_show), applet);
 }
 
@@ -381,9 +379,11 @@ nmn_applet_init (NmnApplet *applet)
     GtkWidget *table;
     char *label;
 
+    gtk_notebook_set_show_tabs (GTK_NOTEBOOK (applet), FALSE);
+
     priv->pane = gtk_hbox_new (FALSE, 6);
     gtk_container_set_border_width (GTK_CONTAINER (priv->pane), 6);
-    gtk_box_pack_start (GTK_BOX (applet), priv->pane, TRUE, TRUE, 0);
+    gtk_notebook_append_page (GTK_NOTEBOOK (applet), priv->pane, NULL);
 
     /* left side (Networks list, add new connection button) */
     vbox = gtk_vbox_new (FALSE, 6);
diff --git a/src/nmn-applet.h b/src/nmn-applet.h
index f03cc15..97ba7f5 100644
--- a/src/nmn-applet.h
+++ b/src/nmn-applet.h
@@ -35,11 +35,11 @@ G_BEGIN_DECLS
 #define NMN_APPLET_MODEL "model"
 
 typedef struct {
-    GtkVBox parent;
+    GtkNotebook parent;
 } NmnApplet;
 
 typedef struct {
-    GtkVBoxClass parent;
+    GtkNotebookClass parent;
 } NmnAppletClass;
 
 GType nmn_applet_get_type (void);
diff --git a/src/nmn-new-connection.c b/src/nmn-new-connection.c
index febb291..3d625e4 100644
--- a/src/nmn-new-connection.c
+++ b/src/nmn-new-connection.c
@@ -48,6 +48,14 @@ enum {
     LAST_PROP
 };
 
+enum {
+    CLOSE,
+
+    LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
 #define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), NMN_TYPE_NEW_CONNECTION, NmnNewConnectionPrivate))
 
 typedef struct {
@@ -594,6 +602,12 @@ mobile_page_init (NmnNewConnection *connection)
 }
 
 static void
+close (NmnNewConnection *self)
+{
+    g_signal_emit (self, signals[CLOSE], 0);
+}
+
+static void
 nmn_new_connection_init (NmnNewConnection *self)
 {
     NmnNewConnectionPrivate *priv = GET_PRIVATE (self);
@@ -664,7 +678,7 @@ nmn_new_connection_init (NmnNewConnection *self)
     gtk_box_pack_start (GTK_BOX (self), w, FALSE, FALSE, 0);
     button = gtk_button_new_with_label (_("Return to Networking"));
     gtk_container_add (GTK_CONTAINER (w), button);
-    g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_hide), self);
+    g_signal_connect_swapped (button, "clicked", G_CALLBACK (close), self);
 
     gtk_widget_show_all (GTK_WIDGET (self));
 }
@@ -769,4 +783,14 @@ nmn_new_connection_class_init (NmnNewConnectionClass *class)
                               "NmnModel",
                               NMN_TYPE_MODEL,
                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+    /* signals */
+    signals[CLOSE] = g_signal_new 
+        ("close",
+         G_OBJECT_CLASS_TYPE (class),
+         G_SIGNAL_RUN_LAST,
+         G_STRUCT_OFFSET (NmnNewConnectionClass, close),
+         NULL, NULL,
+         g_cclosure_marshal_VOID__VOID,
+         G_TYPE_NONE, 0);
 }
diff --git a/src/nmn-new-connection.h b/src/nmn-new-connection.h
index 886b531..476bbb8 100644
--- a/src/nmn-new-connection.h
+++ b/src/nmn-new-connection.h
@@ -38,6 +38,9 @@ typedef struct {
 
 typedef struct {
     GtkVBoxClass parent;
+
+    /* Signals */
+    void (*close) (NmnNewConnection *self);
 } NmnNewConnectionClass;
 
 GType nmn_new_connection_get_type (void);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]