Mercurial > pidgin.yaz
comparison libpurple/plugins/joinpart.c @ 15823:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 3b6ce2116f74 |
children | 4999bbc52881 |
comparison
equal
deleted
inserted
replaced
15822:84b0f9b23ede | 15823:32c366eeeb99 |
---|---|
1 /** | 1 /** |
2 * gaim | 2 * purple |
3 * | 3 * |
4 * Gaim is the legal property of its developers, whose names are too numerous | 4 * Purple is the legal property of its developers, whose names are too numerous |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | 5 * to list here. Please refer to the COPYRIGHT file distributed with this |
6 * source distribution. | 6 * source distribution. |
7 * | 7 * |
8 * This program is free software; you can redistribute it and/or modify | 8 * This program is free software; you can redistribute it and/or modify |
9 * it under the terms of the GNU General Public License as published by | 9 * it under the terms of the GNU General Public License as published by |
41 #define THRESHOLD_PREF "/plugins/core/joinpart/threshold" | 41 #define THRESHOLD_PREF "/plugins/core/joinpart/threshold" |
42 #define THRESHOLD_DEFAULT 20 | 42 #define THRESHOLD_DEFAULT 20 |
43 | 43 |
44 struct joinpart_key | 44 struct joinpart_key |
45 { | 45 { |
46 GaimConversation *conv; | 46 PurpleConversation *conv; |
47 char *user; | 47 char *user; |
48 }; | 48 }; |
49 | 49 |
50 static guint joinpart_key_hash(const struct joinpart_key *key) | 50 static guint joinpart_key_hash(const struct joinpart_key *key) |
51 { | 51 { |
70 | 70 |
71 g_free(key->user); | 71 g_free(key->user); |
72 g_free(key); | 72 g_free(key); |
73 } | 73 } |
74 | 74 |
75 static gboolean should_hide_notice(GaimConversation *conv, const char *name, | 75 static gboolean should_hide_notice(PurpleConversation *conv, const char *name, |
76 GHashTable *users) | 76 GHashTable *users) |
77 { | 77 { |
78 GaimConvChat *chat; | 78 PurpleConvChat *chat; |
79 int threshold; | 79 int threshold; |
80 struct joinpart_key *key; | 80 struct joinpart_key *key; |
81 time_t *last_said; | 81 time_t *last_said; |
82 | 82 |
83 g_return_val_if_fail(conv != NULL, FALSE); | 83 g_return_val_if_fail(conv != NULL, FALSE); |
84 g_return_val_if_fail(gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_CHAT, FALSE); | 84 g_return_val_if_fail(purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT, FALSE); |
85 | 85 |
86 /* If the room is small, don't bother. */ | 86 /* If the room is small, don't bother. */ |
87 chat = GAIM_CONV_CHAT(conv); | 87 chat = PURPLE_CONV_CHAT(conv); |
88 threshold = gaim_prefs_get_int(THRESHOLD_PREF); | 88 threshold = purple_prefs_get_int(THRESHOLD_PREF); |
89 if (g_list_length(gaim_conv_chat_get_users(chat)) < threshold) | 89 if (g_list_length(purple_conv_chat_get_users(chat)) < threshold) |
90 return FALSE; | 90 return FALSE; |
91 | 91 |
92 /* We always care about our buddies! */ | 92 /* We always care about our buddies! */ |
93 if (gaim_find_buddy(gaim_conversation_get_account(conv), name)) | 93 if (purple_find_buddy(purple_conversation_get_account(conv), name)) |
94 return FALSE; | 94 return FALSE; |
95 | 95 |
96 /* Only show the notice if the user has spoken recently. */ | 96 /* Only show the notice if the user has spoken recently. */ |
97 key = g_new(struct joinpart_key, 1); | 97 key = g_new(struct joinpart_key, 1); |
98 key->conv = conv; | 98 key->conv = conv; |
99 key->user = g_strdup(name); | 99 key->user = g_strdup(name); |
100 last_said = g_hash_table_lookup(users, key); | 100 last_said = g_hash_table_lookup(users, key); |
101 if (last_said != NULL) | 101 if (last_said != NULL) |
102 { | 102 { |
103 int delay = gaim_prefs_get_int(DELAY_PREF); | 103 int delay = purple_prefs_get_int(DELAY_PREF); |
104 if (delay > 0 && (*last_said + (delay * 60)) >= time(NULL)) | 104 if (delay > 0 && (*last_said + (delay * 60)) >= time(NULL)) |
105 return FALSE; | 105 return FALSE; |
106 } | 106 } |
107 | 107 |
108 return TRUE; | 108 return TRUE; |
109 } | 109 } |
110 | 110 |
111 static gboolean chat_buddy_leaving_cb(GaimConversation *conv, const char *name, | 111 static gboolean chat_buddy_leaving_cb(PurpleConversation *conv, const char *name, |
112 const char *reason, GHashTable *users) | 112 const char *reason, GHashTable *users) |
113 { | 113 { |
114 return should_hide_notice(conv, name, users); | 114 return should_hide_notice(conv, name, users); |
115 } | 115 } |
116 | 116 |
117 static gboolean chat_buddy_joining_cb(GaimConversation *conv, const char *name, | 117 static gboolean chat_buddy_joining_cb(PurpleConversation *conv, const char *name, |
118 GaimConvChatBuddyFlags flags, | 118 PurpleConvChatBuddyFlags flags, |
119 GHashTable *users) | 119 GHashTable *users) |
120 { | 120 { |
121 return should_hide_notice(conv, name, users); | 121 return should_hide_notice(conv, name, users); |
122 } | 122 } |
123 | 123 |
124 static void received_chat_msg_cb(GaimAccount *account, char *sender, | 124 static void received_chat_msg_cb(PurpleAccount *account, char *sender, |
125 char *message, GaimConversation *conv, | 125 char *message, PurpleConversation *conv, |
126 GaimMessageFlags flags, GHashTable *users) | 126 PurpleMessageFlags flags, GHashTable *users) |
127 { | 127 { |
128 struct joinpart_key key; | 128 struct joinpart_key key; |
129 time_t *last_said; | 129 time_t *last_said; |
130 | 130 |
131 /* Most of the time, we'll already have tracked the user, | 131 /* Most of the time, we'll already have tracked the user, |
154 } | 154 } |
155 | 155 |
156 static gboolean check_expire_time(struct joinpart_key *key, | 156 static gboolean check_expire_time(struct joinpart_key *key, |
157 time_t *last_said, time_t *limit) | 157 time_t *last_said, time_t *limit) |
158 { | 158 { |
159 gaim_debug_info("joinpart", "Removing key for %s/%s\n", key->conv->name, key->user); | 159 purple_debug_info("joinpart", "Removing key for %s/%s\n", key->conv->name, key->user); |
160 return (*last_said < *limit); | 160 return (*last_said < *limit); |
161 } | 161 } |
162 | 162 |
163 static gboolean clean_users_hash(GHashTable *users) | 163 static gboolean clean_users_hash(GHashTable *users) |
164 { | 164 { |
165 int delay = gaim_prefs_get_int(DELAY_PREF); | 165 int delay = purple_prefs_get_int(DELAY_PREF); |
166 time_t limit = time(NULL) - (60 * delay); | 166 time_t limit = time(NULL) - (60 * delay); |
167 | 167 |
168 g_hash_table_foreach_remove(users, (GHRFunc)check_expire_time, &limit); | 168 g_hash_table_foreach_remove(users, (GHRFunc)check_expire_time, &limit); |
169 | 169 |
170 return TRUE; | 170 return TRUE; |
171 } | 171 } |
172 | 172 |
173 static gboolean plugin_load(GaimPlugin *plugin) | 173 static gboolean plugin_load(PurplePlugin *plugin) |
174 { | 174 { |
175 void *conv_handle; | 175 void *conv_handle; |
176 GHashTable *users; | 176 GHashTable *users; |
177 guint id; | 177 guint id; |
178 gpointer *data; | 178 gpointer *data; |
180 users = g_hash_table_new_full((GHashFunc)joinpart_key_hash, | 180 users = g_hash_table_new_full((GHashFunc)joinpart_key_hash, |
181 (GEqualFunc)joinpart_key_equal, | 181 (GEqualFunc)joinpart_key_equal, |
182 (GDestroyNotify)joinpart_key_destroy, | 182 (GDestroyNotify)joinpart_key_destroy, |
183 g_free); | 183 g_free); |
184 | 184 |
185 conv_handle = gaim_conversations_get_handle(); | 185 conv_handle = purple_conversations_get_handle(); |
186 gaim_signal_connect(conv_handle, "chat-buddy-joining", plugin, | 186 purple_signal_connect(conv_handle, "chat-buddy-joining", plugin, |
187 GAIM_CALLBACK(chat_buddy_joining_cb), users); | 187 PURPLE_CALLBACK(chat_buddy_joining_cb), users); |
188 gaim_signal_connect(conv_handle, "chat-buddy-leaving", plugin, | 188 purple_signal_connect(conv_handle, "chat-buddy-leaving", plugin, |
189 GAIM_CALLBACK(chat_buddy_leaving_cb), users); | 189 PURPLE_CALLBACK(chat_buddy_leaving_cb), users); |
190 gaim_signal_connect(conv_handle, "received-chat-msg", plugin, | 190 purple_signal_connect(conv_handle, "received-chat-msg", plugin, |
191 GAIM_CALLBACK(received_chat_msg_cb), users); | 191 PURPLE_CALLBACK(received_chat_msg_cb), users); |
192 | 192 |
193 /* Cleanup every 5 minutes */ | 193 /* Cleanup every 5 minutes */ |
194 id = gaim_timeout_add(1000 * 60 * 5, (GSourceFunc)clean_users_hash, users); | 194 id = purple_timeout_add(1000 * 60 * 5, (GSourceFunc)clean_users_hash, users); |
195 | 195 |
196 data = g_new(gpointer, 2); | 196 data = g_new(gpointer, 2); |
197 data[0] = users; | 197 data[0] = users; |
198 data[1] = GUINT_TO_POINTER(id); | 198 data[1] = GUINT_TO_POINTER(id); |
199 plugin->extra = data; | 199 plugin->extra = data; |
200 | 200 |
201 return TRUE; | 201 return TRUE; |
202 } | 202 } |
203 | 203 |
204 static gboolean plugin_unload(GaimPlugin *plugin) | 204 static gboolean plugin_unload(PurplePlugin *plugin) |
205 { | 205 { |
206 gpointer *data = plugin->extra; | 206 gpointer *data = plugin->extra; |
207 | 207 |
208 /* Destroy the hash table. The core plugin code will | 208 /* Destroy the hash table. The core plugin code will |
209 * disconnect the signals, and since Gaim is single-threaded, | 209 * disconnect the signals, and since Purple is single-threaded, |
210 * we don't have to worry one will be called after this. */ | 210 * we don't have to worry one will be called after this. */ |
211 g_hash_table_destroy((GHashTable *)data[0]); | 211 g_hash_table_destroy((GHashTable *)data[0]); |
212 | 212 |
213 g_source_remove(GPOINTER_TO_UINT(data[1])); | 213 g_source_remove(GPOINTER_TO_UINT(data[1])); |
214 g_free(data); | 214 g_free(data); |
215 | 215 |
216 return TRUE; | 216 return TRUE; |
217 } | 217 } |
218 | 218 |
219 static GaimPluginPrefFrame * | 219 static PurplePluginPrefFrame * |
220 get_plugin_pref_frame(GaimPlugin *plugin) | 220 get_plugin_pref_frame(PurplePlugin *plugin) |
221 { | 221 { |
222 GaimPluginPrefFrame *frame; | 222 PurplePluginPrefFrame *frame; |
223 GaimPluginPref *ppref; | 223 PurplePluginPref *ppref; |
224 | 224 |
225 g_return_val_if_fail(plugin != NULL, FALSE); | 225 g_return_val_if_fail(plugin != NULL, FALSE); |
226 | 226 |
227 frame = gaim_plugin_pref_frame_new(); | 227 frame = purple_plugin_pref_frame_new(); |
228 | 228 |
229 ppref = gaim_plugin_pref_new_with_label(_("Join/Part Hiding Configuration")); | 229 ppref = purple_plugin_pref_new_with_label(_("Join/Part Hiding Configuration")); |
230 gaim_plugin_pref_frame_add(frame, ppref); | 230 purple_plugin_pref_frame_add(frame, ppref); |
231 | 231 |
232 ppref = gaim_plugin_pref_new_with_name_and_label(THRESHOLD_PREF, | 232 ppref = purple_plugin_pref_new_with_name_and_label(THRESHOLD_PREF, |
233 _("Minimum Room Size")); | 233 _("Minimum Room Size")); |
234 gaim_plugin_pref_set_bounds(ppref, 0, 1000); | 234 purple_plugin_pref_set_bounds(ppref, 0, 1000); |
235 gaim_plugin_pref_frame_add(frame, ppref); | 235 purple_plugin_pref_frame_add(frame, ppref); |
236 | 236 |
237 | 237 |
238 ppref = gaim_plugin_pref_new_with_name_and_label(DELAY_PREF, | 238 ppref = purple_plugin_pref_new_with_name_and_label(DELAY_PREF, |
239 _("User Inactivity Timeout (in minutes)")); | 239 _("User Inactivity Timeout (in minutes)")); |
240 gaim_plugin_pref_set_bounds(ppref, 0, 8 * 60); /* 8 Hours */ | 240 purple_plugin_pref_set_bounds(ppref, 0, 8 * 60); /* 8 Hours */ |
241 gaim_plugin_pref_frame_add(frame, ppref); | 241 purple_plugin_pref_frame_add(frame, ppref); |
242 | 242 |
243 return frame; | 243 return frame; |
244 } | 244 } |
245 | 245 |
246 static GaimPluginUiInfo prefs_info = { | 246 static PurplePluginUiInfo prefs_info = { |
247 get_plugin_pref_frame, | 247 get_plugin_pref_frame, |
248 0, /* page_num (reserved) */ | 248 0, /* page_num (reserved) */ |
249 NULL /* frame (reserved) */ | 249 NULL /* frame (reserved) */ |
250 }; | 250 }; |
251 | 251 |
252 static GaimPluginInfo info = | 252 static PurplePluginInfo info = |
253 { | 253 { |
254 GAIM_PLUGIN_MAGIC, | 254 PURPLE_PLUGIN_MAGIC, |
255 GAIM_MAJOR_VERSION, | 255 PURPLE_MAJOR_VERSION, |
256 GAIM_MINOR_VERSION, | 256 PURPLE_MINOR_VERSION, |
257 GAIM_PLUGIN_STANDARD, /**< type */ | 257 PURPLE_PLUGIN_STANDARD, /**< type */ |
258 NULL, /**< ui_requirement */ | 258 NULL, /**< ui_requirement */ |
259 0, /**< flags */ | 259 0, /**< flags */ |
260 NULL, /**< dependencies */ | 260 NULL, /**< dependencies */ |
261 GAIM_PRIORITY_DEFAULT, /**< priority */ | 261 PURPLE_PRIORITY_DEFAULT, /**< priority */ |
262 | 262 |
263 JOINPART_PLUGIN_ID, /**< id */ | 263 JOINPART_PLUGIN_ID, /**< id */ |
264 N_("Join/Part Hiding"), /**< name */ | 264 N_("Join/Part Hiding"), /**< name */ |
265 VERSION, /**< version */ | 265 VERSION, /**< version */ |
266 /** summary */ | 266 /** summary */ |
268 /** description */ | 268 /** description */ |
269 N_("This plugin hides join/part messages in large " | 269 N_("This plugin hides join/part messages in large " |
270 "rooms, except for those users actively taking " | 270 "rooms, except for those users actively taking " |
271 "part in a conversation."), | 271 "part in a conversation."), |
272 "Richard Laager <rlaager@pidgin.im>", /**< author */ | 272 "Richard Laager <rlaager@pidgin.im>", /**< author */ |
273 GAIM_WEBSITE, /**< homepage */ | 273 PURPLE_WEBSITE, /**< homepage */ |
274 | 274 |
275 plugin_load, /**< load */ | 275 plugin_load, /**< load */ |
276 plugin_unload, /**< unload */ | 276 plugin_unload, /**< unload */ |
277 NULL, /**< destroy */ | 277 NULL, /**< destroy */ |
278 | 278 |
281 &prefs_info, /**< prefs_info */ | 281 &prefs_info, /**< prefs_info */ |
282 NULL /**< actions */ | 282 NULL /**< actions */ |
283 }; | 283 }; |
284 | 284 |
285 static void | 285 static void |
286 init_plugin(GaimPlugin *plugin) | 286 init_plugin(PurplePlugin *plugin) |
287 { | 287 { |
288 gaim_prefs_add_none("/plugins/core/joinpart"); | 288 purple_prefs_add_none("/plugins/core/joinpart"); |
289 | 289 |
290 gaim_prefs_add_int(DELAY_PREF, DELAY_DEFAULT); | 290 purple_prefs_add_int(DELAY_PREF, DELAY_DEFAULT); |
291 gaim_prefs_add_int(THRESHOLD_PREF, THRESHOLD_DEFAULT); | 291 purple_prefs_add_int(THRESHOLD_PREF, THRESHOLD_DEFAULT); |
292 } | 292 } |
293 | 293 |
294 GAIM_INIT_PLUGIN(joinpart, init_plugin, info) | 294 PURPLE_INIT_PLUGIN(joinpart, init_plugin, info) |