Mercurial > pidgin.yaz
changeset 13987:f94309c7c480
[gaim-migrate @ 16559]
Change the log-timestamp and conversation-timestamp signals to pass around a time_t instead of a struct tm. Most of this changeset is Ethan's work.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 24 Jul 2006 05:08:30 +0000 |
parents | 8a8b4f7f7d99 |
children | 4d5cc9e4cb12 |
files | configure.ac doc/gtkconv-signals.dox doc/log-signals.dox plugins/timestamp_format.c src/gtkconv.c src/log.c src/signals.c src/signals.h src/value.h |
diffstat | 9 files changed, 87 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac Mon Jul 24 04:27:42 2006 +0000 +++ b/configure.ac Mon Jul 24 05:08:30 2006 +0000 @@ -60,6 +60,9 @@ dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST AC_STRUCT_TM +AC_CHECK_SIZEOF(time_t, ,[ +#include <stdio.h> +#include <time.h>]) AC_C_BIGENDIAN
--- a/doc/gtkconv-signals.dox Mon Jul 24 04:27:42 2006 +0000 +++ b/doc/gtkconv-signals.dox Mon Jul 24 05:08:30 2006 +0000 @@ -24,12 +24,12 @@ @signaldef conversation-timestamp @signalproto -char *(*conversation_timestamp)(GaimConversation *conv, struct tm *tm); +char *(*conversation_timestamp)(GaimConversation *conv, time_t when); @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. + @param when The time to be converted to a string. @return A textual representation of the time, or @c NULL to use a default format. @endsignaldef
--- a/doc/log-signals.dox Mon Jul 24 04:27:42 2006 +0000 +++ b/doc/log-signals.dox Mon Jul 24 05:08:30 2006 +0000 @@ -8,13 +8,13 @@ @signaldef log-timestamp @signalproto -char *(*log_timestamp)(GaimConversation *conv, struct tm *tm); +char *(*log_timestamp)(GaimConversation *conv, time_t when); @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. + @param when 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.
--- a/plugins/timestamp_format.c Mon Jul 24 04:27:42 2006 +0000 +++ b/plugins/timestamp_format.c Mon Jul 24 05:08:30 2006 +0000 @@ -52,18 +52,18 @@ } static char *timestamp_cb_common(GaimConversation *conv, - const struct tm *tm, + time_t t, gboolean force, const char *dates) { + struct tm *tm = localtime(&t); 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")) || - (time(NULL) > (mktime((struct tm *)tm) + 20*60))) + (time(NULL) > (mktime(tm) + 20*60))) { if (force) return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm)); @@ -78,7 +78,7 @@ } static char *conversation_timestamp_cb(GaimConversation *conv, - const struct tm *tm, gpointer data) + time_t t, gpointer data) { gboolean force = gaim_prefs_get_bool( "/plugins/gtk/timestamp_format/force_24hr"); @@ -86,13 +86,11 @@ "/plugins/gtk/timestamp_format/use_dates/conversation"); g_return_val_if_fail(conv != NULL, NULL); - g_return_val_if_fail(tm != NULL, NULL); - return timestamp_cb_common(conv, tm, force, dates); + return timestamp_cb_common(conv, t, force, dates); } -static char *log_timestamp_cb(GaimLog *log, - const struct tm *tm, gpointer data) +static char *log_timestamp_cb(GaimLog *log, time_t t, gpointer data) { gboolean force = gaim_prefs_get_bool( "/plugins/gtk/timestamp_format/force_24hr"); @@ -100,17 +98,18 @@ "/plugins/gtk/timestamp_format/use_dates/log"); g_return_val_if_fail(log != NULL, NULL); - g_return_val_if_fail(tm != NULL, NULL); if (log->type == GAIM_LOG_SYSTEM) { - if (force) + if (force) { + struct tm *tm = localtime(&t); return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm)); - else + } else { return NULL; + } } - return timestamp_cb_common(log->conv, tm, force, dates); + return timestamp_cb_common(log->conv, t, force, dates); } static gboolean
--- a/src/gtkconv.c Mon Jul 24 04:27:42 2006 +0000 +++ b/src/gtkconv.c Mon Jul 24 05:08:30 2006 +0000 @@ -4691,7 +4691,6 @@ GaimConversationType type; char *displaying; gboolean plugin_return; - struct tm tm; g_return_if_fail(conv != NULL); gtkconv = GAIM_GTK_CONVERSATION(conv); @@ -4776,16 +4775,16 @@ 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), "<BR>", gtk_font_options_all); - tm = *(localtime(&mtime)); mdate = gaim_signal_emit_return_1(gaim_gtk_conversations_get_handle(), "conversation-timestamp", - conv, &tm); + conv, mtime); if (mdate == NULL) { + struct tm *tm = localtime(&mtime); if (time(NULL) > mtime + 20*60) /* show date if older than 20 minutes */ - mdate = g_strdup(gaim_date_format_long(&tm)); + mdate = g_strdup(gaim_date_format_long(tm)); else - mdate = g_strdup(gaim_time_format(&tm)); + mdate = g_strdup(gaim_time_format(tm)); } sml_attrib = g_strdup_printf("sml=\"%s\"", gaim_account_get_protocol_name(account)); @@ -6576,11 +6575,17 @@ "GaimGtkWindow *")); gaim_signal_register(handle, "conversation-timestamp", - gaim_marshal_POINTER__POINTER_POINTER, +#if SIZEOF_TIME_T == 4 + gaim_marshal_POINTER__POINTER_INT, +#elif SIZEOF_TIME_T == 8 + gaim_marshal_POINTER__POINTER_INT64, +#else +# error Unknown size of time_t +#endif gaim_value_new(GAIM_TYPE_POINTER), 2, gaim_value_new(GAIM_TYPE_SUBTYPE, - GAIM_SUBTYPE_CONVERSATION), - gaim_value_new(GAIM_TYPE_POINTER)); + GAIM_SUBTYPE_LOG), + gaim_value_new(GAIM_TYPE_TIME_T)); gaim_signal_register(handle, "displaying-im-msg", gaim_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_POINTER,
--- a/src/log.c Mon Jul 24 04:27:42 2006 +0000 +++ b/src/log.c Mon Jul 24 05:08:30 2006 +0000 @@ -594,12 +594,17 @@ gaim_log_logger_add(old_logger); gaim_signal_register(handle, "log-timestamp", - gaim_marshal_POINTER__POINTER_POINTER, +#if SIZEOF_TIME_T == 4 + gaim_marshal_POINTER__POINTER_INT, +#elif SIZEOF_TIME_T == 8 + gaim_marshal_POINTER__POINTER_INT64, +#else +# error Unknown size of time_t +#endif gaim_value_new(GAIM_TYPE_POINTER), 2, gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_LOG), - gaim_value_new(GAIM_TYPE_BOXED, - "struct tm *")); + gaim_value_new(GAIM_TYPE_TIME_T)); gaim_prefs_connect_callback(NULL, "/core/logging/format", logger_pref_cb, NULL); @@ -623,14 +628,15 @@ static char *log_get_timestamp(GaimLog *log, time_t when) { char *date; - struct tm tm = *(localtime(&when)); + struct tm tm; date = gaim_signal_emit_return_1(gaim_log_get_handle(), "log-timestamp", - log, &tm); + log, when); if (date != NULL) return date; + tm = *(localtime(&when)); if (log->type == GAIM_LOG_SYSTEM || time(NULL) > when + 20*60) return g_strdup(gaim_date_format_long(&tm)); else
--- a/src/signals.c Mon Jul 24 04:27:42 2006 +0000 +++ b/src/signals.c Mon Jul 24 05:08:30 2006 +0000 @@ -955,6 +955,36 @@ } void +gaim_marshal_POINTER__POINTER_INT( + GaimCallback cb, va_list args, void *data, + void **return_val) +{ + gpointer ret_val; + void *arg1 = va_arg(args, void *); + gint arg2 = va_arg(args, gint); + + ret_val = ((gpointer(*)(void *, gint, void *))cb)(arg1, arg2, data); + + if (return_val != NULL) + *return_val = ret_val; +} + +void +gaim_marshal_POINTER__POINTER_INT64( + GaimCallback cb, va_list args, void *data, + void **return_val) +{ + gpointer ret_val; + void *arg1 = va_arg(args, void *); + gint64 arg2 = va_arg(args, gint64); + + ret_val = ((gpointer(*)(void *, gint64, void *))cb)(arg1, arg2, data); + + if (return_val != NULL) + *return_val = ret_val; +} + +void gaim_marshal_POINTER__POINTER_POINTER(GaimCallback cb, va_list args, void *data, void **return_val) {
--- a/src/signals.h Mon Jul 24 04:27:42 2006 +0000 +++ b/src/signals.h Mon Jul 24 05:08:30 2006 +0000 @@ -327,6 +327,10 @@ void gaim_marshal_BOOLEAN__INT_POINTER( GaimCallback cb, va_list args, void *data, void **return_val); +void gaim_marshal_POINTER__POINTER_INT( + GaimCallback cb, va_list args, void *data, void **return_val); +void gaim_marshal_POINTER__POINTER_INT64( + 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); /*@}*/
--- a/src/value.h Mon Jul 24 04:27:42 2006 +0000 +++ b/src/value.h Mon Jul 24 05:08:30 2006 +0000 @@ -26,6 +26,7 @@ #define _GAIM_VALUE_H_ #include <glib.h> +#include "config.h" /** * Specific value types. @@ -53,6 +54,16 @@ } GaimType; +/* time_t is normally either an int or a uint; this is a little ugly + * and probably deserves revisiting. */ +#if SIZEOF_TIME_T == 8 +# define GAIM_TYPE_TIME_T GAIM_TYPE_INT64 +#else +# define GAIM_TYPE_TIME_T GAIM_TYPE_INT +#endif /* sizeof(time_t) == 8 */ + + + /** * Gaim-specific subtype values. */