aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2011-09-08 15:07:08 +0800
committerWill Thompson <will.thompson@collabora.co.uk>2011-10-15 01:22:01 +0800
commit6a56f4c19ff31722619e5494639884a6a2646967 (patch)
tree0f42990ebc09c02ce78eace330d7ab01c28579dc
parent8bd6c6b3fa285cdf99f5a9b09c5c03ccf19ace5d (diff)
downloadgsoc2013-empathy-6a56f4c19ff31722619e5494639884a6a2646967.tar
gsoc2013-empathy-6a56f4c19ff31722619e5494639884a6a2646967.tar.gz
gsoc2013-empathy-6a56f4c19ff31722619e5494639884a6a2646967.tar.bz2
gsoc2013-empathy-6a56f4c19ff31722619e5494639884a6a2646967.tar.lz
gsoc2013-empathy-6a56f4c19ff31722619e5494639884a6a2646967.tar.xz
gsoc2013-empathy-6a56f4c19ff31722619e5494639884a6a2646967.tar.zst
gsoc2013-empathy-6a56f4c19ff31722619e5494639884a6a2646967.zip
TpChat: hide guts of Telepathy properties.
This will make it easier to replace these with new stuff. The funky indentation in the callbacks for the subject and title changing is to make it clear that I didn't change that code; I'll reindent it in another patch.
-rw-r--r--libempathy-gtk/empathy-chat.c68
-rw-r--r--libempathy/empathy-tp-chat.c121
-rw-r--r--libempathy/empathy-tp-chat.h22
3 files changed, 136 insertions, 75 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index b1d469f3f..09146d896 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -758,26 +758,20 @@ chat_command_topic (EmpathyChat *chat,
GStrv strv)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- EmpathyTpChatProperty *property;
- GValue value = {0, };
- property = empathy_tp_chat_get_property (priv->tp_chat, "subject");
- if (property == NULL) {
+ if (!empathy_tp_chat_supports_subject (priv->tp_chat)) {
empathy_chat_view_append_event (chat->view,
_("Topic not supported on this conversation"));
return;
}
- if (!(property->flags & TP_PROPERTY_FLAG_WRITE)) {
+ if (!empathy_tp_chat_can_set_subject (priv->tp_chat)) {
empathy_chat_view_append_event (chat->view,
_("You are not allowed to change the topic"));
return;
}
- g_value_init (&value, G_TYPE_STRING);
- g_value_set_string (&value, strv[1]);
- empathy_tp_chat_set_property (priv->tp_chat, "subject", &value);
- g_value_unset (&value);
+ empathy_tp_chat_set_subject (priv->tp_chat, strv[1]);
}
void
@@ -1586,16 +1580,12 @@ chat_topic_expander_activate_cb (GtkExpander *expander,
}
static void
-chat_property_changed_cb (EmpathyTpChat *tp_chat,
- const gchar *name,
- GValue *value,
- EmpathyChat *chat)
+chat_subject_changed_cb (EmpathyChat *chat)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- if (!tp_strdiff (name, "subject")) {
g_free (priv->subject);
- priv->subject = g_value_dup_string (value);
+ priv->subject = g_strdup (empathy_tp_chat_get_subject (priv->tp_chat));
g_object_notify (G_OBJECT (chat), "subject");
if (EMP_STR_EMPTY (priv->subject)) {
@@ -1625,12 +1615,16 @@ chat_property_changed_cb (EmpathyTpChat *tp_chat,
empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
g_free (str);
}
- }
- else if (!tp_strdiff (name, "name")) {
+}
+
+static void
+chat_title_changed_cb (EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
g_free (priv->name);
- priv->name = g_value_dup_string (value);
+ priv->name = g_strdup (empathy_tp_chat_get_title (priv->tp_chat));
g_object_notify (G_OBJECT (chat), "name");
- }
}
static gboolean
@@ -3144,11 +3138,13 @@ chat_finalize (GObject *object)
g_signal_handlers_disconnect_by_func (priv->tp_chat,
chat_state_changed_cb, chat);
g_signal_handlers_disconnect_by_func (priv->tp_chat,
- chat_property_changed_cb, chat);
- g_signal_handlers_disconnect_by_func (priv->tp_chat,
chat_members_changed_cb, chat);
g_signal_handlers_disconnect_by_func (priv->tp_chat,
chat_remote_contact_changed_cb, chat);
+ g_signal_handlers_disconnect_by_func (priv->tp_chat,
+ chat_title_changed_cb, chat);
+ g_signal_handlers_disconnect_by_func (priv->tp_chat,
+ chat_subject_changed_cb, chat);
empathy_tp_chat_leave (priv->tp_chat, "");
g_object_unref (priv->tp_chat);
}
@@ -3828,7 +3824,6 @@ empathy_chat_set_tp_chat (EmpathyChat *chat,
EmpathyTpChat *tp_chat)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- GPtrArray *properties;
g_return_if_fail (EMPATHY_IS_CHAT (chat));
g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
@@ -3859,9 +3854,6 @@ empathy_chat_set_tp_chat (EmpathyChat *chat,
g_signal_connect (tp_chat, "chat-state-changed-empathy",
G_CALLBACK (chat_state_changed_cb),
chat);
- g_signal_connect (tp_chat, "property-changed",
- G_CALLBACK (chat_property_changed_cb),
- chat);
g_signal_connect (tp_chat, "members-changed",
G_CALLBACK (chat_members_changed_cb),
chat);
@@ -3880,28 +3872,18 @@ empathy_chat_set_tp_chat (EmpathyChat *chat,
g_signal_connect_swapped (tp_chat, "notify::n-messages-sending",
G_CALLBACK (chat_n_messages_sending_changed_cb),
chat);
+ g_signal_connect_swapped (tp_chat, "notify::title",
+ G_CALLBACK (chat_title_changed_cb),
+ chat);
+ g_signal_connect_swapped (tp_chat, "notify::subject",
+ G_CALLBACK (chat_subject_changed_cb),
+ chat);
/* Get initial value of properties */
- properties = empathy_tp_chat_get_properties (priv->tp_chat);
- if (properties != NULL) {
- guint i;
-
- for (i = 0; i < properties->len; i++) {
- EmpathyTpChatProperty *property;
-
- property = g_ptr_array_index (properties, i);
- if (property->value == NULL)
- continue;
-
- chat_property_changed_cb (priv->tp_chat,
- property->name,
- property->value,
- chat);
- }
- }
-
chat_sms_channel_changed_cb (chat);
chat_remote_contact_changed_cb (chat);
+ chat_title_changed_cb (chat);
+ chat_subject_changed_cb (chat);
if (chat->input_text_view) {
gtk_widget_set_sensitive (chat->input_text_view, TRUE);
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index dcd6193ec..952d9a8ee 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -37,6 +37,13 @@
#define DEBUG_FLAG EMPATHY_DEBUG_TP | EMPATHY_DEBUG_CHAT
#include "empathy-debug.h"
+typedef struct {
+ gchar *name;
+ guint id;
+ TpPropertyFlags flags;
+ GValue *value;
+} EmpathyTpChatProperty;
+
struct _EmpathyTpChatPrivate {
TpAccount *account;
EmpathyContact *user;
@@ -63,13 +70,14 @@ enum {
PROP_ACCOUNT,
PROP_REMOTE_CONTACT,
PROP_N_MESSAGES_SENDING,
+ PROP_TITLE,
+ PROP_SUBJECT,
};
enum {
MESSAGE_RECEIVED,
SEND_ERROR,
CHAT_STATE_CHANGED,
- PROPERTY_CHANGED,
MESSAGE_ACKNOWLEDGED,
LAST_SIGNAL
};
@@ -651,8 +659,13 @@ tp_chat_properties_changed_cb (TpProxy *proxy,
}
DEBUG ("property %s changed", property->name);
- g_signal_emit (chat, signals[PROPERTY_CHANGED], 0,
- property->name, property->value);
+
+ if (!tp_strdiff (property->name, "name")) {
+ g_object_notify (chat, "title");
+ } else if (!tp_strdiff (property->name, "subject")) {
+ g_object_notify (chat, "subject");
+ }
+
break;
}
}
@@ -721,7 +734,7 @@ tp_chat_list_properties_cb (TpProxy *proxy,
g_array_free (ids, TRUE);
}
-void
+static void
empathy_tp_chat_set_property (EmpathyTpChat *self,
const gchar *name,
const GValue *value)
@@ -773,7 +786,19 @@ empathy_tp_chat_set_property (EmpathyTpChat *self,
}
}
-EmpathyTpChatProperty *
+void
+empathy_tp_chat_set_subject (EmpathyTpChat *self,
+ const gchar *subject)
+{
+ GValue value = { 0, };
+
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_set_string (&value, subject);
+ empathy_tp_chat_set_property (self, "subject", &value);
+ g_value_unset (&value);
+}
+
+static EmpathyTpChatProperty *
empathy_tp_chat_get_property (EmpathyTpChat *self,
const gchar *name)
{
@@ -794,10 +819,54 @@ empathy_tp_chat_get_property (EmpathyTpChat *self,
return NULL;
}
-GPtrArray *
-empathy_tp_chat_get_properties (EmpathyTpChat *self)
+const gchar *
+empathy_tp_chat_get_title (EmpathyTpChat *self)
+{
+ EmpathyTpChatProperty *property;
+
+ 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);
+ }
+}
+
+gboolean
+empathy_tp_chat_supports_subject (EmpathyTpChat *self)
{
- return self->priv->properties;
+ return (empathy_tp_chat_get_property (self, "subject") != NULL);
+}
+
+gboolean
+empathy_tp_chat_can_set_subject (EmpathyTpChat *self)
+{
+ EmpathyTpChatProperty *property;
+
+ property = empathy_tp_chat_get_property (self, "subject");
+
+ if (property == NULL) {
+ return FALSE;
+ } else if (property->flags & TP_PROPERTY_FLAG_WRITE) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+const gchar *
+empathy_tp_chat_get_subject (EmpathyTpChat *self)
+{
+ EmpathyTpChatProperty *property;
+
+ 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);
+ }
}
static void
@@ -1170,6 +1239,14 @@ tp_chat_get_property (GObject *object,
g_value_set_uint (value,
g_hash_table_size (self->priv->messages_being_sent));
break;
+ case PROP_TITLE:
+ g_value_set_string (value,
+ empathy_tp_chat_get_title (self));
+ break;
+ case PROP_SUBJECT:
+ g_value_set_string (value,
+ empathy_tp_chat_get_subject (self));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -1259,6 +1336,24 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
0, G_MAXUINT, 0,
G_PARAM_READABLE));
+ g_object_class_install_property (object_class,
+ PROP_TITLE,
+ g_param_spec_string ("title",
+ "Title",
+ "A human-readable name for the room, if any",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_SUBJECT,
+ g_param_spec_string ("subject",
+ "Subject",
+ "The room's current subject, if any",
+ NULL,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
/* Signals */
signals[MESSAGE_RECEIVED] =
g_signal_new ("message-received-empathy",
@@ -1290,16 +1385,6 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
G_TYPE_NONE,
2, EMPATHY_TYPE_CONTACT, G_TYPE_UINT);
- signals[PROPERTY_CHANGED] =
- g_signal_new ("property-changed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE,
- 2, G_TYPE_STRING, G_TYPE_VALUE);
-
signals[MESSAGE_ACKNOWLEDGED] =
g_signal_new ("message-acknowledged",
G_TYPE_FROM_CLASS (klass),
diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h
index 810cb5184..cc1c16aaf 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -53,13 +53,6 @@ struct _EmpathyTpChatClass {
TpTextChannelClass parent_class;
};
-typedef struct {
- gchar *name;
- guint id;
- TpPropertyFlags flags;
- GValue *value;
-} EmpathyTpChatProperty;
-
typedef enum {
EMPATHY_DELIVERY_STATUS_NONE,
EMPATHY_DELIVERY_STATUS_SENDING,
@@ -83,13 +76,14 @@ EmpathyContact *empathy_tp_chat_get_remote_contact (EmpathyTpChat *chat);
TpAccount * empathy_tp_chat_get_account (EmpathyTpChat *chat);
void empathy_tp_chat_send (EmpathyTpChat *chat,
TpMessage *message);
-void empathy_tp_chat_set_property (EmpathyTpChat *chat,
- const gchar *name,
- const GValue *value);
-EmpathyTpChatProperty *
- empathy_tp_chat_get_property (EmpathyTpChat *chat,
- const gchar *name);
-GPtrArray * empathy_tp_chat_get_properties (EmpathyTpChat *chat);
+
+const gchar * empathy_tp_chat_get_title (EmpathyTpChat *self);
+
+gboolean empathy_tp_chat_supports_subject (EmpathyTpChat *self);
+const gchar * empathy_tp_chat_get_subject (EmpathyTpChat *self);
+gboolean empathy_tp_chat_can_set_subject (EmpathyTpChat *self);
+void empathy_tp_chat_set_subject (EmpathyTpChat *self,
+ const gchar *subject);
/* Returns a read-only list of pending messages (should be a copy maybe ?) */
const GList * empathy_tp_chat_get_pending_messages (EmpathyTpChat *chat);