# HG changeset patch # User Sean Egan # Date 1069136761 0 # Node ID 219903d294016f7cbdbf0cae0c0fb5cbfb5327e9 # Parent 450b25d8d95367e8c7f2e7f27fa3e4306066023b [gaim-migrate @ 8170] And good night. committer: Tailor Script diff -r 450b25d8d953 -r 219903d29401 src/log.c --- 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 (_("The logger has no read function")); } + +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, diff -r 450b25d8d953 -r 219903d29401 src/log.h --- 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 *