[geary/wip/composer-folks: 2/22] Clean up ContactFlag API
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/composer-folks: 2/22] Clean up ContactFlag API
- Date: Sat, 15 Jun 2019 14:31:04 +0000 (UTC)
commit 2ff2d2421f9fdb86e815549d051462078d0cad30
Author: Michael Gratton <mike vee net>
Date: Sat Jun 8 08:21:37 2019 +1000
Clean up ContactFlag API
Move ContactFlag class into Contact class, rename Contact.flags property
to avoid redundancy and make it non-nullable to be able to simplify its
use.
po/POTFILES.in | 1 -
src/client/application/application-contact.vala | 13 +++---
src/engine/api/geary-contact-flags.vala | 50 --------------------
src/engine/api/geary-contact.vala | 58 ++++++++++++++++++++----
src/engine/common/common-contact-store-impl.vala | 35 ++++++--------
src/engine/meson.build | 1 -
6 files changed, 72 insertions(+), 86 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index fd5d51c3..1e1ec5cd 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -111,7 +111,6 @@ src/engine/api/geary-attachment.vala
src/engine/api/geary-base-object.vala
src/engine/api/geary-client-service.vala
src/engine/api/geary-composed-email.vala
-src/engine/api/geary-contact-flags.vala
src/engine/api/geary-contact-importance.vala
src/engine/api/geary-contact-store.vala
src/engine/api/geary-contact.vala
diff --git a/src/client/application/application-contact.vala b/src/client/application/application-contact.vala
index bda158aa..ef597209 100644
--- a/src/client/application/application-contact.vala
+++ b/src/client/application/application-contact.vala
@@ -49,7 +49,7 @@ public class Application.Contact : Geary.BaseObject {
return (
this.individual != null ||
(this.contact != null &&
- this.contact.always_load_remote_images())
+ this.contact.flags.always_load_remote_images())
);
}
}
@@ -182,13 +182,14 @@ public class Application.Contact : Geary.BaseObject {
throws GLib.Error {
ContactStore? store = this.store;
if (store != null && this.contact != null) {
- Geary.ContactFlags flags = (
- this.contact.contact_flags ?? new Geary.ContactFlags()
- );
if (enabled) {
- flags.add(Geary.ContactFlags.ALWAYS_LOAD_REMOTE_IMAGES);
+ this.contact.flags.add(
+ Geary.Contact.Flags.ALWAYS_LOAD_REMOTE_IMAGES
+ );
} else {
- flags.remove(Geary.ContactFlags.ALWAYS_LOAD_REMOTE_IMAGES);
+ this.contact.flags.remove(
+ Geary.Contact.Flags.ALWAYS_LOAD_REMOTE_IMAGES
+ );
}
yield store.account.contact_store.update_contacts(
diff --git a/src/engine/api/geary-contact.vala b/src/engine/api/geary-contact.vala
index 34c6ae3a..a8c031e4 100644
--- a/src/engine/api/geary-contact.vala
+++ b/src/engine/api/geary-contact.vala
@@ -5,22 +5,67 @@
*/
public class Geary.Contact : BaseObject {
+
+
+ /**
+ * Named flags for contact objects.
+ */
+ public class Flags : Geary.NamedFlags {
+
+ public static NamedFlag ALWAYS_LOAD_REMOTE_IMAGES {
+ get {
+ if (_always_load_remote_images == null) {
+ _always_load_remote_images = new NamedFlag("ALWAYSLOADREMOTEIMAGES");
+ }
+
+ return _always_load_remote_images;
+ }
+ }
+ private static NamedFlag? _always_load_remote_images = null;
+
+
+ public bool always_load_remote_images() {
+ return contains(ALWAYS_LOAD_REMOTE_IMAGES);
+ }
+
+ public string serialize() {
+ string ret = "";
+ foreach (NamedFlag flag in list) {
+ ret += flag.serialize() + " ";
+ }
+
+ return ret.strip();
+ }
+
+ public void deserialize(string? flags) {
+ if (!String.is_empty(flags)) {
+ foreach (string flag in flags.split(" ")) {
+ add(new NamedFlag(flag));
+ }
+ }
+ }
+
+ }
+
+
public string normalized_email { get; private set; }
public string email { get; private set; }
public string? real_name { get; private set; }
public int highest_importance { get; set; }
- public ContactFlags? contact_flags { get; set; default = null; }
+ public Flags flags { get; set; default = new Flags(); }
- public Contact(string email, string? real_name, int highest_importance,
- string? normalized_email = null, ContactFlags? contact_flags = null) {
+ public Contact(string email,
+ string? real_name,
+ int highest_importance,
+ string? normalized_email = null) {
this.normalized_email = normalized_email ?? email.normalize().casefold();
this.email = email;
this.real_name = real_name;
this.highest_importance = highest_importance;
- this.contact_flags = contact_flags;
}
- public Contact.from_rfc822_address(RFC822.MailboxAddress address, int highest_importance) {
+ public Contact.from_rfc822_address(RFC822.MailboxAddress address,
+ int highest_importance) {
this(address.address, address.name, highest_importance);
}
@@ -28,7 +73,4 @@ public class Geary.Contact : BaseObject {
return new RFC822.MailboxAddress(real_name, email);
}
- public inline bool always_load_remote_images() {
- return contact_flags != null && contact_flags.always_load_remote_images();
- }
}
diff --git a/src/engine/common/common-contact-store-impl.vala
b/src/engine/common/common-contact-store-impl.vala
index e060bbc0..0ddde6d0 100644
--- a/src/engine/common/common-contact-store-impl.vala
+++ b/src/engine/common/common-contact-store-impl.vala
@@ -34,7 +34,7 @@ internal class Geary.ContactStoreImpl : BaseObject, Geary.ContactStore {
stmt.bind_string(0, contact.normalized_email);
stmt.bind_string(1, contact.email);
stmt.bind_string(2, contact.real_name);
- stmt.bind_string(3, (contact.contact_flags != null) ? contact.contact_flags.serialize() : null);
+ stmt.bind_string(3, contact.flags.serialize());
stmt.bind_int(4, contact.highest_importance);
stmt.exec(cancellable);
@@ -42,14 +42,7 @@ internal class Geary.ContactStoreImpl : BaseObject, Geary.ContactStore {
// Update existing contact
// Merge two flags sets together
- ContactFlags? merged_flags = contact.contact_flags;
- if (existing.contact_flags != null) {
- if (merged_flags != null) {
- merged_flags.add_all(existing.contact_flags);
- } else {
- merged_flags = existing.contact_flags;
- }
- }
+ contact.flags.add_all(existing.flags);
// update remaining fields, careful not to overwrite
// non-null real_name with null (but using latest
@@ -63,7 +56,7 @@ internal class Geary.ContactStoreImpl : BaseObject, Geary.ContactStore {
0, !String.is_empty(contact.real_name) ? contact.real_name : existing.real_name
);
stmt.bind_string(
- 1, (merged_flags != null) ? merged_flags.serialize() : null
+ 1, contact.flags.serialize()
);
stmt.bind_int(
2, int.max(contact.highest_importance, existing.highest_importance)
@@ -88,16 +81,18 @@ internal class Geary.ContactStoreImpl : BaseObject, Geary.ContactStore {
stmt.bind_string(0, email);
Db.Result result = stmt.exec(cancellable);
- if (result.finished)
- return null;
-
- return new Contact(
- email,
- result.string_at(0),
- result.int_at(1),
- result.string_at(2),
- ContactFlags.deserialize(result.string_at(3))
- );
+
+ Contact? contact = null;
+ if (!result.finished) {
+ contact = new Contact(
+ email,
+ result.string_at(0),
+ result.int_at(1),
+ result.string_at(2)
+ );
+ contact.flags.deserialize(result.string_at(3));
+ }
+ return contact;
}
diff --git a/src/engine/meson.build b/src/engine/meson.build
index d85f0c63..5a593fa6 100644
--- a/src/engine/meson.build
+++ b/src/engine/meson.build
@@ -10,7 +10,6 @@ geary_engine_vala_sources = files(
'api/geary-client-service.vala',
'api/geary-composed-email.vala',
'api/geary-contact.vala',
- 'api/geary-contact-flags.vala',
'api/geary-contact-importance.vala',
'api/geary-contact-store.vala',
'api/geary-credentials.vala',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]