pidgin: 8ddc977f: timestamp formats: Allow forcing 12-hour...
darkrain42 at pidgin.im
darkrain42 at pidgin.im
Sat Apr 24 19:10:40 EDT 2010
-----------------------------------------------------------------
Revision: 8ddc977fbfde9ae03ce17528a910e1191061292e
Ancestor: de0f6b7b9429dd7161de925ce6bdb02fbb7daaec
Author: jemaltz at gmail.com
Date: 2010-04-24T23:06:17
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/8ddc977fbfde9ae03ce17528a910e1191061292e
Modified files:
COPYRIGHT ChangeLog pidgin/plugins/timestamp_format.c
ChangeLog:
timestamp formats: Allow forcing 12-hour time formats. Closes #11667.
Patch from Jonathan "jemaltz" Maltz. I modified it a bit and changed
the preference from an int-enum to a string.
-------------- next part --------------
============================================================
--- COPYRIGHT 1958092dbadfc1b730cb92b3cf04d3e139c62997
+++ COPYRIGHT e7dd3d647ad0deb86446404af235e5289bfef2e5
@@ -295,6 +295,7 @@ Willian T. Mahan
Paolo Maggi
Sulabh Mahajan
Willian T. Mahan
+Jonathan Maltz
Tobias Markmann
Kris Marsh
Fidel Martinez
============================================================
--- ChangeLog 68de6b3c01d691d8f2de555c64203fc591dab56a
+++ ChangeLog 75f015e018bc5f9b787d66c0e8b5ce8ed3728673
@@ -47,6 +47,8 @@ version 2.7.0 (??/??/????):
buddy icons.
* The 'Message Timestamp Formats' plugin allows changing the timestamp
format from the timestamps' context menu in conversation log.
+ * The 'Message Timestamp Formats' plugin allows forcing 12-hour
+ timestamps. (Jonathan Maltz)
* Fix pastes from Chrome (rich-text pastes and probably URLs
having garbage appended to them)
============================================================
--- pidgin/plugins/timestamp_format.c 079009d4ec89d3f4a3af8d2a049c5b85158bd027
+++ pidgin/plugins/timestamp_format.c 98e657d8e8a17814a4af51e6b2580ca33e6750dc
@@ -12,6 +12,17 @@
#include <time.h>
+static const char *format_12hour_hour(const struct tm *tm)
+{
+ static char hr[3];
+ int hour = tm->tm_hour % 12;
+ if (hour == 0)
+ hour = 12;
+
+ g_snprintf(hr, sizeof(hr), "%d", hour);
+ return hr;
+}
+
static PurplePluginPrefFrame *
get_plugin_pref_frame(PurplePlugin *plugin)
{
@@ -24,10 +35,14 @@ get_plugin_pref_frame(PurplePlugin *plug
ppref = purple_plugin_pref_new_with_label(_("Timestamp Format Options"));
purple_plugin_pref_frame_add(frame, ppref);
- tmp = g_strdup_printf(_("_Force 24-hour time format"));
+ tmp = g_strdup_printf(_("_Force timestamp format:"));
ppref = purple_plugin_pref_new_with_name_and_label(
- "/plugins/gtk/timestamp_format/force_24hr",
+ "/plugins/gtk/timestamp_format/force",
tmp);
+ purple_plugin_pref_set_type(ppref, PURPLE_PLUGIN_PREF_CHOICE);
+ purple_plugin_pref_add_choice(ppref, _("Use system default"), "default");
+ purple_plugin_pref_add_choice(ppref, _("12 hour time format"), "force12");
+ purple_plugin_pref_add_choice(ppref, _("24 hour time format"), "force24");
purple_plugin_pref_frame_add(frame, ppref);
g_free(tmp);
@@ -58,27 +73,50 @@ static char *timestamp_cb_common(PurpleC
static char *timestamp_cb_common(PurpleConversation *conv,
time_t t,
gboolean show_date,
- gboolean force,
+ const char *force,
const char *dates,
gboolean parens)
{
+ struct tm *tm;
+
g_return_val_if_fail(dates != NULL, NULL);
+ tm = localtime(&t);
+
if (show_date ||
!strcmp(dates, "always") ||
(conv != NULL && purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT && !strcmp(dates, "chats")))
{
- struct tm *tm = localtime(&t);
- if (force)
+ if (g_str_equal(force, "force24"))
return g_strdup_printf("%s%s%s", parens ? "(" : "", purple_utf8_strftime("%Y-%m-%d %H:%M:%S", tm), parens ? ")" : "");
- else
+ else if (g_str_equal(force, "force12")) {
+ char *date = g_strdup_printf("%s", purple_utf8_strftime("%Y-%m-%d ", tm));
+ char *remtime = g_strdup_printf("%s", purple_utf8_strftime(":%M:%S %p", tm));
+ const char *hour = format_12hour_hour(tm);
+ char *output;
+
+ output = g_strdup_printf("%s%s%s%s%s",
+ parens ? "(" : "", date,
+ hour, remtime, parens ? ")" : "");
+
+ g_free(date);
+ g_free(remtime);
+
+ return output;
+ } else
return g_strdup_printf("%s%s%s", parens ? "(" : "", purple_date_format_long(tm), parens ? ")" : "");
}
- if (force)
- {
- struct tm *tm = localtime(&t);
+ if (g_str_equal(force, "force24"))
return g_strdup_printf("%s%s%s", parens ? "(" : "", purple_utf8_strftime("%H:%M:%S", tm), parens ? ")" : "");
+ else if (g_str_equal(force, "force12")) {
+ const char *hour = format_12hour_hour(tm);
+ char *remtime = g_strdup_printf("%s", purple_utf8_strftime(":%M:%S %p", tm));
+ char *output = g_strdup_printf("%s%s%s%s", parens ? "(" : "", hour, remtime, parens ? ")" : "");
+
+ g_free(remtime);
+
+ return output;
}
return NULL;
@@ -87,8 +125,8 @@ static char *conversation_timestamp_cb(P
static char *conversation_timestamp_cb(PurpleConversation *conv,
time_t t, gboolean show_date, gpointer data)
{
- gboolean force = purple_prefs_get_bool(
- "/plugins/gtk/timestamp_format/force_24hr");
+ const char *force = purple_prefs_get_string(
+ "/plugins/gtk/timestamp_format/force");
const char *dates = purple_prefs_get_string(
"/plugins/gtk/timestamp_format/use_dates/conversation");
@@ -99,8 +137,8 @@ static char *log_timestamp_cb(PurpleLog
static char *log_timestamp_cb(PurpleLog *log, time_t t, gboolean show_date, gpointer data)
{
- gboolean force = purple_prefs_get_bool(
- "/plugins/gtk/timestamp_format/force_24hr");
+ const char *force = purple_prefs_get_string(
+ "/plugins/gtk/timestamp_format/force");
const char *dates = purple_prefs_get_string(
"/plugins/gtk/timestamp_format/use_dates/log");
@@ -264,7 +302,17 @@ init_plugin(PurplePlugin *plugin)
purple_prefs_add_none("/plugins/gtk");
purple_prefs_add_none("/plugins/gtk/timestamp_format");
- purple_prefs_add_bool("/plugins/gtk/timestamp_format/force_24hr", TRUE);
+ if (!purple_prefs_exists("/plugins/gtk/timestamp_format/force") &&
+ purple_prefs_exists("/plugins/gtk/timestamp_format/force_24hr"))
+ {
+ if (purple_prefs_get_bool(
+ "/plugins/gtk/timestamp_format/force_24hr"))
+ purple_prefs_add_string("/plugins/gtk/timestamp_format/force", "force24");
+ else
+ purple_prefs_add_string("/plugins/gtk/timestamp_format/force", "force12");
+ }
+ else
+ purple_prefs_add_string("/plugins/gtk/timestamp_format/force", "default");
purple_prefs_add_none("/plugins/gtk/timestamp_format/use_dates");
purple_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/conversation", "automatic");
More information about the Commits
mailing list