[geary/wip/244-save-sent-ui-missing: 1/3] Allow both accounts and services to have provider-specific defaults
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/244-save-sent-ui-missing: 1/3] Allow both accounts and services to have provider-specific defaults
- Date: Wed, 20 Feb 2019 03:09:32 +0000 (UTC)
commit 5475290272be682aeffbed1a8f62d0301af54a09
Author: Michael Gratton <mike vee net>
Date: Wed Feb 20 13:51:26 2019 +1100
Allow both accounts and services to have provider-specific defaults
This updates both AccountInformation and ServiceInformation to
implicitly apply provide-specific defaults, allowing the same
mechanism to provide defaults for accounts, and meaning that API
clients do not need to do this themselves any more. Add unit tests.
src/client/accounts/accounts-editor-add-pane.vala | 13 ++++----
src/client/accounts/accounts-manager.vala | 3 --
src/engine/api/geary-account-information.vala | 15 +++++----
src/engine/api/geary-service-information.vala | 7 +++--
src/engine/api/geary-service-provider.vala | 17 +++++++++-
.../gmail/imap-engine-gmail-account.vala | 4 +++
.../outlook/imap-engine-outlook-account.vala | 4 +++
.../yahoo/imap-engine-yahoo-account.vala | 4 +++
.../engine/api/geary-account-information-test.vala | 36 ++++++++++++++++++++++
9 files changed, 82 insertions(+), 21 deletions(-)
---
diff --git a/src/client/accounts/accounts-editor-add-pane.vala
b/src/client/accounts/accounts-editor-add-pane.vala
index 75789bd1..6c9a61c3 100644
--- a/src/client/accounts/accounts-editor-add-pane.vala
+++ b/src/client/accounts/accounts-editor-add-pane.vala
@@ -309,8 +309,9 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
}
private Geary.ServiceInformation new_imap_service() {
- Geary.ServiceInformation service =
- new Geary.ServiceInformation(Geary.Protocol.IMAP);
+ Geary.ServiceInformation service = new Geary.ServiceInformation(
+ Geary.Protocol.IMAP, this.provider
+ );
if (this.provider == Geary.ServiceProvider.OTHER) {
service.credentials = new Geary.Credentials(
@@ -331,7 +332,6 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
service.port = service.get_default_port();
}
} else {
- this.provider.setup_service(service);
service.credentials = new Geary.Credentials(
Geary.Credentials.Method.PASSWORD,
this.email.value.get_text().strip(),
@@ -343,8 +343,9 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
}
private Geary.ServiceInformation new_smtp_service() {
- Geary.ServiceInformation service =
- new Geary.ServiceInformation(Geary.Protocol.SMTP);
+ Geary.ServiceInformation service = new Geary.ServiceInformation(
+ Geary.Protocol.SMTP, this.provider
+ );
if (this.provider == Geary.ServiceProvider.OTHER) {
service.credentials_requirement = this.smtp_auth.value.source;
@@ -369,8 +370,6 @@ internal class Accounts.EditorAddPane : Gtk.Grid, EditorPane {
if (service.port == 0) {
service.port = service.get_default_port();
}
- } else {
- this.provider.setup_service(service);
}
return service;
diff --git a/src/client/accounts/accounts-manager.vala b/src/client/accounts/accounts-manager.vala
index 8eb040db..426cb28a 100644
--- a/src/client/accounts/accounts-manager.vala
+++ b/src/client/accounts/accounts-manager.vala
@@ -602,9 +602,6 @@ public class Accounts.Manager : GLib.Object {
} catch (GLib.KeyFileError err) {
throw new ConfigError.SYNTAX(err.message);
}
- account.service_provider.setup_service(account.incoming);
- account.service_provider.setup_service(account.outgoing);
-
} else {
account.service_label = goa_mediator.get_service_label();
try {
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index 35b4a5fd..78b3c065 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -152,16 +152,10 @@ public class Geary.AccountInformation : BaseObject {
public CredentialsMediator mediator { get; private set; }
/* Incoming email service configuration. */
- public ServiceInformation incoming {
- get; set;
- default = new ServiceInformation(Protocol.IMAP);
- }
+ public ServiceInformation incoming { get; set; }
/* Outgoing email service configuration. */
- public ServiceInformation outgoing {
- get; set;
- default = new ServiceInformation(Protocol.SMTP);
- }
+ public ServiceInformation outgoing { get; set; }
/** A lock that can be used to ensure saving is serialised. */
public Nonblocking.Mutex write_lock {
@@ -253,6 +247,11 @@ public class Geary.AccountInformation : BaseObject {
this.id = id;
this.mediator = mediator;
this.service_provider = provider;
+ this.incoming = new ServiceInformation(Protocol.IMAP, provider);
+ this.outgoing = new ServiceInformation(Protocol.SMTP, provider);
+
+ provider.set_account_defaults(this);
+
append_sender(primary_mailbox);
}
diff --git a/src/engine/api/geary-service-information.vala b/src/engine/api/geary-service-information.vala
index e0df4abf..2028e040 100644
--- a/src/engine/api/geary-service-information.vala
+++ b/src/engine/api/geary-service-information.vala
@@ -116,7 +116,7 @@ public class Geary.ServiceInformation : GLib.Object {
/**
* Constructs a new configuration for a specific service.
*/
- public ServiceInformation(Protocol proto) {
+ public ServiceInformation(Protocol proto, ServiceProvider provider) {
this.protocol = proto;
// Prefer TLS by RFC 8314, but use START_TLS for SMTP for the
// moment while its still more widely deployed.
@@ -126,13 +126,16 @@ public class Geary.ServiceInformation : GLib.Object {
this.credentials_requirement = (proto == Protocol.SMTP)
? Credentials.Requirement.USE_INCOMING
: Credentials.Requirement.CUSTOM;
+
+ provider.set_service_defaults(this);
}
/**
* Constructs a copy of the given service configuration.
*/
public ServiceInformation.copy(ServiceInformation other) {
- this(other.protocol);
+ // Use OTHER here to get blank defaults
+ this(other.protocol, ServiceInformation.OTHER);
this.host = other.host;
this.port = other.port;
this.transport_security = other.transport_security;
diff --git a/src/engine/api/geary-service-provider.vala b/src/engine/api/geary-service-provider.vala
index 540526a6..4d6fd943 100644
--- a/src/engine/api/geary-service-provider.vala
+++ b/src/engine/api/geary-service-provider.vala
@@ -29,7 +29,22 @@ public enum Geary.ServiceProvider {
);
}
- public void setup_service(ServiceInformation service) {
+
+ internal void set_account_defaults(AccountInformation service) {
+ switch (this) {
+ case GMAIL:
+ ImapEngine.GmailAccount.setup_account(service);
+ break;
+ case YAHOO:
+ ImapEngine.YahooAccount.setup_account(service);
+ break;
+ case OUTLOOK:
+ ImapEngine.OutlookAccount.setup_account(service);
+ break;
+ }
+ }
+
+ internal void set_service_defaults(ServiceInformation service) {
switch (this) {
case GMAIL:
ImapEngine.GmailAccount.setup_service(service);
diff --git a/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
b/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
index f246e5b6..8e7b3acc 100644
--- a/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
+++ b/src/engine/imap-engine/gmail/imap-engine-gmail-account.vala
@@ -17,6 +17,10 @@ private class Geary.ImapEngine.GmailAccount : Geary.ImapEngine.GenericAccount {
};
+ public static void setup_account(AccountInformation account) {
+ account.save_sent = false;
+ }
+
public static void setup_service(ServiceInformation service) {
switch (service.protocol) {
case Protocol.IMAP:
diff --git a/src/engine/imap-engine/outlook/imap-engine-outlook-account.vala
b/src/engine/imap-engine/outlook/imap-engine-outlook-account.vala
index 8d7e162d..afce5172 100644
--- a/src/engine/imap-engine/outlook/imap-engine-outlook-account.vala
+++ b/src/engine/imap-engine/outlook/imap-engine-outlook-account.vala
@@ -9,6 +9,10 @@
private class Geary.ImapEngine.OutlookAccount : Geary.ImapEngine.GenericAccount {
+ public static void setup_account(AccountInformation account) {
+ // noop
+ }
+
public static void setup_service(ServiceInformation service) {
switch (service.protocol) {
case Protocol.IMAP:
diff --git a/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala
b/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala
index a754bff0..edd24a3d 100644
--- a/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala
+++ b/src/engine/imap-engine/yahoo/imap-engine-yahoo-account.vala
@@ -9,6 +9,10 @@
private class Geary.ImapEngine.YahooAccount : Geary.ImapEngine.GenericAccount {
+ public static void setup_account(AccountInformation account) {
+ // noop
+ }
+
public static void setup_service(ServiceInformation service) {
switch (service.protocol) {
case Protocol.IMAP:
diff --git a/test/engine/api/geary-account-information-test.vala
b/test/engine/api/geary-account-information-test.vala
index 6ec75420..abe5d9da 100644
--- a/test/engine/api/geary-account-information-test.vala
+++ b/test/engine/api/geary-account-information-test.vala
@@ -10,9 +10,45 @@ class Geary.AccountInformationTest : TestCase {
public AccountInformationTest() {
base("Geary.AccountInformationTest");
+ add_test("test_save_sent_defaults", test_save_sent_defaults);
add_test("test_sender_mailboxes", test_sender_mailboxes);
}
+ public void test_save_sent_defaults() throws GLib.Error {
+ assert_true(
+ new AccountInformation(
+ "test",
+ ServiceProvider.OTHER,
+ new MockCredentialsMediator(),
+ new RFC822.MailboxAddress(null, "test1 example com")
+ ).save_sent
+ );
+ assert_false(
+ new AccountInformation(
+ "test",
+ ServiceProvider.GMAIL,
+ new MockCredentialsMediator(),
+ new RFC822.MailboxAddress(null, "test1 example com")
+ ).save_sent
+ );
+ assert_true(
+ new AccountInformation(
+ "test",
+ ServiceProvider.OUTLOOK,
+ new MockCredentialsMediator(),
+ new RFC822.MailboxAddress(null, "test1 example com")
+ ).save_sent
+ );
+ assert_true(
+ new AccountInformation(
+ "test",
+ ServiceProvider.YAHOO,
+ new MockCredentialsMediator(),
+ new RFC822.MailboxAddress(null, "test1 example com")
+ ).save_sent
+ );
+ }
+
public void test_sender_mailboxes() throws GLib.Error {
AccountInformation test = new AccountInformation(
"test",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]