aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2009-10-10 06:28:26 +0800
committerXavier Claessens <xclaesse@gmail.com>2009-11-01 22:36:45 +0800
commit940f9b60e27fe79d64357c651525cbf50a936567 (patch)
tree92a7ad5aae1285f5b5a1562ddf3df464c1210b11
parente00d3a20de6603e927f4c977492052701cc0a988 (diff)
downloadgsoc2013-empathy-940f9b60e27fe79d64357c651525cbf50a936567.tar
gsoc2013-empathy-940f9b60e27fe79d64357c651525cbf50a936567.tar.gz
gsoc2013-empathy-940f9b60e27fe79d64357c651525cbf50a936567.tar.bz2
gsoc2013-empathy-940f9b60e27fe79d64357c651525cbf50a936567.tar.lz
gsoc2013-empathy-940f9b60e27fe79d64357c651525cbf50a936567.tar.xz
gsoc2013-empathy-940f9b60e27fe79d64357c651525cbf50a936567.tar.zst
gsoc2013-empathy-940f9b60e27fe79d64357c651525cbf50a936567.zip
Fix topic not always shown, and add /topic command support.
https://bugzilla.gnome.org/show_bug.cgi?id=573407
-rw-r--r--libempathy-gtk/empathy-chat.c51
-rw-r--r--libempathy/empathy-tp-chat.c73
-rw-r--r--libempathy/empathy-tp-chat.h11
3 files changed, 108 insertions, 27 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index 3931115be..6c712a54e 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -394,6 +394,31 @@ chat_send (EmpathyChat *chat,
if (strcmp (msg, "/clear") == 0) {
empathy_chat_view_clear (chat->view);
return;
+ } else if (g_str_has_prefix (msg, "/topic")) {
+ EmpathyTpChatProperty *property;
+ GValue value = {0, };
+ gchar *topic;
+
+ property = empathy_tp_chat_get_property (priv->tp_chat, "subject");
+ if (property == NULL) {
+ empathy_chat_view_append_event (chat->view,
+ _("This conversation does not have topic"));
+ return;
+ }
+
+ if (!(property->flags & TP_PROPERTY_FLAG_WRITE)) {
+ empathy_chat_view_append_event (chat->view,
+ _("You need to be a channel operator to do that"));
+ return;
+ }
+
+ topic = g_strstrip (g_strdup (msg + strlen ("/topic")));
+ g_value_init (&value, G_TYPE_STRING);
+ g_value_take_string (&value, topic);
+ empathy_tp_chat_set_property (priv->tp_chat, "subject", &value);
+ g_value_unset (&value);
+
+ return;
}
message = empathy_message_new_from_entry (msg);
@@ -1449,9 +1474,6 @@ chat_create_ui (EmpathyChat *chat)
chat->input_text_view);
gtk_widget_show (chat->input_text_view);
- /* Create contact list */
- chat_update_contacts_visibility (chat);
-
/* Initialy hide the topic, will be shown if not empty */
gtk_widget_hide (priv->hbox_topic);
@@ -1588,7 +1610,6 @@ chat_constructed (GObject *object)
{
EmpathyChat *chat = EMPATHY_CHAT (object);
- chat_create_ui (chat);
chat_add_logs (chat);
show_pending_messages (chat);
}
@@ -1728,6 +1749,8 @@ empathy_chat_init (EmpathyChat *chat)
/* Add nick name completion */
priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_name);
g_completion_set_compare (priv->completion, chat_contacts_completion_func);
+
+ chat_create_ui (chat);
}
EmpathyChat *
@@ -1752,6 +1775,7 @@ empathy_chat_set_tp_chat (EmpathyChat *chat,
{
EmpathyChatPriv *priv = GET_PRIV (chat);
TpConnection *connection;
+ GPtrArray *properties;
g_return_if_fail (EMPATHY_IS_CHAT (chat));
g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
@@ -1794,6 +1818,25 @@ empathy_chat_set_tp_chat (EmpathyChat *chat,
G_CALLBACK (chat_remote_contact_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_remote_contact_changed_cb (chat);
if (chat->input_text_view) {
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index 09077538a..83faaff39 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -58,13 +58,6 @@ typedef struct {
gboolean ready;
} EmpathyTpChatPriv;
-typedef struct {
- gchar *name;
- guint id;
- TpPropertyFlags flags;
- GValue *value;
-} TpChatProperty;
-
static void tp_chat_iface_init (EmpathyContactListIface *iface);
enum {
@@ -493,10 +486,10 @@ tp_chat_property_flags_changed_cb (TpProxy *proxy,
}
for (i = 0; i < properties->len; i++) {
- GValueArray *prop_struct;
- TpChatProperty *property;
- guint id;
- guint flags;
+ GValueArray *prop_struct;
+ EmpathyTpChatProperty *property;
+ guint id;
+ guint flags;
prop_struct = g_ptr_array_index (properties, i);
id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
@@ -531,10 +524,10 @@ tp_chat_properties_changed_cb (TpProxy *proxy,
}
for (i = 0; i < properties->len; i++) {
- GValueArray *prop_struct;
- TpChatProperty *property;
- guint id;
- GValue *src_value;
+ GValueArray *prop_struct;
+ EmpathyTpChatProperty *property;
+ guint id;
+ GValue *src_value;
prop_struct = g_ptr_array_index (properties, i);
id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
@@ -597,11 +590,11 @@ tp_chat_list_properties_cb (TpProxy *proxy,
ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), properties->len);
priv->properties = g_ptr_array_sized_new (properties->len);
for (i = 0; i < properties->len; i++) {
- GValueArray *prop_struct;
- TpChatProperty *property;
+ GValueArray *prop_struct;
+ EmpathyTpChatProperty *property;
prop_struct = g_ptr_array_index (properties, i);
- property = g_slice_new0 (TpChatProperty);
+ property = g_slice_new0 (EmpathyTpChatProperty);
property->id = g_value_get_uint (g_value_array_get_nth (prop_struct, 0));
property->name = g_value_dup_string (g_value_array_get_nth (prop_struct, 1));
property->flags = g_value_get_uint (g_value_array_get_nth (prop_struct, 3));
@@ -628,9 +621,13 @@ empathy_tp_chat_set_property (EmpathyTpChat *chat,
const gchar *name,
const GValue *value)
{
- EmpathyTpChatPriv *priv = GET_PRIV (chat);
- TpChatProperty *property;
- guint i;
+ EmpathyTpChatPriv *priv = GET_PRIV (chat);
+ EmpathyTpChatProperty *property;
+ guint i;
+
+ if (!priv->had_properties_list) {
+ return;
+ }
for (i = 0; i < priv->properties->len; i++) {
property = g_ptr_array_index (priv->properties, i);
@@ -672,6 +669,36 @@ empathy_tp_chat_set_property (EmpathyTpChat *chat,
}
}
+EmpathyTpChatProperty *
+empathy_tp_chat_get_property (EmpathyTpChat *chat,
+ const gchar *name)
+{
+ EmpathyTpChatPriv *priv = GET_PRIV (chat);
+ EmpathyTpChatProperty *property;
+ guint i;
+
+ if (!priv->had_properties_list) {
+ return NULL;
+ }
+
+ for (i = 0; i < priv->properties->len; i++) {
+ property = g_ptr_array_index (priv->properties, i);
+ if (!tp_strdiff (property->name, name)) {
+ return property;
+ }
+ }
+
+ return NULL;
+}
+
+GPtrArray *
+empathy_tp_chat_get_properties (EmpathyTpChat *chat)
+{
+ EmpathyTpChatPriv *priv = GET_PRIV (chat);
+
+ return priv->properties;
+}
+
static void
tp_chat_dispose (GObject *object)
{
@@ -727,14 +754,14 @@ tp_chat_finalize (GObject *object)
if (priv->properties) {
for (i = 0; i < priv->properties->len; i++) {
- TpChatProperty *property;
+ EmpathyTpChatProperty *property;
property = g_ptr_array_index (priv->properties, i);
g_free (property->name);
if (property->value) {
tp_g_value_slice_free (property->value);
}
- g_slice_free (TpChatProperty, property);
+ g_slice_free (EmpathyTpChatProperty, property);
}
g_ptr_array_free (priv->properties, TRUE);
}
diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h
index f7d2b58a1..f07f0648f 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -52,6 +52,13 @@ struct _EmpathyTpChatClass {
GObjectClass parent_class;
};
+typedef struct {
+ gchar *name;
+ guint id;
+ TpPropertyFlags flags;
+ GValue *value;
+} EmpathyTpChatProperty;
+
GType empathy_tp_chat_get_type (void) G_GNUC_CONST;
EmpathyTpChat *empathy_tp_chat_new (TpChannel *channel);
void empathy_tp_chat_close (EmpathyTpChat *chat);
@@ -67,6 +74,10 @@ void empathy_tp_chat_set_state (EmpathyTpChat *chat,
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);
/* Returns a read-only list of pending messages (should be a copy maybe ?) */
const GList * empathy_tp_chat_get_pending_messages (EmpathyTpChat *chat);