[folks/wip/arbitrary-field-interface] Add ExtendedInfo interface and implementation in EDS backend



commit 4f47ff8e4cb721f4f2efbdb32bfc568d3ebd3ab6
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Wed Jul 3 12:57:25 2013 +0200

    Add ExtendedInfo interface and implementation in EDS backend

 backends/eds/lib/edsf-persona-store.vala |   34 +++++++++
 backends/eds/lib/edsf-persona.vala       |   22 ++++++
 folks/Makefile.am                        |    1 +
 folks/extended-info.vala                 |  114 ++++++++++++++++++++++++++++++
 4 files changed, 171 insertions(+), 0 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 46bb9f6..38a1b21 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -1687,6 +1687,40 @@ public class Edsf.PersonaStore : Folks.PersonaStore
       yield this._commit_modified_property (persona, "email-addresses");
     }
 
+  internal ExtendedFieldDetails _get_extended_field (Edsf.Persona persona, string name)
+    {
+      unowned VCardAttribute? attr = persona.contact.get_attribute (name);
+      if (attr != null)
+        {
+          ExtendedFieldDetails details = new ExtendedFieldDetails (attr.get_value (), null);
+
+          foreach (unowned E.VCardAttributeParam param in attr.get_params ())
+            {
+              details.add_parameter (param.get_name (), param.get_values ());
+            }
+
+           return details;
+        }
+
+      return null;
+    }
+
+  internal async void _change_extended_field (Edsf.Persona persona,
+      string name, ExtendedFieldDetails details) throws PropertyError
+    {
+      var vcard = (E.VCard) persona.contact;
+      unowned E.VCardAttribute? prev_attr = vcard.get_attribute (name);
+
+      if (prev_attr != null)
+        persona.contact.remove_attribute (prev_attr);
+
+      E.VCardAttribute new_attr = new E.VCardAttribute ("", name);
+      new_attr.add_value (details.value);
+
+      persona.contact.add_attribute (new_attr);
+      yield this._commit_modified_property (persona, "extended-info");
+    }
+
   internal async void _set_phones (Edsf.Persona persona,
       Set<PhoneFieldDetails> phones) throws PropertyError
     {
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 5f3ff0a..c849a8d 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -40,6 +40,7 @@ public class Edsf.Persona : Folks.Persona,
     AvatarDetails,
     BirthdayDetails,
     EmailDetails,
+    ExtendedInfo,
     FavouriteDetails,
     GenderDetails,
     GroupDetails,
@@ -346,6 +347,27 @@ public class Edsf.Persona : Folks.Persona,
           email_addresses);
     }
 
+  /**
+   * { inheritDoc}
+   *
+   * @since 0.9.4
+   */
+  public ExtendedFieldDetails get_extended_field (string name)
+    {
+      return ((Edsf.PersonaStore) this.store)._get_extended_field (this, name);
+    }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since 0.9.4
+   */
+  public async void change_extended_field (
+      string name, ExtendedFieldDetails value) throws PropertyError
+    {
+      yield ((Edsf.PersonaStore) this.store)._change_extended_field.begin (this, name, value);
+    }
+
   private SmallSet<NoteFieldDetails>? _notes = null;
   private Set<NoteFieldDetails>? _notes_ro = null;
 
diff --git a/folks/Makefile.am b/folks/Makefile.am
index ae6d456..6e2e1a1 100644
--- a/folks/Makefile.am
+++ b/folks/Makefile.am
@@ -71,6 +71,7 @@ libfolks_la_SOURCES = \
        backend-store.vala \
        birthday-details.vala \
        email-details.vala \
+       extended-info.vala \
        favourite-details.vala \
        folks-namespace.vala \
        gender-details.vala \
diff --git a/folks/extended-info.vala b/folks/extended-info.vala
new file mode 100644
index 0000000..af04ef5
--- /dev/null
+++ b/folks/extended-info.vala
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2013 Collabora Ltd.
+ *
+ * This library 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 library 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 library.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *       Rodrigo Moya <rodrigo gnome org>
+ */
+
+using GLib;
+using Gee;
+
+/**
+ * Object representing an arbitrary field that can have some parameters
+ * associated with it.
+ *
+ * See { link Folks.AbstractFieldDetails} for details on common parameter names
+ * and values.
+ *
+ * @since 0.9.4
+ */
+public class Folks.ExtendedFieldDetails : AbstractFieldDetails<string>
+{
+  /**
+   * Create a new ExtendedFieldDetails.
+   *
+   * @param value the value of the field
+   * @param parameters initial parameters. See
+   * { link AbstractFieldDetails.parameters}. A ``null`` value is equivalent to
+   * an empty map of parameters.
+   *
+   * @return a new ExtendedFieldDetails
+   *
+   * @since 0.9.4
+   */
+  public ExtendedFieldDetails (string value,
+                                                          MultiMap<string, string>? parameters = null)
+    {
+      if (value == "")
+        {
+          warning ("Empty value passed to ExtendedFieldDetails.");
+        }
+
+      this.value = value;
+      if (parameters != null)
+        this.parameters = (!) parameters;
+       }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since 0.6.0
+   */
+  public override bool equal (AbstractFieldDetails<string> that)
+    {
+      return base.equal (that);
+    }
+
+  /**
+   * { inheritDoc}
+   *
+   * @since 0.6.0
+   */
+  public override uint hash ()
+    {
+      return base.hash ();
+    }
+}
+
+/**
+ * Arbitrary field interface.
+ *
+ * This interface allows clients to store arbitrary fields for contacts in backends
+ * that support it.
+ *
+ * @since 0.9.4
+ */
+public interface Folks.ExtendedInfo : Object
+{
+  /**
+   * Retrieve the value for an arbitrary field.
+   *
+   * @since 0.9.4
+   */
+  public abstract ExtendedFieldDetails get_extended_field (string name);
+
+  /**
+   * Change the value of an arbitrary field.
+   *
+   * @param name name of the arbitrary field to change value
+   * @param value new value for the arbitrary field
+   * @throws PropertyError if setting the value failed
+   *
+   * @since 0.9.4
+   */
+  public virtual async void change_extended_field (
+      string name, ExtendedFieldDetails value) throws PropertyError
+    {
+      /* Default implementation */
+      throw new PropertyError.NOT_WRITEABLE (
+          _("Extended fields are not writeable on this contact."));
+       }
+}
\ No newline at end of file


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]