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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
|
/***************************************************************************
* *
* Copyright (C) 2005, 2006 by Kevin Gilbert *
* kev.gilbert@cdu.edu.au *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
***************************************************************************/
#include <ntqbuttongroup.h>
#include <ntqcheckbox.h>
#include <ntqcombobox.h>
#include <ntqlabel.h>
#include <ntqlayout.h>
#include <ntqlineedit.h>
#include <ntqlistbox.h>
#include <ntqpushbutton.h>
#include <ntqradiobutton.h>
#include <ntqstringlist.h>
#include <ntqvalidator.h>
#include <tdeconfig.h>
#include <kdebug.h>
#include <tdeglobal.h>
#include <kiconloader.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include "commonwidget.h"
#include "whatsthis.h"
// constructor
// ===========
CommonWidget::CommonWidget( TQWidget* parent, const char* name )
: TQWidget( parent, name ),
m_hosts( NULL ),
m_portRangeIgnoreChange( false ),
m_portRanges( NULL )
{ createLayout( );
m_portRangeAddButton->setEnabled( false );
m_portRangeDeleteButton->setEnabled( false );
}
// destructor
// ==========
CommonWidget::~CommonWidget( )
{ if( m_hosts != NULL )
delete m_hosts;
if( m_portRanges != NULL )
delete m_portRanges;
}
// buildPortRangesTables
// =====================
bool CommonWidget::buildPortRangesTables( const boolPtr tcpPorts, const boolPtr udpPorts )
{ memset( tcpPorts, 0, 64 * 1024 );
memset( udpPorts, 0, 64 * 1024 );
TQStringList portRanges;
getPortRanges( &portRanges );
for( TQStringList::Iterator it = portRanges.begin( ); it != portRanges.end( ); ++it )
{ TQString portRange = *it;
bool tcp = false;
bool udp = false;
if( portRange[ 0 ].isDigit( ))
{ tcp = true;
udp = true;
}
else
if( portRange[ 0 ].lower( ) == 't' )
{ tcp = true;
portRange = portRange.right( portRange.length( ) - 2 );
}
else
if( portRange[ 0 ].lower( ) == 'u' )
{ udp = true;
portRange = portRange.right( portRange.length( ) - 2 );
}
else
{ KMessageBox::error( this, i18n( TQString( "Internal error - Unknown Port Range protocol '%1'" ).arg( portRange[ 0 ])), i18n( "Internal error" ));
return false;
}
TQStringList ports = TQStringList::split( "-", portRange );
if( ports.count( ) > 2 )
{ KMessageBox::error( this, i18n( "Internal error - Illegal Port Range encountered" ), i18n( "Internal error" ));
return false;
}
ushort portFirst = ports.front( ).toUShort( );
ushort portLast = portFirst;
if( ports.count( ) > 1 )
portLast = ports.back( ).toUShort( );
for( uint port = portFirst; port <= portLast; port++ )
{ if( tcp )
tcpPorts[ port ] = true;
if( udp )
udpPorts[ port ] = true;
}
}
return true;
}
// createLayout
// ============
void CommonWidget::createLayout( )
{ TQGridLayout* gridLayout = new TQGridLayout( this );
TDEIconLoader* iconLoader = TDEGlobal::iconLoader( );
TQIconSet clearRightIconSet = iconLoader->loadIconSet( "locationbar_erase", TDEIcon::Small );
byte row = 1;
m_hostButton = new TQPushButton( clearRightIconSet, NULL, this, "host button" );
m_hostComboBox = new TQComboBox( true, this, "target hosts combobox" );
TQHBoxLayout* hostLayout = new TQHBoxLayout( );
byte col = 0;
hostLayout->insertStretch( col++, 0 );
hostLayout->insertWidget( col++, new TQLabel( i18n( "Target host(s)" ), this, "target hosts label" ), 0 );
hostLayout->insertStretch( col++, 1 );
hostLayout->insertWidget( col++, m_hostButton, 0 );
hostLayout->insertStretch( col++, 1 );
hostLayout->insertWidget( col++, m_hostComboBox, 100 );
hostLayout->insertStretch( col++, 0 );
gridLayout->addMultiCellLayout( hostLayout, row, row, 1, 5 );
TQButtonGroup* resloveGroup = new TQButtonGroup( 3, TQt::Vertical, i18n( "Resolve names" ), this, "resolve names group" );
m_resovleDefaultRadio = new TQRadioButton( i18n( "Default" ), resloveGroup, "default resolve radio" );
m_resovleAlwaysRadio = new TQRadioButton( i18n( "Always (-R)" ), resloveGroup, "always resolve radio" );
m_resovleNeverRadio = new TQRadioButton( i18n( "Never (-n)" ), resloveGroup, "never resolve radio" );
row = 4;
gridLayout->addMultiCellWidget( resloveGroup, row, row + 3, 1, 1 );
byte rowBlock1 = ++row;
m_portRangeAddButton = new TQPushButton( i18n( "Add" ), this, "add port range button" );
m_portRangeDeleteButton = new TQPushButton( i18n( "Delete" ), this, "delete port range button" );
m_portRangeComboBox = new TQComboBox( this, "port range combobox" );
m_portRangeLineEdit = new TQLineEdit( this, "port range line edit" );
m_portRangeListBox = new TQListBox( this, "port range listbox" );
m_portRangesCheckBox = new TQCheckBox( i18n( "Port ranges (-p <port ranges>)" ), this, "port ranges checkbox" );
m_portRangeComboBox->insertItem( i18n( "Both" ), BothProtocol );
m_portRangeComboBox->insertItem( i18n( "TCP" ), TCPProtocol );
m_portRangeComboBox->insertItem( i18n( "UDP" ), UDPProtocol );
m_portRangeLineEdit->setValidator( new TQRegExpValidator( TQRegExp( "^\\d{1,5}-{1}\\d{1,5}$" ), this, "port range regx" ));
row = 3;
gridLayout->addMultiCellWidget( m_portRangesCheckBox, row, row, 3, 5, TQt::AlignCenter );
row++;
m_portRangeButton = new TQPushButton( clearRightIconSet, NULL, this, "host button" );
TQHBoxLayout* portRangeLayout = new TQHBoxLayout( );
col = 0;
portRangeLayout->insertStretch( col++, 0 );
portRangeLayout->insertWidget( col++, new TQLabel( i18n( "New range data: " ), this, "new range data label" ), 0 );
portRangeLayout->insertStretch( col++, 1 );
portRangeLayout->insertWidget( col++, m_portRangeButton, 0 );
portRangeLayout->insertStretch( col++, 1 );
portRangeLayout->insertWidget( col++, m_portRangeLineEdit, 100 );
portRangeLayout->insertStretch( col++, 0 );
gridLayout->addMultiCellLayout( portRangeLayout, row, row, 3, 5 );
gridLayout->addWidget( new TQLabel( i18n( "Protocol" ), this, "protocol label" ), row + 1, 3 );
gridLayout->addWidget( m_portRangeComboBox, row + 2, 3 );
gridLayout->addWidget( m_portRangeAddButton, row + 4, 3 );
gridLayout->addWidget( m_portRangeDeleteButton, row + 5, 3 );
byte rowBlock2 = _max_( row + 5, rowBlock1 );
gridLayout->addMultiCellWidget( m_portRangeListBox, row + 1, rowBlock2, 5, 5 );
gridLayout->setColStretch( 0, 4 );
gridLayout->setColStretch( 2, 2 );
gridLayout->setColStretch( 5, 10 );
gridLayout->setColStretch( 6, 4 );
gridLayout->setRowStretch( 0, 10 );
gridLayout->setRowStretch( 2, 10 );
gridLayout->setRowStretch( rowBlock2 + 1, 10 );
}
// enablePortRangeWidgets
// ======================
void CommonWidget::enablePortRangeWidgets( )
{ bool portRangesState = m_portRangesCheckBox->isChecked( );
m_portRangeAddButton->setEnabled( false );
m_portRangeDeleteButton->setEnabled( false );
m_portRangeButton->setEnabled( portRangesState );
m_portRangeLineEdit->setEnabled( portRangesState );
m_portRangeLineEdit->clear( );
m_portRangeComboBox->setEnabled( portRangesState );
m_portRangeListBox->setEnabled( portRangesState );
if( portRangesState )
emit( disableFastScan( ));
}
// finaliseInitialisation
// ======================
void CommonWidget::finaliseInitialisation( )
{ WhatsThis* whatsThis = new WhatsThis( this );
connect( m_hostButton, SIGNAL( clicked( )), SLOT( slotHostButtonClicked( )));
connect( m_hostComboBox, SIGNAL( activated( int )), SLOT( slotHostActivated( int )));
connect( m_hostComboBox, SIGNAL( textChanged( const TQString& )), SLOT( slotHostTextChanged( const TQString& )));
connect( m_portRangeAddButton, SIGNAL( clicked( )), SLOT( slotPortRangeAddClicked( )));
connect( m_portRangeButton, SIGNAL( clicked( )), SLOT( slotPortRangeButtonClicked( )));
connect( m_portRangeDeleteButton, SIGNAL( clicked( )), SLOT( slotPortRangeDeleteClicked( )));
connect( m_portRangeComboBox, SIGNAL( activated( int )), SLOT( slotPortRangeActivated( int )));
connect( m_portRangeLineEdit, SIGNAL( textChanged( const TQString& )), SLOT( slotPortRangeTextChanged( const TQString& )));
connect( m_portRangeListBox, SIGNAL( doubleClicked( TQListBoxItem* )), SLOT( slotPortRangeDoubleClicked( TQListBoxItem* )));
connect( m_portRangeListBox, SIGNAL( highlighted( int )), SLOT( slotPortRangeHighlighted( )));
connect( m_portRangesCheckBox, SIGNAL( clicked( )), SLOT( slotPortRangesClicked( )));
connect( whatsThis, SIGNAL( clicked( )), SLOT( slotWhatsThisClicked( )));
connect( m_hostButton, SIGNAL( clicked( )), SIGNAL( optionsDirty( )));
connect( m_hostComboBox, SIGNAL( activated ( int )), SIGNAL( optionsDirty( )));
connect( m_hostComboBox, SIGNAL( textChanged( const TQString& )), SIGNAL( optionsDirty( )));
connect( m_portRangeAddButton, SIGNAL( clicked( )), SIGNAL( optionsDirty( )));
connect( m_portRangeButton, SIGNAL( clicked( )), SIGNAL( optionsDirty( )));
connect( m_portRangeComboBox, SIGNAL( activated( int )), SIGNAL( optionsDirty( )));
connect( m_portRangeDeleteButton, SIGNAL( clicked( )), SIGNAL( optionsDirty( )));
connect( m_portRangeLineEdit, SIGNAL( textChanged( const TQString& )), SIGNAL( optionsDirty( )));
connect( m_portRangeListBox, SIGNAL( doubleClicked( TQListBoxItem* )), SIGNAL( optionsDirty( )));
connect( m_portRangeListBox, SIGNAL( highlighted ( int )), SIGNAL( optionsDirty( )));
connect( m_portRangesCheckBox, SIGNAL( clicked( )), SIGNAL( optionsDirty( )));
connect( m_resovleAlwaysRadio, SIGNAL( clicked( )), SIGNAL( optionsDirty( )));
connect( m_resovleDefaultRadio, SIGNAL( clicked( )), SIGNAL( optionsDirty( )));
connect( m_resovleNeverRadio, SIGNAL( clicked( )), SIGNAL( optionsDirty( )));
emit( targetChanged( m_hostComboBox->currentText( )));
}
TQString CommonWidget::getHostName( ) const
{ return m_hostComboBox->currentText( );
}
// getHosts
// ========
void CommonWidget::getHosts( TQStringList* hosts )
{ hosts->clear( );
for( ushort i = 0; i < m_hostComboBox->count( ); i++ )
hosts->append( m_hostComboBox->text( i ));
}
// getOptions
// ==========
bool CommonWidget::getOptions( )
{ TQStringList portRanges;
getPortRanges( &portRanges );
bool portRangesState = m_portRangesCheckBox->isChecked( );
if( portRangesState && portRanges.isEmpty( ))
{ KMessageBox::error( this, i18n( TQString( "Port ranges not specified" )), i18n( "Port ranges error" ));
return false;
}
m_host = m_hostComboBox->currentText( );
m_hostCurrentItem = m_hostComboBox->currentItem( );
m_portRangeCurrentItem = m_portRangeComboBox->currentItem( );
m_portRangesState = portRangesState;
m_resovleAlwaysState = m_resovleAlwaysRadio->isChecked( );
m_resovleDefaultState = m_resovleDefaultRadio->isChecked( );
m_resovleNeverState = m_resovleNeverRadio->isChecked( );
if( m_portRanges != NULL )
delete m_portRanges;
m_portRanges = new TQStringList( portRanges );
getHosts( m_hosts );
disconnect( m_hostComboBox, SIGNAL( activated( int )), this, SLOT( slotHostActivated( int )));
disconnect( m_hostComboBox, SIGNAL( textChanged( const TQString& )), this, SLOT( slotHostTextChanged( const TQString& )));
disconnect( m_hostComboBox, SIGNAL( activated ( int )), this, SIGNAL( optionsDirty( )));
disconnect( m_hostComboBox, SIGNAL( textChanged( const TQString& )), this, SIGNAL( optionsDirty( )));
byte i;
TQStringList::Iterator it;
for( i = 0, it = m_hosts->begin( ); it != m_hosts->end( ); i++, ++it )
if( *it == m_host )
break;
if( it != m_hosts->end( ))
{ m_hostComboBox->removeItem( i );
m_hosts->remove( it );
}
else
while( m_hostComboBox->count( ) > MAX_HOST_HISTORY - 1 )
{ m_hostComboBox->removeItem( MAX_HOST_HISTORY - 1 );
m_hosts->pop_back( );
}
m_hostComboBox->insertItem( m_host, 0 );
m_hostComboBox->setCurrentItem( 0 );
m_hosts->prepend( m_host );
connect( m_hostComboBox, SIGNAL( activated( int )), SLOT( slotHostActivated( int )));
connect( m_hostComboBox, SIGNAL( textChanged( const TQString& )), SLOT( slotHostTextChanged( const TQString& )));
connect( m_hostComboBox, SIGNAL( activated ( int )), SIGNAL( optionsDirty( )));
connect( m_hostComboBox, SIGNAL( textChanged( const TQString& )), SIGNAL( optionsDirty( )));
return true;
}
// getPortRanges
// =============
void CommonWidget::getPortRanges( TQStringList* portRanges )
{ portRanges->clear( );
for( ushort i = 0; i < m_portRangeListBox->count( ); i++ )
portRanges->append( m_portRangeListBox->text( i ));
}
// portRangesOverlapping
// =====================
bool CommonWidget::portRangesOverlapping( const ushort portFirst, const ushort portLast )
{ boolPtr tcpPorts = new bool[ 64 * 1024 ];
boolPtr udpPorts = new bool[ 64 * 1024 ];
if( !buildPortRangesTables( tcpPorts, udpPorts ))
{ delete [] tcpPorts;
delete [] udpPorts;
return false;
}
bool tcp = false;
bool udp = false;
switch( m_portRangeComboBox->currentItem( ))
{ case 0: tcp = udp = true; break;
case 1: tcp = true; break;
case 2: udp = true; break;
default:
kdDebug( ) << i18n( "unknown value in Port Range Protocol combo box" ) << endl;
ASSERT( false );
delete [] tcpPorts;
delete [] udpPorts;
return false;
}
uint port;
TQString protocol;
for( port = portFirst; port <= portLast; port++ )
{ if( tcp && tcpPorts[ port ])
{ protocol = "TCP";
break;
}
if( udp && udpPorts[ port ])
{ protocol = "UDP";
break;
}
}
if( port <= portLast )
{ KMessageBox::sorry( this, i18n( "Overlapping Port Range - %1 port %2" ).arg( protocol ).arg( TQString::number( port )), i18n( "Overlapping Port Range" ));
delete [] tcpPorts;
delete [] udpPorts;
return false;
}
delete [] tcpPorts;
delete [] udpPorts;
return true;
}
// readProfile
// ===========
void CommonWidget::readProfile( TDEConfig* config )
{ m_hostCurrentItem = config->readNumEntry( "hostCurrentItem" );
m_portRangeCurrentItem = config->readNumEntry( "portRangeCurrentItem" );
m_portRangesState = config->readBoolEntry( "portRangesState" );
m_resovleAlwaysState = config->readBoolEntry( "resovleAlwaysState" );
m_resovleDefaultState = config->readBoolEntry( "resovleDefaultState" );
m_resovleNeverState = config->readBoolEntry( "resovleNeverState" );
m_hosts = new TQStringList( config->readListEntry( "hosts" ));
m_portRanges = new TQStringList( config->readListEntry( "portRanges" ));
}
// saveProfile
// ===========
void CommonWidget::saveProfile( TDEConfig* config )
{ config->writeEntry( "hostCurrentItem", m_hostCurrentItem );
config->writeEntry( "hosts", *m_hosts );
config->writeEntry( "portRanges", *m_portRanges );
config->writeEntry( "portRangeCurrentItem", m_portRangeCurrentItem );
config->writeEntry( "portRangesState", m_portRangesState );
config->writeEntry( "resovleAlwaysState", m_resovleAlwaysState );
config->writeEntry( "resovleDefaultState", m_resovleDefaultState );
config->writeEntry( "resovleNeverState", m_resovleNeverState );
}
// setInitialValues
// ================
void CommonWidget::setInitialValues( )
{ m_hostComboBox->clear( );
m_hostComboBox->insertStringList( *m_hosts );
m_portRangeListBox->insertStringList( *m_portRanges );
m_portRangeComboBox->setCurrentItem( m_portRangeCurrentItem );
m_portRangesCheckBox->setChecked( m_portRangesState );
m_resovleAlwaysRadio->setChecked( m_resovleAlwaysState );
m_resovleDefaultRadio->setChecked( m_resovleDefaultState );
m_resovleNeverRadio->setChecked( m_resovleNeverState );
if( m_hostComboBox->count( ))
m_hostComboBox->setCurrentItem( m_hostCurrentItem );
enablePortRangeWidgets( );
}
// slotDisablePortRanges
// =====================
void CommonWidget::slotDisablePortRanges( )
{ m_portRangesCheckBox->setChecked( false );
slotPortRangesClicked( );
}
// slotHostActivated
// =================
void CommonWidget::slotHostActivated( int /* index */)
{ emit( targetChanged( m_hostComboBox->currentText( )));
}
// slotHostButtonClicked
// =====================
void CommonWidget::slotHostButtonClicked( )
{ m_hostComboBox->clearEdit( );
}
// slotHostTextChanged
// ===================
void CommonWidget::slotHostTextChanged( const TQString& text )
{ emit( targetChanged( text ));
}
// slotPortRangeAddClicked
// =======================
void CommonWidget::slotPortRangeAddClicked( )
{ TQString text;
if( !validatePortRange( text ))
return;
switch( m_portRangeComboBox->currentItem( ))
{ case BothProtocol: break;
case TCPProtocol: text = "T:" + text; break;
case UDPProtocol: text = "U:" + text; break;
default:
kdDebug( ) << i18n( "unknown value in Port Range Protocol combo box" ) << endl;
ASSERT( false );
}
m_portRangeAddButton->setEnabled( false );
emit( optionsDirty( ));
m_portRangeLineEdit->clear( );
m_portRangeListBox->insertItem( text );
}
// slotPortRangeDeleteClicked
// ==========================
void CommonWidget::slotPortRangeDeleteClicked( )
{ m_portRangeIgnoreChange = true;
m_portRangeListBox->removeItem( m_portRangeListBox->currentItem( ));
m_portRangeAddButton->setEnabled( true );
m_portRangeDeleteButton->setEnabled( false );
emit( optionsDirty( ));
}
// slotPortRangeActivated
// ======================
void CommonWidget::slotPortRangeActivated( int /* index */)
{ m_portRangeAddButton->setEnabled( true );
}
// slotPortRangeActivated
// ======================
void CommonWidget::slotPortRangeButtonClicked( )
{ m_portRangeAddButton->setEnabled( false );
m_portRangeDeleteButton->setEnabled( false );
m_portRangeLineEdit->clear( );
}
// slotPortRangeDoubleClicked
// ==========================
void CommonWidget::slotPortRangeDoubleClicked( TQListBoxItem* item )
{ if( item == NULL )
return;
TQString text = item->text( );
if( text[ 0 ].isDigit( ))
m_portRangeComboBox->setCurrentItem( BothProtocol );
else
{ switch( text[ 0 ].latin1( ))
{ case 'T': m_portRangeComboBox->setCurrentItem( TCPProtocol ); break;
case 'U': m_portRangeComboBox->setCurrentItem( UDPProtocol ); break;
default:
kdDebug( ) << i18n( "unknown value in Port Range Protocol" ) << endl;
ASSERT( false );
m_portRangeComboBox->setCurrentItem( BothProtocol );
}
text = text.right( text.length( ) - 2 );
}
m_portRangeIgnoreChange = true;
m_portRangeLineEdit->setText( text );
m_portRangeDeleteButton->setEnabled( true );
}
// slotPortRangeHighlighted
// ========================
void CommonWidget::slotPortRangeHighlighted( )
{ if( m_portRangeIgnoreChange )
m_portRangeIgnoreChange = false;
else
{ m_portRangeAddButton->setEnabled( false );
m_portRangeDeleteButton->setEnabled( false );
m_portRangeLineEdit->clear( );
}
}
// slotPortRangesClicked
// =====================
void CommonWidget::slotPortRangesClicked( )
{ enablePortRangeWidgets( );
}
// slotPortRangeTextChanged
// ========================
void CommonWidget::slotPortRangeTextChanged( const TQString& /* text */)
{ if( m_portRangeIgnoreChange )
m_portRangeIgnoreChange = false;
else
m_portRangeAddButton->setEnabled( m_portRangeLineEdit->text( ).length( ));
}
// slotWhatsThisClicked
// ====================
void CommonWidget::slotWhatsThisClicked( )
{ if( m_hostButton->hasMouse( )) emit( displayHelp( "target" ));
else if( m_hostComboBox->hasMouse( )) emit( displayHelp( "target" ));
else if( m_portRangeAddButton->hasMouse( )) emit( displayDocBook( "common_options" ));
else if( m_portRangeButton->hasMouse( )) emit( displayDocBook( "common_options" ));
else if( m_portRangeComboBox->hasMouse( )) emit( displayDocBook( "common_options" ));
else if( m_portRangeDeleteButton->hasMouse( )) emit( displayDocBook( "common_options" ));
else if( m_portRangeLineEdit->hasMouse( )) emit( displayDocBook( "common_options" ));
else if( m_portRangeListBox->hasMouse( )) emit( displayDocBook( "common_options" ));
else if( m_portRangesCheckBox->hasMouse( )) emit( displayHelp( "-p" ));
else if( m_resovleAlwaysRadio->hasMouse( )) emit( displayHelp( "-R" ));
else if( m_resovleDefaultRadio->hasMouse( )) emit( displayDocBook( "common_options" ));
else if( m_resovleNeverRadio->hasMouse( )) emit( displayHelp( "-n" ));
else emit( displayUnknown( ));
}
// validatePortRange
// =================
bool CommonWidget::validatePortRange( TQString& text )
{ uint portFirst;
uint portLast;
if( !validatePortRangeText( text, portFirst, portLast ))
return false;
if( !portRangesOverlapping( portFirst, portLast ))
return false;
return true;
}
// validatePortRangeText
// =====================
bool CommonWidget::validatePortRangeText( TQString& text, uint& portFirst, uint& portLast )
{ text = m_portRangeLineEdit->text( );
TQStringList ports = TQStringList::split( "-", text );
if( ports.count( ) > 2 )
{ KMessageBox::error( this, i18n( "Internal error - you seem to have been allowed to entered an illegal Port Range" ), i18n( "Internal error" ));
return false;
}
portFirst = ports.front( ).toUInt( );
portLast = portFirst;
if( ports.count( ) > 1 )
portLast = ports.back( ).toUInt( );
if( !portFirst || portFirst > 65535 || !portLast || portLast > 65535 || portFirst > portLast )
{ KMessageBox::sorry( this,
i18n( "Ports must be in the range 1 to 65,535 and ranges must be in ascending order" ),
i18n( "Invalid Port Range" ));
return false;
}
return true;
}
|