annotate gtk/plugins/cap/cap.c @ 14350:eec3ce357b70

[gaim-migrate @ 17053] * Fixed stupid plugin loading decision that prevented user from being able to change the dbi drivers path in preferences if it was wrong. * Prefs UI improved greatly. committer: Tailor Script <tailor@pidgin.im>
author Geoff Foster <g-off_>
date Sun, 27 Aug 2006 02:44:52 +0000
parents 63ef6342db05
children f309a5b3f184
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1 /*
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
2 * Contact Availability Prediction plugin for Gaim
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
3 *
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
4 * Copyright (C) 2006 Geoffrey Foster.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
5 *
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
7 * modify it under the terms of the GNU General Public License as
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
8 * published by the Free Software Foundation; either version 2 of the
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
9 * License, or (at your option) any later version.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
10 *
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
14 * General Public License for more details.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
15 *
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
19 * 02111-1307, USA.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
20 */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
21
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
22 #include "cap.h"
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
23
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
24 static char * quote_string(const char *str) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
25 gchar *quoted_str = NULL;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
26 quoted_str = g_strdup(str);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
27 dbi_driver_quote_string(_driver, &quoted_str);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
28 return quoted_str;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
29 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
30
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
31 static void generate_minute_stats(CapStatistics *statistics) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
32 gchar *buddy_name = quote_string(statistics->buddy->name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
33 gchar *protocol_id = quote_string(gaim_account_get_protocol_id(statistics->buddy->account));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
34 gchar *account_id = quote_string(gaim_account_get_username(statistics->buddy->account));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
35 dbi_result result = dbi_conn_queryf(_conn, "select minute_val, success_count, failed_count from cap_msg_count where buddy=%s account=%s and protocol=%s;", buddy_name, account_id, protocol_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
36
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
37 while(dbi_result_next_row(result)) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
38 int minute_val = dbi_result_get_int(result, "minute_val");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
39 int success_count = dbi_result_get_int(result, "success_count");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
40 int failed_count = dbi_result_get_int(result, "failed_count");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
41 double ratio = ((double)success_count/(double)(success_count + failed_count));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
42 statistics->minute_stats[minute_val] = ratio;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
43 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
44 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
45 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
46
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
47 static void generate_prediction(CapStatistics *statistics) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
48 if(statistics->buddy) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
49 if(statistics->prediction == NULL)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
50 statistics->prediction = g_malloc(sizeof(CapPrediction));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
51 statistics->prediction->probability = generate_prediction_for(statistics->buddy);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
52 statistics->prediction->generated_at = time(NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
53 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
54 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
55
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
56 static double generate_prediction_for(GaimBuddy *buddy) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
57 double prediction = 1.0f;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
58 gboolean generated = FALSE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
59 gchar *buddy_name = quote_string(buddy->name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
60 gchar *protocol_id = quote_string(gaim_account_get_protocol_id(buddy->account));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
61 gchar *account_id = quote_string(gaim_account_get_username(buddy->account));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
62 gchar *status_id = quote_string(gaim_status_get_id(get_status_for(buddy)));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
63 time_t t = time(NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
64 struct tm *current_time = localtime(&t);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
65 int current_minute = current_time->tm_min + current_time->tm_hour * 60;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
66 int threshold = gaim_prefs_get_int("/plugins/gtk/cap/threshold");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
67 int min_minute = (current_minute - threshold) % 1440;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
68 int max_minute = (current_minute + threshold) % 1440;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
69 dbi_result result;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
70
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
71 result = dbi_conn_queryf(_conn, "select success_count, failed_count from cap_msg_count where buddy=%s and account=%s and protocol=%s and minute_val>=%d and minute_val<=%d;", buddy_name, account_id, protocol_id, min_minute, max_minute);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
72 if(result) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
73 int successes = 0;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
74 int failures = 0;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
75 while(dbi_result_next_row(result)) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
76 if(!dbi_result_field_is_null(result, "success_count"))
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
77 successes += dbi_result_get_int(result, "success_count");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
78
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
79 if(!dbi_result_field_is_null(result, "failed_count"))
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
80 failures += dbi_result_get_int(result, "failed_count");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
81 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
82 if(failures + successes > 0) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
83 prediction *= ((double)successes/((double)(successes + failures)));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
84 generated = TRUE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
85 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
86 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
87 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
88
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
89
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
90 /*
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
91 * Note to self: apparently when using a function like sum results in not being able to get
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
92 * the values for fields using libdbi...why? the way I'm doing it above sucks, find a fix.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
93 result = dbi_conn_queryf(_conn, "select sum(success_count) as successes, sum(failed_count) as failures from cap_msg_count where buddy=%s and account=%s and protocol=%s and minute_val>=%d and minute_val<=%d;", buddy_name, account_id, protocol_id, min_minute, max_minute);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
94 gaim_debug_info("cap", "select sum(success_count) as successes, sum(failed_count) as failures from cap_msg_count where buddy=%s and account=%s and protocol=%s and minute_val>=%d and minute_val<=%d;\n", buddy_name, account_id, protocol_id, min_minute, max_minute);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
95
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
96 if(result) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
97 int failures;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
98 int successes;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
99 int rc = dbi_result_get_numrows(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
100 dbi_result_next_row(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
101 gaim_debug_info("cap", "Result code: %d\n", rc);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
102 failures = dbi_result_get_int_idx(result, 1);//"failures");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
103 successes = dbi_result_get_int_idx(result, 2); //"successes");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
104 gaim_debug_info("cap", "Successes = %d; Failures = %d\n", successes, failures);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
105 dbi_result_get_fields(result, "successes.%i failures.%i", &successes, &failures);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
106 gaim_debug_info("cap", "Successes = %d; Failures = %d\n", successes, failures);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
107 if(failures + successes > 0.0)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
108 prediction *= ((double)successes/((double)(successes + failures)));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
109 gaim_debug_info("cap", "After message value prediction is %0.4f.\n", prediction);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
110 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
111 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
112 */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
113
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
114 result = dbi_conn_queryf(_conn, "select success_count, failed_count from cap_status_count where buddy=%s and account=%s and protocol=%s and status=%s;", buddy_name, account_id, protocol_id, status_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
115 if(result) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
116 int successes = 0;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
117 int failures = 0;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
118
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
119 dbi_result_next_row(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
120
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
121 if(!dbi_result_field_is_null(result, "success_count"))
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
122 successes = dbi_result_get_int(result, "success_count");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
123
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
124 if(!dbi_result_field_is_null(result, "failed_count"))
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
125 failures = dbi_result_get_int(result, "failed_count");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
126
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
127 if(successes + failures > 0) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
128 prediction *= ((double)successes/(double)(successes + failures));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
129 generated = TRUE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
130 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
131 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
132 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
133
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
134 free(buddy_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
135 free(account_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
136 free(protocol_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
137 free(status_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
138
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
139 if(strcmp(gaim_status_get_id(get_status_for(buddy)), "offline") == 0) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
140 //This is kind of stupid, change it.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
141 if(prediction == 1.0f)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
142 prediction = 0.0f;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
143 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
144
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
145 if(generated)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
146 return prediction;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
147 else
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
148 return -1;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
149 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
150
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
151 static CapStatistics * get_stats_for(GaimBuddy *buddy) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
152 gchar *buddy_name;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
153 gchar *q_buddy_name = quote_string(buddy->name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
154 CapStatistics *stats;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
155 buddy_name = g_strdup(buddy->name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
156 stats = g_hash_table_lookup(_buddy_stats, buddy_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
157 if(!stats) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
158 dbi_result result;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
159 stats = g_malloc(sizeof(CapStatistics));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
160 stats->last_message = -1;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
161 stats->last_message_status_id = NULL;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
162 stats->last_status_id = NULL;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
163 stats->prediction = NULL;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
164 g_hash_table_insert(_buddy_stats, buddy_name, stats);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
165 stats->buddy = buddy;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
166 /* Setup the last seen online time from database or -1 if no time available. */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
167 result = dbi_conn_queryf(_conn,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
168 //"select max(event_time) as last_event_time from cap_status where buddy=\'%s\' and status!=\'offline\';",
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
169 "select event_time from cap_status where buddy=\'%s\' and status!=\'offline\' order by event_time desc;",
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
170 q_buddy_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
171 if(result && dbi_result_get_numrows(result) > 0) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
172 dbi_result_next_row(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
173 stats->last_seen = dbi_result_get_datetime(result, "event_time");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
174 } else {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
175 stats->last_seen = -1;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
176 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
177 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
178 /* Setup the last messaged time to be a 'useable' value for comparisons. */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
179 //result = dbi_conn_queryf(conn, "", );
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
180 /* Setup the last status id to nothing */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
181 // --> Better approach would be to get the last status available in db and use it.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
182 result = dbi_conn_queryf(_conn,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
183 "select status, max(event_time) from cap_status where buddy=\'%s\' group by status;",
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
184 buddy->name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
185 if(result && dbi_result_get_numrows(result) > 0) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
186 dbi_result_next_row(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
187 stats->last_status_id = dbi_result_get_string_copy(result, "status");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
188 } else {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
189 stats->last_status_id = "";
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
190 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
191 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
192 //TODO: populate stats from database
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
193 } else {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
194 g_free(buddy_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
195 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
196 free(q_buddy_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
197 generate_prediction(stats);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
198 return stats;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
199 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
200
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
201 static void destroy_stats(gpointer data) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
202 CapStatistics *stats = data;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
203 g_free(stats->prediction);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
204 //g_free(stats->hourly_usage);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
205 //g_free(stats->daily_usage);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
206 g_free(stats);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
207 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
208
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
209 static gboolean remove_stats_for(GaimBuddy *buddy) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
210 gboolean success = TRUE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
211 //GString *buddy_name = g_string_new(buddy->name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
212 gchar *buddy_name = g_strdup(buddy->name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
213 success = g_hash_table_remove(_buddy_stats, buddy_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
214 g_free(buddy_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
215 return success;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
216 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
217
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
218 static dbi_result insert_cap_msg_count_success(const char *buddy_name, const char *account, const char *protocol, int minute) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
219 gaim_debug_info("cap", "Insert cap_msg_count success: %s %s %s %d\n", buddy_name, account, protocol, minute);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
220 return dbi_conn_queryf(_conn, "insert into cap_msg_count (buddy, account, protocol, minute_val, success_count, failed_count) values (%s, %s, %s, %d, %d, %d) on duplicate key update success_count=success_count+1;", buddy_name, account, protocol, minute, 1, 0);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
221 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
222
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
223 static dbi_result insert_cap_status_count_success(const char *buddy_name, const char *account, const char *protocol, const char *status_id) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
224 gaim_debug_info("cap", "Insert cap_status_count success: %s %s %s %s\n", buddy_name, account, protocol, status_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
225 return dbi_conn_queryf(_conn, "insert into cap_status_count (buddy, account, protocol, status, success_count, failed_count) values(%s, %s, %s, %s, %d, %d) on duplicate key update success_count=success_count+1;", buddy_name, account, protocol, status_id, 1, 0);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
226 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
227
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
228 static dbi_result insert_cap_msg_count_failed(const char *buddy_name, const char *account, const char *protocol, int minute) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
229 gaim_debug_info("cap", "Insert cap_msg_count failed: %s %s %s %d\n", buddy_name, account, protocol, minute);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
230 return dbi_conn_queryf(_conn, "insert into cap_msg_count (buddy, account, protocol, minute_val, success_count, failed_count) values (%s, %s, %s, %d, %d, %d) on duplicate key update failed_count=failed_count+1;", buddy_name, account, protocol, minute, 0, 1);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
231 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
232
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
233 static dbi_result insert_cap_status_count_failed(const char *buddy_name, const char *account, const char *protocol, const char *status_id) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
234 gaim_debug_info("cap", "Insert cap_status_count failed: %s %s %s %s\n", buddy_name, account, protocol, status_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
235 return dbi_conn_queryf(_conn, "insert into cap_status_count (buddy, account, protocol, status, success_count, failed_count) values(%s, %s, %s, %s, %d, %d) on duplicate key update failed_count=failed_count+1;", buddy_name, account, protocol, status_id, 0, 1);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
236 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
237
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
238 static void insert_cap_success(CapStatistics *stats) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
239 dbi_result result;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
240 gchar *buddy_name = quote_string(stats->buddy->name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
241 gchar *protocol_id = quote_string(gaim_account_get_protocol_id(stats->buddy->account));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
242 gchar *account_id = quote_string(gaim_account_get_username(stats->buddy->account));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
243 gchar *status_id = (stats->last_message_status_id) ?
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
244 quote_string(stats->last_message_status_id) :
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
245 quote_string(gaim_status_get_id(get_status_for(stats->buddy)));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
246 struct tm *current_time;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
247 int minute;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
248
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
249 if(stats->last_message == -1) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
250 time_t now = time(NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
251 current_time = localtime(&now);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
252 } else {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
253 current_time = localtime(&stats->last_message);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
254 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
255 minute = current_time->tm_min + current_time->tm_hour * 60;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
256
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
257 result = insert_cap_msg_count_success(buddy_name, account_id, protocol_id, minute);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
258 if(result)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
259 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
260
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
261 result = insert_cap_status_count_success(buddy_name, account_id, protocol_id, status_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
262 if(result)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
263 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
264
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
265 stats->last_message = -1;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
266 stats->last_message_status_id = NULL;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
267
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
268 free(status_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
269 free(protocol_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
270 free(account_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
271 free(buddy_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
272 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
273
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
274 static void insert_cap_failure(CapStatistics *stats) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
275 dbi_result result;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
276 gchar *buddy_name = quote_string(stats->buddy->name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
277 gchar *protocol_id = quote_string(gaim_account_get_protocol_id(stats->buddy->account));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
278 gchar *account_id = quote_string(gaim_account_get_username(stats->buddy->account));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
279 gchar *status_id = (stats->last_message_status_id) ?
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
280 quote_string(stats->last_message_status_id) :
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
281 quote_string(gaim_status_get_id(get_status_for(stats->buddy)));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
282 struct tm *current_time = localtime(&stats->last_message);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
283 int minute = current_time->tm_min + current_time->tm_hour * 60;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
284
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
285 result = insert_cap_msg_count_failed(buddy_name, account_id, protocol_id, minute);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
286 if(result)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
287 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
288
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
289 result = insert_cap_status_count_failed(buddy_name, account_id, protocol_id, status_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
290 if(result)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
291 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
292
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
293 stats->last_message = -1;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
294 stats->last_message_status_id = NULL;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
295
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
296 free(status_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
297 free(protocol_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
298 free(account_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
299 free(buddy_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
300 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
301
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
302 static gboolean max_message_difference_cb(gpointer data) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
303 CapStatistics *stats = data;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
304 gaim_debug_info("cap", "Max Message Difference timeout occured\n");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
305 insert_cap_failure(stats);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
306 stats->timeout_source_id = 0;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
307 return FALSE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
308 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
309
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
310 /* Gaim Signal Handlers */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
311
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
312 //sent-im-msg
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
313 static void sent_im_msg(GaimAccount *account, const char *receiver, const char *message) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
314 GaimBuddy *buddy = gaim_find_buddy(account, receiver);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
315 guint interval = gaim_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 1000 * 60;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
316 guint words = word_count(message);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
317 CapStatistics *stats = get_stats_for(buddy);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
318
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
319 insert_word_count(gaim_account_get_username(account), receiver, words);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
320 stats->last_message = time(NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
321 stats->last_message_status_id = gaim_status_get_id(get_status_for(buddy));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
322 if(stats->timeout_source_id != 0)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
323 g_source_remove(stats->timeout_source_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
324
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
325 stats->timeout_source_id = g_timeout_add(interval, max_message_difference_cb, stats);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
326 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
327
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
328 //received-im-msg
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
329 static void received_im_msg(GaimAccount *account, char *sender, char *message,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
330 GaimConversation *conv, GaimMessageFlags flags) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
331 GaimBuddy *buddy = gaim_find_buddy(account, sender);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
332 guint words = word_count(message);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
333 CapStatistics *stats = get_stats_for(buddy);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
334
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
335 //insert_word_count(sender, buddy_name, words);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
336
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
337 //If we are waiting for a response from a prior message
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
338 // then cancel the timeout callback.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
339 if(stats->timeout_source_id != 0) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
340 gaim_debug_info("cap", "Cancelling timeout callback\n");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
341 g_source_remove(stats->timeout_source_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
342 stats->timeout_source_id = 0;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
343 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
344
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
345 insert_cap_success(stats);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
346
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
347 stats->last_message = -1; //Reset the last_message value
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
348 stats->last_message_status_id = NULL; //Reset the last status id value
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
349 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
350
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
351 //buddy-status-changed
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
352 static void buddy_status_changed(GaimBuddy *buddy, GaimStatus *old_status, GaimStatus *status) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
353 CapStatistics *stats = get_stats_for(buddy);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
354 insert_status_change_from_gaim_status(stats, status);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
355 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
356
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
357 //buddy-signed-on
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
358 static void buddy_signed_on(GaimBuddy *buddy) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
359 CapStatistics *stats = get_stats_for(buddy);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
360
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
361 /* If the statistic object existed but doesn't have a buddy pointer associated
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
362 * with it then reassociate one with it. The pointer being null is a result
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
363 * of a buddy with existing stats signing off and Gaim sticking around.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
364 */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
365 if(!stats->buddy) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
366 stats->buddy = buddy;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
367 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
368
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
369 insert_status_change(stats);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
370 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
371
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
372 //buddy-signed-off
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
373 static void buddy_signed_off(GaimBuddy *buddy) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
374 CapStatistics *stats = get_stats_for(buddy);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
375
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
376 /* We don't necessarily want to delete a buddies generated statistics every time they go offline.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
377 * Instead we just set the buddy pointer to null so that when they come back online we can look
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
378 * them up again and continue using their statistics.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
379 */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
380 insert_status_change(stats);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
381 //stats->buddy = NULL;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
382 stats->last_seen = time(NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
383 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
384
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
385 static void buddy_idle(GaimBuddy *buddy, gboolean old_idle, gboolean idle) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
386 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
387
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
388 static void blist_node_extended_menu(GaimBlistNode *node, GList **menu) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
389 GaimBuddy *buddy;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
390 GaimMenuAction *menu_action;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
391 gaim_debug_info("cap", "got extended blist menu\n");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
392 gaim_debug_info("cap", "is buddy: %d\n", GAIM_BLIST_NODE_IS_BUDDY(node));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
393 gaim_debug_info("cap", "is contact: %d\n", GAIM_BLIST_NODE_IS_CONTACT(node));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
394 gaim_debug_info("cap", "is group: %d\n", GAIM_BLIST_NODE_IS_GROUP(node));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
395 /* Probably only concerned with buddy/contact types. Contacts = meta-buddies (grouped msn/jabber/etc.) */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
396 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
397 buddy = (GaimBuddy *)node;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
398 menu_action = gaim_menu_action_new(_("Display Statistics"),
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
399 GAIM_CALLBACK(display_statistics_action_cb), NULL, NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
400 *menu = g_list_append(*menu, menu_action);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
401 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
402
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
403 //drawing-tooltip
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
404 static void drawing_tooltip(GaimBlistNode *node, GString *text, gboolean full) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
405 if(node->type == GAIM_BLIST_BUDDY_NODE) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
406 GaimBuddy *buddy = (GaimBuddy *)node;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
407 CapStatistics *stats = get_stats_for(buddy);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
408 // get the probability that this buddy will respond and add to the tooltip
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
409 if(stats->prediction->probability >= 0.0) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
410 g_string_append_printf(text, "\n<b>%s</b> %0.4f", _("Response Probability:"), stats->prediction->probability);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
411 } else {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
412 g_string_append_printf(text, "\n<b>%s</b> ???", _("Response Probability:"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
413 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
414 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
415 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
416
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
417 //signed-on
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
418 static void signed_on(GaimConnection *gc) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
419 GaimAccount *account = gaim_connection_get_account(gc);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
420 const char *my_gaim_name = gaim_account_get_username(account);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
421 gchar *my_name = g_strdup(my_gaim_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
422 time_t *last_offline = g_hash_table_lookup(_my_offline_times, my_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
423
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
424 gchar *account_id = quote_string(gaim_account_get_username(account));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
425 gchar *protocol_id = quote_string(gaim_account_get_protocol_id(account));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
426 dbi_result result;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
427
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
428 result = dbi_conn_queryf(_conn, "insert into cap_my_usage values(%s, %s, %d, now());", account_id, protocol_id, 1);
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
429 if(result)
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
430 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
431
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
432 if(last_offline) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
433 if(difftime(*last_offline, time(NULL)) > gaim_prefs_get_int("/plugins/gtk/cap/max_seen_difference") * 60) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
434 //reset all of the last_message times to -1
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
435 g_hash_table_foreach(_my_offline_times, reset_all_last_message_times, NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
436 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
437 g_hash_table_remove(_my_offline_times, my_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
438 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
439 g_free(my_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
440 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
441
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
442 //signed-off
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
443 static void signed_off(GaimConnection *gc) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
444 /* Here we record the time you (the user) sign off of an account.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
445 * The account username is the key in the hashtable and the sign off time_t
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
446 * (equal to the sign off time) is the value. */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
447 GaimAccount *account = gaim_connection_get_account(gc);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
448 const char *my_gaim_name = gaim_account_get_username(account);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
449 gchar *my_name = g_strdup(my_gaim_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
450 time_t *offline_time = g_malloc(sizeof(time_t));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
451 gchar *account_id = quote_string(gaim_account_get_username(account));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
452 gchar *protocol_id = quote_string(gaim_account_get_protocol_id(account));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
453 dbi_result result;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
454
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
455 result = dbi_conn_queryf(_conn, "insert into cap_my_usage values(%s, %s, %d, now());", account_id, protocol_id, 0);
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
456 if(result)
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
457 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
458
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
459 time(offline_time);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
460 g_hash_table_insert(_my_offline_times, my_name, offline_time);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
461 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
462
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
463 static const gchar * get_error_msg() {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
464 if(error_msg)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
465 return error_msg->str;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
466 else
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
467 return NULL;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
468 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
469
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
470 static void set_error_msg(const gchar *msg) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
471 if(!error_msg)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
472 error_msg = g_string_new(msg);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
473 else
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
474 g_string_assign(error_msg, msg);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
475 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
476
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
477 static void append_error_msg(const gchar *msg) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
478 if(!error_msg)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
479 set_error_msg(msg);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
480 else
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
481 g_string_append(error_msg, msg);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
482 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
483
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
484 static void reset_all_last_message_times(gpointer key, gpointer value, gpointer user_data) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
485 CapStatistics *stats = value;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
486 stats->last_message = -1;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
487 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
488
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
489 static GaimStatus * get_status_for(GaimBuddy *buddy) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
490 GaimPresence *presence = gaim_buddy_get_presence(buddy);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
491 GaimStatus *status = gaim_presence_get_active_status(presence);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
492 return status;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
493 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
494
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
495 static void create_tables() {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
496 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
497
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
498 static gboolean create_database_connection() {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
499 int rc;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
500 int driver_type;
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
501
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
502 if(_conn)
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
503 return TRUE;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
504
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
505 //make database connection here
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
506 _conn = dbi_conn_new(gaim_prefs_get_string("/plugins/gtk/cap/db_driver"));
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
507 if(!_conn)
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
508 return FALSE;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
509
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
510 _driver = dbi_conn_get_driver(_conn);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
511 gaim_debug_info("cap", "Using driver: %s\n", gaim_prefs_get_string("/plugins/gtk/cap/db_driver"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
512 if(strcmp(gaim_prefs_get_string("/plugins/gtk/cap/db_driver"), "mysql") == 0) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
513 driver_type = MYSQL;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
514 dbi_conn_set_option(_conn, "host", gaim_prefs_get_string("/plugins/gtk/cap/mysql/db_host"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
515 dbi_conn_set_option(_conn, "username", gaim_prefs_get_string("/plugins/gtk/cap/mysql/db_user"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
516 dbi_conn_set_option(_conn, "password", gaim_prefs_get_string("/plugins/gtk/cap/mysql/db_password"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
517 dbi_conn_set_option(_conn, "dbname", gaim_prefs_get_string("/plugins/gtk/cap/mysql/db_name"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
518 dbi_conn_set_option(_conn, "encoding", "auto");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
519 dbi_conn_set_option_numeric(_conn, "port", gaim_prefs_get_int("/plugins/gtk/cap/mysql/db_port"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
520 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
521 if(dbi_conn_connect(_conn) < 0) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
522 const char *err_msg = "";
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
523 //rc = dbi_conn_error(_conn, &err_msg);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
524 rc = dbi_conn_error(_conn, NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
525 gaim_debug_error("cap", "CAP could not create database connection. %d\n", rc);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
526 //set_error_msg(_("Could not create database connection. Reason: "));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
527 //append_error_msg(err_msg);
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
528 _conn = NULL;
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
529 return FALSE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
530 } else {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
531 //Add tables here
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
532 create_tables();
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
533 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
534 gaim_debug_info("cap", "Database connection successfully made.\n");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
535 return TRUE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
536 }
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
537 static void destroy_database_connection() {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
538 if(_conn)
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
539 dbi_conn_close(_conn);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
540
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
541 _conn = NULL;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
542 }
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
543
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
544 static guint word_count(const gchar *string) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
545 //TODO: doesn't really work, should use regex instead (#include <regex.h>)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
546 gchar **result = g_strsplit_set(string, " ", -1);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
547 guint count = g_strv_length(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
548
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
549 g_strfreev(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
550
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
551 return count;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
552 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
553
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
554 /* If the difference in time between the present time and the time that
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
555 * you last sent a message to a buddy is less than some value then return
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
556 * true, otherwise return false.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
557 * The difference can either be + or - the max_difference.
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
558 * max_difference is in seconds
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
559 */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
560 static gboolean last_message_time_in_range(CapStatistics *statistics, gdouble max_difference) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
561 time_t now = time(NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
562 gdouble difference = 0.0;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
563 //If there is no last_message time then it is considered in range
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
564 if(statistics->last_message == -1) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
565 return TRUE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
566 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
567 //Compute the difference between now and the last_message
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
568 difference = difftime(statistics->last_message, now);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
569 //Absolute value
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
570 difference = (difference < 0.0) ? -difference : difference;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
571 //If the difference is less than the maximum then we are good and its in range, otherwise not
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
572 if(difference <= max_difference)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
573 return TRUE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
574 else
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
575 return FALSE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
576 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
577
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
578 static gboolean last_seen_time_in_range(CapStatistics *statistics, gdouble max_difference) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
579 time_t now = time(NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
580 gdouble difference = 0.0;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
581 if(statistics->last_seen == -1)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
582 return FALSE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
583 difference = difftime(statistics->last_seen, now);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
584 difference = (difference < 0.0) ? -difference : difference;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
585 if(difference < max_difference)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
586 return TRUE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
587 else
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
588 return FALSE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
589 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
590
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
591 static void insert_status_change(CapStatistics *statistics) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
592 insert_status_change_from_gaim_status(statistics, get_status_for(statistics->buddy));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
593 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
594
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
595 static void insert_status_change_from_gaim_status(CapStatistics *statistics, GaimStatus *status) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
596 dbi_result result;
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
597 gchar *status_id;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
598 gchar *buddy_name;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
599 gchar *protocol_id;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
600 gchar *account_id;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
601
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
602 /* It would seem that some protocols receive periodic updates of the buddies status.
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
603 * Check to make sure the last status is not the same as current status to prevent
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
604 * to many duplicated useless database entries. */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
605 if(strcmp(statistics->last_status_id, gaim_status_get_id(status)) == 0)
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
606 return;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
607
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
608 status_id = quote_string(gaim_status_get_id(status));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
609 buddy_name = quote_string(statistics->buddy->name);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
610 protocol_id = quote_string(gaim_account_get_protocol_id(statistics->buddy->account));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
611 account_id = quote_string(gaim_account_get_username(statistics->buddy->account));
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
612
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
613 statistics->last_status_id = gaim_status_get_id(status);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
614 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);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
615
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
616 result = dbi_conn_queryf(_conn, "insert into cap_status (buddy, account, protocol, status, event_time) values(%s, %s, %s, %s, now());", buddy_name, account_id, protocol_id, status_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
617 if(result)
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
618 dbi_result_free(result);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
619 else {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
620 const char *err = "";
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
621 dbi_conn_error(_conn, &err);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
622 gaim_debug_error("cap", "Could not insert status change event into database. %s\n", err);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
623 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
624
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
625 free(status_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
626 free(buddy_name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
627 free(protocol_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
628 free(account_id);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
629 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
630
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
631 static void insert_word_count(const char *sender, const char *receiver, guint count) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
632 //TODO!
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
633 //dbi_result result;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
634 //result = dbi_conn_queryf(_conn, "insert into cap_message values(\'%s\', \'%s\', %d, now());", sender, receiver, count);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
635 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
636
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
637 /* Callbacks */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
638 void display_statistics_action_cb(GaimBlistNode *node, gpointer data) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
639 GaimBuddy *buddy;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
640
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
641 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
642 buddy = (GaimBuddy *)node;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
643 gaim_debug_info("cap", "Statistics for %s requested.\n", buddy->name);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
644 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
645
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
646 /* Gaim plugin specific code */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
647
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
648 static gboolean plugin_load(GaimPlugin *plugin) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
649 _plugin_pointer = plugin;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
650 _signals_connected = FALSE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
651
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
652 /* buddy_stats is a hashtable where strings are keys
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
653 * and the keys are a buddies account id (GaimBuddy.name).
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
654 * keys/values are automatically deleted */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
655 _buddy_stats = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, destroy_stats);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
656
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
657 /* ? - Can't remember at the moment
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
658 */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
659 _my_offline_times = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
660
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
661 if(gaim_prefs_exists("/plugins/gtk/cap/libdbi_drivers"))
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
662 _num_drivers = dbi_initialize(gaim_prefs_get_string("/plugins/gtk/cap/libdbi_drivers"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
663 else
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
664 _num_drivers = dbi_initialize(NULL);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
665
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
666 if(_num_drivers == -1) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
667 gaim_debug_error("cap", "Error initializing dbi.\n");
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
668 gaim_prefs_set_bool("/plugins/gtk/cap/configured", FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
669 _dbi_initialized = FALSE;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
670 } else {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
671 _dbi_initialized = TRUE;
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
672 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
673
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
674
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
675 if(gaim_prefs_get_bool("/plugins/gtk/cap/configured") && gaim_prefs_get_bool("/plugins/gtk/cap/connected")) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
676 if(create_database_connection()) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
677 add_plugin_functionality(plugin);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
678 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
679 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
680 return TRUE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
681 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
682
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
683 static void add_plugin_functionality(GaimPlugin *plugin) {
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
684 if(_signals_connected)
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
685 return;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
686
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
687 gaim_debug_info("cap", "Adding plugin functionality.\n");
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
688
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
689 /* Connect all the signals */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
690 gaim_signal_connect(gaim_conversations_get_handle(), "sent-im-msg", plugin,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
691 GAIM_CALLBACK(sent_im_msg), NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
692
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
693 gaim_signal_connect(gaim_conversations_get_handle(), "received-im-msg", plugin,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
694 GAIM_CALLBACK(received_im_msg), NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
695
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
696 gaim_signal_connect(gaim_blist_get_handle(), "buddy-status-changed", plugin,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
697 GAIM_CALLBACK(buddy_status_changed), NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
698
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
699 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-on", plugin,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
700 GAIM_CALLBACK(buddy_signed_on), NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
701
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
702 gaim_signal_connect(gaim_blist_get_handle(), "buddy-signed-off", plugin,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
703 GAIM_CALLBACK(buddy_signed_off), NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
704
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
705 //gaim_signal_connect(gaim_blist_get_handle(), "blist-node-extended-menu", plugin,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
706 // GAIM_CALLBACK(blist_node_extended_menu), NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
707
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
708 gaim_signal_connect(gaim_gtk_blist_get_handle(), "drawing-tooltip", plugin,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
709 GAIM_CALLBACK(drawing_tooltip), NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
710
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
711 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", plugin,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
712 GAIM_CALLBACK(signed_on), NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
713
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
714 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", plugin,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
715 GAIM_CALLBACK(signed_off), NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
716
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
717 gaim_signal_connect(gaim_blist_get_handle(), "buddy-idle-changed", plugin,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
718 GAIM_CALLBACK(buddy_idle), NULL);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
719
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
720 _signals_connected = TRUE;
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
721 }
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
722
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
723 static void cancel_conversation_timeouts(gpointer key, gpointer value, gpointer user_data) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
724 CapStatistics *stats = value;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
725 if(stats->timeout_source_id != 0) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
726 g_source_remove(stats->timeout_source_id);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
727 stats->timeout_source_id = 0;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
728 }
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
729 }
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
730
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
731 static void remove_plugin_functionality(GaimPlugin *plugin) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
732 if(!_signals_connected)
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
733 return;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
734
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
735 gaim_debug_info("cap", "Removing plugin functionality.\n");
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
736
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
737 /* If there are any timeouts waiting to be processed then cancel them */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
738 g_hash_table_foreach(_buddy_stats, cancel_conversation_timeouts, NULL);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
739
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
740 /* Connect all the signals */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
741 gaim_signal_disconnect(gaim_conversations_get_handle(), "sent-im-msg", plugin,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
742 GAIM_CALLBACK(sent_im_msg));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
743
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
744 gaim_signal_disconnect(gaim_conversations_get_handle(), "received-im-msg", plugin,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
745 GAIM_CALLBACK(received_im_msg));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
746
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
747 gaim_signal_disconnect(gaim_blist_get_handle(), "buddy-status-changed", plugin,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
748 GAIM_CALLBACK(buddy_status_changed));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
749
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
750 gaim_signal_disconnect(gaim_blist_get_handle(), "buddy-signed-on", plugin,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
751 GAIM_CALLBACK(buddy_signed_on));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
752
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
753 gaim_signal_disconnect(gaim_blist_get_handle(), "buddy-signed-off", plugin,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
754 GAIM_CALLBACK(buddy_signed_off));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
755
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
756 //gaim_signal_disconnect(gaim_blist_get_handle(), "blist-node-extended-menu", plugin,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
757 // GAIM_CALLBACK(blist_node_extended_menu));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
758
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
759 gaim_signal_disconnect(gaim_gtk_blist_get_handle(), "drawing-tooltip", plugin,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
760 GAIM_CALLBACK(drawing_tooltip));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
761
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
762 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-on", plugin,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
763 GAIM_CALLBACK(signed_on));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
764
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
765 gaim_signal_disconnect(gaim_connections_get_handle(), "signed-off", plugin,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
766 GAIM_CALLBACK(signed_off));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
767
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
768 gaim_signal_disconnect(gaim_blist_get_handle(), "buddy-idle-changed", plugin,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
769 GAIM_CALLBACK(buddy_idle));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
770
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
771 _signals_connected = FALSE;
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
772 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
773
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
774 static void write_stats_on_unload(gpointer key, gpointer value, gpointer user_data) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
775 CapStatistics *stats = value;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
776 if(stats->last_message != -1 && stats->buddy != NULL) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
777 insert_cap_failure(stats);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
778 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
779 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
780
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
781 static gboolean plugin_unload(GaimPlugin *plugin) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
782 gaim_debug_info("cap", "CAP plugin unloading\n");
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
783
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
784 //clean up memory allocations
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
785 if(_buddy_stats) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
786 g_hash_table_foreach(_buddy_stats, write_stats_on_unload, NULL);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
787 g_hash_table_destroy(_buddy_stats);
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
788 }
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
789
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
790 //close database connection
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
791 dbi_conn_close(_conn);
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
792 _conn = NULL;
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
793 dbi_shutdown();
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
794
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
795 return TRUE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
796 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
797
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
798 static GtkWidget * get_config_frame(GaimPlugin *plugin) {
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
799 CapPrefsUI *ui = create_cap_prefs_ui();
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
800
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
801 /* Since we are editing the database setup we will disable the plugin.
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
802 * This will prevent database updates from occuring while there is potentially
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
803 * no connection to the database.
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
804 */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
805 remove_plugin_functionality(_plugin_pointer);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
806
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
807 return ui->ret;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
808 }
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
809
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
810 static void cap_prefs_ui_destroy_cb(GtkObject *object, gpointer user_data) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
811 CapPrefsUI *ui = user_data;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
812 if(_conn) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
813 add_plugin_functionality(_plugin_pointer);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
814 }
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
815 g_free(ui);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
816 }
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
817
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
818 static CapPrefsUI * create_cap_prefs_ui() {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
819 CapPrefsUI *ui = g_malloc(sizeof(CapPrefsUI));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
820
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
821 ui->ret = gtk_vbox_new(FALSE, 18);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
822 gtk_container_set_border_width(GTK_CONTAINER(ui->ret), 10);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
823 ui->db_vbox = gaim_gtk_make_frame(ui->ret, _("Database Configuration"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
824 ui->cap_vbox = gaim_gtk_make_frame(ui->ret, _("Statistics Configuration"));
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
825
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
826 /* dbd path input folder selector button */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
827 ui->dbd_label = gtk_label_new(_("libdbi driver path:"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
828 gtk_misc_set_alignment(GTK_MISC(ui->dbd_label), 0, 0.5);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
829 ui->dbd_input = gtk_file_chooser_button_new(_("libdbi Drivers Path"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
830 ui->dbd_button = gtk_button_new_with_label(_("Verify"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
831 ui->dbd_hbox = gtk_hbox_new(FALSE, 18);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
832 gtk_box_pack_start(GTK_BOX(ui->dbd_hbox), ui->dbd_label, FALSE, FALSE, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
833 gtk_box_pack_start(GTK_BOX(ui->dbd_hbox), ui->dbd_input, FALSE, FALSE, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
834 gtk_box_pack_start(GTK_BOX(ui->dbd_hbox), ui->dbd_button, FALSE, FALSE, 0);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
835
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
836 /* Setup the driver selection widget */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
837 ui->driver_choice = gtk_combo_box_new_text();
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
838
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
839 ui->driver_vbox = gtk_vbox_new(FALSE, 18);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
840 ui->driver_label = gtk_label_new(_("Driver:"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
841 gtk_misc_set_alignment(GTK_MISC(ui->driver_label), 0, 0.5);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
842 ui->driver_select_hbox = gtk_hbox_new(FALSE, 18);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
843 ui->driver_connect_button = gtk_toggle_button_new_with_label(_("Connected"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
844
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
845 gtk_box_pack_start(GTK_BOX(ui->driver_select_hbox), ui->driver_label, FALSE, FALSE, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
846 gtk_box_pack_start(GTK_BOX(ui->driver_select_hbox), ui->driver_choice, FALSE, FALSE, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
847 gtk_box_pack_start(GTK_BOX(ui->driver_select_hbox), ui->driver_connect_button, FALSE, FALSE, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
848
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
849 ui->driver_config = gtk_expander_new_with_mnemonic(_("Configure"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
850 ui->driver_config_hbox = gtk_hbox_new(FALSE, 18);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
851 gtk_box_pack_start(GTK_BOX(ui->driver_config_hbox), ui->driver_config, FALSE, FALSE, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
852
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
853 gtk_box_pack_start(GTK_BOX(ui->driver_vbox), ui->driver_select_hbox, FALSE, FALSE, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
854 gtk_box_pack_start(GTK_BOX(ui->driver_vbox), ui->driver_config_hbox, FALSE, FALSE, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
855
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
856 /* msg_difference spinner */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
857 ui->msg_difference_label = gtk_label_new(_("Maximum response timeout:"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
858 gtk_misc_set_alignment(GTK_MISC(ui->msg_difference_label), 0, 0.5);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
859 ui->msg_difference_input = gtk_spin_button_new_with_range(1, 1440, 1);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
860 ui->msg_difference_minutes_label = gtk_label_new(_("minutes"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
861 gtk_misc_set_alignment(GTK_MISC(ui->msg_difference_minutes_label), 0, 0.5);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
862
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
863 /* last_seen spinner */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
864 ui->last_seen_label = gtk_label_new(_("Maximum last-seen difference:"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
865 gtk_misc_set_alignment(GTK_MISC(ui->last_seen_label), 0, 0.5);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
866 ui->last_seen_input = gtk_spin_button_new_with_range(1, 1440, 1);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
867 ui->last_seen_minutes_label = gtk_label_new(_("minutes"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
868 gtk_misc_set_alignment(GTK_MISC(ui->last_seen_minutes_label), 0, 0.5);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
869
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
870 /* threshold spinner */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
871 ui->threshold_label = gtk_label_new(_("Threshold:"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
872 gtk_misc_set_alignment(GTK_MISC(ui->threshold_label), 0, 0.5);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
873 ui->threshold_input = gtk_spin_button_new_with_range(1, 1440, 1);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
874 ui->threshold_minutes_label = gtk_label_new(_("minutes"));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
875 gtk_misc_set_alignment(GTK_MISC(ui->threshold_minutes_label), 0, 0.5);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
876
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
877 /* Layout threshold/last-seen/response-timeout input items */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
878 ui->table_layout = gtk_table_new(3, 3, FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
879 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->threshold_label, 0, 1, 0, 1,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
880 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
881 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
882
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
883 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->threshold_input, 1, 2, 0, 1,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
884 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
885 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
886
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
887 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->threshold_minutes_label, 2, 3, 0, 1,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
888 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
889 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
890
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
891 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->msg_difference_label, 0, 1, 1, 2,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
892 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
893 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
894
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
895 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->msg_difference_input, 1, 2, 1, 2,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
896 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
897 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
898
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
899 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->msg_difference_minutes_label, 2, 3, 1, 2,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
900 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
901 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
902
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
903 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->last_seen_label, 0, 1, 2,3,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
904 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
905 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
906
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
907 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->last_seen_input, 1, 2, 2, 3,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
908 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
909 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
910
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
911 gtk_table_attach(GTK_TABLE(ui->table_layout), ui->last_seen_minutes_label, 2, 3, 2, 3,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
912 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
913 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
914
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
915
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
916 /* Config window - lay it out */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
917 gtk_box_pack_start(GTK_BOX(ui->db_vbox), ui->dbd_hbox, FALSE, FALSE, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
918 gtk_box_pack_start(GTK_BOX(ui->db_vbox), ui->driver_vbox, FALSE, FALSE, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
919 gtk_box_pack_start(GTK_BOX(ui->cap_vbox), ui->table_layout, FALSE, FALSE, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
920
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
921 /* Set the input areas to contain the configuration values from
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
922 * gaim prefs.
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
923 */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
924 if(gaim_prefs_exists("/plugins/gtk/cap/libdbi_drivers")) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
925 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(ui->dbd_input), gaim_prefs_get_string("/plugins/gtk/cap/libdbi_drivers"));
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
926 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
927 if(gaim_prefs_exists("/plugins/gtk/cap/max_msg_difference")) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
928 int max_msg_diff = gaim_prefs_get_int("/plugins/gtk/cap/max_msg_difference");
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
929 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ui->msg_difference_input), max_msg_diff);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
930 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
931 if(gaim_prefs_exists("/plugins/gtk/cap/max_seen_difference")) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
932 int max_seen_diff = gaim_prefs_get_int("/plugins/gtk/cap/max_seen_difference");
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
933 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ui->last_seen_input), max_seen_diff);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
934 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
935 if(gaim_prefs_exists("/plugins/gtk/cap/threshold")) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
936 int threshold = gaim_prefs_get_int("/plugins/gtk/cap/threshold");
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
937 gtk_spin_button_set_value(GTK_SPIN_BUTTON(ui->threshold_input), threshold);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
938 }
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
939
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
940 /* Add the signals */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
941 g_signal_connect(G_OBJECT(ui->ret), "destroy",
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
942 G_CALLBACK(cap_prefs_ui_destroy_cb), ui);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
943
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
944 g_signal_connect(G_OBJECT(ui->driver_choice), "changed",
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
945 G_CALLBACK(driver_choice_changed_cb), ui);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
946
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
947 g_signal_connect(G_OBJECT(ui->driver_config), "notify::expanded",
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
948 G_CALLBACK(driver_config_expanded_cb), ui);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
949
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
950 g_signal_connect(G_OBJECT(ui->driver_connect_button), "toggled",
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
951 G_CALLBACK(connect_toggled_cb), ui);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
952
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
953 g_signal_connect(G_OBJECT(ui->msg_difference_input), "value-changed",
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
954 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/max_msg_difference");
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
955
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
956 g_signal_connect(G_OBJECT(ui->last_seen_input), "value-changed",
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
957 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/max_seen_difference");
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
958
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
959 g_signal_connect(G_OBJECT(ui->threshold_input), "value-changed",
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
960 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/threshold");
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
961
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
962 g_signal_connect(G_OBJECT(ui->dbd_button), "clicked",
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
963 G_CALLBACK(driver_location_verify_cb), ui);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
964
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
965 /* libdbi was not successfully initialized so disable the driver selection.
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
966 * Also disable the configuration for the database.
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
967 */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
968 if(!_dbi_initialized || _num_drivers <= 0) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
969 /* Since DBI is not available disable database configuration */
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
970 gtk_widget_set_sensitive(ui->driver_choice, FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
971 gtk_widget_set_sensitive(ui->driver_config, FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
972 gtk_widget_set_sensitive(ui->driver_connect_button, FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
973 } else {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
974 set_driver_choice_options(GTK_COMBO_BOX(ui->driver_choice));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
975 }
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
976
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
977 if(_conn) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
978 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui->driver_connect_button), TRUE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
979 gtk_widget_set_sensitive(ui->driver_choice, FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
980 gtk_widget_set_sensitive(ui->driver_config, FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
981 } else {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
982 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui->driver_connect_button), FALSE);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
983 }
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
984
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
985 return ui;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
986 }
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
987
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
988 static void driver_choice_changed_cb(GtkComboBox *widget, gpointer user_data) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
989 CapPrefsUI *ui = user_data;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
990 if(strcmp(gtk_combo_box_get_active_text(GTK_COMBO_BOX(ui->driver_choice)), "mysql") == 0) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
991 gtk_widget_set_sensitive(ui->driver_config, TRUE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
992 gtk_widget_set_sensitive(ui->driver_connect_button, TRUE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
993 } else {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
994 gtk_widget_set_sensitive(ui->driver_config, FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
995 gtk_widget_set_sensitive(ui->driver_connect_button, FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
996 }
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
997 }
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
998
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
999 static void driver_config_expanded_cb(GObject *object, GParamSpec *param_spec, gpointer user_data) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1000 CapPrefsUI *ui = user_data;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1001 GtkExpander *expander;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1002 gchar *driver = gtk_combo_box_get_active_text(GTK_COMBO_BOX(ui->driver_choice));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1003 expander = GTK_EXPANDER(object);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1004 if(gtk_expander_get_expanded(expander)) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1005 if(strcmp(driver, "mysql") == 0) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1006 gtk_container_add(GTK_CONTAINER(expander), get_mysql_config());
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1007 }
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1008 } else {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1009 gtk_container_remove(GTK_CONTAINER(expander), gtk_bin_get_child(GTK_BIN(expander)));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1010 }
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1011 }
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1012
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1013 static void connect_toggled_cb(GtkToggleButton *togglebutton, gpointer user_data) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1014 CapPrefsUI *ui = user_data;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1015 if(gtk_toggle_button_get_active(togglebutton)) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1016 //connect
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1017 if(create_database_connection()) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1018 gtk_widget_set_sensitive(GTK_WIDGET(ui->driver_choice), FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1019 gtk_widget_set_sensitive(GTK_WIDGET(ui->driver_config), FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1020 gtk_widget_set_sensitive(GTK_WIDGET(ui->dbd_input), FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1021 gtk_widget_set_sensitive(GTK_WIDGET(ui->dbd_button), FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1022 gaim_prefs_set_bool("/plugins/gtk/cap/connected", TRUE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1023 } else {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1024 gtk_toggle_button_set_active(togglebutton, FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1025 }
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1026 } else {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1027 //disconnect
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1028 destroy_database_connection();
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1029 gtk_widget_set_sensitive(GTK_WIDGET(ui->driver_choice), TRUE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1030 gtk_widget_set_sensitive(GTK_WIDGET(ui->driver_config), TRUE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1031 gtk_widget_set_sensitive(GTK_WIDGET(ui->dbd_input), TRUE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1032 gtk_widget_set_sensitive(GTK_WIDGET(ui->dbd_button), TRUE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1033 gaim_prefs_set_bool("/plugins/gtk/cap/connected", FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1034 }
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1035 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1036
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1037 static void numeric_spinner_prefs_cb(GtkSpinButton *spinbutton, gpointer user_data) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1038 gaim_prefs_set_int(user_data, gtk_spin_button_get_value_as_int(spinbutton));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1039 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1040
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1041 static void driver_location_verify_cb(GtkButton *button, gpointer user_data) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1042 CapPrefsUI *ui = user_data;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1043 gchar *path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(ui->dbd_input));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1044
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1045 if(_dbi_initialized)
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1046 dbi_shutdown();
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1047
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1048 gaim_prefs_set_string("/plugins/gtk/cap/libdbi_drivers", path);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1049 _num_drivers = dbi_initialize(path);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1050 if(_num_drivers == -1) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1051 _dbi_initialized = FALSE;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1052 } else {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1053 _dbi_initialized = TRUE;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1054 }
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1055 if(_num_drivers > 0) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1056 gtk_widget_set_sensitive(GTK_WIDGET(ui->driver_choice), TRUE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1057 gtk_widget_set_sensitive(GTK_WIDGET(ui->driver_config), TRUE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1058 gtk_widget_set_sensitive(GTK_WIDGET(ui->driver_connect_button), TRUE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1059 set_driver_choice_options(GTK_COMBO_BOX(ui->driver_choice));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1060 } else {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1061 gtk_widget_set_sensitive(GTK_WIDGET(ui->driver_choice), FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1062 gtk_widget_set_sensitive(GTK_WIDGET(ui->driver_config), FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1063 gtk_expander_set_expanded(GTK_EXPANDER(ui->driver_config), FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1064 gtk_widget_set_sensitive(GTK_WIDGET(ui->driver_connect_button), FALSE);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1065 }
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1066 }
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1067
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1068 static gboolean text_entry_prefs_cb(GtkWidget *widget, GdkEventFocus *event, gpointer user_data) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1069 gaim_prefs_set_string(user_data, gtk_entry_get_text(GTK_ENTRY(widget)));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1070 return FALSE;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1071 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1072
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1073 void set_driver_choice_options(GtkComboBox *chooser) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1074 dbi_driver driver = NULL;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1075 GtkListStore *list_store;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1076 gint index = 0;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1077 gint selected = 0;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1078
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1079 list_store = GTK_LIST_STORE(gtk_combo_box_get_model(chooser));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1080 gtk_list_store_clear(list_store);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1081
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1082 if(!_dbi_initialized)
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1083 return;
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1084
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1085 while((driver = dbi_driver_list(driver)) != NULL) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1086 gtk_combo_box_append_text(chooser, dbi_driver_get_name(driver));
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1087 if(strcmp(dbi_driver_get_name(driver), gaim_prefs_get_string("/plugins/gtk/cap/db_driver")) == 0) {
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1088 selected = index;
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1089 }
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1090 ++index;
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1091 }
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1092 gtk_combo_box_set_active(chooser, selected);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1093 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1094
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1095 static GtkWidget * get_mysql_config() {
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1096 GtkWidget *config_area = gtk_table_new(5, 2, FALSE);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1097 GtkWidget *username_label = gtk_label_new(_("Username:"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1098 GtkWidget *username_input = gtk_entry_new();
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1099 GtkWidget *password_label = gtk_label_new(_("Password:"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1100 GtkWidget *password_input = gtk_entry_new();
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1101 GtkWidget *host_label = gtk_label_new(_("Host:"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1102 GtkWidget *host_input = gtk_entry_new();
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1103 GtkWidget *db_label = gtk_label_new(_("Database:"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1104 GtkWidget *db_input = gtk_entry_new();
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1105 GtkWidget *port_label = gtk_label_new(_("Port:"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1106 GtkWidget *port_input = gtk_spin_button_new_with_range(0, 10000, 1);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1107
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1108 gtk_entry_set_visibility(GTK_ENTRY(password_input), FALSE);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1109
14350
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1110 gtk_misc_set_alignment(GTK_MISC(username_label), 0, 0.5);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1111 gtk_misc_set_padding(GTK_MISC(username_label), 10, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1112
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1113 gtk_misc_set_alignment(GTK_MISC(password_label), 0, 0.5);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1114 gtk_misc_set_padding(GTK_MISC(password_label), 10, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1115
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1116 gtk_misc_set_alignment(GTK_MISC(host_label), 0, 0.5);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1117 gtk_misc_set_padding(GTK_MISC(host_label), 10, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1118
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1119 gtk_misc_set_alignment(GTK_MISC(db_label), 0, 0.5);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1120 gtk_misc_set_padding(GTK_MISC(db_label), 10, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1121
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1122 gtk_misc_set_alignment(GTK_MISC(port_label), 0, 0.5);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1123 gtk_misc_set_padding(GTK_MISC(port_label), 10, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1124
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1125 gtk_table_attach(GTK_TABLE(config_area), host_label, 0, 1, 0, 1,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1126 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1127 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1128 gtk_table_attach(GTK_TABLE(config_area), host_input, 1, 2, 0, 1,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1129 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1130 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1131 gtk_table_attach(GTK_TABLE(config_area), port_label, 0, 1, 1, 2,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1132 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1133 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1134 gtk_table_attach(GTK_TABLE(config_area), port_input, 1, 2, 1, 2,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1135 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1136 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1137 gtk_table_attach(GTK_TABLE(config_area), db_label, 0, 1, 2, 3,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1138 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1139 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1140 gtk_table_attach(GTK_TABLE(config_area), db_input, 1, 2, 2, 3,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1141 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1142 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1143 gtk_table_attach(GTK_TABLE(config_area), username_label, 0, 1, 3, 4,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1144 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1145 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1146 gtk_table_attach(GTK_TABLE(config_area), username_input, 1, 2, 3, 4,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1147 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1148 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1149 gtk_table_attach(GTK_TABLE(config_area), password_label, 0, 1, 4, 5,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1150 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1151 (GtkAttachOptions) (0), 0, 0);
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1152 gtk_table_attach(GTK_TABLE(config_area), password_input, 1, 2, 4, 5,
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1153 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
eec3ce357b70 [gaim-migrate @ 17053]
Geoff Foster <g-off_>
parents: 14266
diff changeset
1154 (GtkAttachOptions) (0), 0, 0);
14266
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1155
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1156 //Initialize with data
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1157 if(gaim_prefs_exists("/plugins/gtk/cap/mysql/db_host")) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1158 gtk_entry_set_text(GTK_ENTRY(host_input), gaim_prefs_get_string("/plugins/gtk/cap/mysql/db_host"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1159 } else {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1160 gtk_entry_set_text(GTK_ENTRY(host_input), "localhost");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1161 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1162 if(gaim_prefs_exists("/plugins/gtk/cap/mysql/db_port")) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1163 gtk_spin_button_set_value(GTK_SPIN_BUTTON(port_input), gaim_prefs_get_int("/plugins/gtk/cap/mysql/db_port"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1164 } else {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1165 gtk_spin_button_set_value(GTK_SPIN_BUTTON(port_input), 3306);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1166 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1167 if(gaim_prefs_exists("/plugins/gtk/cap/mysql/db_user")) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1168 gtk_entry_set_text(GTK_ENTRY(username_input), gaim_prefs_get_string("/plugins/gtk/cap/mysql/db_user"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1169 } else {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1170 gtk_entry_set_text(GTK_ENTRY(username_input), "root");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1171 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1172 if(gaim_prefs_exists("/plugins/gtk/cap/mysql/db_password")) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1173 gtk_entry_set_text(GTK_ENTRY(password_input), gaim_prefs_get_string("/plugins/gtk/cap/mysql/db_password"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1174 } else {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1175 gtk_entry_set_text(GTK_ENTRY(password_input), "");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1176 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1177 if(gaim_prefs_exists("/plugins/gtk/cap/mysql/db_name")) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1178 gtk_entry_set_text(GTK_ENTRY(db_input), gaim_prefs_get_string("/plugins/gtk/cap/mysql/db_name"));
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1179 } else {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1180 gtk_entry_set_text(GTK_ENTRY(db_input), "cap");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1181 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1182
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1183 //Add callbacks
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1184 g_signal_connect(G_OBJECT(host_input), "focus-out-event",
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1185 G_CALLBACK(text_entry_prefs_cb), "/plugins/gtk/cap/mysql/db_host");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1186 g_signal_connect(G_OBJECT(port_input), "value-changed",
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1187 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/mysql/db_port");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1188 g_signal_connect(G_OBJECT(username_input), "focus-out-event",
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1189 G_CALLBACK(text_entry_prefs_cb), "/plugins/gtk/cap/mysql/db_user");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1190 g_signal_connect(G_OBJECT(password_input), "focus-out-event",
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1191 G_CALLBACK(text_entry_prefs_cb), "/plugins/gtk/cap/mysql/db_password");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1192 g_signal_connect(G_OBJECT(db_input), "focus-out-event",
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1193 G_CALLBACK(text_entry_prefs_cb), "/plugins/gtk/cap/mysql/db_name");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1194
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1195 gtk_widget_show_all(config_area);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1196
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1197 return config_area;
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1198 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1199
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1200 static GaimGtkPluginUiInfo ui_info = {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1201 get_config_frame,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1202 0 /* page_num (reserved) */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1203 };
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1204
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1205 static GaimPluginInfo info = {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1206 GAIM_PLUGIN_MAGIC,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1207 GAIM_MAJOR_VERSION,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1208 GAIM_MINOR_VERSION,
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1209 GAIM_PLUGIN_STANDARD, /**< type */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1210 GAIM_GTK_PLUGIN_TYPE, /**< ui_requirement */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1211 0, /**< flags */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1212 NULL, /**< dependencies */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1213 GAIM_PRIORITY_DEFAULT, /**< priority */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1214 CAP_PLUGIN_ID, /**< id */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1215 "Contact Availability Prediction", /**< name */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1216 VERSION, /**< version */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1217 N_("Contact Availability Prediction plugin."), /** summary */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1218 N_("The contact availability plugin (cap) is used to display statistical information about buddies in a users contact list."),
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1219 /** description */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1220 "Geoffrey Foster <geoffrey.foster@gmail.com>", /**< author */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1221 GAIM_WEBSITE, /**< homepage */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1222 plugin_load, /**< load */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1223 plugin_unload, /**< unload */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1224 NULL, /**< destroy */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1225 &ui_info, /**< ui_info */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1226 NULL, /**< extra_info */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1227 NULL, /**< prefs_info */
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1228 NULL
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1229 };
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1230
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1231 static void init_plugin(GaimPlugin *plugin) {
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1232 gaim_prefs_add_none("/plugins/gtk/cap");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1233 gaim_prefs_add_int("/plugins/gtk/cap/max_seen_difference", 1);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1234 gaim_prefs_add_int("/plugins/gtk/cap/max_msg_difference", 10);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1235 gaim_prefs_add_int("/plugins/gtk/cap/threshold", 5);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1236 gaim_prefs_add_bool("/plugins/gtk/cap/configured", FALSE);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1237 gaim_prefs_add_string("/plugins/gtk/cap/db_driver", "mysql");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1238 gaim_prefs_add_none("/plugins/gtk/cap/mysql");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1239 gaim_prefs_add_string("/plugins/gtk/cap/mysql/db_host", "localhost");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1240 gaim_prefs_add_int("/plugins/gtk/cap/mysql/db_port", 3306);
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1241 gaim_prefs_add_string("/plugins/gtk/cap/mysql/db_user", "root");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1242 gaim_prefs_add_string("/plugins/gtk/cap/mysql/db_password", "");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1243 gaim_prefs_add_string("/plugins/gtk/cap/mysql/db_name", "cap");
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1244 }
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1245
63ef6342db05 [gaim-migrate @ 16948]
Geoff Foster <g-off_>
parents:
diff changeset
1246 GAIM_INIT_PLUGIN(cap, init_plugin, info);