Mercurial > pidgin.yaz
annotate plugins/timestamp_format.c @ 14088:223570831b0b
[gaim-migrate @ 16711]
Get rid of an assert when editing an account that has no icon
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 12 Aug 2006 10:06:15 +0000 |
parents | f94309c7c480 |
children |
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, | |
13987
f94309c7c480
[gaim-migrate @ 16559]
Richard Laager <rlaager@wiktel.com>
parents:
13114
diff
changeset
|
55 time_t t, |
12737 | 56 gboolean force, |
57 const char *dates) | |
58 { | |
13987
f94309c7c480
[gaim-migrate @ 16559]
Richard Laager <rlaager@wiktel.com>
parents:
13114
diff
changeset
|
59 struct tm *tm = localtime(&t); |
12737 | 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 && | |
12848
d26e3314c650
[gaim-migrate @ 15198]
Richard Laager <rlaager@wiktel.com>
parents:
12737
diff
changeset
|
65 !strcmp(dates, "chats")) || |
13987
f94309c7c480
[gaim-migrate @ 16559]
Richard Laager <rlaager@wiktel.com>
parents:
13114
diff
changeset
|
66 (time(NULL) > (mktime(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, | |
13987
f94309c7c480
[gaim-migrate @ 16559]
Richard Laager <rlaager@wiktel.com>
parents:
13114
diff
changeset
|
81 time_t t, gpointer data) |
12737 | 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 |
13987
f94309c7c480
[gaim-migrate @ 16559]
Richard Laager <rlaager@wiktel.com>
parents:
13114
diff
changeset
|
90 return timestamp_cb_common(conv, t, force, dates); |
12737 | 91 } |
92 | |
13987
f94309c7c480
[gaim-migrate @ 16559]
Richard Laager <rlaager@wiktel.com>
parents:
13114
diff
changeset
|
93 static char *log_timestamp_cb(GaimLog *log, time_t t, gpointer data) |
12737 | 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 | |
13054
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
100 g_return_val_if_fail(log != NULL, NULL); |
fd57413bc421
[gaim-migrate @ 15416]
Richard Laager <rlaager@wiktel.com>
parents:
12851
diff
changeset
|
101 |
12737 | 102 if (log->type == GAIM_LOG_SYSTEM) |
103 { | |
13987
f94309c7c480
[gaim-migrate @ 16559]
Richard Laager <rlaager@wiktel.com>
parents:
13114
diff
changeset
|
104 if (force) { |
f94309c7c480
[gaim-migrate @ 16559]
Richard Laager <rlaager@wiktel.com>
parents:
13114
diff
changeset
|
105 struct tm *tm = localtime(&t); |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13089
diff
changeset
|
106 return g_strdup(gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", tm)); |
13987
f94309c7c480
[gaim-migrate @ 16559]
Richard Laager <rlaager@wiktel.com>
parents:
13114
diff
changeset
|
107 } else { |
12737 | 108 return NULL; |
13987
f94309c7c480
[gaim-migrate @ 16559]
Richard Laager <rlaager@wiktel.com>
parents:
13114
diff
changeset
|
109 } |
12737 | 110 } |
111 | |
13987
f94309c7c480
[gaim-migrate @ 16559]
Richard Laager <rlaager@wiktel.com>
parents:
13114
diff
changeset
|
112 return timestamp_cb_common(log->conv, t, force, dates); |
12737 | 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) |