[seahorse] Port SeahorsePredicate to Vala.
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse] Port SeahorsePredicate to Vala.
- Date: Sat, 4 Nov 2017 01:53:16 +0000 (UTC)
commit fe3fb690538d42d30d1981c8492fbad25975670d
Author: Niels De Graef <nielsdegraef gmail com>
Date: Wed Oct 4 23:53:14 2017 +0200
Port SeahorsePredicate to Vala.
common/Makefile.am | 1 +
common/predicate.vala | 62 ++++++++++++++++++++++++++++
libseahorse/Makefile.am | 1 -
libseahorse/seahorse-collection.h | 2 +-
libseahorse/seahorse-predicate.c | 71 --------------------------------
libseahorse/seahorse-predicate.h | 46 --------------------
libseahorse/seahorse-search-provider.c | 2 -
pgp/seahorse-gpgme-key.c | 1 -
pgp/seahorse-pgp-keysets.c | 1 -
9 files changed, 64 insertions(+), 123 deletions(-)
---
diff --git a/common/Makefile.am b/common/Makefile.am
index a3566eb..8d7bcc1 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -19,6 +19,7 @@ common_VALA = \
common/icons.vala \
common/lockable.vala \
common/object.vala \
+ common/predicate.vala \
common/passphrase-prompt.vala \
common/place.vala \
common/registry.vala \
diff --git a/common/predicate.vala b/common/predicate.vala
new file mode 100644
index 0000000..dcd6616
--- /dev/null
+++ b/common/predicate.vala
@@ -0,0 +1,62 @@
+/*
+ * Seahorse
+ *
+ * Copyright (C) 2008 Stefan Walter
+ * Copyright (C) 2011 Collabora Ltd.
+ * Copyright (C) 2017 Niels De Graef
+ *
+ * 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, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+[CCode (has_target = false)]
+public delegate bool Seahorse.PredicateFunc(Seahorse.Object obj, void* custom_target);
+
+public class Seahorse.Predicate {
+ public Type type;
+ public Usage usage;
+ public Flags flags;
+ public Flags nflags;
+ public PredicateFunc custom;
+ public void* custom_target;
+
+ /**
+ * Matches a seahorse object and a predicate
+ *
+ * @param obj The predicate to match
+ *
+ * @return false if predicate does not match the Object, true else
+ */
+ public bool match(Object obj) {
+ // Check all the fields
+ if (this.type != 0 && !(obj.get_type().is_a(this.type) && this.type.is_a(obj.get_type())))
+ return false;
+
+ if (this.usage != Usage.NONE && this.usage != obj.usage)
+ return false;
+
+ if (this.flags != 0 || this.nflags != 0) {
+ if (this.flags != Flags.NONE && (obj.object_flags in this.flags))
+ return false;
+ if (this.nflags != Flags.NONE && (obj.object_flags in this.nflags))
+ return false;
+ }
+
+ // And any custom stuff
+ if (this.custom != null && !this.custom(obj, this.custom_target))
+ return false;
+
+ return true;
+ }
+}
diff --git a/libseahorse/Makefile.am b/libseahorse/Makefile.am
index b111ad8..372780f 100644
--- a/libseahorse/Makefile.am
+++ b/libseahorse/Makefile.am
@@ -34,7 +34,6 @@ libseahorse_a_SOURCES = \
libseahorse/seahorse-object-list.c libseahorse/seahorse-object-list.h \
libseahorse/seahorse-object-model.c libseahorse/seahorse-object-model.h \
libseahorse/seahorse-object-widget.c libseahorse/seahorse-object-widget.h \
- libseahorse/seahorse-predicate.c libseahorse/seahorse-predicate.h \
libseahorse/seahorse-prefs.c libseahorse/seahorse-prefs.h \
libseahorse/seahorse-progress.c libseahorse/seahorse-progress.h \
libseahorse/seahorse-search-provider.c libseahorse/seahorse-search-provider.h \
diff --git a/libseahorse/seahorse-collection.h b/libseahorse/seahorse-collection.h
index 98dfe7e..2546b06 100644
--- a/libseahorse/seahorse-collection.h
+++ b/libseahorse/seahorse-collection.h
@@ -23,7 +23,7 @@
#include <gcr/gcr.h>
-#include "seahorse-predicate.h"
+#include "seahorse-common.h"
#define SEAHORSE_TYPE_COLLECTION (seahorse_collection_get_type ())
#define SEAHORSE_COLLECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SEAHORSE_TYPE_COLLECTION,
SeahorseCollection))
diff --git a/libseahorse/seahorse-search-provider.c b/libseahorse/seahorse-search-provider.c
index 8ade89c..22cf633 100644
--- a/libseahorse/seahorse-search-provider.c
+++ b/libseahorse/seahorse-search-provider.c
@@ -23,8 +23,6 @@
#include "seahorse-application.h"
#include "seahorse-collection.h"
-#include "seahorse-predicate.h"
-#include "seahorse-search-provider.h"
#include "seahorse-widget.h"
#include "seahorse-shell-search-provider-generated.h"
diff --git a/pgp/seahorse-gpgme-key.c b/pgp/seahorse-gpgme-key.c
index 8d79e45..aac8b44 100644
--- a/pgp/seahorse-gpgme-key.c
+++ b/pgp/seahorse-gpgme-key.c
@@ -33,7 +33,6 @@
#include "seahorse-common.h"
-#include "libseahorse/seahorse-predicate.h"
#include "libseahorse/seahorse-object-list.h"
#include "libseahorse/seahorse-util.h"
diff --git a/pgp/seahorse-pgp-keysets.c b/pgp/seahorse-pgp-keysets.c
index 9f0c663..f567c6f 100644
--- a/pgp/seahorse-pgp-keysets.c
+++ b/pgp/seahorse-pgp-keysets.c
@@ -30,7 +30,6 @@
#include "libseahorse/seahorse-application.h"
#include "libseahorse/seahorse-collection.h"
-#include "libseahorse/seahorse-predicate.h"
/* -----------------------------------------------------------------------------
* COMMON KEYSETS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]