(field_info[i].read_only ? G_PARAM_READABLE : G_PARAM_READWRITE) |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB);
+ else if (field_info[i].t & E_CONTACT_FIELD_TYPE_MULTI)
+ pspec = g_param_spec_boxed (field_info[i].field_name,
+ _(field_info[i].pretty_name),
+ field_info[i].pretty_name,
+ E_TYPE_CONTACT_ATTR_LIST,
+ (field_info[i].read_only ? G_PARAM_READABLE : G_PARAM_READWRITE)
+ | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
else
pspec = g_param_spec_pointer (
field_info[i].field_name,
info = &field_info[prop_id];
if (info->t & E_CONTACT_FIELD_TYPE_MULTI) {
- GList *new_values = g_value_get_pointer (value);
+ GList *new_values = g_value_get_boxed (value);
GList *l;
/* first we remove all attributes of the type we're
info = &field_info[prop_id];
data = e_contact_get (E_CONTACT (object), prop_id);
- if (info->t & E_CONTACT_FIELD_TYPE_BOOLEAN) {
+ if (info->t & E_CONTACT_FIELD_TYPE_MULTI) {
+ g_value_take_boxed (value, data);
+ } else if (info->t & E_CONTACT_FIELD_TYPE_BOOLEAN) {
g_value_set_boolean (value, data != NULL);
} else if (info->t & E_CONTACT_FIELD_TYPE_LIST) {
g_value_set_pointer (value, data);
}
/**
+ * e_contact_field_type:
+ * @field_id: an #EContactField
+ *
+ * Gets the #GType used for this contact field, this indicates
+ * what kind of value can be passed to e_contact_set().
+ *
+ * Returns: The #GType used for @field_id, or %G_TYPE_INVALID if it doesn't exist.
+ *
+ * Since: 3.8
+ **/
+GType
+e_contact_field_type (EContactField field_id)
+{
+ GTypeClass *class;
+ GParamSpec *pspec;
+ const gchar *field_name;
+ GType type = G_TYPE_INVALID;
+
+ g_return_val_if_fail (field_id >= 1 && field_id < E_CONTACT_FIELD_LAST, G_TYPE_INVALID);
+
+ field_name = e_contact_field_name (field_id);
+ class = g_type_class_ref (E_TYPE_CONTACT);
+ pspec = g_object_class_find_property (G_OBJECT_CLASS (class), field_name);
+
+ if (pspec)
+ type = G_PARAM_SPEC_VALUE_TYPE (pspec);
+
+ g_type_class_unref (class);
+
+ return type;
+}
+
+/**
* e_contact_field_name:
* @field_id: an #EContactField
*
}
E_CONTACT_DEFINE_BOXED_TYPE (e_contact_cert, "EContactCert")
+
+
+/**
+ * e_contact_attr_list_copy:
+ * @list: A #GList of strings
+ *
+ * Copies a list of allocated strings, specifically
+ * for the #EContactAttrList boxed type used for multi valued
+ * contact fields.
+ *
+ * Returns: (transfer full): A copy of @list
+ *
+ * Since: 3.8
+ */
+GList *
+e_contact_attr_list_copy (GList *list)
+{
+ GList *dup_list = NULL, *l;
+
+ for (l = list; l; l = l->next) {
+ gchar *str = g_strdup ((gchar *)l->data);
+
+ dup_list = g_list_prepend (dup_list, str);
+ }
+
+ return g_list_reverse (dup_list);
+}
+
+/**
+ * e_contact_attr_list_free:
+ * @list: A #GList of strings
+ *
+ * Frees a list of allocated strings, specifically
+ * for the #EContactAttrList boxed type used for multi valued
+ * contact fields.
+ *
+ * Since: 3.8
+ */
+void
+e_contact_attr_list_free (GList *list)
+{
+ g_list_foreach (list, (GFunc)g_free, NULL);
+ g_list_free (list);
+}
+
+typedef GList EContactAttrList;
+G_DEFINE_BOXED_TYPE (EContactAttrList, e_contact_attr_list, e_contact_attr_list_copy, e_contact_attr_list_free);
#define E_TYPE_CONTACT_PHOTO (e_contact_photo_get_type ())
#define E_TYPE_CONTACT_CERT (e_contact_cert_get_type ())
#define E_TYPE_CONTACT_ADDRESS (e_contact_address_get_type ())
+#define E_TYPE_CONTACT_ATTR_LIST (e_contact_attr_list_get_type ())
typedef struct _EContact EContact;
typedef struct _EContactClass EContactClass;
GType e_contact_address_get_type (void);
void e_contact_address_free (EContactAddress *address);
+GList *e_contact_attr_list_copy (GList *list);
+void e_contact_attr_list_free (GList *list);
+GType e_contact_attr_list_get_type (void);
+
+GType e_contact_field_type (EContactField field_id);
const gchar * e_contact_field_name (EContactField field_id);
const gchar * e_contact_pretty_name (EContactField field_id);
const gchar * e_contact_vcard_attribute (EContactField field_id);