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
|
|
11 static GaimPluginPrefFrame *
|
|
12 get_plugin_pref_frame(GaimPlugin *plugin)
|
|
13 {
|
|
14 GaimPluginPrefFrame *frame;
|
|
15 GaimPluginPref *ppref;
|
|
16
|
|
17 frame = gaim_plugin_pref_frame_new();
|
|
18
|
|
19 ppref = gaim_plugin_pref_new_with_label(_("Timestamp Format Options"));
|
|
20 gaim_plugin_pref_frame_add(frame, ppref);
|
|
21
|
|
22 ppref = gaim_plugin_pref_new_with_name_and_label(
|
|
23 "/plugins/gtk/timestamp_format/force_24hr",
|
|
24 _("_Force (traditional Gaim) 24-hour time format"));
|
|
25 gaim_plugin_pref_frame_add(frame, ppref);
|
|
26
|
|
27 ppref = gaim_plugin_pref_new_with_label(_("Show dates in..."));
|
|
28 gaim_plugin_pref_frame_add(frame, ppref);
|
|
29
|
|
30 ppref = gaim_plugin_pref_new_with_name_and_label(
|
|
31 "/plugins/gtk/timestamp_format/use_dates/conversation",
|
|
32 _("Co_nversations:"));
|
|
33 gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE);
|
|
34 gaim_plugin_pref_add_choice(ppref, "For Delayed Messages", "automatic");
|
|
35 gaim_plugin_pref_add_choice(ppref, "In Chats", "chats");
|
|
36 gaim_plugin_pref_add_choice(ppref, "Always", "always");
|
|
37 gaim_plugin_pref_frame_add(frame, ppref);
|
|
38
|
|
39 ppref = gaim_plugin_pref_new_with_name_and_label(
|
|
40 "/plugins/gtk/timestamp_format/use_dates/log",
|
|
41 _("_Logs:"));
|
|
42 gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE);
|
|
43 gaim_plugin_pref_add_choice(ppref, "For Delayed Messages", "automatic");
|
|
44 gaim_plugin_pref_add_choice(ppref, "In Chats", "chats");
|
|
45 gaim_plugin_pref_add_choice(ppref, "Always", "always");
|
|
46 gaim_plugin_pref_frame_add(frame, ppref);
|
|
47
|
|
48 return frame;
|
|
49 }
|
|
50
|
|
51 static char *timestamp_cb_common(GaimConversation *conv,
|
|
52 const struct tm *tm,
|
|
53 gboolean force,
|
|
54 const char *dates)
|
|
55 {
|
|
56 char buf[64];
|
|
57
|
|
58 g_return_val_if_fail(conv != NULL, NULL);
|
|
59 g_return_val_if_fail(tm != NULL, NULL);
|
|
60 g_return_val_if_fail(dates != NULL, NULL);
|
|
61
|
|
62 if (!strcmp(dates, "always") ||
|
|
63 (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT &&
|
|
64 !strcmp(dates, "chats")))
|
|
65 {
|
|
66 if (force)
|
|
67 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm);
|
|
68 else
|
|
69 strftime(buf, sizeof(buf), "%x %X", tm);
|
|
70
|
|
71 return g_strdup(buf);
|
|
72 }
|
|
73
|
|
74 if (force)
|
|
75 {
|
|
76 strftime(buf, sizeof(buf), "%H:%M:%S", tm);
|
|
77 return g_strdup(buf);
|
|
78 }
|
|
79
|
|
80 return NULL;
|
|
81 }
|
|
82
|
|
83 static char *conversation_timestamp_cb(GaimConversation *conv,
|
|
84 const struct tm *tm, gpointer data)
|
|
85 {
|
|
86 gboolean force = gaim_prefs_get_bool(
|
|
87 "/plugins/gtk/timestamp_format/force_24hr");
|
|
88 const char *dates = gaim_prefs_get_string(
|
|
89 "/plugins/gtk/timestamp_format/use_dates/conversation");
|
|
90 return timestamp_cb_common(conv, tm, force, dates);
|
|
91 }
|
|
92
|
|
93 static char *log_timestamp_cb(GaimLog *log,
|
|
94 const struct tm *tm, gpointer data)
|
|
95 {
|
|
96 gboolean force = gaim_prefs_get_bool(
|
|
97 "/plugins/gtk/timestamp_format/force_24hr");
|
|
98 const char *dates = gaim_prefs_get_string(
|
|
99 "/plugins/gtk/timestamp_format/use_dates/log");
|
|
100
|
|
101 if (log->type == GAIM_LOG_SYSTEM)
|
|
102 {
|
|
103 if (force)
|
|
104 {
|
|
105 char buf[64];
|
|
106 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm);
|
|
107 return g_strdup(buf);
|
|
108 }
|
|
109 else
|
|
110 return NULL;
|
|
111 }
|
|
112
|
|
113 return timestamp_cb_common(log->conv, tm, force, dates);
|
|
114 }
|
|
115
|
|
116 static gboolean
|
|
117 plugin_load(GaimPlugin *plugin)
|
|
118 {
|
|
119 gaim_signal_connect(gaim_gtk_conversations_get_handle(), "conversation-timestamp",
|
|
120 plugin, GAIM_CALLBACK(conversation_timestamp_cb), NULL);
|
|
121 gaim_signal_connect(gaim_log_get_handle(), "log-timestamp",
|
|
122 plugin, GAIM_CALLBACK(log_timestamp_cb), NULL);
|
|
123 return TRUE;
|
|
124 }
|
|
125
|
|
126 static gboolean
|
|
127 plugin_unload(GaimPlugin *plugin)
|
|
128 {
|
|
129 return TRUE;
|
|
130 }
|
|
131
|
|
132 static GaimPluginUiInfo prefs_info = {
|
|
133 get_plugin_pref_frame,
|
|
134 0, /* page num (Reserved) */
|
|
135 NULL /* frame (Reserved) */
|
|
136 };
|
|
137
|
|
138 static GaimPluginInfo info =
|
|
139 {
|
|
140 GAIM_PLUGIN_MAGIC,
|
|
141 GAIM_MAJOR_VERSION,
|
|
142 GAIM_MINOR_VERSION,
|
|
143 GAIM_PLUGIN_STANDARD, /**< type */
|
|
144 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */
|
|
145 0, /**< flags */
|
|
146 NULL, /**< dependencies */
|
|
147 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
148
|
|
149 NULL, /**< id */
|
|
150 N_("Message Timestamp Formats"), /**< name */
|
|
151 VERSION, /**< version */
|
|
152 /** summary */
|
|
153 N_("Customizes the message timestamp formats."),
|
|
154 /** description */
|
|
155 N_("This plugin allows the user to customize "
|
|
156 "conversation and logging message timestamp "
|
|
157 "formats."),
|
|
158 "Richard Laager <rlaager@users.sf.net>", /**< author */
|
|
159 GAIM_WEBSITE, /**< homepage */
|
|
160
|
|
161 plugin_load, /**< load */
|
|
162 plugin_unload, /**< unload */
|
|
163 NULL, /**< destroy */
|
|
164
|
|
165 NULL, /**< ui_info */
|
|
166 NULL, /**< extra_info */
|
|
167 &prefs_info, /**< prefs_info */
|
|
168 NULL /**< actions */
|
|
169 };
|
|
170
|
|
171 static void
|
|
172 init_plugin(GaimPlugin *plugin)
|
|
173 {
|
|
174 gaim_prefs_add_none("/plugins/gtk");
|
|
175 gaim_prefs_add_none("/plugins/gtk/timestamp_format");
|
|
176
|
|
177 gaim_prefs_add_bool("/plugins/gtk/timestamp_format/force_24hr", TRUE);
|
|
178
|
|
179 gaim_prefs_add_none("/plugins/gtk/timestamp_format/use_dates");
|
|
180 gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/conversation", "automatic");
|
|
181 gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/log", "automatic");
|
|
182 }
|
|
183
|
|
184 GAIM_INIT_PLUGIN(timestamp_format, init_plugin, info)
|