[gnome-shell/uajain/st-entry-password-2: 1/8] St: Add a StPasswordEntry subclass based on StEntry
- From: Umang Jain <uajain src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/uajain/st-entry-password-2: 1/8] St: Add a StPasswordEntry subclass based on StEntry
- Date: Fri, 13 Dec 2019 13:09:47 +0000 (UTC)
commit f61a1f3180252dc5d03af8dc14b8cf541433ee1e
Author: Umang Jain <mailumangjain gmail com>
Date: Tue Nov 12 18:44:17 2019 +0530
St: Add a StPasswordEntry subclass based on StEntry
StPasswordEntry will be put to use for password entries
in various shell dialogs. This is done to have a consistent
behaviour for all password entries and introduce a peek
password functionality for these password entries in the
subsequent commits.
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/619
src/st/meson.build | 2 +
src/st/st-password-entry.c | 199 +++++++++++++++++++++++++++++++++++++++++++++
src/st/st-password-entry.h | 43 ++++++++++
3 files changed, 244 insertions(+)
---
diff --git a/src/st/meson.build b/src/st/meson.build
index 172802bf11..7ab203659b 100644
--- a/src/st/meson.build
+++ b/src/st/meson.build
@@ -15,6 +15,7 @@ st_headers = [
'st-icon-colors.h',
'st-image-content.h',
'st-label.h',
+ 'st-password-entry.h',
'st-scrollable.h',
'st-scroll-bar.h',
'st-scroll-view.h',
@@ -125,6 +126,7 @@ st_sources = [
'st-icon-colors.c',
'st-image-content.c',
'st-label.c',
+ 'st-password-entry.c',
'st-private.c',
'st-scrollable.c',
'st-scroll-bar.c',
diff --git a/src/st/st-password-entry.c b/src/st/st-password-entry.c
new file mode 100644
index 0000000000..be8c926122
--- /dev/null
+++ b/src/st/st-password-entry.c
@@ -0,0 +1,199 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * st-password-entry.c: Password entry actor based on st-entry
+ *
+ * Copyright 2019 Endless Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "st-private.h"
+#include "st-password-entry.h"
+
+#define BLACK_CIRCLE 9679
+
+#define ST_PASSWORD_ENTRY_PRIV(x) st_password_entry_get_instance_private ((StPasswordEntry *) x)
+
+typedef struct _StPasswordEntryPrivate StPasswordEntryPrivate;
+
+struct _StPasswordEntry
+{
+ /*< private >*/
+ StEntry parent_instance;
+};
+
+struct _StPasswordEntryPrivate
+{
+ gboolean password_visible;
+};
+
+enum
+{
+ PROP_0,
+
+ PROP_PASSWORD_VISIBLE,
+
+ N_PROPS
+};
+
+static GParamSpec *props[N_PROPS] = { NULL, };
+
+G_DEFINE_TYPE_WITH_PRIVATE (StPasswordEntry, st_password_entry, ST_TYPE_ENTRY);
+
+static void
+st_password_entry_get_property (GObject *gobject,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ StPasswordEntryPrivate *priv = ST_PASSWORD_ENTRY_PRIV (gobject);
+
+ switch (prop_id)
+ {
+ case PROP_PASSWORD_VISIBLE:
+ g_value_set_boolean (value, priv->password_visible);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+st_password_entry_set_property (GObject *gobject,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ StPasswordEntry *entry = ST_PASSWORD_ENTRY (gobject);
+
+ switch (prop_id)
+ {
+ case PROP_PASSWORD_VISIBLE:
+ st_password_entry_set_password_visible (entry, g_value_get_boolean (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+st_password_entry_class_init (StPasswordEntryClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->get_property = st_password_entry_get_property;
+ gobject_class->set_property = st_password_entry_set_property;
+
+ props[PROP_PASSWORD_VISIBLE] = g_param_spec_boolean ("password-visible",
+ "Password visible",
+ "Whether to text in the entry is masked or not",
+ FALSE,
+ ST_PARAM_READWRITE);
+
+ g_object_class_install_properties (gobject_class, N_PROPS, props);
+}
+
+static void
+clutter_text_password_char_cb (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ StPasswordEntry *entry = ST_PASSWORD_ENTRY (user_data);
+ ClutterActor *clutter_text;
+
+ clutter_text = st_entry_get_clutter_text (ST_ENTRY (entry));
+ if (clutter_text_get_password_char (CLUTTER_TEXT (clutter_text)) == 0)
+ st_password_entry_set_password_visible (entry, TRUE);
+ else
+ st_password_entry_set_password_visible (entry, FALSE);
+}
+
+static void
+st_password_entry_init (StPasswordEntry *entry)
+{
+ ClutterActor *clutter_text;
+
+ st_entry_set_text (ST_ENTRY (entry), "");
+
+ clutter_text = st_entry_get_clutter_text (ST_ENTRY (entry));
+ clutter_text_set_password_char (CLUTTER_TEXT (clutter_text), BLACK_CIRCLE);
+
+ st_entry_set_input_purpose (ST_ENTRY (entry), CLUTTER_INPUT_CONTENT_PURPOSE_PASSWORD);
+
+ g_signal_connect (clutter_text, "notify::password-char",
+ G_CALLBACK (clutter_text_password_char_cb), entry);
+}
+
+/**
+ * st_password_entry_new:
+ *
+ * Create a new #StPasswordEntry.
+ *
+ * Returns: a new #StEntry
+ */
+StEntry*
+st_password_entry_new (void)
+{
+ return ST_ENTRY (g_object_new (ST_TYPE_PASSWORD_ENTRY, NULL));
+}
+
+/**
+ * st_password_entry_set_password_visible:
+ * @entry: a #StPasswordEntry
+ * @value: #TRUE to show the password in the entry, #FALSE otherwise
+ *
+ * Sets whether to show or hide text in the password entry.
+ */
+void
+st_password_entry_set_password_visible (StPasswordEntry *entry, gboolean value)
+{
+ StPasswordEntryPrivate *priv;
+ ClutterActor *clutter_text;
+
+ g_return_if_fail (ST_IS_PASSWORD_ENTRY (entry));
+
+ priv = ST_PASSWORD_ENTRY_PRIV (entry);
+ if (priv->password_visible == value)
+ return;
+
+ priv->password_visible = value;
+
+ clutter_text = st_entry_get_clutter_text (ST_ENTRY (entry));
+ if (priv->password_visible)
+ clutter_text_set_password_char (CLUTTER_TEXT (clutter_text), 0);
+ else
+ clutter_text_set_password_char (CLUTTER_TEXT (clutter_text), BLACK_CIRCLE);
+
+ g_object_notify_by_pspec (G_OBJECT (entry), props[PROP_PASSWORD_VISIBLE]);
+}
+
+/**
+ * st_password_entry_get_password_visible:
+ * @entry: a #StPasswordEntry
+ *
+ * Gets whether the text is masked in the password entry.
+ */
+gboolean
+st_password_entry_get_password_visible (StPasswordEntry *entry)
+{
+ StPasswordEntryPrivate *priv;
+
+ g_return_val_if_fail (ST_IS_PASSWORD_ENTRY (entry), FALSE);
+
+ priv = ST_PASSWORD_ENTRY_PRIV (entry);
+ return priv->password_visible;
+}
diff --git a/src/st/st-password-entry.h b/src/st/st-password-entry.h
new file mode 100644
index 0000000000..44dd0b1935
--- /dev/null
+++ b/src/st/st-password-entry.h
@@ -0,0 +1,43 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * st-password-entry.h: Password entry actor based on st-entry
+ *
+ * Copyright 2019 Endless Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#if !defined(ST_H_INSIDE) && !defined(ST_COMPILATION)
+#error "Only <st/st.h> can be included directly.h"
+#endif
+
+#ifndef __ST_PASSWORD_ENTRY_H__
+#define __ST_PASSWORD_ENTRY_H__
+
+G_BEGIN_DECLS
+
+#include <st/st-entry.h>
+
+#define ST_TYPE_PASSWORD_ENTRY (st_password_entry_get_type ())
+
+G_DECLARE_FINAL_TYPE (StPasswordEntry, st_password_entry, ST, PASSWORD_ENTRY, StEntry)
+
+StEntry *st_password_entry_new (void);
+gboolean st_password_entry_get_password_visible (StPasswordEntry *entry);
+void st_password_entry_set_password_visible (StPasswordEntry *entry,
+ gboolean value);
+
+G_END_DECLS
+
+#endif /* __ST_PASSWORD_ENTRY_H__ */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]