summaryrefslogtreecommitdiffstats
path: root/knetworkconf/knetworkconf/kadddevicecontainer.cpp
blob: f8bba5d65217ac764d2d65bcd6204dbc84b8196e (plain)
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

/***************************************************************************
                          kadddevicecontainer.cpp  -  description
                             -------------------
    begin                : Wed Jun 15 00:40:33 UTC 2005
    copyright            : (C) 2005 by Juan Luis Baptiste
    email                : juan.baptiste@kdemail.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/
#include "kadddevicecontainer.h"

KAddDeviceContainer::KAddDeviceContainer(TQWidget *tqparent, const char *name)
 : KDialog(tqparent, name)
{
    _modified = false;   
    _advanced = false;
 
     //Setup extension dialog
    setExtension( new KAddDeviceDlgExtension( this ) );
    setOrientation(Qt::Vertical );
   
    //Create dialog that contains the KAddDeviceDlg and KAddDeviceWifiExt (when 
    //configuring a wireless interface) widgets 
    TQPixmap activeEthernetDeviceImg(BarIcon("network_connected_lan_knc"));
    setIcon(activeEthernetDeviceImg);
    //First create a main TQHBoxLayout
    mainLayout = new TQVBoxLayout( this, 10, 2, "mainLayout"); 
    
    //Create the Addvanced settings, Ok and Cancel buttons and add them to a TQHBoxLayout
    buttonsLayout = new TQHBoxLayout( 0, 0, 4, "buttonsLayout"); 
    kpbAdvanced = new KPushButton( this, "kpbAdvanced" );
    buttonsLayout->addWidget( kpbAdvanced );
    buttonsSpacer = new TQSpacerItem( 70, 20, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
    buttonsLayout->addItem( buttonsSpacer );

    kpbApply = new KPushButton( this, "kpbApply" );
    kpbApply->setEnabled( FALSE );
    kpbApply->setDefault( TRUE );
    buttonsLayout->addWidget( kpbApply );

    kpbCancel = new KPushButton( this, "kpbCancel" );
    buttonsLayout->addWidget( kpbCancel );
            
    setCaption( TQString() );
    kpbAdvanced->setText( i18n( "&Advanced Settings" ) );
    TQToolTip::add( kpbAdvanced, i18n( "Toggle between advanced and basic settings" ) );
    TQWhatsThis::add( kpbAdvanced, i18n( "Toggle between advanced and basic settings" ) );
    kpbApply->setText( i18n( "&OK" ) );
    TQToolTip::add( kpbApply, i18n( "Apply changes" ) );
    kpbCancel->setText( i18n( "&Cancel" ) );
    TQToolTip::add( kpbCancel, i18n( "Forget changes" ) );

    //Creat and add the KAddDeviceDlg widget to the main tqlayout
    addDlg = new KAddDeviceDlg(this);
    mainLayout->addWidget(addDlg);
    mainLayout->setResizeMode(TQLayout::Auto);
    
    //Setup connections
    connect((KAddDeviceDlgExtension*)extension(),TQT_SIGNAL(valueChangedSignal(int)),this,TQT_SLOT(toggleApplyButtonSlot(int)));
    connect(addDlg->kleIPAddress,TQT_SIGNAL(textChanged(const TQString&)),this,TQT_SLOT(toggleApplyButtonSlot(const TQString&)));
//    connect(addDlg->kleGateway,TQT_SIGNAL(textChanged(const TQString&)),this,TQT_SLOT(toggleApplyButtonSlot(const TQString&)));
    connect(addDlg->kcbNettqmask,TQT_SIGNAL(activated(int)),this,TQT_SLOT(toggleApplyButtonSlot(int)));
    connect(addDlg->kcbAutoBootProto,TQT_SIGNAL(activated(const TQString&)),this,TQT_SLOT(toggleApplyButtonSlot(const TQString&)));
    connect(addDlg->kcbstartAtBoot,TQT_SIGNAL(stateChanged(int)),this,TQT_SLOT(toggleApplyButtonSlot(int)));
    connect(addDlg->rbBootProtoAuto,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(toggleAdvancedOptionsSlot(bool)));
    connect(addDlg->rbBootProtoAuto,TQT_SIGNAL(toggled(bool)),kpbAdvanced,TQT_SLOT(setDisabled(bool)));
    connect(addDlg->rbBootProtoAuto,TQT_SIGNAL(stateChanged(int)),this,TQT_SLOT(toggleApplyButtonSlot(int)));
   // connect(addDlg->rbBootProtoAuto,TQT_SIGNAL(toggled(bool)),addDlg->kleIPAddress,TQT_SLOT(setDisabled(bool)));
   // connect(addDlg->rbBootProtoAuto,TQT_SIGNAL(toggled(bool)),addDlg->kcbNettqmask,TQT_SLOT(setDisabled(bool)));        
   // connect(addDlg->rbBootProtoManual,TQT_SIGNAL(toggled(bool)),addDlg->kcbAutoBootProto,TQT_SLOT(setDisabled(bool)));
    connect(kpbCancel,TQT_SIGNAL(clicked()),this,TQT_SLOT(cancelSlot()));
    connect(kpbApply,TQT_SIGNAL(clicked()),this,TQT_SLOT(verifyDeviceInfoSlot()));
    connect(kpbAdvanced,TQT_SIGNAL(clicked()),this,TQT_SLOT(advancedOptionsSlot()));
    
}

void KAddDeviceContainer::addWirelessWidget(){
  extDlg = new KAddDeviceWifiExt(this);
  mainLayout->addWidget( extDlg );
  connect(extDlg->kleEssid,TQT_SIGNAL(textChanged(const TQString&)),this,TQT_SLOT(toggleApplyButtonSlot(const TQString&)));
  connect(extDlg->kleWepKey,TQT_SIGNAL(textChanged(const TQString&)),this,TQT_SLOT(toggleApplyButtonSlot(const TQString&)));
  connect(extDlg->qcbKeyType,TQT_SIGNAL(activated(const TQString&)),this,TQT_SLOT(toggleApplyButtonSlot(const TQString&)));
}
void KAddDeviceContainer::toggleApplyButtonSlot( const TQString & )
{
  toggleApplyButtonSlot(0);
}

void KAddDeviceContainer::toggleApplyButtonSlot( int )
{
  _modified = true;
   kpbApply->setEnabled(true);
}

void KAddDeviceContainer::toggleAdvancedOptionsSlot(bool enabled )
{
   KAddDeviceDlgExtension *advancedOptions = (KAddDeviceDlgExtension *)this->extension();

  if (enabled)
    advancedOptions->gbAdvancedDeviceInfo->setEnabled(false);
  else
    advancedOptions->gbAdvancedDeviceInfo->setEnabled(true);
  
  _modified = true;
  kpbApply->setEnabled(true);
}

void KAddDeviceContainer::verifyDeviceInfoSlot()
{
  KAddDeviceDlgExtension *advancedOptions = (KAddDeviceDlgExtension *)this->extension();
  
  if (addDlg->rbBootProtoManual->isChecked())
  {	
    TQString ipAddress = addDlg->kleIPAddress->text();
    TQString nettqmask = addDlg->kcbNettqmask->currentText();
    TQString broadcast = advancedOptions->kleBroadcast->text();
    TQString gateway = advancedOptions->kleGateway->text();
    
    if (!KAddressValidator::isValidIPAddress(ipAddress))
    {
      KMessageBox::error(this,i18n("The format of the specified IP address is not valid."),i18n("Invalid IP Address"));
    }    
    else if (_advanced && !KAddressValidator::isNetmaskValid(nettqmask))
        KMessageBox::error(this,i18n("The format of the specified nettqmask is not valid."),i18n("Invalid IP Address"));
        
    else if (!broadcast.isEmpty() && _advanced && !KAddressValidator::isBroadcastValid(broadcast))
        KMessageBox::error(this,i18n("The format of the specified broadcast is not valid."),i18n("Invalid IP Address"));
    
    else if (!gateway.isEmpty() && _advanced && !KAddressValidator::isValidIPAddress(gateway))
        KMessageBox::error(this,i18n("The format of the specified Gateway is not valid."),i18n("Invalid IP Address"));
        
    else
    {
      _modified = true;
      close();
    }
  }	
  else if (addDlg->rbBootProtoAuto->isChecked())
  {
    _modified = true;
    close();
  }    
}

void KAddDeviceContainer::makeButtonsResizeable()
{
  kpbApply->setAutoResize(true);
  kpbAdvanced->setAutoResize(true);
  kpbCancel->setAutoResize(true);
}

bool KAddDeviceContainer::modified()
{
  return _modified;
}
bool KAddDeviceContainer::advanced()
{
  return _advanced;
}


void KAddDeviceContainer::advancedOptionsSlot()
{
    if (!_advanced)
    {
      kpbAdvanced->setText(i18n("Basic Settings"));
      addDlg->kcbNettqmask->setEditable(true);	
    }
    else
    {
      kpbAdvanced->setText(i18n("Advanced Settings"));
      addDlg->kcbNettqmask->setEditable(false);      
    }
    _advanced = !_advanced;
    showExtension(_advanced );  
}


void KAddDeviceContainer::cancelSlot()
{
 _modified = false;
 close();
}


KAddDeviceContainer::~KAddDeviceContainer()
{
}

void KAddDeviceContainer::addButtons()
{
  widgetHSpacer = new TQSpacerItem( 20, 16, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
  mainLayout->addItem( widgetHSpacer );  
  mainLayout->addLayout( buttonsLayout );
}

#include "kadddevicecontainer.moc"