Mercurial > pidgin
annotate plugins/timestamp_format.c @ 13647:1003b97adce9
[gaim-migrate @ 16048]
Provide easy access to GTK+/Glib runtime versions for debugging.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Mon, 17 Apr 2006 18:36:26 +0000 |
parents | c73c7dd0721f |
children | f94309c7c480 |
rev | line source |
---|---|
12737 | 1 #include "internal.h" |
2 | |
3 #include "debug.h" | |
4 #include "log.h" | |
5 #include "plugin.h" | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
6 #include "util.h" |
12737 | 7 #include "version.h" |
8 | |
9 #include "gtkconv.h" | |
10 #include "gtkplugin.h" | |
11 | |
12851
c1317074fce3
[gaim-migrate @ 15201]
Richard Laager <rlaager@wiktel.com>
parents:
12848
diff
changeset
|
12 #include <time.h> |
c1317074fce3
[gaim-migrate @ 15201]
Richard Laager <rlaager@wiktel.com>
parents:
12848
diff
changeset
|
13 |
12737 | 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); | |
13089 | 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"); | |
12737 | 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", | |
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
44 _("_Message Logs:")); |
12737 | 45 gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE); |
13089 | 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"); | |
12737 | 49 gaim_plugin_pref_frame_add(frame, ppref); |
50 | |
51 return frame; | |
52 } | |
53 | |
54 static char *timestamp_cb_common(GaimConversation *conv, | |
55 const struct tm *tm, | |
56 gboolean force, | |
57 const char *dates) | |
58 { | |
59 g_return_val_if_fail(conv != NULL, NULL); | |
60 g_return_val_if_fail(tm != 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 && | |
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
65 !strcmp(dates, "chats")) || |
12851
c1317074fce3
[gaim-migrate @ 15201]
Richard Laager <rlaager@wiktel.com>
parents:
12848
diff
changeset
|
66 (time(NULL) > (mktime((struct tm *)tm) + 20*60))) |
12737 | 67 { |
68 if (force) | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
69 return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm)); |
12737 | 70 else |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
71 return g_strdup(gaim_date_format_long(tm)); |
12737 | 72 } |
73 | |
74 if (force) | |
13114
c73c7dd0721f
[gaim-migrate @ 15476]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
75 return g_strdup(gaim_utf8_strftime("%H:%M:%S", tm)); |
12737 | 76 |
77 return NULL; | |
78 } | |
79 | |
80 static char *conversation_timestamp_cb(GaimConversation *conv, | |
81 const struct tm *tm, 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"); | |
13054
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
87 |
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
88 g_return_val_if_fail(conv != NULL, NULL); |
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
89 g_return_val_if_fail(tm != NULL, NULL); |
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
90 |
12737 | 91 return timestamp_cb_common(conv, tm, force, dates); |
92 } | |
93 | |
94 static char *log_timestamp_cb(GaimLog *log, | |
95 const struct tm *tm, gpointer data) | |
96 { | |
97 gboolean force = gaim_prefs_get_bool( | |
98 "/plugins/gtk/timestamp_format/force_24hr"); | |
99 const char *dates = gaim_prefs_get_string( | |
100 "/plugins/gtk/timestamp_format/use_dates/log"); | |
101 | |
13054
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
102 g_return_val_if_fail(log != NULL, NULL); |
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
103 g_return_val_if_fail(tm != NULL, NULL); |
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
104 |
12737 | 105 if (log->type == GAIM_LOG_SYSTEM) |
106 { | |
107 if (force) | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
108 return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm)); |
12737 | 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) |