1 /***************************************************************************
2 networkscanning.cpp - description
4 begin : Sam Apr 24 11:44:20 CEST 2005
5 copyright : (C) 2005 by Stefan Winter
6 email : swinter@kde.org
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
23 #include <QPushButton>
24 #include <QGridLayout>
30 #include <kmessagebox.h>
31 #include <ktempfile.h>
33 #include "networkscanning.h"
34 #include "interface_wireless.h"
35 #include "ui_scanresults.h"
37 NetworkScanning::NetworkScanning ( Interface_wireless
* dev
, QWidget
* parent
):QWidget ( parent
)
44 NetworkScanning::networkScan ( )
46 kDebug ( ) << "Scanning...\n";
47 networks
= device
->get_available_networks ( );
48 // we will get a signal when things are ready to be processed
49 connect ( networks
, SIGNAL ( finishedScanning ( ) ), this, SLOT ( displayResults ( ) ) );
53 NetworkScanning::displayResults ( )
57 if ( networks
->rowCount ( x
) == 0 )
59 KMessageBox::sorry ( 0, i18n ( "The scan is complete, but no networks have been found." ),
60 i18n ( "No Network Available" ) );
64 scanResultsContainer
= new QWidget ( 0 );
65 scanresults_ui
.setupUi ( scanResultsContainer
);
67 scanresults_ui
.resultsTableView
->setModel ( networks
);
68 scanresults_ui
.resultsTableView
->setSelectionBehavior ( QAbstractItemView::SelectRows
);
69 for ( int i
= 0; i
< 4; i
++ )
70 scanresults_ui
.resultsTableView
->resizeColumnToContents ( i
);
72 connect ( scanresults_ui
.resultsTableView
, SIGNAL ( clicked ( const QModelIndex
& ) ), this,
73 SLOT ( changeSwitchButtonState ( const QModelIndex
& ) ) );
75 scanResultsContainer
->show ( );
79 NetworkScanning::changeSwitchButtonState ( const QModelIndex
& index
)
81 scanresults_ui
.switchNetworkButton
->setEnabled ( index
.isValid ( ) );
85 NetworkScanning::switchToNetwork ( )
88 * FIXME: make this work again
90 WEP_KEY encryption = checkWEP();
92 if (encryption == INVALID) {
93 KMessageBox::sorry(0,i18n( "Aborting network switching due to invalid WEP key specification." ), i18n( "Invalid WEP Key" ));
99 KTempFile* tempfile = new KTempFile( QString::null, QString::null, 0700 );
100 QString tempfilename = tempfile->name();
102 cmdline = (QString)"ifconfig %1 down\n";
103 cmdline = cmdline.arg( device->get_interface_name() );
104 write( tempfile->handle(), cmdline.ascii(), strlen( cmdline.ascii() ) );
106 cmdline = (QString)"iwconfig %1 essid %2 mode %3 enc %4\n";
107 cmdline = cmdline.arg( device->get_interface_name() );
108 cmdline = cmdline.arg( KProcess::quote( networks->text( networks->currentRow(), 0 ) ) );
109 cmdline = cmdline.arg( networks->text( networks->currentRow(), 1 ) );
110 if ( encryption != NONE ) {
111 cmdline = cmdline.arg( (encryption == VALID_STRING ? "s:" : "" ) + KProcess::quote( networks->text( networks->currentRow(), 3 ) ) );
113 cmdline = cmdline.arg("off");
115 write( tempfile->handle(), cmdline.ascii(), strlen( cmdline.ascii() ) );
117 cmdline = (QString)"ifconfig %1 up\n";
118 cmdline = cmdline.arg( device->get_interface_name() );
119 write( tempfile->handle(), cmdline.ascii(), strlen( cmdline.ascii() ) );
121 delete tempfile; // autoDeletion off, so the file remains on disk
124 switchProc << "kdesu" << tempfilename;
125 switchProc.start( KProcess::Block );
127 remove(tempfilename.ascii());
132 #include "networkscanning.moc"