aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorXavier Claessens <xclaesse@gmail.com>2007-06-14 05:58:16 +0800
committerXavier Claessens <xclaesse@src.gnome.org>2007-06-14 05:58:16 +0800
commit4ce14ebec31f60a4a6bdd781f88607731912f557 (patch)
tree0ee31695ccdd06cae5f5b09bf5098707528b1dd3 /libempathy
parente24e8894479c1b69364faeb315ab0d0dbf7989f1 (diff)
downloadgsoc2013-empathy-4ce14ebec31f60a4a6bdd781f88607731912f557.tar
gsoc2013-empathy-4ce14ebec31f60a4a6bdd781f88607731912f557.tar.gz
gsoc2013-empathy-4ce14ebec31f60a4a6bdd781f88607731912f557.tar.bz2
gsoc2013-empathy-4ce14ebec31f60a4a6bdd781f88607731912f557.tar.lz
gsoc2013-empathy-4ce14ebec31f60a4a6bdd781f88607731912f557.tar.xz
gsoc2013-empathy-4ce14ebec31f60a4a6bdd781f88607731912f557.tar.zst
gsoc2013-empathy-4ce14ebec31f60a4a6bdd781f88607731912f557.zip
New window for viewing logs.
2007-06-13 Xavier Claessens <xclaesse@gmail.com> * libempathy-gtk/Makefile.am: * libempathy-gtk/gossip-log-window.glade: * libempathy-gtk/gossip-log-window.h: * libempathy-gtk/gossip-log-window.c: * libempathy/empathy-log-manager.c: * libempathy/empathy-log-manager.h: * libempathy-gtk/gossip-chat.c: * libempathy-gtk/empathy-main-window.c: New window for viewing logs. * libempathy-gtk/gossip-chat-view.c: Do not use smooth scroll when resizing the view. * libempathy-gtk/gossip-contact-list-store.c: Do not set active contacts when creating the store, and when contact groups changed. * src/empathy-main.c: Fix warning when using command-line options. * libempathy/empathy-tp-contact-list.c: Check if we have an aliasing iface before setting the alias of a contact. * TODO: Updated. * data/jabber.profile: Ignore ssl errors by default. This is a security vulnerability but we don't really have the choice. * libempathy/gossip-contact.h: * libempathy/gossip-contact.c: Add a "is-user" property to know if it's our self contact. * libempathy/gossip-message.h: * libempathy/gossip-message.c: Add a "receiver" property like that we have our self contact for nick highlight. svn path=/trunk/; revision=148
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-log-manager.c376
-rw-r--r--libempathy/empathy-log-manager.h23
-rw-r--r--libempathy/empathy-tp-chat.c6
-rw-r--r--libempathy/empathy-tp-contact-list.c6
-rw-r--r--libempathy/gossip-contact.c79
-rw-r--r--libempathy/gossip-contact.h4
-rw-r--r--libempathy/gossip-message.c56
-rw-r--r--libempathy/gossip-message.h3
8 files changed, 465 insertions, 88 deletions
diff --git a/libempathy/empathy-log-manager.c b/libempathy/empathy-log-manager.c
index ca5297ea7..49c67ec4e 100644
--- a/libempathy/empathy-log-manager.c
+++ b/libempathy/empathy-log-manager.c
@@ -39,6 +39,7 @@
#define LOG_DIR_CREATE_MODE (S_IRUSR | S_IWUSR | S_IXUSR)
#define LOG_FILE_CREATE_MODE (S_IRUSR | S_IWUSR)
+#define LOG_DIR_CHATROOMS "chatrooms"
#define LOG_FILENAME_SUFFIX ".log"
#define LOG_TIME_FORMAT_FULL "%Y%m%dT%H:%M:%S"
#define LOG_TIME_FORMAT "%Y%m%d"
@@ -51,21 +52,35 @@
"</log>\n"
struct _EmpathyLogManagerPriv {
- gboolean dummy;
+ gchar *basedir;
};
-static void empathy_log_manager_class_init (EmpathyLogManagerClass *klass);
-static void empathy_log_manager_init (EmpathyLogManager *manager);
-static void log_manager_finalize (GObject *object);
-static gchar * log_manager_get_dir (McAccount *account,
- const gchar *chat_id);
-static gchar * log_manager_get_filename (McAccount *account,
- const gchar *chat_id);
-static gchar * log_manager_get_filename_for_date (McAccount *account,
- const gchar *chat_id,
- const gchar *date);
-static gchar * log_manager_get_timestamp_filename (void);
-static gchar * log_manager_get_timestamp_from_message (GossipMessage *message);
+static void empathy_log_manager_class_init (EmpathyLogManagerClass *klass);
+static void empathy_log_manager_init (EmpathyLogManager *manager);
+static void log_manager_finalize (GObject *object);
+static const gchar * log_manager_get_basedir (EmpathyLogManager *manager);
+static GList * log_manager_get_all_files (EmpathyLogManager *manager,
+ const gchar *dir);
+static GList * log_manager_get_chats (EmpathyLogManager *manager,
+ const gchar *dir,
+ gboolean is_chatroom);
+static gchar * log_manager_get_dir (EmpathyLogManager *manager,
+ McAccount *account,
+ const gchar *chat_id,
+ gboolean chatroom);
+static gchar * log_manager_get_filename (EmpathyLogManager *manager,
+ McAccount *account,
+ const gchar *chat_id,
+ gboolean chatroom);
+static gchar * log_manager_get_filename_for_date (EmpathyLogManager *manager,
+ McAccount *account,
+ const gchar *chat_id,
+ gboolean chatroom,
+ const gchar *date);
+static gchar * log_manager_get_timestamp_filename (void);
+static gchar * log_manager_get_timestamp_from_message (GossipMessage *message);
+static EmpathyLogSearchHit *log_manager_search_hit_new (EmpathyLogManager *manager,
+ const gchar *filename);
G_DEFINE_TYPE (EmpathyLogManager, empathy_log_manager, G_TYPE_OBJECT);
@@ -87,6 +102,11 @@ empathy_log_manager_init (EmpathyLogManager *manager)
static void
log_manager_finalize (GObject *object)
{
+ EmpathyLogManagerPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ g_free (priv->basedir);
}
EmpathyLogManager *
@@ -107,6 +127,7 @@ empathy_log_manager_new (void)
void
empathy_log_manager_add_message (EmpathyLogManager *manager,
const gchar *chat_id,
+ gboolean chatroom,
GossipMessage *message)
{
FILE *file;
@@ -132,7 +153,7 @@ empathy_log_manager_add_message (EmpathyLogManager *manager,
return;
}
- filename = log_manager_get_filename (account, chat_id);
+ filename = log_manager_get_filename (manager, account, chat_id, chatroom);
gossip_debug (DEBUG_DOMAIN, "Adding message: '%s' to file: '%s'",
body_str, filename);
@@ -154,24 +175,17 @@ empathy_log_manager_add_message (EmpathyLogManager *manager,
timestamp = log_manager_get_timestamp_from_message (message);
str = gossip_contact_get_name (sender);
- if (!str) {
- contact_name = g_strdup ("");
- } else {
- contact_name = g_markup_escape_text (str, -1);
- }
+ contact_name = g_markup_escape_text (str, -1);
str = gossip_contact_get_id (sender);
- if (!str) {
- contact_id = g_strdup ("");
- } else {
- contact_id = g_markup_escape_text (str, -1);
- }
+ contact_id = g_markup_escape_text (str, -1);
g_fprintf (file,
- "<message time='%s' id='%s' name='%s'>%s</message>\n" LOG_FOOTER,
+ "<message time='%s' id='%s' name='%s' isuser='%s'>%s</message>\n" LOG_FOOTER,
timestamp,
contact_id,
contact_name,
+ gossip_contact_is_user (sender) ? "true" : "false",
body);
fclose (file);
@@ -185,7 +199,8 @@ empathy_log_manager_add_message (EmpathyLogManager *manager,
GList *
empathy_log_manager_get_dates (EmpathyLogManager *manager,
McAccount *account,
- const gchar *chat_id)
+ const gchar *chat_id,
+ gboolean chatroom)
{
GList *dates = NULL;
gchar *date;
@@ -198,7 +213,7 @@ empathy_log_manager_get_dates (EmpathyLogManager *manager,
g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
g_return_val_if_fail (chat_id != NULL, NULL);
- directory = log_manager_get_dir (account, chat_id);
+ directory = log_manager_get_dir (manager, account, chat_id, chatroom);
if (!directory) {
return NULL;
}
@@ -238,6 +253,7 @@ GList *
empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager,
McAccount *account,
const gchar *chat_id,
+ gboolean chatroom,
const gchar *date)
{
gchar *filename;
@@ -251,7 +267,7 @@ empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager,
g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
g_return_val_if_fail (chat_id != NULL, NULL);
- filename = log_manager_get_filename_for_date (account, chat_id, date);
+ filename = log_manager_get_filename_for_date (manager, account, chat_id, chatroom, date);
gossip_debug (DEBUG_DOMAIN, "Attempting to parse filename:'%s'...", filename);
@@ -291,6 +307,8 @@ empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager,
gchar *sender_id;
gchar *sender_name;
gchar *body;
+ gchar *is_user_str;
+ gboolean is_user = FALSE;
if (strcmp (node->name, "message") != 0) {
continue;
@@ -300,10 +318,16 @@ empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager,
time = xmlGetProp (node, "time");
sender_id = xmlGetProp (node, "id");
sender_name = xmlGetProp (node, "name");
+ is_user_str = xmlGetProp (node, "isuser");
+
+ if (is_user_str) {
+ is_user = strcmp (is_user_str, "true") == 0;
+ }
t = gossip_time_parse (time);
sender = gossip_contact_new_full (account, sender_id, sender_name);
+ gossip_contact_set_is_user (sender, is_user);
message = gossip_message_new (body);
gossip_message_set_sender (message, sender);
gossip_message_set_timestamp (message, t);
@@ -329,7 +353,8 @@ empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager,
GList *
empathy_log_manager_get_last_messages (EmpathyLogManager *manager,
McAccount *account,
- const gchar *chat_id)
+ const gchar *chat_id,
+ gboolean chatroom)
{
GList *messages = NULL;
GList *dates;
@@ -339,13 +364,14 @@ empathy_log_manager_get_last_messages (EmpathyLogManager *manager,
g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
g_return_val_if_fail (chat_id != NULL, NULL);
- dates = empathy_log_manager_get_dates (manager, account, chat_id);
+ dates = empathy_log_manager_get_dates (manager, account, chat_id, chatroom);
l = g_list_last (dates);
if (l) {
messages = empathy_log_manager_get_messages_for_date (manager,
account,
chat_id,
+ chatroom,
l->data);
}
@@ -355,22 +381,238 @@ empathy_log_manager_get_last_messages (EmpathyLogManager *manager,
return messages;
}
+GList *
+empathy_log_manager_get_chats (EmpathyLogManager *manager,
+ McAccount *account)
+{
+ const gchar *basedir;
+ gchar *dir;
+
+ basedir = log_manager_get_basedir (manager);
+ dir = g_build_filename (basedir,
+ mc_account_get_unique_name (account),
+ NULL);
+
+ return log_manager_get_chats (manager, dir, FALSE);
+}
+
+GList *
+empathy_log_manager_search_new (EmpathyLogManager *manager,
+ const gchar *text)
+{
+ GList *files, *l;
+ GList *hits = NULL;
+ gchar *text_casefold;
+
+ g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL);
+ g_return_val_if_fail (!G_STR_EMPTY (text), NULL);
+
+ text_casefold = g_utf8_casefold (text, -1);
+
+ files = log_manager_get_all_files (manager, NULL);
+ gossip_debug (DEBUG_DOMAIN, "Found %d log files in total",
+ g_list_length (files));
+
+ for (l = files; l; l = l->next) {
+ gchar *filename;
+ GMappedFile *file;
+ gsize length;
+ gchar *contents;
+ gchar *contents_casefold;
+
+ filename = l->data;
+
+ file = g_mapped_file_new (filename, FALSE, NULL);
+ if (!file) {
+ continue;
+ }
+
+ length = g_mapped_file_get_length (file);
+ contents = g_mapped_file_get_contents (file);
+ contents_casefold = g_utf8_casefold (contents, length);
+
+ g_mapped_file_free (file);
+
+ if (strstr (contents_casefold, text_casefold)) {
+ EmpathyLogSearchHit *hit;
+
+ hit = log_manager_search_hit_new (manager, filename);
+
+ if (hit) {
+ hits = g_list_prepend (hits, hit);
+ gossip_debug (DEBUG_DOMAIN,
+ "Found text:'%s' in file:'%s' on date:'%s'...",
+ text, hit->filename, hit->date);
+ }
+ }
+
+ g_free (contents_casefold);
+ g_free (filename);
+ }
+ g_list_free (files);
+
+ g_free (text_casefold);
+
+ return hits;
+}
+
+void
+empathy_log_manager_search_free (GList *hits)
+{
+ GList *l;
+ EmpathyLogSearchHit *hit;
+
+ for (l = hits; l; l = l->next) {
+ hit = l->data;
+
+ if (hit->account) {
+ g_object_unref (hit->account);
+ }
+
+ g_free (hit->date);
+ g_free (hit->filename);
+ g_free (hit->chat_id);
+
+ g_slice_free (EmpathyLogSearchHit, hit);
+ }
+
+ g_list_free (hits);
+}
+
+/* Format is just date, 20061201. */
+gchar *
+empathy_log_manager_get_date_readable (const gchar *date)
+{
+ GossipTime t;
+
+ t = gossip_time_parse (date);
+
+ return gossip_time_to_string_local (t, "%a %d %b %Y");
+}
+
+static const gchar *
+log_manager_get_basedir (EmpathyLogManager *manager)
+{
+ EmpathyLogManagerPriv *priv;
+
+ priv = GET_PRIV (manager);
+
+ if (priv->basedir) {
+ return priv->basedir;
+ }
+
+ priv->basedir = g_build_path (G_DIR_SEPARATOR_S,
+ g_get_home_dir (),
+ ".gnome2",
+ PACKAGE_NAME,
+ "logs",
+ NULL);
+
+ return priv->basedir;
+}
+
+static GList *
+log_manager_get_all_files (EmpathyLogManager *manager,
+ const gchar *dir)
+{
+ GDir *gdir;
+ GList *files = NULL;
+ const gchar *name;
+
+ if (!dir) {
+ dir = log_manager_get_basedir (manager);
+ }
+
+ gdir = g_dir_open (dir, 0, NULL);
+ if (!gdir) {
+ return NULL;
+ }
+
+ while ((name = g_dir_read_name (gdir)) != NULL) {
+ gchar *filename;
+
+ filename = g_build_filename (dir, name, NULL);
+ if (g_str_has_suffix (filename, LOG_FILENAME_SUFFIX)) {
+ files = g_list_prepend (files, filename);
+ continue;
+ }
+
+ if (g_file_test (filename, G_FILE_TEST_IS_DIR)) {
+ /* Recursively get all log files */
+ files = g_list_concat (files, log_manager_get_all_files (manager, filename));
+ }
+ g_free (filename);
+ }
+
+ g_dir_close (gdir);
+
+ return files;
+}
+
+static GList *
+log_manager_get_chats (EmpathyLogManager *manager,
+ const gchar *dir,
+ gboolean is_chatroom)
+{
+ GDir *gdir;
+ GList *hits = NULL;
+ const gchar *name;
+
+ gdir = g_dir_open (dir, 0, NULL);
+ if (!gdir) {
+ return NULL;
+ }
+
+ while ((name = g_dir_read_name (gdir)) != NULL) {
+ EmpathyLogSearchHit *hit;
+ gchar *filename;
+
+ filename = g_build_filename (dir, name, NULL);
+ if (strcmp (name, LOG_DIR_CHATROOMS) == 0) {
+ hits = g_list_concat (hits, log_manager_get_chats (manager, filename, TRUE));
+ g_free (filename);
+ continue;
+ }
+
+ hit = g_slice_new0 (EmpathyLogSearchHit);
+ hit->chat_id = g_strdup (name);
+ hit->is_chatroom = is_chatroom;
+
+ hits = g_list_prepend (hits, hit);
+ }
+
+ g_dir_close (gdir);
+
+ return hits;
+}
+
static gchar *
-log_manager_get_dir (McAccount *account,
- const gchar *chat_id)
+log_manager_get_dir (EmpathyLogManager *manager,
+ McAccount *account,
+ const gchar *chat_id,
+ gboolean chatroom)
{
const gchar *account_id;
gchar *basedir;
+ gchar *str;
account_id = mc_account_get_unique_name (account);
- basedir = g_build_path (G_DIR_SEPARATOR_S,
- g_get_home_dir (),
- ".gnome2",
- PACKAGE_NAME,
- "logs",
- account_id,
- chat_id,
- NULL);
+ basedir =
+ str = g_build_path (G_DIR_SEPARATOR_S,
+ log_manager_get_basedir (manager),
+ account_id,
+ chat_id,
+ NULL);
+
+ if (chatroom) {
+ basedir = g_build_path (G_DIR_SEPARATOR_S,
+ str,
+ LOG_DIR_CHATROOMS,
+ NULL);
+ g_free (str);
+ } else {
+ basedir = str;
+ }
if (!g_file_test (basedir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) {
gossip_debug (DEBUG_DOMAIN, "Creating directory:'%s'", basedir);
@@ -382,14 +624,16 @@ log_manager_get_dir (McAccount *account,
}
static gchar *
-log_manager_get_filename (McAccount *account,
- const gchar *chat_id)
+log_manager_get_filename (EmpathyLogManager *manager,
+ McAccount *account,
+ const gchar *chat_id,
+ gboolean chatroom)
{
gchar *basedir;
gchar *timestamp;
gchar *filename;
- basedir = log_manager_get_dir (account, chat_id);
+ basedir = log_manager_get_dir (manager, account, chat_id, chatroom);
timestamp = log_manager_get_timestamp_filename ();
filename = g_build_filename (basedir, timestamp, NULL);
@@ -400,15 +644,17 @@ log_manager_get_filename (McAccount *account,
}
static gchar *
-log_manager_get_filename_for_date (McAccount *account,
- const gchar *chat_id,
- const gchar *date)
+log_manager_get_filename_for_date (EmpathyLogManager *manager,
+ McAccount *account,
+ const gchar *chat_id,
+ gboolean chatroom,
+ const gchar *date)
{
gchar *basedir;
gchar *timestamp;
gchar *filename;
- basedir = log_manager_get_dir (account, chat_id);
+ basedir = log_manager_get_dir (manager, account, chat_id, chatroom);
timestamp = g_strconcat (date, LOG_FILENAME_SUFFIX, NULL);
filename = g_build_filename (basedir, timestamp, NULL);
@@ -445,3 +691,39 @@ log_manager_get_timestamp_from_message (GossipMessage *message)
return gossip_time_to_string_utc (t, LOG_TIME_FORMAT_FULL);
}
+static EmpathyLogSearchHit *
+log_manager_search_hit_new (EmpathyLogManager *manager,
+ const gchar *filename)
+{
+ EmpathyLogSearchHit *hit;
+ const gchar *account_name;
+ const gchar *end;
+ gchar **strv;
+ guint len;
+
+ if (!g_str_has_suffix (filename, LOG_FILENAME_SUFFIX)) {
+ return NULL;
+ }
+
+ strv = g_strsplit (filename, G_DIR_SEPARATOR_S, -1);
+ len = g_strv_length (strv);
+
+ hit = g_slice_new0 (EmpathyLogSearchHit);
+
+ end = strstr (strv[len-1], LOG_FILENAME_SUFFIX);
+ hit->date = g_strndup (strv[len-1], end - strv[len-1]);
+ hit->chat_id = g_strdup (strv[len-2]);
+ hit->is_chatroom = (strcmp (strv[len-3], LOG_DIR_CHATROOMS) == 0);
+ if (hit->is_chatroom) {
+ account_name = strv[len-4];
+ } else {
+ account_name = strv[len-3];
+ }
+ hit->account = mc_account_lookup (account_name);
+ hit->filename = g_strdup (filename);
+
+ g_strfreev (strv);
+
+ return hit;
+}
+
diff --git a/libempathy/empathy-log-manager.h b/libempathy/empathy-log-manager.h
index 8df68d5ed..9a163fd36 100644
--- a/libempathy/empathy-log-manager.h
+++ b/libempathy/empathy-log-manager.h
@@ -41,6 +41,7 @@ G_BEGIN_DECLS
typedef struct _EmpathyLogManager EmpathyLogManager;
typedef struct _EmpathyLogManagerClass EmpathyLogManagerClass;
typedef struct _EmpathyLogManagerPriv EmpathyLogManagerPriv;
+typedef struct _EmpathyLogSearchHit EmpathyLogSearchHit;
struct _EmpathyLogManager {
GObject parent;
@@ -50,21 +51,39 @@ struct _EmpathyLogManagerClass {
GObjectClass parent_class;
};
+struct _EmpathyLogSearchHit {
+ McAccount *account;
+ gchar *chat_id;
+ gboolean is_chatroom;
+ gchar *filename;
+ gchar *date;
+};
+
GType empathy_log_manager_get_type (void) G_GNUC_CONST;
EmpathyLogManager *empathy_log_manager_new (void);
void empathy_log_manager_add_message (EmpathyLogManager *manager,
const gchar *chat_id,
+ gboolean chatroom,
GossipMessage *message);
GList * empathy_log_manager_get_dates (EmpathyLogManager *manager,
McAccount *account,
- const gchar *chat_id);
+ const gchar *chat_id,
+ gboolean chatroom);
GList * empathy_log_manager_get_messages_for_date (EmpathyLogManager *manager,
McAccount *account,
const gchar *chat_id,
+ gboolean chatroom,
const gchar *date);
GList * empathy_log_manager_get_last_messages (EmpathyLogManager *manager,
McAccount *account,
- const gchar *chat_id);
+ const gchar *chat_id,
+ gboolean chatroom);
+GList * empathy_log_manager_get_chats (EmpathyLogManager *manager,
+ McAccount *account);
+GList * empathy_log_manager_search_new (EmpathyLogManager *manager,
+ const gchar *text);
+void empathy_log_manager_search_free (GList *hits);
+gchar * empathy_log_manager_get_date_readable (const gchar *date);
G_END_DECLS
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index d63e82551..a2852e1d8 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -790,12 +790,13 @@ tp_chat_emit_message (EmpathyTpChat *chat,
EmpathyTpChatPriv *priv;
GossipMessage *message;
GossipContact *sender;
+ GossipContact *receiver;
priv = GET_PRIV (chat);
+ receiver = empathy_tp_contact_list_get_user (priv->list);
if (from_handle == 0) {
- sender = empathy_tp_contact_list_get_user (priv->list);
- g_object_ref (sender);
+ sender = g_object_ref (receiver);
} else {
sender = empathy_tp_contact_list_get_from_handle (priv->list,
from_handle);
@@ -804,6 +805,7 @@ tp_chat_emit_message (EmpathyTpChat *chat,
message = gossip_message_new (message_body);
gossip_message_set_type (message, type);
gossip_message_set_sender (message, sender);
+ gossip_message_set_receiver (message, receiver);
gossip_message_set_timestamp (message, (GossipTime) timestamp);
g_signal_emit (chat, signals[MESSAGE_RECEIVED], 0, message);
diff --git a/libempathy/empathy-tp-contact-list.c b/libempathy/empathy-tp-contact-list.c
index c81279043..b696e990c 100644
--- a/libempathy/empathy-tp-contact-list.c
+++ b/libempathy/empathy-tp-contact-list.c
@@ -380,8 +380,8 @@ empathy_tp_contact_list_new (McAccount *account)
error ? error->message : "No error given");
g_clear_error (&error);
} else {
- /* FIXME: this adds the handle to the roster */
priv->user_contact = empathy_tp_contact_list_get_from_handle (list, handle);
+ gossip_contact_set_is_user (priv->user_contact, TRUE);
}
return list;
@@ -1276,6 +1276,10 @@ tp_contact_list_name_updated_cb (GossipContact *contact,
priv = GET_PRIV (list);
+ if (!priv->aliasing_iface) {
+ return;
+ }
+
handle = gossip_contact_get_handle (contact);
new_name = gossip_contact_get_name (contact);
diff --git a/libempathy/gossip-contact.c b/libempathy/gossip-contact.c
index 82147f67e..53fe7e182 100644
--- a/libempathy/gossip-contact.c
+++ b/libempathy/gossip-contact.c
@@ -30,7 +30,6 @@
#include "gossip-contact.h"
#include "gossip-utils.h"
#include "gossip-debug.h"
-#include "empathy-contact-manager.h"
#define DEBUG_DOMAIN "Contact"
@@ -47,6 +46,7 @@ struct _GossipContactPriv {
GList *groups;
GossipSubscription subscription;
guint handle;
+ gboolean is_user;
};
static void contact_class_init (GossipContactClass *class);
@@ -70,7 +70,8 @@ enum {
PROP_PRESENCE,
PROP_GROUPS,
PROP_SUBSCRIPTION,
- PROP_HANDLE
+ PROP_HANDLE,
+ PROP_IS_USER
};
static gpointer parent_class = NULL;
@@ -180,6 +181,13 @@ contact_class_init (GossipContactClass *class)
G_MAXUINT,
0,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_IS_USER,
+ g_param_spec_boolean ("is-user",
+ "Contact is-user",
+ "Is contact the user",
+ FALSE,
+ G_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (GossipContactPriv));
}
@@ -187,17 +195,6 @@ contact_class_init (GossipContactClass *class)
static void
contact_init (GossipContact *contact)
{
- GossipContactPriv *priv;
-
- priv = GET_PRIV (contact);
-
- priv->id = NULL;
- priv->name = NULL;
- priv->avatar = NULL;
- priv->account = NULL;
- priv->presence = NULL;
- priv->groups = NULL;
- priv->handle = 0;
}
static void
@@ -269,6 +266,9 @@ contact_get_property (GObject *object,
case PROP_HANDLE:
g_value_set_uint (value, priv->handle);
break;
+ case PROP_IS_USER:
+ g_value_set_boolean (value, priv->is_user);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -318,6 +318,10 @@ contact_set_property (GObject *object,
gossip_contact_set_handle (GOSSIP_CONTACT (object),
g_value_get_uint (value));
break;
+ case PROP_IS_USER:
+ gossip_contact_set_is_user (GOSSIP_CONTACT (object),
+ g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -449,6 +453,18 @@ gossip_contact_get_handle (GossipContact *contact)
return priv->handle;
}
+gboolean
+gossip_contact_is_user (GossipContact *contact)
+{
+ GossipContactPriv *priv;
+
+ g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), FALSE);
+
+ priv = GET_PRIV (contact);
+
+ return priv->is_user;
+}
+
void
gossip_contact_set_id (GossipContact *contact,
const gchar *id)
@@ -630,6 +646,25 @@ gossip_contact_set_handle (GossipContact *contact,
}
void
+gossip_contact_set_is_user (GossipContact *contact,
+ gboolean is_user)
+{
+ GossipContactPriv *priv;
+
+ g_return_if_fail (GOSSIP_IS_CONTACT (contact));
+
+ priv = GET_PRIV (contact);
+
+ if (priv->is_user == is_user) {
+ return;
+ }
+
+ priv->is_user = is_user;
+
+ g_object_notify (G_OBJECT (contact), "is-user");
+}
+
+void
gossip_contact_add_group (GossipContact *contact,
const gchar *group)
{
@@ -722,24 +757,6 @@ gossip_contact_get_status (GossipContact *contact)
return gossip_presence_state_get_default_status (MC_PRESENCE_OFFLINE);
}
-GossipContact *
-gossip_contact_get_user (GossipContact *contact)
-{
- GossipContactPriv *priv;
- EmpathyContactManager *manager;
- GossipContact *user_contact;
-
- g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL);
-
- priv = GET_PRIV (contact);
-
- manager = empathy_contact_manager_new ();
- user_contact = empathy_contact_manager_get_user (manager, priv->account);
- g_object_unref (manager);
-
- return user_contact;
-}
-
gboolean
gossip_contact_equal (gconstpointer v1,
gconstpointer v2)
diff --git a/libempathy/gossip-contact.h b/libempathy/gossip-contact.h
index 23da37538..14b32fdc2 100644
--- a/libempathy/gossip-contact.h
+++ b/libempathy/gossip-contact.h
@@ -69,6 +69,7 @@ GossipPresence * gossip_contact_get_presence (GossipContact
GList * gossip_contact_get_groups (GossipContact *contact);
GossipSubscription gossip_contact_get_subscription (GossipContact *contact);
guint gossip_contact_get_handle (GossipContact *contact);
+gboolean gossip_contact_is_user (GossipContact *contact);
void gossip_contact_set_id (GossipContact *contact,
const gchar *id);
void gossip_contact_set_name (GossipContact *contact,
@@ -85,6 +86,8 @@ void gossip_contact_set_subscription (GossipContact
GossipSubscription subscription);
void gossip_contact_set_handle (GossipContact *contact,
guint handle);
+void gossip_contact_set_is_user (GossipContact *contact,
+ gboolean is_user);
void gossip_contact_add_group (GossipContact *contact,
const gchar *group);
void gossip_contact_remove_group (GossipContact *contact,
@@ -93,7 +96,6 @@ gboolean gossip_contact_is_online (GossipContact
gboolean gossip_contact_is_in_group (GossipContact *contact,
const gchar *group);
const gchar * gossip_contact_get_status (GossipContact *contact);
-GossipContact * gossip_contact_get_user (GossipContact *contact);
gboolean gossip_contact_equal (gconstpointer v1,
gconstpointer v2);
guint gossip_contact_hash (gconstpointer key);
diff --git a/libempathy/gossip-message.c b/libempathy/gossip-message.c
index c4844e655..a46a2a5dc 100644
--- a/libempathy/gossip-message.c
+++ b/libempathy/gossip-message.c
@@ -33,6 +33,7 @@ typedef struct _GossipMessagePriv GossipMessagePriv;
struct _GossipMessagePriv {
GossipMessageType type;
GossipContact *sender;
+ GossipContact *receiver;
gchar *body;
GossipTime timestamp;
@@ -54,6 +55,7 @@ enum {
PROP_0,
PROP_TYPE,
PROP_SENDER,
+ PROP_RECEIVER,
PROP_BODY,
PROP_TIMESTAMP,
};
@@ -114,7 +116,13 @@ gossip_message_class_init (GossipMessageClass *class)
"The sender of the message",
GOSSIP_TYPE_CONTACT,
G_PARAM_READWRITE));
-
+ g_object_class_install_property (object_class,
+ PROP_RECEIVER,
+ g_param_spec_object ("receiver",
+ "Message Receiver",
+ "The receiver of the message",
+ GOSSIP_TYPE_CONTACT,
+ G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_BODY,
g_param_spec_string ("body",
@@ -144,9 +152,6 @@ gossip_message_init (GossipMessage *message)
priv = GET_PRIV (message);
- priv->type = GOSSIP_MESSAGE_TYPE_NORMAL;
- priv->sender = NULL;
- priv->body = NULL;
priv->timestamp = gossip_time_get_current ();
}
@@ -160,6 +165,9 @@ gossip_message_finalize (GObject *object)
if (priv->sender) {
g_object_unref (priv->sender);
}
+ if (priv->receiver) {
+ g_object_unref (priv->receiver);
+ }
g_free (priv->body);
@@ -183,6 +191,9 @@ message_get_property (GObject *object,
case PROP_SENDER:
g_value_set_object (value, priv->sender);
break;
+ case PROP_RECEIVER:
+ g_value_set_object (value, priv->receiver);
+ break;
case PROP_BODY:
g_value_set_string (value, priv->body);
break;
@@ -211,6 +222,10 @@ message_set_property (GObject *object,
gossip_message_set_sender (GOSSIP_MESSAGE (object),
GOSSIP_CONTACT (g_value_get_object (value)));
break;
+ case PROP_RECEIVER:
+ gossip_message_set_receiver (GOSSIP_MESSAGE (object),
+ GOSSIP_CONTACT (g_value_get_object (value)));
+ break;
case PROP_BODY:
gossip_message_set_body (GOSSIP_MESSAGE (object),
g_value_get_string (value));
@@ -290,6 +305,39 @@ gossip_message_set_sender (GossipMessage *message, GossipContact *contact)
g_object_notify (G_OBJECT (message), "sender");
}
+GossipContact *
+gossip_message_get_receiver (GossipMessage *message)
+{
+ GossipMessagePriv *priv;
+
+ g_return_val_if_fail (GOSSIP_IS_MESSAGE (message), NULL);
+
+ priv = GET_PRIV (message);
+
+ return priv->receiver;
+}
+
+void
+gossip_message_set_receiver (GossipMessage *message, GossipContact *contact)
+{
+ GossipMessagePriv *priv;
+ GossipContact *old_receiver;
+
+ g_return_if_fail (GOSSIP_IS_MESSAGE (message));
+ g_return_if_fail (GOSSIP_IS_CONTACT (contact));
+
+ priv = GET_PRIV (message);
+
+ old_receiver = priv->receiver;
+ priv->receiver = g_object_ref (contact);
+
+ if (old_receiver) {
+ g_object_unref (old_receiver);
+ }
+
+ g_object_notify (G_OBJECT (message), "receiver");
+}
+
const gchar *
gossip_message_get_body (GossipMessage *message)
{
diff --git a/libempathy/gossip-message.h b/libempathy/gossip-message.h
index 770ecfe1b..aa4948025 100644
--- a/libempathy/gossip-message.h
+++ b/libempathy/gossip-message.h
@@ -66,6 +66,9 @@ void gossip_message_set_type (GossipMessage *
GossipContact * gossip_message_get_sender (GossipMessage *message);
void gossip_message_set_sender (GossipMessage *message,
GossipContact *contact);
+GossipContact * gossip_message_get_receiver (GossipMessage *message);
+void gossip_message_set_receiver (GossipMessage *message,
+ GossipContact *contact);
const gchar * gossip_message_get_body (GossipMessage *message);
void gossip_message_set_body (GossipMessage *message,
const gchar *body);