aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2011-09-08 17:48:03 +0800
committerWill Thompson <will.thompson@collabora.co.uk>2011-10-15 01:22:03 +0800
commit4e884826ed36617d3579045faae789e6a8744b80 (patch)
treeeccd980929b3170602d45de3daefff58295d0789
parent6a56f4c19ff31722619e5494639884a6a2646967 (diff)
downloadgsoc2013-empathy-4e884826ed36617d3579045faae789e6a8744b80.tar
gsoc2013-empathy-4e884826ed36617d3579045faae789e6a8744b80.tar.gz
gsoc2013-empathy-4e884826ed36617d3579045faae789e6a8744b80.tar.bz2
gsoc2013-empathy-4e884826ed36617d3579045faae789e6a8744b80.tar.lz
gsoc2013-empathy-4e884826ed36617d3579045faae789e6a8744b80.tar.xz
gsoc2013-empathy-4e884826ed36617d3579045faae789e6a8744b80.tar.zst
gsoc2013-empathy-4e884826ed36617d3579045faae789e6a8744b80.zip
TpChat: track subject and title explicitly.
This will allow us to also use the new API (and, ultimately, delete the Telepathy.Properties code cleanly).
-rw-r--r--libempathy/empathy-tp-chat.c87
1 files changed, 37 insertions, 50 deletions
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index 952d9a8ee..15b9503b6 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -55,6 +55,16 @@ struct _EmpathyTpChatPrivate {
GQueue *pending_messages_queue;
gboolean had_properties_list;
GPtrArray *properties;
+
+ /* Subject */
+ gboolean supports_subject;
+ gboolean can_set_subject;
+ gchar *subject;
+
+ /* Room config (for now, we only track the title and don't support
+ * setting it) */
+ gchar *title;
+
gboolean can_upgrade_to_muc;
GHashTable *messages_being_sent;
@@ -620,6 +630,10 @@ tp_chat_property_flags_changed_cb (TpProxy *proxy,
property->flags = flags;
DEBUG ("property %s flags changed: %d",
property->name, property->flags);
+
+ if (!tp_strdiff (property->name, "subject")) {
+ self->priv->can_set_subject = !!(property->flags & TP_PROPERTY_FLAG_WRITE);
+ }
break;
}
}
@@ -633,6 +647,7 @@ tp_chat_properties_changed_cb (TpProxy *proxy,
GObject *chat)
{
EmpathyTpChat *self = (EmpathyTpChat *) chat;
+ EmpathyTpChatPrivate *priv = self->priv;
guint i, j;
if (!self->priv->had_properties_list || !properties) {
@@ -660,9 +675,17 @@ tp_chat_properties_changed_cb (TpProxy *proxy,
DEBUG ("property %s changed", property->name);
- if (!tp_strdiff (property->name, "name")) {
+ if (!tp_strdiff (property->name, "name") &&
+ G_VALUE_HOLDS_STRING (property->value)) {
+ g_free (priv->title);
+ priv->title = g_value_dup_string (property->value);
g_object_notify (chat, "title");
- } else if (!tp_strdiff (property->name, "subject")) {
+ } else if (!tp_strdiff (property->name, "subject") &&
+ G_VALUE_HOLDS_STRING (property->value)) {
+ priv->supports_subject = TRUE;
+ priv->can_set_subject = !!(property->flags & TP_PROPERTY_FLAG_WRITE);
+ g_free (priv->subject);
+ priv->subject = g_value_dup_string (property->value);
g_object_notify (chat, "subject");
}
@@ -798,75 +821,36 @@ empathy_tp_chat_set_subject (EmpathyTpChat *self,
g_value_unset (&value);
}
-static EmpathyTpChatProperty *
-empathy_tp_chat_get_property (EmpathyTpChat *self,
- const gchar *name)
-{
- EmpathyTpChatProperty *property;
- guint i;
-
- if (!self->priv->had_properties_list) {
- return NULL;
- }
-
- for (i = 0; i < self->priv->properties->len; i++) {
- property = g_ptr_array_index (self->priv->properties, i);
- if (!tp_strdiff (property->name, name)) {
- return property;
- }
- }
-
- return NULL;
-}
-
const gchar *
empathy_tp_chat_get_title (EmpathyTpChat *self)
{
- EmpathyTpChatProperty *property;
+ EmpathyTpChatPrivate *priv = self->priv;
- property = empathy_tp_chat_get_property (self, "title");
-
- if (property == NULL || !G_VALUE_HOLDS_STRING (property->value)) {
- return NULL;
- } else {
- return g_value_get_string (property->value);
- }
+ return priv->title;
}
gboolean
empathy_tp_chat_supports_subject (EmpathyTpChat *self)
{
- return (empathy_tp_chat_get_property (self, "subject") != NULL);
+ EmpathyTpChatPrivate *priv = self->priv;
+
+ return priv->supports_subject;
}
gboolean
empathy_tp_chat_can_set_subject (EmpathyTpChat *self)
{
- EmpathyTpChatProperty *property;
-
- property = empathy_tp_chat_get_property (self, "subject");
+ EmpathyTpChatPrivate *priv = self->priv;
- if (property == NULL) {
- return FALSE;
- } else if (property->flags & TP_PROPERTY_FLAG_WRITE) {
- return TRUE;
- } else {
- return FALSE;
- }
+ return priv->can_set_subject;
}
const gchar *
empathy_tp_chat_get_subject (EmpathyTpChat *self)
{
- EmpathyTpChatProperty *property;
+ EmpathyTpChatPrivate *priv = self->priv;
- property = empathy_tp_chat_get_property (self, "subject");
-
- if (property == NULL || !G_VALUE_HOLDS_STRING (property->value)) {
- return NULL;
- } else {
- return g_value_get_string (property->value);
- }
+ return priv->subject;
}
static void
@@ -917,6 +901,9 @@ tp_chat_finalize (GObject *object)
g_queue_free (self->priv->pending_messages_queue);
g_hash_table_destroy (self->priv->messages_being_sent);
+ g_free (self->priv->title);
+ g_free (self->priv->subject);
+
G_OBJECT_CLASS (empathy_tp_chat_parent_class)->finalize (object);
}