[gnome-initial-setup/parental-controls: 5/8] WIP
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup/parental-controls: 5/8] WIP
- Date: Wed, 5 Feb 2020 15:40:37 +0000 (UTC)
commit fb51f6fd7ad40c801c189d0f91d564415a18385e
Author: Philip Withnall <withnall endlessm com>
Date: Tue Feb 4 15:35:07 2020 +0000
WIP
Signed-off-by: Philip Withnall <withnall endlessm com>
gnome-initial-setup/gis-driver.c | 16 ++++--
.../pages/account/gis-account-page-local.c | 48 ++++++++++++-----
.../pages/account/gis-account-page-local.ui | 6 +++
.../pages/account/gis-account-page.c | 4 ++
.../pages/account/um-photo-dialog.c | 16 +++---
.../parental-controls/gis-parental-controls-page.c | 22 +++++++-
.../gis-parental-controls-page.ui | 50 +++++------------
.../pages/password/gis-password-page.c | 62 ++++++++++++----------
.../pages/password/gis-password-page.ui | 4 +-
9 files changed, 136 insertions(+), 92 deletions(-)
---
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index 18046e7..3027a12 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -563,8 +563,16 @@ static void
set_small_screen_based_on_primary_monitor (GisDriver *driver)
{
GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
- GdkDisplay *default_display = gdk_display_get_default ();
- GdkMonitor *primary_monitor = gdk_display_get_primary_monitor (default_display);
+ GdkDisplay *default_display;
+ GdkMonitor *primary_monitor;
+
+ default_display = gdk_display_get_default ();
+ if (default_display == NULL)
+ return;
+
+ primary_monitor = gdk_display_get_primary_monitor (default_display);
+ if (primary_monitor == NULL)
+ return;
priv->small_screen = monitor_is_small (primary_monitor);
}
@@ -678,7 +686,7 @@ connect_to_gdm (GisDriver *driver)
priv->user_verifier = gdm_client_get_user_verifier_sync (priv->client, NULL, &error);
if (error != NULL) {
- g_warning ("Failed to open connection to GDM: %s", error->message);
+ //g_warning ("Failed to open connection to GDM: %s", error->message);
g_clear_object (&priv->user_verifier);
g_clear_object (&priv->greeter);
g_clear_object (&priv->client);
@@ -787,7 +795,7 @@ void
gis_driver_save_data (GisDriver *driver)
{
GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
- gis_assistant_save_data (priv->assistant);
+ //gis_assistant_save_data (priv->assistant);
}
GisDriver *
diff --git a/gnome-initial-setup/pages/account/gis-account-page-local.c
b/gnome-initial-setup/pages/account/gis-account-page-local.c
index c777bbf..0e05b23 100644
--- a/gnome-initial-setup/pages/account/gis-account-page-local.c
+++ b/gnome-initial-setup/pages/account/gis-account-page-local.c
@@ -60,7 +60,6 @@ struct _GisAccountPageLocalPrivate
GdkPixbuf *avatar_pixbuf;
gchar *avatar_filename;
- ActUser *act_user;
ActUserManager *act_client;
GoaClient *goa_client;
@@ -487,7 +486,8 @@ gis_account_page_local_dispose (GObject *object)
}
static void
-set_user_avatar (GisAccountPageLocal *page)
+set_user_avatar (GisAccountPageLocal *page,
+ ActUser *user)
{
GisAccountPageLocalPrivate *priv = gis_account_page_local_get_instance_private (page);
GFile *file = NULL;
@@ -496,7 +496,7 @@ set_user_avatar (GisAccountPageLocal *page)
GError *error = NULL;
if (priv->avatar_filename != NULL) {
- act_user_set_icon_file (priv->act_user, priv->avatar_filename);
+ act_user_set_icon_file (user, priv->avatar_filename);
return;
}
@@ -512,7 +512,7 @@ set_user_avatar (GisAccountPageLocal *page)
if (!gdk_pixbuf_save_to_stream (priv->avatar_pixbuf, stream, "png", NULL, &error, NULL))
goto out;
- act_user_set_icon_file (priv->act_user, g_file_get_path (file));
+ act_user_set_icon_file (user, g_file_get_path (file));
out:
if (error != NULL) {
@@ -529,24 +529,42 @@ local_create_user (GisAccountPageLocal *page)
GisAccountPageLocalPrivate *priv = gis_account_page_local_get_instance_private (page);
const gchar *username;
const gchar *fullname;
- GError *error = NULL;
+ g_autoptr(GError) local_error = NULL;
+ gboolean parental_controls_enabled;
+ g_autoptr(ActUser) main_user = NULL;
+ g_autoptr(ActUser) parent_user = NULL;
username = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (priv->username_combo));
fullname = gtk_entry_get_text (GTK_ENTRY (priv->fullname_entry));
+ parental_controls_enabled = gis_driver_get_parental_controls_enabled (GIS_PAGE (page)->driver);
+
+ /* Always create the admin user first, in case of failure part-way through
+ * this function, which would leave us with no admin user at all. */
+ if (parental_controls_enabled) {
+ parent_user = act_user_manager_create_user (priv->act_client, parent_username, parent_fullname,
ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR, &local_error);
+ if (local_error != NULL) {
+ g_warning ("Failed to create parent user: %s", local_error->message);
+ return;
+ }
- priv->act_user = act_user_manager_create_user (priv->act_client, username, fullname, priv->account_type,
&error);
- if (error != NULL) {
- g_warning ("Failed to create user: %s", error->message);
- g_error_free (error);
+ /* TODO We just passed these to the constructor! */
+ act_user_set_user_name (parent_user, parent_username);
+ act_user_set_account_type (parent_user, ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR);
+ }
+
+ /* Now create the main user. */
+ main_user = act_user_manager_create_user (priv->act_client, username, fullname, priv->account_type,
&local_error);
+ if (local_error != NULL) {
+ g_warning ("Failed to create user: %s", local_error->message);
return;
}
- act_user_set_user_name (priv->act_user, username);
- act_user_set_account_type (priv->act_user, priv->account_type);
+ act_user_set_user_name (main_user, username);
+ act_user_set_account_type (main_user, priv->account_type);
- set_user_avatar (page);
+ set_user_avatar (page, main_user);
- g_signal_emit (page, signals[USER_CREATED], 0, priv->act_user, "");
+ g_signal_emit (page, signals[USER_CREATED], 0, main_user, "");
}
static void
@@ -606,10 +624,14 @@ gis_account_page_local_apply (GisAccountPageLocal *local, GisPage *page)
{
GisAccountPageLocalPrivate *priv = gis_account_page_local_get_instance_private (local);
const gchar *username;
+ gboolean parental_controls_enabled;
username = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (priv->username_combo));
gis_driver_set_username (GIS_PAGE (page)->driver, username);
+ parental_controls_enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
(priv->enable_parental_controls_check_button));
+ gis_driver_set_parental_controls_enabled (GIS_PAGE (page)->driver, parental_controls_enabled);
+
return FALSE;
}
diff --git a/gnome-initial-setup/pages/account/gis-account-page-local.ui
b/gnome-initial-setup/pages/account/gis-account-page-local.ui
index e17ea45..303002e 100644
--- a/gnome-initial-setup/pages/account/gis-account-page-local.ui
+++ b/gnome-initial-setup/pages/account/gis-account-page-local.ui
@@ -145,6 +145,12 @@
<property name="label" translatable="yes">Set up _parental controls for this user</property>
<property name="use-underline">True</property>
</object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">6</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
</child>
</object>
</child>
diff --git a/gnome-initial-setup/pages/account/gis-account-page.c
b/gnome-initial-setup/pages/account/gis-account-page.c
index 089ab97..e200074 100644
--- a/gnome-initial-setup/pages/account/gis-account-page.c
+++ b/gnome-initial-setup/pages/account/gis-account-page.c
@@ -181,6 +181,8 @@ on_local_user_created (GtkWidget *page_local,
act_user_set_language (user, language);
gis_driver_set_user_permissions (GIS_PAGE (page)->driver, user, password);
+
+ /* TODO may need to set the parental controls here */
}
static void
@@ -203,6 +205,8 @@ on_local_user_cached (GtkWidget *page_local,
act_user_set_language (user, language);
gis_driver_set_user_permissions (GIS_PAGE (page)->driver, user, password);
+
+ /* TODO may need to set the parental controls here, or disable parental controls in conjunction with
ENTERPRISE */
}
static void
diff --git a/gnome-initial-setup/pages/account/um-photo-dialog.c
b/gnome-initial-setup/pages/account/um-photo-dialog.c
index 9e87f0b..3c14cc5 100644
--- a/gnome-initial-setup/pages/account/um-photo-dialog.c
+++ b/gnome-initial-setup/pages/account/um-photo-dialog.c
@@ -190,24 +190,26 @@ static GtkWidget *
create_face_widget (gpointer item,
gpointer user_data)
{
- GdkPixbuf *pixbuf = NULL;
+ g_autoptr(GdkPixbuf) pixbuf = NULL;
GtkWidget *image;
+ g_autofree gchar *path = g_file_get_path (G_FILE (item));
- pixbuf = gdk_pixbuf_new_from_file_at_size (g_file_get_path (G_FILE (item)),
+ pixbuf = gdk_pixbuf_new_from_file_at_size (path,
AVATAR_PIXEL_SIZE,
AVATAR_PIXEL_SIZE,
NULL);
- if (pixbuf == NULL)
- return NULL;
- image = gtk_image_new_from_pixbuf (round_image (pixbuf));
- g_object_unref (pixbuf);
+ if (pixbuf != NULL)
+ image = gtk_image_new_from_pixbuf (round_image (pixbuf));
+ else
+ image= gtk_image_new ();
+
gtk_image_set_pixel_size (GTK_IMAGE (image), AVATAR_PIXEL_SIZE);
gtk_widget_show (image);
g_object_set_data_full (G_OBJECT (image),
- "filename", g_file_get_path (G_FILE (item)),
+ "filename", g_steal_pointer (&path),
(GDestroyNotify) g_free);
return image;
diff --git a/gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.c
b/gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.c
index c7b876f..5d12b4c 100644
--- a/gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.c
+++ b/gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.c
@@ -33,6 +33,7 @@
#include <libmalcontent-ui/malcontent-ui.h>
#include "parental-controls-resources.h"
+#include "gis-page-header.h"
#include "gis-parental-controls-page.h"
struct _GisParentalControlsPage
@@ -81,6 +82,19 @@ gis_parental_controls_page_shown (GisPage *gis_page)
/* TODO */
}
+/* TODO: I don’t think this does what I think it does */
+static gboolean
+gis_parental_controls_page_skip (GisPage *gis_page)
+{
+ GisParentalControlsPage *page = GIS_PARENTAL_CONTROLS_PAGE (gis_page);
+
+ /* Skip showing the parental controls if they’re not enabled. */
+ if (!gis_driver_get_parental_controls_enabled (GIS_PAGE (page)->driver))
+ return TRUE;
+
+ return FALSE;
+}
+
static void
gis_parental_controls_page_constructed (GObject *object)
{
@@ -94,6 +108,9 @@ gis_parental_controls_page_constructed (GObject *object)
update_page_validation (page);
+ mct_user_controls_set_user (page->user_controls, selected_user);
+ mct_user_controls_set_permission (self->user_controls, self->permission);
+
/* TODO is this necessary? */
gtk_widget_show (GTK_WIDGET (page));
}
@@ -118,8 +135,9 @@ gis_parental_controls_page_class_init (GisParentalControlsPageClass *klass)
page_class->apply = gis_parental_controls_page_apply;
page_class->save_data = gis_parental_controls_page_save_data;
page_class->shown = gis_parental_controls_page_shown;
+ page_class->skip = gis_parental_controls_page_skip;
- gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/initial-setup/gis-parental_controls-page.ui");
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/initial-setup/gis-parental-controls-page.ui");
gtk_widget_class_bind_template_child (widget_class, GisParentalControlsPage, user_controls);
}
@@ -129,6 +147,8 @@ gis_parental_controls_page_init (GisParentalControlsPage *page)
{
g_resources_register (parental_controls_get_resource ());
+ /* Ensure types exist for widgets in the UI file. */
+ g_type_ensure (GIS_TYPE_PAGE_HEADER);
g_type_ensure (MCT_TYPE_USER_CONTROLS);
gtk_widget_init_template (GTK_WIDGET (page));
diff --git a/gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.ui
b/gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.ui
index 114b491..e27bb3d 100644
--- a/gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.ui
+++ b/gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.ui
@@ -9,45 +9,21 @@
<property name="valign">fill</property>
<property name="orientation">vertical</property>
<child>
- <object class="GtkStack" id="stack">
+ <object class="GisPageHeader" id="header">
+ <property name="visible">True</property>
+ <property name="margin-top">24</property>
+ <!-- TODO title and subtitle are set in code, so are not set here -->
+ <property name="title">Parental Controls for Kimberley</property>
+ <property name="subtitle">TODO blasd farsd hngh wuf</property>
+ <!-- TODO: Would be good to use the user avatar instead of an icon -->
+ <property name="icon-name">dialog-password-symbolic</property>
+ <property name="show-icon" bind-source="GisParentalControlsPage" bind-property="small-screen"
bind-flags="invert-boolean|sync-create"/>
+ </object>
+ </child>
+ <child>
+ <object class="MctUserControls" id="user_controls">
<property name="visible">True</property>
- <property name="valign">start</property>
- <property name="vexpand">True</property>
-
- <child>
- <object class="GtkBox">
- <property name="visible">True</property>
- <child>
- <object class="MctUserControls" id="user_controls">
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="name">user-controls</property>
- </packing>
- </child>
-
- <child>
- <object class="GtkBox">
- <property name="visible">True</property>
- <child>
- <object class="MctUserControls" id="user_controls">
- <property name="visible">True</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="name">parent-password</property>
- </packing>
- </child>
-
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
</child>
</object>
</child>
diff --git a/gnome-initial-setup/pages/password/gis-password-page.c
b/gnome-initial-setup/pages/password/gis-password-page.c
index 3d2de27..743f48a 100644
--- a/gnome-initial-setup/pages/password/gis-password-page.c
+++ b/gnome-initial-setup/pages/password/gis-password-page.c
@@ -66,18 +66,12 @@ typedef enum
static GParamSpec *obj_props[PROP_PARENT_MODE + 1];
static void
-set_parent_mode (GisPasswordPage *page,
- gboolean parent_mode)
+update_header (GisPasswordPage *page)
{
GisPasswordPagePrivate *priv = gis_password_page_get_instance_private (page);
const gchar *title, *subtitle;
- g_return_if_fail (GIS_IS_PASSWORD_PAGE (page));
-
- if (priv->parent_mode == parent_mode)
- return;
-
- if (!parent_mode)
+ if (!priv->parent_mode)
{
title = _("Set a User Password");
subtitle = _("Be careful not to lose your password.");
@@ -92,9 +86,23 @@ set_parent_mode (GisPasswordPage *page,
"title", title,
"subtitle", subtitle,
NULL);
+}
+
+static void
+set_parent_mode (GisPasswordPage *page,
+ gboolean parent_mode)
+{
+ GisPasswordPagePrivate *priv = gis_password_page_get_instance_private (page);
+
+ g_return_if_fail (GIS_IS_PASSWORD_PAGE (page));
+
+ if (priv->parent_mode == parent_mode)
+ return;
priv->parent_mode = parent_mode;
g_object_notify_by_pspec (G_OBJECT (page), obj_props[PROP_PARENT_MODE]);
+
+ update_header (page);
}
static gboolean
@@ -324,6 +332,7 @@ gis_password_page_constructed (GObject *object)
G_CALLBACK (username_changed), page);
validate (page);
+ update_header (page);
gtk_widget_show (GTK_WIDGET (page));
}
@@ -389,25 +398,6 @@ gis_password_page_class_init (GisPasswordPageClass *klass)
GisPageClass *page_class = GIS_PAGE_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- /**
- * GisPasswordPage:parent-mode:
- *
- * If %FALSE (the default), this page will collect a password for the main
- * user account. If %TRUE, it will collect a password for controlling access
- * to parental controls — this will affect where the password is stored, and
- * the appearance of the page.
- *
- * Since: 3.36
- */
- obj_props[PROP_PARENT_MODE] =
- g_param_spec_boolean ("parent-mode", "Parent Mode",
- "Whether to collect a password for the main user account or a parent account.",
- FALSE,
- G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY);
-
- g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_props), obj_props);
-
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
"/org/gnome/initial-setup/gis-password-page.ui");
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisPasswordPage, password_entry);
@@ -427,6 +417,24 @@ gis_password_page_class_init (GisPasswordPageClass *klass)
object_class->get_property = gis_password_page_get_property;
object_class->set_property = gis_password_page_set_property;
object_class->dispose = gis_password_page_dispose;
+
+ /**
+ * GisPasswordPage:parent-mode:
+ *
+ * If %FALSE (the default), this page will collect a password for the main
+ * user account. If %TRUE, it will collect a password for controlling access
+ * to parental controls — this will affect where the password is stored, and
+ * the appearance of the page.
+ *
+ * Since: 3.36
+ */
+ obj_props[PROP_PARENT_MODE] =
+ g_param_spec_boolean ("parent-mode", "Parent Mode",
+ "Whether to collect a password for the main user account or a parent account.",
+ FALSE,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+ g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_props), obj_props);
}
static void
diff --git a/gnome-initial-setup/pages/password/gis-password-page.ui
b/gnome-initial-setup/pages/password/gis-password-page.ui
index 672d39d..b21010c 100644
--- a/gnome-initial-setup/pages/password/gis-password-page.ui
+++ b/gnome-initial-setup/pages/password/gis-password-page.ui
@@ -13,9 +13,7 @@
<object class="GisPageHeader" id="header">
<property name="visible">True</property>
<property name="margin_top">24</property>
- <!-- title and subtitle are set in code, so are not marked as translatable here -->
- <property name="title">Set a Password</property>
- <property name="subtitle">Be careful not to lose your password.</property>
+ <!-- title and subtitle are set in code, so are not set here -->
<property name="icon_name">dialog-password-symbolic</property>
<property name="show_icon" bind-source="GisPasswordPage" bind-property="small-screen"
bind-flags="invert-boolean|sync-create"/>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]