Mercurial > pidgin.yaz
annotate plugins/timestamp_format.c @ 12848:d26e3314c650
[gaim-migrate @ 15198]
Make the options say what the plugin is supposed to do and then make the plugin do what the options say it does.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 12 Jan 2006 06:12:03 +0000 |
parents | a1e241dd50b6 |
children | c1317074fce3 |
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 | |
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); | |
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
34 gaim_plugin_pref_add_choice(ppref, "For delayed messages", "automatic"); |
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
35 gaim_plugin_pref_add_choice(ppref, "For delayed messages and in chats", "chats"); |
12737 | 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", | |
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
41 _("_Message Logs:")); |
12737 | 42 gaim_plugin_pref_set_type(ppref, GAIM_PLUGIN_PREF_CHOICE); |
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
43 gaim_plugin_pref_add_choice(ppref, "For delayed messages", "automatic"); |
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
44 gaim_plugin_pref_add_choice(ppref, "For delayed messages and in chats", "chats"); |
12737 | 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 && | |
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
64 !strcmp(dates, "chats")) || |
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
65 (time(NULL) > (mktime(tm) + 20*60))) |
12737 | 66 { |
67 if (force) | |
68 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm); | |
69 else | |
70 strftime(buf, sizeof(buf), "%x %X", tm); | |
71 | |
72 return g_strdup(buf); | |
73 } | |
74 | |
75 if (force) | |
76 { | |
77 strftime(buf, sizeof(buf), "%H:%M:%S", tm); | |
78 return g_strdup(buf); | |
79 } | |
80 | |
81 return NULL; | |
82 } | |
83 | |
84 static char *conversation_timestamp_cb(GaimConversation *conv, | |
85 const struct tm *tm, gpointer data) | |
86 { | |
87 gboolean force = gaim_prefs_get_bool( | |
88 "/plugins/gtk/timestamp_format/force_24hr"); | |
89 const char *dates = gaim_prefs_get_string( | |
90 "/plugins/gtk/timestamp_format/use_dates/conversation"); | |
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 | |
102 if (log->type == GAIM_LOG_SYSTEM) | |
103 { | |
104 if (force) | |
105 { | |
106 char buf[64]; | |
107 strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm); | |
108 return g_strdup(buf); | |
109 } | |
110 else | |
111 return NULL; | |
112 } | |
113 | |
114 return timestamp_cb_common(log->conv, tm, force, dates); | |
115 } | |
116 | |
117 static gboolean | |
118 plugin_load(GaimPlugin *plugin) | |
119 { | |
120 gaim_signal_connect(gaim_gtk_conversations_get_handle(), "conversation-timestamp", | |
121 plugin, GAIM_CALLBACK(conversation_timestamp_cb), NULL); | |
122 gaim_signal_connect(gaim_log_get_handle(), "log-timestamp", | |
123 plugin, GAIM_CALLBACK(log_timestamp_cb), NULL); | |
124 return TRUE; | |
125 } | |
126 | |
127 static gboolean | |
128 plugin_unload(GaimPlugin *plugin) | |
129 { | |
130 return TRUE; | |
131 } | |
132 | |
133 static GaimPluginUiInfo prefs_info = { | |
134 get_plugin_pref_frame, | |
135 0, /* page num (Reserved) */ | |
136 NULL /* frame (Reserved) */ | |
137 }; | |
138 | |
139 static GaimPluginInfo info = | |
140 { | |
141 GAIM_PLUGIN_MAGIC, | |
142 GAIM_MAJOR_VERSION, | |
143 GAIM_MINOR_VERSION, | |
144 GAIM_PLUGIN_STANDARD, /**< type */ | |
145 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */ | |
146 0, /**< flags */ | |
147 NULL, /**< dependencies */ | |
148 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
149 | |
150 NULL, /**< id */ | |
151 N_("Message Timestamp Formats"), /**< name */ | |
152 VERSION, /**< version */ | |
153 /** summary */ | |
154 N_("Customizes the message timestamp formats."), | |
155 /** description */ | |
156 N_("This plugin allows the user to customize " | |
157 "conversation and logging message timestamp " | |
158 "formats."), | |
159 "Richard Laager <rlaager@users.sf.net>", /**< author */ | |
160 GAIM_WEBSITE, /**< homepage */ | |
161 | |
162 plugin_load, /**< load */ | |
163 plugin_unload, /**< unload */ | |
164 NULL, /**< destroy */ | |
165 | |
166 NULL, /**< ui_info */ | |
167 NULL, /**< extra_info */ | |
168 &prefs_info, /**< prefs_info */ | |
169 NULL /**< actions */ | |
170 }; | |
171 | |
172 static void | |
173 init_plugin(GaimPlugin *plugin) | |
174 { | |
175 gaim_prefs_add_none("/plugins/gtk"); | |
176 gaim_prefs_add_none("/plugins/gtk/timestamp_format"); | |
177 | |
178 gaim_prefs_add_bool("/plugins/gtk/timestamp_format/force_24hr", TRUE); | |
179 | |
180 gaim_prefs_add_none("/plugins/gtk/timestamp_format/use_dates"); | |
181 gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/conversation", "automatic"); | |
182 gaim_prefs_add_string("/plugins/gtk/timestamp_format/use_dates/log", "automatic"); | |
183 } | |
184 | |
185 GAIM_INIT_PLUGIN(timestamp_format, init_plugin, info) |