[seahorse] common: Migrate SeahorseLockable to vala



commit 3ad8df0fa3630838843173221cc9da421a5975d1
Author: Stef Walter <stefw gnome org>
Date:   Wed Jun 19 14:48:28 2013 +0200

    common: Migrate SeahorseLockable to vala

 common/Makefile.am              |    1 +
 common/lockable.vala            |   48 +++++++++++++
 gkr/seahorse-gkr-keyring.c      |   24 +++++--
 libseahorse/Makefile.am         |    1 -
 libseahorse/seahorse-lockable.c |  143 ---------------------------------------
 libseahorse/seahorse-lockable.h |   89 ------------------------
 pkcs11/seahorse-token.c         |   30 +++++----
 pkcs11/seahorse-token.h         |    4 -
 src/seahorse-sidebar.c          |   17 ++---
 9 files changed, 93 insertions(+), 264 deletions(-)
---
diff --git a/common/Makefile.am b/common/Makefile.am
index 5beeb17..f6709f2 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -15,6 +15,7 @@ libcommon_la_SOURCES = \
        exportable.vala \
        exporter.vala \
        icons.vala \
+       lockable.vala \
        place.vala \
        registry.vala \
        viewable.vala \
diff --git a/common/lockable.vala b/common/lockable.vala
new file mode 100644
index 0000000..b6113b8
--- /dev/null
+++ b/common/lockable.vala
@@ -0,0 +1,48 @@
+/*
+ * Seahorse
+ *
+ * Copyright (C) 2004,2005 Stefan Walter
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * 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.
+ */
+
+namespace Seahorse {
+
+public interface Lockable : GLib.Object {
+       public abstract bool lockable { get; }
+       public abstract bool unlockable { get; }
+
+       public abstract async bool lock(GLib.TlsInteraction? interaction,
+                                       GLib.Cancellable? cancellable) throws GLib.Error;
+
+       public abstract async bool unlock(GLib.TlsInteraction? interaction,
+                                         GLib.Cancellable? cancellable) throws GLib.Error;
+
+       public static bool can_lock(GLib.Object object) {
+               if (object is Lockable)
+                       return ((Lockable)object).lockable;
+               return false;
+       }
+
+       public static bool can_unlock(GLib.Object object) {
+               if (object is Lockable)
+                       return ((Lockable)object).unlockable;
+               return false;
+       }
+}
+
+}
diff --git a/gkr/seahorse-gkr-keyring.c b/gkr/seahorse-gkr-keyring.c
index b89cb39..005617c 100644
--- a/gkr/seahorse-gkr-keyring.c
+++ b/gkr/seahorse-gkr-keyring.c
@@ -31,7 +31,6 @@
 
 #include "seahorse-action.h"
 #include "seahorse-common.h"
-#include "seahorse-lockable.h"
 #include "seahorse-progress.h"
 #include "seahorse-util.h"
 
@@ -237,12 +236,25 @@ seahorse_gkr_keyring_get_label (SeahorsePlace *place)
        return secret_collection_get_label (SECRET_COLLECTION (place));
 }
 
+static gboolean
+seahorse_gkr_keyring_get_lockable (SeahorseLockable *lockable)
+{
+       return !secret_collection_get_locked (SECRET_COLLECTION (lockable));
+}
+
+static gboolean
+seahorse_gkr_keyring_get_unlockable (SeahorseLockable *lockable)
+{
+       return secret_collection_get_locked (SECRET_COLLECTION (lockable));
+}
+
 static void
 seahorse_gkr_keyring_get_property (GObject *obj, guint prop_id, GValue *value, 
                            GParamSpec *pspec)
 {
        SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (obj);
        SeahorsePlace *place = SEAHORSE_PLACE (obj);
+       SeahorseLockable *lockable = SEAHORSE_LOCKABLE (obj);
 
        switch (prop_id) {
        case PROP_DESCRIPTION:
@@ -258,10 +270,10 @@ seahorse_gkr_keyring_get_property (GObject *obj, guint prop_id, GValue *value,
                g_value_take_object (value, seahorse_gkr_keyring_get_actions (place));
                break;
        case PROP_LOCKABLE:
-               g_value_set_boolean (value, !secret_collection_get_locked (SECRET_COLLECTION (self)));
+               g_value_set_boolean (value, seahorse_gkr_keyring_get_lockable (lockable));
                break;
        case PROP_UNLOCKABLE:
-               g_value_set_boolean (value, secret_collection_get_locked (SECRET_COLLECTION (self)));
+               g_value_set_boolean (value, seahorse_gkr_keyring_get_unlockable (lockable));
                break;
        case PROP_DELETABLE:
                g_value_set_boolean (value, TRUE);
@@ -484,9 +496,11 @@ seahorse_gkr_keyring_unlock_finish (SeahorseLockable *lockable,
 static void
 seahorse_keyring_lockable_iface (SeahorseLockableIface *iface)
 {
-       iface->lock_async = seahorse_gkr_keyring_lock_async;
+       iface->get_lockable = seahorse_gkr_keyring_get_lockable;
+       iface->get_unlockable = seahorse_gkr_keyring_get_unlockable;
+       iface->lock = seahorse_gkr_keyring_lock_async;
        iface->lock_finish = seahorse_gkr_keyring_lock_finish;
-       iface->unlock_async = seahorse_gkr_keyring_unlock_async;
+       iface->unlock = seahorse_gkr_keyring_unlock_async;
        iface->unlock_finish = seahorse_gkr_keyring_unlock_finish;
 }
 
diff --git a/libseahorse/Makefile.am b/libseahorse/Makefile.am
index 0b943bf..efa4e24 100644
--- a/libseahorse/Makefile.am
+++ b/libseahorse/Makefile.am
@@ -52,7 +52,6 @@ libseahorse_la_SOURCES = \
        seahorse-debug.c seahorse-debug.h \
        seahorse-interaction.c seahorse-interaction.h \
        seahorse-key-manager-store.c seahorse-key-manager-store.h \
-       seahorse-lockable.c seahorse-lockable.h \
        seahorse-object.c seahorse-object.h \
        seahorse-object-list.c seahorse-object-list.h \
        seahorse-object-model.c seahorse-object-model.h \
diff --git a/pkcs11/seahorse-token.c b/pkcs11/seahorse-token.c
index ea1eb4f..3cc7336 100644
--- a/pkcs11/seahorse-token.c
+++ b/pkcs11/seahorse-token.c
@@ -35,7 +35,6 @@
 #include "seahorse-token.h"
 
 #include "seahorse-common.h"
-#include "seahorse-lockable.h"
 #include "seahorse-util.h"
 
 enum {
@@ -65,6 +64,10 @@ struct _SeahorseTokenPrivate {
        GHashTable *objects_visible;
 };
 
+static gboolean      seahorse_token_get_lockable         (SeahorseLockable *lockable);
+
+static gboolean      seahorse_token_get_unlockable       (SeahorseLockable *lockable);
+
 static void          seahorse_token_place_iface          (SeahorsePlaceIface *iface);
 
 static void          seahorse_token_collection_iface     (GcrCollectionIface *iface);
@@ -631,6 +634,7 @@ seahorse_token_get_property (GObject *object,
 {
        SeahorseToken *self = SEAHORSE_TOKEN (object);
        SeahorsePlace *place = SEAHORSE_PLACE (object);
+       SeahorseLockable *lockable = SEAHORSE_LOCKABLE (object);
 
        switch (prop_id) {
        case PROP_LABEL:
@@ -658,10 +662,10 @@ seahorse_token_get_property (GObject *object,
                g_value_set_boxed (value, self->pv->info);
                break;
        case PROP_LOCKABLE:
-               g_value_set_boolean (value, seahorse_token_get_lockable (self));
+               g_value_set_boolean (value, seahorse_token_get_lockable (lockable));
                break;
        case PROP_UNLOCKABLE:
-               g_value_set_boolean (value, seahorse_token_get_unlockable (self));
+               g_value_set_boolean (value, seahorse_token_get_unlockable (lockable));
                break;
        case PROP_SESSION:
                g_value_set_object (value, seahorse_token_get_session (self));
@@ -978,9 +982,11 @@ seahorse_token_unlock_finish (SeahorseLockable *lockable,
 static void
 seahorse_token_lockable_iface (SeahorseLockableIface *iface)
 {
-       iface->lock_async = seahorse_token_lock_async;
+       iface->get_lockable = seahorse_token_get_lockable;
+       iface->get_unlockable = seahorse_token_get_unlockable;
+       iface->lock = seahorse_token_lock_async;
        iface->lock_finish = seahorse_token_lock_finish;
-       iface->unlock_async = seahorse_token_unlock_async;
+       iface->unlock = seahorse_token_unlock_async;
        iface->unlock_finish = seahorse_token_unlock_finish;
 }
 
@@ -1039,13 +1045,12 @@ seahorse_token_get_info (SeahorseToken *self)
        return self->pv->info;
 }
 
-gboolean
-seahorse_token_get_lockable (SeahorseToken *self)
+static gboolean
+seahorse_token_get_lockable (SeahorseLockable *lockable)
 {
+       SeahorseToken *self = SEAHORSE_TOKEN (lockable);
        GckTokenInfo *info;
 
-       g_return_val_if_fail (SEAHORSE_IS_TOKEN (self), FALSE);
-
        info = seahorse_token_get_info (self);
 
        if ((info->flags & CKF_LOGIN_REQUIRED) == 0)
@@ -1058,13 +1063,12 @@ seahorse_token_get_lockable (SeahorseToken *self)
 
 }
 
-gboolean
-seahorse_token_get_unlockable (SeahorseToken *self)
+static gboolean
+seahorse_token_get_unlockable (SeahorseLockable *lockable)
 {
+       SeahorseToken *self = SEAHORSE_TOKEN (lockable);
        GckTokenInfo *info;
 
-       g_return_val_if_fail (SEAHORSE_IS_TOKEN (self), FALSE);
-
        info = seahorse_token_get_info (self);
 
        if ((info->flags & CKF_LOGIN_REQUIRED) == 0)
diff --git a/pkcs11/seahorse-token.h b/pkcs11/seahorse-token.h
index 2a02c84..fed3eba 100644
--- a/pkcs11/seahorse-token.h
+++ b/pkcs11/seahorse-token.h
@@ -58,10 +58,6 @@ GckSession *           seahorse_token_get_session       (SeahorseToken *self);
 void                   seahorse_token_set_session       (SeahorseToken *self,
                                                          GckSession *session);
 
-gboolean               seahorse_token_get_lockable      (SeahorseToken *self);
-
-gboolean               seahorse_token_get_unlockable    (SeahorseToken *self);
-
 GArray *               seahorse_token_get_mechanisms    (SeahorseToken *self);
 
 gboolean               seahorse_token_has_mechanism     (SeahorseToken *self,
diff --git a/src/seahorse-sidebar.c b/src/seahorse-sidebar.c
index 363cffe..a2bbcb5 100644
--- a/src/seahorse-sidebar.c
+++ b/src/seahorse-sidebar.c
@@ -27,7 +27,6 @@
 #include "seahorse-actions.h"
 #include "seahorse-common.h"
 #include "seahorse-interaction.h"
-#include "seahorse-lockable.h"
 #include "seahorse-util.h"
 
 #include "gkr/seahorse-gkr.h"
@@ -578,8 +577,8 @@ on_cell_renderer_action_icon (GtkTreeViewColumn *column,
        lockable = lookup_lockable_for_iter (model, iter);
 
        if (lockable) {
-               can_lock = seahorse_lockable_can_lock (lockable);
-               can_unlock = seahorse_lockable_can_unlock (lockable);
+               can_lock = seahorse_lockable_can_lock (G_OBJECT (lockable));
+               can_unlock = seahorse_lockable_can_unlock (G_OBJECT (lockable));
        }
 
        if (can_lock || can_unlock) {
@@ -815,8 +814,8 @@ place_lock (SeahorseLockable *lockable,
        GCancellable *cancellable = g_cancellable_new ();
        GTlsInteraction *interaction = seahorse_interaction_new (window);
 
-       seahorse_lockable_lock_async (lockable, interaction, cancellable,
-                                     on_place_locked, g_object_ref (window));
+       seahorse_lockable_lock (lockable, interaction, cancellable,
+                               on_place_locked, g_object_ref (window));
 
        g_object_unref (cancellable);
        g_object_unref (interaction);
@@ -854,8 +853,8 @@ place_unlock (SeahorseLockable *lockable,
        GCancellable *cancellable = g_cancellable_new ();
        GTlsInteraction *interaction = seahorse_interaction_new (window);
 
-       seahorse_lockable_unlock_async (lockable, interaction, cancellable,
-                                       on_place_unlocked, g_object_ref (window));
+       seahorse_lockable_unlock (lockable, interaction, cancellable,
+                                 on_place_unlocked, g_object_ref (window));
 
        g_object_unref (cancellable);
        g_object_unref (interaction);
@@ -1186,9 +1185,9 @@ on_tree_view_button_release_event (GtkWidget *widget,
 
        lockable = lookup_lockable_for_iter (model, &iter);
        if (lockable) {
-               if (seahorse_lockable_can_lock (lockable))
+               if (seahorse_lockable_can_lock (G_OBJECT (lockable)))
                        place_lock (lockable, GTK_WINDOW (window));
-               else if (seahorse_lockable_can_unlock (lockable))
+               else if (seahorse_lockable_can_unlock (G_OBJECT (lockable)))
                        place_unlock (lockable, GTK_WINDOW (window));
        }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]