summaryrefslogtreecommitdiffstats
path: root/wifi/kcmwifi/ifconfigpage.cpp
blob: ff5d2cf905bc9d3e87100cb7029c9ba74ce6fe63 (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
/* This file is part of the KDE project
   Copyright (C) 2004 Nadeem Hasan <nhasan@kde.org>

   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; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include <kdebug.h>
#include <kdialogbase.h>
#include <klineedit.h>
#include <klocale.h>
#include <kurlrequester.h>

#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <tqradiobutton.h>

#include "configcrypto.h"
#include "configpower.h"
#include "ifconfigpage.h"
#include "wificonfig.h"

#include <unistd.h>
#include <sys/types.h>

IfConfigPage::IfConfigPage( int configNum, TQWidget *parent, const char *name )
    : IfConfigPageBase( parent, name ),
      m_configNum( configNum )
{
  connect( cb_pmEnabled, TQT_SIGNAL( toggled( bool ) ), TQT_SIGNAL( changed() ) );
  connect( cb_useCrypto, TQT_SIGNAL( toggled( bool ) ), TQT_SIGNAL( changed() ) );
  connect( le_networkName, TQT_SIGNAL( textChanged( const TQString & ) ),
                           TQT_SIGNAL( changed() ) );
  connect( cmb_wifiMode, TQT_SIGNAL( activated( int ) ), TQT_SIGNAL( changed() ) );
  connect( cmb_speed, TQT_SIGNAL( activated( int ) ), TQT_SIGNAL( changed() ) );
  connect( cb_runScript, TQT_SIGNAL( toggled( bool ) ), TQT_SIGNAL( changed() ) );
  connect( url_connectScript, TQT_SIGNAL( textChanged( const TQString & ) ),
	   		      TQT_SIGNAL( changed() ) );
  connect( cb_Autodetect, TQT_SIGNAL( toggled( bool ) ), TQT_SIGNAL( changed() ) );
  connect( le_interface, TQT_SIGNAL( textChanged( const TQString & ) ),
		         TQT_SIGNAL( changed() ) );

  connect( pb_setupPower, TQT_SIGNAL( clicked() ), TQT_SLOT( slotSetupPower() ) );
  connect( pb_setupCrypto, TQT_SIGNAL( clicked() ), TQT_SLOT( slotSetupCrypto() ) );

  connect( cb_useCrypto, TQT_SIGNAL( toggled( bool ) ),
           pb_setupCrypto, TQT_SLOT( setEnabled( bool ) ) );
  connect( cb_pmEnabled, TQT_SIGNAL( toggled( bool ) ),
           pb_setupPower, TQT_SLOT( setEnabled( bool ) ) );
  connect( cb_runScript, TQT_SIGNAL( toggled( bool ) ),
           lb_connectScript, TQT_SLOT( setEnabled( bool ) ) );
  connect( cb_runScript, TQT_SIGNAL( toggled( bool ) ),
           lb_connectScript, TQT_SLOT( setEnabled( bool ) ) );
  connect( cb_runScript, TQT_SIGNAL( toggled( bool ) ),
           lb_connectScript, TQT_SLOT( setEnabled( bool ) ) );
  connect( cb_Autodetect, TQT_SIGNAL( toggled( bool ) ),
           le_interface, TQT_SLOT( setDisabled( bool ) ) );

  connect( cb_Autodetect, TQT_SIGNAL( toggled( bool ) ),
           this, TQT_SLOT ( slotResetInterface( bool ) ) );
}

void IfConfigPage::slotResetInterface( bool checked )
{
  if ( checked )
  {
    WifiConfig *config = WifiConfig::instance();
    le_interface->setText( config->autoDetectInterface() );
  }
}

void IfConfigPage::load()
{
  WifiConfig *config = WifiConfig::instance();
  IfConfig ifConfig = config->m_ifConfig[ m_configNum ];

  le_networkName->setText( ifConfig.m_networkName );
  if ( ! ifConfig.m_interface.isEmpty() )
  {
    le_interface->setText( ifConfig.m_interface );
    cb_Autodetect->setChecked( false );
  }
  else
  {
    if ( geteuid()==0 )
      le_interface->setText( config->autoDetectInterface() );
    cb_Autodetect->setChecked( true );
  }

  cmb_wifiMode->setCurrentItem( ifConfig.m_wifiMode );
  cmb_speed->setCurrentItem( ifConfig.m_speed );
  cb_runScript->setChecked( ifConfig.m_runScript );
  url_connectScript->setURL( ifConfig.m_connectScript );
  cb_useCrypto->setChecked( ifConfig.m_useCrypto );
  cb_pmEnabled->setChecked( ifConfig.m_pmEnabled );

  pb_setupCrypto->setEnabled( ifConfig.m_useCrypto );
  pb_setupPower->setEnabled( ifConfig.m_pmEnabled );
  lb_connectScript->setEnabled( ifConfig.m_runScript );
  url_connectScript->setEnabled( ifConfig.m_runScript );
}

void IfConfigPage::save()
{
  WifiConfig *config = WifiConfig::instance();
  IfConfig &ifconfig = config->m_ifConfig[ m_configNum ];

  ifconfig.m_networkName = le_networkName->text();
  ifconfig.m_interface = cb_Autodetect->isChecked()? TQString() :
                                                     le_interface->text();
  ifconfig.m_wifiMode = ( IfConfig::WifiMode ) cmb_wifiMode->currentItem();
  ifconfig.m_speed = ( IfConfig::Speed ) cmb_speed->currentItem();
  ifconfig.m_runScript = cb_runScript->isChecked();
  ifconfig.m_connectScript = url_connectScript->url();
  ifconfig.m_useCrypto = cb_useCrypto->isChecked();
  ifconfig.m_pmEnabled = cb_pmEnabled->isChecked();
}

void IfConfigPage::slotSetupPower()
{
  KDialogBase *dlg = new KDialogBase( this, "ConfigPower", true,
      i18n( "Configure Power Mode" ), KDialogBase::Ok|KDialogBase::Cancel,
      KDialogBase::Ok );
  ConfigPower *power = new ConfigPower( dlg, "ConfigPower" );

  WifiConfig *config = WifiConfig::instance();
  IfConfig &ifconfig = config->m_ifConfig[ m_configNum ];
  power->load( ifconfig );

  dlg->setMainWidget( power );

  if ( dlg->exec() == KDialog::Accepted )
  {
    power->save( ifconfig );
    emit changed();
  }
}

void IfConfigPage::slotSetupCrypto()
{
  KDialogBase *dlg = new KDialogBase( this, "ConfigCrypto", true,
      i18n( "Configure Encryption" ), KDialogBase::Ok|KDialogBase::Cancel,
      KDialogBase::Ok );
  ConfigCrypto *crypto = new ConfigCrypto( dlg, "ConfigCrypto" );

  WifiConfig *config = WifiConfig::instance();
  IfConfig &ifconfig = config->m_ifConfig[ m_configNum ];
  crypto->load( ifconfig );

  dlg->setMainWidget( crypto );

  if ( dlg->exec() == KDialog::Accepted )
  {
    crypto->save( ifconfig );
    emit changed();
  }
}

#include "ifconfigpage.moc"