changeset 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 8ffd1679df93
children d484f23cd92b
files plugins/history.c src/gtkblist.c src/gtklog.c src/log.c src/log.h
diffstat 5 files changed, 67 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/history.c	Thu May 06 23:56:52 2004 +0000
+++ b/plugins/history.c	Fri May 07 02:30:02 2004 +0000
@@ -21,14 +21,23 @@
 static void historize(GaimConversation *c)
 {
 	GaimGtkConversation *gtkconv;
+	GaimConversationType convtype;
 	char *history = NULL;
 	guint flags;
 	GtkIMHtmlOptions options = GTK_IMHTML_NO_COLOURS;
-	GList *logs = gaim_log_get_logs(gaim_conversation_get_name(c),
-			gaim_conversation_get_account(c));
+	GList *logs = NULL;
+
+	convtype = gaim_conversation_get_type(c);
+	if (convtype == GAIM_CONV_IM)
+		logs = gaim_log_get_logs(GAIM_LOG_IM,
+				gaim_conversation_get_name(c), gaim_conversation_get_account(c));
+	else if (convtype == GAIM_CONV_CHAT)
+		logs = gaim_log_get_logs(GAIM_LOG_CHAT,
+				gaim_conversation_get_name(c), gaim_conversation_get_account(c));
 
 	if (!logs)
 		return;
+
 	history = gaim_log_read((GaimLog*)logs->data, &flags);
 	gtkconv = GAIM_GTK_CONVERSATION(c);
 	if (flags & GAIM_LOG_READ_NO_NEWLINE)
@@ -37,6 +46,7 @@
 	gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<hr>", options);
 	gtk_imhtml_scroll_to_end(GTK_IMHTML(gtkconv->imhtml));
 	g_free(history);
+
 	while (logs) {
 		GaimLog *log = logs->data;
 		GList *logs2;
@@ -45,7 +55,6 @@
 		g_list_free_1(logs);
 		logs = logs2;
 	}
-	
 }
 
 static gboolean
--- a/src/gtkblist.c	Thu May 06 23:56:52 2004 +0000
+++ b/src/gtkblist.c	Fri May 07 02:30:02 2004 +0000
@@ -4775,7 +4775,7 @@
 
 	if(GAIM_BLIST_NODE_IS_CONTACT(node)) {
 		for (n = node->child; n; n = n->next)
-			log_size += gaim_log_get_total_size(((GaimBuddy*)(n))->name, ((GaimBuddy*)(n))->account);
+			log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy*)(n))->name, ((GaimBuddy*)(n))->account);
 		buddy_name = gaim_contact_get_alias((GaimContact*)node);
 	} else if(GAIM_BLIST_NODE_IS_CHAT(node)) {
 		/* we don't have a reliable way of getting the log filename
@@ -4804,7 +4804,7 @@
 
 		if(GAIM_BLIST_NODE_IS_CONTACT(n)) {
 			for (n2 = n->child; n2; n2 = n2->next)
-				this_log_size += gaim_log_get_total_size(((GaimBuddy*)(n2))->name, ((GaimBuddy*)(n2))->account);
+				this_log_size += gaim_log_get_total_size(GAIM_LOG_IM, ((GaimBuddy*)(n2))->name, ((GaimBuddy*)(n2))->account);
 			this_buddy_name = gaim_contact_get_alias((GaimContact*)n);
 		} else {
 			this_buddy_name = NULL;
--- a/src/gtklog.c	Thu May 06 23:56:52 2004 +0000
+++ b/src/gtklog.c	Fri May 07 02:30:02 2004 +0000
@@ -252,7 +252,7 @@
 	}
 
 	lv = g_new0(GaimGtkLogViewer, 1);
-	lv->logs = logs = gaim_log_get_logs(screenname, account);
+	lv->logs = logs = gaim_log_get_logs(GAIM_LOG_IM, screenname, account);
 	g_hash_table_insert(log_viewers, ht, lv);
 
 	/* Window ***********/
--- 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);
--- a/src/log.h	Thu May 06 23:56:52 2004 +0000
+++ b/src/log.h	Fri May 07 02:30:02 2004 +0000
@@ -74,7 +74,7 @@
 	void (*finalize)(GaimLog *log);
 
 	/** This function returns a sorted GList of available GaimLogs */
-	GList *(*list)(const char *name, GaimAccount *account);
+	GList *(*list)(GaimLogType type, const char *name, GaimAccount *account);
 
 	/** Given one of the logs returned by the logger's list function,
 	 * this returns the contents of the log in GtkIMHtml markup */
@@ -86,7 +86,7 @@
 
 	/** Returns the total size of all the logs. If this is undefined a default
 	 * implementation is used */
-	int (*total_size)(const char *name, GaimAccount *account);
+	int (*total_size)(GaimLogType type, const char *name, GaimAccount *account);
 
 	/** This function returns a sorted GList of available system GaimLogs */
 	GList *(*list_syslog)(GaimAccount *account);
@@ -165,11 +165,12 @@
 	/**
 	 * Returns a list of all available logs
 	 *
+	 * @param type                The type of the log
 	 * @param name                The name of the log
 	 * @param account             The account
 	 * @return                    A sorted list of GaimLogs
 	 */
-	GList *gaim_log_get_logs(const char *name, GaimAccount *account);
+	GList *gaim_log_get_logs(GaimLogType type, const char *name, GaimAccount *account);
 
 	/**
 	 * Returns a list of all available system logs
@@ -194,7 +195,7 @@
 	 * @param account             The account
 	 * @return                    The size in bytes
 	 */
-	 int gaim_log_get_total_size(const char *name, GaimAccount *account);
+	 int gaim_log_get_total_size(GaimLogType type, const char *name, GaimAccount *account);
 
 	/**
 	 * Implements GCompareFunc
@@ -221,13 +222,13 @@
 	 *
 	 * @return The new logger
 	 */
-	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*));
 	/**
 	 * Frees a logger
 	 *