diff src/log.c @ 8898:de87e510ff9a

[gaim-migrate @ 9667] This makes the history plugin work in chats and not just conversations. To do this I had to change some functions in log.c to pass around the GaimLogType (GAIM_LOG_IM, GAIM_LOG_CHAT, or GAIM_LOG_SYSTEM). I hope that's not a problem... Here's how I see it: When creating a new GaimLog you need 3 things, the type, your account and the name of the other person/chat. It only makes sense that you would need those same 3 things to find a log. Or to calculate log size. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 07 May 2004 02:30:02 +0000
parents 4aee5a47937d
children db95a6641ec1
line wrap: on
line diff
--- a/src/log.c	Thu May 06 23:56:52 2004 +0000
+++ b/src/log.c	Fri May 07 02:30:02 2004 +0000
@@ -132,7 +132,7 @@
 	g_free(lu);
 }
 
-int gaim_log_get_total_size(const char *name, GaimAccount *account)
+int gaim_log_get_total_size(GaimLogType type, const char *name, GaimAccount *account)
 {
 	int size;
 	GSList *n;
@@ -150,9 +150,9 @@
 			GaimLogLogger *logger = n->data;
 
 			if(logger->total_size){
-				size += (logger->total_size)(name, account);
+				size += (logger->total_size)(type, name, account);
 			} else if(logger->list) {
-				GList *logs = (logger->list)(name, account);
+				GList *logs = (logger->list)(type, name, account);
 				int this_size = 0;
 
 				while (logs) {
@@ -196,12 +196,13 @@
 }
 
 
-GaimLogLogger *gaim_log_logger_new(void(*create)(GaimLog *),
-				   void(*write)(GaimLog *, GaimMessageFlags, const char *,
-						time_t, const char *),
-				   void(*finalize)(GaimLog *), GList*(*list)(const char*, GaimAccount*),
-				   char*(*read)(GaimLog*, GaimLogReadFlags*),
-				   int(*size)(GaimLog*))
+GaimLogLogger *gaim_log_logger_new(
+				void(*create)(GaimLog *),
+				void(*write)(GaimLog *, GaimMessageFlags, const char *, time_t, const char *),
+				void(*finalize)(GaimLog *),
+				GList*(*list)(GaimLogType type, const char*, GaimAccount*),
+				char*(*read)(GaimLog*, GaimLogReadFlags*),
+				int(*size)(GaimLog*))
 {
 	GaimLogLogger *logger = g_new0(GaimLogLogger, 1);
 	logger->create = create;
@@ -268,7 +269,7 @@
 	return b->time - a->time;
 }
 
-GList *gaim_log_get_logs(const char *name, GaimAccount *account)
+GList *gaim_log_get_logs(GaimLogType type, const char *name, GaimAccount *account)
 {
 	GList *logs = NULL;
 	GSList *n;
@@ -276,7 +277,7 @@
 		GaimLogLogger *logger = n->data;
 		if (!logger->list)
 			continue;
-		logs = g_list_concat(logs, logger->list(name, account));
+		logs = g_list_concat(logs, logger->list(type, name, account));
 	}
 
 	return g_list_sort(logs, gaim_log_compare);
@@ -329,31 +330,34 @@
 	FILE *file;
 };
 
-static GList *log_lister_common(const char *screenname, GaimAccount *account, const char *ext, GaimLogLogger *logger)
+static GList *log_lister_common(GaimLogType type, const char *name, GaimAccount *account, const char *ext, GaimLogLogger *logger)
 {
 	GDir *dir;
 	GList *list = NULL;
 	const char *filename;
 	char *me;
-
 	const char *prpl;
 	char *path;
 
 	if(!account)
 		return NULL;
 
-	me = g_strdup(gaim_normalize(account, gaim_account_get_username(account)));
+	if (type == GAIM_LOG_CHAT)
+		me = g_strdup_printf("%s.chat", gaim_normalize(account, gaim_account_get_username(account)));
+	else
+		me = g_strdup(gaim_normalize(account, gaim_account_get_username(account)));
 
 	/* does this seem like a bad way to get this component of the path to anyone else? --Nathan */
 	prpl = GAIM_PLUGIN_PROTOCOL_INFO
 		(gaim_find_prpl(gaim_account_get_protocol_id(account)))->list_icon(account, NULL);
-	path = g_build_filename(gaim_user_dir(), "logs", prpl, me, gaim_normalize(account, screenname), NULL);
+	path = g_build_filename(gaim_user_dir(), "logs", prpl, me, gaim_normalize(account, name), NULL);
 	g_free(me);
 
 	if (!(dir = g_dir_open(path, 0, NULL))) {
 		g_free(path);
 		return NULL;
 	}
+
 	while ((filename = g_dir_read_name(dir))) {
 		if (gaim_str_has_suffix(filename, ext) &&
 				strlen(filename) == 17 + strlen(ext)) {
@@ -361,7 +365,7 @@
 			struct generic_logger_data *data;
 			time_t stamp = gaim_str_to_time(filename, FALSE);
 
-			log = gaim_log_new(GAIM_LOG_IM, screenname, account, stamp);
+			log = gaim_log_new(type, name, account, stamp);
 			log->logger = logger;
 			log->logger_data = data = g_new0(struct generic_logger_data, 1);
 			data->path = g_build_filename(path, filename, NULL);
@@ -415,6 +419,12 @@
 		char *dir;
 		FILE *file;
 
+		if (log->type == GAIM_LOG_CHAT) {
+			char *chat = g_strdup_printf("%s.chat", guy);
+			g_free(guy);
+			guy = chat;
+		}
+
 		strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.xml", localtime(&log->time));
 
 		dir = g_build_filename(ud, "logs",
@@ -467,9 +477,9 @@
 	}
 }
 
-static GList *xml_logger_list(const char *sn, GaimAccount *account)
+static GList *xml_logger_list(GaimLogType type, const char *sn, GaimAccount *account)
 {
-	return log_lister_common(sn, account, ".xml", &xml_logger);
+	return log_lister_common(type, sn, account, ".xml", &xml_logger);
 }
 
 static GaimLogLogger xml_logger =  {
@@ -595,14 +605,14 @@
 	}
 }
 
-static GList *html_logger_list(const char *sn, GaimAccount *account)
+static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account)
 {
-	return log_lister_common(sn, account, ".html", &html_logger);
+	return log_lister_common(type, sn, account, ".html", &html_logger);
 }
 
 static GList *html_logger_list_syslog(GaimAccount *account)
 {
-	return log_lister_common(".system", account, ".html", &html_logger);
+	return log_lister_common(GAIM_LOG_SYSTEM, ".system", account, ".html", &html_logger);
 }
 
 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags)
@@ -688,22 +698,23 @@
 		 * creating a new file there would result in empty files in the case
 		 * that you open a convo with someone, but don't say anything.
 		 *
-		 * The log is also not system log. Because if it is, data would be
-		 * created in txt_logger_create
+		 * The log is also not a system log. Because if it is, data would
+		 * be created in txt_logger_create
 		 */
 		char *ud = gaim_user_dir();
-		char *filename;
 		char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account)));
 		char *chat;
 		const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO
 			(gaim_find_prpl(gaim_account_get_protocol_id(log->account)))->list_icon(log->account, NULL);
 		char *dir;
+		char *filename;
 
 		if (log->type == GAIM_LOG_CHAT) {
 			chat = g_strdup_printf("%s.chat", guy);
 			g_free(guy);
 			guy = chat;
 		}
+
 		strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.txt", localtime(&log->time));
 
 		dir = g_build_filename(ud, "logs",
@@ -781,14 +792,14 @@
 	}
 }
 
-static GList *txt_logger_list(const char *sn, GaimAccount *account)
+static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account)
 {
-	return log_lister_common(sn, account, ".txt", &txt_logger);
+	return log_lister_common(type, sn, account, ".txt", &txt_logger);
 }
 
 static GList *txt_logger_list_syslog(GaimAccount *account)
 {
-	return log_lister_common(".system", account, ".txt", &txt_logger);
+	return log_lister_common(GAIM_LOG_SYSTEM, ".system", account, ".txt", &txt_logger);
 }
 
 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags)
@@ -867,7 +878,7 @@
 	int length;
 };
 
-static GList *old_logger_list(const char *sn, GaimAccount *account)
+static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account)
 {
 	FILE *file;
 	char buf[BUF_LONG];
@@ -993,7 +1004,7 @@
 	return list;
 }
 
-static int old_logger_total_size(const char *name, GaimAccount *account)
+static int old_logger_total_size(GaimLogType type, const char *name, GaimAccount *account)
 {
 	char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, name));
 	char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL);