comparison pidgin/plugins/timestamp_format.c @ 15519:b15cc37605c4

In Pidgin, display a full date on the timestamp of the first message to cross the boundary into a new day. Sean and various users want this. I think I'm finally going to admit it's a decent idea. I've also refactored plenty of code related to the conversation-timestamp and log-timestamp signals. This breaks API compatibility, but I'm pretty sure the only plugin that uses those signals is the Message Timestamps plugin that we ship. The changes eliminate duplicated code between the core/UI and the plugin.
author Richard Laager <rlaager@wiktel.com>
date Sat, 03 Feb 2007 20:28:41 +0000
parents d75099d2567e
children 45d3dd67fa13
comparison
equal deleted inserted replaced
15515:75ffc646647f 15519:b15cc37605c4
51 return frame; 51 return frame;
52 } 52 }
53 53
54 static char *timestamp_cb_common(GaimConversation *conv, 54 static char *timestamp_cb_common(GaimConversation *conv,
55 time_t t, 55 time_t t,
56 gboolean show_date,
56 gboolean force, 57 gboolean force,
57 const char *dates) 58 const char *dates)
58 { 59 {
59 struct tm *tm = localtime(&t);
60 g_return_val_if_fail(conv != NULL, NULL); 60 g_return_val_if_fail(conv != NULL, NULL);
61 g_return_val_if_fail(dates != NULL, NULL); 61 g_return_val_if_fail(dates != NULL, NULL);
62 62
63 if (!strcmp(dates, "always") || 63 if (show_date ||
64 (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT && 64 !strcmp(dates, "always") ||
65 !strcmp(dates, "chats")) || 65 (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT && !strcmp(dates, "chats")))
66 (time(NULL) > (mktime(tm) + 20*60)))
67 { 66 {
67 struct tm *tm = localtime(&t);
68 if (force) 68 if (force)
69 return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm)); 69 return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm));
70 else 70 else
71 return g_strdup(gaim_date_format_long(tm)); 71 return g_strdup(gaim_date_format_long(tm));
72 } 72 }
73 73
74 if (force) 74 if (force)
75 {
76 struct tm *tm = localtime(&t);
75 return g_strdup(gaim_utf8_strftime("%H:%M:%S", tm)); 77 return g_strdup(gaim_utf8_strftime("%H:%M:%S", tm));
78 }
76 79
77 return NULL; 80 return NULL;
78 } 81 }
79 82
80 static char *conversation_timestamp_cb(GaimConversation *conv, 83 static char *conversation_timestamp_cb(GaimConversation *conv,
81 time_t t, gpointer data) 84 time_t t, gboolean show_date, gpointer data)
82 { 85 {
83 gboolean force = gaim_prefs_get_bool( 86 gboolean force = gaim_prefs_get_bool(
84 "/plugins/gtk/timestamp_format/force_24hr"); 87 "/plugins/gtk/timestamp_format/force_24hr");
85 const char *dates = gaim_prefs_get_string( 88 const char *dates = gaim_prefs_get_string(
86 "/plugins/gtk/timestamp_format/use_dates/conversation"); 89 "/plugins/gtk/timestamp_format/use_dates/conversation");
87 90
88 g_return_val_if_fail(conv != NULL, NULL); 91 g_return_val_if_fail(conv != NULL, NULL);
89 92
90 return timestamp_cb_common(conv, t, force, dates); 93 return timestamp_cb_common(conv, t, show_date, force, dates);
91 } 94 }
92 95
93 static char *log_timestamp_cb(GaimLog *log, time_t t, gpointer data) 96 static char *log_timestamp_cb(GaimLog *log, time_t t, gboolean show_date, gpointer data)
94 { 97 {
95 gboolean force = gaim_prefs_get_bool( 98 gboolean force = gaim_prefs_get_bool(
96 "/plugins/gtk/timestamp_format/force_24hr"); 99 "/plugins/gtk/timestamp_format/force_24hr");
97 const char *dates = gaim_prefs_get_string( 100 const char *dates = gaim_prefs_get_string(
98 "/plugins/gtk/timestamp_format/use_dates/log"); 101 "/plugins/gtk/timestamp_format/use_dates/log");
99 102
100 g_return_val_if_fail(log != NULL, NULL); 103 g_return_val_if_fail(log != NULL, NULL);
101 104
102 if (log->type == GAIM_LOG_SYSTEM) 105 return timestamp_cb_common(log->conv, t, show_date, force, dates);
103 {
104 if (force) {
105 struct tm *tm = localtime(&t);
106 return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm));
107 } else {
108 return NULL;
109 }
110 }
111
112 return timestamp_cb_common(log->conv, t, force, dates);
113 } 106 }
114 107
115 static gboolean 108 static gboolean
116 plugin_load(GaimPlugin *plugin) 109 plugin_load(GaimPlugin *plugin)
117 { 110 {
138 { 131 {
139 GAIM_PLUGIN_MAGIC, 132 GAIM_PLUGIN_MAGIC,
140 GAIM_MAJOR_VERSION, 133 GAIM_MAJOR_VERSION,
141 GAIM_MINOR_VERSION, 134 GAIM_MINOR_VERSION,
142 GAIM_PLUGIN_STANDARD, /**< type */ 135 GAIM_PLUGIN_STANDARD, /**< type */
143 PIDGIN_PLUGIN_TYPE, /**< ui_requirement */ 136 PIDGIN_PLUGIN_TYPE, /**< ui_requirement */
144 0, /**< flags */ 137 0, /**< flags */
145 NULL, /**< dependencies */ 138 NULL, /**< dependencies */
146 GAIM_PRIORITY_DEFAULT, /**< priority */ 139 GAIM_PRIORITY_DEFAULT, /**< priority */
147 140
148 NULL, /**< id */ 141 NULL, /**< id */