/soc/2015/igor.gajowiak/chatlog: 17b9adaadd7e: Replaced buddy wi...

Igor Gajowiak igor.gajowiak at gmail.com
Tue Aug 11 02:02:41 EDT 2015


Changeset: 17b9adaadd7ebec33a7182586309d8e14158acd1
Author:	 Igor Gajowiak <igor.gajowiak at gmail.com>
Date:	 2015-08-11 08:02 +0200
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/igor.gajowiak/chatlog/rev/17b9adaadd7e

Description:

Replaced buddy with contact in some places. Added exporting chat messages from legacy log.

diffstat:

 libpurple/genericlog.c            |  10 +++---
 libpurple/genericlog.h            |  16 ++++++------
 libpurple/plugins/log/legacylog.c |  49 ++++++++++++++++++++++++++------------
 libpurple/plugins/log/logsqlite.c |  17 ++++++-------
 pidgin/gtkgenericlog.c            |   4 +-
 5 files changed, 56 insertions(+), 40 deletions(-)

diffs (272 lines):

diff --git a/libpurple/genericlog.c b/libpurple/genericlog.c
--- a/libpurple/genericlog.c
+++ b/libpurple/genericlog.c
@@ -311,11 +311,11 @@ purple_genericlog_get_older_msgs(PurpleB
 }
 
 gboolean
-purple_genericlog_get_all_buddies(GList** result, GError** error)
+purple_genericlog_get_all_contacts(GList** result, GError** error)
 {
-	DEFINE_GENERICLOG_FUNC_WITH_RETURN(get_all_buddies,
-		"%s does not support getting buddies",
-		"Getting buddies from %s failed", result);
+	DEFINE_GENERICLOG_FUNC_WITH_RETURN(get_all_contacts,
+		"%s does not support getting contacts",
+		"Getting contacts from %s failed", result);
 }
 
 gboolean
@@ -563,7 +563,7 @@ purple_genericlog_class_init(PurpleGener
 	klass->get_unseen_msgs = NULL;
 	klass->get_all_msgs = NULL;
 	klass->get_older_msgs = NULL;
-	klass->get_all_buddies = NULL;
+	klass->get_all_contacts = NULL;
 	klass->get_all_days = NULL;
 	klass->wipe_log_for_contact = NULL;
 	klass->init_export = NULL;
diff --git a/libpurple/genericlog.h b/libpurple/genericlog.h
--- a/libpurple/genericlog.h
+++ b/libpurple/genericlog.h
@@ -74,11 +74,11 @@ struct _PurpleGenericLog
  *                   then upper bound check is skipped. Messages are sorted
  *                   by their timestamp in descending order.
  *                   Returns %TRUE if operation succeeds, %FALSE otherwise.
- * @get_all_buddies: Gets a list of all #PurpleBlistNode objects with at least
- *                   one message in the log. Returns %TRUE if operation
- *                   succeeds, %FALSE otherwise. The client is responsible for
- *                   freeing the result using
- *                   g_list_free_full(result, g_object_unref).
+ * @get_all_contacts: Gets a list of all #PurpleBlistNode objects with at least
+ *                    one message in the log. Returns %TRUE if operation
+ *                    succeeds, %FALSE otherwise. The client is responsible for
+ *                    freeing the result using
+ *                    g_list_free_full(result, g_object_unref).
  * @get_all_days:    Gets an array of all days with at least one message
  *                   received from or sent to a given contact
  *                   (PurpleChat or PurpleBuddy). The days are sorted
@@ -127,7 +127,7 @@ struct _PurpleGenericLogClass
 	gboolean (*get_older_msgs)(PurpleBlistNode *contact, guint64 timestamp,
 		PurpleMessage *message, GList **result);
 
-	gboolean (*get_all_buddies)(GList **result);
+	gboolean (*get_all_contacts)(GList **result);
 
 	gboolean (*get_all_days)(PurpleBlistNode *contact, GArray **result);
 
@@ -354,7 +354,7 @@ purple_genericlog_get_older_msgs(PurpleB
 	PurpleMessage *message, GList **result, GError **error);
 
 /**
- * purple_genericlog_get_all_buddies:
+ * purple_genericlog_get_all_contacts:
  * @result[out]: Return location for a #GList containing a list of #PurpleBuddy
  *               objects. This will not be set in case of any errors.
  * @error:       Return location for a #GError or %NULL. If provided, this
@@ -369,7 +369,7 @@ purple_genericlog_get_older_msgs(PurpleB
  * Returns: %TRUE if succeeds, %FALSE otherwise.
  */
 gboolean
-purple_genericlog_get_all_buddies(GList **result, GError **error);
+purple_genericlog_get_all_contacts(GList **result, GError **error);
 
 /**
  * purple_genericlog_get_all_days:
diff --git a/libpurple/plugins/log/legacylog.c b/libpurple/plugins/log/legacylog.c
--- a/libpurple/plugins/log/legacylog.c
+++ b/libpurple/plugins/log/legacylog.c
@@ -40,14 +40,15 @@
 static GRegex *msg_regex = NULL;
 static GRegex *date_regex = NULL;
 static GRegex *time_regex = NULL;
+static GRegex *contact_regex = NULL;
 
 typedef enum
 {
-	DIR_DEPTH_PROTOCOL  = 1,
-	DIR_DEPTH_ACCOUNT   = 2,
-	DIR_DEPTH_BUDDYNAME = 3,
-	DIR_DEPTH_LAST      = 3,
-	DIR_DEPTH_MAX       = 4
+	DIR_DEPTH_PROTOCOL    = 1,
+	DIR_DEPTH_ACCOUNT     = 2,
+	DIR_DEPTH_CONTACTNAME = 3,
+	DIR_DEPTH_LAST        = 3,
+	DIR_DEPTH_MAX         = 4
 } DirDepth;
 
 typedef struct _Iter
@@ -368,7 +369,18 @@ get_account(const Iter *iter)
 static PurpleBlistNode *
 get_contact(PurpleAccount *account, const Iter *iter)
 {
-	const gchar *contact_name = iter->dir_names[DIR_DEPTH_BUDDYNAME];
+	GMatchInfo *info;
+
+	gchar *contact_name = NULL;
+
+	/* If dir name matches "xxx.chat" then it is a chat */
+	if (g_regex_match(contact_regex, iter->dir_names[DIR_DEPTH_CONTACTNAME], 0,
+			&info)) {
+		contact_name = g_match_info_fetch(info, 1);
+	}
+	else {
+		contact_name = g_strdup(iter->dir_names[DIR_DEPTH_CONTACTNAME]);
+	}
 
 	PurpleBlistNode *contact = PURPLE_BLIST_NODE(purple_blist_find_buddy(
 		account, contact_name));
@@ -378,29 +390,30 @@ get_contact(PurpleAccount *account, cons
 			account, contact_name));
 	}
 
+	g_match_info_free(info);
+	g_free(contact_name);
+
 	return contact;
 }
 
 static PurpleMessage*
-make_message(PurpleAccount *account, const gchar *contents, const gchar *color,
-	const gchar *msg_time, const Iter *iter)
+make_message(PurpleAccount *account, PurpleBlistNode *contact,
+	const gchar *contents, const gchar *color, const gchar *msg_time,
+	const Iter *iter)
 {
-	PurpleBuddy *buddy = purple_blist_find_buddy(account,
-		iter->dir_names[DIR_DEPTH_BUDDYNAME]);
-	if (!buddy)
-		return NULL;
-
+	g_return_val_if_fail(contact != NULL, NULL);
+	
 	guint64 timestamp;
 	if(!parse_timestamp(iter->log_file_name, msg_time, &timestamp))
 		return NULL;
 
 	PurpleMessage *msg;
 	if (strcmp(color, "#A82F2F") == 0) {
-		msg = purple_message_new_incoming(purple_buddy_get_name(buddy),
+		msg = purple_message_new_incoming(PURPLE_BLIST_NODE_NAME(contact),
 			contents, PURPLE_MESSAGE_RECV, 0);
 	}
 	else {
-		msg = purple_message_new_outgoing(purple_buddy_get_name(buddy),
+		msg = purple_message_new_outgoing(PURPLE_BLIST_NODE_NAME(contact),
 			contents, PURPLE_MESSAGE_SEND);
 	}
 
@@ -448,7 +461,7 @@ fill_arrays(gchar *text, GArray *account
 
 		PurpleAccount *acc = get_account(iter);
 		PurpleBlistNode *contact = get_contact(acc, iter);
-		PurpleMessage *msg = make_message(acc, div_removed, color,
+		PurpleMessage *msg = make_message(acc, contact, div_removed, color,
 			msg_time, iter);
 
 		g_free(div_removed);
@@ -681,6 +694,9 @@ plugin_load(PurplePlugin *plugin, GError
 		0, 0, NULL);
 	g_assert(time_regex);
 
+	contact_regex = g_regex_new("^(.*)\\.chat$", 0, 0, NULL);
+	g_assert(contact_regex);
+
 	return TRUE;
 }
 
@@ -690,6 +706,7 @@ plugin_unload(PurplePlugin *plugin, GErr
 	g_regex_unref(msg_regex);
 	g_regex_unref(date_regex);
 	g_regex_unref(time_regex);
+	g_regex_unref(contact_regex);
 
 	purple_genericlog_unregister(PURPLE_GENERICLOG(legacylog_instance));
 	g_object_unref(legacylog_instance);
diff --git a/libpurple/plugins/log/logsqlite.c b/libpurple/plugins/log/logsqlite.c
--- a/libpurple/plugins/log/logsqlite.c
+++ b/libpurple/plugins/log/logsqlite.c
@@ -395,8 +395,8 @@ sqlitelog_create_tables(sqlite3 *db_hand
 		"AccountId INTEGER NOT NULL, "
 		"FOREIGN KEY(AccountId) REFERENCES Accounts(Id)); "
 
-		/* For fetching buddy ID */
-		"CREATE UNIQUE INDEX BuddiesIndex ON Contacts(AccountId, Name); "
+		/* For fetching contact ID */
+		"CREATE UNIQUE INDEX ContactsIndex ON Contacts(AccountId, Name); "
 
 		"CREATE TABLE Days("
 		"Id INTEGER PRIMARY KEY AUTOINCREMENT, "
@@ -404,7 +404,7 @@ sqlitelog_create_tables(sqlite3 *db_hand
 		"ContactId INTEGER NOT NULL, "
 		"FOREIGN KEY(ContactId) REFERENCES Contacts(Id)); "
 
-		/* For fetching days for a given buddy */
+		/* For fetching days for a given contact */
 		"CREATE UNIQUE INDEX DaysIndex ON Days(ContactId, Time); "
 
 		"CREATE TABLE Messages("
@@ -437,7 +437,7 @@ sqlitelog_create_tables(sqlite3 *db_hand
 		"DELETE FROM Contacts WHERE AccountId = OLD.Id; "
 		"END; "
 
-		"CREATE TRIGGER BuddyDeleted AFTER DELETE ON Contacts "
+		"CREATE TRIGGER ContactDeleted AFTER DELETE ON Contacts "
 		"BEGIN "
 		"DELETE FROM Messages WHERE ContactId = OLD.Id; "
 		"DELETE FROM Days WHERE ContactId = OLD.Id; "
@@ -944,7 +944,7 @@ sqlitelog_mark_as_seen_impl(unsigned msg
 }
 
 static gboolean
-sqlitelog_get_all_buddies_impl(GList **result)
+sqlitelog_get_all_contacts_impl(GList **result)
 {
 	g_assert(result);
 
@@ -1282,7 +1282,7 @@ sqlitelog_get_older_msgs(PurpleBlistNode
 }
 
 static gboolean
-sqlitelog_get_all_buddies(GList **result)
+sqlitelog_get_all_contacts(GList **result)
 {
 	g_return_val_if_fail(result != NULL, FALSE);
 
@@ -1292,10 +1292,9 @@ sqlitelog_get_all_buddies(GList **result
 		return FALSE;
 	}
 
-	return sqlitelog_get_all_buddies_impl(result);
+	return sqlitelog_get_all_contacts_impl(result);
 }
 
-
 static gboolean
 sqlitelog_get_all_days(PurpleBlistNode *contact, GArray **result)
 {
@@ -1371,7 +1370,7 @@ purple_sqlitelog_class_init (PurpleSqlit
 	klass->parent_class.get_unseen_msgs = sqlitelog_get_unseen_msgs;
 	klass->parent_class.get_all_msgs = sqlitelog_get_all_msgs;
 	klass->parent_class.get_older_msgs = sqlitelog_get_older_msgs;
-	klass->parent_class.get_all_buddies = sqlitelog_get_all_buddies;
+	klass->parent_class.get_all_contacts = sqlitelog_get_all_contacts;
 	klass->parent_class.get_all_days = sqlitelog_get_all_days;
 	klass->parent_class.wipe_log_for_contact =
 		sqlitelog_wipe_log_for_contact;
diff --git a/pidgin/gtkgenericlog.c b/pidgin/gtkgenericlog.c
--- a/pidgin/gtkgenericlog.c
+++ b/pidgin/gtkgenericlog.c
@@ -708,9 +708,9 @@ populate_buddylist_store(GtkTreeStore *s
 	gtk_tree_store_clear(store);
 
 	GList *contacts;
-	if (!purple_genericlog_get_all_buddies(&contacts, NULL)) {
+	if (!purple_genericlog_get_all_contacts(&contacts, NULL)) {
 		purple_debug_error(GTKGENERICLOG_DEBUG_CATEGORY,
-			"Getting buddies failed");
+			"Getting contacts failed");
 		return;
 	}
 



More information about the Commits mailing list