-rw-r--r-- | noncore/settings/networksettings/mainwindow/mainwindowimp.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp index 8feb7a5..f83e370 100644 --- a/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindow/mainwindowimp.cpp @@ -1,106 +1,107 @@ #include "mainwindowimp.h" #include "addconnectionimp.h" #include "interfaceinformationimp.h" #include "interfacesetupimp.h" #include "interfaces.h" #include "module.h" /* OPIE */ #include <opie2/odebug.h> +#include <qpe/applnk.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/qlibrary.h> #include <qpe/resource.h> /* QT */ #include <qpushbutton.h> #include <qlistbox.h> #include <qlineedit.h> #include <qlistview.h> #include <qheader.h> #include <qlabel.h> #include <qtabwidget.h> // in order to disable the profiles tab #include <qmessagebox.h> #if QT_VERSION < 0x030000 #include <qlist.h> #else #include <qptrlist.h> #endif #include <qdir.h> #include <qfile.h> #include <qtextstream.h> #include <qregexp.h> /* STD */ #include <net/if.h> #include <sys/ioctl.h> #include <sys/socket.h> #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" #define _PROCNETDEV "/proc/net/dev" MainWindowImp::MainWindowImp(QWidget *parent, const char *name, WFlags) : MainWindow(parent, name, Qt::WStyle_ContextHelp), advancedUserMode(true), scheme(DEFAULT_SCHEME) { connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); //remove tab with no function tabWidget->removePage( tab ); // Load connections. // /usr/local/kde/lib/libinterfaces.la loadModules(QPEApplication::qpeDir() + "plugins/networksettings"); getAllInterfaces(); Interfaces i; QStringList list = i.getInterfaceList(); QMap<QString, Interface*>::Iterator it; for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { /* * we skipped it in getAllInterfaces now * we need to ignore it as well */ if (m_handledIfaces.contains( *ni) ) { odebug << "Not up iface handled by module" << oendl; continue; } bool found = false; for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ) { if(it.key() == (*ni)) found = true; } if(!found) { if(!(*ni).contains("_")) { Interface *i = new Interface(this, *ni, false); i->setAttached(false); i->setHardwareName(tr("Disconnected")); interfaceNames.insert(i->getInterfaceName(), i); updateInterface(i); connect(i, SIGNAL(updateInterface(Interface*)), this, SLOT(updateInterface(Interface*))); } } } //getInterfaceList(); connectionList->header()->hide(); Config cfg("NetworkSetup"); profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) profilesList->insertItem((*it)); currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); @@ -427,193 +428,195 @@ void MainWindowImp::configureClicked() { QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok); return; } QString currentProfileText = currentProfileLabel->text(); if(currentProfileText.upper() == "ALL"); currentProfileText = ""; Interface *i = interfaceItems[item]; if(i->getModuleOwner()) { QWidget *moduleConfigure = i->getModuleOwner()->configure(i); if(moduleConfigure != NULL) { i->getModuleOwner()->setProfile(currentProfileText); QPEApplication::showWidget( moduleConfigure ); return; } } InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose | Qt::WStyle_ContextHelp ); configure->setProfile(currentProfileText); QPEApplication::showDialog( configure ); } /** * Pull up the information about the currently selected interface. * Report an error if no interface is selected. * If the interface has a module owner then request its configure. */ void MainWindowImp::informationClicked() { QListViewItem *item = connectionList->currentItem(); if(!item) { QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); return; } Interface *i = interfaceItems[item]; // if(!i->isAttached()){ // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); // return; // } if(i->getModuleOwner()) { QWidget *moduleInformation = i->getModuleOwner()->information(i); if(moduleInformation != NULL) { QPEApplication::showWidget( moduleInformation ); #ifdef DEBUG odebug << "MainWindowImp::informationClicked:: Module owner has created, we showed." << oendl; #endif return; } } InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog | Qt::WStyle_ContextHelp); QPEApplication::showWidget( information ); } /** * Update this interface. If no QListViewItem exists create one. * @param Interface* pointer to the interface that needs to be updated. */ void MainWindowImp::updateInterface(Interface *i) { if(!advancedUserMode) { if(i->getInterfaceName() == "lo") return; } QListViewItem *item = NULL; // Find the interface, making it if needed. if(items.find(i) == items.end()) { item = new QListViewItem(connectionList, "", "", ""); // See if you can't find a module owner for this interface QMap<Module*, QLibrary*>::Iterator it; for( it = libraries.begin(); it != libraries.end(); ++it ) { if(it.key()->isOwner(i)) i->setModuleOwner(it.key()); } items.insert(i, item); interfaceItems.insert(item, i); } else item = items[i]; // Update the icons and information #ifdef QWS - item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); + QPixmap pic; + pic.convertFromImage( Resource::loadImage( i->getStatus() ? "up": "down" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); + item->setPixmap(0, ( pic )); #else item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); #endif QString typeName = "lan"; if(i->getInterfaceName() == "lo") typeName = "lo"; if(i->getInterfaceName().contains("irda")) typeName = "irda"; if(i->getInterfaceName().contains("wlan")) typeName = "wlan"; if(i->getInterfaceName().contains("usb")) typeName = "usb"; if(!i->isAttached()) typeName = "connect_no"; // Actually try to use the Module if(i->getModuleOwner() != NULL) typeName = i->getModuleOwner()->getPixmapName(i); #ifdef QWS item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); #else item->setPixmap(1, (SmallIcon(typeName))); #endif item->setText(2, i->getHardwareName()); item->setText(3, QString("(%1)").arg(i->getInterfaceName())); item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); } void MainWindowImp::newProfileChanged(const QString& newText) { if(newText.length() > 0) newProfileButton->setEnabled(true); else newProfileButton->setEnabled(false); } /** * Adds a new profile to the list of profiles. * Don't add profiles that already exists. * Appends to the list and QStringList */ void MainWindowImp::addProfile() { QString newProfileName = newProfile->text(); if(profiles.grep(newProfileName).count() > 0) { QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); return; } profiles.append(newProfileName); profilesList->insertItem(newProfileName); } /** * Removes the currently selected profile in the combo. * Doesn't delete if there are less then 2 profiles. */ void MainWindowImp::removeProfile() { if(profilesList->count() <= 1) { QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); return; } QString profileToRemove = profilesList->currentText(); if(profileToRemove == "All") { QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); return; } // Can't remove the curent profile if(profileToRemove == currentProfileLabel->text()) { QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); return; } if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) { profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); profilesList->clear(); for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) profilesList->insertItem((*it)); // Remove any interface settings and mappings. Interfaces interfaces; // Go through them one by one QMap<Interface*, QListViewItem*>::Iterator it; for( it = items.begin(); it != items.end(); ++it ) { QString interfaceName = it.key()->getInterfaceName(); odebug << interfaceName.latin1() << oendl; if(interfaces.setInterface(interfaceName + "_" + profileToRemove)) |