# HG changeset patch # User Richard Laager # Date 1136492256 0 # Node ID a1e241dd50b6f560b1b106bc4b315573b2b1fa99 # Parent f49d49444c6894bcd9c3ebd8faca82feb87c3165 [gaim-migrate @ 15082] Conversation and Logging Message Timestamp Formatting... The idea here is that we should honor the user's locale for message timestamps in the conversation window and in the logs. I've added a signal and created a plugin that allows one to override this. The plugin is named "Message Timestamp Formats". Enabling that will by default change the timestamps back to the format we had before this commit. (That is to say, it forces the old format and ignores the locale.) The plugin also has options to show dates in the timestamps "Always", "In Chats", or "For Delayed Messages" (the default behavior). This addresses all requests for 12 hour timestamps, allows people to continue with the 24 hour timestamps we have, even if their locale says differently, enables plugin authors to override the message timestamp formats in any way they choose, and addresses requests for complete dates in logs. To recap, if you don't like the format string your locale has, enabled the "Message Timestamp Formats" plugin. committer: Tailor Script diff -r f49d49444c68 -r a1e241dd50b6 doc/Makefile.am --- a/doc/Makefile.am Thu Jan 05 19:50:12 2006 +0000 +++ b/doc/Makefile.am Thu Jan 05 20:17:36 2006 +0000 @@ -20,6 +20,7 @@ gtkconv-signals.dox \ gtkimhtml-signals.dox \ gtkrc-2.0 \ + log-signals.dox \ notify-signals.dox \ plugin-ids.dox \ plugin-signals.dox \ diff -r f49d49444c68 -r a1e241dd50b6 doc/gtkconv-signals.dox --- a/doc/gtkconv-signals.dox Thu Jan 05 19:50:12 2006 +0000 +++ b/doc/gtkconv-signals.dox Thu Jan 05 20:17:36 2006 +0000 @@ -2,6 +2,7 @@ @signals @signal conversation-dragging + @signal conversation-timestamp @signal displaying-im-msg @signal displayed-im-msg @signal displaying-chat-msg @@ -21,6 +22,19 @@ @param destination The window where the conversation will be moved to. @endsignaldef + @signaldef conversation-timestamp + @signalproto +char *(*conversation_timestamp)(GaimConversation *conv, struct tm *tm); + @endsignalproto + @signaldesc + Emitted to allow plugins to customize the timestamp on a message. + @param conv The conversation the message belongs to. + @param tm The time to be converted to a string. + @return A textual representation of the time, or @c NULL to use a + default format. + @endsignaldef + + @signaldef displaying-im-msg @signalproto gboolean (*displaying_im_msg)(GaimAccount *account, GaimConversation *conv, diff -r f49d49444c68 -r a1e241dd50b6 doc/log-signals.dox --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/log-signals.dox Thu Jan 05 20:17:36 2006 +0000 @@ -0,0 +1,24 @@ +/** @page log-signals Log Signals + + @signals + @signal log-timestamp + @endsignals + +
+ + @signaldef log-timestamp + @signalproto +char *(*log_timestamp)(GaimConversation *conv, struct tm *tm); + @endsignalproto + @signaldesc + Emitted to allow plugins to customize the timestamp on a message + being logged. + @param log The log the message belongs to. + @param tm The time to be converted to a string. + @return A textual representation of the time, or @c NULL to use a + default format. + @note Plugins must be careful of logs with a type of GAIM_LOG_SYSTEM. + @endsignaldef + +*/ +// vim: syntax=c tw=75 et diff -r f49d49444c68 -r a1e241dd50b6 plugins/ChangeLog.API --- a/plugins/ChangeLog.API Thu Jan 05 19:50:12 2006 +0000 +++ b/plugins/ChangeLog.API Thu Jan 05 20:17:36 2006 +0000 @@ -217,6 +217,10 @@ * gaim_plugin_pref_get_format_type() * gaim_plugin_pref_set_format_type() * GaimStringFormatType + * gaim_log_get_handle() + * gaim_log_uninit() + * GAIM_SUBTYPE_LOG + * gaim_marshal_POINTER__POINTER_POINTER Signals - Changed: (See the Doxygen docs for details on all signals.) * Signal propagation now stops after a handler returns a non-NULL value. diff -r f49d49444c68 -r a1e241dd50b6 plugins/Makefile.am --- a/plugins/Makefile.am Thu Jan 05 19:50:12 2006 +0000 +++ b/plugins/Makefile.am Thu Jan 05 20:17:36 2006 +0000 @@ -36,46 +36,49 @@ plugindir = $(libdir)/gaim -extplacement_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) -gaimrc_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) -history_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) -iconaway_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) -idle_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) -notify_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) -relnot_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) -spellchk_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) -statenotify_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) -timestamp_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) +extplacement_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) +gaimrc_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) +history_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) +iconaway_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) +idle_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) +notify_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) +relnot_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) +spellchk_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) +statenotify_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) +timestamp_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) +timestamp_format_la_LDFLAGS = -module -avoid-version $(GTK_LIBS) # this can't be in a conditional otherwise automake 1.4 yells -dbus_example_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) $(DBUS_LIBS) +dbus_example_la_LDFLAGS = -module -avoid-version $(GLIB_LIBS) $(DBUS_LIBS) if PLUGINS plugin_LTLIBRARIES = \ - extplacement.la \ - gaimrc.la \ - history.la \ - iconaway.la \ - idle.la \ - notify.la \ - relnot.la \ - spellchk.la \ - statenotify.la \ - timestamp.la \ + extplacement.la \ + gaimrc.la \ + history.la \ + iconaway.la \ + idle.la \ + notify.la \ + relnot.la \ + spellchk.la \ + statenotify.la \ + timestamp.la \ + timestamp_format.la \ $(DBUS_LTLIB) -extplacement_la_SOURCES = extplacement.c -gaimrc_la_SOURCES = gaimrc.c -history_la_SOURCES = history.c -iconaway_la_SOURCES = iconaway.c -idle_la_SOURCES = idle.c -notify_la_SOURCES = notify.c -relnot_la_SOURCES = relnot.c -spellchk_la_SOURCES = spellchk.c -statenotify_la_SOURCES = statenotify.c -timestamp_la_SOURCES = timestamp.c +extplacement_la_SOURCES = extplacement.c +gaimrc_la_SOURCES = gaimrc.c +history_la_SOURCES = history.c +iconaway_la_SOURCES = iconaway.c +idle_la_SOURCES = idle.c +notify_la_SOURCES = notify.c +relnot_la_SOURCES = relnot.c +spellchk_la_SOURCES = spellchk.c +statenotify_la_SOURCES = statenotify.c +timestamp_la_SOURCES = timestamp.c +timestamp_format_la_SOURCES = timestamp_format.c if ENABLE_DBUS diff -r f49d49444c68 -r a1e241dd50b6 plugins/timestamp_format.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/timestamp_format.c Thu Jan 05 20:17:36 2006 +0000 @@ -0,0 +1,184 @@ +#include "internal.h" + +#include "debug.h" +#include "log.h" +#include "plugin.h" +#include "version.h" + +#include "gtkconv.h" +#include "gtkplugin.h" + +static GaimPluginPrefFrame * +get_plugin_pref_frame(GaimPlugin *plugin) +{ + GaimPluginPrefFrame *frame; + GaimPluginPref *ppref; + + frame = gaim_plugin_pref_frame_new(); + + ppref = gaim_plugin_pref_new_with_label(_("Timestamp Format Options")); + gaim_plugin_pref_frame_add(frame, ppref); + + ppref = gaim_plugin_pref_new_with_name_and_label( + "/plugins/gtk/timestamp_format/force_24hr", + _("_Force (traditional Gaim) 24-hour time format")); + gaim_plugin_pref_frame_add(frame, ppref); + + ppref = gaim_plugin_pref_new_with_label(_("Show dates in...")); + gaim_plugin_pref_frame_add(frame, ppref); + + ppref = gaim_plugin_pref_new_with_name_and_label( + "/plugins/gtk/timestamp_format/use_dates/conversation", + _("Co_nversations:")); + gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE); + gaim_plugin_pref_add_choice(ppref, "For Delayed Messages", "automatic"); + gaim_plugin_pref_add_choice(ppref, "In Chats", "chats"); + gaim_plugin_pref_add_choice(ppref, "Always", "always"); + gaim_plugin_pref_frame_add(frame, ppref); + + ppref = gaim_plugin_pref_new_with_name_and_label( + "/plugins/gtk/timestamp_format/use_dates/log", + _("_Logs:")); + gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE); + gaim_plugin_pref_add_choice(ppref, "For Delayed Messages", "automatic"); + gaim_plugin_pref_add_choice(ppref, "In Chats", "chats"); + gaim_plugin_pref_add_choice(ppref, "Always", "always"); + gaim_plugin_pref_frame_add(frame, ppref); + + return frame; +} + +static char *timestamp_cb_common(GaimConversation *conv, + const struct tm *tm, + gboolean force, + const char *dates) +{ + char buf[64]; + + g_return_val_if_fail(conv != NULL, NULL); + g_return_val_if_fail(tm != NULL, NULL); + g_return_val_if_fail(dates != NULL, NULL); + + if (!strcmp(dates, "always") || + (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT && + !strcmp(dates, "chats"))) + { + if (force) + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm); + else + strftime(buf, sizeof(buf), "%x %X", tm); + + return g_strdup(buf); + } + + if (force) + { + strftime(buf, sizeof(buf), "%H:%M:%S", tm); + return g_strdup(buf); + } + + return NULL; +} + +static char *conversation_timestamp_cb(GaimConversation *conv, + const struct tm *tm, gpointer data) +{ + gboolean force = gaim_prefs_get_bool( + "/plugins/gtk/timestamp_format/force_24hr"); + const char *dates = gaim_prefs_get_string( + "/plugins/gtk/timestamp_format/use_dates/conversation"); + return timestamp_cb_common(conv, tm, force, dates); +} + +static char *log_timestamp_cb(GaimLog *log, + const struct tm *tm, gpointer data) +{ + gboolean force = gaim_prefs_get_bool( + "/plugins/gtk/timestamp_format/force_24hr"); + const char *dates = gaim_prefs_get_string( + "/plugins/gtk/timestamp_format/use_dates/log"); + + if (log->type == GAIM_LOG_SYSTEM) + { + if (force) + { + char buf[64]; + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm); + return g_strdup(buf); + } + else + return NULL; + } + + return timestamp_cb_common(log->conv, tm, force, dates); +} + +static gboolean +plugin_load(GaimPlugin *plugin) +{ + gaim_signal_connect(gaim_gtk_conversations_get_handle(), "conversation-timestamp", + plugin, GAIM_CALLBACK(conversation_timestamp_cb), NULL); + gaim_signal_connect(gaim_log_get_handle(), "log-timestamp", + plugin, GAIM_CALLBACK(log_timestamp_cb), NULL); + return TRUE; +} + +static gboolean +plugin_unload(GaimPlugin *plugin) +{ + return TRUE; +} + +static GaimPluginUiInfo prefs_info = { + get_plugin_pref_frame, + 0, /* page num (Reserved) */ + NULL /* frame (Reserved) */ +}; + +static GaimPluginInfo info = +{ + GAIM_PLUGIN_MAGIC, + GAIM_MAJOR_VERSION, + GAIM_MINOR_VERSION, + GAIM_PLUGIN_STANDARD, /**< type */ + GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ + 0, /**< flags */ + NULL, /**< dependencies */ + GAIM_PRIORITY_DEFAULT, /**< priority */ + + NULL, /**< id */ + N_("Message Timestamp Formats"), /**< name */ + VERSION, /**< version */ + /** summary */ + N_("Customizes the message timestamp formats."), + /** description */ + N_("This plugin allows the user to customize " + "conversation and logging message timestamp " + "formats."), + "Richard Laager ", /**< author */ + GAIM_WEBSITE, /**< homepage */ + + plugin_load, /**< load */ + plugin_unload, /**< unload */ + NULL, /**< destroy */ + + NULL, /**< ui_info */ + NULL, /**< extra_info */ + &prefs_info, /**< prefs_info */ + NULL /**< actions */ +}; + +static void +init_plugin(GaimPlugin *plugin) +{ + gaim_prefs_add_none("/plugins/gtk"); + gaim_prefs_add_none("/plugins/gtk/timestamp_format"); + + gaim_prefs_add_bool("/plugins/gtk/timestamp_format/force_24hr", TRUE); + + gaim_prefs_add_none("/plugins/gtk/timestamp_format/use_dates"); + gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/conversation", "automatic"); + gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/log", "automatic"); +} + +GAIM_INIT_PLUGIN(timestamp_format, init_plugin, info) diff -r f49d49444c68 -r a1e241dd50b6 src/gtkconv.c --- a/src/gtkconv.c Thu Jan 05 19:50:12 2006 +0000 +++ b/src/gtkconv.c Thu Jan 05 20:17:36 2006 +0000 @@ -4453,7 +4453,7 @@ "/gaim/gtk/conversations/scrollback_lines"); int line_count; char buf2[BUF_LONG]; - char mdate[64]; + char *mdate; char color[10]; char *str; char *with_font_tag; @@ -4462,6 +4462,7 @@ GaimConversationType type; char *displaying; gboolean plugin_return; + struct tm tm = *(localtime(&mtime)); gtkconv = GAIM_GTK_CONVERSATION(conv); @@ -4513,10 +4514,20 @@ if (gtk_text_buffer_get_char_count(gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml)))) gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "
", gtk_font_options_all); - if(time(NULL) > mtime + 20*60) /* show date if older than 20 minutes */ - strftime(mdate, sizeof(mdate), "%Y-%m-%d %H:%M:%S", localtime(&mtime)); - else - strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); + mdate = gaim_signal_emit_return_1(gaim_gtk_conversations_get_handle(), + "conversation-timestamp", + conv, &tm); + if (mdate == NULL) + { + char buf[64]; + + if (time(NULL) > mtime + 20*60) /* show date if older than 20 minutes */ + strftime(buf, sizeof(buf), "%x %X", &tm); + else + strftime(buf, sizeof(buf), "%X", &tm); + + mdate = g_strdup(buf); + } if(gc) sml_attrib = g_strdup_printf("sml=\"%s\"", @@ -4733,8 +4744,8 @@ g_free(new_message); } - if(sml_attrib) - g_free(sml_attrib); + g_free(mdate); + g_free(sml_attrib); gaim_signal_emit(gaim_gtk_conversations_get_handle(), (type == GAIM_CONV_TYPE_IM ? "displayed-im-msg" : "displayed-chat-msg"), @@ -6178,6 +6189,13 @@ gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_CONV_WINDOW)); + gaim_signal_register(handle, "conversation-timestamp", + gaim_marshal_POINTER__POINTER_POINTER, + gaim_value_new(GAIM_TYPE_POINTER), 2, + gaim_value_new(GAIM_TYPE_SUBTYPE, + GAIM_SUBTYPE_CONVERSATION), + gaim_value_new(GAIM_TYPE_POINTER)); + gaim_signal_register(handle, "displaying-im-msg", gaim_marshal_BOOLEAN__POINTER_POINTER_POINTER_UINT, gaim_value_new(GAIM_TYPE_BOOLEAN), 4, diff -r f49d49444c68 -r a1e241dd50b6 src/gtkprefs.c --- a/src/gtkprefs.c Thu Jan 05 19:50:12 2006 +0000 +++ b/src/gtkprefs.c Thu Jan 05 20:17:36 2006 +0000 @@ -1296,9 +1296,6 @@ gaim_gtk_prefs_checkbox(_("Log all _status changes to system log"), "/core/logging/log_system", vbox); - gaim_gtk_prefs_checkbox(_("Include _date in timestamps"), - "/core/logging/include_date_timestamps", vbox); - gtk_widget_show_all(ret); return ret; diff -r f49d49444c68 -r a1e241dd50b6 src/log.c --- a/src/log.c Thu Jan 05 19:50:12 2006 +0000 +++ b/src/log.c Thu Jan 05 20:17:36 2006 +0000 @@ -485,15 +485,28 @@ return g_list_sort(logs, gaim_log_compare); } +/**************************************************************************** + * LOG SUBSYSTEM ************************************************************ + ****************************************************************************/ + +void * +gaim_log_get_handle(void) +{ + static int handle; + + return &handle; +} + void gaim_log_init(void) { + void *handle = gaim_log_get_handle(); + gaim_prefs_add_none("/core/logging"); gaim_prefs_add_bool("/core/logging/log_ims", FALSE); gaim_prefs_add_bool("/core/logging/log_chats", FALSE); gaim_prefs_add_bool("/core/logging/log_system", FALSE); gaim_prefs_add_string("/core/logging/format", "txt"); - gaim_prefs_add_bool("/core/logging/include_date_timestamps", FALSE); html_logger = gaim_log_logger_new("html", _("HTML"), 8, NULL, @@ -529,6 +542,13 @@ old_logger_get_log_sets); gaim_log_logger_add(old_logger); + gaim_signal_register(handle, "log-timestamp", + gaim_marshal_POINTER__POINTER_POINTER, + gaim_value_new(GAIM_TYPE_POINTER), 2, + gaim_value_new(GAIM_TYPE_SUBTYPE, + GAIM_SUBTYPE_LOG), + gaim_value_new(GAIM_TYPE_POINTER)); + gaim_prefs_connect_callback(NULL, "/core/logging/format", logger_pref_cb, NULL); gaim_prefs_trigger_callback("/core/logging/format"); @@ -538,10 +558,39 @@ (GDestroyNotify)_gaim_logsize_user_free_key, NULL); } +void +gaim_log_uninit(void) +{ + gaim_signals_unregister_by_instance(gaim_log_get_handle()); +} + /**************************************************************************** * LOGGERS ****************************************************************** ****************************************************************************/ +static char *log_get_timestamp(GaimLog *log, time_t when) +{ + char *date; + struct tm tm = *(localtime(&when)); + + date = gaim_signal_emit_return_1(gaim_log_get_handle(), + "log-timestamp", + log, &tm); + if (date == NULL) + { + char buf[64]; + + if (log->type == GAIM_LOG_SYSTEM || time(NULL) > when + 20*60) + strftime(buf, sizeof(buf), "%x %X", &tm); + else + strftime(buf, sizeof(buf), "%X", &tm); + + date = g_strdup(buf); + } + + return date; +} + void gaim_log_common_writer(GaimLog *log, const char *ext) { char date[64]; @@ -764,7 +813,7 @@ GaimMessageFlags type, const char *from, time_t time, const char *message) { - char date[64]; + char *date; char *xhtml = NULL; if (!log->logger_data) { @@ -772,17 +821,18 @@ * 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. */ + char buf[64]; char *dir = gaim_log_get_log_dir(log->type, log->name, log->account); FILE *file; if (dir == NULL) return; - strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.xml", localtime(&log->time)); + strftime(buf, sizeof(buf), "%Y-%m-%d.%H%M%S.xml", localtime(&log->time)); gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); - char *filename = g_build_filename(dir, date, NULL); + char *filename = g_build_filename(dir, buf, NULL); g_free(dir); log->logger_data = g_fopen(filename, "a"); @@ -795,7 +845,7 @@ fprintf(log->logger_data, "\n" "\n"); - strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); fprintf(log->logger_data, "\n", date, log->name, prpl); } @@ -804,10 +854,7 @@ if(!data->file) return; - if (gaim_prefs_get_bool("/core/logging/include_date_timestamps")) - strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time)); - else - strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); + date = log_get_timestamp(log, time); gaim_markup_html_to_xhtml(message, &xhtml, NULL); if (from) @@ -823,6 +870,7 @@ type & GAIM_MESSAGE_RECV ? "direction='received'" : "", date, xhtml): fflush(log->logger_data); + g_free(date); g_free(xhtml); } @@ -860,11 +908,12 @@ const char *from, time_t time, const char *message) { char *msg_fixed; - char date[64]; + char *date; GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); GaimLogCommonLoggerData *data = log->logger_data; if(!data) { + char buf[64]; const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); gaim_log_common_writer(log, ".html"); @@ -875,17 +924,16 @@ if(!data->file) return; - strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); + strftime(buf, sizeof(buf), "%c", localtime(&log->time)); fprintf(data->file, ""); fprintf(data->file, ""); fprintf(data->file, ""); fprintf(data->file, "Conversation with %s at %s on %s (%s)", - log->name, date, gaim_account_get_username(log->account), prpl); + log->name, buf, gaim_account_get_username(log->account), prpl); fprintf(data->file, ""); fprintf(data->file, "

Conversation with %s at %s on %s (%s)

\n", log->name, date, gaim_account_get_username(log->account), prpl); - } /* if we can't write to the file, give up before we hurt ourselves */ @@ -893,16 +941,11 @@ return; gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); + date = log_get_timestamp(log, time); if(log->type == GAIM_LOG_SYSTEM){ - strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time)); fprintf(data->file, "---- %s @ %s ----
\n", msg_fixed, date); } else { - if (gaim_prefs_get_bool("/core/logging/include_date_timestamps")) - strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time)); - else - strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); - if (type & GAIM_MESSAGE_SYSTEM) fprintf(data->file, "(%s) %s
\n", date, msg_fixed); else if (type & GAIM_MESSAGE_WHISPER) @@ -929,7 +972,7 @@ date, from, msg_fixed); } } - + g_free(date); g_free(msg_fixed); fflush(data->file); } @@ -986,7 +1029,7 @@ GaimMessageFlags type, const char *from, time_t time, const char *message) { - char date[64]; + char *date; GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); GaimLogCommonLoggerData *data = log->logger_data; char *stripped = NULL; @@ -996,6 +1039,7 @@ * 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. */ + char buf[64]; const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); gaim_log_common_writer(log, ".txt"); @@ -1006,54 +1050,49 @@ if(!data->file) return; - strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); + strftime(buf, sizeof(buf), "%c", localtime(&log->time)); fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", - log->name, date, gaim_account_get_username(log->account), prpl); + log->name, buf, gaim_account_get_username(log->account), prpl); } /* if we can't write to the file, give up before we hurt ourselves */ if(!data->file) return; - stripped = gaim_markup_strip_html(message); - - if(log->type == GAIM_LOG_SYSTEM){ - strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time)); - fprintf(data->file, "---- %s @ %s ----\n", stripped, date); - } else { - if (gaim_prefs_get_bool("/core/logging/include_date_timestamps")) - strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time)); - else - strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); + stripped = gaim_markup_strip_html(message); + date = log_get_timestamp(log, time); - if (type & GAIM_MESSAGE_SEND || - type & GAIM_MESSAGE_RECV) { - if (type & GAIM_MESSAGE_AUTO_RESP) { - fprintf(data->file, _("(%s) %s : %s\n"), date, - from, stripped); - } else { - if(gaim_message_meify(stripped, -1)) - fprintf(data->file, "(%s) ***%s %s\n", date, from, - stripped); - else - fprintf(data->file, "(%s) %s: %s\n", date, from, - stripped); - } - } else if (type & GAIM_MESSAGE_SYSTEM) - fprintf(data->file, "(%s) %s\n", date, stripped); - else if (type & GAIM_MESSAGE_NO_LOG) { - /* This shouldn't happen */ - g_free(stripped); - return; - } else if (type & GAIM_MESSAGE_WHISPER) - fprintf(data->file, "(%s) *%s* %s", date, from, stripped); - else - fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "", - from ? ":" : "", stripped); - } - - fflush(data->file); - g_free(stripped); + if(log->type == GAIM_LOG_SYSTEM){ + fprintf(data->file, "---- %s @ %s ----\n", stripped, date); + } else { + if (type & GAIM_MESSAGE_SEND || + type & GAIM_MESSAGE_RECV) { + if (type & GAIM_MESSAGE_AUTO_RESP) { + fprintf(data->file, _("(%s) %s : %s\n"), date, + from, stripped); + } else { + if(gaim_message_meify(stripped, -1)) + fprintf(data->file, "(%s) ***%s %s\n", date, from, + stripped); + else + fprintf(data->file, "(%s) %s: %s\n", date, from, + stripped); + } + } else if (type & GAIM_MESSAGE_SYSTEM) + fprintf(data->file, "(%s) %s\n", date, stripped); + else if (type & GAIM_MESSAGE_NO_LOG) { + /* This shouldn't happen */ + g_free(stripped); + return; + } else if (type & GAIM_MESSAGE_WHISPER) + fprintf(data->file, "(%s) *%s* %s", date, from, stripped); + else + fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "", + from ? ":" : "", stripped); + } + g_free(date); + g_free(stripped); + fflush(data->file); } static void txt_logger_finalize(GaimLog *log) diff -r f49d49444c68 -r a1e241dd50b6 src/log.h --- a/src/log.h Thu Jan 05 19:50:12 2006 +0000 +++ b/src/log.h Thu Jan 05 20:17:36 2006 +0000 @@ -423,10 +423,28 @@ */ GList *gaim_log_logger_get_options(void); +/**************************************************************************/ +/** @name Conversations Subsystem */ +/**************************************************************************/ +/*@{*/ + /** * Initializes the log subsystem. */ void gaim_log_init(void); + +/** + * Returns the log subsystem handle. + * + * @return The log subsystem handle. + */ +void *gaim_log_get_handle(void); + +/** + * Uninitializes the log subsystem. + */ +void gaim_log_uninit(void); + /*@}*/ diff -r f49d49444c68 -r a1e241dd50b6 src/signals.c --- a/src/signals.c Thu Jan 05 19:50:12 2006 +0000 +++ b/src/signals.c Thu Jan 05 20:17:36 2006 +0000 @@ -945,3 +945,17 @@ if (return_val != NULL) *return_val = GINT_TO_POINTER(ret_val); } + +void +gaim_marshal_POINTER__POINTER_POINTER(GaimCallback cb, va_list args, void *data, + void **return_val) +{ + gpointer ret_val; + void *arg1 = va_arg(args, void *); + void *arg2 = va_arg(args, void *); + + ret_val = ((gpointer (*)(void *, void *, void *))cb)(arg1, arg2, data); + + if (return_val != NULL) + *return_val = ret_val; +} diff -r f49d49444c68 -r a1e241dd50b6 src/signals.h --- a/src/signals.h Thu Jan 05 19:50:12 2006 +0000 +++ b/src/signals.h Thu Jan 05 20:17:36 2006 +0000 @@ -327,6 +327,8 @@ void gaim_marshal_BOOLEAN__INT_POINTER( GaimCallback cb, va_list args, void *data, void **return_val); +void gaim_marshal_POINTER__POINTER_POINTER( + GaimCallback cb, va_list args, void *data, void **return_val); /*@}*/ #ifdef __cplusplus diff -r f49d49444c68 -r a1e241dd50b6 src/value.h --- a/src/value.h Thu Jan 05 19:50:12 2006 +0000 +++ b/src/value.h Thu Jan 05 20:17:36 2006 +0000 @@ -71,8 +71,8 @@ GAIM_SUBTYPE_PLUGIN, GAIM_SUBTYPE_BLIST_NODE, GAIM_SUBTYPE_CIPHER, - GAIM_SUBTYPE_STATUS - + GAIM_SUBTYPE_STATUS, + GAIM_SUBTYPE_LOG } GaimSubType; /**