Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

wlanmodule.cpp

Go to the documentation of this file.
00001 
00002 #include "wlanmodule.h"
00003 #include "wlanimp2.h"
00004 #include "infoimp.h"
00005 #include "wextensions.h"
00006 #include "interfaceinformationimp.h"
00007 
00008 /* OPIE */
00009 #include <opie2/odebug.h>
00010 #include <qpe/qpeapplication.h>
00011 using namespace Opie::Core;
00012 
00013 /* QT */
00014 #include <qcheckbox.h>
00015 #include <qcombobox.h>
00016 #include <qlabel.h>
00017 #include <qlineedit.h>
00018 #include <qprogressbar.h>
00019 #include <qspinbox.h>
00020 #include <qtabwidget.h>
00021 
00022 
00026 WLANModule::WLANModule()
00027     : Module(),
00028       wlanconfigWiget(0)
00029 {
00030 }
00031 
00035 WLANModule::~WLANModule(){
00036   Interface *i;
00037   for ( i=list.first(); i != 0; i=list.next() )
00038     delete i;
00039 
00040 }
00041 
00045 void WLANModule::setProfile(const QString &newProfile){
00046   profile = newProfile;
00047 }
00048 
00054 QString WLANModule::getPixmapName(Interface* ){
00055   return "wlan";
00056 }
00057 
00063 bool WLANModule::isOwner(Interface *i){
00064   WExtensions we(i->getInterfaceName());
00065   if(!we.doesHaveWirelessExtensions())
00066     return false;
00067 
00068   i->setHardwareName("802.11b");
00069   list.append(i);
00070   return true;
00071 }
00072 
00077 QWidget *WLANModule::configure(Interface *i){
00078   WLANImp *wlanconfig = new WLANImp(0, "WlanConfig", i, true,  ::Qt::WDestructiveClose);
00079   wlanconfig->setProfile(profile);
00080   return wlanconfig;
00081 }
00082 
00087 QWidget *WLANModule::information(Interface *i){
00088   WExtensions we(i->getInterfaceName());
00089   if(!we.doesHaveWirelessExtensions())
00090     return NULL;
00091 
00092   return getInfo( i );
00093 }
00094 
00100 QList<Interface> WLANModule::getInterfaces(){
00101   return list;
00102 }
00103 
00110 Interface *WLANModule::addNewInterface(const QString &){
00111   // We can't add a 802.11 interface, either the hardware will be there
00112   // or it wont.
00113   return NULL;
00114 }
00115 
00120 bool WLANModule::remove(Interface*){
00121   // Can't remove a hardware device, you can stop it though.
00122   return false;
00123 }
00124 
00125 void WLANModule::receive(const QCString &param, const QByteArray &arg)
00126 {
00127     odebug << "WLANModule::receive "+param << oendl; 
00128     QStringList params = QStringList::split(",",param);
00129     int count = params.count();
00130     odebug << "WLANModule got " << count << " params" << oendl; 
00131     if (count < 2){
00132         odebug << "Erorr less than 2 parameter" << oendl; 
00133         odebug << "RETURNING" << oendl; 
00134         return;
00135     }
00136 
00137     QDataStream stream(arg,IO_ReadOnly);
00138     QString interface;
00139     QString action;
00140     int countMsgs = 0;
00141     stream >> interface;
00142     odebug << "got count? >" << interface.latin1() << "<" << oendl; 
00143     if (interface == "count"){
00144         odebug << "got count" << oendl; 
00145         stream >> action;
00146         odebug << "Got count num >" << action.latin1() << "<" << oendl; 
00147         countMsgs = action.toInt();
00148     }
00149 
00150     QDialog *toShow;
00151     //while (! stream.atEnd() ){
00152     for (int i = 0; i < countMsgs; i++){
00153         odebug << "start stream " << i << "/" << countMsgs << "" << oendl; 
00154         if (stream.atEnd()){
00155             odebug << "end of stream" << oendl; 
00156             return;
00157         }
00158         stream >> interface;
00159         odebug << "got iface" << oendl; 
00160         stream >> action;
00161         odebug << "WLANModule got interface " << interface.latin1() << " and acion " << action.latin1() << "" << oendl; 
00162         // find interfaces
00163         Interface *ifa=0;
00164         for ( Interface *i=list.first(); i != 0; i=list.next() ){
00165             if (i->getInterfaceName() == interface){
00166                 odebug << "WLANModule found interface " << interface.latin1() << "" << oendl; 
00167                 ifa = i;
00168             }
00169         }
00170 
00171         if (ifa == 0){
00172             odebug << "WLANModule Did not find " << interface.latin1() << "" << oendl; 
00173             odebug << "skipping" << oendl; 
00174             count = 0;
00175         }
00176 
00177         if (count == 2){
00178             // those should call the interface directly
00179             QWidget *info = getInfo( ifa );
00180             QPEApplication::showWidget( info );
00181 
00182             if ( action.contains("start" ) ){
00183                 ifa->start();
00184             } else if ( action.contains("restart" ) ){
00185                 ifa->restart();
00186             } else if ( action.contains("stop" ) ){
00187                 ifa->stop();
00188             }else if ( action.contains("refresh" ) ){
00189                 ifa->refresh();
00190             }
00191         }else if (count == 3){
00192             QString value;
00193             if (!wlanconfigWiget){
00194                 //FIXME: what if it got closed meanwhile?
00195                 wlanconfigWiget = (WLANImp*) configure(ifa);
00196                 toShow = (QDialog*) wlanconfigWiget;
00197             }
00198             QPEApplication::showWidget( wlanconfigWiget );
00199             stream >> value;
00200             odebug << "WLANModule (build 4) is setting " << action.latin1() << " of " << interface.latin1() << " to " << value.latin1() << "" << oendl; 
00201             if (value.isEmpty()){
00202                 odebug << "value is empty!!!\nreturning" << oendl; 
00203                 return;
00204             }
00205             if ( action.contains("ESSID") ){
00206                 QComboBox *combo = wlanconfigWiget->essid;
00207                 bool found = false;
00208                 for ( int i = 0; i < combo->count(); i++)
00209                     if ( combo->text( i ) == value ){
00210                         combo->setCurrentItem( i );
00211                         found = true;
00212                 }
00213                 if (!found) combo->insertItem( value, 0 );
00214             }else if ( action.contains("Mode") ){
00215                 QComboBox *combo = wlanconfigWiget->mode;
00216                 for ( int i = 0; i < combo->count(); i++)
00217                     if ( combo->text( i ) == value ){
00218                     combo->setCurrentItem( i );
00219                     }
00220 
00221             }else if (action.contains("Channel")){
00222                 bool ok;
00223                 odebug << "converting channel" << oendl; 
00224                 int chan = value.toInt( &ok );
00225                 if (ok){
00226                     odebug << "ok setting channel" << oendl; 
00227                     wlanconfigWiget->specifyChan->setChecked( true );
00228                     wlanconfigWiget->networkChannel->setValue( chan );
00229                 }
00230             }else if (action.contains("MacAddr")){
00231                 wlanconfigWiget->specifyAp->setChecked( true );
00232                 wlanconfigWiget->macEdit->setText( value );
00233             }else
00234                 odebug << "wlan plugin has no clue" << oendl; 
00235         }
00236         odebug << "next stream" << oendl; 
00237     }// while stream
00238     odebug << "end of stream" << oendl; 
00239     if (toShow) toShow->exec();
00240     odebug << "returning" << oendl; 
00241 }
00242 
00243 QWidget *WLANModule::getInfo( Interface *i)
00244 {
00245     odebug << "WLANModule::getInfo start" << oendl; 
00246     WlanInfoImp *info = new WlanInfoImp(0, i->getInterfaceName(), ::Qt::WDestructiveClose);
00247     InterfaceInformationImp *information = new InterfaceInformationImp(info->tabWidget, "InterfaceSetupImp", i);
00248     info->tabWidget->insertTab(information, "TCP/IP", 0);
00249     info->tabWidget->setCurrentPage( 0 );
00250     info->tabWidget->showPage( information );
00251     if (info->tabWidget->currentPage() == information ) odebug << "infotab OK" << oendl; 
00252     else odebug << "infotab NOT OK" << oendl; 
00253     odebug << "current idx " << info->tabWidget->currentPageIndex() << "" << oendl; 
00254     odebug << "WLANModule::getInfo return" << oendl; 
00255     return info;
00256 }
00257 

Generated on Sat Nov 5 16:17:52 2005 for OPIE by  doxygen 1.4.2