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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/*
statisticsplugin.h
Copyright (c) 2003-2004 by Marc Cramdal <[email protected]>
*************************************************************************
* *
* 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. *
* *
*************************************************************************
*/
#ifndef STATISTICSPLUGIN_H
#define STATISTICSPLUGIN_H
#include <tqobject.h>
#include <tqmap.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <dcopobject.h>
#include "kopeteplugin.h"
#include "kopetemessage.h"
#include "kopetemessagehandler.h"
#include "kopeteonlinestatus.h"
#include "statisticsdcopiface.h"
class TQString;
class StatisticsDB;
class StatisticsContact;
class StatisticsDCOPIface;
class KopeteView;
class KActionCollection;
/** \section Kopete Statistics Plugin
*
* \subsection intro_sec Introduction
*
* This plugin aims at giving detailed statistics on metacontacts, for instance, how long was
* the metacontact online, how long was it busy etc.
* In the future, it will maybe make prediction on when the contact should be available for chat.
*
* \subsection install_sec How it works ...
* Each Metacontact is bound to a StatisticsContact which has access to the SQLITE database.
* This StatisticsContact stores the last status of the metacontact; the member function onlineStatusChanged is called when the
* metacontact status changed (this is managed in the slot slotOnlineStatusChanged of StatisticsPlugin) and then the DB is
* updated for the contact.
*
* More exactly the DB is updated only if the oldstatus was not Offline
* To have an idea how it works, here is a table :
*
* <table>
* <tr>
* <td>Event</td><td>Changes to database</td><td>oldStatus</td>
* </tr>
* <tr>
* <td>John 17:44 Away <i>(connexion)</i></td><td> - <i>(oldstatus was offline)</i></td><td>oldstatus = away </td>
* </tr>
* <tr>
* <td>John 18:01 Online</td><td>(+) Away 17:44 18:01</td><td>oldstatus = online</td>
* </tr>
* <tr>
* <td>John 18:30 Offline <i>(disconnect)</i></td><td>(+) Online 18:01 18:30</td><td>oldstatus = offline</td>
* </tr>
* <tr>
* <td>John 18:45 Online <i>(connexion)</i></td><td> - <i>(oldstatus was offline)</i></td><td>oldstatus = online</td>
* </tr>
* <tr>
* <td>John 20:30 Offline <i>(disconnect)</i></td><td>(+) Online 18:45 20:30</td><td>oldstatus = offline</td>
* </tr>
* </table>
*
* etc.
*
* \subsection install_sec Some little stats
* This plugin is able to record some other stats, not based on events. Theyre saved in the commonstat table in which we store stats
* like this :
*
* <code>statname, statvalue1, statvalue2</code>
*
* Generally, we store the value, and its ponderation. If an average on one hundred messages says that the contact X takes about
* 3 seconds between two messages, we store "timebetweentwomessages", "3", "100"
*
*
*
* StatisticsPlugin is the main Statistics plugin class.
* Contains mainly slots.
*/
class StatisticsPlugin : public Kopete::Plugin, virtual public StatisticsDCOPIface
{
Q_OBJECT
public:
/// Standard plugin constructors
StatisticsPlugin(TQObject *parent, const char *name, const TQStringList &args);
~StatisticsPlugin();
/// Method to access m_db member
StatisticsDB *db() { return m_db; }
private slots:
// Do the initializations
void slotInitialize();
public slots:
/** \brief This slot is called when the status of a contact changed.
*
* Then it searches for the contact bind to the metacontact who triggered the signal and calls
* the specific StatisticsContact::onlineStatusChanged of the StatisticsContact to update the StatisticsContact status,
* and maybe, update the database.
*/
void slotOnlineStatusChanged(Kopete::MetaContact *contact, Kopete::OnlineStatus::StatusType status );
/**
* Builds and show the StatisticsDialog for a contact
*/
void slotViewStatistics();
/**
*
* Extract the metaContactId from the message, and calls the
* StatisticsContact::newMessageReceived(Kopete::Message& m) function
* for the corresponding contact
*/
void slotAboutToReceive(Kopete::Message& m);
/*
* Managing views
*/
/**
* \brief Only connects the Kopete::ChatSession::closing() signal to our slotViewClosed().
*/
void slotViewCreated(Kopete::ChatSession* session);
/**
* One aim of this slot is to be able to stop recording time between two messages
* for the contact in the chatsession. But, we only
* want to do this if the contact is not in an other chatsession.
*/
void slotViewClosed(Kopete::ChatSession* session);
/**
* Slot called when a new metacontact is added to make some slots connections and to create a new
* StatisticsContact object.
*
* In the constructor, we connect the metacontacts already existing to some slots, but we need to do this
* when new metacontacts are added.
* This function is also called when we loop over the contact list in the constructor.
*/
void slotMetaContactAdded(Kopete::MetaContact *mc);
/**
* Slot called when a metacontact is removed to delete statistic data from db and to remove StatisticsContact object.
*/
void slotMetaContactRemoved(Kopete::MetaContact *mc);
/**
* Slot called when a contact is added to metacontact.
*/
void slotContactAdded(Kopete::Contact *c);
/**
* Slot called when a contact is removed from metacontact.
*/
void slotContactRemoved(Kopete::Contact *c);
/*
* DCOP functions
* See statisticsdcopiface.h for the documentation
*/
void dcopStatisticsDialog(TQString id);
bool dcopWasOnline(TQString id, int timeStamp);
bool dcopWasOnline(TQString id, TQString dt);
bool dcopWasAway(TQString id, int timeStamp);
bool dcopWasAway(TQString id, TQString dt);
bool dcopWasOffline(TQString id, int timeStamp);
bool dcopWasOffline(TQString id, TQString dt);
bool dcopWasStatus(TQString id, TQDateTime dateTime, Kopete::OnlineStatus::StatusType status);
TQString dcopStatus(TQString id, TQString dateTime);
TQString dcopStatus(TQString id, int timeStamp);
TQString dcopMainStatus(TQString id, int timeStamp);
private:
StatisticsDB *m_db;
/** Associate a Kopete::Contact id to a StatisticsContact to retrieve
* the StatisticsContact corresponding to the Kopete::Contact
*/
TQMap<TQString, StatisticsContact*> statisticsContactMap;
/** Associate a Kopete::MetaContact to a StatisticsContact to retrieve
* the StatisticsContact corresponding to the MetaContact
*/
TQMap<Kopete::MetaContact*, StatisticsContact*> statisticsMetaContactMap;
};
#endif
|