Mercurial > pidgin
annotate plugins/timestamp_format.c @ 12959:acf22abb86ba
[gaim-migrate @ 15312]
I got tired of people asking me for this on Windows, and of telling people to
use it and them saying "I can't find it" when they didn't bother to tell me
they were using Windows first.
committer: Tailor Script <tailor@pidgin.im>
author | Etan Reisner <pidgin@unreliablesource.net> |
---|---|
date | Fri, 20 Jan 2006 01:44:06 +0000 |
parents | c1317074fce3 |
children | fd57413bc421 |
rev | line source |
---|---|
12737 | 1 #include "internal.h" |
2 | |
3 #include "debug.h" | |
4 #include "log.h" | |
5 #include "plugin.h" | |
6 #include "version.h" | |
7 | |
8 #include "gtkconv.h" | |
9 #include "gtkplugin.h" | |
10 | |
12851
c1317074fce3
[gaim-migrate @ 15201]
Richard Laager <rlaager@wiktel.com>
parents:
12848
diff
changeset
|
11 #include <time.h> |
c1317074fce3
[gaim-migrate @ 15201]
Richard Laager <rlaager@wiktel.com>
parents:
12848
diff
changeset
|
12 |
12737 | 13 static GaimPluginPrefFrame * |
14 get_plugin_pref_frame(GaimPlugin *plugin) | |
15 { | |
16 GaimPluginPrefFrame *frame; | |
17 GaimPluginPref *ppref; | |
18 | |
19 frame = gaim_plugin_pref_frame_new(); | |
20 | |
21 ppref = gaim_plugin_pref_new_with_label(_("Timestamp Format Options")); | |
22 gaim_plugin_pref_frame_add(frame, ppref); | |
23 | |
24 ppref = gaim_plugin_pref_new_with_name_and_label( | |
25 "/plugins/gtk/timestamp_format/force_24hr", | |
26 _("_Force (traditional Gaim) 24-hour time format")); | |
27 gaim_plugin_pref_frame_add(frame, ppref); | |
28 | |
29 ppref = gaim_plugin_pref_new_with_label(_("Show dates in...")); | |
30 gaim_plugin_pref_frame_add(frame, ppref); | |
31 | |
32 ppref = gaim_plugin_pref_new_with_name_and_label( | |
33 "/plugins/gtk/timestamp_format/use_dates/conversation", | |
34 _("Co_nversations:")); | |
35 gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE); | |
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
36 gaim_plugin_pref_add_choice(ppref, "For delayed messages", "automatic"); |
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
37 gaim_plugin_pref_add_choice(ppref, "For delayed messages and in chats", "chats"); |
12737 | 38 gaim_plugin_pref_add_choice(ppref, "Always", "always"); |
39 gaim_plugin_pref_frame_add(frame, ppref); | |
40 | |
41 ppref = gaim_plugin_pref_new_with_name_and_label( | |
42 "/plugins/gtk/timestamp_format/use_dates/log", | |
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
43 _("_Message Logs:")); |
12737 | 44 gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE); |
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
45 gaim_plugin_pref_add_choice(ppref, "For delayed messages", "automatic"); |
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
46 gaim_plugin_pref_add_choice(ppref, "For delayed messages and in chats", "chats"); |
12737 | 47 gaim_plugin_pref_add_choice(ppref, "Always", "always"); |
48 gaim_plugin_pref_frame_add(frame, ppref); | |
49 | |
50 return frame; | |
51 } | |
52 | |
53 static char *timestamp_cb_common(GaimConversation *conv, | |
54 const struct tm *tm, | |
55 gboolean force, | |
56 const char *dates) | |
57 { | |
58 char buf[64]; | |
59 | |
60 g_return_val_if_fail(conv != NULL, NULL); | |
61 g_return_val_if_fail(tm != NULL, NULL); | |
62 g_return_val_if_fail(dates != NULL, NULL); | |
63 | |
64 if (!strcmp(dates, "always") || | |
65 (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT && | |
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
66 !strcmp(dates, "chats")) || |
12851
c1317074fce3
[gaim-migrate @ 15201]
Richard Laager <rlaager@wiktel.com>
parents:
12848
diff
changeset
|
67 (time(NULL) > (mktime((struct tm *)tm) + 20*60))) |
12737 | 68 { |
69 if (force) | |
70 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm); | |
71 else | |
72 strftime(buf, sizeof(buf), "%x %X", tm); | |
73 | |
74 return g_strdup(buf); | |
75 } | |
76 | |
77 if (force) | |
78 { | |
79 strftime(buf, sizeof(buf), "%H:%M:%S", tm); | |
80 return g_strdup(buf); | |
81 } | |
82 | |
83 return NULL; | |
84 } | |
85 | |
86 static char *conversation_timestamp_cb(GaimConversation *conv, | |
87 const struct tm *tm, gpointer data) | |
88 { | |
89 gboolean force = gaim_prefs_get_bool( | |
90 "/plugins/gtk/timestamp_format/force_24hr"); | |
91 const char *dates = gaim_prefs_get_string( | |
92 "/plugins/gtk/timestamp_format/use_dates/conversation"); | |
93 return timestamp_cb_common(conv, tm, force, dates); | |
94 } | |
95 | |
96 static char *log_timestamp_cb(GaimLog *log, | |
97 const struct tm *tm, gpointer data) | |
98 { | |
99 gboolean force = gaim_prefs_get_bool( | |
100 "/plugins/gtk/timestamp_format/force_24hr"); | |
101 const char *dates = gaim_prefs_get_string( | |
102 "/plugins/gtk/timestamp_format/use_dates/log"); | |
103 | |
104 if (log->type == GAIM_LOG_SYSTEM) | |
105 { | |
106 if (force) | |
107 { | |
108 char buf[64]; | |
109 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm); | |
110 return g_strdup(buf); | |
111 } | |
112 else | |
113 return NULL; | |
114 } | |
115 | |
116 return timestamp_cb_common(log->conv, tm, force, dates); | |
117 } | |
118 | |
119 static gboolean | |
120 plugin_load(GaimPlugin *plugin) | |
121 { | |
122 gaim_signal_connect(gaim_gtk_conversations_get_handle(), "conversation-timestamp", | |
123 plugin, GAIM_CALLBACK(conversation_timestamp_cb), NULL); | |
124 gaim_signal_connect(gaim_log_get_handle(), "log-timestamp", | |
125 plugin, GAIM_CALLBACK(log_timestamp_cb), NULL); | |
126 return TRUE; | |
127 } | |
128 | |
129 static gboolean | |
130 plugin_unload(GaimPlugin *plugin) | |
131 { | |
132 return TRUE; | |
133 } | |
134 | |
135 static GaimPluginUiInfo prefs_info = { | |
136 get_plugin_pref_frame, | |
137 0, /* page num (Reserved) */ | |
138 NULL /* frame (Reserved) */ | |
139 }; | |
140 | |
141 static GaimPluginInfo info = | |
142 { | |
143 GAIM_PLUGIN_MAGIC, | |
144 GAIM_MAJOR_VERSION, | |
145 GAIM_MINOR_VERSION, | |
146 GAIM_PLUGIN_STANDARD, /**< type */ | |
147 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ | |
148 0, /**< flags */ | |
149 NULL, /**< dependencies */ | |
150 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
151 | |
152 NULL, /**< id */ | |
153 N_("Message Timestamp Formats"), /**< name */ | |
154 VERSION, /**< version */ | |
155 /** summary */ | |
156 N_("Customizes the message timestamp formats."), | |
157 /** description */ | |
158 N_("This plugin allows the user to customize " | |
159 "conversation and logging message timestamp " | |
160 "formats."), | |
161 "Richard Laager <rlaager@users.sf.net>", /**< author */ | |
162 GAIM_WEBSITE, /**< homepage */ | |
163 | |
164 plugin_load, /**< load */ | |
165 plugin_unload, /**< unload */ | |
166 NULL, /**< destroy */ | |
167 | |
168 NULL, /**< ui_info */ | |
169 NULL, /**< extra_info */ | |
170 &prefs_info, /**< prefs_info */ | |
171 NULL /**< actions */ | |
172 }; | |
173 | |
174 static void | |
175 init_plugin(GaimPlugin *plugin) | |
176 { | |
177 gaim_prefs_add_none("/plugins/gtk"); | |
178 gaim_prefs_add_none("/plugins/gtk/timestamp_format"); | |
179 | |
180 gaim_prefs_add_bool("/plugins/gtk/timestamp_format/force_24hr", TRUE); | |
181 | |
182 gaim_prefs_add_none("/plugins/gtk/timestamp_format/use_dates"); | |
183 gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/conversation", "automatic"); | |
184 gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/log", "automatic"); | |
185 } | |
186 | |
187 GAIM_INIT_PLUGIN(timestamp_format, init_plugin, info) |