source: src-qt4/pc-netmanager/src/wificonfig/wifiselectiondialog.cpp @ 1f0939e

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 1f0939e was 1f0939e, checked in by Kris Moore <kris@…>, 21 months ago
  • Initial merge of code from PC-BSD SVN repo for my private (pre-release) hacking
  • Property mode set to 100644
File size: 9.3 KB
Line 
1#include "wifiselectiondialog.h"
2#include "ui_wifiselectiondialog.h"
3#include <qtextstream.h>
4#include <QGroupBox>
5
6void wifiselectiondialog::init(QString device)
7{
8   DeviceName = device;
9   
10   connect( pushScan, SIGNAL( clicked() ), this, SLOT(slotOpenWifiScan()) );
11   connect( pushConnect, SIGNAL( clicked() ), this, SLOT(slotConnect()) );
12   connect( pushCancel, SIGNAL( clicked() ), this, SLOT(slotCancel()) );
13   connect( pushSecurity, SIGNAL( clicked() ), this, SLOT(slotCheckWhichSecurity()) );
14}
15
16
17void wifiselectiondialog::slotOpenWifiScan()
18{
19   dialogWifiscanssid = new wifiscanssid();
20   dialogWifiscanssid->init(DeviceName);
21   connect( dialogWifiscanssid, SIGNAL( saved(QString) ), this, SLOT( slotSSIDChanged(QString) ) );
22   dialogWifiscanssid->exec();
23}
24
25
26void wifiselectiondialog::slotSSIDChanged( QString newSSID )
27{
28       lineSSID->setText(newSSID);
29}
30
31   
32void wifiselectiondialog::slotCancel()
33{
34    close();
35}
36
37void wifiselectiondialog::slotConnect()
38{
39    QString selectedSSID;
40   
41    // Make sure a device was selected
42    if (lineSSID->text().isEmpty())
43    {
44        QMessageBox::warning( this, tr("No SSID!"), tr("Error: You must select a wireless network to connect!\n") );
45        return;
46    }
47
48    if ( (checkBSSID->isChecked() && lineSSID->text().length() != 17) || (checkBSSID->isChecked() && lineSSID->text().count(":") != 5) )
49    {
50        QMessageBox::warning( this, tr("Invalid BSSID!"), tr("Error: The specified BSSID appears invalid. It must be in the format xx:xx:xx:xx:xx:xx\n") );
51        return;
52    }
53
54    // Check that we even have a WEP Key yet
55    if (radioSecurityWEP->isChecked() && WEPKey.isEmpty() ) {
56       QMessageBox::warning( this, tr("Warning"), tr("WEP is selected, but not configured!\nPlease configure your WEP key before saving!") );
57       return;
58    }
59
60    // Check that we even have a WPA-Personal Key yet
61    if (radioSecurityWPAPersonal->isChecked() && WPAPersonalKey.isEmpty() ) {
62       QMessageBox::warning( this, tr("Warning"), tr("WPA-Personal is selected, but not configured!\nPlease configure your WPA key before saving!") );
63       return;
64    }
65
66    // Check all the WPAEnt settings
67    if (radioSecurityWPAEnt->isChecked() ) {
68
69       // Check if the key is setup for WPA EAP-TLS
70       if ( WPAEType == 1 && ( WPAEIdent.isEmpty() || WPAEPrivKeyFile.isEmpty() || WPAEPassword.isEmpty() ))
71       {
72          QMessageBox::warning( this, tr("Warning"), tr("WPA-Enterprise is selected, but not configured!\nPlease configure your WPA settings before saving!") );
73          return;
74       }
75
76       // Check if the key is setup for WPA EAP-TTLS && EAP-PEAP
77       if ( (WPAEType == 2 || WPAEType == 3) && ( WPAEIdent.isEmpty() || WPAEPassword.isEmpty() ) ) 
78       {
79          QMessageBox::warning( this, tr("Warning"), tr("WPA-Enterprise is selected, but not configured!\nPlease configure your WPA settings before saving!") );
80          return;
81       }
82
83    } // End of WPAEnt setting check
84   
85
86    if( ! EditingSSID.isEmpty() )
87    {
88      // We are editing an existing SSID, issue delete command before adding new one
89      emit signalDeleteSSID(EditingSSID);
90    }
91   
92    selectedSSID = lineSSID->text();
93    bool usingBSSID = checkBSSID->isChecked() ;
94   
95    // Emit the new network SSID the user selected
96    if ( radioSecurityDisabled->isChecked() )
97    {
98        emit signalSavedOpen(selectedSSID, usingBSSID); 
99    }
100
101    if ( radioSecurityWEP->isChecked() )
102    {
103        emit signalSavedWEP(selectedSSID, usingBSSID, WEPKey, WEPIndex, WEPHex ); 
104    }
105
106    if ( radioSecurityWPAPersonal->isChecked() )
107    {
108        emit signalSavedWPA(selectedSSID, usingBSSID, WPAPersonalKey ); 
109    }
110   
111    if ( radioSecurityWPAEnt->isChecked() )
112    {
113        emit signalSavedWPAE(selectedSSID, usingBSSID, WPAEType, WPAEIdent, WPAECACert, WPAEClientCert, WPAEPrivKeyFile, WPAEPassword, WPAEKeyMgmt ); 
114    }
115
116    close();
117}
118
119// Overloaded function which lets us set editing variables using WPA-Ent
120void wifiselectiondialog::initEdit(QString selectedSSID, bool usingBSSID, int editWPAEType, QString editWPAEIdent, QString editWPAECACert, QString editWPAEClientCert, QString editWPAEPrivKeyFile, QString editWPAEPassword, int keyMgmt)
121{
122   pushConnect->setText(tr("Save"));
123   EditingSSID=selectedSSID;
124   SSID=selectedSSID;
125   lineSSID->setText(selectedSSID);
126   checkBSSID->setChecked(usingBSSID);
127   radioSecurityWPAEnt->setChecked(true);
128   WPAEType=editWPAEType; 
129   WPAEIdent=editWPAEIdent; 
130   WPAECACert=editWPAECACert; 
131   WPAEClientCert=editWPAEClientCert; 
132   WPAEPrivKeyFile=editWPAEPrivKeyFile; 
133   WPAEPassword=editWPAEPassword; 
134   WPAEKeyMgmt = keyMgmt;
135}
136
137// Overloaded function which lets us set editing variables using WPA-Personal
138void wifiselectiondialog::initEdit(QString selectedSSID, bool usingBSSID, QString editWPAPersonalKey)
139{
140   pushConnect->setText(tr("Save"));
141   EditingSSID=selectedSSID;
142   SSID=selectedSSID;
143   lineSSID->setText(selectedSSID);
144   checkBSSID->setChecked(usingBSSID);
145   radioSecurityWPAPersonal->setChecked(true);
146   WPAPersonalKey=editWPAPersonalKey;
147}
148
149// Overloaded function which lets us set editing variables using WEP
150void wifiselectiondialog::initEdit(QString selectedSSID, bool usingBSSID, QString editWEPKey, int editWEPIndex, bool editWEPHex)
151{
152   pushConnect->setText(tr("Save"));
153   EditingSSID=selectedSSID;
154   SSID=selectedSSID;
155   lineSSID->setText(selectedSSID);
156   checkBSSID->setChecked(usingBSSID);
157   radioSecurityWEP->setChecked(true);
158   WEPKey=editWEPKey;
159   WEPIndex=editWEPIndex;
160   WEPHex=editWEPHex;
161}
162
163// Overloaded function which lets us set what we are editing with no encryption
164void wifiselectiondialog::initEdit(QString selectedSSID, bool usingBSSID)
165{
166   pushConnect->setText(tr("Save"));
167   EditingSSID=selectedSSID;
168   SSID=selectedSSID;
169   lineSSID->setText(selectedSSID);
170   checkBSSID->setChecked(usingBSSID);
171   radioSecurityDisabled->setChecked(true);
172}
173
174void wifiselectiondialog::slotConfigWEP()
175{
176   dialogWEP = new wepConfig();
177   
178   if ( ! WEPKey.isEmpty() )
179   {
180       dialogWEP->setKey(WEPKey, WEPIndex, WEPHex);
181   }
182   
183   connect( dialogWEP, SIGNAL( saved(QString, int, bool) ), this, SLOT( slotWEPChanged(QString, int, bool) ) ); 
184   dialogWEP->exec();
185}
186
187
188void wifiselectiondialog::slotWEPChanged( QString newKey, int newIndex, bool hexkey )
189{
190    WEPKey = newKey;
191    WEPIndex = newIndex;
192    WEPHex = hexkey;
193    // Check the status of the radio buttons
194    slotCheckSecurityRadio();
195   
196}
197
198
199void wifiselectiondialog::slotCheckSecurityRadio()
200{
201    // Check to see which radio button is checked and take appropriate actions
202   
203    if ( radioSecurityDisabled->isChecked() )
204    {
205        pushSecurity->setEnabled(FALSE);
206    } else if ( radioSecurityWEP->isChecked() ) {
207        pushSecurity->setEnabled(TRUE);
208        // Check if the key is setup
209        if ( ! WEPKey.isEmpty() )
210        {
211            radioSecurityWEP->setText( tr("WEP (Configured)") );
212        } else {
213            radioSecurityWEP->setText( tr("WEP") );
214        }
215    } else if ( radioSecurityWPAPersonal->isChecked() ) {
216        pushSecurity->setEnabled(TRUE);
217        // Check if the key is setup
218        if ( ! WPAPersonalKey.isEmpty() )
219        {
220            radioSecurityWPAPersonal->setText( tr("WPA Personal (Configured)") );
221        } else {
222            radioSecurityWPAPersonal->setText( tr("WPA Personal") );
223        }
224       
225    } else if ( radioSecurityWPAEnt->isChecked() ) {
226        pushSecurity->setEnabled(TRUE);
227       
228        // Check if the key is setup
229        if ( ! WPAEIdent.isEmpty() && ! WPAEPassword.isEmpty() ) {
230            radioSecurityWPAEnt->setText(tr("WPA Enterprise (Configured)") );
231        } else {
232            radioSecurityWPAEnt->setText(tr("WPA Enterprise") );
233        }
234
235    }
236
237}
238
239
240void wifiselectiondialog::slotCheckWhichSecurity()
241{
242        if ( radioSecurityDisabled->isChecked() )
243    {
244            return;
245    } else if ( radioSecurityWEP->isChecked() ) {
246        // Run the WEP config dialog
247        slotConfigWEP();
248    } else if ( radioSecurityWPAPersonal->isChecked() ) {
249        slotConfigWPAP();
250    } else if ( radioSecurityWPAEnt->isChecked() ) {
251        slotConfigWPAE();
252    }
253
254}
255
256
257void wifiselectiondialog::slotConfigWPAP()
258{
259    // Bring up the WPA-Personal config dialog
260   
261   dialogWPAP = new dialogWPAPersonal();
262   
263   if ( ! WPAPersonalKey.isEmpty() )
264   {
265       dialogWPAP->setKey(WPAPersonalKey);
266   }
267   
268   connect( dialogWPAP, SIGNAL( saved(QString) ), this, SLOT( slotWPAPChanged(QString) ) ); 
269   dialogWPAP->exec();
270
271}
272
273
274void wifiselectiondialog::slotConfigWPAE()
275{
276   // Bring up the WPA-Enterprise config dialog
277   
278   libWPAE = new dialogWPAE();
279   
280   if ( ! WPAEIdent.isEmpty() )
281   {
282       libWPAE->setVariables(WPAEType, WPAEIdent, WPAECACert, WPAEClientCert, WPAEPrivKeyFile, WPAEPassword, WPAEKeyMgmt);
283   }
284   
285   connect( libWPAE, SIGNAL( saved(int, QString, QString, QString, QString, QString, int) ), this, SLOT( slotWPAEChanged(int, QString, QString, QString, QString, QString, int) ) ); 
286   libWPAE->exec();
287}
288
289
290void wifiselectiondialog::slotWPAPChanged( QString newKey )
291{
292    WPAPersonalKey = newKey;
293    slotCheckSecurityRadio();
294}
295
296
297void wifiselectiondialog::slotWPAEChanged( int type, QString EAPIdent, QString CACert, QString ClientCert, QString PrivKeyFile, QString PrivKeyPass, int keyMgmt )
298{
299  WPAEType = type;
300  WPAEIdent=EAPIdent;
301  WPAECACert=CACert;
302  WPAEClientCert=ClientCert;
303  WPAEPrivKeyFile=PrivKeyFile;
304  WPAEPassword=PrivKeyPass;
305  WPAEKeyMgmt=keyMgmt;
306
307  slotCheckSecurityRadio();
308
309}
310
311void wifiselectiondialog::setWPAOnly(bool set)
312{
313   if ( ! set )
314      return;
315
316   groupBox->setHidden(true);
317   radioSecurityWEP->setHidden(true);
318   radioSecurityWPAPersonal->setHidden(true);
319
320}
Note: See TracBrowser for help on using the repository browser.