[seahorse] Port SeahorseServers to Vala
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse] Port SeahorseServers to Vala
- Date: Sat, 4 Nov 2017 01:53:01 +0000 (UTC)
commit 45e4e37f8503c8dcbb4aa7fdb1ae1fb7ecca23ff
Author: Niels De Graef <nielsdegraef gmail com>
Date: Mon Oct 2 13:30:16 2017 +0200
Port SeahorseServers to Vala
common/Makefile.am | 1 +
common/config.vapi | 1 +
common/servers.vala | 116 ++++++++++++++++++++
libseahorse/Makefile.am | 1 -
libseahorse/seahorse-keyserver-control.c | 3 +-
libseahorse/seahorse-prefs.c | 1 -
libseahorse/seahorse-servers.c | 168 ------------------------------
libseahorse/seahorse-servers.h | 44 --------
pgp/seahorse-hkp-source.c | 3 +-
pgp/seahorse-keyserver-search.c | 3 +-
pgp/seahorse-keyserver-sync.c | 3 +-
pgp/seahorse-ldap-source.c | 1 -
pgp/seahorse-pgp-backend.c | 1 -
src/seahorse-main.c | 1 -
14 files changed, 126 insertions(+), 221 deletions(-)
---
diff --git a/common/Makefile.am b/common/Makefile.am
index 29443d8..e29ff49 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -15,6 +15,7 @@ common_VALA = \
common/passphrase-prompt.vala \
common/place.vala \
common/registry.vala \
+ common/servers.vala \
common/types.vala \
common/util.vala \
common/validity.vala \
diff --git a/common/config.vapi b/common/config.vapi
index d14caf7..389a670 100644
--- a/common/config.vapi
+++ b/common/config.vapi
@@ -30,6 +30,7 @@ namespace Prefs {
[CCode (cheader_filename = "libseahorse/seahorse-application.h")]
namespace Application {
public unowned Gtk.Application @get();
+ public unowned GLib.Settings pgp_settings(Gtk.Application? self = null);
}
[CCode (cheader_filename = "libseahorse/seahorse-util.h")]
diff --git a/common/servers.vala b/common/servers.vala
new file mode 100644
index 0000000..916e07a
--- /dev/null
+++ b/common/servers.vala
@@ -0,0 +1,116 @@
+/*
+ * Seahorse
+ *
+ * Copyright (C) 2008 Stefan Walter
+ * 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 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, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+namespace Seahorse.Servers {
+
+[CCode (cname = "SeahorseValidUriFunc", has_target = false)]
+public delegate bool ValidUriFunc(string uri);
+
+private struct ServerInfo {
+ public string type;
+ public string description;
+ public ValidUriFunc validator;
+}
+
+private HashTable<string, ServerInfo?>? server_types = null;
+
+[CCode (array_null_terminated = true, array_length = false)]
+public string[] get_types() {
+ string[] types = {};
+
+ if (server_types != null) {
+ server_types.foreach((uri, server_info) => {
+ types += server_info.type;
+ });
+ }
+
+ return types;
+}
+
+public string? get_description(string? type) {
+ if (server_types == null)
+ return null;
+
+ ServerInfo? info = server_types.lookup(type);
+ if (info != null)
+ return info.description;
+
+ return null;
+}
+
+public void register_type(string? type, string? description, ValidUriFunc validate) {
+ ServerInfo info = ServerInfo() {
+ description = description,
+ type = type,
+ validator = validate
+ };
+
+ if (server_types == null)
+ server_types = new HashTable<string, ServerInfo?>(str_hash, str_equal);
+
+ server_types.replace(info.type, info);
+}
+
+public void cleanup() {
+ server_types = null;
+}
+
+[CCode (array_null_terminated = true, array_length = false)]
+public string[] get_uris() {
+ string[] servers = Application.pgp_settings().get_strv("keyservers");
+
+ // The values are 'uri name', remove the name part
+ string[] uris = {};
+ foreach (string server in servers)
+ uris += server.strip().split(" ", 2)[0];
+
+ return uris;
+}
+
+[CCode (array_null_terminated = true, array_length = false)]
+public string[] get_names() {
+ string[] servers = Application.pgp_settings().get_strv("keyservers");
+
+ // The values are 'uri name', remove the name part
+ string[] names = {};
+ foreach (string server in servers)
+ names += server.strip().split(" ", 2)[1];
+
+ return names;
+}
+
+/**
+ * Checks to see if the passed uri is valid against registered validators
+ */
+public bool is_valid_uri(string? uri) {
+ if (uri == null || server_types == null)
+ return false;
+
+ string[] parts = uri.split(":", 2);
+ if (parts.length > 0) {
+ weak ServerInfo? info = server_types.lookup(parts[0]);
+ if (info != null && (info.validator(uri)))
+ return true;
+ }
+
+ return false;
+}
+
+}
diff --git a/libseahorse/Makefile.am b/libseahorse/Makefile.am
index d9b0fa9..8dd0d0a 100644
--- a/libseahorse/Makefile.am
+++ b/libseahorse/Makefile.am
@@ -45,7 +45,6 @@ libseahorse_a_SOURCES = \
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 \
- libseahorse/seahorse-servers.c libseahorse/seahorse-servers.h \
libseahorse/seahorse-util.c libseahorse/seahorse-util.h \
libseahorse/seahorse-widget.c libseahorse/seahorse-widget.h \
$(dbus_shell_search_provider_built_sources) \
diff --git a/libseahorse/seahorse-keyserver-control.c b/libseahorse/seahorse-keyserver-control.c
index 6c16080..b404c10 100644
--- a/libseahorse/seahorse-keyserver-control.c
+++ b/libseahorse/seahorse-keyserver-control.c
@@ -21,9 +21,10 @@
#include "seahorse-application.h"
#include "seahorse-keyserver-control.h"
-#include "seahorse-servers.h"
#include "seahorse-util.h"
+#include "seahorse-common.h"
+
#define UPDATING "updating"
enum {
diff --git a/libseahorse/seahorse-prefs.c b/libseahorse/seahorse-prefs.c
index cfac081..54bdb76 100644
--- a/libseahorse/seahorse-prefs.c
+++ b/libseahorse/seahorse-prefs.c
@@ -21,7 +21,6 @@
#include "seahorse-application.h"
#include "seahorse-keyserver-control.h"
#include "seahorse-prefs.h"
-#include "seahorse-servers.h"
#include "seahorse-util.h"
#include "seahorse-widget.h"
diff --git a/pgp/seahorse-hkp-source.c b/pgp/seahorse-hkp-source.c
index b0291df..2c46769 100644
--- a/pgp/seahorse-hkp-source.c
+++ b/pgp/seahorse-hkp-source.c
@@ -31,9 +31,10 @@
#include "seahorse-pgp-subkey.h"
#include "seahorse-pgp-uid.h"
+#include "seahorse-common.h"
+
#include "libseahorse/seahorse-object-list.h"
#include "libseahorse/seahorse-progress.h"
-#include "libseahorse/seahorse-servers.h"
#include "libseahorse/seahorse-util.h"
#include <libsoup/soup.h>
diff --git a/pgp/seahorse-keyserver-search.c b/pgp/seahorse-keyserver-search.c
index 05de3a3..f5057d7 100644
--- a/pgp/seahorse-keyserver-search.c
+++ b/pgp/seahorse-keyserver-search.c
@@ -26,7 +26,8 @@
#include "seahorse-keyserver-results.h"
#include "seahorse-pgp-backend.h"
-#include "libseahorse/seahorse-servers.h"
+#include "seahorse-common.h"
+
#include "libseahorse/seahorse-util.h"
#include "libseahorse/seahorse-widget.h"
diff --git a/pgp/seahorse-keyserver-sync.c b/pgp/seahorse-keyserver-sync.c
index b34949a..34f6492 100644
--- a/pgp/seahorse-keyserver-sync.c
+++ b/pgp/seahorse-keyserver-sync.c
@@ -25,10 +25,11 @@
#include "seahorse-pgp-backend.h"
#include "seahorse-transfer.h"
+#include "seahorse-common.h"
+
#include "libseahorse/seahorse-object.h"
#include "libseahorse/seahorse-prefs.h"
#include "libseahorse/seahorse-progress.h"
-#include "libseahorse/seahorse-servers.h"
#include "libseahorse/seahorse-util.h"
#include "libseahorse/seahorse-widget.h"
diff --git a/pgp/seahorse-ldap-source.c b/pgp/seahorse-ldap-source.c
index cb64601..4819c91 100644
--- a/pgp/seahorse-ldap-source.c
+++ b/pgp/seahorse-ldap-source.c
@@ -36,7 +36,6 @@
#include "libseahorse/seahorse-object-list.h"
#include "libseahorse/seahorse-progress.h"
-#include "libseahorse/seahorse-servers.h"
#include "libseahorse/seahorse-util.h"
#include <ldap.h>
diff --git a/pgp/seahorse-pgp-backend.c b/pgp/seahorse-pgp-backend.c
index 29962a1..2f78db5 100644
--- a/pgp/seahorse-pgp-backend.c
+++ b/pgp/seahorse-pgp-backend.c
@@ -30,7 +30,6 @@
#include "seahorse-common.h"
#include "libseahorse/seahorse-progress.h"
-#include "libseahorse/seahorse-servers.h"
#include "libseahorse/seahorse-util.h"
#include <glib/gi18n.h>
diff --git a/src/seahorse-main.c b/src/seahorse-main.c
index dcc34f2..4526f68 100644
--- a/src/seahorse-main.c
+++ b/src/seahorse-main.c
@@ -26,7 +26,6 @@
#include "seahorse-resources.h"
#include "libseahorse/seahorse-application.h"
-#include "libseahorse/seahorse-servers.h"
#include "libseahorse/seahorse-util.h"
#include "pgp/seahorse-pgp.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]