|
14266
|
1 /*
|
|
|
2 * Contact Availability Prediction plugin for Gaim
|
|
|
3 *
|
|
|
4 * Copyright (C) 2006 Geoffrey Foster.
|
|
|
5 *
|
|
|
6 * This program is free software; you can redistribute it and/or
|
|
|
7 * modify it under the terms of the GNU General Public License as
|
|
|
8 * published by the Free Software Foundation; either version 2 of the
|
|
|
9 * License, or (at your option) any later version.
|
|
|
10 *
|
|
|
11 * This program is distributed in the hope that it will be useful, but
|
|
|
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
14 * General Public License for more details.
|
|
|
15 *
|
|
|
16 * You should have received a copy of the GNU General Public License
|
|
|
17 * along with this program; if not, write to the Free Software
|
|
|
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
19 * 02111-1307, USA.
|
|
|
20 */
|
|
|
21
|
|
|
22 #include "cap.h"
|
|
|
23
|
|
|
24 static void generate_prediction(CapStatistics *statistics) {
|
|
|
25 if(statistics->buddy) {
|
|
|
26 if(statistics->prediction == NULL)
|
|
|
27 statistics->prediction = g_malloc(sizeof(CapPrediction));
|
|
|
28 statistics->prediction->probability = generate_prediction_for(statistics->buddy);
|
|
|
29 statistics->prediction->generated_at = time(NULL);
|
|
|
30 }
|
|
|
31 }
|
|
|
32
|
|
|
33 static double generate_prediction_for(GaimBuddy *buddy) {
|
|
|
34 double prediction = 1.0f;
|
|
|
35 gboolean generated = FALSE;
|
|
14511
|
36 gchar *buddy_name = buddy->name;
|
|
|
37 const gchar *protocol_id = gaim_account_get_protocol_id(buddy->account);
|
|
|
38 const gchar *account_id = gaim_account_get_username(buddy->account);
|
|
|
39 const gchar *status_id = gaim_status_get_id(get_status_for(buddy));
|
|
14266
|
40 time_t t = time(NULL);
|
|
|
41 struct tm *current_time = localtime(&t);
|
|
|
42 int current_minute = current_time->tm_min + current_time->tm_hour * 60;
|
|
|
43 int threshold = gaim_prefs_get_int("/plugins/gtk/cap/threshold");
|
|
|
44 int min_minute = (current_minute - threshold) % 1440;
|
|
|
45 int max_minute = (current_minute + threshold) % 1440;
|
|
14511
|
46 char *sql;
|
|
|
47 sqlite3_stmt *stmt = NULL;
|
|
|
48 const char *tail = NULL;
|
|
|
49 int rc;
|
|
14266
|
50
|
|
|
51
|
|
14511
|
52 sql = sqlite3_mprintf("select sum(success_count) as successes, sum(failed_count) as failures "
|
|
|
53 "from cap_msg_count where "
|
|
|
54 "buddy=%Q and account=%Q and protocol=%Q and minute_val>=%d and minute_val<=%d;",
|
|
|
55 buddy_name, account_id, protocol_id, min_minute, max_minute);
|
|
|
56 rc = sqlite3_prepare(_db, sql, -1, &stmt, &tail);
|
|
|
57 if(rc == SQLITE_OK) {
|
|
14266
|
58 int successes = 0;
|
|
|
59 int failures = 0;
|
|
14511
|
60 if(stmt != NULL) {
|
|
|
61 if(sqlite3_step(stmt) == SQLITE_ROW) {
|
|
|
62 successes = sqlite3_column_int(stmt, 0);
|
|
|
63 failures = sqlite3_column_int(stmt, 1);
|
|
|
64 if(failures + successes > 0) {
|
|
|
65 prediction *= ((double)successes/((double)(successes+failures)));
|
|
|
66 generated = TRUE;
|
|
|
67 }
|
|
|
68 }
|
|
|
69 sqlite3_finalize(stmt);
|
|
|
70 }
|
|
|
71 }
|
|
|
72 sqlite3_free(sql);
|
|
14266
|
73
|
|
14511
|
74 sql = sqlite3_mprintf("select sum(success_count) as successes, sum(failed_count) as failures "
|
|
|
75 "from cap_status_count where "
|
|
|
76 "buddy=%Q and account=%Q and protocol=%Q and status=%Q;",
|
|
|
77 buddy_name, account_id, protocol_id, status_id);
|
|
|
78 rc = sqlite3_prepare(_db, sql, -1, &stmt, &tail);
|
|
|
79 if(rc == SQLITE_OK) {
|
|
|
80 int successes = 0;
|
|
|
81 int failures = 0;
|
|
|
82 if(stmt != NULL) {
|
|
|
83 if(sqlite3_step(stmt) == SQLITE_ROW) {
|
|
|
84 successes = sqlite3_column_int(stmt, 0);
|
|
|
85 failures = sqlite3_column_int(stmt, 1);
|
|
|
86 if(failures + successes > 0) {
|
|
|
87 prediction *= ((double)successes/((double)(successes+failures)));
|
|
|
88 generated = TRUE;
|
|
|
89 }
|
|
|
90 }
|
|
|
91 sqlite3_finalize(stmt);
|
|
14266
|
92 }
|
|
|
93 }
|
|
14511
|
94 sqlite3_free(sql);
|
|
14266
|
95
|
|
14511
|
96
|
|
14266
|
97 if(strcmp(gaim_status_get_id(get_status_for(buddy)), "offline") == 0) {
|
|
14516
|
98 /* This is kind of stupid, change it. */
|
|
14266
|
99 if(prediction == 1.0f)
|
|
|
100 prediction = 0.0f;
|
|
|
101 }
|
|
|
102
|
|
|
103 if(generated)
|
|
|
104 return prediction;
|
|
|
105 else
|
|
|
106 return -1;
|
|
|
107 }
|
|
|
108
|
|
|
109 static CapStatistics * get_stats_for(GaimBuddy *buddy) {
|
|
|
110 gchar *buddy_name;
|
|
|
111 CapStatistics *stats;
|
|
|
112 buddy_name = g_strdup(buddy->name);
|
|
|
113 stats = g_hash_table_lookup(_buddy_stats, buddy_name);
|
|
|
114 if(!stats) {
|
|
|
115 stats = g_malloc(sizeof(CapStatistics));
|
|
|
116 stats->last_message = -1;
|
|
|
117 stats->last_message_status_id = NULL;
|
|
|
118 stats->last_status_id = NULL;
|
|
|
119 stats->prediction = NULL;
|
|
|
120 g_hash_table_insert(_buddy_stats, buddy_name, stats);
|
|
|
121 stats->buddy = buddy;
|
|
14511
|
122 stats->last_seen = -1;
|
|
|
123 stats->last_status_id = "";
|
|
14266
|
124 } else {
|
|
|
125 g_free(buddy_name);
|
|
|
126 }
|
|
|
127 generate_prediction(stats);
|
|
|
128 return stats;
|
|
|
129 }
|
|
|
130
|
|
|
131 static void destroy_stats(gpointer data) {
|
|
|
132 CapStatistics *stats = data;
|
|
|
133 g_free(stats->prediction);
|
|
14516
|
134 /* g_free(stats->hourly_usage); */
|
|
|
135 /* g_free(stats->daily_usage); */
|
|
14266
|
136 g_free(stats);
|
|
|
137 }
|
|
|
138
|
|
14511
|
139 static void
|
|
|
140 insert_cap_msg_count_success(const char *buddy_name, const char *account, const char *protocol, int minute) {
|
|
|
141 int rc;
|
|
|
142 sqlite3_stmt *stmt;
|
|
|
143 const char *tail;
|
|
|
144 char *sql_select = sqlite3_mprintf("SELECT * FROM cap_msg_count WHERE "
|
|
|
145 "buddy=%Q AND account=%Q AND protocol=%Q AND minute_val=%d;",
|
|
|
146 buddy_name, account, protocol, minute);
|
|
|
147 char *sql_ins_up = NULL;
|
|
|
148
|
|
|
149 gaim_debug_info("cap", "%s\n", sql_select);
|
|
|
150
|
|
|
151 sqlite3_prepare(_db, sql_select, -1, &stmt, &tail);
|
|
|
152
|
|
|
153 rc = sqlite3_step(stmt);
|
|
14266
|
154
|
|
14511
|
155 if(rc == SQLITE_DONE) {
|
|
|
156 sql_ins_up = sqlite3_mprintf("INSERT INTO cap_msg_count VALUES (%Q, %Q, %Q, %d, %d, %d);",
|
|
|
157 buddy_name, account, protocol, minute, 1, 0);
|
|
|
158 } else if(rc == SQLITE_ROW) {
|
|
|
159 sql_ins_up = sqlite3_mprintf("UPDATE cap_msg_count SET success_count=success_count+1 WHERE "
|
|
|
160 "buddy=%Q AND account=%Q AND protocol=%Q AND minute_val=%d;",
|
|
|
161 buddy_name, account, protocol, minute);
|
|
|
162 } else {
|
|
|
163 gaim_debug_info("cap", "%d\n", rc);
|
|
|
164 sqlite3_finalize(stmt);
|
|
|
165 sqlite3_free(sql_select);
|
|
|
166 return;
|
|
|
167 }
|
|
|
168
|
|
|
169 sqlite3_finalize(stmt);
|
|
|
170 sqlite3_free(sql_select);
|
|
|
171
|
|
|
172 sqlite3_exec(_db, sql_ins_up, NULL, NULL, NULL);
|
|
|
173 sqlite3_free(sql_ins_up);
|
|
14266
|
174 }
|
|
|
175
|
|
14511
|
176 static void
|
|
|
177 insert_cap_status_count_success(const char *buddy_name, const char *account, const char *protocol, const char *status_id) {
|
|
|
178 int rc;
|
|
|
179 sqlite3_stmt *stmt;
|
|
|
180 const char *tail;
|
|
|
181 char *sql_select = sqlite3_mprintf("SELECT * FROM cap_status_count WHERE "
|
|
|
182 "buddy=%Q AND account=%Q AND protocol=%Q AND status=%Q;",
|
|
|
183 buddy_name, account, protocol, status_id);
|
|
|
184 char *sql_ins_up = NULL;
|
|
|
185
|
|
|
186 gaim_debug_info("cap", "%s\n", sql_select);
|
|
|
187
|
|
|
188 sqlite3_prepare(_db, sql_select, -1, &stmt, &tail);
|
|
|
189
|
|
|
190 rc = sqlite3_step(stmt);
|
|
|
191
|
|
|
192 if(rc == SQLITE_DONE) {
|
|
|
193 sql_ins_up = sqlite3_mprintf("INSERT INTO cap_status_count VALUES (%Q, %Q, %Q, %Q, %d, %d);",
|
|
|
194 buddy_name, account, protocol, status_id, 1, 0);
|
|
|
195 } else if(rc == SQLITE_ROW) {
|
|
|
196 sql_ins_up = sqlite3_mprintf("UPDATE cap_status_count SET success_count=success_count+1 WHERE "
|
|
|
197 "buddy=%Q AND account=%Q AND protocol=%Q AND status=%Q;",
|
|
|
198 buddy_name, account, protocol, status_id);
|
|
|
199 } else {
|
|
|
200 gaim_debug_info("cap", "%d\n", rc);
|
|
|
201 sqlite3_finalize(stmt);
|
|
|
202 sqlite3_free(sql_select);
|
|
|
203 return;
|
|
|
204 }
|
|
|
205
|
|
|
206 sqlite3_finalize(stmt);
|
|
|
207 sqlite3_free(sql_select);
|
|
|
208
|
|
|
209 sqlite3_exec(_db, sql_ins_up, NULL, NULL, NULL);
|
|
|
210 sqlite3_free(sql_ins_up);
|
|
14266
|
211 }
|
|
|
212
|
|
14511
|
213 static void
|
|
|
214 insert_cap_msg_count_failed(const char *buddy_name, const char *account, const char *protocol, int minute) {
|
|
|
215 int rc;
|
|
|
216 sqlite3_stmt *stmt;
|
|
|
217 const char *tail;
|
|
|
218 char *sql_select = sqlite3_mprintf("SELECT * FROM cap_msg_count WHERE "
|
|
|
219 "buddy=%Q AND account=%Q AND protocol=%Q AND minute_val=%d;",
|
|
|
220 buddy_name, account, protocol, minute);
|
|
|
221 char *sql_ins_up = NULL;
|
|
|
222
|
|
|
223 gaim_debug_info("cap", "%s\n", sql_select);
|
|
|
224
|
|
|
225 sqlite3_prepare(_db, sql_select, -1, &stmt, &tail);
|
|
|
226
|
|
|
227 rc = sqlite3_step(stmt);
|
|
|
228
|
|
|
229 if(rc == SQLITE_DONE) {
|
|
|
230 sql_ins_up = sqlite3_mprintf("INSERT INTO cap_msg_count VALUES (%Q, %Q, %Q, %d, %d, %d);",
|
|
|
231 buddy_name, account, protocol, minute, 0, 1);
|
|
|
232 } else if(rc == SQLITE_ROW) {
|
|
|
233 sql_ins_up = sqlite3_mprintf("UPDATE cap_msg_count SET failed_count=failed_count+1 WHERE "
|
|
|
234 "buddy=%Q AND account=%Q AND protocol=%Q AND minute_val=%d;",
|
|
|
235 buddy_name, account, protocol, minute);
|
|
|
236 } else {
|
|
|
237 gaim_debug_info("cap", "%d\n", rc);
|
|
|
238 sqlite3_finalize(stmt);
|
|
|
239 sqlite3_free(sql_select);
|
|
|
240 return;
|
|
|
241 }
|
|
|
242
|
|
|
243 sqlite3_finalize(stmt);
|
|
|
244 sqlite3_free(sql_select);
|
|
|
245
|
|
|
246 sqlite3_exec(_db, sql_ins_up, NULL, NULL, NULL);
|
|
|
247 sqlite3_free(sql_ins_up);
|
|
14266
|
248 }
|
|
|
249
|
|
14511
|
250 static void
|
|
|
251 insert_cap_status_count_failed(const char *buddy_name, const char *account, const char *protocol, const char *status_id) {
|
|
|
252 int rc;
|
|
|
253 sqlite3_stmt *stmt;
|
|
|
254 const char *tail;
|
|
|
255 char *sql_select = sqlite3_mprintf("SELECT * FROM cap_status_count WHERE "
|
|
|
256 "buddy=%Q AND account=%Q AND protocol=%Q AND status=%Q;",
|
|
|
257 buddy_name, account, protocol, status_id);
|
|
|
258 char *sql_ins_up = NULL;
|
|
|
259
|
|
|
260 gaim_debug_info("cap", "%s\n", sql_select);
|
|
|
261
|
|
|
262 sqlite3_prepare(_db, sql_select, -1, &stmt, &tail);
|
|
|
263
|
|
|
264 rc = sqlite3_step(stmt);
|
|
|
265
|
|
|
266 if(rc == SQLITE_DONE) {
|
|
|
267 sql_ins_up = sqlite3_mprintf("INSERT INTO cap_status_count VALUES (%Q, %Q, %Q, %Q, %d, %d);",
|
|
|
268 buddy_name, account, protocol, status_id, 0, 1);
|
|
|
269 } else if(rc == SQLITE_ROW) {
|
|
|
270 sql_ins_up = sqlite3_mprintf("UPDATE cap_status_count SET failed_count=failed_count+1 WHERE "
|
|
|
271 "buddy=%Q AND account=%Q AND protocol=%Q AND status=%Q;",
|
|
|
272 buddy_name, account, protocol, status_id);
|
|
|
273 } else {
|
|
|
274 gaim_debug_info("cap", "%d\n", rc);
|
|
|
275 sqlite3_finalize(stmt);
|
|
|
276 sqlite3_free(sql_select);
|
|
|
277 return;
|
|
|
278 }
|
|
|
279
|
|
|
280 sqlite3_finalize(stmt);
|
|
|
281 sqlite3_free(sql_select);
|
|
|
282
|
|
|
283 sqlite3_exec(_db, sql_ins_up, NULL, NULL, NULL);
|
|
|
284 sqlite3_free(sql_ins_up);
|
|
14266
|
285 }
|
|
|
286
|
|
|
287 static void insert_cap_success(CapStatistics *stats) {
|
|
14511
|
288 gchar *buddy_name = stats->buddy->name;
|
|
|
289 const gchar *protocol_id = gaim_account_get_protocol_id(stats->buddy->account);
|
|
|
290 const gchar *account_id = gaim_account_get_username(stats->buddy->account);
|
|
|
291 const gchar *status_id = (stats->last_message_status_id) ?
|
|
|
292 stats->last_message_status_id :
|
|
|
293 gaim_status_get_id(get_status_for(stats->buddy));
|
|
14266
|
294 struct tm *current_time;
|
|
|
295 int minute;
|
|
|
296
|
|
|
297 if(stats->last_message == -1) {
|
|
|
298 time_t now = time(NULL);
|
|
|
299 current_time = localtime(&now);
|
|
|
300 } else {
|
|
|
301 current_time = localtime(&stats->last_message);
|
|
|
302 }
|
|
|
303 minute = current_time->tm_min + current_time->tm_hour * 60;
|
|
|
304
|
|
14511
|
305 insert_cap_msg_count_success(buddy_name, account_id, protocol_id, minute);
|
|
14266
|
306
|
|
14511
|
307 insert_cap_status_count_success(buddy_name, account_id, protocol_id, status_id);
|
|
14266
|
308
|
|
|
309 stats->last_message = -1;
|
|
|
310 stats->last_message_status_id = NULL;
|
|
|
311 }
|
|
|
312
|
|
|
313 static void insert_cap_failure(CapStatistics *stats) {
|
|
14511
|
314 gchar *buddy_name = stats->buddy->name;
|
|
|
315 const gchar *protocol_id = gaim_account_get_protocol_id(stats->buddy->account);
|
|
|
316 const gchar *account_id = gaim_account_get_username(stats->buddy->account);
|
|
|
317 const gchar *status_id = (stats->last_message_status_id) ?
|
|
|
318 stats->last_message_status_id :
|
|
|
319 gaim_status_get_id(get_status_for(stats->buddy));
|
|
14266
|
320 struct tm *current_time = localtime(&stats->last_message);
|
|
|
321 int minute = current_time->tm_min + current_time->tm_hour * 60;
|
|
|
322
|
|
14511
|
323 insert_cap_msg_count_failed(buddy_name, account_id, protocol_id, minute);
|
|
14266
|
324
|
|
14511
|
325 insert_cap_status_count_failed(buddy_name, account_id, protocol_id, status_id);
|
|
14266
|
326
|
|
|
327 stats->last_message = -1;
|
|
|
328 stats->last_message_status_id = NULL;
|
|
|
329 }
|
|
|
330
|
|
|
331 static gboolean max_message_difference_cb(gpointer data) {
|
|
|
332 CapStatistics *stats = data;
|
|
|
333 gaim_debug_info("cap", "Max Message Difference timeout occured\n");
|
|
|
334 insert_cap_failure(stats);
|
|
|
335 stats->timeout_source_id = 0;
|
|
|
336 return FALSE;
|
|
|
337 }
|
|
|
338
|
|
|
339 /* Gaim Signal Handlers */
|
|
|
340
|
|
14516
|
341 /* sent-im-msg */
|
|
14266
|
342 static void sent_im_msg(GaimAccount *account, const char *receiver, const char *message) {
|
|
|
343 GaimBuddy *buddy = gaim_find_buddy(account, receiver);
|
|
|
344 guint interval = gaim_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 1000 * 60;
|
|
|
345 guint words = word_count(message);
|
|
|
346 CapStatistics *stats = get_stats_for(buddy);
|
|
|
347
|
|
|
348 insert_word_count(gaim_account_get_username(account), receiver, words);
|
|
|
349 stats->last_message = time(NULL);
|
|
|
350 stats->last_message_status_id = gaim_status_get_id(get_status_for(buddy));
|
|
|
351 if(stats->timeout_source_id != 0)
|
|
|
352 g_source_remove(stats->timeout_source_id);
|
|
|
353
|
|
|
354 stats->timeout_source_id = g_timeout_add(interval, max_message_difference_cb, stats);
|
|
|
355 }
|
|
|
356
|
|
14516
|
357 /* received-im-msg */
|
|
14511
|
358 static void
|
|
|
359 received_im_msg(GaimAccount *account, char *sender, char *message, GaimConversation *conv, GaimMessageFlags flags) {
|
|
14266
|
360 GaimBuddy *buddy = gaim_find_buddy(account, sender);
|
|
14516
|
361 /* guint words = word_count(message); */
|
|
14266
|
362 CapStatistics *stats = get_stats_for(buddy);
|
|
|
363
|
|
14516
|
364 /* insert_word_count(sender, buddy_name, words); */
|
|
14266
|
365
|
|
14516
|
366 /* If we are waiting for a response from a prior message
|
|
|
367 * then cancel the timeout callback. */
|
|
14266
|
368 if(stats->timeout_source_id != 0) {
|
|
|
369 gaim_debug_info("cap", "Cancelling timeout callback\n");
|
|
|
370 g_source_remove(stats->timeout_source_id);
|
|
|
371 stats->timeout_source_id = 0;
|
|
|
372 }
|
|
|
373
|
|
|
374 insert_cap_success(stats);
|
|
|
375
|
|
14516
|
376 /* Reset the last_message value */
|
|
|
377 stats->last_message = -1;
|
|
|
378 /* Reset the last status id value */
|
|
|
379 stats->last_message_status_id = NULL;
|
|
14266
|
380 }
|
|
|
381
|
|
14516
|
382 /* buddy-status-changed */
|
|
14266
|
383 static void buddy_status_changed(GaimBuddy *buddy, GaimStatus *old_status, GaimStatus *status) {
|
|
|
384 CapStatistics *stats = get_stats_for(buddy);
|
|
|
385 insert_status_change_from_gaim_status(stats, status);
|
|
|
386 }
|
|
|
387
|
|
14516
|
388 /* buddy-signed-on */
|
|
14266
|
389 static void buddy_signed_on(GaimBuddy *buddy) {
|
|
|
390 CapStatistics *stats = get_stats_for(buddy);
|
|
|
391
|
|
|
392 /* If the statistic object existed but doesn't have a buddy pointer associated
|
|
|
393 * with it then reassociate one with it. The pointer being null is a result
|
|
14516
|
394 * of a buddy with existing stats signing off and Gaim sticking around. */
|
|
14266
|
395 if(!stats->buddy) {
|
|
|
396 stats->buddy = buddy;
|
|
|
397 }
|
|
|
398
|
|
|
399 insert_status_change(stats);
|
|
|
400 }
|
|
|
401
|
|
14516
|
402 /* buddy-signed-off */
|
|
14266
|
403 static void buddy_signed_off(GaimBuddy *buddy) {
|
|
|
404 CapStatistics *stats = get_stats_for(buddy);
|
|
|
405
|
|
|
406 /* We don't necessarily want to delete a buddies generated statistics every time they go offline.
|
|
|
407 * Instead we just set the buddy pointer to null so that when they come back online we can look
|
|
|
408 * them up again and continue using their statistics.
|
|
|
409 */
|
|
|
410 insert_status_change(stats);
|
|
14516
|
411 /* stats->buddy = NULL; */
|
|
14266
|
412 stats->last_seen = time(NULL);
|
|
|
413 }
|
|
|
414
|
|
|
415 static void buddy_idle(GaimBuddy *buddy, gboolean old_idle, gboolean idle) {
|
|
|
416 }
|
|
|
417
|
|
|
418 static void blist_node_extended_menu(GaimBlistNode *node, GList **menu) {
|
|
|
419 GaimBuddy *buddy;
|
|
|
420 GaimMenuAction *menu_action;
|
|
|
421 gaim_debug_info("cap", "got extended blist menu\n");
|
|
|
422 gaim_debug_info("cap", "is buddy: %d\n", GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
|
423 gaim_debug_info("cap", "is contact: %d\n", GAIM_BLIST_NODE_IS_CONTACT(node));
|
|
|
424 gaim_debug_info("cap", "is group: %d\n", GAIM_BLIST_NODE_IS_GROUP(node));
|
|
|
425 /* Probably only concerned with buddy/contact types. Contacts = meta-buddies (grouped msn/jabber/etc.) */
|
|
|
426 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
|
427 buddy = (GaimBuddy *)node;
|
|
|
428 menu_action = gaim_menu_action_new(_("Display Statistics"),
|
|
|
429 GAIM_CALLBACK(display_statistics_action_cb), NULL, NULL);
|
|
|
430 *menu = g_list_append(*menu, menu_action);
|
|
|
431 }
|
|
|
432
|
|
14516
|
433 /* drawing-tooltip */
|
|
14266
|
434 static void drawing_tooltip(GaimBlistNode *node, GString *text, gboolean full) {
|
|
|
435 if(node->type == GAIM_BLIST_BUDDY_NODE) {
|
|
|
436 GaimBuddy *buddy = (GaimBuddy *)node;
|
|
|
437 CapStatistics *stats = get_stats_for(buddy);
|
|
14516
|
438 /* get the probability that this buddy will respond and add to the tooltip */
|
|
14266
|
439 if(stats->prediction->probability >= 0.0) {
|
|
14511
|
440 g_string_append_printf(text, "\n<b>%s</b> %3.0f %%", _("Response Probability:"),
|
|
|
441 100 * stats->prediction->probability);
|
|
14266
|
442 } else {
|
|
|
443 g_string_append_printf(text, "\n<b>%s</b> ???", _("Response Probability:"));
|
|
|
444 }
|
|
|
445 }
|
|
|
446 }
|
|
|
447
|
|
14516
|
448 /* signed-on */
|
|
14266
|
449 static void signed_on(GaimConnection *gc) {
|
|
|
450 GaimAccount *account = gaim_connection_get_account(gc);
|
|
|
451 const char *my_gaim_name = gaim_account_get_username(account);
|
|
|
452 gchar *my_name = g_strdup(my_gaim_name);
|
|
|
453 time_t *last_offline = g_hash_table_lookup(_my_offline_times, my_name);
|
|
|
454
|
|
14511
|
455 const gchar *account_id = gaim_account_get_username(account);
|
|
|
456 const gchar *protocol_id = gaim_account_get_protocol_id(account);
|
|
|
457 char *sql;
|
|
14266
|
458
|
|
14511
|
459 sql = sqlite3_mprintf("insert into cap_my_usage values(%Q, %Q, %d, now());", account_id, protocol_id, 1);
|
|
|
460 sqlite3_exec(_db, sql, NULL, NULL, NULL);
|
|
|
461 sqlite3_free(sql);
|
|
14266
|
462
|
|
|
463 if(last_offline) {
|
|
|
464 if(difftime(*last_offline, time(NULL)) > gaim_prefs_get_int("/plugins/gtk/cap/max_seen_difference") * 60) {
|
|
14516
|
465 /* reset all of the last_message times to -1 */
|
|
14266
|
466 g_hash_table_foreach(_my_offline_times, reset_all_last_message_times, NULL);
|
|
|
467 }
|
|
|
468 g_hash_table_remove(_my_offline_times, my_name);
|
|
|
469 }
|
|
|
470 g_free(my_name);
|
|
|
471 }
|
|
|
472
|
|
14516
|
473 /* signed-off */
|
|
14266
|
474 static void signed_off(GaimConnection *gc) {
|
|
|
475 /* Here we record the time you (the user) sign off of an account.
|
|
|
476 * The account username is the key in the hashtable and the sign off time_t
|
|
|
477 * (equal to the sign off time) is the value. */
|
|
|
478 GaimAccount *account = gaim_connection_get_account(gc);
|
|
|
479 const char *my_gaim_name = gaim_account_get_username(account);
|
|
|
480 gchar *my_name = g_strdup(my_gaim_name);
|
|
|
481 time_t *offline_time = g_malloc(sizeof(time_t));
|
|
14511
|
482 const gchar *account_id = gaim_account_get_username(account);
|
|
|
483 const gchar *protocol_id = gaim_account_get_protocol_id(account);
|
|
|
484 char *sql;
|
|
14266
|
485
|
|
14511
|
486 sql = sqlite3_mprintf("insert into cap_my_usage values(%Q, %Q, %d, now());", account_id, protocol_id, 0);
|
|
|
487 sqlite3_exec(_db, sql, NULL, NULL, NULL);
|
|
|
488 sqlite3_free(sql);
|
|
14266
|
489
|
|
|
490 time(offline_time);
|
|
|
491 g_hash_table_insert(_my_offline_times, my_name, offline_time);
|
|
|
492 }
|
|
|
493
|
|
|
494 static void reset_all_last_message_times(gpointer key, gpointer value, gpointer user_data) {
|
|
|
495 CapStatistics *stats = value;
|
|
|
496 stats->last_message = -1;
|
|
|
497 }
|
|
|
498
|
|
|
499 static GaimStatus * get_status_for(GaimBuddy *buddy) {
|
|
|
500 GaimPresence *presence = gaim_buddy_get_presence(buddy);
|
|
|
501 GaimStatus *status = gaim_presence_get_active_status(presence);
|
|
|
502 return status;
|
|
|
503 }
|
|
|
504
|
|
|
505 static void create_tables() {
|
|
14511
|
506 int rc;
|
|
|
507 rc = sqlite3_exec(_db,
|
|
|
508 "CREATE TABLE IF NOT EXISTS cap_status ("
|
|
|
509 " buddy varchar(60) not null,"
|
|
|
510 " account varchar(60) not null,"
|
|
|
511 " protocol varchar(60) not null,"
|
|
|
512 " status varchar(60) not null,"
|
|
|
513 " event_time datetime not null,"
|
|
|
514 " primary key (buddy, account, protocol, event_time)"
|
|
|
515 ");",
|
|
|
516 NULL, NULL, NULL);
|
|
|
517
|
|
|
518 rc = sqlite3_exec(_db,
|
|
|
519 "create table if not exists cap_message ("
|
|
|
520 " sender varchar(60) not null,"
|
|
|
521 " receiver varchar(60) not null,"
|
|
|
522 " account varchar(60) not null,"
|
|
|
523 " protocol varchar(60) not null,"
|
|
|
524 " word_count integer not null,"
|
|
|
525 " event_time datetime not null,"
|
|
|
526 " primary key (sender, account, protocol, receiver, event_time)"
|
|
|
527 ");",
|
|
|
528 NULL, NULL, NULL);
|
|
|
529
|
|
|
530 rc = sqlite3_exec(_db,
|
|
|
531 "create table if not exists cap_msg_count ("
|
|
|
532 " buddy varchar(60) not null,"
|
|
|
533 " account varchar(60) not null,"
|
|
|
534 " protocol varchar(60) not null,"
|
|
|
535 " minute_val int not null,"
|
|
|
536 " success_count int not null,"
|
|
|
537 " failed_count int not null,"
|
|
|
538 " primary key (buddy, account, protocol, minute_val)"
|
|
|
539 ");",
|
|
|
540 NULL, NULL, NULL);
|
|
|
541
|
|
|
542 rc = sqlite3_exec(_db,
|
|
|
543 "create table if not exists cap_status_count ("
|
|
|
544 " buddy varchar(60) not null,"
|
|
|
545 " account varchar(60) not null,"
|
|
|
546 " protocol varchar(60) not null,"
|
|
|
547 " status varchar(60) not null,"
|
|
|
548 " success_count int not null,"
|
|
|
549 " failed_count int not null,"
|
|
|
550 " primary key (buddy, account, protocol, status)"
|
|
|
551 ");",
|
|
|
552 NULL, NULL, NULL);
|
|
|
553
|
|
|
554 rc = sqlite3_exec(_db,
|
|
|
555 "create table if not exists cap_my_usage ("
|
|
|
556 " account varchar(60) not null,"
|
|
|
557 " protocol varchar(60) not null,"
|
|
|
558 " online tinyint not null,"
|
|
|
559 " event_time datetime not null,"
|
|
|
560 " primary key(account, protocol, online, event_time)"
|
|
|
561 ");",
|
|
|
562 NULL, NULL, NULL);
|
|
14266
|
563 }
|
|
|
564
|
|
|
565 static gboolean create_database_connection() {
|
|
14511
|
566 GString *path;
|
|
14266
|
567 int rc;
|
|
14350
|
568
|
|
14511
|
569 if(_db)
|
|
14350
|
570 return TRUE;
|
|
|
571
|
|
14516
|
572 /* build the path */
|
|
14511
|
573 path = g_string_new(gaim_user_dir());
|
|
14513
|
574 g_string_append(path, G_DIR_SEPARATOR_S);
|
|
|
575 g_string_append(path, "cap.db");
|
|
|
576
|
|
14516
|
577 /* make database connection here */
|
|
14511
|
578 rc = sqlite3_open(path->str, &_db);
|
|
14513
|
579 g_string_free(path, TRUE);
|
|
14511
|
580 if(rc != SQLITE_OK)
|
|
14350
|
581 return FALSE;
|
|
|
582
|
|
14516
|
583 /* Add tables here */
|
|
14511
|
584 create_tables();
|
|
14266
|
585 gaim_debug_info("cap", "Database connection successfully made.\n");
|
|
|
586 return TRUE;
|
|
|
587 }
|
|
14350
|
588 static void destroy_database_connection() {
|
|
14511
|
589 if(_db)
|
|
|
590 sqlite3_close(_db);
|
|
14350
|
591
|
|
14511
|
592 _db = NULL;
|
|
14350
|
593 }
|
|
14266
|
594
|
|
|
595 static guint word_count(const gchar *string) {
|
|
14516
|
596 /*TODO: doesn't really work, should use regex instead (#include <regex.h>)*/
|
|
14266
|
597 gchar **result = g_strsplit_set(string, " ", -1);
|
|
|
598 guint count = g_strv_length(result);
|
|
|
599
|
|
|
600 g_strfreev(result);
|
|
|
601
|
|
|
602 return count;
|
|
|
603 }
|
|
|
604
|
|
|
605 static void insert_status_change(CapStatistics *statistics) {
|
|
|
606 insert_status_change_from_gaim_status(statistics, get_status_for(statistics->buddy));
|
|
|
607 }
|
|
|
608
|
|
|
609 static void insert_status_change_from_gaim_status(CapStatistics *statistics, GaimStatus *status) {
|
|
14511
|
610 char *sql;
|
|
|
611 int rc;
|
|
|
612 const gchar *status_id;
|
|
|
613 const gchar *buddy_name;
|
|
|
614 const gchar *protocol_id;
|
|
|
615 const gchar *account_id;
|
|
14350
|
616
|
|
|
617 /* It would seem that some protocols receive periodic updates of the buddies status.
|
|
|
618 * Check to make sure the last status is not the same as current status to prevent
|
|
|
619 * to many duplicated useless database entries. */
|
|
|
620 if(strcmp(statistics->last_status_id, gaim_status_get_id(status)) == 0)
|
|
|
621 return;
|
|
|
622
|
|
14511
|
623 status_id = gaim_status_get_id(status);
|
|
|
624 buddy_name = statistics->buddy->name;
|
|
|
625 protocol_id = gaim_account_get_protocol_id(statistics->buddy->account);
|
|
|
626 account_id = gaim_account_get_username(statistics->buddy->account);
|
|
14266
|
627
|
|
|
628 statistics->last_status_id = gaim_status_get_id(status);
|
|
14511
|
629
|
|
14266
|
630 gaim_debug_info("cap", "Executing: insert into cap_status (buddy, account, protocol, status, event_time) values(%s, %s, %s, %s, now());\n", buddy_name, account_id, protocol_id, status_id);
|
|
|
631
|
|
14511
|
632 sql = sqlite3_mprintf("insert into cap_status values (%Q, %Q, %Q, %Q, now());", buddy_name, account_id, protocol_id, status_id);
|
|
|
633 rc = sqlite3_exec(_db, sql, NULL, NULL, NULL);
|
|
|
634 sqlite3_free(sql);
|
|
14266
|
635 }
|
|
|
636
|
|
|
637 static void insert_word_count(const char *sender, const char *receiver, guint count) {
|
|
14516
|
638 /* TODO! */
|
|
|
639 /* dbi_result result; */
|
|
|
640 /* result = dbi_conn_queryf(_conn, "insert into cap_message values(\'%s\', \'%s\', %d, now());", sender, receiver, count); */
|
|
14266
|
641 }
|
|
|
642
|
|
|
643 /* Callbacks */
|
|
|
644 void display_statistics_action_cb(GaimBlistNode *node, gpointer data) {
|
|
|
645 GaimBuddy *buddy;
|
|
|
646
|
|
|
647 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
|
648 buddy = (GaimBuddy *)node;
|
|
|
649 gaim_debug_info("cap", "Statistics for %s requested.\n", buddy->name);
|
|
|
650 }
|
|
|
651
|
|
|
652 /* Gaim plugin specific code */
|
|
|
653
|
|
|
654 static gboolean plugin_load(GaimPlugin *plugin) {
|
|
|
655 _plugin_pointer = plugin;
|
|
|
656 _signals_connected = FALSE;
|
|
|
657
|
|
14350
|
658 /* buddy_stats is a hashtable where strings are keys
|
|
|
659 * and the keys are a buddies account id (GaimBuddy.name).
|
|
|
660 * keys/values are automatically deleted */
|
|
|
661 _buddy_stats = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, destroy_stats);
|
|
14266
|
662
|
|
14350
|
663 /* ? - Can't remember at the moment
|
|
|
664 */
|
|
|
665 _my_offline_times = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
|
|
666
|
|
14511
|
667 if(create_database_connection()) {
|
|
|
668 add_plugin_functionality(plugin);
|
|
14266
|
669 }
|
|
|
670 return TRUE;
|
|
|
671 }
|
|
|
672
|
|
14350
|
673 static void add_plugin_functionality(GaimPlugin *plugin) {
|
|
14266
|
674 if(_signals_connected)
|
|
14350
|
675 return;
|
|
|
676
|
|
|
677 gaim_debug_info("cap", "Adding plugin functionality.\n");
|
|
14266
|
678
|
|
|
679 /* Connect all the signals */
|
|
|
680 gaim_signal_connect(gaim_conversations_get_handle(), "sent-im-msg", plugin,
|
|
|
681 GAIM_CALLBACK(sent_im_msg), NULL);
|
|
|
682
|
|
|
683 gaim_signal_connect(gaim_conversations_get_handle(), "received-im-msg", plugin,
|
|
|
684 GAIM_CALLBACK(received_im_msg), NULL);
|
|
|
685
|
|
|
686 gaim_signal_connect(gaim_blist_get_handle(), "buddy-status-changed", plugin,
|
|
|
687 GAIM_CALLBACK(buddy_status_changed), NULL);
|
|
|
688
|
|
|
689 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-on", plugin,
|
|
|
690 GAIM_CALLBACK(buddy_signed_on), NULL);
|
|
|
691
|
|
|
692 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-off", plugin,
|
|
|
693 GAIM_CALLBACK(buddy_signed_off), NULL);
|
|
|
694
|
|
14516
|
695 /*gaim_signal_connect(gaim_blist_get_handle(), "blist-node-extended-menu", plugin,
|
|
|
696 GAIM_CALLBACK(blist_node_extended_menu), NULL);*/
|
|
14266
|
697
|
|
|
698 gaim_signal_connect(gaim_gtk_blist_get_handle(), "drawing-tooltip", plugin,
|
|
|
699 GAIM_CALLBACK(drawing_tooltip), NULL);
|
|
|
700
|
|
|
701 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", plugin,
|
|
|
702 GAIM_CALLBACK(signed_on), NULL);
|
|
|
703
|
|
|
704 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", plugin,
|
|
|
705 GAIM_CALLBACK(signed_off), NULL);
|
|
|
706
|
|
|
707 gaim_signal_connect(gaim_blist_get_handle(), "buddy-idle-changed", plugin,
|
|
|
708 GAIM_CALLBACK(buddy_idle), NULL);
|
|
|
709
|
|
|
710 _signals_connected = TRUE;
|
|
14350
|
711 }
|
|
14266
|
712
|
|
14350
|
713 static void cancel_conversation_timeouts(gpointer key, gpointer value, gpointer user_data) {
|
|
|
714 CapStatistics *stats = value;
|
|
|
715 if(stats->timeout_source_id != 0) {
|
|
|
716 g_source_remove(stats->timeout_source_id);
|
|
|
717 stats->timeout_source_id = 0;
|
|
|
718 }
|
|
|
719 }
|
|
|
720
|
|
|
721 static void remove_plugin_functionality(GaimPlugin *plugin) {
|
|
|
722 if(!_signals_connected)
|
|
|
723 return;
|
|
|
724
|
|
|
725 gaim_debug_info("cap", "Removing plugin functionality.\n");
|
|
|
726
|
|
|
727 /* If there are any timeouts waiting to be processed then cancel them */
|
|
|
728 g_hash_table_foreach(_buddy_stats, cancel_conversation_timeouts, NULL);
|
|
|
729
|
|
|
730 /* Connect all the signals */
|
|
|
731 gaim_signal_disconnect(gaim_conversations_get_handle(), "sent-im-msg", plugin,
|
|
|
732 GAIM_CALLBACK(sent_im_msg));
|
|
|
733
|
|
|
734 gaim_signal_disconnect(gaim_conversations_get_handle(), "received-im-msg", plugin,
|
|
|
735 GAIM_CALLBACK(received_im_msg));
|
|
|
736
|
|
|
737 gaim_signal_disconnect(gaim_blist_get_handle(), "buddy-status-changed", plugin,
|
|
|
738 GAIM_CALLBACK(buddy_status_changed));
|
|
|
739
|
|
|
740 gaim_signal_disconnect(gaim_blist_get_handle(), "buddy-signed-on", plugin,
|
|
|
741 GAIM_CALLBACK(buddy_signed_on));
|
|
|
742
|
|
|
743 gaim_signal_disconnect(gaim_blist_get_handle(), "buddy-signed-off", plugin,
|
|
|
744 GAIM_CALLBACK(buddy_signed_off));
|
|
|
745
|
|
14516
|
746 /*gaim_signal_disconnect(gaim_blist_get_handle(), "blist-node-extended-menu", plugin,
|
|
|
747 GAIM_CALLBACK(blist_node_extended_menu));*/
|
|
14350
|
748
|
|
|
749 gaim_signal_disconnect(gaim_gtk_blist_get_handle(), "drawing-tooltip", plugin,
|
|
|
750 GAIM_CALLBACK(drawing_tooltip));
|
|
|
751
|
|
|
752 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-on", plugin,
|
|
|
753 GAIM_CALLBACK(signed_on));
|
|
|
754
|
|
|
755 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-off", plugin,
|
|
|
756 GAIM_CALLBACK(signed_off));
|
|
|
757
|
|
|
758 gaim_signal_disconnect(gaim_blist_get_handle(), "buddy-idle-changed", plugin,
|
|
|
759 GAIM_CALLBACK(buddy_idle));
|
|
|
760
|
|
|
761 _signals_connected = FALSE;
|
|
14266
|
762 }
|
|
|
763
|
|
|
764 static void write_stats_on_unload(gpointer key, gpointer value, gpointer user_data) {
|
|
|
765 CapStatistics *stats = value;
|
|
|
766 if(stats->last_message != -1 && stats->buddy != NULL) {
|
|
|
767 insert_cap_failure(stats);
|
|
|
768 }
|
|
|
769 }
|
|
|
770
|
|
|
771 static gboolean plugin_unload(GaimPlugin *plugin) {
|
|
|
772 gaim_debug_info("cap", "CAP plugin unloading\n");
|
|
14350
|
773
|
|
14516
|
774 /* clean up memory allocations */
|
|
14350
|
775 if(_buddy_stats) {
|
|
|
776 g_hash_table_foreach(_buddy_stats, write_stats_on_unload, NULL);
|
|
14266
|
777 g_hash_table_destroy(_buddy_stats);
|
|
14350
|
778 }
|
|
14266
|
779
|
|
14516
|
780 /* close database connection */
|
|
14511
|
781 destroy_database_connection();
|
|
14266
|
782
|
|
|
783 return TRUE;
|
|
|
784 }
|
|
|
785
|
|
14350
|
786 static CapPrefsUI * create_cap_prefs_ui() {
|
|
|
787 CapPrefsUI *ui = g_malloc(sizeof(CapPrefsUI));
|
|
|
788
|
|
|
789 ui->ret = gtk_vbox_new(FALSE, 18);
|
|
|
790 gtk_container_set_border_width(GTK_CONTAINER(ui->ret), 10);
|
|
|
791 ui->cap_vbox = gaim_gtk_make_frame(ui->ret, _("Statistics Configuration"));
|
|
14266
|
792
|
|
14350
|
793 /* msg_difference spinner */
|
|
|
794 ui->msg_difference_label = gtk_label_new(_("Maximum response timeout:"));
|
|
|
795 gtk_misc_set_alignment(GTK_MISC(ui->msg_difference_label), 0, 0.5);
|
|
|
796 ui->msg_difference_input = gtk_spin_button_new_with_range(1, 1440, 1);
|
|
|
797 ui->msg_difference_minutes_label = gtk_label_new(_("minutes"));
|
|
|
798 gtk_misc_set_alignment(GTK_MISC(ui->msg_difference_minutes_label), 0, 0.5);
|
|
14266
|
799
|
|
14350
|
800 /* last_seen spinner */
|
|
|
801 ui->last_seen_label = gtk_label_new(_("Maximum last-seen difference:"));
|
|
|
802 gtk_misc_set_alignment(GTK_MISC(ui->last_seen_label), 0, 0.5);
|
|
|
803 ui->last_seen_input = gtk_spin_button_new_with_range(1, 1440, 1);
|
|
|
804 ui->last_seen_minutes_label = gtk_label_new(_("minutes"));
|
|
|
805 gtk_misc_set_alignment(GTK_MISC(ui->last_seen_minutes_label), 0, 0.5);
|
|
|
806
|
|
|
807 /* threshold spinner */
|
|
|
808 ui->threshold_label = gtk_label_new(_("Threshold:"));
|
|
|
809 gtk_misc_set_alignment(GTK_MISC(ui->threshold_label), 0, 0.5);
|
|
|
810 ui->threshold_input = gtk_spin_button_new_with_range(1, 1440, 1);
|
|
|
811 ui->threshold_minutes_label = gtk_label_new(_("minutes"));
|
|
|
812 gtk_misc_set_alignment(GTK_MISC(ui->threshold_minutes_label), 0, 0.5);
|
|
|
813
|
|
|
814 /* Layout threshold/last-seen/response-timeout input items */
|
|
|
815 ui->table_layout = gtk_table_new(3, 3, FALSE);
|
|
|
816 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->threshold_label, 0, 1, 0, 1,
|
|
|
817 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
818 (GtkAttachOptions) (0), 0, 0);
|
|
|
819
|
|
|
820 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->threshold_input, 1, 2, 0, 1,
|
|
|
821 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
822 (GtkAttachOptions) (0), 0, 0);
|
|
|
823
|
|
|
824 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->threshold_minutes_label, 2, 3, 0, 1,
|
|
|
825 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
826 (GtkAttachOptions) (0), 0, 0);
|
|
|
827
|
|
|
828 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->msg_difference_label, 0, 1, 1, 2,
|
|
|
829 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
830 (GtkAttachOptions) (0), 0, 0);
|
|
|
831
|
|
|
832 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->msg_difference_input, 1, 2, 1, 2,
|
|
|
833 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
834 (GtkAttachOptions) (0), 0, 0);
|
|
|
835
|
|
|
836 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->msg_difference_minutes_label, 2, 3, 1, 2,
|
|
|
837 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
838 (GtkAttachOptions) (0), 0, 0);
|
|
|
839
|
|
|
840 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->last_seen_label, 0, 1, 2,3,
|
|
|
841 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
842 (GtkAttachOptions) (0), 0, 0);
|
|
|
843
|
|
|
844 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->last_seen_input, 1, 2, 2, 3,
|
|
|
845 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
846 (GtkAttachOptions) (0), 0, 0);
|
|
|
847
|
|
|
848 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->last_seen_minutes_label, 2, 3, 2, 3,
|
|
|
849 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
|
|
|
850 (GtkAttachOptions) (0), 0, 0);
|
|
|
851
|
|
|
852
|
|
|
853 /* Config window - lay it out */
|
|
|
854 gtk_box_pack_start(GTK_BOX(ui->cap_vbox), ui->table_layout, FALSE, FALSE, 0);
|
|
|
855
|
|
|
856 /* Set the input areas to contain the configuration values from
|
|
|
857 * gaim prefs.
|
|
|
858 */
|
|
14266
|
859 if(gaim_prefs_exists("/plugins/gtk/cap/max_msg_difference")) {
|
|
|
860 int max_msg_diff = gaim_prefs_get_int("/plugins/gtk/cap/max_msg_difference");
|
|
14350
|
861 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ui->msg_difference_input), max_msg_diff);
|
|
14266
|
862 }
|
|
|
863 if(gaim_prefs_exists("/plugins/gtk/cap/max_seen_difference")) {
|
|
|
864 int max_seen_diff = gaim_prefs_get_int("/plugins/gtk/cap/max_seen_difference");
|
|
14350
|
865 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ui->last_seen_input), max_seen_diff);
|
|
14266
|
866 }
|
|
|
867 if(gaim_prefs_exists("/plugins/gtk/cap/threshold")) {
|
|
|
868 int threshold = gaim_prefs_get_int("/plugins/gtk/cap/threshold");
|
|
14350
|
869 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ui->threshold_input), threshold);
|
|
14266
|
870 }
|
|
14350
|
871
|
|
|
872 /* Add the signals */
|
|
|
873 g_signal_connect(G_OBJECT(ui->ret), "destroy",
|
|
|
874 G_CALLBACK(cap_prefs_ui_destroy_cb), ui);
|
|
|
875
|
|
|
876 g_signal_connect(G_OBJECT(ui->msg_difference_input), "value-changed",
|
|
|
877 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/max_msg_difference");
|
|
|
878
|
|
|
879 g_signal_connect(G_OBJECT(ui->last_seen_input), "value-changed",
|
|
|
880 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/max_seen_difference");
|
|
|
881
|
|
|
882 g_signal_connect(G_OBJECT(ui->threshold_input), "value-changed",
|
|
14266
|
883 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/threshold");
|
|
14350
|
884
|
|
|
885 return ui;
|
|
|
886 }
|
|
|
887
|
|
14511
|
888 static void cap_prefs_ui_destroy_cb(GtkObject *object, gpointer user_data) {
|
|
14350
|
889 CapPrefsUI *ui = user_data;
|
|
14511
|
890 if(_db) {
|
|
|
891 add_plugin_functionality(_plugin_pointer);
|
|
14350
|
892 }
|
|
14511
|
893 g_free(ui);
|
|
14266
|
894 }
|
|
|
895
|
|
|
896 static void numeric_spinner_prefs_cb(GtkSpinButton *spinbutton, gpointer user_data) {
|
|
|
897 gaim_prefs_set_int(user_data, gtk_spin_button_get_value_as_int(spinbutton));
|
|
|
898 }
|
|
|
899
|
|
|
900 static GaimGtkPluginUiInfo ui_info = {
|
|
|
901 get_config_frame,
|
|
|
902 0 /* page_num (reserved) */
|
|
|
903 };
|
|
|
904
|
|
|
905 static GaimPluginInfo info = {
|
|
|
906 GAIM_PLUGIN_MAGIC,
|
|
|
907 GAIM_MAJOR_VERSION,
|
|
|
908 GAIM_MINOR_VERSION,
|
|
|
909 GAIM_PLUGIN_STANDARD, /**< type */
|
|
|
910 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */
|
|
|
911 0, /**< flags */
|
|
|
912 NULL, /**< dependencies */
|
|
|
913 GAIM_PRIORITY_DEFAULT, /**< priority */
|
|
|
914 CAP_PLUGIN_ID, /**< id */
|
|
|
915 "Contact Availability Prediction", /**< name */
|
|
|
916 VERSION, /**< version */
|
|
|
917 N_("Contact Availability Prediction plugin."), /** summary */
|
|
|
918 N_("The contact availability plugin (cap) is used to display statistical information about buddies in a users contact list."),
|
|
|
919 /** description */
|
|
|
920 "Geoffrey Foster <geoffrey.foster@gmail.com>", /**< author */
|
|
|
921 GAIM_WEBSITE, /**< homepage */
|
|
|
922 plugin_load, /**< load */
|
|
|
923 plugin_unload, /**< unload */
|
|
|
924 NULL, /**< destroy */
|
|
|
925 &ui_info, /**< ui_info */
|
|
|
926 NULL, /**< extra_info */
|
|
|
927 NULL, /**< prefs_info */
|
|
|
928 NULL
|
|
|
929 };
|
|
|
930
|
|
14511
|
931 static GtkWidget * get_config_frame(GaimPlugin *plugin) {
|
|
|
932 CapPrefsUI *ui = create_cap_prefs_ui();
|
|
|
933
|
|
|
934 /*
|
|
|
935 * Prevent database stuff from occuring since we are editing values
|
|
|
936 */
|
|
|
937 remove_plugin_functionality(_plugin_pointer);
|
|
|
938
|
|
|
939 return ui->ret;
|
|
|
940 }
|
|
|
941
|
|
14266
|
942 static void init_plugin(GaimPlugin *plugin) {
|
|
|
943 gaim_prefs_add_none("/plugins/gtk/cap");
|
|
|
944 gaim_prefs_add_int("/plugins/gtk/cap/max_seen_difference", 1);
|
|
|
945 gaim_prefs_add_int("/plugins/gtk/cap/max_msg_difference", 10);
|
|
|
946 gaim_prefs_add_int("/plugins/gtk/cap/threshold", 5);
|
|
|
947 }
|
|
|
948
|
|
|
949 GAIM_INIT_PLUGIN(cap, init_plugin, info);
|