[geary/wip/768975-service-info: 3/4] Introduce ServiceInformation classes
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/768975-service-info: 3/4] Introduce ServiceInformation classes
- Date: Thu, 12 Oct 2017 02:55:05 +0000 (UTC)
commit cd3cb4c6ffedbc99270758e32b0fa602806296b4
Author: Oskar Viljasaar <oskar viljasaar gmail com>
Date: Fri Jul 14 17:10:35 2017 +0200
Introduce ServiceInformation classes
This introduces an abstract ServiceInformation class and a derived
LocalServiceInformation class describing various settings used to
connect to IMAP and SMTP servers. No functional changes for now.
In the future, LocalServiceInformation will be moved client-side.
po/POTFILES.in | 2 +
src/CMakeLists.txt | 2 +
.../api/geary-local-service-information.vala | 107 ++++++++++++++++++++
src/engine/api/geary-service-information.vala | 49 +++++++++
4 files changed, 160 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b4d416f..515b48f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -123,6 +123,7 @@ src/engine/api/geary-folder-supports-mark.vala
src/engine/api/geary-folder-supports-move.vala
src/engine/api/geary-folder-supports-remove.vala
src/engine/api/geary-folder.vala
+src/engine/api/geary-local-service-information.vala
src/engine/api/geary-logging.vala
src/engine/api/geary-named-flag.vala
src/engine/api/geary-named-flags.vala
@@ -130,6 +131,7 @@ src/engine/api/geary-progress-monitor.vala
src/engine/api/geary-revokable.vala
src/engine/api/geary-search-folder.vala
src/engine/api/geary-search-query.vala
+src/engine/api/geary-service-information.vala
src/engine/api/geary-service-provider.vala
src/engine/api/geary-service.vala
src/engine/api/geary-special-folder-type.vala
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 63e5d27..48edda2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -35,6 +35,7 @@ engine/api/geary-folder-supports-empty.vala
engine/api/geary-folder-supports-mark.vala
engine/api/geary-folder-supports-move.vala
engine/api/geary-folder-supports-remove.vala
+engine/api/geary-local-service-information.vala
engine/api/geary-logging.vala
engine/api/geary-named-flag.vala
engine/api/geary-named-flags.vala
@@ -43,6 +44,7 @@ engine/api/geary-revokable.vala
engine/api/geary-search-folder.vala
engine/api/geary-search-query.vala
engine/api/geary-service.vala
+engine/api/geary-service-information.vala
engine/api/geary-service-provider.vala
engine/api/geary-special-folder-type.vala
diff --git a/src/engine/api/geary-local-service-information.vala
b/src/engine/api/geary-local-service-information.vala
new file mode 100644
index 0000000..41bb7dc
--- /dev/null
+++ b/src/engine/api/geary-local-service-information.vala
@@ -0,0 +1,107 @@
+/* Copyright 2017 Software Freedom Conservancy Inc.
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+/* A local service implementation. This loads and saves IMAP and SMTP settings
+ * from and to an account's configuration file. */
+public class Geary.LocalServiceInformation : Geary.ServiceInformation {
+
+ // The account's configuration file.
+ private File file;
+
+ public LocalServiceInformation(Geary.Service service,
+ File config_directory,
+ Geary.CredentialsMediator? mediator) {
+ this.service = service;
+ this.file = config_directory.get_child(Geary.AccountInformation.SETTINGS_FILENAME);
+ this.mediator = mediator;
+ this.credentials_method = "METHOD_LIBSECRET";
+ }
+
+ public override void load_settings(KeyFile? key_file = null) throws Error {
+ string host_key = "";
+ string port_key = "";
+ string use_ssl_key = "";
+ string use_starttls_key = "";
+ uint16 default_port = 0;
+
+ key_file.load_from_file(file.get_path() ?? "", KeyFileFlags.NONE);
+
+ switch (service) {
+ case Geary.Service.IMAP:
+ host_key = Geary.Config.IMAP_HOST;
+ port_key = Geary.Config.IMAP_PORT;
+ use_ssl_key = Geary.Config.IMAP_SSL;
+ use_starttls_key = Geary.Config.IMAP_STARTTLS;
+ default_port = Geary.Imap.ClientConnection.DEFAULT_PORT_SSL;
+ break;
+ case Geary.Service.SMTP:
+ host_key = Geary.Config.SMTP_HOST;
+ port_key = Geary.Config.SMTP_PORT;
+ use_ssl_key = Geary.Config.SMTP_SSL;
+ use_starttls_key = Geary.Config.SMTP_STARTTLS;
+ default_port = Geary.Smtp.ClientConnection.DEFAULT_PORT_SSL;
+ this.smtp_noauth = Geary.Config.get_bool_value(
+ key_file, Geary.Config.GROUP, Geary.Config.SMTP_NOAUTH, this.smtp_noauth);
+ if (smtp_noauth)
+ credentials = null;
+ this.smtp_use_imap_credentials = Geary.Config.get_bool_value(
+ key_file, Geary.Config.GROUP, Geary.Config.SMTP_USE_IMAP_CREDENTIALS,
this.smtp_use_imap_credentials);
+ break;
+ }
+
+ this.host = Geary.Config.get_string_value(
+ key_file, Geary.Config.GROUP, host_key, this.host);
+ this.port = Geary.Config.get_uint16_value(
+ key_file, Geary.Config.GROUP, port_key, default_port);
+ this.use_ssl = Geary.Config.get_bool_value(
+ key_file, Geary.Config.GROUP, use_ssl_key, this.use_ssl);
+ this.use_starttls = Geary.Config.get_bool_value(
+ key_file, Geary.Config.GROUP, use_starttls_key, this.use_starttls);
+ }
+
+ public override void load_credentials(KeyFile? key_file = null, string? email_address = null) throws
Error {
+ string remember_password_key = "";
+ string username_key = "";
+
+ key_file.load_from_file(file.get_path() ?? "", KeyFileFlags.NONE);
+
+ switch (this.service) {
+ case Geary.Service.IMAP:
+ username_key = Geary.Config.IMAP_USERNAME_KEY;
+ remember_password_key = Geary.Config.IMAP_REMEMBER_PASSWORD_KEY;
+ break;
+ case Geary.Service.SMTP:
+ username_key = Geary.Config.SMTP_USERNAME_KEY;
+ remember_password_key = Geary.Config.SMTP_REMEMBER_PASSWORD_KEY;
+ break;
+ }
+
+ this.credentials.user = Geary.Config.get_string_value(
+ key_file, Geary.Config.GROUP, username_key, email_address);
+ this.remember_password = Geary.Config.get_bool_value(
+ key_file, Geary.Config.GROUP, remember_password_key, this.remember_password);
+ }
+
+ public override void save_settings(KeyFile? key_file = null) {
+ switch (this.service) {
+ case Geary.Service.IMAP:
+ key_file.set_value(Geary.Config.GROUP, Geary.Config.IMAP_HOST, this.host);
+ key_file.set_integer(Geary.Config.GROUP, Geary.Config.IMAP_PORT, this.port);
+ key_file.set_boolean(Geary.Config.GROUP, Geary.Config.IMAP_SSL, this.use_ssl);
+ key_file.set_boolean(Geary.Config.GROUP, Geary.Config.IMAP_STARTTLS, this.use_starttls);
+ break;
+ case Geary.Service.SMTP:
+ key_file.set_value(Geary.Config.GROUP, Geary.Config.SMTP_HOST, this.host);
+ key_file.set_integer(Geary.Config.GROUP, Geary.Config.SMTP_PORT, this.port);
+ key_file.set_boolean(Geary.Config.GROUP, Geary.Config.SMTP_SSL, this.use_ssl);
+ key_file.set_boolean(Geary.Config.GROUP, Geary.Config.SMTP_STARTTLS, this.use_starttls);
+ key_file.set_boolean(Geary.Config.GROUP, Geary.Config.SMTP_USE_IMAP_CREDENTIALS,
this.smtp_use_imap_credentials);
+ key_file.set_boolean(Geary.Config.GROUP, Geary.Config.SMTP_NOAUTH, this.smtp_noauth);
+ break;
+ }
+ }
+
+}
diff --git a/src/engine/api/geary-service-information.vala b/src/engine/api/geary-service-information.vala
new file mode 100644
index 0000000..e3e5760
--- /dev/null
+++ b/src/engine/api/geary-service-information.vala
@@ -0,0 +1,49 @@
+/* Copyright 2017 Software Freedom Conservancy Inc.
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+public abstract class Geary.ServiceInformation : GLib.Object {
+ public const string METHOD_LIBSECRET = "libsecret";
+ public const string METHOD_GOA = "goa";
+
+ public string host { get; set; default = ""; }
+ public uint16 port { get; set; }
+ public bool use_starttls { get; set; default = false; }
+ public bool use_ssl { get; set; default = true; }
+ public bool remember_password { get; set; default = false; }
+ public Geary.Credentials credentials { get; set; default = new Geary.Credentials(null, null); }
+ public Geary.Service service { get; set; }
+ public Geary.CredentialsMediator? mediator { get; set; default = null; }
+ public string credentials_method { get; set; default = ""; }
+
+ // Used with SMTP servers
+ public bool smtp_noauth { get; set; default = false; }
+ public bool smtp_use_imap_credentials { get; set; default = false; }
+
+ public abstract void load_settings(KeyFile? key_file = null) throws Error;
+
+ public abstract void load_credentials(KeyFile? key_file = null, string? email_address = null) throws
Error;
+
+ public abstract void save_settings(KeyFile? key_file = null);
+
+ public void copy_from(Geary.ServiceInformation from) {
+ this.host = from.host;
+ this.port = from.port;
+ this.use_starttls = from.use_starttls;
+ this.use_ssl = from.use_ssl;
+ this.remember_password = from.remember_password;
+ this.credentials = from.credentials;
+ this.service = from.service;
+ this.mediator = from.mediator;
+ this.credentials_method = from.credentials_method;
+ this.smtp_noauth = from.smtp_noauth;
+ this.smtp_use_imap_credentials = from.smtp_use_imap_credentials;
+ }
+
+ public void set_password(string password, bool remember = false) {
+ this.credentials = new Credentials(this.credentials.user, password);
+ this.remember_password = remember;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]