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

mainwindowimp.cpp

Go to the documentation of this file.
00001 
00002 #include "mainwindowimp.h"
00003 #include "addconnectionimp.h"
00004 #include "interfaceinformationimp.h"
00005 #include "interfacesetupimp.h"
00006 #include "interfaces.h"
00007 #include "module.h"
00008 
00009 /* OPIE */
00010 #include <opie2/odebug.h>
00011 #include <opie2/oprocess.h>
00012 #include <opie2/oresource.h>
00013 
00014 #include <qpe/applnk.h>
00015 #include <qpe/qcopenvelope_qws.h>
00016 #include <qpe/qpeapplication.h>
00017 #include <qpe/config.h>
00018 #include <qpe/qlibrary.h>
00019 
00020 /* QT */
00021 #include <qpushbutton.h>
00022 #include <qlistbox.h>
00023 #include <qlineedit.h>
00024 #include <qlistview.h>
00025 #include <qheader.h>
00026 #include <qlabel.h>
00027 #include <qtabwidget.h> // in order to disable the profiles tab
00028 #include <qmessagebox.h>
00029 #include <qtextstream.h>
00030 #include <qregexp.h>
00031 
00032 
00033 #if QT_VERSION < 0x030000
00034 #include <qlist.h>
00035 #else
00036 #include <qptrlist.h>
00037 #endif
00038 #include <qdir.h>
00039 #include <qfile.h>
00040 #include <qtextstream.h>
00041 #include <qregexp.h>
00042 
00043 /* STD */
00044 #include <net/if.h>
00045 #include <sys/ioctl.h>
00046 #include <sys/socket.h>
00047 
00048 #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
00049 #define _PROCNETDEV "/proc/net/dev"
00050 
00051 // is this always right?
00052 #define _HOSTFILE "/etc/hostname"
00053 #define _IRDANAME "/proc/sys/net/irda/devname"
00054 
00055 using namespace Opie::Core;
00056 
00057 MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME)
00058 {
00059     connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
00060     connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
00061     connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
00062     connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
00063 
00064     //remove tab with no function
00065     tabWidget->removePage( tab );
00066 
00067     // Load connections.
00068     // /usr/local/kde/lib/libinterfaces.la
00069     loadModules(QPEApplication::qpeDir() + "plugins/networksettings");
00070     getAllInterfaces();
00071 
00072     Interfaces i;
00073     QStringList list = i.getInterfaceList();
00074     QMap<QString, Interface*>::Iterator it;
00075     for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni )
00076     {
00077         /*
00078          * we skipped it in getAllInterfaces now
00079          * we need to ignore it as well
00080          */
00081         if (m_handledIfaces.contains( *ni) )
00082         {
00083             odebug << "Not up iface handled by module" << oendl;
00084             continue;
00085         }
00086         bool found = false;
00087         for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it )
00088         {
00089             if(it.key() == (*ni))
00090                 found = true;
00091         }
00092         if(!found)
00093         {
00094             if(!(*ni).contains("_"))
00095             {
00096                 Interface *i = new Interface(this, *ni, false);
00097                 i->setAttached(false);
00098                 i->setHardwareName(tr("Disconnected"));
00099                 interfaceNames.insert(i->getInterfaceName(), i);
00100                 updateInterface(i);
00101                 connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*)));
00102             }
00103         }
00104     }
00105 
00106     //getInterfaceList();
00107     connectionList->header()->hide();
00108 
00109     Config cfg("NetworkSetup");
00110     profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
00111     for ( QStringList::Iterator it = profiles.begin();
00112             it != profiles.end(); ++it)
00113         profilesList->insertItem((*it));
00114     currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
00115     advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
00116     scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
00117 
00118     QFile file(scheme);
00119     if ( file.open(IO_ReadOnly) )
00120     {    // file opened successfully
00121         QTextStream stream( &file );        // use a text stream
00122         while ( !stream.eof() )
00123         {        // until end of file...
00124             QString line = stream.readLine();       // line of text excluding '\n'
00125             if(line.contains("SCHEME"))
00126             {
00127                 line = line.mid(7, line.length());
00128                 currentProfileLabel->setText(line);
00129                 break;
00130             }
00131         }
00132         file.close();
00133     }
00134     makeChannel();
00135     initHostname();
00136 }
00137 
00141 MainWindowImp::~MainWindowImp()
00142 {
00143     // Save profiles.
00144     Config cfg("NetworkSetup");
00145     cfg.setGroup("General");
00146     cfg.writeEntry("Profiles", profiles.join(" "));
00147 
00148     // Delete all interfaces that don't have owners.
00149     QMap<Interface*, QListViewItem*>::Iterator iIt;
00150     for( iIt = items.begin(); iIt != items.end(); ++iIt )
00151     {
00152         if(iIt.key()->getModuleOwner() == NULL)
00153             delete iIt.key();
00154     }
00155 
00156     // Delete Modules and Libraries
00157     QMap<Module*, QLibrary*>::Iterator it;
00158     for( it = libraries.begin(); it != libraries.end(); ++it )
00159     {
00160         delete it.key();
00161         // I wonder why I can't delete the libraries
00162         // What fucking shit this is.
00163         //delete it.data();
00164     }
00165 }
00166 
00170 void MainWindowImp::getAllInterfaces()
00171 {
00172     int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
00173     if(sockfd == -1)
00174         return;
00175 
00176     struct ifreq ifr;
00177     QStringList ifaces;
00178     QFile procFile(QString(_PROCNETDEV));
00179     int result;
00180     Interface *i;
00181 
00182     if (! procFile.exists())
00183     {
00184         struct ifreq ifrs[100];
00185         struct ifconf ifc;
00186         ifc.ifc_len = sizeof(ifrs);
00187         ifc.ifc_req = ifrs;
00188         result = ioctl(sockfd, SIOCGIFCONF, &ifc);
00189 
00190         for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++)
00191         {
00192             struct ifreq *pifr = &ifrs[i];
00193             if ( !QString( pifr->ifr_name ).startsWith( "wifi" ) ) ifaces += pifr->ifr_name;
00194             else odebug << "ignoring hostap control interface " << pifr->ifr_name << oendl;
00195         }
00196     }
00197     else
00198     {
00199         procFile.open(IO_ReadOnly);
00200         QString line;
00201         QTextStream procTs(&procFile);
00202         int loc = -1;
00203 
00204         procTs.readLine(); // eat a line
00205         procTs.readLine(); // eat a line
00206         while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null)
00207         {
00208             if((loc = line.find(":")) != -1)
00209             {
00210                 // ignore wifi* (hostap control interfaces)
00211                 if ( !line.left(loc).startsWith( "wifi" ) ) ifaces += line.left(loc);
00212                 else odebug << "ignoring hostap control interface " << line.left(loc) << oendl;
00213             }
00214         }
00215     }
00216 
00217     for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it)
00218     {
00219         int flags = 0;
00220         if ( m_handledIfaces.contains( (*it) ) )
00221         {
00222             odebug << " " << (*it).latin1() << " is handled by a module" << oendl;
00223             continue;
00224         }
00225         //    int family;
00226         i = NULL;
00227 
00228         strcpy(ifr.ifr_name, (*it).latin1());
00229 
00230         struct ifreq ifcopy;
00231         ifcopy = ifr;
00232         result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
00233         flags = ifcopy.ifr_flags;
00234         i = new Interface(this, ifr.ifr_name, false);
00235         i->setAttached(true);
00236         if ((flags & IFF_UP) == IFF_UP)
00237             i->setStatus(true);
00238         else
00239             i->setStatus(false);
00240 
00241         if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
00242             i->setHardwareName("Ethernet");
00243         else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
00244             i->setHardwareName("Point to Point");
00245         else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
00246             i->setHardwareName("Multicast");
00247         else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
00248             i->setHardwareName("Loopback");
00249         else
00250             i->setHardwareName("Unknown");
00251 
00252         owarn << "Adding interface " << ifr.ifr_name << " to interfaceNames\n" << oendl;
00253         interfaceNames.insert(i->getInterfaceName(), i);
00254         updateInterface(i);
00255         connect(i, SIGNAL(updateInterface(Interface*)),
00256                 this, SLOT(updateInterface(Interface*)));
00257     }
00258     // now lets ask the plugins too ;)
00259     QMap<Module*, QLibrary*>::Iterator it;
00260     QList<Interface> ilist;
00261     for( it = libraries.begin(); it != libraries.end(); ++it )
00262     {
00263         if(it.key())
00264         {
00265             ilist = it.key()->getInterfaces();
00266             for( i = ilist.first(); i != 0; i = ilist.next() )
00267             {
00268                 owarn << "Adding interface " << i->getInterfaceName().latin1() << " to interfaceNames\n" << oendl;
00269                 interfaceNames.insert(i->getInterfaceName(), i);
00270                 updateInterface(i);
00271                 connect(i, SIGNAL(updateInterface(Interface*)),
00272                         this, SLOT(updateInterface(Interface*)));
00273             }
00274         }
00275     }
00276 }
00277 
00283 void MainWindowImp::loadModules(const QString &path)
00284 {
00285 #ifdef DEBUG
00286     odebug << "MainWindowImp::loadModules: " << path.latin1() << "" << oendl;
00287 #endif
00288     QDir d(path);
00289     if(!d.exists())
00290         return;
00291 
00292     QString lang = ::getenv("LANG");
00293     // Don't want sym links
00294     d.setFilter( QDir::Files | QDir::NoSymLinks );
00295     const QFileInfoList *list = d.entryInfoList();
00296     QFileInfoListIterator it( *list );
00297     QFileInfo *fi;
00298     while ( (fi=it.current()) )
00299     {
00300         if(fi->fileName().contains(".so"))
00301         {
00302             /* if loaded install translation */
00303             if( loadPlugin(path + "/" + fi->fileName()) != 0l ){
00304                 QTranslator *trans = new QTranslator(qApp);
00305                 QString fn = QPEApplication::qpeDir()+"i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+".qm";
00306                 if( trans->load( fn ) )
00307                     qApp->installTranslator( trans );
00308                 else
00309                     delete trans;
00310             }
00311             odebug << "loaded plugin: >" << QString(path + "/" + fi->fileName()).latin1() << "< " << oendl;
00312         }
00313         ++it;
00314     }
00315 }
00316 
00323 Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString)
00324 {
00325 #ifdef DEBUG
00326     odebug << "MainWindowImp::loadPlugin: " << pluginFileName.latin1() << ": resolving " << resolveString.latin1() << "" << oendl;
00327 #endif
00328     QLibrary *lib = new QLibrary(pluginFileName);
00329     void *functionPointer = lib->resolve(resolveString);
00330     if( !functionPointer )
00331     {
00332 #ifdef DEBUG
00333         odebug << "MainWindowImp::loadPlugin: Warning: " << pluginFileName.latin1() << " is not a plugin" << oendl;
00334 #endif
00335         delete lib;
00336         return 0;
00337     }
00338     // Try to get an object.
00339     Module *object = ((Module* (*)()) functionPointer)();
00340     if(object == 0)
00341     {
00342 #ifdef DEBUG
00343         odebug << "MainWindowImp: Couldn't create object, but did load library!" << oendl;
00344 #endif
00345         delete lib;
00346         return 0;
00347     }
00348 
00349     m_handledIfaces += object->handledInterfaceNames();
00350     // Store for deletion later
00351     libraries.insert(object, lib);
00352     return object;
00353 }
00354 
00359 void MainWindowImp::addClicked()
00360 {
00361     QMap<Module*, QLibrary*>::Iterator it;
00362     QMap<QString, QString> list;
00363     QMap<QString, Module*> newInterfaceOwners;
00364 
00365     for( it = libraries.begin(); it != libraries.end(); ++it )
00366     {
00367         if(it.key())
00368         {
00369             (it.key())->possibleNewInterfaces(list);
00370         }
00371     }
00372     // See if the list has anything that we can add.
00373     if(list.count() == 0)
00374     {
00375         QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok);
00376         return;
00377     }
00378     AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
00379     addNewConnection.addConnections(list);
00380     if( QDialog::Accepted == QPEApplication::execDialog( &addNewConnection ) )
00381     {
00382         QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
00383         if(!item)
00384             return;
00385 
00386         for( it = libraries.begin(); it != libraries.end(); ++it )
00387         {
00388             if(it.key())
00389             {
00390                 Interface *i = (it.key())->addNewInterface(item->text(0));
00391                 if(i)
00392                 {
00393                     odebug << "iface name " << i->getInterfaceName().latin1() << "" << oendl;
00394                     interfaceNames.insert(i->getInterfaceName(), i);
00395                     updateInterface(i);
00396                 }
00397             }
00398         }
00399     }
00400 }
00401 
00406 void MainWindowImp::removeClicked()
00407 {
00408     QListViewItem *item = connectionList->currentItem();
00409     if(!item)
00410     {
00411         QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
00412         return;
00413     }
00414 
00415     Interface *i = interfaceItems[item];
00416     if(i->getModuleOwner() == NULL)
00417     {
00418         QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
00419     }
00420     else
00421     {
00422         if(!i->getModuleOwner()->remove(i))
00423             QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok);
00424         else
00425         {
00426             delete item;
00427             //      QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
00428         }
00429     }
00430 }
00431 
00437 void MainWindowImp::configureClicked()
00438 {
00439     QListViewItem *item = connectionList->currentItem();
00440     if(!item)
00441     {
00442         QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok);
00443         return;
00444     }
00445 
00446     QString currentProfileText = currentProfileLabel->text();
00447     if(currentProfileText.upper() == "ALL");
00448     currentProfileText = "";
00449 
00450     Interface *i = interfaceItems[item];
00451 
00452     if(i->getModuleOwner())
00453     {
00454         QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
00455         if(moduleConfigure != NULL)
00456         {
00457             i->getModuleOwner()->setProfile(currentProfileText);
00458             QPEApplication::showWidget( moduleConfigure );
00459             return;
00460         }
00461     }
00462 
00463     InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose  | Qt::WStyle_ContextHelp );
00464     configure->setProfile(currentProfileText);
00465     QPEApplication::showDialog( configure );
00466 }
00467 
00473 void MainWindowImp::informationClicked()
00474 {
00475     QListViewItem *item = connectionList->currentItem();
00476     if(!item)
00477     {
00478         QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
00479         return;
00480     }
00481 
00482     Interface *i = interfaceItems[item];
00483     //   if(!i->isAttached()){
00484     //     QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
00485     //     return;
00486     //   }
00487 
00488     if(i->getModuleOwner())
00489     {
00490         QWidget *moduleInformation = i->getModuleOwner()->information(i);
00491         if(moduleInformation != NULL)
00492         {
00493             QPEApplication::showWidget( moduleInformation );
00494 #ifdef DEBUG
00495             odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl;
00496 #endif
00497             return;
00498         }
00499     }
00500     InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog  | Qt::WStyle_ContextHelp);
00501     QPEApplication::showWidget( information );
00502 }
00503 
00508 void MainWindowImp::updateInterface(Interface *i)
00509 {
00510     if(!advancedUserMode)
00511     {
00512         if(i->getInterfaceName() == "lo")
00513             return;
00514     }
00515 
00516     QListViewItem *item = NULL;
00517 
00518     // Find the interface, making it if needed.
00519     if(items.find(i) == items.end())
00520     {
00521         item = new QListViewItem(connectionList, "", "", "");
00522         // See if you can't find a module owner for this interface
00523         QMap<Module*, QLibrary*>::Iterator it;
00524         for( it = libraries.begin(); it != libraries.end(); ++it )
00525         {
00526             if(it.key()->isOwner(i))
00527                 i->setModuleOwner(it.key());
00528         }
00529         items.insert(i, item);
00530         interfaceItems.insert(item, i);
00531     }
00532     else
00533         item = items[i];
00534 
00535     // Update the icons and information
00536     item->setPixmap( 0, Opie::Core::OResource::loadPixmap( i->getStatus() ? "up" : "down", Opie::Core::OResource::SmallIcon ) );
00537 
00538     QString typeName = "lan";
00539     if(i->getInterfaceName() == "lo")
00540         typeName = "lo";
00541     if(i->getInterfaceName().contains("irda"))
00542         typeName = "irda";
00543     if(i->getInterfaceName().contains("wlan"))
00544         typeName = "wlan";
00545     if(i->getInterfaceName().contains("usb"))
00546         typeName = "usb";
00547 
00548     if(!i->isAttached())
00549         typeName = "connect_no";
00550     // Actually try to use the Module
00551     if(i->getModuleOwner() != NULL)
00552         typeName = i->getModuleOwner()->getPixmapName(i);
00553 
00554     item->setPixmap( 1, ( Opie::Core::OResource::loadPixmap( "networksettings/" + typeName, Opie::Core::OResource::SmallIcon ) ) );
00555     
00556     item->setText(2, i->getHardwareName());
00557     item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
00558     item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
00559 }
00560 
00561 void MainWindowImp::newProfileChanged(const QString& newText)
00562 {
00563     if(newText.length() > 0)
00564         newProfileButton->setEnabled(true);
00565     else
00566         newProfileButton->setEnabled(false);
00567 }
00568 
00574 void MainWindowImp::addProfile()
00575 {
00576     QString newProfileName = newProfile->text();
00577     if(profiles.grep(newProfileName).count() > 0)
00578     {
00579         QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
00580         return;
00581     }
00582     profiles.append(newProfileName);
00583     profilesList->insertItem(newProfileName);
00584 }
00585 
00590 void MainWindowImp::removeProfile()
00591 {
00592     if(profilesList->count() <= 1)
00593     {
00594         QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok);
00595         return;
00596     }
00597     QString profileToRemove = profilesList->currentText();
00598     if(profileToRemove == "All")
00599     {
00600         QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok);
00601         return;
00602     }
00603     // Can't remove the curent profile
00604     if(profileToRemove == currentProfileLabel->text())
00605     {
00606         QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok);
00607         return;
00608 
00609     }
00610 
00611     if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
00612     {
00613         profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
00614         profilesList->clear();
00615         for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
00616             profilesList->insertItem((*it));
00617 
00618         // Remove any interface settings and mappings.
00619         Interfaces interfaces;
00620         // Go through them one by one
00621         QMap<Interface*, QListViewItem*>::Iterator it;
00622         for( it = items.begin(); it != items.end(); ++it )
00623         {
00624             QString interfaceName = it.key()->getInterfaceName();
00625             odebug << interfaceName.latin1() << oendl;
00626             if(interfaces.setInterface(interfaceName + "_" + profileToRemove))
00627             {
00628                 interfaces.removeInterface();
00629                 if(interfaces.setMapping(interfaceName))
00630                 {
00631                     if(profilesList->count() == 1)
00632                         interfaces.removeMapping();
00633                     else
00634                     {
00635                         interfaces.removeMap("map", interfaceName + "_" + profileToRemove);
00636                     }
00637                 }
00638                 interfaces.write();
00639                 break;
00640             }
00641         }
00642     }
00643 }
00644 
00649 void MainWindowImp::changeProfile()
00650 {
00651     if(profilesList->currentItem() == -1)
00652     {
00653         QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok);
00654         return;
00655     }
00656     QString newProfile = profilesList->text(profilesList->currentItem());
00657     if(newProfile != currentProfileLabel->text())
00658     {
00659         currentProfileLabel->setText(newProfile);
00660         QFile::remove(scheme);
00661         QFile file(scheme);
00662         if ( file.open(IO_ReadWrite) )
00663         {
00664             QTextStream stream( &file );
00665             stream << QString("SCHEME=%1").arg(newProfile);
00666             file.close();
00667         }
00668         // restart all up devices?
00669         if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok)
00670         {
00671             // Go through them one by one
00672             QMap<Interface*, QListViewItem*>::Iterator it;
00673             for( it = items.begin(); it != items.end(); ++it )
00674             {
00675                 if(it.key()->getStatus() == true)
00676                     it.key()->restart();
00677             }
00678         }
00679     }
00680     // TODO change the profile in the modules
00681 }
00682 
00683 
00684 void MainWindowImp::makeChannel()
00685 {
00686     channel = new QCopChannel( "QPE/Application/networksettings", this );
00687     connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
00688              this, SLOT(receive(const QCString&,const QByteArray&)) );
00689 }
00690 
00691 void MainWindowImp::receive(const QCString &msg, const QByteArray &arg)
00692 {
00693     bool found = false;
00694     odebug << "MainWindowImp::receive QCop msg >"+msg+"<" << oendl;
00695     if (msg == "raise")
00696     {
00697         raise();
00698         return;
00699     }
00700 
00701     QString dest = msg.left(msg.find("("));
00702     QCString param = msg.right(msg.length() - msg.find("(") - 1);
00703     param = param.left( param.length() - 1 );
00704     odebug << "dest >" << dest.latin1() << "< param >"+param+"<" << oendl;
00705 
00706     QMap<Module*, QLibrary*>::Iterator it;
00707     for( it = libraries.begin(); it != libraries.end(); ++it )
00708     {
00709         odebug << "plugin >" << it.key()->type().latin1() << "<" << oendl;
00710         if(it.key()->type() == dest)
00711         {
00712             it.key()->receive( param, arg );
00713             found = true;
00714         }
00715     }
00716 
00717 
00718     if (found) QPEApplication::setKeepRunning();
00719     else odebug << "Huh what do ya want" << oendl;
00720 }
00721 
00722 void MainWindowImp::setHostname()
00723 {
00724     static QRegExp filter("[^A-Za-z0-9_\\-\\.]");
00725     if (filter.match(m_Nameinput->text())!=-1) {
00726         odebug << "Wrong hostname" << oendl;
00727         QMessageBox::critical(0, tr("Sorry"), tr("This is a wrong name.<br>Please use A-Z, a-z, _, - or a single dot."));
00728         return;
00729     }
00730 
00731     OProcess h;
00732     _procTemp="";
00733     h << "hostname" << m_Nameinput->text();
00734     connect(&h,SIGNAL(receivedStderr(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
00735     h.start(OProcess::Block,OProcess::Stderr);
00736     odebug << "Got " << _procTemp << " - " << h.exitStatus() << oendl;
00737     if (h.exitStatus()!=0) {
00738         QMessageBox::critical(0, tr("Sorry"), QString(tr("Could not set name.\n%1")).arg(_procTemp.stripWhiteSpace()));
00739         return;
00740     }
00741     _procTemp="";
00742 
00743     QFile f(_HOSTFILE);
00744     if (f.open(IO_Truncate|IO_WriteOnly))
00745     {
00746         QTextStream s(&f);
00747         s << m_Nameinput->text();
00748     } else {
00749         QMessageBox::critical(0, tr("Sorry"), tr("Could not save name."));
00750         return;
00751     }
00752 
00753     f.close();
00754     f.setName(_IRDANAME);
00755     if (f.open(IO_WriteOnly))
00756     {
00757         QTextStream s(&f);
00758         s << m_Nameinput->text();
00759     } else {
00760         QMessageBox::critical(0, tr("Sorry"), tr("Could not set infrared name."));
00761     }
00762 }
00763 
00764 void MainWindowImp::initHostname()
00765 {
00766     OProcess h;
00767     _procTemp="";
00768 
00769     h << "hostname";
00770     connect(&h,SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),this,SLOT(slotHostname(Opie::Core::OProcess*,char*,int)));
00771     h.start(OProcess::Block,OProcess::AllOutput);
00772     odebug << "Got " << _procTemp <<oendl;
00773     m_Nameinput->setText(_procTemp.stripWhiteSpace());
00774     _procTemp="";
00775 }
00776 
00777 void MainWindowImp::slotHostname(Opie::Core::OProcess */*proc*/, char *buffer, int buflen)
00778 {
00779     if (buflen < 1 || buffer==0) return;
00780     char*_t = new char[buflen+1];
00781     ::memset(_t,0,buflen+1);
00782     ::memcpy(_t,buffer,buflen);
00783     _procTemp+=_t;
00784     delete[]_t;
00785 }

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