source: src-qt4/pc-netmanager/src/wificonfig/wifiselectiondialog.cpp @ 0cfe72f

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since 0cfe72f was 0cfe72f, checked in by Kris Moore <kris@…>, 16 months ago

Add all the changes for related using of split pcbsd-utils libs

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