[gnome-control-center] user-accounts: Add way to change modes



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

    user-accounts: Add way to change modes
    
    Add the buttons to switch 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..7751ef5 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-mode">
+                    <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 19ca585..40aac6c 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 *container_widget;
@@ -44,10 +50,19 @@ struct _UmAccountDialog {
         GCancellable *cancellable;
         GtkSpinner *spinner;
 
+        /* Buttons to switch modes between local/enterprise */
+        UmAccountMode mode;
+        GtkWidget *mode_container;
+        gboolean mode_updating;
+        GtkWidget *mode_buttons[NUM_MODES];
+        GtkWidget *mode_areas[NUM_MODES];
+
         /* Local user account widgets */
         GtkWidget *local_username;
         GtkWidget *local_name;
         GtkWidget *local_account_type;
+
+        /* Enterprise widgets */
 };
 
 struct _UmAccountDialogClass {
@@ -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
+mode_change (UmAccountDialog *self,
+             UmAccountMode mode)
+{
+        GtkWidget *button;
+        gint visible_count = 0;
+        gboolean active;
+        gint i;
+
+        g_assert (!self->mode_updating);
+        self->mode_updating = TRUE;
+
+        for (i = 0; i < NUM_MODES; i++) {
+                button = self->mode_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->mode_areas[i]), active);
+
+                if (gtk_widget_get_visible (button))
+                        visible_count++;
+        }
+
+        /* Show mode container if more than one visible */
+        gtk_widget_set_visible (GTK_WIDGET (self->mode_container), visible_count > 1);
+
+        self->mode = mode;
+        self->mode_updating = FALSE;
+        dialog_validate (self);
+}
+
+static void
+mode_toggled (UmAccountDialog *self,
+              GtkToggleButton *toggle,
+              UmAccountMode mode)
+{
+        if (self->mode_updating)
+                return;
+
+        /* Undo the toggle if already pressed */
+        if (!gtk_toggle_button_get_active (toggle))
+                gtk_toggle_button_set_active (toggle, TRUE);
+
+        /* Otherwise update mode */
+        else
+                mode_change (self, mode);
+}
+
+static void
+on_local_toggle (GtkToggleButton *toggle,
+                 gpointer user_data)
+{
+        mode_toggled (UM_ACCOUNT_DIALOG (user_data), toggle, UM_LOCAL);
+}
+
+static void
+on_enterprise_toggle (GtkToggleButton *toggle,
+                      gpointer user_data)
+{
+        mode_toggled (UM_ACCOUNT_DIALOG (user_data), toggle, UM_ENTERPRISE);
+}
+
+static void
+mode_init (UmAccountDialog *self,
+           GtkBuilder *builder)
+{
+        GtkWidget *widget;
+
+        self->mode_container = (GtkWidget *) gtk_builder_get_object (builder, "account-mode");
+
+        widget = (GtkWidget *) gtk_builder_get_object (builder, "local-area");
+        self->mode_areas[UM_LOCAL] = widget;
+        widget = (GtkWidget *) gtk_builder_get_object (builder, "enterprise-area");
+        self->mode_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->mode_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->mode_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->container_widget = widget;
 
         local_area_init (self, builder);
+        mode_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:
@@ -393,6 +535,7 @@ um_account_dialog_show (UmAccountDialog     *self,
         self->cancellable = g_cancellable_new ();
 
         local_prepare (self);
+        mode_change (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]