[gcr] Add commun gcr unlock functionality.
authorStef Walter <stef@memberwebs.com>
Mon, 1 Feb 2010 02:21:38 +0000 (02:21 +0000)
committerStef Walter <stef@memberwebs.com>
Mon, 1 Feb 2010 02:32:45 +0000 (02:32 +0000)
gcr/Makefile.am
gcr/gcr-unlock-options-widget.c [new file with mode: 0644]
gcr/gcr-unlock-options-widget.h [new file with mode: 0644]
gcr/gcr-unlock-options-widget.ui [new file with mode: 0644]

index 2cc41f6..84a5344 100644 (file)
@@ -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 (file)
index 0000000..8e5facf
--- /dev/null
@@ -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 <glib/gi18n-lib.h>
+
+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 (file)
index 0000000..835a550
--- /dev/null
@@ -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 <glib-object.h>
+#include <gtk/gtk.h>
+
+#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 (file)
index 0000000..0fbe17d
--- /dev/null
@@ -0,0 +1,136 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="GtkFrame" id="unlock-options-widget">
+    <property name="visible">True</property>
+    <property name="label_xalign">0</property>
+    <property name="shadow_type">none</property>
+    <child>
+      <object class="GtkAlignment" id="options_area">
+        <property name="visible">True</property>
+        <property name="top_padding">3</property>
+        <property name="left_padding">12</property>
+        <child>
+          <object class="GtkVBox" id="vbox4">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">6</property>
+            <child>
+              <object class="GtkRadioButton" id="lock_logout_choice">
+                <property name="label" translatable="yes">Lock this keyring when I log out.</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkHBox" id="hbox2">
+                <property name="visible">True</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkVBox" id="vbox5">
+                    <property name="visible">True</property>
+                    <property name="orientation">vertical</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkRadioButton" id="lock_after_choice">
+                        <property name="label" translatable="yes">Lock this keyring after</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="draw_indicator">True</property>
+                        <property name="group">lock_logout_choice</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkRadioButton" id="lock_idle_choice">
+                        <property name="label" translatable="yes">Lock this keyring if idle for</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="draw_indicator">True</property>
+                        <property name="group">lock_logout_choice</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSpinButton" id="lock_minutes_spin">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">&#x2022;</property>
+                    <property name="adjustment">spin_adjustment</property>
+                    <property name="climb_rate">1</property>
+                    <property name="numeric">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">minutes.</property>
+                  </object>
+                  <packing>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="per_application_check">
+                <property name="label" translatable="yes">Prompt me for each application that accesses this keyring.</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child type="label">
+      <object class="GtkCheckButton" id="auto_unlock_check">
+        <property name="label" translatable="yes">Automatically unlock this keyring whenever I'm logged in.</property>
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">False</property>
+        <property name="draw_indicator">True</property>
+      </object>
+    </child>
+  </object>
+  <object class="GtkAdjustment" id="spin_adjustment">
+    <property name="lower">1</property>
+    <property name="upper">999</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+</interface>