| |
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 PurplePluginPrefFrame * |
| |
15 get_plugin_pref_frame(PurplePlugin *plugin) |
| |
16 { |
| |
17 PurplePluginPrefFrame *frame; |
| |
18 PurplePluginPref *ppref; |
| |
19 char *tmp; |
| |
20 |
| |
21 frame = purple_plugin_pref_frame_new(); |
| |
22 |
| |
23 ppref = purple_plugin_pref_new_with_label(_("Timestamp Format Options")); |
| |
24 purple_plugin_pref_frame_add(frame, ppref); |
| |
25 |
| |
26 tmp = g_strdup_printf(_("_Force (traditional %s) 24-hour time format"), PIDGIN_NAME); |
| |
27 ppref = purple_plugin_pref_new_with_name_and_label( |
| |
28 "/plugins/gtk/timestamp_format/force_24hr", |
| |
29 tmp); |
| |
30 purple_plugin_pref_frame_add(frame, ppref); |
| |
31 g_free(tmp); |
| |
32 |
| |
33 ppref = purple_plugin_pref_new_with_label(_("Show dates in...")); |
| |
34 purple_plugin_pref_frame_add(frame, ppref); |
| |
35 |
| |
36 ppref = purple_plugin_pref_new_with_name_and_label( |
| |
37 "/plugins/gtk/timestamp_format/use_dates/conversation", |
| |
38 _("Co_nversations:")); |
| |
39 purple_plugin_pref_set_type(ppref, PURPLE_PLUGIN_PREF_CHOICE); |
| |
40 purple_plugin_pref_add_choice(ppref, _("For delayed messages"), "automatic"); |
| |
41 purple_plugin_pref_add_choice(ppref, _("For delayed messages and in chats"), "chats"); |
| |
42 purple_plugin_pref_add_choice(ppref, _("Always"), "always"); |
| |
43 purple_plugin_pref_frame_add(frame, ppref); |
| |
44 |
| |
45 ppref = purple_plugin_pref_new_with_name_and_label( |
| |
46 "/plugins/gtk/timestamp_format/use_dates/log", |
| |
47 _("_Message Logs:")); |
| |
48 purple_plugin_pref_set_type(ppref, PURPLE_PLUGIN_PREF_CHOICE); |
| |
49 purple_plugin_pref_add_choice(ppref, _("For delayed messages"), "automatic"); |
| |
50 purple_plugin_pref_add_choice(ppref, _("For delayed messages and in chats"), "chats"); |
| |
51 purple_plugin_pref_add_choice(ppref, _("Always"), "always"); |
| |
52 purple_plugin_pref_frame_add(frame, ppref); |
| |
53 |
| |
54 return frame; |
| |
55 } |
| |
56 |
| |
57 static char *timestamp_cb_common(PurpleConversation *conv, |
| |
58 time_t t, |
| |
59 gboolean show_date, |
| |
60 gboolean force, |
| |
61 const char *dates) |
| |
62 { |
| |
63 g_return_val_if_fail(dates != NULL, NULL); |
| |
64 |
| |
65 if (show_date || |
| |
66 !strcmp(dates, "always") || |
| |
67 (conv != NULL && purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT && !strcmp(dates, "chats"))) |
| |
68 { |
| |
69 struct tm *tm = localtime(&t); |
| |
70 if (force) |
| |
71 return g_strdup(purple_utf8_strftime("%Y-%m-%d %H:%M:%S", tm)); |
| |
72 else |
| |
73 return g_strdup(purple_date_format_long(tm)); |
| |
74 } |
| |
75 |
| |
76 if (force) |
| |
77 { |
| |
78 struct tm *tm = localtime(&t); |
| |
79 return g_strdup(purple_utf8_strftime("%H:%M:%S", tm)); |
| |
80 } |
| |
81 |
| |
82 return NULL; |
| |
83 } |
| |
84 |
| |
85 static char *conversation_timestamp_cb(PurpleConversation *conv, |
| |
86 time_t t, gboolean show_date, gpointer data) |
| |
87 { |
| |
88 gboolean force = purple_prefs_get_bool( |
| |
89 "/plugins/gtk/timestamp_format/force_24hr"); |
| |
90 const char *dates = purple_prefs_get_string( |
| |
91 "/plugins/gtk/timestamp_format/use_dates/conversation"); |
| |
92 |
| |
93 g_return_val_if_fail(conv != NULL, NULL); |
| |
94 |
| |
95 return timestamp_cb_common(conv, t, show_date, force, dates); |
| |
96 } |
| |
97 |
| |
98 static char *log_timestamp_cb(PurpleLog *log, time_t t, gboolean show_date, gpointer data) |
| |
99 { |
| |
100 gboolean force = purple_prefs_get_bool( |
| |
101 "/plugins/gtk/timestamp_format/force_24hr"); |
| |
102 const char *dates = purple_prefs_get_string( |
| |
103 "/plugins/gtk/timestamp_format/use_dates/log"); |
| |
104 |
| |
105 g_return_val_if_fail(log != NULL, NULL); |
| |
106 |
| |
107 return timestamp_cb_common(log->conv, t, show_date, force, dates); |
| |
108 } |
| |
109 |
| |
110 static gboolean |
| |
111 plugin_load(PurplePlugin *plugin) |
| |
112 { |
| |
113 purple_signal_connect(pidgin_conversations_get_handle(), "conversation-timestamp", |
| |
114 plugin, PURPLE_CALLBACK(conversation_timestamp_cb), NULL); |
| |
115 purple_signal_connect(purple_log_get_handle(), "log-timestamp", |
| |
116 plugin, PURPLE_CALLBACK(log_timestamp_cb), NULL); |
| |
117 return TRUE; |
| |
118 } |
| |
119 |
| |
120 static gboolean |
| |
121 plugin_unload(PurplePlugin *plugin) |
| |
122 { |
| |
123 return TRUE; |
| |
124 } |
| |
125 |
| |
126 static PurplePluginUiInfo prefs_info = { |
| |
127 get_plugin_pref_frame, |
| |
128 0, /* page num (Reserved) */ |
| |
129 NULL /* frame (Reserved) */ |
| |
130 }; |
| |
131 |
| |
132 static PurplePluginInfo info = |
| |
133 { |
| |
134 PURPLE_PLUGIN_MAGIC, |
| |
135 PURPLE_MAJOR_VERSION, |
| |
136 PURPLE_MINOR_VERSION, |
| |
137 PURPLE_PLUGIN_STANDARD, /**< type */ |
| |
138 PIDGIN_PLUGIN_TYPE, /**< ui_requirement */ |
| |
139 0, /**< flags */ |
| |
140 NULL, /**< dependencies */ |
| |
141 PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| |
142 |
| |
143 "core-timestamp_format", /**< id */ |
| |
144 N_("Message Timestamp Formats"), /**< name */ |
| |
145 VERSION, /**< version */ |
| |
146 /** summary */ |
| |
147 N_("Customizes the message timestamp formats."), |
| |
148 /** description */ |
| |
149 N_("This plugin allows the user to customize " |
| |
150 "conversation and logging message timestamp " |
| |
151 "formats."), |
| |
152 "Richard Laager <rlaager@pidgin.im>", /**< author */ |
| |
153 PURPLE_WEBSITE, /**< homepage */ |
| |
154 |
| |
155 plugin_load, /**< load */ |
| |
156 plugin_unload, /**< unload */ |
| |
157 NULL, /**< destroy */ |
| |
158 |
| |
159 NULL, /**< ui_info */ |
| |
160 NULL, /**< extra_info */ |
| |
161 &prefs_info, /**< prefs_info */ |
| |
162 NULL /**< actions */ |
| |
163 }; |
| |
164 |
| |
165 static void |
| |
166 init_plugin(PurplePlugin *plugin) |
| |
167 { |
| |
168 purple_prefs_add_none("/plugins/gtk"); |
| |
169 purple_prefs_add_none("/plugins/gtk/timestamp_format"); |
| |
170 |
| |
171 purple_prefs_add_bool("/plugins/gtk/timestamp_format/force_24hr", TRUE); |
| |
172 |
| |
173 purple_prefs_add_none("/plugins/gtk/timestamp_format/use_dates"); |
| |
174 purple_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/conversation", "automatic"); |
| |
175 purple_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/log", "automatic"); |
| |
176 } |
| |
177 |
| |
178 PURPLE_INIT_PLUGIN(timestamp_format, init_plugin, info) |