changeset 7556:219903d29401

[gaim-migrate @ 8170] And good night. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Tue, 18 Nov 2003 06:26:01 +0000
parents 450b25d8d953
children 859ebaacc37b
files src/log.c src/log.h
diffstat 2 files changed, 71 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/log.c	Tue Nov 18 05:45:14 2003 +0000
+++ b/src/log.c	Tue Nov 18 06:26:01 2003 +0000
@@ -81,6 +81,31 @@
 	}
 	return (_("<b><font color=\"red\">The logger has no read function</font></b>"));
 }
+	
+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;
+}
+
+int gaim_log_get_total_size(const char *name, GaimAccount *account)
+{
+	GList *logs = gaim_log_get_logs(name, account);
+	int size = 0;
+	
+	while (logs) {
+		GList *logs2 = logs->next;
+		GaimLog *log = (GaimLog*)(logs->data);
+		size += gaim_log_get_size(log);
+		g_free(log->name);
+		g_free(log);
+		g_list_free_1(logs);
+		logs = logs2;
+	}
+	return size;
+}
 
 /****************************************************************************
  * LOGGER FUNCTIONS *********************************************************
@@ -110,7 +135,8 @@
 				   void(*write)(GaimLog *, GaimMessageFlags, const char *,
 						time_t, const char *),
 				   void(*finalize)(GaimLog *), GList*(*list)(const char*, GaimAccount*),
-				   char*(*read)(GaimLog*, GaimLogReadFlags*))
+				   char*(*read)(GaimLog*, GaimLogReadFlags*),
+				   int(*size)(GaimLog*))
 {
 	GaimLogLogger *logger = g_new0(GaimLogLogger, 1);
 	logger->create = create;
@@ -118,6 +144,7 @@
 	logger->finalize = finalize;
 	logger->list = list;
 	logger->read = read;
+	logger->size = size;
 	return logger;
 }
 
@@ -269,6 +296,17 @@
 	return list;
 }
 
+/* Only to be used with logs listed from log_lister_common */
+int log_sizer_common(GaimLog *log) 
+{
+	struct stat st;
+
+	if (stat((char*)(log->logger_data), &st))
+		st.st_size = 0;
+
+	return st.st_size;
+}
+
 #if 0 /* Maybe some other time. */
 /****************
  ** XML LOGGER **
@@ -506,7 +544,8 @@
 	html_logger_write,
 	html_logger_finalize,
 	html_logger_list,
-	html_logger_read
+	html_logger_read,
+	log_sizer_common
 };
 
 
@@ -637,7 +676,8 @@
 	txt_logger_write,
 	txt_logger_finalize,
 	txt_logger_list,
-	txt_logger_read
+	txt_logger_read,
+	log_sizer_common
 };
 
 /****************
@@ -752,6 +792,12 @@
 	return read;
 }
 
+int old_logger_size (GaimLog *log)
+{
+	struct old_logger_data *data = log->logger_data;
+	return data->length;
+}
+
 static GaimLogLogger old_logger = {
 	"old logger", "old",
 	NULL, NULL, NULL,
--- a/src/log.h	Tue Nov 18 05:45:14 2003 +0000
+++ b/src/log.h	Tue Nov 18 06:26:01 2003 +0000
@@ -77,6 +77,10 @@
 	/** Given one of the logs returned by the logger's list function,
 	 * this returns the contents of the log in GtkIMHtml markup */
 	char *(*read)(GaimLog *log, GaimLogReadFlags *flags);
+	
+	/** 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);
 };
 
 /**
@@ -158,7 +162,22 @@
 	 */
 	GList *gaim_log_get_logs(const char *name, GaimAccount *account);
 
+	/**
+	 * Returns the size of a log 
+	 *
+	 * @param log                 The log
+	 * @return                    The size of the log, in bytes
+	 */
+	int gaim_log_get_size(GaimLog *log);
 
+	/**
+	 * Returns the size, in bytes, of all available logs in this conversation
+	 *
+	 * @param name                The name of the log
+	 * @param account             The account
+	 * @return                    The size in bytes
+	 */
+	 int gaim_log_get_total_log_size(const char *name, GaimAccount *account);
 	/******************************************
 	 ** LOGGER FUNCTIONS **********************
 	 ******************************************/
@@ -171,6 +190,7 @@
 	 * @param finalize The logger's finalize function.
 	 * @param list     The logger's list function.
 	 * @param read     The logger's read function.
+	 * @param size     The logger's size function.
 	 *
 	 * @return The new logger
 	 */
@@ -179,7 +199,8 @@
 							const char *, time_t, const char *),
 					   void(*finalize)(GaimLog *),
 					   GList*(*list)(const char*, GaimAccount*),
-					   char*(*read)(GaimLog*, GaimLogReadFlags*));
+					   char*(*read)(GaimLog*, GaimLogReadFlags*),
+					   int(*size)(GaimLog*));
 	/**
 	 * Frees a logger
 	 *