1
/**vim: ts=4, wrap, tw=80
3
* --- libkvistatwindow.cpp ---
5
* This is a plugin for KVirc 2.0 Phoenix. It allows you to see
6
* statistics of your IRC sessions - total words said etc.
7
* More features are still to come.
9
* (c) Krzysztof Godlewski <kristoff@poczta.wprost.pl>
12
* This program is FREE software. You can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; either version 2
15
* of the License, or (at your opinion) any later version.
17
* This program is distributed in the HOPE that it will be USEFUL,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
* See the GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program. If not, write to the Free Software Foundation,
24
* Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
#include <qpushbutton.h>
29
#include <qmessagebox.h>
31
#include "libkvistatwindow.h"
32
#include "libkvistatsystraywidget.h"
33
#include "libkvistat.h"
35
#include "kvi_locale.h"
37
extern KviStatController * g_pStatPluginController;
39
KviStatWindow::KviStatWindow() : QTabDialog(0, "KviStatWindow", false )
42
cap.sprintf(__tr("Stats since %s"),
43
g_pStatPluginController->statData().startDate.ptr());
45
labels.setAutoDelete(true);
47
QVBox *vb = new QVBox(this);
49
vb->resize( 290, 270 );
51
setFixedSize( vb->width() + 20, vb->height() + 20 );
55
// Words / letters tab
56
for( ; lab_count < 8; lab_count++ )
58
labels.append(new QLabel(vb));
59
labels.at(lab_count)->setTextFormat(PlainText);
62
addTab(vb, _CHAR_2_QSTRING(__tr("Words/Letters")));
67
m_chansView = new QListView(vb);
69
const char *columns[] = { __tr("Name"), __tr("Joins"), __tr("Words"), __tr("Kicks"), __tr("Bans"), __tr("Topics")};
78
for( uint i = 0; i < sizeof(columns) / sizeof(columns[0]); i++ )
79
m_chansView->addColumn(_CHAR_2_QSTRING(columns[i]));
81
m_chansView->setColumnWidth( Col_Name, 62 );
83
QHBox *hb = new QHBox(vb);
87
QPushButton *b = new QPushButton( _CHAR_2_QSTRING(__tr("Remove channel")), hb );
88
connect(b, SIGNAL(clicked()), SLOT(slotRemoveChan()));
90
b = new QPushButton( _CHAR_2_QSTRING(__tr("Remove all")), hb );
91
connect( b, SIGNAL(clicked()), g_pStatPluginController,
92
SLOT(slotRemoveAllChans()));
94
addTab(vb,_CHAR_2_QSTRING(__tr("Channels")));
101
for( ; lab_count < 14; lab_count++ )
103
labels.append(new QLabel(vb));
104
labels.at(lab_count)->setTextFormat(PlainText);
107
addTab(vb, _CHAR_2_QSTRING(__tr( "Misc")));
109
setDefaultButton( _CHAR_2_QSTRING(__tr( "Reset")));
110
connect( this, SIGNAL(defaultButtonPressed()), g_pStatPluginController,
116
KviStatWindow::~KviStatWindow()
120
void KviStatWindow::updateStats()
122
const KviStatData sd = g_pStatPluginController->statData();
126
/* Ugly... but only this way can I make qt display iso8859-2 (and others) correctly I think.
127
* s.local8Bit() doesn't seem to work... */
130
s = _CHAR_2_QSTRING(__tr("Total Words:\t\t\t"));
131
n.sprintf("%i.", sd.totalWords);
132
labels.at(0)->setText(s+n);
133
s = _CHAR_2_QSTRING(__tr("Total Letters:\t\t\t"));
134
n.sprintf("%i.",sd.totalLetters );
135
labels.at(1)->setText(s+n);
136
s = _CHAR_2_QSTRING(__tr("Channels Words:\t\t\t"));
137
n.sprintf("%i.",sd.chansWords );
138
labels.at(2)->setText(s+n);
139
s = _CHAR_2_QSTRING( __tr("Channels Letters:\t\t"));
140
n.sprintf("%i.", sd.chansLetters );
141
labels.at(3)->setText(s+n);
142
s = _CHAR_2_QSTRING( __tr("Queries Words:\t\t\t"));
143
n.sprintf("%i.", sd.queriesWords );
144
labels.at(4)->setText(s+n);
145
s = _CHAR_2_QSTRING( __tr("Queries Letters:\t\t\t"));
146
n.sprintf("%i.", sd.queriesLetters );
147
labels.at(5)->setText(s+n);
148
s = _CHAR_2_QSTRING( __tr("DCCs Words:\t\t\t"));
149
n.sprintf("%i.", sd.dccsWords );
150
labels.at(6)->setText(s+n);
151
s = _CHAR_2_QSTRING( __tr("DCCs Letters:\t\t\t"));
152
n.sprintf("%i.", sd.dccsLetters );
153
labels.at(7)->setText(s+n);
157
s = _CHAR_2_QSTRING( __tr("Number of IRC sessions:\t\t"));
158
n.sprintf("%i.", sd.onIrc);
159
labels.at(8)->setText(s+n);
160
s = _CHAR_2_QSTRING( __tr("Words Record:\t\t\t"));
161
n.sprintf("%i.", sd.wordsRecord );
162
labels.at(9)->setText(s+n);
163
s = _CHAR_2_QSTRING( __tr("Number of kicks given:\t\t"));
164
n.sprintf("%i.", sd.kicks );
165
labels.at(10)->setText(s+n);
166
s = _CHAR_2_QSTRING( __tr("Number of bans set:\t\t"));
167
n.sprintf("%i.", sd.bans );
168
labels.at(11)->setText(s+n);
169
s = _CHAR_2_QSTRING( __tr("Number of joins to channels:\t"));
170
n.sprintf("%i.", sd.joins );
171
labels.at(12)->setText(s+n);
172
s = _CHAR_2_QSTRING( __tr("Number of topic changes:\t\t"));
173
n.sprintf("%i.", sd.topics );
174
labels.at(13)->setText(s+n);
178
m_chansView->clear();
179
for( const KviStatChan *c = g_pStatPluginController->chanList()->first();
180
c; c = g_pStatPluginController->chanList()->next() )
182
QListViewItem *vi = new QListViewItem( m_chansView );
183
vi->setText(Col_Name, c->name() );
184
vi->setText(Col_Words, s.setNum(c->words()));
185
vi->setText(Col_Joins, s.setNum(c->joins()));
186
vi->setText(Col_Kicks, s.setNum(c->kicks()));
187
vi->setText(Col_Bans, s.setNum(c->bans()));
188
vi->setText(Col_Topics,s.setNum(c->topics()));
189
m_chansView->insertItem(vi);
192
m_chansView->setSorting( Col_Words );
195
void KviStatWindow::slotRemoveChan()
197
if( ! m_chansView->selectedItem() )
200
KviStr cn = m_chansView->selectedItem()->text(Col_Name).latin1();
201
if( QMessageBox::warning( 0,_CHAR_2_QSTRING(__tr("Remove Channel")),
202
_CHAR_2_QSTRING(__tr("Are you sure you want to remove this channel from your statistics ?")),
203
_CHAR_2_QSTRING(__tr("Yes")), _CHAR_2_QSTRING(__tr("No")), 0, 1) == 0 ) // def. button: No( == 1)
205
KviStatChan *chan = g_pStatPluginController->findStatChan(cn.ptr());
206
m_chansView->removeItem( m_chansView->selectedItem() );
207
g_pStatPluginController->removeChan(chan);
211
#include "libkvistatwindow.moc"