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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
/* This file is part of KNemo
Copyright (C) 2004, 2006 Percy Leonhardt <percy@eris23.de>
KNemo is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
KNemo 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <tqtimer.h>
#include <tqlabel.h>
#include <tqstring.h>
#include <tqgroupbox.h>
#include <tqdatetime.h>
#include <tqtabwidget.h>
#include <kdebug.h>
#include <tdeconfig.h>
#include <tdelocale.h>
#include <tdeglobal.h>
#include <kiconloader.h>
#include <kactivelabel.h>
#include <tdeio/global.h>
#include "data.h"
#include "interface.h"
#include "interfacestatistics.h"
#include "interfacestatusdialog.h"
InterfaceStatusDialog::InterfaceStatusDialog( Interface* interface, TQWidget* parent, const char* name )
: InterfaceStatusDlg( parent, name ),
mPosInitialized( false ),
mInterface( interface )
{
setIcon( SmallIcon( "knemo" ) );
setCaption( interface->getName() + " " + i18n( "Interface Status" ) );
updateDialog();
if ( interface->getData().available )
{
enableNetworkGroups( 0 );
}
else
{
disableNetworkGroups( 0 );
}
if ( !interface->getData().wirelessDevice )
{
TQWidget* wirelessTab = tabWidget->page( 2 );
tabWidget->removePage( wirelessTab );
delete wirelessTab;
}
if ( !interface->getSettings().activateStatistics )
{
setStatisticsGroupEnabled( false );
}
// Restore window size and position.
TDEConfig* config = new TDEConfig( "knemorc", false );
if ( config->hasGroup( "Interface_" + mInterface->getName() ) )
{
config->setGroup( "Interface_" + mInterface->getName() );
if ( config->hasKey( "StatusX" ) && config->hasKey( "StatusY" ) )
{
mPos.setX( config->readNumEntry( "StatusX" ) );
mPos.setY( config->readNumEntry( "StatusY" ) );
mPosInitialized = true;
}
if ( config->hasKey( "StatusWidth" ) && config->hasKey( "StatusHeight" ) )
resize( config->readNumEntry( "StatusWidth" ),
config->readNumEntry( "StatusHeight" ) );
}
delete config;
statisticsChanged();
mTimer = new TQTimer();
connect( mTimer, TQ_SIGNAL( timeout() ), this, TQ_SLOT( updateDialog() ) );
mTimer->start( 1000 );
}
InterfaceStatusDialog::~InterfaceStatusDialog()
{
mTimer->stop();
delete mTimer;
// Store window size and position.
TDEConfig* config = new TDEConfig( "knemorc", false );
if ( config->hasGroup( "Interface_" + mInterface->getName() ) )
{
config->setGroup( "Interface_" + mInterface->getName() );
config->writeEntry( "StatusX", x() );
config->writeEntry( "StatusY", y() );
config->writeEntry( "StatusWidth", width() );
config->writeEntry( "StatusHeight", height() );
config->sync();
}
delete config;
}
void InterfaceStatusDialog::hide()
{
mPos = pos();
mPosInitialized = true;
TQDialog::hide();
}
void InterfaceStatusDialog::show()
{
TQDialog::show();
/**
* mPosInitialized should always be true, except when
* starting KNemo for the very first time.
*/
if ( mPosInitialized )
move( mPos );
}
void InterfaceStatusDialog::setStatisticsGroupEnabled( bool enabled )
{
groupBoxStatistics->setEnabled( enabled );
}
void InterfaceStatusDialog::updateDialog()
{
InterfaceData& data = mInterface->getData();
InterfaceSettings& settings = mInterface->getSettings();
// connection tab
textLabelInterface->setText( mInterface->getName() );
textLabelAlias->setText( settings.alias );
if ( data.available )
{
textLabelStatus->setText( i18n( "Connection established." ) );
int upsecs = mInterface->getStartTime().secsTo( TQDateTime::currentDateTime() );
int updays = upsecs / 86400; // don't use TQDateTime::daysTo() because
// we only want complete days
TQString uptime;
if ( updays == 1 )
uptime = "1 day, ";
else if ( updays > 1 )
uptime = TQString( "%1 days, " ).arg( updays );
upsecs -= 86400 * updays; // we only want the seconds of today
int hrs = upsecs / 3600;
int mins = ( upsecs - hrs * 3600 ) / 60;
int secs = upsecs - hrs * 3600 - mins * 60;
TQString time;
time.sprintf( "%02d:%02d:%02d", hrs, mins, secs );
uptime += time;
textLabelUptime->setText( uptime );
}
else if ( data.existing )
{
textLabelStatus->setText( i18n( "Not connected." ) );
textLabelUptime->setText( "00:00:00" );
}
else
{
textLabelStatus->setText( i18n( "Not existing." ) );
textLabelUptime->setText( "00:00:00" );
}
if ( data.available )
{
// ip tab
textLabelIP->setText( data.ipAddress );
textLabelSubnet->setText( data.subnetMask );
if ( mInterface->getType() == Interface::ETHERNET )
{
variableLabel1->setText( i18n( "Broadcast Address:" ) );
variableText1->setText( data.broadcastAddress );
variableLabel2->setText( i18n( "Default Gateway:" ) );
variableText2->setText( data.defaultGateway );
variableLabel3->setText( i18n( "HW-Address:" ) );
variableText3->setText( data.hwAddress );
}
else if ( mInterface->getType() == Interface::PPP )
{
variableLabel1->setText( i18n( "PtP-Address:" ) );
variableText1->setText( data.ptpAddress );
variableLabel2->setText( TQString() );
variableText2->setText( TQString() );
variableLabel3->setText( TQString() );
variableText3->setText( TQString() );
}
else
{
// shouldn't happen
variableLabel1->setText( TQString() );
variableText1->setText( TQString() );
variableLabel2->setText( TQString() );
variableText2->setText( TQString() );
variableLabel3->setText( TQString() );
variableText3->setText( TQString() );
}
// traffic tab
textLabelPacketsSend->setText( TQString::number( data.txPackets ) );
textLabelPacketsReceived->setText( TQString::number( data.rxPackets ) );
textLabelBytesSend->setText( data.txString );
textLabelBytesReceived->setText( data.rxString );
unsigned long bytesPerSecond = data.outgoingBytes / mInterface->getGeneralData().pollInterval;
textLabelSpeedSend->setText( TDEIO::convertSize( bytesPerSecond ) + i18n( "/s" ) );
bytesPerSecond = data.incomingBytes / mInterface->getGeneralData().pollInterval;
textLabelSpeedReceived->setText( TDEIO::convertSize( bytesPerSecond ) + i18n( "/s" ) );
if ( data.wirelessDevice )
{
WirelessData& wdata = mInterface->getWirelessData();
// wireless tab
textLabelESSID->setText( wdata.essid );
textLabelAccessPoint->setText( wdata.accessPoint );
textLabelNickName->setText( wdata.nickName );
textLabelMode->setText( wdata.mode );
textLabelFreqChannel->setText( wdata.frequency + " [" + wdata.channel + "]" );
textLabelBitRate->setText( wdata.bitRate );
textLabelLinkQuality->setText( wdata.linkQuality + "%" );
if ( wdata.encryption == true )
{
textLabelEncryption->setText( i18n( "active" ) );
}
else
{
textLabelEncryption->setText( i18n( "off" ) );
}
}
}
}
void InterfaceStatusDialog::enableNetworkGroups( int )
{
groupBoxIP->setEnabled( true );
groupBoxCurrentConnection->setEnabled( true );
}
void InterfaceStatusDialog::disableNetworkGroups( int )
{
groupBoxIP->setEnabled( false );
groupBoxCurrentConnection->setEnabled( false );
// clear IP group
textLabelIP->setText( TQString() );
textLabelSubnet->setText( TQString() );
variableText1->setText( TQString() );
variableText2->setText( TQString() );
variableText3->setText( TQString() );
// clear current connection group
textLabelPacketsSend->setText( TQString() );
textLabelPacketsReceived->setText( TQString() );
textLabelBytesSend->setText( TQString() );
textLabelBytesReceived->setText( TQString() );
textLabelSpeedSend->setText( TQString() );
textLabelSpeedReceived->setText( TQString() );
// clear wireless tab
if ( mInterface->getData().wirelessDevice )
{
textLabelESSID->setText( TQString() );
textLabelAccessPoint->setText( TQString() );
textLabelNickName->setText( TQString() );
textLabelMode->setText( TQString() );
textLabelFreqChannel->setText( TQString() );
textLabelBitRate->setText( TQString() );
textLabelLinkQuality->setText( TQString() );
textLabelEncryption->setText( TQString() );
}
}
void InterfaceStatusDialog::statisticsChanged()
{
InterfaceStatistics* statistics = mInterface->getStatistics();
if ( statistics == 0 )
{
return;
}
const StatisticEntry* entry = statistics->getCurrentDay();
textLabelTodaySent->setText( TDEIO::convertSize( entry->txBytes ) );
textLabelTodayReceived->setText( TDEIO::convertSize( entry->rxBytes ) );
textLabelTodayTotal->setText( TDEIO::convertSize( entry->txBytes + entry->rxBytes ) );
entry = statistics->getCurrentMonth();
textLabelMonthSent->setText( TDEIO::convertSize( entry->txBytes ) );
textLabelMonthReceived->setText( TDEIO::convertSize( entry->rxBytes ) );
textLabelMonthTotal->setText( TDEIO::convertSize( entry->txBytes + entry->rxBytes ) );
entry = statistics->getCurrentYear();
textLabelYearSent->setText( TDEIO::convertSize( entry->txBytes ) );
textLabelYearReceived->setText( TDEIO::convertSize( entry->rxBytes ) );
textLabelYearTotal->setText( TDEIO::convertSize( entry->txBytes + entry->rxBytes ) );
}
#include "interfacestatusdialog.moc"
|