aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@src.gnome.org>2008-04-02 17:41:50 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2008-04-02 17:41:50 +0800
commit137e275fa6bf039dd5581483bf0cd9ed5be88914 (patch)
treee56978c81d89599e53b8c90d6e9522875961443d /libempathy
parentc17d91d81999edd94cd4417acb8e39491076098b (diff)
downloadgsoc2013-empathy-137e275fa6bf039dd5581483bf0cd9ed5be88914.tar
gsoc2013-empathy-137e275fa6bf039dd5581483bf0cd9ed5be88914.tar.gz
gsoc2013-empathy-137e275fa6bf039dd5581483bf0cd9ed5be88914.tar.bz2
gsoc2013-empathy-137e275fa6bf039dd5581483bf0cd9ed5be88914.tar.lz
gsoc2013-empathy-137e275fa6bf039dd5581483bf0cd9ed5be88914.tar.xz
gsoc2013-empathy-137e275fa6bf039dd5581483bf0cd9ed5be88914.tar.zst
gsoc2013-empathy-137e275fa6bf039dd5581483bf0cd9ed5be88914.zip
Rework EmpathyChat's API, it is now a subclass of GtkBin.
svn path=/trunk/; revision=840
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-message.c61
-rw-r--r--libempathy/empathy-message.h43
-rw-r--r--libempathy/empathy-tp-chat.c105
-rw-r--r--libempathy/empathy-tp-chat.h3
4 files changed, 148 insertions, 64 deletions
diff --git a/libempathy/empathy-message.c b/libempathy/empathy-message.c
index 76b49bd1a..d6b8e5323 100644
--- a/libempathy/empathy-message.c
+++ b/libempathy/empathy-message.c
@@ -437,6 +437,67 @@ empathy_message_get_date_and_time (EmpathyMessage *message, time_t *timestamp)
return date;
}
+#define IS_SEPARATOR(ch) (ch == ' ' || ch == ',' || ch == '.' || ch == ':')
+gboolean
+empathy_message_should_highlight (EmpathyMessage *message)
+{
+ EmpathyContact *contact;
+ const gchar *msg, *to;
+ gchar *cf_msg, *cf_to;
+ gchar *ch;
+ gboolean ret_val;
+
+ g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE);
+
+ ret_val = FALSE;
+
+ msg = empathy_message_get_body (message);
+ if (!msg) {
+ return FALSE;
+ }
+
+ contact = empathy_message_get_receiver (message);
+ if (!contact || !empathy_contact_is_user (contact)) {
+ return FALSE;
+ }
+
+ to = empathy_contact_get_name (contact);
+ if (!to) {
+ return FALSE;
+ }
+
+ cf_msg = g_utf8_casefold (msg, -1);
+ cf_to = g_utf8_casefold (to, -1);
+
+ ch = strstr (cf_msg, cf_to);
+ if (ch == NULL) {
+ goto finished;
+ }
+ if (ch != cf_msg) {
+ /* Not first in the message */
+ if (!IS_SEPARATOR (*(ch - 1))) {
+ goto finished;
+ }
+ }
+
+ ch = ch + strlen (cf_to);
+ if (ch >= cf_msg + strlen (cf_msg)) {
+ ret_val = TRUE;
+ goto finished;
+ }
+
+ if (IS_SEPARATOR (*ch)) {
+ ret_val = TRUE;
+ goto finished;
+ }
+
+finished:
+ g_free (cf_msg);
+ g_free (cf_to);
+
+ return ret_val;
+}
+
EmpathyMessageType
empathy_message_type_from_str (const gchar *type_str)
{
diff --git a/libempathy/empathy-message.h b/libempathy/empathy-message.h
index d1c995fe4..d07565b06 100644
--- a/libempathy/empathy-message.h
+++ b/libempathy/empathy-message.h
@@ -58,27 +58,28 @@ typedef enum {
EMPATHY_MESSAGE_TYPE_LAST
} EmpathyMessageType;
-GType empathy_message_get_gtype (void) G_GNUC_CONST;
-EmpathyMessage * empathy_message_new (const gchar *body);
-EmpathyMessageType empathy_message_get_type (EmpathyMessage *message);
-void empathy_message_set_type (EmpathyMessage *message,
- EmpathyMessageType type);
-EmpathyContact * empathy_message_get_sender (EmpathyMessage *message);
-void empathy_message_set_sender (EmpathyMessage *message,
- EmpathyContact *contact);
-EmpathyContact * empathy_message_get_receiver (EmpathyMessage *message);
-void empathy_message_set_receiver (EmpathyMessage *message,
- EmpathyContact *contact);
-const gchar * empathy_message_get_body (EmpathyMessage *message);
-void empathy_message_set_body (EmpathyMessage *message,
- const gchar *body);
-time_t empathy_message_get_timestamp (EmpathyMessage *message);
-void empathy_message_set_timestamp (EmpathyMessage *message,
- time_t timestamp);
-GDate * empathy_message_get_date_and_time (EmpathyMessage *message,
- time_t *timestamp);
-EmpathyMessageType empathy_message_type_from_str (const gchar *type_str);
-const gchar * empathy_message_type_to_str (EmpathyMessageType type);
+GType empathy_message_get_gtype (void) G_GNUC_CONST;
+EmpathyMessage * empathy_message_new (const gchar *body);
+EmpathyMessageType empathy_message_get_type (EmpathyMessage *message);
+void empathy_message_set_type (EmpathyMessage *message,
+ EmpathyMessageType type);
+EmpathyContact * empathy_message_get_sender (EmpathyMessage *message);
+void empathy_message_set_sender (EmpathyMessage *message,
+ EmpathyContact *contact);
+EmpathyContact * empathy_message_get_receiver (EmpathyMessage *message);
+void empathy_message_set_receiver (EmpathyMessage *message,
+ EmpathyContact *contact);
+const gchar * empathy_message_get_body (EmpathyMessage *message);
+void empathy_message_set_body (EmpathyMessage *message,
+ const gchar *body);
+time_t empathy_message_get_timestamp (EmpathyMessage *message);
+void empathy_message_set_timestamp (EmpathyMessage *message,
+ time_t timestamp);
+GDate * empathy_message_get_date_and_time (EmpathyMessage *message,
+ time_t *timestamp);
+gboolean empathy_message_should_highlight (EmpathyMessage *message);
+EmpathyMessageType empathy_message_type_from_str (const gchar *type_str);
+const gchar * empathy_message_type_to_str (EmpathyMessageType type);
G_END_DECLS
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index 0cbd5eea3..4c7702cd1 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -43,7 +43,7 @@
struct _EmpathyTpChatPriv {
EmpathyContactFactory *factory;
EmpathyContact *user;
- EmpathyContact *initiator;
+ EmpathyContact *remote_contact;
EmpathyTpGroup *group;
McAccount *account;
TpChannel *channel;
@@ -74,6 +74,7 @@ enum {
PROP_TP_CHAN,
PROP_CHANNEL,
PROP_ACKNOWLEDGE,
+ PROP_REMOTE_CONTACT,
};
enum {
@@ -202,7 +203,7 @@ tp_chat_get_members (EmpathyContactList *list)
members = empathy_tp_group_get_members (priv->group);
} else {
members = g_list_prepend (members, g_object_ref (priv->user));
- members = g_list_prepend (members, g_object_ref (priv->initiator));
+ members = g_list_prepend (members, g_object_ref (priv->remote_contact));
}
return members;
@@ -670,23 +671,54 @@ empathy_tp_chat_set_property (EmpathyTpChat *chat,
}
}
-static gboolean
+static void
tp_chat_channel_ready_cb (EmpathyTpChat *chat)
{
EmpathyTpChatPriv *priv = GET_PRIV (chat);
empathy_debug (DEBUG_DOMAIN, "Channel ready");
+ if (tp_proxy_has_interface_by_id (priv->channel,
+ TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
+ priv->group = empathy_tp_group_new (priv->account, priv->tp_chan);
+
+ g_signal_connect (priv->group, "member-added",
+ G_CALLBACK (tp_chat_member_added_cb),
+ chat);
+ g_signal_connect (priv->group, "member-removed",
+ G_CALLBACK (tp_chat_member_removed_cb),
+ chat);
+ g_signal_connect (priv->group, "local-pending",
+ G_CALLBACK (tp_chat_local_pending_cb),
+ chat);
+ } else {
+ priv->remote_contact = empathy_contact_factory_get_from_handle (priv->factory,
+ priv->account,
+ priv->tp_chan->handle);
+ g_object_notify (G_OBJECT (chat), "remote-contact");
+ }
+
+ if (tp_proxy_has_interface_by_id (priv->channel,
+ TP_IFACE_QUARK_PROPERTIES_INTERFACE)) {
+ tp_cli_properties_interface_call_list_properties (priv->channel, -1,
+ tp_chat_list_properties_cb,
+ NULL, NULL,
+ G_OBJECT (chat));
+ tp_cli_properties_interface_connect_to_properties_changed (priv->channel,
+ tp_chat_properties_changed_cb,
+ NULL, NULL,
+ G_OBJECT (chat), NULL);
+ tp_cli_properties_interface_connect_to_property_flags_changed (priv->channel,
+ tp_chat_property_flags_changed_cb,
+ NULL, NULL,
+ G_OBJECT (chat), NULL);
+ }
+
tp_cli_channel_type_text_call_list_pending_messages (priv->channel, -1,
priv->acknowledge,
tp_chat_list_pending_messages_cb,
NULL, NULL,
G_OBJECT (chat));
- tp_cli_properties_interface_call_list_properties (priv->channel, -1,
- tp_chat_list_properties_cb,
- NULL, NULL,
- G_OBJECT (chat));
-
tp_cli_channel_type_text_connect_to_received (priv->channel,
tp_chat_received_cb,
@@ -708,16 +740,6 @@ tp_chat_channel_ready_cb (EmpathyTpChat *chat)
tp_chat_state_changed_cb,
NULL, NULL,
G_OBJECT (chat), NULL);
- tp_cli_properties_interface_connect_to_properties_changed (priv->channel,
- tp_chat_properties_changed_cb,
- NULL, NULL,
- G_OBJECT (chat), NULL);
- tp_cli_properties_interface_connect_to_property_flags_changed (priv->channel,
- tp_chat_property_flags_changed_cb,
- NULL, NULL,
- G_OBJECT (chat), NULL);
-
- return FALSE;
}
static void
@@ -758,8 +780,8 @@ tp_chat_finalize (GObject *object)
g_ptr_array_free (priv->properties, TRUE);
}
- if (priv->initiator) {
- g_object_unref (priv->initiator);
+ if (priv->remote_contact) {
+ g_object_unref (priv->remote_contact);
}
if (priv->group) {
g_object_unref (priv->group);
@@ -803,25 +825,6 @@ tp_chat_constructor (GType type,
chat);
}
- if (tp_proxy_has_interface_by_id (priv->channel,
- TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP)) {
- priv->group = empathy_tp_group_new (priv->account, priv->tp_chan);
-
- g_signal_connect (priv->group, "member-added",
- G_CALLBACK (tp_chat_member_added_cb),
- chat);
- g_signal_connect (priv->group, "member-removed",
- G_CALLBACK (tp_chat_member_removed_cb),
- chat);
- g_signal_connect (priv->group, "local-pending",
- G_CALLBACK (tp_chat_local_pending_cb),
- chat);
- } else {
- priv->initiator = empathy_contact_factory_get_from_handle (priv->factory,
- priv->account,
- priv->tp_chan->handle);
- }
-
return chat;
}
@@ -846,6 +849,9 @@ tp_chat_get_property (GObject *object,
case PROP_ACKNOWLEDGE:
g_value_set_boolean (value, priv->acknowledge);
break;
+ case PROP_REMOTE_CONTACT:
+ g_value_set_object (value, priv->remote_contact);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -906,7 +912,6 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
TELEPATHY_CHAN_TYPE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
-
g_object_class_install_property (object_class,
PROP_CHANNEL,
g_param_spec_object ("channel",
@@ -915,7 +920,6 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
TP_TYPE_CHANNEL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
-
g_object_class_install_property (object_class,
PROP_ACKNOWLEDGE,
g_param_spec_boolean ("acknowledge",
@@ -923,7 +927,14 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
"Wheter or not received messages should be acknowledged",
FALSE,
G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
+ G_PARAM_CONSTRUCT));
+ g_object_class_install_property (object_class,
+ PROP_REMOTE_CONTACT,
+ g_param_spec_object ("remote-contact",
+ "The remote contact",
+ "The remote contact if there is no group iface on the channel",
+ EMPATHY_TYPE_CONTACT,
+ G_PARAM_READABLE));
/* Signals */
signals[MESSAGE_RECEIVED] =
@@ -1150,3 +1161,13 @@ empathy_tp_chat_get_id (EmpathyTpChat *chat)
return priv->id;
}
+EmpathyContact *
+empathy_tp_chat_get_remote_contact (EmpathyTpChat *chat)
+{
+ EmpathyTpChatPriv *priv = GET_PRIV (chat);
+
+ g_return_val_if_fail (EMPATHY_IS_TP_CHAT (chat), NULL);
+
+ return priv->remote_contact;
+}
+
diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h
index 72c0c0122..3911e1dd1 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -61,11 +61,12 @@ EmpathyTpChat *empathy_tp_chat_new (McAccount *account
EmpathyTpChat *empathy_tp_chat_new_with_contact (EmpathyContact *contact);
McAccount * empathy_tp_chat_get_account (EmpathyTpChat *chat);
TpChan * empathy_tp_chat_get_channel (EmpathyTpChat *chat);
+const gchar * empathy_tp_chat_get_id (EmpathyTpChat *chat);
+EmpathyContact*empathy_tp_chat_get_remote_contact (EmpathyTpChat *chat);
void empathy_tp_chat_send (EmpathyTpChat *chat,
EmpathyMessage *message);
void empathy_tp_chat_set_state (EmpathyTpChat *chat,
TpChannelChatState state);
-const gchar * empathy_tp_chat_get_id (EmpathyTpChat *chat);
void empathy_tp_chat_set_property (EmpathyTpChat *chat,
const gchar *name,
const GValue *value);