[krb5-auth-dialog] Drop gtksecentry
- From: Guido Günther <guidog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [krb5-auth-dialog] Drop gtksecentry
- Date: Wed, 6 Oct 2010 09:39:19 +0000 (UTC)
commit cda21c8444b0f4e7096a0a5415faef9e19b43ee9
Author: Guido Günther <agx sigxcpu org>
Date: Tue Oct 5 16:28:09 2010 +0200
Drop gtksecentry
Use our own entry buffer using the secmem functions but derived from
GtkEntryBuffer instead. This fixes the build with GTK+ 3 and gets us the
unicode and input method handling for free.
Makefile.am | 2 +-
configure.ac | 3 +-
gtksecentry/Makefile.am | 12 -
gtksecentry/gseal-gtk-compat.h | 61 -
gtksecentry/gtksecentry.c | 3364 ----------------------------------------
gtksecentry/gtksecentry.h | 190 ---
src/Makefile.am | 5 +-
src/ka-dialog.c | 1 -
src/ka-entry-buffer.c | 229 +++
src/ka-entry-buffer.h | 58 +
src/ka-pwdialog.c | 18 +-
src/ka-pwdialog.h | 2 +-
12 files changed, 300 insertions(+), 3645 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index a6a2bc4..4bc81e1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
NULL =
-SUBDIRS = secmem gtksecentry src po etpo icons preferences help examples plugins
+SUBDIRS = secmem src po etpo icons preferences help examples plugins
EXTRA_DIST = \
krb5-auth-dialog.spec \
diff --git a/configure.ac b/configure.ac
index c96302d..14fb2a6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -39,7 +39,7 @@ AC_MSG_RESULT([$with_gtk])
case "$with_gtk" in
2.0) GTK_API_VERSION=2.0
- GTK_REQUIRED=2.16.0
+ GTK_REQUIRED=2.18.0
GLIB_REQUIRED=2.16.0
DBUS_REQUIRED=0.60
GCONF_REQUIRED=2.8
@@ -281,7 +281,6 @@ krb5-auth-dialog.spec
src/Makefile
src/krb5-auth-dialog.1
secmem/Makefile
-gtksecentry/Makefile
icons/Makefile
icons/22x22/Makefile
icons/48x48/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 591c69f..6c04c5d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -44,11 +44,12 @@ krb5_auth_dialog_SOURCES = \
ka-plugin-loader.h \
ka-closures.h \
ka-closures.c \
+ ka-entry-buffer.h \
+ ka-entry-buffer.c \
dummy-strings.c \
$(NULL)
krb5_auth_dialog_CPPFLAGS = \
- -I$(top_srcdir)/gtksecentry \
-I$(top_srcdir)/secmem \
-DKA_DATA_DIR=\""$(pkgdatadir)"\" \
-DDATA_DIR=\""$(datadir)"\" \
@@ -71,7 +72,6 @@ krb5_auth_dialog_CFLAGS = \
$(NULL)
krb5_auth_dialog_LDADD = \
- $(top_builddir)/gtksecentry/libgtksecentry.a \
$(top_builddir)/secmem/libsecmem.a \
$(NETWORK_MANAGER_LIBS) \
$(LIBCAP) \
@@ -95,7 +95,6 @@ ka-dbus-glue.h: $(srcdir)/ka-dbus.xml
$< > $@
AM_CPPFLAGS = \
- -I $(top_srcdir)/gtksecentry/ \
-I $(top_srcdir)/secmem/ \
$(DISABLE_DEPRECATED) \
$(NULL)
diff --git a/src/ka-dialog.c b/src/ka-dialog.c
index f8c9775..8d5cd46 100644
--- a/src/ka-dialog.c
+++ b/src/ka-dialog.c
@@ -32,7 +32,6 @@
#include <glib/gi18n.h>
#include <gio/gio.h>
-#include "gtksecentry.h"
#include "secmem-util.h"
#include "memory.h"
diff --git a/src/ka-entry-buffer.c b/src/ka-entry-buffer.c
new file mode 100644
index 0000000..45587bf
--- /dev/null
+++ b/src/ka-entry-buffer.c
@@ -0,0 +1,229 @@
+/* Krb5 Auth Applet -- Acquire and release kerberos tickets
+ *
+ * (C) 2010 Guido Guenther <agx sigxcpu org>
+ *
+ * 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.
+ *
+ */
+
+/* Create an entry buffer that uses the secmem routines for password storage */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include <string.h>
+
+#include "ka-entry-buffer.h"
+#include "memory.h"
+
+struct _KaEntryBuffer {
+ GtkEntryBuffer parent;
+
+ KaEntryBufferPrivate *priv;
+};
+
+struct _KaEntryBufferClass {
+ GtkEntryBufferClass parent_class;
+};
+
+G_DEFINE_TYPE (KaEntryBuffer, ka_entry_buffer, GTK_TYPE_ENTRY_BUFFER)
+
+struct _KaEntryBufferPrivate {
+ gchar *password;
+ gsize password_size;
+ gsize password_bytes;
+ guint password_chars;
+};
+
+
+static const gchar *
+ka_entry_buffer_pw_get_text (GtkEntryBuffer *buffer,
+ gsize * n_bytes)
+{
+ KaEntryBuffer *self = KA_ENTRY_BUFFER(buffer);
+
+ if (n_bytes)
+ *n_bytes = self->priv->password_bytes;
+ if (!self->priv->password)
+ return "";
+ return self->priv->password;
+}
+
+
+static guint
+ka_entry_buffer_pw_get_length (GtkEntryBuffer *buffer)
+{
+ KaEntryBuffer *self = KA_ENTRY_BUFFER(buffer);
+ return self->priv->password_chars;
+}
+
+
+static guint
+ka_entry_buffer_pw_insert_text (GtkEntryBuffer *buffer,
+ guint position,
+ const gchar *chars,
+ guint n_chars)
+{
+ KaEntryBuffer *self = KA_ENTRY_BUFFER(buffer);
+ KaEntryBufferPrivate *pv = self->priv;
+ gsize prev_size;
+ gsize n_bytes;
+ gsize at;
+
+ n_bytes = g_utf8_offset_to_pointer (chars, n_chars) - chars;
+
+ /* Need more memory */
+ if (n_bytes + pv->password_bytes + 1 > pv->password_size) {
+ gchar *et_new;
+
+ prev_size = pv->password_size;
+
+ /* Calculate our new buffer size */
+ while (n_bytes + pv->password_bytes + 1 > pv->password_size) {
+ if (pv->password_size == 0)
+ pv->password_size = PW_MIN_SIZE;
+ else {
+ if (2 * pv->password_size < GTK_ENTRY_BUFFER_MAX_SIZE)
+ pv->password_size *= 2;
+ else {
+ pv->password_size = GTK_ENTRY_BUFFER_MAX_SIZE;
+ if (n_bytes >
+ pv->password_size - pv->password_bytes - 1) {
+ n_bytes =
+ pv->password_size - pv->password_bytes - 1;
+ n_bytes =
+ g_utf8_find_prev_char (chars,
+ chars + n_bytes + 1) -
+ chars;
+ n_chars = g_utf8_strlen (chars, n_bytes);
+ }
+ break;
+ }
+ }
+ }
+
+ et_new = secmem_malloc (pv->password_size);
+ memcpy (et_new, pv->password,
+ MIN (prev_size, pv->password_size));
+ secmem_free (pv->password);
+ pv->password = et_new;
+ }
+
+ /* Actual text insertion */
+ at = g_utf8_offset_to_pointer (pv->password,
+ position) - pv->password;
+ g_memmove (pv->password + at + n_bytes, pv->password + at,
+ pv->password_bytes - at);
+ memcpy (pv->password + at, chars, n_bytes);
+
+ /* Book keeping */
+ pv->password_bytes += n_bytes;
+ pv->password_chars += n_chars;
+ pv->password[pv->password_bytes] = '\0';
+
+ gtk_entry_buffer_emit_inserted_text (GTK_ENTRY_BUFFER(self), position, chars, n_chars);
+ return n_chars;
+}
+
+
+static guint
+ka_entry_buffer_pw_delete_text (GtkEntryBuffer *buffer,
+ guint position, guint n_chars)
+{
+ KaEntryBuffer *self = KA_ENTRY_BUFFER(buffer);
+ KaEntryBufferPrivate *pv = self->priv;
+ gsize start, end;
+
+ if (position > pv->password_chars)
+ position = pv->password_chars;
+ if (position + n_chars > pv->password_chars)
+ n_chars = pv->password_chars - position;
+
+ if (n_chars > 0) {
+ start =
+ g_utf8_offset_to_pointer (pv->password,
+ position) - pv->password;
+ end =
+ g_utf8_offset_to_pointer (pv->password,
+ position + n_chars) - pv->password;
+
+ g_memmove (pv->password + start, pv->password + end,
+ pv->password_bytes + 1 - end);
+ pv->password_chars -= n_chars;
+ pv->password_bytes -= (end - start);
+ gtk_entry_buffer_emit_deleted_text (GTK_ENTRY_BUFFER(self), position, n_chars);
+ }
+ return n_chars;
+}
+
+
+static void
+ka_entry_buffer_dispose (GObject *object)
+{
+ G_OBJECT_CLASS (ka_entry_buffer_parent_class)->dispose (object);
+}
+
+static void
+ka_entry_buffer_finalize (GObject *object)
+{
+ KaEntryBuffer *self = KA_ENTRY_BUFFER(object);
+
+ if (self->priv->password) {
+ secmem_free (self->priv->password);
+ self->priv->password_size = 0;
+ self->priv->password_bytes = 0;
+ self->priv->password_chars = 0;
+ }
+ G_OBJECT_CLASS (ka_entry_buffer_parent_class)->finalize (object);
+}
+
+static void
+ka_entry_buffer_class_init (KaEntryBufferClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkEntryBufferClass *eb_class = GTK_ENTRY_BUFFER_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (KaEntryBufferPrivate));
+
+ eb_class->get_text = ka_entry_buffer_pw_get_text;
+ eb_class->get_length = ka_entry_buffer_pw_get_length;
+ eb_class->insert_text = ka_entry_buffer_pw_insert_text;
+ eb_class->delete_text = ka_entry_buffer_pw_delete_text;
+
+ object_class->dispose = ka_entry_buffer_dispose;
+ object_class->finalize = ka_entry_buffer_finalize;
+}
+
+static void
+ka_entry_buffer_init (KaEntryBuffer *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
+ KA_TYPE_ENTRY_BUFFER,
+ KaEntryBufferPrivate);
+ self->priv->password = NULL;
+ self->priv->password_size = 0;
+ self->priv->password_bytes = 0;
+ self->priv->password_chars = 0;
+}
+
+KaEntryBuffer *
+ka_entry_buffer_new (void)
+{
+ return g_object_new (KA_TYPE_ENTRY_BUFFER, NULL);
+}
+
+/*
+ * vim:ts:sts=4:sw=4:et:
+ */
diff --git a/src/ka-entry-buffer.h b/src/ka-entry-buffer.h
new file mode 100644
index 0000000..5626ac4
--- /dev/null
+++ b/src/ka-entry-buffer.h
@@ -0,0 +1,58 @@
+/* Krb5 Auth Applet -- Acquire and release kerberos tickets
+ *
+ * (C) 2010 Guido Guenther <agx sigxcpu org>
+ *
+ * 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.
+ *
+ */
+
+#ifndef KA_ENTRY_BUFFER_H
+#define KA_ENTRY_BUFFER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define KA_TYPE_ENTRY_BUFFER ka_entry_buffer_get_type()
+
+#define KA_ENTRY_BUFFER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), KA_TYPE_ENTRY_BUFFER, KaEntryBuffer))
+
+#define KA_ENTRY_BUFFER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), KA_TYPE_ENTRY_BUFFER, KaEntryBufferClass))
+
+#define KA_IS_ENTRY_BUFFER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), KA_TYPE_ENTRY_BUFFER))
+
+#define KA_IS_ENTRY_BUFFER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), KA_TYPE_ENTRY_BUFFER))
+
+#define KA_ENTRY_BUFFER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), KA_TYPE_ENTRY_BUFFER, KaEntryBufferClass))
+
+/* Minimum buffer size */
+#define PW_MIN_SIZE 32
+
+typedef struct _KaEntryBuffer KaEntryBuffer;
+typedef struct _KaEntryBufferClass KaEntryBufferClass;
+typedef struct _KaEntryBufferPrivate KaEntryBufferPrivate;
+
+GType ka_entry_buffer_get_type (void);
+
+KaEntryBuffer* ka_entry_buffer_new (void);
+
+G_END_DECLS
+
+#endif /* _KA_ENTRY_BUFFER */
diff --git a/src/ka-pwdialog.c b/src/ka-pwdialog.c
index da34471..0570ac2 100644
--- a/src/ka-pwdialog.c
+++ b/src/ka-pwdialog.c
@@ -25,6 +25,7 @@
#include "ka-applet-priv.h"
#include "ka-dialog.h"
#include "ka-pwdialog.h"
+#include "ka-entry-buffer.h"
struct _KaPwDialog {
GObject parent;
@@ -196,7 +197,7 @@ ka_pwdialog_hide (const KaPwDialog* pwdialog, gboolean force)
const gchar*
ka_pwdialog_get_password(KaPwDialog *pwdialog)
{
- return gtk_secure_entry_get_text (GTK_SECURE_ENTRY (pwdialog->priv->pw_entry));
+ return gtk_entry_get_text (GTK_ENTRY(pwdialog->priv->pw_entry));
}
gboolean
@@ -229,7 +230,6 @@ ka_pwdialog_setup (KaPwDialog* pwdialog, const gchar *krb5prompt,
{
KaPwDialogPrivate *priv = pwdialog->priv;
gchar *wrong_markup = NULL;
- GtkWidget *e;
gchar *prompt;
int pw4len;
@@ -251,13 +251,8 @@ ka_pwdialog_setup (KaPwDialog* pwdialog, const gchar *krb5prompt,
}
}
- e = gtk_entry_new ();
- gtk_secure_entry_set_invisible_char (GTK_SECURE_ENTRY (priv->pw_entry),
- gtk_entry_get_invisible_char (GTK_ENTRY (e)));
- gtk_widget_destroy (e);
-
/* Clear the password entry field */
- gtk_secure_entry_set_text (GTK_SECURE_ENTRY (priv->pw_entry), "");
+ gtk_entry_set_text (GTK_ENTRY (priv->pw_entry), "");
/* Use the prompt label that krb5 provides us */
gtk_label_set_text (GTK_LABEL (priv->krb_label), prompt);
@@ -292,18 +287,21 @@ KaPwDialog*
ka_pwdialog_create(GtkBuilder* xml)
{
KaPwDialog *pwdialog = ka_pwdialog_new();
+ KaEntryBuffer *buffer = ka_entry_buffer_new ();
KaPwDialogPrivate *priv = pwdialog->priv;
GtkWidget *entry_hbox = NULL;
priv->dialog = GTK_WIDGET (gtk_builder_get_object (xml, "krb5_dialog"));
priv->status_label = GTK_WIDGET (gtk_builder_get_object (xml, "krb5_status_label"));
priv->krb_label = GTK_WIDGET (gtk_builder_get_object (xml, "krb5_message_label"));
- priv->pw_entry = GTK_WIDGET (gtk_secure_entry_new ());
+ priv->pw_entry = GTK_WIDGET (gtk_entry_new_with_buffer (GTK_ENTRY_BUFFER(buffer)));
+ gtk_entry_set_visibility(GTK_ENTRY(priv->pw_entry), FALSE);
+ g_object_unref (buffer);
priv->error_dialog = ka_error_dialog_new();
entry_hbox = GTK_WIDGET (gtk_builder_get_object (xml, "entry_hbox"));
gtk_container_add (GTK_CONTAINER (entry_hbox), priv->pw_entry);
- gtk_secure_entry_set_activates_default (GTK_SECURE_ENTRY (priv->pw_entry), TRUE);
+ gtk_entry_set_activates_default (GTK_ENTRY (priv->pw_entry), TRUE);
gtk_widget_show (priv->pw_entry);
return pwdialog;
diff --git a/src/ka-pwdialog.h b/src/ka-pwdialog.h
index 8b39402..1c244f8 100644
--- a/src/ka-pwdialog.h
+++ b/src/ka-pwdialog.h
@@ -23,9 +23,9 @@
#include <glib.h>
#include <glib-object.h>
+#include <gtk/gtk.h>
#include "config.h"
-#include "gtksecentry.h"
G_BEGIN_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]