From: Sean E. <sea...@us...> - 2003-11-18 06:26:05
|
Update of /cvsroot/gaim/gaim/src In directory sc8-pr-cvs1:/tmp/cvs-serv8695/src Modified Files: gtkblist.c log.c log.h Log Message: And good night. Index: gtkblist.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkblist.c,v retrieving revision 1.130 retrieving revision 1.131 diff -u -d -p -r1.130 -r1.131 --- gtkblist.c 11 Nov 2003 20:33:58 -0000 1.130 +++ gtkblist.c 18 Nov 2003 06:26:01 -0000 1.131 @@ -3824,20 +3824,6 @@ static GtkTreeIter sort_method_status(Ga } } -static int get_log_size(char *name) -{ - char *logname = g_strdup_printf("%s.log", gaim_normalize(NULL, name)); - char *filename = g_build_filename(gaim_user_dir(), "logs", logname, NULL); - struct stat st; - - if (stat(filename, &st)) - st.st_size = 0; - - g_free(filename); - g_free(logname); - return st.st_size; -} - static GtkTreeIter sort_method_log(GaimBlistNode *node, GaimBuddyList *blist, GtkTreeIter groupiter, GtkTreeIter *cur) { GtkTreeIter more_z, iter; @@ -3852,7 +3838,7 @@ static GtkTreeIter sort_method_log(GaimB if(GAIM_BLIST_NODE_IS_CONTACT(node)) { for (n = node->child; n; n = n->next) - log_size += get_log_size(((GaimBuddy*)(n))->name); + log_size += gaim_log_get_total_size(((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 @@ -3881,7 +3867,7 @@ static GtkTreeIter sort_method_log(GaimB if(GAIM_BLIST_NODE_IS_CONTACT(n)) { for (n2 = n->child; n2; n2 = n2->next) - this_log_size += get_log_size(((GaimBuddy*)(n2))->name); + this_log_size += gaim_log_get_total_size(((GaimBuddy*)(n2))->name, ((GaimBuddy*)(n2))->account); this_buddy_name = gaim_contact_get_alias((GaimContact*)n); } else { this_buddy_name = NULL; Index: log.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/log.c,v retrieving revision 1.60 retrieving revision 1.61 diff -u -d -p -r1.60 -r1.61 --- log.c 18 Nov 2003 05:45:14 -0000 1.60 +++ log.c 18 Nov 2003 06:26:01 -0000 1.61 @@ -81,6 +81,31 @@ char *gaim_log_read(GaimLog *log, GaimLo } 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 @@ GaimLogLogger *gaim_log_logger_new(void( 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 @@ GaimLogLogger *gaim_log_logger_new(void( logger->finalize = finalize; logger->list = list; logger->read = read; + logger->size = size; return logger; } @@ -269,6 +296,17 @@ static GList *log_lister_common(const ch 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 @@ static GaimLogLogger html_logger = { html_logger_write, html_logger_finalize, html_logger_list, - html_logger_read + html_logger_read, + log_sizer_common }; @@ -637,7 +676,8 @@ static GaimLogLogger txt_logger = { txt_logger_write, txt_logger_finalize, txt_logger_list, - txt_logger_read + txt_logger_read, + log_sizer_common }; /**************** @@ -750,6 +790,12 @@ char * old_logger_read (GaimLog *log, Ga if(strstr(read, "<BR>")) *flags |= GAIM_LOG_READ_NO_NEWLINE; return read; +} + +int old_logger_size (GaimLog *log) +{ + struct old_logger_data *data = log->logger_data; + return data->length; } static GaimLogLogger old_logger = { Index: log.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/log.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -p -r1.7 -r1.8 --- log.h 7 Nov 2003 08:26:34 -0000 1.7 +++ log.h 18 Nov 2003 06:26:01 -0000 1.8 @@ -77,6 +77,10 @@ struct _GaimLogLogger { /** 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 @@ extern "C" { */ 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 @@ extern "C" { * @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 @@ extern "C" { 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 * |