[seahorse] Don't require an Application to rerieve a Settings.
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse] Don't require an Application to rerieve a Settings.
- Date: Mon, 29 Jan 2018 09:13:37 +0000 (UTC)
commit 7802f67fdf1a51494fb9531bdc7b3440732b5073
Author: Niels De Graef <nielsdegraef gmail com>
Date: Mon Jan 29 10:11:27 2018 +0100
Don't require an Application to rerieve a Settings.
This will allow us more easily to move Application to src/, where it
belongs.
common/app-settings.vala | 56 ++++++++++++++++++++++++++++++++
common/config.vapi | 2 -
common/keyserver-control.vala | 8 ++--
common/meson.build | 2 +
common/pgp-settings.vala | 62 ++++++++++++++++++++++++++++++++++++
common/prefs.vala | 8 ++--
common/servers.vala | 8 +---
libseahorse/seahorse-application.c | 32 ------------------
libseahorse/seahorse-application.h | 2 -
pgp/seahorse-keyserver-search.c | 13 +++----
pgp/seahorse-keyserver-sync.c | 11 ++----
pgp/seahorse-pgp-backend.c | 16 +++++-----
pgp/seahorse-pgp-keysets.c | 4 +--
pgp/seahorse-signer.c | 2 +-
14 files changed, 150 insertions(+), 76 deletions(-)
---
diff --git a/common/app-settings.vala b/common/app-settings.vala
new file mode 100644
index 0000000..370ebe7
--- /dev/null
+++ b/common/app-settings.vala
@@ -0,0 +1,56 @@
+/*
+ * Seahorse
+ *
+ * Copyright (C) 2018 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/>.
+ */
+
+public class Seahorse.AppSettings : GLib.Settings {
+ public string[] last_search_servers {
+ owned get { return get_strv("last-search-servers"); }
+ set { set_strv("last-search-servers", value); }
+ }
+
+ public string last_search_text {
+ owned get { return get_string("last-search-text"); }
+ set { set_string("last-search-text", value); }
+ }
+
+ public bool server_auto_publish {
+ get { return get_boolean("server-auto-publish"); }
+ set { set_boolean("server-auto-publish", value); }
+ }
+
+ public bool server_auto_retrieve {
+ get { return get_boolean("server-auto-retrieve"); }
+ set { set_boolean("server-auto-retrieve", value); }
+ }
+
+ public string server_publish_to {
+ owned get { return get_string("server-publish-to"); }
+ set { set_string("server-publish-to", value); }
+ }
+
+ public AppSettings () {
+ GLib.Object (schema_id: "org.gnome.seahorse");
+ }
+
+ private static AppSettings? _instance = null;
+ public static AppSettings instance() {
+ if (_instance == null)
+ _instance = new AppSettings();
+ return _instance;
+ }
+}
diff --git a/common/config.vapi b/common/config.vapi
index b722504..02ccb37 100644
--- a/common/config.vapi
+++ b/common/config.vapi
@@ -24,8 +24,6 @@ namespace Seahorse {
[CCode (cheader_filename = "libseahorse/seahorse-application.h")]
namespace Application {
public unowned Gtk.Application @get();
- public unowned GLib.Settings pgp_settings(Gtk.Application? self = null);
- public unowned GLib.Settings settings(Gtk.Application? self = null);
}
[CCode (cheader_filename = "libseahorse/seahorse-util.h")]
diff --git a/common/keyserver-control.vala b/common/keyserver-control.vala
index 8e851d0..7486563 100644
--- a/common/keyserver-control.vala
+++ b/common/keyserver-control.vala
@@ -67,9 +67,9 @@ public class Seahorse.KeyserverControl : Gtk.ComboBox {
populate_combo(true);
this.changed.connect(on_keyserver_changed);
- Application.pgp_settings().changed["keyserver"].connect(() => populate_combo(false));
+ PgpSettings.instance().changed["keyserver"].connect(() => populate_combo(false));
if (this.settings_key != null)
- Application.settings().changed[this.settings_key].connect(() => populate_combo(true));
+ AppSettings.instance().changed[this.settings_key].connect(() => populate_combo(true));
}
public string? selected() {
@@ -95,7 +95,7 @@ public class Seahorse.KeyserverControl : Gtk.ComboBox {
return;
if (this.settings_key != null)
- Application.settings().set_string(this.settings_key, selected() ?? "");
+ AppSettings.instance().set_string(this.settings_key, selected() ?? "");
}
private int compare_func(Gtk.TreeModel model, Gtk.TreeIter a, Gtk.TreeIter b) {
@@ -127,7 +127,7 @@ public class Seahorse.KeyserverControl : Gtk.ComboBox {
string? chosen = null;
int chosen_info = Option.KEYSERVER;
if (with_key && this.settings_key != null) {
- chosen = Application.settings().get_string(this.settings_key);
+ chosen = AppSettings.instance().get_string(this.settings_key);
} else {
if (get_active_iter(out iter)) {
this.model.get(iter, Column.TEXT, out chosen,
diff --git a/common/meson.build b/common/meson.build
index 3154305..60d10b6 100644
--- a/common/meson.build
+++ b/common/meson.build
@@ -1,6 +1,7 @@
common_sources = [
'actions.vala',
'add-keyserver-dialog.vala',
+ 'app-settings.vala',
'backend.vala',
'catalog.vala',
'collection.vala',
@@ -14,6 +15,7 @@ common_sources = [
'lockable.vala',
'object.vala',
'passphrase-prompt.vala',
+ 'pgp-settings.vala',
'place.vala',
'predicate.vala',
'prefs.vala',
diff --git a/common/pgp-settings.vala b/common/pgp-settings.vala
new file mode 100644
index 0000000..4959899
--- /dev/null
+++ b/common/pgp-settings.vala
@@ -0,0 +1,62 @@
+/*
+ * Seahorse
+ *
+ * Copyright (C) 2018 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/>.
+ */
+
+/* This is installed by gnome-keyring */
+public class Seahorse.PgpSettings : GLib.Settings {
+ public bool ascii_armor {
+ get { return get_boolean("ascii-armor"); }
+ set { set_boolean("ascii-armor", value); }
+ }
+
+ public string default_key {
+ owned get { return get_string("default-key"); }
+ set { set_string("default-key", value); }
+ }
+
+ public bool encrypt_to_self {
+ get { return get_boolean("encrypt-to-self"); }
+ set { set_boolean("encrypt-to-self", value); }
+ }
+
+ public string[] keyservers {
+ owned get { return get_strv("keyservers"); }
+ set { set_strv("keyservers", value); }
+ }
+
+ public string last_signer {
+ owned get { return get_string("last-signer"); }
+ set { set_string("last-signer", value); }
+ }
+
+ public string sort_recipients_by {
+ owned get { return get_string("sort-recipients-by"); }
+ set { set_string("sort-recipients-by", value); }
+ }
+
+ public PgpSettings () {
+ GLib.Object (schema_id: "org.gnome.crypto.pgp");
+ }
+
+ private static PgpSettings? _instance = null;
+ public static PgpSettings instance() {
+ if (_instance == null)
+ _instance = new PgpSettings();
+ return _instance;
+ }
+}
diff --git a/common/prefs.vala b/common/prefs.vala
index 9edad26..aa33282 100644
--- a/common/prefs.vala
+++ b/common/prefs.vala
@@ -142,7 +142,7 @@ public class Seahorse.Prefs : Gtk.Dialog {
selection.set_mode(Gtk.SelectionMode.SINGLE);
selection.changed.connect(keyserver_sel_changed);
- Application.pgp_settings().changed["keyserver"].connect((settings, key) => {
+ PgpSettings.instance().changed["keyserver"].connect((settings, key) => {
populate_keyservers(settings.get_strv(key));
});
@@ -153,9 +153,9 @@ public class Seahorse.Prefs : Gtk.Dialog {
this.keyserver_publish_to_label.set_mnemonic_widget(skc);
- Application.settings().bind("server-auto-retrieve", this.auto_retrieve, "active",
+ AppSettings.instance().bind("server-auto-retrieve", this.auto_retrieve, "active",
SettingsBindFlags.DEFAULT);
- Application.settings().bind("server-auto-publish", this.auto_sync, "active",
+ AppSettings.instance().bind("server-auto-publish", this.auto_sync, "active",
SettingsBindFlags.DEFAULT);
}
@@ -199,7 +199,7 @@ public class Seahorse.Prefs : Gtk.Dialog {
} while (model.iter_next(ref iter));
}
- Application.pgp_settings().set_strv("keyservers", values);
+ PgpSettings.instance().keyservers = values;
}
private void keyserver_row_changed (Gtk.TreeModel model, Gtk.TreePath arg1, Gtk.TreeIter arg2) {
diff --git a/common/servers.vala b/common/servers.vala
index 916e07a..6c453d9 100644
--- a/common/servers.vala
+++ b/common/servers.vala
@@ -74,11 +74,9 @@ public void cleanup() {
[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)
+ foreach (string server in PgpSettings.instance().keyservers)
uris += server.strip().split(" ", 2)[0];
return uris;
@@ -86,11 +84,9 @@ public string[] get_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)
+ foreach (string server in PgpSettings.instance().keyservers)
names += server.strip().split(" ", 2)[1];
return names;
diff --git a/libseahorse/seahorse-application.c b/libseahorse/seahorse-application.c
index 874161e..33afc91 100644
--- a/libseahorse/seahorse-application.c
+++ b/libseahorse/seahorse-application.c
@@ -34,8 +34,6 @@
struct _SeahorseApplication {
GtkApplication parent;
- GSettings *seahorse_settings;
- GSettings *crypto_pgp_settings;
SeahorseSearchProvider *search_provider;
};
@@ -60,13 +58,6 @@ seahorse_application_constructed (GObject *obj)
G_OBJECT_CLASS (seahorse_application_parent_class)->constructed (obj);
the_application = self;
-
- self->seahorse_settings = g_settings_new ("org.gnome.seahorse");
-
-#ifdef WITH_PGP
- /* This is installed by gnome-keyring */
- self->crypto_pgp_settings = g_settings_new ("org.gnome.crypto.pgp");
-#endif
}
static void
@@ -75,11 +66,6 @@ seahorse_application_finalize (GObject *gobject)
SeahorseApplication *self = SEAHORSE_APPLICATION (gobject);
the_application = NULL;
-#ifdef WITH_PGP
- g_clear_object (&self->crypto_pgp_settings);
-#endif
- g_clear_object (&self->seahorse_settings);
-
g_clear_object (&self->search_provider);
G_OBJECT_CLASS (seahorse_application_parent_class)->finalize (gobject);
@@ -255,24 +241,6 @@ seahorse_application_get (void)
return GTK_APPLICATION (the_application);
}
-GSettings *
-seahorse_application_settings (SeahorseApplication *self)
-{
- if (self == NULL)
- self = the_application;
- g_return_val_if_fail (SEAHORSE_IS_APPLICATION (self), NULL);
- return self->seahorse_settings;
-}
-
-GSettings *
-seahorse_application_pgp_settings (SeahorseApplication *self)
-{
- if (self == NULL)
- self = the_application;
- g_return_val_if_fail (SEAHORSE_IS_APPLICATION (self), NULL);
- return self->crypto_pgp_settings;
-}
-
void
seahorse_application_initialize_search (SeahorseApplication *self)
{
diff --git a/libseahorse/seahorse-application.h b/libseahorse/seahorse-application.h
index 5287d4e..5a72a60 100644
--- a/libseahorse/seahorse-application.h
+++ b/libseahorse/seahorse-application.h
@@ -42,8 +42,6 @@ GtkApplication * seahorse_application_new (void);
GtkApplication * seahorse_application_get (void);
-GSettings * seahorse_application_settings (SeahorseApplication *self);
-
GSettings * seahorse_application_pgp_settings (SeahorseApplication *self);
void seahorse_application_initialize_search (SeahorseApplication *self);
diff --git a/pgp/seahorse-keyserver-search.c b/pgp/seahorse-keyserver-search.c
index f5057d7..f88d024 100644
--- a/pgp/seahorse-keyserver-search.c
+++ b/pgp/seahorse-keyserver-search.c
@@ -247,7 +247,7 @@ select_inital_keyservers (SeahorseWidget *swidget)
gchar *name;
guint i;
- names = g_settings_get_strv (seahorse_application_settings (NULL), "last-search-servers");
+ names = g_settings_get_strv (seahorse_app_settings_instance (), "last-search-servers");
/* Close the expander if all servers are selected */
widget = seahorse_widget_get_widget (swidget, "search-where");
@@ -416,12 +416,12 @@ on_keyserver_search_ok_clicked (GtkButton *button, SeahorseWidget *swidget)
/* Get search text and save it for next time */
search = gtk_entry_get_text (GTK_ENTRY (widget));
g_return_if_fail (search != NULL && search[0] != 0);
- g_settings_set_string (seahorse_application_settings (NULL), "last-search-text", search);
+ seahorse_app_settings_set_last_search_text (seahorse_app_settings_instance (), search);
/* The keyservers to search, and save for next time */
selection = get_keyserver_selection (swidget);
g_return_if_fail (selection->uris != NULL);
- g_settings_set_strv (seahorse_application_settings (NULL), "last-search-servers",
+ g_settings_set_strv (seahorse_app_settings_instance (), "last-search-servers",
selection->all ? NULL : (const gchar * const*)selection->uris->pdata);
/* Open the new result window; its transient parent is *our* transient
@@ -465,7 +465,7 @@ seahorse_keyserver_search_show (GtkWindow *parent)
SeahorseWidget *swidget;
GtkWindow *window;
GtkWidget *widget;
- GSettings *settings;
+ SeahorsePgpSettings *settings;
gchar *search;
swidget = seahorse_widget_new ("keyserver-search", parent);
@@ -476,8 +476,7 @@ seahorse_keyserver_search_show (GtkWindow *parent)
widget = seahorse_widget_get_widget (swidget, "search-text");
g_return_val_if_fail (widget != NULL, window);
- search = g_settings_get_string (seahorse_application_settings (NULL),
- "last-search-text");
+ search = seahorse_app_settings_get_last_search_text (seahorse_app_settings_instance ());
if (search != NULL) {
gtk_entry_set_text (GTK_ENTRY (widget), search);
gtk_editable_select_region (GTK_EDITABLE (widget), 0, -1);
@@ -485,7 +484,7 @@ seahorse_keyserver_search_show (GtkWindow *parent)
}
/* The key servers to list */
- settings = seahorse_application_pgp_settings (NULL);
+ settings = seahorse_pgp_settings_instance ();
on_settings_keyservers_changed (settings, "keyservers", swidget);
g_signal_connect_object (settings, "changed::keyservers",
G_CALLBACK (on_settings_keyservers_changed), swidget, 0);
diff --git a/pgp/seahorse-keyserver-sync.c b/pgp/seahorse-keyserver-sync.c
index 324eb09..bab9fad 100644
--- a/pgp/seahorse-keyserver-sync.c
+++ b/pgp/seahorse-keyserver-sync.c
@@ -49,8 +49,7 @@ on_transfer_upload_complete (GObject *object,
gchar *publish_to;
if (!seahorse_pgp_backend_transfer_finish (SEAHORSE_PGP_BACKEND (object), result, &error)) {
- publish_to = g_settings_get_string (seahorse_application_settings (NULL),
- "server-publish-to");
+ publish_to = seahorse_app_settings_get_server_publish_to (seahorse_app_settings_instance ());
seahorse_util_handle_error (&error, NULL,
_("Couldn’t publish keys to server"), publish_to);
g_free (publish_to);
@@ -112,8 +111,7 @@ update_message (SeahorseWidget *swidget)
widget2 = seahorse_widget_get_widget (swidget, "sync-message");
sync_button = seahorse_widget_get_widget (swidget, "sync-button");
- text = g_settings_get_string (seahorse_application_settings (NULL),
- "server-publish-to");
+ text = seahorse_app_settings_get_server_publish_to (seahorse_app_settings_instance ());
if (text && text[0]) {
gtk_widget_show (widget);
gtk_widget_hide (widget2);
@@ -167,7 +165,7 @@ seahorse_keyserver_sync_show (GList *keys, GtkWindow *parent)
/* The right help message */
update_message (swidget);
- g_signal_connect_object (seahorse_application_settings (NULL), "changed::server-publish-to",
+ g_signal_connect_object (seahorse_app_settings_instance (), "changed::server-publish-to",
G_CALLBACK (on_settings_publish_to_changed), swidget, 0);
keys = g_list_copy (keys);
@@ -222,8 +220,7 @@ seahorse_keyserver_sync (GList *keys)
g_strfreev (keyservers);
/* Publishing keys online */
- keyserver = g_settings_get_string (seahorse_application_settings (NULL),
- "server-publish-to");
+ keyserver = seahorse_app_settings_get_server_publish_to (seahorse_app_settings_instance ());
if (keyserver && keyserver[0]) {
source = seahorse_pgp_backend_lookup_remote (NULL, keyserver);
diff --git a/pgp/seahorse-pgp-backend.c b/pgp/seahorse-pgp-backend.c
index 2f78db5..cda6e96 100644
--- a/pgp/seahorse-pgp-backend.c
+++ b/pgp/seahorse-pgp-backend.c
@@ -172,11 +172,11 @@ seahorse_pgp_backend_constructed (GObject *obj)
self->unknown = seahorse_unknown_source_new ();
#ifdef WITH_KEYSERVER
- g_signal_connect (seahorse_application_pgp_settings (NULL), "changed::keyservers",
+ g_signal_connect (seahorse_pgp_settings_instance (), "changed::keyservers",
G_CALLBACK (on_settings_keyservers_changed), self);
/* Initial loading */
- on_settings_keyservers_changed (seahorse_application_pgp_settings (NULL), "keyservers", self);
+ on_settings_keyservers_changed (seahorse_pgp_settings_instance (), "keyservers", self);
#endif
}
@@ -241,7 +241,7 @@ seahorse_pgp_backend_finalize (GObject *obj)
SeahorsePgpBackend *self = SEAHORSE_PGP_BACKEND (obj);
#ifdef WITH_KEYSERVER
- g_signal_handlers_disconnect_by_func (seahorse_application_pgp_settings (NULL),
+ g_signal_handlers_disconnect_by_func (seahorse_pgp_settings_instance (),
on_settings_keyservers_changed, self);
#endif
@@ -356,16 +356,16 @@ SeahorsePgpKey *
seahorse_pgp_backend_get_default_key (SeahorsePgpBackend *self)
{
SeahorsePgpKey *key = NULL;
- GSettings *settings;
+ SeahorsePgpSettings *settings;
const gchar *keyid;
gchar *value;
self = self ? self : seahorse_pgp_backend_get ();
g_return_val_if_fail (SEAHORSE_IS_PGP_BACKEND (self), NULL);
- settings = seahorse_application_pgp_settings (NULL);
+ settings = seahorse_pgp_settings_instance ();
if (settings != NULL) {
- value = g_settings_get_string (settings, "default-key");
+ value = seahorse_pgp_settings_get_default_key (settings);
if (value != NULL && value[0]) {
if (g_str_has_prefix (value, "openpgp:"))
keyid = value + strlen ("openpgp:");
@@ -485,7 +485,7 @@ seahorse_pgp_backend_search_remote_async (SeahorsePgpBackend *self,
g_return_if_fail (SEAHORSE_IS_PGP_BACKEND (self));
/* Get a list of all selected key servers */
- names = g_settings_get_strv (seahorse_application_settings (NULL), "last-search-servers");
+ names = g_settings_get_strv (seahorse_app_settings_instance (), "last-search-servers");
if (names != NULL && names[0] != NULL) {
servers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
for (i = 0; names[i] != NULL; i++)
@@ -768,7 +768,7 @@ seahorse_pgp_backend_discover_keys (SeahorsePgpBackend *self,
#ifdef WITH_KEYSERVER
/* Start a discover process on all todiscover */
- if (g_settings_get_boolean (seahorse_application_settings (NULL), "server-auto-retrieve"))
+ if (seahorse_app_settings_get_server_auto_retrieve (seahorse_app_settings_instance ()))
seahorse_pgp_backend_retrieve_async (self, keyids, SEAHORSE_PLACE (self->keyring),
cancellable, NULL, NULL);
#endif
diff --git a/pgp/seahorse-pgp-keysets.c b/pgp/seahorse-pgp-keysets.c
index 42a187c..aab2fb5 100644
--- a/pgp/seahorse-pgp-keysets.c
+++ b/pgp/seahorse-pgp-keysets.c
@@ -28,8 +28,6 @@
#include "seahorse-common.h"
-#include "libseahorse/seahorse-application.h"
-
/* -----------------------------------------------------------------------------
* COMMON KEYSETS
*/
@@ -78,7 +76,7 @@ seahorse_keyset_pgp_signers_new (void)
collection = seahorse_collection_new_for_predicate (GCR_COLLECTION (keyring),
predicate, g_free);
- g_signal_connect_object (seahorse_application_pgp_settings (NULL), "changed::default-key",
+ g_signal_connect_object (seahorse_pgp_settings_instance (), "changed::default-key",
G_CALLBACK (on_settings_default_key_changed), collection, 0);
return GCR_COLLECTION (collection);
diff --git a/pgp/seahorse-signer.c b/pgp/seahorse-signer.c
index a4d1ab7..836a8ba 100755
--- a/pgp/seahorse-signer.c
+++ b/pgp/seahorse-signer.c
@@ -81,7 +81,7 @@ seahorse_signer_get (GtkWindow *parent)
seahorse_combo_keys_attach (GTK_COMBO_BOX (combo), collection, NULL);
g_object_unref (collection);
- settings = seahorse_application_pgp_settings (NULL);
+ settings = seahorse_pgp_settings_instance ();
/* Select the last key used */
id = g_settings_get_string (settings, "last-signer");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]