[gnome-initial-setup/wip/oholy/account-offline] account: Add offline mode for enterprise page



commit 03c76821617560d3c05d62253e168b83152a4a29
Author: Ondrej Holy <oholy redhat com>
Date:   Fri Nov 2 13:10:36 2018 +0100

    account: Add offline mode for enterprise page

 gnome-initial-setup/pages/account/Makefile.am      |  1 +
 .../pages/account/account.gresource.xml            |  1 +
 .../pages/account/gis-account-page-offline.c       | 73 +++++++++++++++++
 .../pages/account/gis-account-page-offline.h       | 52 ++++++++++++
 .../pages/account/gis-account-page-offline.ui      | 95 ++++++++++++++++++++++
 .../pages/account/gis-account-page.c               | 25 +++++-
 .../pages/account/gis-account-page.ui              |  5 ++
 gnome-initial-setup/pages/account/meson.build      |  2 +
 8 files changed, 251 insertions(+), 3 deletions(-)
---
diff --git a/gnome-initial-setup/pages/account/Makefile.am b/gnome-initial-setup/pages/account/Makefile.am
index 33652f6..f516944 100644
--- a/gnome-initial-setup/pages/account/Makefile.am
+++ b/gnome-initial-setup/pages/account/Makefile.am
@@ -28,6 +28,7 @@ libgisaccount_la_SOURCES =                                            \
        gis-account-pages.c gis-account-pages.h                         \
        gis-account-page-local.c gis-account-page-local.h               \
        gis-account-page-enterprise.c gis-account-page-enterprise.h     \
+       gis-account-page-offline.c gis-account-page-offline.h           \
        um-realm-manager.c um-realm-manager.h                           \
        um-utils.c um-utils.h                                           \
        um-photo-dialog.c um-photo-dialog.h                             \
diff --git a/gnome-initial-setup/pages/account/account.gresource.xml 
b/gnome-initial-setup/pages/account/account.gresource.xml
index d698ba9..3b0b1ae 100644
--- a/gnome-initial-setup/pages/account/account.gresource.xml
+++ b/gnome-initial-setup/pages/account/account.gresource.xml
@@ -5,5 +5,6 @@
     <file preprocess="xml-stripblanks" alias="gis-account-page.ui">gis-account-page.ui</file>
     <file preprocess="xml-stripblanks" alias="gis-account-page-local.ui">gis-account-page-local.ui</file>
     <file preprocess="xml-stripblanks" 
alias="gis-account-page-enterprise.ui">gis-account-page-enterprise.ui</file>
+    <file preprocess="xml-stripblanks" alias="gis-account-page-offline.ui">gis-account-page-offline.ui</file>
   </gresource>
 </gresources>
diff --git a/gnome-initial-setup/pages/account/gis-account-page-offline.c 
b/gnome-initial-setup/pages/account/gis-account-page-offline.c
new file mode 100644
index 0000000..dd0e398
--- /dev/null
+++ b/gnome-initial-setup/pages/account/gis-account-page-offline.c
@@ -0,0 +1,73 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2018 Red Hat
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gis-account-page-offline.h"
+#include "gnome-initial-setup.h"
+
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+struct _GisAccountPageOfflinePrivate
+{
+  GtkWidget *image;
+};
+typedef struct _GisAccountPageOfflinePrivate GisAccountPageOfflinePrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GisAccountPageOffline, gis_account_page_offline, GTK_TYPE_BIN);
+
+static void
+gis_account_page_offline_realize (GtkWidget *widget)
+{
+  GisAccountPageOffline *page = GIS_ACCOUNT_PAGE_OFFLINE (widget);
+  GisAccountPageOfflinePrivate *priv = gis_account_page_offline_get_instance_private (page);
+  GtkWidget *gis_page;
+
+  gis_page = gtk_widget_get_ancestor (widget, GIS_TYPE_PAGE);
+  g_object_bind_property (gis_page, "small-screen",
+                          priv->image, "visible",
+                          G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
+
+  GTK_WIDGET_CLASS (gis_account_page_offline_parent_class)->realize (widget);
+}
+
+static void
+gis_account_page_offline_class_init (GisAccountPageOfflineClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  widget_class->realize = gis_account_page_offline_realize;
+
+  gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), 
"/org/gnome/initial-setup/gis-account-page-offline.ui");
+
+  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisAccountPageOffline, image);
+}
+
+static void
+gis_account_page_offline_init (GisAccountPageOffline *page)
+{
+  gtk_widget_init_template (GTK_WIDGET (page));
+}
+
+void
+gis_account_page_offline_shown (GisAccountPageOffline *page)
+{
+
+}
diff --git a/gnome-initial-setup/pages/account/gis-account-page-offline.h 
b/gnome-initial-setup/pages/account/gis-account-page-offline.h
new file mode 100644
index 0000000..4b4b847
--- /dev/null
+++ b/gnome-initial-setup/pages/account/gis-account-page-offline.h
@@ -0,0 +1,52 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2018 Red Hat
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIS_ACCOUNT_PAGE_OFFLINE_H__
+#define __GIS_ACCOUNT_PAGE_OFFLINE_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GIS_TYPE_ACCOUNT_PAGE_OFFLINE            (gis_account_page_offline_get_type ())
+#define GIS_ACCOUNT_PAGE_OFFLINE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GIS_TYPE_ACCOUNT_PAGE_OFFLINE, GisAccountPageOffline))
+#define GIS_ACCOUNT_PAGE_OFFLINE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  
GIS_TYPE_ACCOUNT_PAGE_OFFLINE, GisAccountPageOfflineClass))
+#define GIS_IS_ACCOUNT_PAGE_OFFLINE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GIS_TYPE_ACCOUNT_PAGE_OFFLINE))
+#define GIS_IS_ACCOUNT_PAGE_OFFLINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  
GIS_TYPE_ACCOUNT_PAGE_OFFLINE))
+#define GIS_ACCOUNT_PAGE_OFFLINE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  
GIS_TYPE_ACCOUNT_PAGE_OFFLINE, GisAccountPageOfflineClass))
+
+typedef struct _GisAccountPageOffline        GisAccountPageOffline;
+typedef struct _GisAccountPageOfflineClass   GisAccountPageOfflineClass;
+
+struct _GisAccountPageOffline
+{
+    GtkBin parent;
+};
+
+struct _GisAccountPageOfflineClass
+{
+    GtkBinClass parent_class;
+};
+
+GType gis_account_page_offline_get_type (void);
+
+void     gis_account_page_offline_shown (GisAccountPageOffline *offline);
+
+G_END_DECLS
+
+#endif /* __GIS_ACCOUNT_PAGE_OFFLINE_H__ */
diff --git a/gnome-initial-setup/pages/account/gis-account-page-offline.ui 
b/gnome-initial-setup/pages/account/gis-account-page-offline.ui
new file mode 100644
index 0000000..7c394d5
--- /dev/null
+++ b/gnome-initial-setup/pages/account/gis-account-page-offline.ui
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <template class="GisAccountPageOffline" parent="GtkBin">
+    <child>
+      <object class="GtkBox" id="area">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="halign">center</property>
+        <property name="valign">fill</property>
+        <child>
+          <object class="GtkImage" id="image">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="pixel_size">96</property>
+            <property name="icon_name">dialog-password-symbolic</property>
+            <property name="icon_size">1</property>
+            <property name="margin_top">24</property>
+            <property name="margin_bottom">26</property>
+            <style>
+              <class name="dim-label" />
+            </style>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="title">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">True</property>
+            <property name="label" translatable="yes">Enterprise Login</property>
+            <property name="margin_bottom">14</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+              <attribute name="scale" value="1.8"/>
+            </attributes>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="subtitle">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="valign">start</property>
+            <property name="margin_bottom">26</property>
+            <property name="label" translatable="yes">Enterprise login allows an existing centrally managed 
user account to be used on this device. You can also use this account to access company resources on the 
internet.</property>
+            <property name="justify">center</property>
+            <property name="wrap">True</property>
+            <property name="max-width-chars">45</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkImage">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="icon_name">network-offline-symbolic</property>
+            <property name="pixel_size">160</property>
+            <property name="vexpand">True</property>
+            <property name="hexpand">True</property>
+            <property name="margin_bottom">6</property>
+            <property name="valign">end</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">You are Offline</property>
+            <property name="yalign">0</property>
+            <property name="justify">center</property>
+            <property name="hexpand">True</property>
+            <attributes>
+              <attribute name="scale" value="1.6"/>
+            </attributes>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">You must be online in order to add enterprise 
users.</property>
+            <property name="yalign">0</property>
+            <property name="justify">center</property>
+            <property name="vexpand">True</property>
+            <property name="hexpand">True</property>
+            <attributes>
+              <attribute name="scale" value="1.2"/>
+            </attributes>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
+
+
diff --git a/gnome-initial-setup/pages/account/gis-account-page.c 
b/gnome-initial-setup/pages/account/gis-account-page.c
index 4c41cb1..3451434 100644
--- a/gnome-initial-setup/pages/account/gis-account-page.c
+++ b/gnome-initial-setup/pages/account/gis-account-page.c
@@ -28,6 +28,7 @@
 #include "gis-account-page.h"
 #include "gis-account-page-local.h"
 #include "gis-account-page-enterprise.h"
+#include "gis-account-page-offline.h"
 
 #include <glib/gi18n.h>
 #include <gio/gio.h>
@@ -36,6 +37,7 @@ struct _GisAccountPagePrivate
 {
   GtkWidget *page_local;
   GtkWidget *page_enterprise;
+  GtkWidget *page_offline;
 
   GtkWidget *page_toggle;
   GtkWidget *stack;
@@ -103,9 +105,24 @@ set_mode (GisAccountPage *page,
       gis_account_page_local_shown (GIS_ACCOUNT_PAGE_LOCAL (priv->page_local));
       break;
     case UM_ENTERPRISE:
-      gtk_stack_set_visible_child (GTK_STACK (priv->stack), priv->page_enterprise);
-      gis_account_page_enterprise_shown (GIS_ACCOUNT_PAGE_ENTERPRISE (priv->page_enterprise));
-      break;
+      {
+        GNetworkMonitor *monitor;
+        gboolean available;
+
+        monitor = g_network_monitor_get_default ();
+        available = g_network_monitor_get_network_available (monitor);
+        if (available)
+          {
+            gtk_stack_set_visible_child (GTK_STACK (priv->stack), priv->page_enterprise);
+            gis_account_page_enterprise_shown (GIS_ACCOUNT_PAGE_ENTERPRISE (priv->page_enterprise));
+          }
+        else
+          {
+            gtk_stack_set_visible_child (GTK_STACK (priv->stack), priv->page_offline);
+            gis_account_page_offline_shown (GIS_ACCOUNT_PAGE_OFFLINE (priv->page_offline));
+          }
+        break;
+      }
     default:
       g_assert_not_reached ();
     }
@@ -252,6 +269,7 @@ gis_account_page_class_init (GisAccountPageClass *klass)
 
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisAccountPage, page_local);
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisAccountPage, page_enterprise);
+  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisAccountPage, page_offline);
 
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisAccountPage, page_toggle);
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisAccountPage, stack);
@@ -270,6 +288,7 @@ gis_account_page_init (GisAccountPage *page)
   g_resources_register (account_get_resource ());
   g_type_ensure (GIS_TYPE_ACCOUNT_PAGE_LOCAL);
   g_type_ensure (GIS_TYPE_ACCOUNT_PAGE_ENTERPRISE);
+  g_type_ensure (GIS_TYPE_ACCOUNT_PAGE_OFFLINE);
 
   gtk_widget_init_template (GTK_WIDGET (page));
 }
diff --git a/gnome-initial-setup/pages/account/gis-account-page.ui 
b/gnome-initial-setup/pages/account/gis-account-page.ui
index bf55701..d0d0fae 100644
--- a/gnome-initial-setup/pages/account/gis-account-page.ui
+++ b/gnome-initial-setup/pages/account/gis-account-page.ui
@@ -23,6 +23,11 @@
                 <property name="visible">True</property>
               </object>
             </child>
+            <child>
+              <object class="GisAccountPageOffline" id="page_offline">
+                <property name="visible">True</property>
+              </object>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
diff --git a/gnome-initial-setup/pages/account/meson.build b/gnome-initial-setup/pages/account/meson.build
index 1130465..2a3f5d8 100644
--- a/gnome-initial-setup/pages/account/meson.build
+++ b/gnome-initial-setup/pages/account/meson.build
@@ -23,6 +23,8 @@ sources += files(
     'gis-account-page-local.h',
     'gis-account-page-enterprise.c',
     'gis-account-page-enterprise.h',
+    'gis-account-page-offline.c',
+    'gis-account-page-offline.h',
     'um-realm-manager.c',
     'um-realm-manager.h',
     'um-utils.c',


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