[geary/wip/714104-refine-account-dialog: 35/69] Make Geary.Protocol consistent with new-style enum methods.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/714104-refine-account-dialog: 35/69] Make Geary.Protocol consistent with new-style enum methods.
- Date: Fri, 30 Nov 2018 12:51:16 +0000 (UTC)
commit 174da182649cfac14cc5c0b4f2460dd3331151a6
Author: Michael James Gratton <mike vee net>
Date: Mon Jul 23 16:42:21 2018 +1000
Make Geary.Protocol consistent with new-style enum methods.
src/client/application/secret-mediator.vala | 4 +-
src/client/dialogs/certificate-warning-dialog.vala | 2 +-
src/engine/api/geary-account-information.vala | 2 +-
src/engine/api/geary-service-information.vala | 51 ++++++++--------------
4 files changed, 21 insertions(+), 38 deletions(-)
---
diff --git a/src/client/application/secret-mediator.vala b/src/client/application/secret-mediator.vala
index 37171fa1..aad73993 100644
--- a/src/client/application/secret-mediator.vala
+++ b/src/client/application/secret-mediator.vala
@@ -199,7 +199,7 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
SecretMediator.schema,
new_attrs(service),
Secret.COLLECTION_DEFAULT,
- "Geary %s password".printf(service.protocol.name()),
+ "Geary %s password".printf(service.protocol.to_value()),
password,
cancellable
);
@@ -209,7 +209,7 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
HashTable<string,string> table = new HashTable<string,string>(
str_hash, str_equal
);
- table.insert(ATTR_PROTO, service.protocol.name());
+ table.insert(ATTR_PROTO, service.protocol.to_value());
table.insert(ATTR_HOST, service.host);
table.insert(ATTR_LOGIN, service.credentials.user);
return table;
diff --git a/src/client/dialogs/certificate-warning-dialog.vala
b/src/client/dialogs/certificate-warning-dialog.vala
index d9fdc756..bcdc4bb9 100644
--- a/src/client/dialogs/certificate-warning-dialog.vala
+++ b/src/client/dialogs/certificate-warning-dialog.vala
@@ -36,7 +36,7 @@ public class CertificateWarningDialog {
Geary.Endpoint endpoint = service.endpoint;
top_label.label = _("The identity of the %s mail server at %s:%u could not be verified.").printf(
- service.protocol.user_label(), endpoint.remote_address.hostname, endpoint.remote_address.port);
+ service.protocol.to_value(), endpoint.remote_address.hostname, endpoint.remote_address.port);
warnings_label.label = generate_warning_list(
service.endpoint.tls_validation_warnings
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index 3994b80f..9285441a 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -35,7 +35,7 @@ public class Geary.AccountInformation : BaseObject {
private static Geary.Endpoint get_shared_endpoint(ServiceInformation service,
Endpoint endpoint) {
string key = "%s/%s:%u".printf(
- service.protocol.user_label(),
+ service.protocol.to_value(),
endpoint.remote_address.hostname,
endpoint.remote_address.port
);
diff --git a/src/engine/api/geary-service-information.vala b/src/engine/api/geary-service-information.vala
index 83ae5353..0e98d431 100644
--- a/src/engine/api/geary-service-information.vala
+++ b/src/engine/api/geary-service-information.vala
@@ -1,53 +1,36 @@
-/* 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.
- */
-
-/* Copyright 2016 Software Freedom Conservancy Inc.
+/*
+ * 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.
*/
/**
- * The email wire protocols supported by the engine.
+ * The network protocols supported by the engine for email services.
*/
public enum Geary.Protocol {
IMAP,
SMTP;
- /**
- * Returns a user-visible label for the protocol.
- */
- public string user_label() {
- switch (this) {
- case IMAP:
- return _("IMAP");
-
- case SMTP:
- return _("SMTP");
- default:
- assert_not_reached();
+ public static Protocol for_value(string value)
+ throws EngineError {
+ switch (value.ascii_up()) {
+ case "IMAP":
+ return IMAP;
+ case "SMTP":
+ return SMTP;
}
+ throw new EngineError.BAD_PARAMETERS(
+ "Unknown Protocol value: %s", value
+ );
}
- /**
- * Returns a short version of the enum key.
- */
- public string name() {
- switch (this) {
- case IMAP:
- return "IMAP";
-
- case SMTP:
- return "SMTP";
-
- default:
- assert_not_reached();
- }
+ public string to_value() {
+ string value = to_string();
+ return value.substring(value.last_index_of("_") + 1);
}
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]