From b973007cb78f3d3d96899d4ca6e921d52d7e9c93 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 1 Feb 2010 02:21:38 +0000 Subject: [PATCH] [gcr] Add commun gcr unlock functionality. --- gcr/Makefile.am | 7 +- gcr/gcr-unlock-options-widget.c | 299 +++++++++++++++++++++++++++++++++++++++ gcr/gcr-unlock-options-widget.h | 56 ++++++++ gcr/gcr-unlock-options-widget.ui | 136 ++++++++++++++++++ 4 files changed, 496 insertions(+), 2 deletions(-) create mode 100644 gcr/gcr-unlock-options-widget.c create mode 100644 gcr/gcr-unlock-options-widget.h create mode 100644 gcr/gcr-unlock-options-widget.ui diff --git a/gcr/Makefile.am b/gcr/Makefile.am index 2cc41f6..84a5344 100644 --- a/gcr/Makefile.am +++ b/gcr/Makefile.am @@ -6,7 +6,8 @@ uidir = $(datadir)/gcr/ui/ ui_DATA = \ gcr-certificate-basics-widget.ui \ - gcr-import-dialog.ui + gcr-import-dialog.ui \ + gcr-unlock-options-widget.ui # ------------------------------------------------------------------ # HEADERS @@ -20,7 +21,8 @@ inc_HEADERS = \ gcr-certificate-details-widget.h \ gcr-importer.h \ gcr-parser.h \ - gcr-types.h + gcr-types.h \ + gcr-unlock-options-widget.h # ------------------------------------------------------------------ # LIBRARY @@ -50,6 +52,7 @@ libgcr_la_SOURCES = \ gcr-parser.c gcr-parser.h \ gcr-simple-certificate.c gcr-simple-certificate.h \ gcr-types.h \ + gcr-unlock-options-widget.c gcr-unlock-options-widget.h \ $(BUILT_SOURCES) libgcr_la_CFLAGS = \ diff --git a/gcr/gcr-unlock-options-widget.c b/gcr/gcr-unlock-options-widget.c new file mode 100644 index 0000000..8e5facf --- /dev/null +++ b/gcr/gcr-unlock-options-widget.c @@ -0,0 +1,299 @@ +/* + * Copyright (C) 2010 Stefan Walter + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 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 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include "config.h" + +#include "gcr-unlock-options-widget.h" + +#include + +enum { + PROP_0, + PROP_UNLOCK_AUTO, + PROP_UNLOCK_GLOBAL, + PROP_UNLOCK_TIMEOUT, + PROP_UNLOCK_IDLE +}; + +struct _GcrUnlockOptionsWidgetPrivate { + GtkBuilder *builder; + GtkToggleButton *auto_unlock; + GtkToggleButton *per_application; + GtkToggleButton *lock_logout; + GtkToggleButton *lock_after; + GtkToggleButton *lock_idle; + GtkSpinButton *spin_minutes; +}; + +G_DEFINE_TYPE (GcrUnlockOptionsWidget, gcr_unlock_options_widget, GTK_TYPE_ALIGNMENT); + +/* ----------------------------------------------------------------------------- + * INTERNAL + */ + +static GtkToggleButton* +builder_get_toggle_button (GtkBuilder *builder, const gchar *name) +{ + GObject *object = gtk_builder_get_object (builder, name); + g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (object), NULL); + return GTK_TOGGLE_BUTTON (object); +} + +static GtkSpinButton* +builder_get_spin_button (GtkBuilder *builder, const gchar *name) +{ + GObject *object = gtk_builder_get_object (builder, name); + g_return_val_if_fail (GTK_IS_SPIN_BUTTON (object), NULL); + return GTK_SPIN_BUTTON (object); +} + +static void +on_auto_check_unlock_toggled (GtkToggleButton *check, GtkBuilder *builder) +{ + GtkWidget *area = GTK_WIDGET (gtk_builder_get_object (builder, "options_area")); + gtk_widget_set_sensitive (area, !gtk_toggle_button_get_active (check)); +} + +static void +on_timeout_choices_toggled (GtkToggleButton *unused, GtkBuilder *builder) +{ + GtkWidget *spin; + GtkToggleButton *after, *idle; + + spin = GTK_WIDGET (gtk_builder_get_object (builder, "lock_minutes_spin")); + after = builder_get_toggle_button (builder, "lock_after_choice"); + idle = builder_get_toggle_button (builder, "lock_idle_choice"); + gtk_widget_set_sensitive (spin, gtk_toggle_button_get_active (after) || + gtk_toggle_button_get_active (idle)); + +} + +/* ----------------------------------------------------------------------------- + * OBJECT + */ + + +static GObject* +gcr_unlock_options_widget_constructor (GType type, guint n_props, GObjectConstructParam *props) +{ + GObject *obj = G_OBJECT_CLASS (gcr_unlock_options_widget_parent_class)->constructor (type, n_props, props); + GcrUnlockOptionsWidget *self = NULL; + GtkToggleButton *button; + GtkWidget *widget; + + if (obj) { + self = GCR_UNLOCK_OPTIONS_WIDGET (obj); + + if (!gtk_builder_add_from_file (self->pv->builder, UIDIR "gcr-unlock-options-widget.ui", NULL)) + g_return_val_if_reached (obj); + + widget = GTK_WIDGET (gtk_builder_get_object (self->pv->builder, "unlock-options-widget")); + g_return_val_if_fail (GTK_IS_WIDGET (widget), obj); + gtk_container_add (GTK_CONTAINER (self), widget); + gtk_widget_show (widget); + + button = builder_get_toggle_button (self->pv->builder, "auto_unlock_check"); + g_signal_connect (button, "toggled", G_CALLBACK (on_auto_check_unlock_toggled), self->pv->builder); + on_auto_check_unlock_toggled (button, self->pv->builder); + + button = builder_get_toggle_button (self->pv->builder, "lock_logout_choice"); + g_signal_connect (button, "toggled", G_CALLBACK (on_timeout_choices_toggled), self->pv->builder); + button = builder_get_toggle_button (self->pv->builder, "lock_after_choice"); + g_signal_connect (button, "toggled", G_CALLBACK (on_timeout_choices_toggled), self->pv->builder); + button = builder_get_toggle_button (self->pv->builder, "lock_idle_choice"); + g_signal_connect (button, "toggled", G_CALLBACK (on_timeout_choices_toggled), self->pv->builder); + on_timeout_choices_toggled (button, self->pv->builder); + } + + return obj; +} + +static void +gcr_unlock_options_widget_init (GcrUnlockOptionsWidget *self) +{ + self->pv = (G_TYPE_INSTANCE_GET_PRIVATE (self, GCR_TYPE_UNLOCK_OPTIONS_WIDGET, GcrUnlockOptionsWidgetPrivate)); + self->pv->builder = gtk_builder_new (); +} + +static void +gcr_unlock_options_widget_dispose (GObject *obj) +{ + GcrUnlockOptionsWidget *self = GCR_UNLOCK_OPTIONS_WIDGET (obj); + + if (self->pv->builder) + g_object_unref (self->pv->builder); + self->pv->builder = NULL; + + G_OBJECT_CLASS (gcr_unlock_options_widget_parent_class)->dispose (obj); +} + +static void +gcr_unlock_options_widget_finalize (GObject *obj) +{ + GcrUnlockOptionsWidget *self = GCR_UNLOCK_OPTIONS_WIDGET (obj); + + g_assert (!self->pv->builder); + + G_OBJECT_CLASS (gcr_unlock_options_widget_parent_class)->finalize (obj); +} + +static void +gcr_unlock_options_widget_set_property (GObject *obj, guint prop_id, const GValue *value, + GParamSpec *pspec) +{ + GcrUnlockOptionsWidget *self = GCR_UNLOCK_OPTIONS_WIDGET (obj); + GtkToggleButton *button; + GtkSpinButton *spin; + gint seconds; + + spin = builder_get_spin_button (self->pv->builder, "lock_minutes_spin"); + + switch (prop_id) { + case PROP_UNLOCK_AUTO: + button = builder_get_toggle_button (self->pv->builder, "auto_unlock_check"); + gtk_toggle_button_set_active (button, g_value_get_boolean (value)); + break; + case PROP_UNLOCK_GLOBAL: + button = builder_get_toggle_button (self->pv->builder, "per_application_check"); + gtk_toggle_button_set_active (button, !g_value_get_boolean (value)); + break; + case PROP_UNLOCK_TIMEOUT: + button = builder_get_toggle_button (self->pv->builder, "lock_after_choice"); + seconds = g_value_get_int (value); + if (seconds <= 0) { + gtk_toggle_button_set_active (button, FALSE); + } else { + gtk_toggle_button_set_active (button, TRUE); + spin = builder_get_spin_button (self->pv->builder, "lock_minutes_spin"); + gtk_spin_button_set_value (spin, seconds / 60); + } + break; + case PROP_UNLOCK_IDLE: + button = builder_get_toggle_button (self->pv->builder, "lock_idle_choice"); + seconds = g_value_get_int (value); + if (seconds <= 0) { + gtk_toggle_button_set_active (button, FALSE); + } else { + gtk_toggle_button_set_active (button, TRUE); + spin = builder_get_spin_button (self->pv->builder, "lock_minutes_spin"); + gtk_spin_button_set_value (spin, seconds / 60); + } + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); + break; + } +} + +static void +gcr_unlock_options_widget_get_property (GObject *obj, guint prop_id, GValue *value, + GParamSpec *pspec) +{ + GcrUnlockOptionsWidget *self = GCR_UNLOCK_OPTIONS_WIDGET (obj); + GtkToggleButton *button; + GtkSpinButton *spin; + gboolean auto_unlock; + gint minutes; + + button = builder_get_toggle_button (self->pv->builder, "auto_unlock_check"); + auto_unlock = gtk_toggle_button_get_active (button); + + spin = builder_get_spin_button (self->pv->builder, "lock_minutes_spin"); + minutes = gtk_spin_button_get_value_as_int (spin); + + switch (prop_id) { + case PROP_UNLOCK_AUTO: + g_value_set_boolean (value, auto_unlock); + break; + case PROP_UNLOCK_GLOBAL: + if (auto_unlock) { + g_value_set_boolean (value, TRUE); + } else { + button = builder_get_toggle_button (self->pv->builder, "per_application_check"); + g_value_set_boolean (value, !gtk_toggle_button_get_active (button)); + } + break; + case PROP_UNLOCK_TIMEOUT: + if (auto_unlock) { + g_value_set_int (value, 0); + } else { + button = builder_get_toggle_button (self->pv->builder, "lock_after_choice"); + if (!gtk_toggle_button_get_active (button)) + g_value_set_int (value, 0); + else + g_value_set_int (value, minutes * 60); + } + break; + case PROP_UNLOCK_IDLE: + if (auto_unlock) { + g_value_set_int (value, 0); + } else { + button = builder_get_toggle_button (self->pv->builder, "lock_idle_choice"); + if (!gtk_toggle_button_get_active (button)) + g_value_set_int (value, 0); + else + g_value_set_int (value, minutes * 60); + } + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); + break; + } +} + +static void +gcr_unlock_options_widget_class_init (GcrUnlockOptionsWidgetClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gcr_unlock_options_widget_parent_class = g_type_class_peek_parent (klass); + g_type_class_add_private (klass, sizeof (GcrUnlockOptionsWidgetPrivate)); + + gobject_class->constructor = gcr_unlock_options_widget_constructor; + gobject_class->dispose = gcr_unlock_options_widget_dispose; + gobject_class->finalize = gcr_unlock_options_widget_finalize; + gobject_class->set_property = gcr_unlock_options_widget_set_property; + gobject_class->get_property = gcr_unlock_options_widget_get_property; + + g_object_class_install_property (gobject_class, PROP_UNLOCK_AUTO, + g_param_spec_boolean ("unlock-auto", "Unlock Auto", "Unlock Automatically", + FALSE, G_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, PROP_UNLOCK_GLOBAL, + g_param_spec_boolean ("unlock-global", "Unlock Global", "Unlock Globally", + TRUE, G_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, PROP_UNLOCK_TIMEOUT, + g_param_spec_int ("unlock-timeout", "Unlock Timeout", "Unlock Timeout", + 0, G_MAXINT, 0, G_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, PROP_UNLOCK_IDLE, + g_param_spec_int ("unlock-idle", "Unlock Idle", "Unlock Idle Timeout", + 0, G_MAXINT, 0, G_PARAM_READWRITE)); +} + +/* ----------------------------------------------------------------------------- + * PUBLIC + */ + +GtkWidget* +gcr_unlock_options_widget_new (void) +{ + return g_object_new (GCR_TYPE_UNLOCK_OPTIONS_WIDGET, NULL); +} diff --git a/gcr/gcr-unlock-options-widget.h b/gcr/gcr-unlock-options-widget.h new file mode 100644 index 0000000..835a550 --- /dev/null +++ b/gcr/gcr-unlock-options-widget.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2010 Stefan Walter + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 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 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef __GCR_UNLOCK_OPTIONS_WIDGET_H__ +#define __GCR_UNLOCK_OPTIONS_WIDGET_H__ + +#include +#include + +#include "gcr-types.h" + +G_BEGIN_DECLS + +#define GCR_TYPE_UNLOCK_OPTIONS_WIDGET (gcr_unlock_options_widget_get_type ()) +#define GCR_UNLOCK_OPTIONS_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCR_TYPE_UNLOCK_OPTIONS_WIDGET, GcrUnlockOptionsWidget)) +#define GCR_UNLOCK_OPTIONS_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCR_TYPE_UNLOCK_OPTIONS_WIDGET, GcrUnlockOptionsWidgetClass)) +#define GCR_IS_UNLOCK_OPTIONS_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCR_TYPE_UNLOCK_OPTIONS_WIDGET)) +#define GCR_IS_UNLOCK_OPTIONS_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCR_TYPE_UNLOCK_OPTIONS_WIDGET)) +#define GCR_UNLOCK_OPTIONS_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCR_TYPE_UNLOCK_OPTIONS_WIDGET, GcrUnlockOptionsWidgetClass)) + +typedef struct _GcrUnlockOptionsWidget GcrUnlockOptionsWidget; +typedef struct _GcrUnlockOptionsWidgetClass GcrUnlockOptionsWidgetClass; +typedef struct _GcrUnlockOptionsWidgetPrivate GcrUnlockOptionsWidgetPrivate; + +struct _GcrUnlockOptionsWidget { + GtkAlignment parent; + GcrUnlockOptionsWidgetPrivate *pv; +}; + +struct _GcrUnlockOptionsWidgetClass { + GtkAlignmentClass parent_class; +}; + +GType gcr_unlock_options_widget_get_type (void); + +GtkWidget* gcr_unlock_options_widget_new (void); + +G_END_DECLS + +#endif /* __GCR_UNLOCK_OPTIONS_WIDGET_H__ */ diff --git a/gcr/gcr-unlock-options-widget.ui b/gcr/gcr-unlock-options-widget.ui new file mode 100644 index 0000000..0fbe17d --- /dev/null +++ b/gcr/gcr-unlock-options-widget.ui @@ -0,0 +1,136 @@ + + + + + + True + 0 + none + + + True + 3 + 12 + + + True + vertical + 6 + + + Lock this keyring when I log out. + True + True + False + True + True + + + 0 + + + + + True + 6 + + + True + vertical + 6 + + + Lock this keyring after + True + True + False + True + lock_logout_choice + + + False + 0 + + + + + Lock this keyring if idle for + True + True + False + True + lock_logout_choice + + + False + 1 + + + + + False + 0 + + + + + True + True + + spin_adjustment + 1 + True + + + False + 1 + + + + + True + 0 + minutes. + + + 2 + + + + + 1 + + + + + Prompt me for each application that accesses this keyring. + True + True + False + True + + + 2 + + + + + + + + + Automatically unlock this keyring whenever I'm logged in. + True + True + False + True + + + + + 1 + 999 + 1 + 10 + + -- 2.7.4