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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
/*
* kcmsambastatistics.cpp
*
* Copyright (c) 2000 Alexander Neundorf <alexander.neundorf@rz.tu-ilmenau.de>
*
* Requires the Qt widget libraries, available at no cost at
* http://www.troll.no/
*
* 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 02110-1301, USA.
*/
#include "kcmsambastatistics.h"
#include "kcmsambastatistics.moc"
#include <qlayout.h>
#include <qlistview.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qpushbutton.h>
#include <qregexp.h>
#include <kglobal.h>
#include <klocale.h>
#include <kdebug.h>
#include <kdialog.h>
StatisticsView::StatisticsView(QWidget *parent,KConfig *config, const char *name)
:QWidget (parent, name)
,configFile(config)
,dataList(0)
,connectionsCount(0)
,filesCount(0)
,calcCount(0)
{
viewStatistics = new QListView( this );
connectionsL = new QLabel( i18n( "Connections: 0" ), this );
filesL = new QLabel( i18n( "File accesses: 0" ), this );
eventCb = new QComboBox( false, this );
eventL = new QLabel( eventCb, i18n( "Event: " ), this );
serviceLe = new QLineEdit( this );
serviceL = new QLabel( serviceLe, i18n( "Service/File:" ), this );
hostLe = new QLineEdit( this );
hostL = new QLabel( hostLe, i18n( "Host/User:" ), this );
calcButton = new QPushButton( i18n( "&Search" ), this );
clearButton = new QPushButton( i18n( "Clear Results" ), this );
expandedInfoCb = new QCheckBox( i18n( "Show expanded service info" ), this );
expandedUserCb = new QCheckBox( i18n( "Show expanded host info" ), this );
viewStatistics->setAllColumnsShowFocus(TRUE);
viewStatistics->setFocusPolicy(QWidget::ClickFocus);
viewStatistics->setShowSortIndicator(true);
viewStatistics->addColumn(i18n("Nr"),30);
viewStatistics->addColumn(i18n("Event"),130);
viewStatistics->addColumn(i18n("Service/File"),200);
viewStatistics->addColumn(i18n("Host/User"),90);
viewStatistics->addColumn(i18n("Hits"),50);
//viewStatistics->addColumn(i18n("Percentage"),100);
eventCb->insertItem(i18n("Connection"));
eventCb->insertItem(i18n("File Access"));
expandedInfoCb->setChecked(FALSE);
expandedUserCb->setChecked(FALSE);
clearStatistics();
serviceLe->setText("*");
hostLe->setText("*");
viewStatistics->setMinimumSize(375,200);
connectionsL->setMinimumSize(connectionsL->sizeHint());
filesL->setMinimumSize(filesL->sizeHint());
eventL->setMinimumSize(eventL->sizeHint());
eventCb->setMinimumSize(eventCb->sizeHint());
hostL->setMinimumSize(hostL->sizeHint());
hostLe->setMinimumSize(120,hostLe->sizeHint().height());
serviceL->setMinimumSize(serviceL->sizeHint());
serviceLe->setMinimumSize(120,serviceLe->sizeHint().height());
calcButton->setMinimumSize(calcButton->sizeHint());
clearButton->setMinimumSize(clearButton->sizeHint());
expandedInfoCb->setMinimumSize(expandedInfoCb->sizeHint());
expandedUserCb->setMinimumSize(expandedUserCb->sizeHint());
QVBoxLayout *topLayout=new QVBoxLayout(this, KDialog::marginHint(),
KDialog::spacingHint());
topLayout->addWidget(viewStatistics,1);
QGridLayout *subLayout=new QGridLayout(topLayout,4,3);
subLayout->setColStretch(1,1);
subLayout->setColStretch(2,1);
QHBoxLayout *twoButtonsLayout=new QHBoxLayout;
twoButtonsLayout->addWidget(calcButton,1);
twoButtonsLayout->addWidget(clearButton,1);
subLayout->addWidget(connectionsL,0,0);
subLayout->addWidget(filesL,0,1);
subLayout->addWidget(eventL,1,0);
subLayout->addWidget(serviceL,1,1);
subLayout->addWidget(hostL,1,2);
subLayout->addWidget(eventCb,2,0);
subLayout->addWidget(serviceLe,2,1);
subLayout->addWidget(hostLe,2,2);
subLayout->addLayout(twoButtonsLayout,3,0);
subLayout->addWidget(expandedInfoCb,3,1);
subLayout->addWidget(expandedUserCb,3,2);
connect(clearButton,SIGNAL(clicked()),this,SLOT(clearStatistics()));
connect(calcButton,SIGNAL(clicked()),this,SLOT(calculate()));
setListInfo(0,0,0);
}
void StatisticsView::setListInfo(QListView *list, int nrOfFiles, int nrOfConnections)
{
dataList=list;
filesCount=nrOfFiles;
connectionsCount=nrOfConnections;
connectionsL->setText(i18n("Connections: %1").arg(KGlobal::locale()->formatNumber(connectionsCount, 0)));
filesL->setText(i18n("File accesses: %1").arg(KGlobal::locale()->formatNumber(filesCount, 0)));
clearStatistics();
}
void StatisticsView::calculate()
{
if (dataList==0) return;
QApplication::setOverrideCursor(waitCursor);
int connCount(0);
if (eventCb->currentText()==i18n("Connection"))
connCount=1;
//something has to be counted exactly
if ((expandedInfoCb->isChecked()) || (expandedUserCb->isChecked()))
{
SambaLog sLog;
QRegExp rService(serviceLe->text(),FALSE,TRUE);
QRegExp rHost(hostLe->text(),FALSE,TRUE);
QString item2, item3;
QListViewItem* item=dataList->firstChild();
while (item!=0)
{
if (connCount)
{
if ((QString(item->text(1)).contains(i18n("CONNECTION OPENED")))
&& (QString(item->text(2)).contains(rService)) && (QString(item->text(3)).contains(rHost)))
{
if (expandedInfoCb->isChecked()) item2=item->text(2);
else item2=serviceLe->text();
if (expandedUserCb->isChecked()) item3=item->text(3);
else item3=hostLe->text();
sLog.addItem(item2,item3);
//count++;
};
}
else
{
if ((QString(item->text(1)).contains(i18n("FILE OPENED")))
&& (QString(item->text(2)).contains(rService)) && (QString(item->text(3)).contains(rHost)))
{
if (expandedInfoCb->isChecked()) item2=item->text(2);
else item2=serviceLe->text();
if (expandedUserCb->isChecked()) item3=item->text(3);
else item3=hostLe->text();
sLog.addItem(item2,item3);
};
};
item=item->nextSibling();
};
for (LogItem* tmpItem=sLog.items.first();tmpItem!=0;tmpItem=sLog.items.next())
{
for (SmallLogItem *tmpStr=tmpItem->accessed.first();tmpStr!=0;tmpStr=tmpItem->accessed.next())
{
calcCount++;
QString number("");
number.sprintf("%6d",calcCount);
QString hits("");
hits.sprintf("%7d",tmpStr->count);
new QListViewItem(viewStatistics,number,eventCb->currentText(),tmpItem->name,tmpStr->name,hits);
};
};
}
//no expanded info needed
else
{
calcCount++;
int count(0);
QRegExp rService(serviceLe->text(),FALSE,TRUE);
QRegExp rHost(hostLe->text(),FALSE,TRUE);
QListViewItem* item=dataList->firstChild();
while (item!=0)
{
if (connCount)
{
if ((QString(item->text(1)).contains(i18n("CONNECTION OPENED")))
&& (QString(item->text(2)).contains(rService)) && (QString(item->text(3)).contains(rHost)))
count++;
}
else
{
if ((QString(item->text(1)).contains(i18n("FILE OPENED")))
&& (QString(item->text(2)).contains(rService)) && (QString(item->text(3)).contains(rHost)))
count++;
};
item=item->nextSibling();
};
QString number("");
number.sprintf("%6d",calcCount);
QString hits("");
hits.sprintf("%7d",count);
new QListViewItem(viewStatistics,number,eventCb->currentText(),serviceLe->text(),hostLe->text(),hits);
};
QApplication::restoreOverrideCursor();
}
void StatisticsView::clearStatistics()
{
viewStatistics->clear();
calcCount=0;
}
void SambaLog::printItems()
{
kdDebug() << "****** printing items: ******" << endl;
for (LogItem* tmpItem=items.first();tmpItem!=0;tmpItem=items.next())
{
kdDebug() << "SERVICE: " << tmpItem->name << endl;
for (SmallLogItem* tmpLog=tmpItem->accessed.first();tmpLog!=0;tmpLog=tmpItem->accessed.next())
kdDebug() << " accessed by: " << tmpLog->name << " " << tmpLog->count << endl;
};
kdDebug() << "------ end of printing ------" << endl << endl;
}
LogItem* SambaLog::itemInList(QString name)
{
LogItem* tmpItem(items.first());
LogItem* foundItem(0);
while ((tmpItem!=0) && (foundItem==0))
{
if (tmpItem->name==name) foundItem=tmpItem;
tmpItem=items.next();
};
return foundItem;
}
void SambaLog::addItem(QString share, QString user)
{
//cout<<" adding connection: -"<<share<<"- -"<<user<<"-"<<endl;
LogItem* tmp(itemInList(share));
if (tmp!=0)
{
tmp->count++;
tmp->addItem(user);
}
else
{
items.append(new LogItem(share,user));
};
}
SmallLogItem* LogItem::itemInList(QString name)
{
SmallLogItem* tmpItem(accessed.first());
SmallLogItem* foundItem(0);
while ((tmpItem!=0) && (foundItem==0))
{
if (tmpItem->name==name) foundItem=tmpItem;
tmpItem=accessed.next();
};
return foundItem;
}
void LogItem::addItem (QString host)
{
SmallLogItem* tmp(itemInList(host));
if (tmp!=0)
tmp->count++;
else
accessed.append(new SmallLogItem(host));
}
|