[gnome-control-center/wip/enterprise-login: 13/15] user-accounts: Add switcher between modes



commit 23ee7bd192140d96da0bfc468c05203a356af8bb
Author: Stef Walter <stefw gnome org>
Date:   Thu Jun 7 00:20:29 2012 +0200

    user-accounts: Add switcher between modes
    
    Add the switcher between the local account and enterprise
    modes.
    
    The enterprise area just has a place holder widget for now.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=677548

 panels/user-accounts/data/account-dialog.ui |   82 +++++++++++++++
 panels/user-accounts/um-account-dialog.c    |  147 ++++++++++++++++++++++++++-
 2 files changed, 227 insertions(+), 2 deletions(-)
---
diff --git a/panels/user-accounts/data/account-dialog.ui b/panels/user-accounts/data/account-dialog.ui
index d64873f..089b32e 100644
--- a/panels/user-accounts/data/account-dialog.ui
+++ b/panels/user-accounts/data/account-dialog.ui
@@ -41,6 +41,61 @@
                </object>
             </child>
             <child>
+              <object class="GtkAlignment" id="alignment1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xscale">0</property>
+                <property name="yscale">0</property>
+                <property name="bottom-padding">10</property>
+                <property name="top-padding">6</property>
+                <child>
+                  <object class="GtkBox" id="account-switcher">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <style>
+                      <class name="linked"/>
+                    </style>
+                    <child>
+                      <object class="GtkToggleButton" id="local-button">
+                        <property name="label" translatable="yes">_Local Account</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="focus_on_click">False</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkToggleButton" id="enterprise-button">
+                        <property name="label" translatable="yes">_Enterprise Login</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="focus_on_click">False</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkGrid" id="local-area">
                 <property name="visible">True</property>
                 <property name="hexpand">True</property>
@@ -147,5 +202,32 @@
                 <property name="fill">False</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkGrid" id="enterprise-area">
+                <property name="visible">True</property>
+                <property name="hexpand">True</property>
+                <property name="column_spacing">10</property>
+                <property name="row_spacing">10</property>
+                <child>
+                  <object class="GtkLabel" id="label61">
+                    <property name="visible">True</property>
+                    <property name="xalign">1</property>
+                    <property name="label" translatable="yes">Enterprise Widgets</property>
+                    <property name="use_underline">True</property>
+                    <style>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+              </packing>
+            </child>
           </object>
 </interface>
diff --git a/panels/user-accounts/um-account-dialog.c b/panels/user-accounts/um-account-dialog.c
index 616ce64..65ee1a3 100644
--- a/panels/user-accounts/um-account-dialog.c
+++ b/panels/user-accounts/um-account-dialog.c
@@ -37,6 +37,12 @@ static void   dialog_validate     (UmAccountDialog *self);
 #define UM_ACCOUNT_DIALOG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), UM_TYPE_ACCOUNT_DIALOG, \
                                                                       UmAccountDialogClass))
 
+typedef enum {
+        UM_LOCAL,
+        UM_ENTERPRISE,
+        NUM_MODES
+} UmAccountMode;
+
 struct _UmAccountDialog {
         GtkDialog parent;
         GtkWidget *widgets;
@@ -44,10 +50,19 @@ struct _UmAccountDialog {
         GCancellable *cancellable;
         GtkSpinner *spinner;
 
+        /* Bar switcher stuff */
+        UmAccountMode mode;
+        GtkWidget *switcher;
+        gboolean switcher_updating;
+        GtkWidget *switcher_buttons[NUM_MODES];
+        GtkWidget *switcher_areas[NUM_MODES];
+
         /* Local widgets */
         GtkWidget *local_username;
         GtkWidget *local_name;
         GtkWidget *local_account_type;
+
+        /* Enterprise widgets */
 };
 
 typedef struct {
@@ -250,12 +265,128 @@ dialog_validate (UmAccountDialog *self)
 {
         gboolean valid = FALSE;
 
-        valid = local_validate (self);
+        switch (self->mode) {
+        case UM_LOCAL:
+                valid = local_validate (self);
+                break;
+        case UM_ENTERPRISE:
+                /* TODO: Implement */
+                valid = FALSE;
+                break;
+        default:
+                valid = FALSE;
+                break;
+        }
 
         gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, valid);
 }
 
 static void
+label_set_bold (GtkLabel *label,
+                gboolean  bold)
+{
+        PangoAttrList *attrs;
+        PangoAttribute *attr;
+
+        attrs = pango_attr_list_new ();
+        attr = pango_attr_weight_new (bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
+        pango_attr_list_insert (attrs, attr);
+        gtk_label_set_attributes (label, attrs);
+        pango_attr_list_unref (attrs);
+}
+
+
+static void
+switcher_switch (UmAccountDialog *self,
+                 UmAccountMode mode)
+{
+        GtkWidget *button;
+        gint visible_count = 0;
+        gboolean active;
+        gint i;
+
+        g_assert (!self->switcher_updating);
+        self->switcher_updating = TRUE;
+
+        for (i = 0; i < NUM_MODES; i++) {
+                button = self->switcher_buttons[i];
+                active = (i == (gint)mode);
+
+                /* The toggle state */
+                if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)) != active)
+                        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), active);
+
+                /* Make toggled buttons bold */
+                label_set_bold (GTK_LABEL (gtk_bin_get_child (GTK_BIN (button))), active);
+
+                /* Show the correct area */
+                gtk_widget_set_visible (GTK_WIDGET (self->switcher_areas[i]), active);
+
+                if (gtk_widget_get_visible (button))
+                        visible_count++;
+        }
+
+        /* Show switcher if more than one visible */
+        gtk_widget_set_visible (GTK_WIDGET (self->switcher), visible_count > 1);
+
+        self->mode = mode;
+        self->switcher_updating = FALSE;
+        dialog_validate (self);
+}
+
+static void
+switcher_toggle (UmAccountDialog *self,
+                 GtkToggleButton *toggle,
+                 UmAccountMode mode)
+{
+        if (self->switcher_updating)
+                return;
+
+        /* Undo the toggle if already pressed */
+        if (!gtk_toggle_button_get_active (toggle))
+                gtk_toggle_button_set_active (toggle, TRUE);
+
+        /* Otherwise switch to new area */
+        else
+                switcher_switch (self, mode);
+}
+
+static void
+on_local_toggle (GtkToggleButton *toggle,
+                 gpointer user_data)
+{
+        switcher_toggle (UM_ACCOUNT_DIALOG (user_data), toggle, UM_LOCAL);
+}
+
+static void
+on_enterprise_toggle (GtkToggleButton *toggle,
+                      gpointer user_data)
+{
+        switcher_toggle (UM_ACCOUNT_DIALOG (user_data), toggle, UM_ENTERPRISE);
+}
+
+static void
+switcher_init (UmAccountDialog *self,
+               GtkBuilder *builder)
+{
+        GtkWidget *widget;
+
+        self->switcher = (GtkWidget *) gtk_builder_get_object (builder, "account-switcher");
+
+        widget = (GtkWidget *) gtk_builder_get_object (builder, "local-area");
+        self->switcher_areas[UM_LOCAL] = widget;
+        widget = (GtkWidget *) gtk_builder_get_object (builder, "enterprise-area");
+        self->switcher_areas[UM_ENTERPRISE] = widget;
+
+        widget = (GtkWidget *) gtk_builder_get_object (builder, "local-button");
+        g_signal_connect (widget, "toggled", G_CALLBACK (on_local_toggle), self);
+        self->switcher_buttons[UM_LOCAL] = widget;
+        widget = (GtkWidget *) gtk_builder_get_object (builder, "enterprise-button");
+        g_signal_connect (widget, "toggled", G_CALLBACK (on_enterprise_toggle), self);
+        self->switcher_buttons[UM_ENTERPRISE] = widget;
+}
+
+static void
 um_account_dialog_init (UmAccountDialog *self)
 {
         GtkBuilder *builder;
@@ -312,6 +443,7 @@ um_account_dialog_init (UmAccountDialog *self)
         self->widgets = widget;
 
         local_area_init (self, builder);
+        switcher_init (self, builder);
 
         g_object_unref (builder);
 }
@@ -324,7 +456,17 @@ um_account_dialog_response (GtkDialog *dialog,
 
         switch (response_id) {
         case GTK_RESPONSE_OK:
-                local_create_user (self);
+                switch (self->mode) {
+                case UM_LOCAL:
+                        local_create_user (self);
+                        break;
+                case UM_ENTERPRISE:
+                        /* TODO: */
+                        g_assert_not_reached ();
+                        break;
+                default:
+                        g_assert_not_reached ();
+                }
                 break;
         case GTK_RESPONSE_CANCEL:
         case GTK_RESPONSE_DELETE_EVENT:
@@ -396,6 +538,7 @@ um_account_dialog_perform (UmAccountDialog     *self,
         self->cancellable = g_cancellable_new ();
 
         local_prepare (self);
+        switcher_switch (self, UM_LOCAL);
         dialog_validate (self);
 
         gtk_window_set_modal (GTK_WINDOW (self), parent != NULL);



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