summaryrefslogtreecommitdiff
path: root/telepathy-glib
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-10-28 14:54:53 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-11-11 16:49:21 +0000
commitc73bd6a29e23bdc7afa8a26be0fd6ade0065c03a (patch)
treef8d2ac9acfda4cd46ec5f42232922f74a42f5b60 /telepathy-glib
parent712b3b082f740d1be16b7c74ad7a457aa91947c6 (diff)
downloadtelepathy-glib-c73bd6a29e23bdc7afa8a26be0fd6ade0065c03a.tar.gz
TpPresenceStatusSpec: be a boxed type
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=71048 Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Diffstat (limited to 'telepathy-glib')
-rw-r--r--telepathy-glib/presence-mixin.c100
-rw-r--r--telepathy-glib/presence-mixin.h19
2 files changed, 118 insertions, 1 deletions
diff --git a/telepathy-glib/presence-mixin.c b/telepathy-glib/presence-mixin.c
index f8d44b816..50a70b59e 100644
--- a/telepathy-glib/presence-mixin.c
+++ b/telepathy-glib/presence-mixin.c
@@ -1581,6 +1581,13 @@ tp_presence_mixin_simple_presence_register_with_contacts_mixin (GObject *obj)
tp_presence_mixin_simple_presence_fill_contact_attributes);
}
+/* For now, self->priv is just self if heap-allocated, NULL if not. */
+static gboolean
+_tp_presence_status_spec_is_heap_allocated (const TpPresenceStatusSpec *self)
+{
+ return (self->priv == (TpPresenceStatusSpecPrivate *) self);
+}
+
/**
* tp_presence_status_spec_get_presence_type:
* @self: a presence status specification
@@ -1666,3 +1673,96 @@ tp_presence_status_spec_has_message (const TpPresenceStatusSpec *self)
return FALSE;
}
+
+/**
+ * tp_presence_status_spec_new:
+ * @name: the name of the new presence status
+ * @type: the category into which this presence status falls
+ * @can_set_on_self: %TRUE if the user can set this presence status
+ * on themselves
+ * @has_message: %TRUE if this presence status is accompanied by an
+ * optional human-readable message
+ *
+ * <!-- -->
+ *
+ * Returns: (transfer full): a new #TpPresenceStatusSpec
+ * Since: 0.UNRELEASED
+ */
+TpPresenceStatusSpec *
+tp_presence_status_spec_new (const gchar *name,
+ TpConnectionPresenceType type,
+ gboolean can_set_on_self,
+ gboolean has_message)
+{
+ TpPresenceStatusSpec *ret;
+ static const TpPresenceStatusOptionalArgumentSpec yes_it_has_a_message[] = {
+ { "message", "s" },
+ { NULL }
+ };
+
+ g_return_val_if_fail (!tp_str_empty (name), NULL);
+ g_return_val_if_fail (type >= 0 && type < TP_NUM_CONNECTION_PRESENCE_TYPES,
+ NULL);
+
+ ret = g_slice_new0 (TpPresenceStatusSpec);
+
+ ret->name = g_strdup (name);
+ ret->presence_type = type;
+ ret->self = can_set_on_self;
+
+ if (has_message)
+ ret->optional_arguments = yes_it_has_a_message;
+ else
+ ret->optional_arguments = NULL;
+
+ /* dummy marker for "this is on the heap" rather than a real struct */
+ ret->priv = (TpPresenceStatusSpecPrivate *) ret;
+
+ return ret;
+}
+
+/**
+ * tp_presence_status_spec_copy:
+ * @self: a presence status specification
+ *
+ * Copy a presence status specification.
+ *
+ * If @self has optional arguments other than a string named "message",
+ * they are not copied. Optional arguments with other names or types
+ * are deprecated.
+ *
+ * Returns: (transfer full): a new #TpPresenceStatusSpec resembling @self
+ * Since: 0.UNRELEASED
+ */
+TpPresenceStatusSpec *
+tp_presence_status_spec_copy (const TpPresenceStatusSpec *self)
+{
+ g_return_val_if_fail (self != NULL, NULL);
+
+ return tp_presence_status_spec_new (self->name, self->presence_type,
+ self->self, tp_presence_status_spec_has_message (self));
+}
+
+/**
+ * tp_presence_status_spec_free:
+ * @self: (transfer full): a presence status specification
+ *
+ * Free a presence status specification produced by
+ * tp_presence_status_spec_new() or tp_presence_status_spec_copy().
+ *
+ * Since: 0.UNRELEASED
+ */
+void
+tp_presence_status_spec_free (TpPresenceStatusSpec *self)
+{
+ g_return_if_fail (_tp_presence_status_spec_is_heap_allocated (self));
+
+ /* This struct was designed to always be on the stack, so freeing this
+ * needs a non-const-correct cast */
+ g_free ((gchar *) self->name);
+
+ g_slice_free (TpPresenceStatusSpec, self);
+}
+
+G_DEFINE_BOXED_TYPE (TpPresenceStatusSpec, tp_presence_status_spec,
+ tp_presence_status_spec_copy, tp_presence_status_spec_free)
diff --git a/telepathy-glib/presence-mixin.h b/telepathy-glib/presence-mixin.h
index 6654c5b8c..d10d6b031 100644
--- a/telepathy-glib/presence-mixin.h
+++ b/telepathy-glib/presence-mixin.h
@@ -35,6 +35,7 @@ G_BEGIN_DECLS
typedef struct _TpPresenceStatusOptionalArgumentSpec
TpPresenceStatusOptionalArgumentSpec;
typedef struct _TpPresenceStatusSpec TpPresenceStatusSpec;
+typedef struct _TpPresenceStatusSpecPrivate TpPresenceStatusSpecPrivate;
struct _TpPresenceStatusOptionalArgumentSpec {
const gchar *name;
@@ -53,7 +54,7 @@ struct _TpPresenceStatusSpec {
/*<private>*/
gpointer _future1;
- gpointer _future2;
+ TpPresenceStatusSpecPrivate *priv;
};
_TP_AVAILABLE_IN_UNRELEASED
@@ -72,6 +73,22 @@ _TP_AVAILABLE_IN_UNRELEASED
gboolean tp_presence_status_spec_has_message (
const TpPresenceStatusSpec *self);
+_TP_AVAILABLE_IN_UNRELEASED
+GType tp_presence_status_spec_get_type (void);
+
+_TP_AVAILABLE_IN_UNRELEASED
+TpPresenceStatusSpec *tp_presence_status_spec_new (const gchar *name,
+ TpConnectionPresenceType type,
+ gboolean can_set_on_self,
+ gboolean has_message);
+
+_TP_AVAILABLE_IN_UNRELEASED
+TpPresenceStatusSpec *tp_presence_status_spec_copy (
+ const TpPresenceStatusSpec *self);
+
+_TP_AVAILABLE_IN_UNRELEASED
+void tp_presence_status_spec_free (TpPresenceStatusSpec *self);
+
typedef struct _TpPresenceStatus TpPresenceStatus;
struct _TpPresenceStatus {