| 91 sqlite3_finalize(stmt); |
91 sqlite3_finalize(stmt); |
| 92 } |
92 } |
| 93 } |
93 } |
| 94 sqlite3_free(sql); |
94 sqlite3_free(sql); |
| 95 |
95 |
| 96 |
96 |
| 97 if(strcmp(purple_status_get_id(get_status_for(buddy)), "offline") == 0) { |
97 if(strcmp(purple_status_get_id(get_status_for(buddy)), "offline") == 0) { |
| 98 /* This is kind of stupid, change it. */ |
98 /* This is kind of stupid, change it. */ |
| 99 if(prediction == 1.0f) |
99 if(prediction == 1.0f) |
| 100 prediction = 0.0f; |
100 prediction = 0.0f; |
| 101 } |
101 } |
| 150 char *sql_ins_up = NULL; |
150 char *sql_ins_up = NULL; |
| 151 |
151 |
| 152 purple_debug_info("cap", "%s\n", sql_select); |
152 purple_debug_info("cap", "%s\n", sql_select); |
| 153 |
153 |
| 154 sqlite3_prepare(_db, sql_select, -1, &stmt, &tail); |
154 sqlite3_prepare(_db, sql_select, -1, &stmt, &tail); |
| 155 |
155 |
| 156 rc = sqlite3_step(stmt); |
156 rc = sqlite3_step(stmt); |
| 157 |
157 |
| 158 if(rc == SQLITE_DONE) { |
158 if(rc == SQLITE_DONE) { |
| 159 sql_ins_up = sqlite3_mprintf("INSERT INTO cap_msg_count VALUES (%Q, %Q, %Q, %d, %d, %d);", |
159 sql_ins_up = sqlite3_mprintf("INSERT INTO cap_msg_count VALUES (%Q, %Q, %Q, %d, %d, %d);", |
| 160 buddy_name, account, protocol, minute, 1, 0); |
160 buddy_name, account, protocol, minute, 1, 0); |
| 187 char *sql_ins_up = NULL; |
187 char *sql_ins_up = NULL; |
| 188 |
188 |
| 189 purple_debug_info("cap", "%s\n", sql_select); |
189 purple_debug_info("cap", "%s\n", sql_select); |
| 190 |
190 |
| 191 sqlite3_prepare(_db, sql_select, -1, &stmt, &tail); |
191 sqlite3_prepare(_db, sql_select, -1, &stmt, &tail); |
| 192 |
192 |
| 193 rc = sqlite3_step(stmt); |
193 rc = sqlite3_step(stmt); |
| 194 |
194 |
| 195 if(rc == SQLITE_DONE) { |
195 if(rc == SQLITE_DONE) { |
| 196 sql_ins_up = sqlite3_mprintf("INSERT INTO cap_status_count VALUES (%Q, %Q, %Q, %Q, %d, %d);", |
196 sql_ins_up = sqlite3_mprintf("INSERT INTO cap_status_count VALUES (%Q, %Q, %Q, %Q, %d, %d);", |
| 197 buddy_name, account, protocol, status_id, 1, 0); |
197 buddy_name, account, protocol, status_id, 1, 0); |
| 224 char *sql_ins_up = NULL; |
224 char *sql_ins_up = NULL; |
| 225 |
225 |
| 226 purple_debug_info("cap", "%s\n", sql_select); |
226 purple_debug_info("cap", "%s\n", sql_select); |
| 227 |
227 |
| 228 sqlite3_prepare(_db, sql_select, -1, &stmt, &tail); |
228 sqlite3_prepare(_db, sql_select, -1, &stmt, &tail); |
| 229 |
229 |
| 230 rc = sqlite3_step(stmt); |
230 rc = sqlite3_step(stmt); |
| 231 |
231 |
| 232 if(rc == SQLITE_DONE) { |
232 if(rc == SQLITE_DONE) { |
| 233 sql_ins_up = sqlite3_mprintf("INSERT INTO cap_msg_count VALUES (%Q, %Q, %Q, %d, %d, %d);", |
233 sql_ins_up = sqlite3_mprintf("INSERT INTO cap_msg_count VALUES (%Q, %Q, %Q, %d, %d, %d);", |
| 234 buddy_name, account, protocol, minute, 0, 1); |
234 buddy_name, account, protocol, minute, 0, 1); |
| 261 char *sql_ins_up = NULL; |
261 char *sql_ins_up = NULL; |
| 262 |
262 |
| 263 purple_debug_info("cap", "%s\n", sql_select); |
263 purple_debug_info("cap", "%s\n", sql_select); |
| 264 |
264 |
| 265 sqlite3_prepare(_db, sql_select, -1, &stmt, &tail); |
265 sqlite3_prepare(_db, sql_select, -1, &stmt, &tail); |
| 266 |
266 |
| 267 rc = sqlite3_step(stmt); |
267 rc = sqlite3_step(stmt); |
| 268 |
268 |
| 269 if(rc == SQLITE_DONE) { |
269 if(rc == SQLITE_DONE) { |
| 270 sql_ins_up = sqlite3_mprintf("INSERT INTO cap_status_count VALUES (%Q, %Q, %Q, %Q, %d, %d);", |
270 sql_ins_up = sqlite3_mprintf("INSERT INTO cap_status_count VALUES (%Q, %Q, %Q, %Q, %d, %d);", |
| 271 buddy_name, account, protocol, status_id, 0, 1); |
271 buddy_name, account, protocol, status_id, 0, 1); |
| 294 const gchar *status_id = (stats->last_message_status_id) ? |
294 const gchar *status_id = (stats->last_message_status_id) ? |
| 295 stats->last_message_status_id : |
295 stats->last_message_status_id : |
| 296 purple_status_get_id(get_status_for(stats->buddy)); |
296 purple_status_get_id(get_status_for(stats->buddy)); |
| 297 struct tm *current_time; |
297 struct tm *current_time; |
| 298 int minute; |
298 int minute; |
| 299 |
299 |
| 300 if(stats->last_message == -1) { |
300 if(stats->last_message == -1) { |
| 301 time_t now = time(NULL); |
301 time_t now = time(NULL); |
| 302 current_time = localtime(&now); |
302 current_time = localtime(&now); |
| 303 } else { |
303 } else { |
| 304 current_time = localtime(&stats->last_message); |
304 current_time = localtime(&stats->last_message); |
| 305 } |
305 } |
| 306 minute = current_time->tm_min + current_time->tm_hour * 60; |
306 minute = current_time->tm_min + current_time->tm_hour * 60; |
| 307 |
307 |
| 308 insert_cap_msg_count_success(buddy_name, account_id, protocol_id, minute); |
308 insert_cap_msg_count_success(buddy_name, account_id, protocol_id, minute); |
| 309 |
309 |
| 310 insert_cap_status_count_success(buddy_name, account_id, protocol_id, status_id); |
310 insert_cap_status_count_success(buddy_name, account_id, protocol_id, status_id); |
| 311 |
311 |
| 312 stats->last_message = -1; |
312 stats->last_message = -1; |
| 313 stats->last_message_status_id = NULL; |
313 stats->last_message_status_id = NULL; |
| 314 } |
314 } |
| 322 purple_status_get_id(get_status_for(stats->buddy)); |
322 purple_status_get_id(get_status_for(stats->buddy)); |
| 323 struct tm *current_time = localtime(&stats->last_message); |
323 struct tm *current_time = localtime(&stats->last_message); |
| 324 int minute = current_time->tm_min + current_time->tm_hour * 60; |
324 int minute = current_time->tm_min + current_time->tm_hour * 60; |
| 325 |
325 |
| 326 insert_cap_msg_count_failed(buddy_name, account_id, protocol_id, minute); |
326 insert_cap_msg_count_failed(buddy_name, account_id, protocol_id, minute); |
| 327 |
327 |
| 328 insert_cap_status_count_failed(buddy_name, account_id, protocol_id, status_id); |
328 insert_cap_status_count_failed(buddy_name, account_id, protocol_id, status_id); |
| 329 |
329 |
| 330 stats->last_message = -1; |
330 stats->last_message = -1; |
| 331 stats->last_message_status_id = NULL; |
331 stats->last_message_status_id = NULL; |
| 332 } |
332 } |
| 333 |
333 |
| 334 static gboolean max_message_difference_cb(gpointer data) { |
334 static gboolean max_message_difference_cb(gpointer data) { |
| 382 return; |
382 return; |
| 383 |
383 |
| 384 stats = get_stats_for(buddy); |
384 stats = get_stats_for(buddy); |
| 385 |
385 |
| 386 /* insert_word_count(sender, buddy_name, words); */ |
386 /* insert_word_count(sender, buddy_name, words); */ |
| 387 |
387 |
| 388 /* If we are waiting for a response from a prior message |
388 /* If we are waiting for a response from a prior message |
| 389 * then cancel the timeout callback. */ |
389 * then cancel the timeout callback. */ |
| 390 if(stats->timeout_source_id != 0) { |
390 if(stats->timeout_source_id != 0) { |
| 391 purple_debug_info("cap", "Cancelling timeout callback\n"); |
391 purple_debug_info("cap", "Cancelling timeout callback\n"); |
| 392 purple_timeout_remove(stats->timeout_source_id); |
392 purple_timeout_remove(stats->timeout_source_id); |
| 579 /* make database connection here */ |
579 /* make database connection here */ |
| 580 rc = sqlite3_open(path, &_db); |
580 rc = sqlite3_open(path, &_db); |
| 581 g_free(path); |
581 g_free(path); |
| 582 if(rc != SQLITE_OK) |
582 if(rc != SQLITE_OK) |
| 583 return FALSE; |
583 return FALSE; |
| 584 |
584 |
| 585 /* Add tables here */ |
585 /* Add tables here */ |
| 586 create_tables(); |
586 create_tables(); |
| 587 purple_debug_info("cap", "Database connection successfully made.\n"); |
587 purple_debug_info("cap", "Database connection successfully made.\n"); |
| 588 return TRUE; |
588 return TRUE; |
| 589 } |
589 } |
| 650 |
650 |
| 651 /* buddy_stats is a hashtable where strings are keys |
651 /* buddy_stats is a hashtable where strings are keys |
| 652 * and the keys are a buddies account id (PurpleBuddy.name). |
652 * and the keys are a buddies account id (PurpleBuddy.name). |
| 653 * keys/values are automatically deleted */ |
653 * keys/values are automatically deleted */ |
| 654 _buddy_stats = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, destroy_stats); |
654 _buddy_stats = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, destroy_stats); |
| 655 |
655 |
| 656 /* ? - Can't remember at the moment |
656 /* ? - Can't remember at the moment |
| 657 */ |
657 */ |
| 658 _my_offline_times = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
658 _my_offline_times = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
| 659 |
659 |
| 660 if(create_database_connection()) { |
660 if(create_database_connection()) { |
| 666 static void add_plugin_functionality(PurplePlugin *plugin) { |
666 static void add_plugin_functionality(PurplePlugin *plugin) { |
| 667 if(_signals_connected) |
667 if(_signals_connected) |
| 668 return; |
668 return; |
| 669 |
669 |
| 670 purple_debug_info("cap", "Adding plugin functionality.\n"); |
670 purple_debug_info("cap", "Adding plugin functionality.\n"); |
| 671 |
671 |
| 672 /* Connect all the signals */ |
672 /* Connect all the signals */ |
| 673 purple_signal_connect(purple_conversations_get_handle(), "sent-im-msg", plugin, |
673 purple_signal_connect(purple_conversations_get_handle(), "sent-im-msg", plugin, |
| 674 PURPLE_CALLBACK(sent_im_msg), NULL); |
674 PURPLE_CALLBACK(sent_im_msg), NULL); |
| 675 |
675 |
| 676 purple_signal_connect(purple_conversations_get_handle(), "received-im-msg", plugin, |
676 purple_signal_connect(purple_conversations_get_handle(), "received-im-msg", plugin, |
| 688 purple_signal_connect(pidgin_blist_get_handle(), "drawing-tooltip", plugin, |
688 purple_signal_connect(pidgin_blist_get_handle(), "drawing-tooltip", plugin, |
| 689 PURPLE_CALLBACK(drawing_tooltip), NULL); |
689 PURPLE_CALLBACK(drawing_tooltip), NULL); |
| 690 |
690 |
| 691 purple_signal_connect(purple_connections_get_handle(), "signed-on", plugin, |
691 purple_signal_connect(purple_connections_get_handle(), "signed-on", plugin, |
| 692 PURPLE_CALLBACK(signed_on), NULL); |
692 PURPLE_CALLBACK(signed_on), NULL); |
| 693 |
693 |
| 694 purple_signal_connect(purple_connections_get_handle(), "signed-off", plugin, |
694 purple_signal_connect(purple_connections_get_handle(), "signed-off", plugin, |
| 695 PURPLE_CALLBACK(signed_off), NULL); |
695 PURPLE_CALLBACK(signed_off), NULL); |
| 696 |
696 |
| 697 _signals_connected = TRUE; |
697 _signals_connected = TRUE; |
| 698 } |
698 } |
| 711 |
711 |
| 712 purple_debug_info("cap", "Removing plugin functionality.\n"); |
712 purple_debug_info("cap", "Removing plugin functionality.\n"); |
| 713 |
713 |
| 714 /* If there are any timeouts waiting to be processed then cancel them */ |
714 /* If there are any timeouts waiting to be processed then cancel them */ |
| 715 g_hash_table_foreach(_buddy_stats, cancel_conversation_timeouts, NULL); |
715 g_hash_table_foreach(_buddy_stats, cancel_conversation_timeouts, NULL); |
| 716 |
716 |
| 717 /* Connect all the signals */ |
717 /* Connect all the signals */ |
| 718 purple_signal_disconnect(purple_conversations_get_handle(), "sent-im-msg", plugin, |
718 purple_signal_disconnect(purple_conversations_get_handle(), "sent-im-msg", plugin, |
| 719 PURPLE_CALLBACK(sent_im_msg)); |
719 PURPLE_CALLBACK(sent_im_msg)); |
| 720 |
720 |
| 721 purple_signal_disconnect(purple_conversations_get_handle(), "received-im-msg", plugin, |
721 purple_signal_disconnect(purple_conversations_get_handle(), "received-im-msg", plugin, |
| 733 purple_signal_disconnect(pidgin_blist_get_handle(), "drawing-tooltip", plugin, |
733 purple_signal_disconnect(pidgin_blist_get_handle(), "drawing-tooltip", plugin, |
| 734 PURPLE_CALLBACK(drawing_tooltip)); |
734 PURPLE_CALLBACK(drawing_tooltip)); |
| 735 |
735 |
| 736 purple_signal_disconnect(purple_connections_get_handle(), "signed-on", plugin, |
736 purple_signal_disconnect(purple_connections_get_handle(), "signed-on", plugin, |
| 737 PURPLE_CALLBACK(signed_on)); |
737 PURPLE_CALLBACK(signed_on)); |
| 738 |
738 |
| 739 purple_signal_disconnect(purple_connections_get_handle(), "signed-off", plugin, |
739 purple_signal_disconnect(purple_connections_get_handle(), "signed-off", plugin, |
| 740 PURPLE_CALLBACK(signed_off)); |
740 PURPLE_CALLBACK(signed_off)); |
| 741 |
741 |
| 742 _signals_connected = FALSE; |
742 _signals_connected = FALSE; |
| 743 } |
743 } |
| 749 } |
749 } |
| 750 } |
750 } |
| 751 |
751 |
| 752 static gboolean plugin_unload(PurplePlugin *plugin) { |
752 static gboolean plugin_unload(PurplePlugin *plugin) { |
| 753 purple_debug_info("cap", "CAP plugin unloading\n"); |
753 purple_debug_info("cap", "CAP plugin unloading\n"); |
| 754 |
754 |
| 755 /* clean up memory allocations */ |
755 /* clean up memory allocations */ |
| 756 if(_buddy_stats) { |
756 if(_buddy_stats) { |
| 757 g_hash_table_foreach(_buddy_stats, write_stats_on_unload, NULL); |
757 g_hash_table_foreach(_buddy_stats, write_stats_on_unload, NULL); |
| 758 g_hash_table_destroy(_buddy_stats); |
758 g_hash_table_destroy(_buddy_stats); |
| 759 } |
759 } |
| 760 |
760 |
| 761 /* close database connection */ |
761 /* close database connection */ |
| 762 destroy_database_connection(); |
762 destroy_database_connection(); |
| 763 |
763 |
| 764 return TRUE; |
764 return TRUE; |
| 765 } |
765 } |
| 854 g_signal_connect(G_OBJECT(ui->ret), "destroy", |
854 g_signal_connect(G_OBJECT(ui->ret), "destroy", |
| 855 G_CALLBACK(cap_prefs_ui_destroy_cb), ui); |
855 G_CALLBACK(cap_prefs_ui_destroy_cb), ui); |
| 856 |
856 |
| 857 g_signal_connect(G_OBJECT(ui->msg_difference_input), "value-changed", |
857 g_signal_connect(G_OBJECT(ui->msg_difference_input), "value-changed", |
| 858 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/max_msg_difference"); |
858 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/max_msg_difference"); |
| 859 |
859 |
| 860 g_signal_connect(G_OBJECT(ui->last_seen_input), "value-changed", |
860 g_signal_connect(G_OBJECT(ui->last_seen_input), "value-changed", |
| 861 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/max_seen_difference"); |
861 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/max_seen_difference"); |
| 862 |
862 |
| 863 g_signal_connect(G_OBJECT(ui->threshold_input), "value-changed", |
863 g_signal_connect(G_OBJECT(ui->threshold_input), "value-changed", |
| 864 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/threshold"); |
864 G_CALLBACK(numeric_spinner_prefs_cb), "/plugins/gtk/cap/threshold"); |
| 865 |
865 |
| 866 return ui; |
866 return ui; |
| 867 } |
867 } |
| 868 |
868 |
| 869 static void cap_prefs_ui_destroy_cb(GtkObject *object, gpointer user_data) { |
869 static void cap_prefs_ui_destroy_cb(GtkObject *object, gpointer user_data) { |
| 870 CapPrefsUI *ui = user_data; |
870 CapPrefsUI *ui = user_data; |