changeset 8096:81079e3eda47

[gaim-migrate @ 8795] i tend to agree with javabsp that even though this doesn't affect the O(n^2)-ness of the sort, that its still better than before since reading the whole file over is huge in and of itself committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Tue, 13 Jan 2004 17:16:08 +0000
parents 4396d1088273
children 997afe61914e
files src/log.c src/log.h
diffstat 2 files changed, 53 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/log.c	Tue Jan 13 16:05:38 2004 +0000
+++ b/src/log.c	Tue Jan 13 17:16:08 2004 +0000
@@ -31,6 +31,8 @@
 #include "util.h"
 #include "stringref.h"
 
+static GSList *loggers = NULL;
+
 static GaimLogLogger html_logger;
 static GaimLogLogger txt_logger;
 static GaimLogLogger old_logger;
@@ -45,6 +47,7 @@
 	log->name = g_strdup(name);
 	log->account = account;
 	log->time = time;
+	log->logger_data = NULL;
 	log->logger = gaim_log_logger_get();
 	if (log->logger && log->logger->create)
 		log->logger->create(log);
@@ -88,6 +91,7 @@
 int gaim_log_get_size(GaimLog *log)
 {
 	g_return_val_if_fail(log && log->logger, 0);
+
 	if (log->logger->size)
 		return log->logger->size(log);
 	return 0;
@@ -95,17 +99,29 @@
 
 int gaim_log_get_total_size(const char *name, GaimAccount *account)
 {
-	GList *logs = gaim_log_get_logs(name, account);
 	int size = 0;
+	GSList *n;
 
+	for (n = loggers; n; n = n->next) {
+		GaimLogLogger *logger = n->data;
+
+		if(logger->total_size){
+			size += (logger->total_size)(name, account);
+		} else if(logger->list) {
+			GList *logs = (logger->list)(name, account);
+			int this_size = 0;
 
-	while (logs) {
-		GList *logs2 = logs->next;
-		GaimLog *log = (GaimLog*)(logs->data);
-		size += gaim_log_get_size(log);
-		gaim_log_free(log);
-		g_list_free_1(logs);
-		logs = logs2;
+			while (logs) {
+				GList *logs2 = logs->next;
+				GaimLog *log = (GaimLog*)(logs->data);
+				this_size += gaim_log_get_size(log);
+				gaim_log_free(log);
+				g_list_free_1(logs);
+				logs = logs2;
+			}
+
+			size += this_size;
+		}
 	}
 
 	return size;
@@ -116,7 +132,6 @@
  ****************************************************************************/
 
 static GaimLogLogger *current_logger = NULL;
-static GSList *loggers = NULL;
 
 static void logger_pref_cb(const char *name, GaimPrefType type,
 			   gpointer value, gpointer data)
@@ -412,6 +427,7 @@
 	xml_logger_write,
 	xml_logger_finalize,
 	xml_logger_list,
+	NULL,
 	NULL
 };
 #endif
@@ -553,7 +569,8 @@
 	html_logger_finalize,
 	html_logger_list,
 	html_logger_read,
-	log_sizer_common
+	log_sizer_common,
+	NULL
 };
 
 
@@ -688,7 +705,8 @@
 	txt_logger_finalize,
 	txt_logger_list,
 	txt_logger_read,
-	log_sizer_common
+	log_sizer_common,
+	NULL
 };
 
 /****************
@@ -831,6 +849,24 @@
 	return list;
 }
 
+static int old_logger_total_size(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);
+	int size;
+	struct stat st;
+
+	if (stat(pathstr, &st))
+		size = 0;
+	else
+		size = st.st_size;
+
+	g_free(logfile);
+	g_free(pathstr);
+
+	return size;
+}
+
 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags)
 {
 	struct old_logger_data *data = log->logger_data;
@@ -864,5 +900,6 @@
 	old_logger_finalize,
 	old_logger_list,
 	old_logger_read,
-	old_logger_size
+	old_logger_size,
+	old_logger_total_size
 };
--- a/src/log.h	Tue Jan 13 16:05:38 2004 +0000
+++ b/src/log.h	Tue Jan 13 17:16:08 2004 +0000
@@ -83,6 +83,10 @@
 	/** Given one of the logs returned by the logger's list function,
 	 * this returns the size of the log in bytes */
 	int (*size)(GaimLog *log);
+
+	/** 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);
 };
 
 /**