Mercurial > pidgin.yaz
comparison pidgin/plugins/timestamp_format.c @ 15374:5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 20 Jan 2007 02:32:10 +0000 |
parents | |
children | d54794a47c56 |
comparison
equal
deleted
inserted
replaced
15373:f79e0f4df793 | 15374:5fe8042783c1 |
---|---|
1 #include "internal.h" | |
2 | |
3 #include "debug.h" | |
4 #include "log.h" | |
5 #include "plugin.h" | |
6 #include "util.h" | |
7 #include "version.h" | |
8 | |
9 #include "gtkconv.h" | |
10 #include "gtkplugin.h" | |
11 | |
12 #include <time.h> | |
13 | |
14 static GaimPluginPrefFrame * | |
15 get_plugin_pref_frame(GaimPlugin *plugin) | |
16 { | |
17 GaimPluginPrefFrame *frame; | |
18 GaimPluginPref *ppref; | |
19 | |
20 frame = gaim_plugin_pref_frame_new(); | |
21 | |
22 ppref = gaim_plugin_pref_new_with_label(_("Timestamp Format Options")); | |
23 gaim_plugin_pref_frame_add(frame, ppref); | |
24 | |
25 ppref = gaim_plugin_pref_new_with_name_and_label( | |
26 "/plugins/gtk/timestamp_format/force_24hr", | |
27 _("_Force (traditional Gaim) 24-hour time format")); | |
28 gaim_plugin_pref_frame_add(frame, ppref); | |
29 | |
30 ppref = gaim_plugin_pref_new_with_label(_("Show dates in...")); | |
31 gaim_plugin_pref_frame_add(frame, ppref); | |
32 | |
33 ppref = gaim_plugin_pref_new_with_name_and_label( | |
34 "/plugins/gtk/timestamp_format/use_dates/conversation", | |
35 _("Co_nversations:")); | |
36 gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE); | |
37 gaim_plugin_pref_add_choice(ppref, _("For delayed messages"), "automatic"); | |
38 gaim_plugin_pref_add_choice(ppref, _("For delayed messages and in chats"), "chats"); | |
39 gaim_plugin_pref_add_choice(ppref, _("Always"), "always"); | |
40 gaim_plugin_pref_frame_add(frame, ppref); | |
41 | |
42 ppref = gaim_plugin_pref_new_with_name_and_label( | |
43 "/plugins/gtk/timestamp_format/use_dates/log", | |
44 _("_Message Logs:")); | |
45 gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE); | |
46 gaim_plugin_pref_add_choice(ppref, _("For delayed messages"), "automatic"); | |
47 gaim_plugin_pref_add_choice(ppref, _("For delayed messages and in chats"), "chats"); | |
48 gaim_plugin_pref_add_choice(ppref, _("Always"), "always"); | |
49 gaim_plugin_pref_frame_add(frame, ppref); | |
50 | |
51 return frame; | |
52 } | |
53 | |
54 static char *timestamp_cb_common(GaimConversation *conv, | |
55 time_t t, | |
56 gboolean force, | |
57 const char *dates) | |
58 { | |
59 struct tm *tm = localtime(&t); | |
60 g_return_val_if_fail(conv != NULL, NULL); | |
61 g_return_val_if_fail(dates != NULL, NULL); | |
62 | |
63 if (!strcmp(dates, "always") || | |
64 (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT && | |
65 !strcmp(dates, "chats")) || | |
66 (time(NULL) > (mktime(tm) + 20*60))) | |
67 { | |
68 if (force) | |
69 return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm)); | |
70 else | |
71 return g_strdup(gaim_date_format_long(tm)); | |
72 } | |
73 | |
74 if (force) | |
75 return g_strdup(gaim_utf8_strftime("%H:%M:%S", tm)); | |
76 | |
77 return NULL; | |
78 } | |
79 | |
80 static char *conversation_timestamp_cb(GaimConversation *conv, | |
81 time_t t, gpointer data) | |
82 { | |
83 gboolean force = gaim_prefs_get_bool( | |
84 "/plugins/gtk/timestamp_format/force_24hr"); | |
85 const char *dates = gaim_prefs_get_string( | |
86 "/plugins/gtk/timestamp_format/use_dates/conversation"); | |
87 | |
88 g_return_val_if_fail(conv != NULL, NULL); | |
89 | |
90 return timestamp_cb_common(conv, t, force, dates); | |
91 } | |
92 | |
93 static char *log_timestamp_cb(GaimLog *log, time_t t, gpointer data) | |
94 { | |
95 gboolean force = gaim_prefs_get_bool( | |
96 "/plugins/gtk/timestamp_format/force_24hr"); | |
97 const char *dates = gaim_prefs_get_string( | |
98 "/plugins/gtk/timestamp_format/use_dates/log"); | |
99 | |
100 g_return_val_if_fail(log != NULL, NULL); | |
101 | |
102 if (log->type == GAIM_LOG_SYSTEM) | |
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 } | |
114 | |
115 static gboolean | |
116 plugin_load(GaimPlugin *plugin) | |
117 { | |
118 gaim_signal_connect(gaim_gtk_conversations_get_handle(), "conversation-timestamp", | |
119 plugin, GAIM_CALLBACK(conversation_timestamp_cb), NULL); | |
120 gaim_signal_connect(gaim_log_get_handle(), "log-timestamp", | |
121 plugin, GAIM_CALLBACK(log_timestamp_cb), NULL); | |
122 return TRUE; | |
123 } | |
124 | |
125 static gboolean | |
126 plugin_unload(GaimPlugin *plugin) | |
127 { | |
128 return TRUE; | |
129 } | |
130 | |
131 static GaimPluginUiInfo prefs_info = { | |
132 get_plugin_pref_frame, | |
133 0, /* page num (Reserved) */ | |
134 NULL /* frame (Reserved) */ | |
135 }; | |
136 | |
137 static GaimPluginInfo info = | |
138 { | |
139 GAIM_PLUGIN_MAGIC, | |
140 GAIM_MAJOR_VERSION, | |
141 GAIM_MINOR_VERSION, | |
142 GAIM_PLUGIN_STANDARD, /**< type */ | |
143 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ | |
144 0, /**< flags */ | |
145 NULL, /**< dependencies */ | |
146 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
147 | |
148 NULL, /**< id */ | |
149 N_("Message Timestamp Formats"), /**< name */ | |
150 VERSION, /**< version */ | |
151 /** summary */ | |
152 N_("Customizes the message timestamp formats."), | |
153 /** description */ | |
154 N_("This plugin allows the user to customize " | |
155 "conversation and logging message timestamp " | |
156 "formats."), | |
157 "Richard Laager <rlaager@users.sf.net>", /**< author */ | |
158 GAIM_WEBSITE, /**< homepage */ | |
159 | |
160 plugin_load, /**< load */ | |
161 plugin_unload, /**< unload */ | |
162 NULL, /**< destroy */ | |
163 | |
164 NULL, /**< ui_info */ | |
165 NULL, /**< extra_info */ | |
166 &prefs_info, /**< prefs_info */ | |
167 NULL /**< actions */ | |
168 }; | |
169 | |
170 static void | |
171 init_plugin(GaimPlugin *plugin) | |
172 { | |
173 gaim_prefs_add_none("/plugins/gtk"); | |
174 gaim_prefs_add_none("/plugins/gtk/timestamp_format"); | |
175 | |
176 gaim_prefs_add_bool("/plugins/gtk/timestamp_format/force_24hr", TRUE); | |
177 | |
178 gaim_prefs_add_none("/plugins/gtk/timestamp_format/use_dates"); | |
179 gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/conversation", "automatic"); | |
180 gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/log", "automatic"); | |
181 } | |
182 | |
183 GAIM_INIT_PLUGIN(timestamp_format, init_plugin, info) |