[gnome-control-center/wip/user-identities: 5/7] wip: users: Add rough outline of identity manager interface



commit 130a9466358b50461ddf51f10e2d1e59701dac70
Author: Ray Strode <rstrode redhat com>
Date:   Mon Feb 20 00:38:08 2012 -0500

    wip: users: Add rough outline of identity manager interface

 panels/user-accounts/Makefile.am                   |    4 +
 panels/user-accounts/data/user-accounts-dialog.ui  |   24 ++-
 panels/user-accounts/um-identity-manager-private.h |   43 +++
 panels/user-accounts/um-identity-manager.c         |  157 ++++++++++
 panels/user-accounts/um-identity-manager.h         |  111 +++++++
 panels/user-accounts/um-identity.c                 |   57 ++++
 panels/user-accounts/um-identity.h                 |   63 ++++
 panels/user-accounts/um-user-panel.c               |  325 +++++++++++++++++++-
 8 files changed, 780 insertions(+), 4 deletions(-)
---
diff --git a/panels/user-accounts/Makefile.am b/panels/user-accounts/Makefile.am
index 2907f01..ce52837 100644
--- a/panels/user-accounts/Makefile.am
+++ b/panels/user-accounts/Makefile.am
@@ -25,6 +25,10 @@ endif
 libuser_accounts_la_SOURCES =		\
 	um-account-type.h		\
 	um-account-type.c 		\
+	um-identity-manager.h		\
+	um-identity-manager.c		\
+	um-identity.h			\
+	um-identity.c			\
 	um-user.h 			\
 	um-user.c 			\
 	um-user-manager.h 		\
diff --git a/panels/user-accounts/data/user-accounts-dialog.ui b/panels/user-accounts/data/user-accounts-dialog.ui
index 8d91aec..aec8156 100644
--- a/panels/user-accounts/data/user-accounts-dialog.ui
+++ b/panels/user-accounts/data/user-accounts-dialog.ui
@@ -296,6 +296,24 @@
                           </packing>
                         </child>
                         <child>
+                          <object class="GtkLabel" id="accessible-realms-label">
+                            <property name="visible">True</property>
+                            <property name="xalign">1</property>
+                            <property name="halign">GTK_ALIGN_END</property>
+                            <property name="hexpand">TRUE</property>
+                            <property name="label" translatable="yes">Accessible Realms</property>
+                            <style>
+                              <class name="dim-label"/>
+                            </style>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="width">1</property>
+                            <property name="top_attach">7</property>
+                            <property name="height">1</property>
+                          </packing>
+                        </child>
+                        <child>
                           <object class="GtkLabel" id="autologin-label">
                             <property name="visible">True</property>
                             <property name="xalign">1</property>
@@ -311,7 +329,7 @@
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="width">1</property>
-                            <property name="top_attach">7</property>
+                            <property name="top_attach">8</property>
                             <property name="height">1</property>
                           </packing>
                         </child>
@@ -335,7 +353,7 @@
                           <packing>
                             <property name="left_attach">2</property>
                             <property name="width">1</property>
-                            <property name="top_attach">7</property>
+                            <property name="top_attach">8</property>
                             <property name="height">1</property>
                           </packing>
                         </child>
@@ -355,7 +373,7 @@
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="width">1</property>
-                            <property name="top_attach">8</property>
+                            <property name="top_attach">9</property>
                             <property name="height">1</property>
                           </packing>
                         </child>
diff --git a/panels/user-accounts/um-identity-manager-private.h b/panels/user-accounts/um-identity-manager-private.h
new file mode 100644
index 0000000..463045e
--- /dev/null
+++ b/panels/user-accounts/um-identity-manager-private.h
@@ -0,0 +1,43 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors: Ray Strode
+ */
+
+#ifndef __UM_IDENTITY_MANAGER_PRIVATE_H__
+#define __UM_IDENTITY_MANAGER_PRIVATE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "um-identity-manager.h"
+
+G_BEGIN_DECLS
+
+void      _um_identity_manager_emit_identity_added (UmIdentityManager *identity_manager,
+                                                    UmIdentity *identity);
+void      _um_identity_manager_emit_identity_removed (UmIdentityManager *identity_manager,
+                                                      UmIdentity *identity);
+void      _um_identity_manager_emit_identity_expired (UmIdentityManager *identity_manager,
+                                                      UmIdentity *identity);
+void      _um_identity_manager_emit_identity_renewed (UmIdentityManager *identity_manager,
+                                                      UmIdentity *identity);
+G_END_DECLS
+
+#endif /* __UM_IDENTITY_MANAGER_PRIVATE_H__ */
diff --git a/panels/user-accounts/um-identity-manager.c b/panels/user-accounts/um-identity-manager.c
new file mode 100644
index 0000000..19f6456
--- /dev/null
+++ b/panels/user-accounts/um-identity-manager.c
@@ -0,0 +1,157 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "um-identity-manager.h"
+#include "um-identity-manager-private.h"
+
+enum {
+        IDENTITY_ADDED,
+        IDENTITY_REMOVED,
+        IDENTITY_EXPIRED,
+        IDENTITY_RENEWED,
+        NUMBER_OF_SIGNALS,
+};
+
+static guint signals[NUMBER_OF_SIGNALS] = { 0 };
+
+G_DEFINE_INTERFACE (UmIdentityManager, um_identity_manager, G_TYPE_OBJECT);
+
+static void
+um_identity_manager_default_init (UmIdentityManagerInterface *interface)
+{
+      signals[IDENTITY_ADDED] = g_signal_new ("identity-added",
+                                              G_TYPE_FROM_INTERFACE (interface),
+                                              G_SIGNAL_RUN_LAST,
+                                              G_STRUCT_OFFSET (UmIdentityManagerInterface, identity_added),
+                                              NULL, NULL, NULL,
+                                              G_TYPE_NONE, 1, UM_TYPE_IDENTITY);
+      signals[IDENTITY_REMOVED] = g_signal_new ("identity-removed",
+                                                G_TYPE_FROM_INTERFACE (interface),
+                                                G_SIGNAL_RUN_LAST,
+                                                G_STRUCT_OFFSET (UmIdentityManagerInterface, identity_removed),
+                                                NULL, NULL, NULL,
+                                                G_TYPE_NONE, 1, UM_TYPE_IDENTITY);
+      signals[IDENTITY_EXPIRED] = g_signal_new ("identity-expired",
+                                                G_TYPE_FROM_INTERFACE (interface),
+                                                G_SIGNAL_RUN_LAST,
+                                                G_STRUCT_OFFSET (UmIdentityManagerInterface, identity_expired),
+                                                NULL, NULL, NULL,
+                                                G_TYPE_NONE, 1, UM_TYPE_IDENTITY);
+      signals[IDENTITY_RENEWED] = g_signal_new ("identity-renewed",
+                                                G_TYPE_FROM_INTERFACE (interface),
+                                                G_SIGNAL_RUN_LAST,
+                                                G_STRUCT_OFFSET (UmIdentityManagerInterface, identity_renewed),
+                                                NULL, NULL, NULL,
+                                                G_TYPE_NONE, 1, UM_TYPE_IDENTITY);
+}
+
+GQuark
+um_identity_manager_error_quark (void)
+{
+        static GQuark error_quark = 0;
+
+        if (error_quark == 0) {
+                error_quark = g_quark_from_static_string ("um-identity-manager-error");
+        }
+
+        return error_quark;
+}
+
+void
+um_identity_manager_list_identities (UmIdentityManager   *self,
+                                     GCancellable        *cancellable,
+                                     GAsyncReadyCallback  callback,
+                                     gpointer             user_data)
+{
+        UM_IDENTITY_MANAGER_GET_IFACE (self)->list_identities (self,
+                                                               cancellable,
+                                                               callback,
+                                                               user_data);
+}
+
+GList *
+um_identity_manager_list_identities_finish (UmIdentityManager  *self,
+                                            GAsyncResult       *result,
+                                            GError            **error)
+{
+        return UM_IDENTITY_MANAGER_GET_IFACE (self)->list_identities_finish (self,
+                                                                             result,
+                                                                             error);
+}
+
+void
+um_identity_manager_sign_identity_out (UmIdentityManager   *self,
+                                       UmIdentity          *identity,
+                                       GCancellable        *cancellable,
+                                       GAsyncReadyCallback  callback,
+                                       gpointer             user_data)
+{
+        UM_IDENTITY_MANAGER_GET_IFACE (self)->sign_identity_out (self, identity, cancellable, callback, user_data);
+}
+
+void
+um_identity_manager_sign_identity_out_finish (UmIdentityManager  *self,
+                                              GAsyncResult       *result,
+                                              GError            **error)
+{
+        UM_IDENTITY_MANAGER_GET_IFACE (self)->sign_identity_out_finish (self, result, error);
+}
+
+char *
+um_identity_manager_name_identity (UmIdentityManager *self,
+                                   UmIdentity        *identity)
+{
+        return UM_IDENTITY_MANAGER_GET_IFACE (self)->name_identity (self,
+                                                                    identity);
+}
+
+void
+_um_identity_manager_emit_identity_added (UmIdentityManager *self,
+                                          UmIdentity        *identity)
+{
+        g_signal_emit (G_OBJECT (self), signals[IDENTITY_ADDED], 0, identity);
+}
+
+void
+_um_identity_manager_emit_identity_removed (UmIdentityManager *self,
+                                            UmIdentity        *identity)
+{
+        g_signal_emit (G_OBJECT (self), signals[IDENTITY_REMOVED], 0, identity);
+}
+
+void
+_um_identity_manager_emit_identity_expired (UmIdentityManager *self,
+                                            UmIdentity        *identity)
+{
+        g_signal_emit (G_OBJECT (self), signals[IDENTITY_EXPIRED], 0, identity);
+}
+
+void
+_um_identity_manager_emit_identity_renewed (UmIdentityManager *self,
+                                            UmIdentity        *identity)
+{
+        g_signal_emit (G_OBJECT (self), signals[IDENTITY_RENEWED], 0, identity);
+}
diff --git a/panels/user-accounts/um-identity-manager.h b/panels/user-accounts/um-identity-manager.h
new file mode 100644
index 0000000..1845e45
--- /dev/null
+++ b/panels/user-accounts/um-identity-manager.h
@@ -0,0 +1,111 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors: Ray Strode
+ */
+
+#ifndef __UM_IDENTITY_MANAGER_H__
+#define __UM_IDENTITY_MANAGER_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include "um-identity.h"
+
+G_BEGIN_DECLS
+
+#define UM_TYPE_IDENTITY_MANAGER             (um_identity_manager_get_type ())
+#define UM_IDENTITY_MANAGER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), UM_TYPE_IDENTITY_MANAGER, UmIdentityManager))
+#define UM_IDENTITY_MANAGER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), UM_TYPE_IDENTITY_MANAGER, UmIdentityManagerInterface))
+#define UM_IS_IDENTITY_MANAGER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UM_TYPE_IDENTITY_MANAGER))
+#define UM_IDENTITY_MANAGER_GET_IFACE(obj)   (G_TYPE_INSTANCE_GET_INTERFACE((obj), UM_TYPE_IDENTITY_MANAGER, UmIdentityManagerInterface))
+#define UM_IDENTITY_MANAGER_ERROR            (um_identity_manager_error_quark ())
+
+typedef struct _UmIdentityManager          UmIdentityManager;
+typedef struct _UmIdentityManagerInterface UmIdentityManagerInterface;
+typedef enum   _UmIdentityManagerError     UmIdentityManagerError;
+
+struct _UmIdentityManagerInterface
+{
+        GTypeInterface base_interface;
+
+        /* Signals */
+        void      (* identity_added)    (UmIdentityManager *identity_manager,
+                                         UmIdentity        *identity);
+
+        void      (* identity_removed)  (UmIdentityManager *identity_manager,
+                                         UmIdentity        *identity);
+        void      (* identity_expired)  (UmIdentityManager *identity_manager,
+                                         UmIdentity        *identity);
+        void      (* identity_renewed)  (UmIdentityManager *identity_manager,
+                                         UmIdentity        *identity);
+
+        /* Virtual Functions */
+        void      (* list_identities)        (UmIdentityManager   *identity_manager,
+                                              GCancellable        *cancellable,
+                                              GAsyncReadyCallback  callback,
+                                              gpointer             user_data);
+        GList *   (* list_identities_finish) (UmIdentityManager  *identity_manager,
+                                              GAsyncResult       *result,
+                                              GError            **error);
+
+        void      (* sign_identity_out)  (UmIdentityManager   *identity_manager,
+                                          UmIdentity          *identity,
+                                          GCancellable        *cancellable,
+                                          GAsyncReadyCallback  callback,
+                                          gpointer             user_data);
+        void      (* sign_identity_out_finish)  (UmIdentityManager  *identity_manager,
+                                                 GAsyncResult       *result,
+                                                 GError            **error);
+
+        char  *   (* name_identity)      (UmIdentityManager *identity_manager,
+                                          UmIdentity        *identity);
+};
+
+enum _UmIdentityManagerError {
+        UM_IDENTITY_MANAGER_ERROR_INITIALIZING,
+        UM_IDENTITY_MANAGER_ERROR_MONITORING,
+        UM_IDENTITY_MANAGER_ERROR_SIGNING_OUT
+};
+
+GType      um_identity_manager_get_type         (void);
+GQuark     um_identity_manager_error_quark      (void);
+
+void       um_identity_manager_list_identities  (UmIdentityManager   *identity_manager,
+                                                 GCancellable        *cancellable,
+                                                 GAsyncReadyCallback  callback,
+                                                 gpointer             user_data);
+GList *    um_identity_manager_list_identities_finish  (UmIdentityManager  *identity_manager,
+                                                        GAsyncResult       *result,
+                                                        GError            **error);
+void       um_identity_manager_sign_identity_out    (UmIdentityManager   *identity_manager,
+                                                     UmIdentity          *identity,
+                                                     GCancellable        *cancellable,
+                                                     GAsyncReadyCallback  callback,
+                                                     gpointer             user_data);
+void       um_identity_manager_sign_identity_out_finish (UmIdentityManager *identity_manager,
+                                                         GAsyncResult       *result,
+                                                         GError            **error);
+char      *um_identity_manager_name_identity    (UmIdentityManager *identity_manager,
+                                                 UmIdentity        *identity);
+
+G_END_DECLS
+
+#endif /* __UM_IDENTITY_MANAGER_H__ */
diff --git a/panels/user-accounts/um-identity.c b/panels/user-accounts/um-identity.c
new file mode 100644
index 0000000..e8e250b
--- /dev/null
+++ b/panels/user-accounts/um-identity.c
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+#include <glib/gi18n.h>
+
+#include "um-identity.h"
+
+G_DEFINE_INTERFACE (UmIdentity, um_identity, G_TYPE_OBJECT);
+
+static void
+um_identity_default_init (UmIdentityInterface *interface)
+{
+}
+
+GQuark
+um_identity_error_quark (void)
+{
+        static GQuark error_quark = 0;
+
+        if (error_quark == 0) {
+                error_quark = g_quark_from_static_string ("um-identity-error");
+        }
+
+        return error_quark;
+}
+
+const char *
+um_identity_get_identifier (UmIdentity *self)
+{
+        return UM_IDENTITY_GET_IFACE (self)->get_identifier (self);
+}
+
+gboolean
+um_identity_is_signed_in (UmIdentity *self)
+{
+        return UM_IDENTITY_GET_IFACE (self)->is_signed_in (self);
+}
diff --git a/panels/user-accounts/um-identity.h b/panels/user-accounts/um-identity.h
new file mode 100644
index 0000000..0a40775
--- /dev/null
+++ b/panels/user-accounts/um-identity.h
@@ -0,0 +1,63 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors: Ray Strode <rstrode redhat com>
+ */
+
+#ifndef __UM_IDENTITY_H__
+#define __UM_IDENTITY_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define UM_TYPE_IDENTITY             (um_identity_get_type ())
+#define UM_IDENTITY(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), UM_TYPE_IDENTITY, UmIdentity))
+#define UM_IDENTITY_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), UM_TYPE_IDENTITY, UmIdentityInterface))
+#define UM_IS_IDENTITY(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UM_TYPE_IDENTITY))
+#define UM_IDENTITY_GET_IFACE(obj)   (G_TYPE_INSTANCE_GET_INTERFACE((obj), UM_TYPE_IDENTITY, UmIdentityInterface))
+#define UM_IDENTITY_ERROR            (um_identity_error_quark ())
+
+typedef struct _UmIdentity          UmIdentity;
+typedef struct _UmIdentityInterface UmIdentityInterface;
+typedef enum   _UmIdentityError     UmIdentityError;
+
+struct _UmIdentityInterface
+{
+        GTypeInterface base_interface;
+
+        const char * (* get_identifier)  (UmIdentity *identity);
+        gboolean     (* is_signed_in)    (UmIdentity *identity);
+};
+
+enum _UmIdentityError {
+        UM_IDENTITY_ERROR_VERIFYING,
+        UM_IDENTITY_ERROR_ERASING
+};
+
+GType       um_identity_get_type         (void);
+GQuark      um_identity_error_quark      (void);
+
+const char *um_identity_get_identifier   (UmIdentity *identity);
+gboolean    um_identity_is_signed_in     (UmIdentity *identity);
+
+G_END_DECLS
+
+#endif /* __UM_IDENTITY_H__ */
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index d65e1de..cd30d3e 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -41,8 +41,11 @@
 
 #include "um-user.h"
 #include "um-user-manager.h"
+#include "um-identity-manager.h"
+#include "um-kerberos-identity-manager.h"
 
 #include "cc-strength-bar.h"
+
 #include "um-editable-button.h"
 #include "um-editable-combo.h"
 
@@ -70,6 +73,7 @@ struct _UmUserPanelPrivate {
         GPermission *permission;
         GtkWidget *language_chooser;
 
+        UmIdentityManager *identity_manager;
         UmAccountDialog *account_dialog;
         UmPasswordDialog *password_dialog;
         UmPhotoDialog *photo_dialog;
@@ -548,6 +552,80 @@ autologin_changed (GObject            *object,
 }
 
 static void
+get_position_of_accessible_realms_label (UmUserPanelPrivate *d,
+                                         int                *left_position,
+                                         int                *top_position)
+{
+
+        GtkWidget *grid, *label;
+
+        grid = get_widget (d, "user-grid");
+        label = get_widget (d, "accessible-realms-label");
+        gtk_container_child_get (GTK_CONTAINER (grid),
+                                 label,
+                                 "left-attach", left_position,
+                                 "top-attach", top_position,
+                                 NULL);
+}
+
+static void
+get_position_of_next_realm_hbox (UmUserPanelPrivate *d,
+                                 int                *left_position,
+                                 int                *top_position)
+{
+        GtkWidget *grid, *last_realm_hbox;
+
+        grid = get_widget (d, "user-grid");
+        get_position_of_accessible_realms_label (d, left_position, top_position);
+        *left_position += 1;
+        do {
+                last_realm_hbox = gtk_grid_get_child_at (GTK_GRID (grid),
+                                                         *left_position,
+                                                         *top_position);
+                if (last_realm_hbox != NULL) {
+                        *top_position += 1;
+                }
+        } while (last_realm_hbox != NULL);
+}
+
+static void
+update_accessible_realms_visiblity (UmUserPanelPrivate *d)
+{
+        GtkWidget *grid, *label, *widget;
+        int left_position, top_position;
+        UmUser    *user;
+        uid_t      uid;
+
+        grid = get_widget (d, "user-grid");
+        label = get_widget (d, "accessible-realms-label");
+
+        user = get_selected_user (d);
+        uid = um_user_get_uid (user);
+
+        get_position_of_accessible_realms_label (d,
+                                                 &left_position,
+                                                 &top_position);
+        /* FIXME: this means if the first realm ever goes away, all the others
+         * hide.  We should just keep a list of realms and then we can check if
+         * the list is not NULL, and also use the list to move where the
+         * realms are positioned
+         */
+        widget = gtk_grid_get_child_at (GTK_GRID (grid),
+                                        left_position + 1,
+                                        top_position);
+
+        /* We only need to show or hide the label, because all
+         * the realm boxes automatically mimick the labels
+         * visibility
+         */
+        if (widget != NULL && uid == geteuid ()) {
+                gtk_widget_show (label);
+        } else {
+                gtk_widget_hide (label);
+        }
+}
+
+static void
 show_user (UmUser *user, UmUserPanelPrivate *d)
 {
         GtkWidget *image;
@@ -624,6 +702,8 @@ show_user (UmUser *user, UmUserPanelPrivate *d)
                         gtk_widget_hide (widget);
                 }
         }
+
+        update_accessible_realms_visiblity (d);
 }
 
 static void on_permission_changed (GPermission *permission, GParamSpec *pspec, gpointer data);
@@ -1334,6 +1414,249 @@ setup_main_window (UmUserPanelPrivate *d)
 }
 
 static void
+remove_accessible_realm_for_identity (UmUserPanelPrivate *d,
+                                      UmIdentity         *identity)
+{
+        GtkWidget *hbox;
+
+        hbox = g_object_get_data (G_OBJECT (identity),
+                                 "accessible-realm-hbox");
+
+        if (hbox != NULL) {
+                g_assert (GTK_IS_WIDGET (hbox));
+
+                gtk_widget_destroy (hbox);
+                g_object_set_data (G_OBJECT (identity),
+                                   "accessible-realm-hbox",
+                                   NULL);
+        }
+
+        update_accessible_realms_visiblity (d);
+}
+
+static void
+on_signed_out (UmIdentityManager *manager,
+               GAsyncResult      *result,
+               gpointer           user_data)
+{
+        UmIdentity *identity = UM_IDENTITY (user_data);
+
+        um_identity_manager_sign_identity_out_finish (manager,
+                                                      result,
+                                                      NULL);
+        g_object_unref (identity);
+}
+
+static void
+on_sign_out_clicked (GtkButton          *button,
+                     UmUserPanelPrivate *d)
+{
+        UmIdentity *identity;
+
+        identity = g_object_get_data (G_OBJECT (button),
+                                      "accessible-realm-identity");
+
+        um_identity_manager_sign_identity_out (d->identity_manager,
+                                               identity,
+                                               NULL,
+                                               (GAsyncReadyCallback)
+                                               on_signed_out,
+                                               g_object_ref (identity));
+}
+
+static void
+mimick_visibility (GtkWidget *widget,
+                   GtkWidget *mimicker)
+{
+        gtk_widget_set_visible (mimicker, gtk_widget_get_visible (widget));
+}
+
+static void
+stop_mimicking_visibility (GtkWidget *widget,
+                           GtkWidget *mimicker)
+{
+        g_signal_handlers_disconnect_by_func (G_OBJECT (widget),
+                                              G_CALLBACK (mimick_visibility),
+                                              mimicker);
+}
+
+static void
+add_accessible_realm_for_identity (UmUserPanelPrivate *d,
+                                   UmIdentity         *identity)
+{
+        GtkWidget *realm_hbox;
+        char *name;
+        GtkWidget *label, *button;
+        GtkWidget *grid;
+        int left_position, top_position;
+
+        remove_accessible_realm_for_identity (d, identity);
+
+        label = get_widget (d, "accessible-realms-label");
+
+        realm_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+
+        /* Synchronize the realms visibility with the realms label */
+        g_signal_connect (G_OBJECT (label),
+                          "show",
+                          G_CALLBACK (mimick_visibility),
+                          realm_hbox);
+        g_signal_connect (G_OBJECT (label),
+                          "hide",
+                          G_CALLBACK (mimick_visibility),
+                          realm_hbox);
+        g_object_weak_ref (G_OBJECT (realm_hbox),
+                           (GWeakNotify)
+                           stop_mimicking_visibility,
+                           label);
+
+        name = um_identity_manager_name_identity (d->identity_manager,
+                                                  identity);
+        label = gtk_label_new (name);
+        g_free (name);
+        gtk_container_add (GTK_CONTAINER (realm_hbox), label);
+
+        button = gtk_button_new_with_label (_("Sign Out"));
+        gtk_widget_set_halign (GTK_WIDGET (button),
+                               GTK_ALIGN_END);
+        gtk_widget_set_hexpand (GTK_WIDGET (button),
+                                TRUE);
+
+        g_object_set_data (G_OBJECT (button),
+                           "accessible-realm-identity",
+                           identity);
+        g_signal_connect (G_OBJECT (button),
+                          "clicked",
+                          G_CALLBACK (on_sign_out_clicked),
+                          d);
+        gtk_container_add (GTK_CONTAINER (realm_hbox), button);
+        gtk_widget_show_all (realm_hbox);
+
+        g_object_set_data (G_OBJECT (identity),
+                           "accessible-realm-hbox",
+                           realm_hbox);
+
+        grid = get_widget (d, "user-grid");
+
+        get_position_of_next_realm_hbox (d, &left_position, &top_position);
+
+        gtk_grid_attach (GTK_GRID (grid),
+                         realm_hbox,
+                         left_position,
+                         top_position,
+                         1,
+                         1);
+        update_accessible_realms_visiblity (d);
+}
+
+static void
+on_identity_added (UmIdentityManager *manager,
+                   UmIdentity        *identity,
+                   gpointer           user_data)
+{
+        UmUserPanelPrivate *d = user_data;
+
+        add_accessible_realm_for_identity (d, identity);
+}
+
+static void
+on_identity_renewed (UmIdentityManager *manager,
+                     UmIdentity        *identity,
+                     gpointer           user_data)
+{
+        UmUserPanelPrivate *d = user_data;
+
+        add_accessible_realm_for_identity (d, identity);
+}
+
+static void
+on_identity_removed (UmIdentityManager *manager,
+                     UmIdentity        *identity,
+                     gpointer           user_data)
+{
+        UmUserPanelPrivate *d = user_data;
+
+        remove_accessible_realm_for_identity (d, identity);
+}
+
+static void
+on_identity_expired (UmIdentityManager *manager,
+                     UmIdentity        *identity,
+                     gpointer           user_data)
+{
+        UmUserPanelPrivate *d = user_data;
+
+        remove_accessible_realm_for_identity (d, identity);
+}
+
+static void
+on_identities_listed (UmIdentityManager *manager,
+                      GAsyncResult      *result,
+                      gpointer           user_data)
+{
+        UmUserPanelPrivate *d = user_data;
+        GError *error = NULL;
+        GList *identities, *node;
+
+        g_signal_connect (manager,
+                          "identity-added",
+                          G_CALLBACK (on_identity_added),
+                          d);
+
+        g_signal_connect (manager,
+                          "identity-removed",
+                          G_CALLBACK (on_identity_removed),
+                          d);
+
+        g_signal_connect (manager,
+                          "identity-expired",
+                          G_CALLBACK (on_identity_expired),
+                          d);
+
+        g_signal_connect (manager,
+                          "identity-renewed",
+                          G_CALLBACK (on_identity_renewed),
+                          d);
+
+        identities = um_identity_manager_list_identities_finish (manager,
+                                                                 result,
+                                                                 &error);
+
+        if (identities == NULL) {
+                if (error != NULL) {
+                        g_warning ("UmUserPanel: Could not list identities: %s",
+                                   error->message);
+                        g_error_free (error);
+                }
+
+                gtk_widget_hide (get_widget (d, "accessible-realms-vbox"));
+                return;
+        }
+
+        node = identities;
+        while (node != NULL) {
+                UmIdentity *identity = UM_IDENTITY (node->data);
+
+                if (um_identity_is_signed_in (identity)) {
+                        add_accessible_realm_for_identity (d, identity);
+                }
+
+                node = node->next;
+        }
+}
+
+static void
+setup_identity_manager (UmUserPanelPrivate *d)
+{
+        d->identity_manager = um_kerberos_identity_manager_new ();
+        um_identity_manager_list_identities (d->identity_manager,
+                                             NULL,
+                                             (GAsyncReadyCallback)
+                                             on_identities_listed,
+                                             d);
+}
+
+static void
 um_user_panel_init (UmUserPanel *self)
 {
         UmUserPanelPrivate *d;
@@ -1366,7 +1689,7 @@ um_user_panel_init (UmUserPanel *self)
                 g_error_free (error);
                 return;
         }
-
+        setup_identity_manager (d);
         setup_main_window (d);
         d->account_dialog = um_account_dialog_new ();
         d->password_dialog = um_password_dialog_new ();



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