~ubuntu-branches/ubuntu/hoary/kvirc/hoary

« back to all changes in this revision

Viewing changes to src/plugins/stat/libkvistatwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Robin Verduijn
  • Date: 2004-12-14 15:32:19 UTC
  • mfrom: (0.2.1 upstream) (1.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20041214153219-fdink3gyp2s20b6g
Tags: 2:2.1.3.1-2
* Change Recommends on xmms to a Suggests.
* Rebuild against KDE 3.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**vim: ts=4, wrap, tw=80
2
 
  *
3
 
  *             --- libkvistatwindow.cpp ---
4
 
  *
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.
8
 
  *
9
 
  * (c) Krzysztof Godlewski <kristoff@poczta.wprost.pl>
10
 
  *
11
 
  * 
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.
16
 
  *
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.
21
 
 
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.
25
 
  **/
26
 
 
27
 
 
28
 
#include <qpushbutton.h>
29
 
#include <qmessagebox.h>
30
 
 
31
 
#include "libkvistatwindow.h"
32
 
#include "libkvistatsystraywidget.h"
33
 
#include "libkvistat.h"
34
 
 
35
 
#include "kvi_locale.h"
36
 
 
37
 
extern KviStatController * g_pStatPluginController;
38
 
 
39
 
KviStatWindow::KviStatWindow() : QTabDialog(0, "KviStatWindow", false )
40
 
{
41
 
        QString cap;
42
 
        cap.sprintf(__tr("Stats since %s"),
43
 
                g_pStatPluginController->statData().startDate.ptr());
44
 
        setCaption(cap);
45
 
        labels.setAutoDelete(true);
46
 
 
47
 
        QVBox *vb = new QVBox(this);
48
 
        vb->setMargin(5);
49
 
        vb->resize( 290, 270 );
50
 
 
51
 
        setFixedSize( vb->width() + 20, vb->height() + 20 );
52
 
 
53
 
        int lab_count = 0;
54
 
//
55
 
// Words / letters tab
56
 
        for( ; lab_count < 8; lab_count++ )
57
 
        {
58
 
                labels.append(new QLabel(vb));
59
 
                labels.at(lab_count)->setTextFormat(PlainText);
60
 
        }
61
 
 
62
 
        addTab(vb, _CHAR_2_QSTRING(__tr("Words/Letters")));
63
 
//
64
 
// Chanlist
65
 
        vb = new QVBox(this);
66
 
        vb->setMargin(5);
67
 
        m_chansView = new QListView(vb);
68
 
 
69
 
        const char *columns[] = { __tr("Name"), __tr("Joins"), __tr("Words"), __tr("Kicks"), __tr("Bans"), __tr("Topics")};
70
 
 
71
 
#define Col_Name                0
72
 
#define Col_Joins               1
73
 
#define Col_Words               2
74
 
#define Col_Kicks               3
75
 
#define Col_Bans                4
76
 
#define Col_Topics              5
77
 
 
78
 
        for( uint i = 0; i < sizeof(columns) / sizeof(columns[0]); i++ )
79
 
                m_chansView->addColumn(_CHAR_2_QSTRING(columns[i]));
80
 
 
81
 
        m_chansView->setColumnWidth( Col_Name, 62 );
82
 
 
83
 
        QHBox *hb = new QHBox(vb);
84
 
        hb->setMargin(5);
85
 
        hb->setSpacing(10);
86
 
 
87
 
        QPushButton *b = new QPushButton( _CHAR_2_QSTRING(__tr("Remove channel")), hb );
88
 
        connect(b, SIGNAL(clicked()), SLOT(slotRemoveChan()));
89
 
 
90
 
        b = new QPushButton( _CHAR_2_QSTRING(__tr("Remove all")), hb );
91
 
        connect( b, SIGNAL(clicked()), g_pStatPluginController,
92
 
                SLOT(slotRemoveAllChans()));
93
 
 
94
 
        addTab(vb,_CHAR_2_QSTRING(__tr("Channels")));
95
 
 
96
 
//
97
 
// Misc
98
 
        vb = new QVBox(this);
99
 
        vb->setMargin(5);
100
 
 
101
 
        for( ; lab_count < 14; lab_count++ )
102
 
        {
103
 
                labels.append(new QLabel(vb));
104
 
                labels.at(lab_count)->setTextFormat(PlainText);
105
 
        }
106
 
 
107
 
        addTab(vb, _CHAR_2_QSTRING(__tr( "Misc")));
108
 
        
109
 
        setDefaultButton( _CHAR_2_QSTRING(__tr( "Reset")));
110
 
        connect( this, SIGNAL(defaultButtonPressed()), g_pStatPluginController,
111
 
                SLOT(slotReset()));
112
 
 
113
 
        updateStats();
114
 
}
115
 
 
116
 
KviStatWindow::~KviStatWindow()
117
 
{
118
 
}
119
 
 
120
 
void KviStatWindow::updateStats()
121
 
{
122
 
        const KviStatData sd = g_pStatPluginController->statData();
123
 
 
124
 
//
125
 
// Words/Letters
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... */
128
 
        QString s;
129
 
        QString n;
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);
154
 
 
155
 
//
156
 
// Misc
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);
175
 
 
176
 
//
177
 
// Channels
178
 
        m_chansView->clear();
179
 
        for( const KviStatChan *c = g_pStatPluginController->chanList()->first();
180
 
                c; c = g_pStatPluginController->chanList()->next() )
181
 
        {
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);
190
 
        }
191
 
 
192
 
        m_chansView->setSorting( Col_Words );
193
 
}
194
 
 
195
 
void KviStatWindow::slotRemoveChan()
196
 
{
197
 
        if( ! m_chansView->selectedItem() )
198
 
                return;
199
 
 
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)
204
 
        {
205
 
                KviStatChan *chan = g_pStatPluginController->findStatChan(cn.ptr());
206
 
                m_chansView->removeItem( m_chansView->selectedItem() );
207
 
                g_pStatPluginController->removeChan(chan);
208
 
        }
209
 
}
210
 
 
211
 
#include "libkvistatwindow.moc"