summaryrefslogtreecommitdiff
path: root/pidgin/plugins/cap/cap.h
blob: c00e38458447f69570f0e8e2e44a256d42162c4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
 * Contact Availability Prediction plugin for Purple
 *
 * Copyright (C) 2006 Geoffrey Foster.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02111-1301, USA.
 */

#ifndef _CAP_H_
#define _CAP_H_

#include "internal.h"
#include "pidgin.h"

#include "conversation.h"

#include "gtkconv.h"
#include "gtkblist.h"
#include "gtkplugin.h"
#include "gtkutils.h"

#include "blist.h"
#include "notify.h"
#include "version.h"
#include "debug.h"

#include "util.h"

#include <glib.h>
#include <time.h>
#include <sqlite3.h>
#include "cap_statistics.h"

#define CAP_PLUGIN_ID "gtk-g-off_-cap"

/* Variables used throughout lifetime of the plugin */
PurplePlugin *_plugin_pointer;
sqlite3 *_db; /**< The database */

GHashTable *_buddy_stats = NULL;
GHashTable *_my_offline_times = NULL;
gboolean _signals_connected;
gboolean _sqlite_initialized;

/* Prefs UI */
typedef struct _CapPrefsUI CapPrefsUI;

struct _CapPrefsUI { 
	GtkWidget *ret;
	GtkWidget *cap_vbox;
	GtkWidget *table_layout;

	GtkWidget *threshold_label;
	GtkWidget *threshold_input;
	GtkWidget *threshold_minutes_label;

	GtkWidget *msg_difference_label;
	GtkWidget *msg_difference_input;
	GtkWidget *msg_difference_minutes_label;

	GtkWidget *last_seen_label;
	GtkWidget *last_seen_input;
	GtkWidget *last_seen_minutes_label;
};

static void generate_prediction(CapStatistics *statistics);
static double generate_prediction_for(PurpleBuddy *buddy);
static CapStatistics * get_stats_for(PurpleBuddy *buddy);
static void destroy_stats(gpointer data);
static void insert_cap_msg_count_success(const char *buddy_name, const char *account, const char *protocol, int minute);
static void insert_cap_status_count_success(const char *buddy_name, const char *account, const char *protocol, const char *status_id);
static void insert_cap_msg_count_failed(const char *buddy_name, const char *account, const char *protocol, int minute);
static void insert_cap_status_count_failed(const char *buddy_name, const char *account, const char *protocol, const char *status_id);
static void insert_cap_success(CapStatistics *stats);
static void insert_cap_failure(CapStatistics *stats);
static gboolean max_message_difference_cb(gpointer data);
/* Pidgin Signal Handlers */
/* sent-im-msg */
static void sent_im_msg(PurpleAccount *account, const char *receiver, const char *message);
/* received-im-msg */
static void received_im_msg(PurpleAccount *account, char *sender, char *message, PurpleConversation *conv, PurpleMessageFlags flags);
/* buddy-status-changed */
static void buddy_status_changed(PurpleBuddy *buddy, PurpleStatus *old_status, PurpleStatus *status);
/* buddy-signed-on */
static void buddy_signed_on(PurpleBuddy *buddy);
/* buddy-signed-off */
static void buddy_signed_off(PurpleBuddy *buddy);
static void buddy_idle(PurpleBuddy *buddy, gboolean old_idle, gboolean idle);
static void blist_node_extended_menu(PurpleBlistNode *node, GList **menu);
/* drawing-tooltip */
static void drawing_tooltip(PurpleBlistNode *node, GString *text, gboolean full);
/* signed-on */
static void signed_on(PurpleConnection *gc);
/* signed-off */
static void signed_off(PurpleConnection *gc);
static void reset_all_last_message_times(gpointer key, gpointer value, gpointer user_data);
static PurpleStatus * get_status_for(PurpleBuddy *buddy);
static void create_tables();
static gboolean create_database_connection();
static void destroy_database_connection();
static guint word_count(const gchar *string);
static void insert_status_change(CapStatistics *statistics);
static void insert_status_change_from_purple_status(CapStatistics *statistics, PurpleStatus *status);
static void insert_word_count(const char *sender, const char *receiver, guint count);
void display_statistics_action_cb(PurpleBlistNode *node, gpointer data);
static gboolean plugin_load(PurplePlugin *plugin);
static void add_plugin_functionality(PurplePlugin *plugin);
static void cancel_conversation_timeouts(gpointer key, gpointer value, gpointer user_data);
static void remove_plugin_functionality(PurplePlugin *plugin);
static void write_stats_on_unload(gpointer key, gpointer value, gpointer user_data);
static gboolean plugin_unload(PurplePlugin *plugin);
static CapPrefsUI * create_cap_prefs_ui();
static void cap_prefs_ui_destroy_cb(GtkObject *object, gpointer user_data);
static void numeric_spinner_prefs_cb(GtkSpinButton *spinbutton, gpointer user_data);
static GtkWidget * get_config_frame(PurplePlugin *plugin);
static void init_plugin(PurplePlugin *plugin);

#endif