summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/mainwindowimp.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings/mainwindowimp.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp28
1 files changed, 7 insertions, 21 deletions
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index f9ca83b..b9fff56 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -1,145 +1,145 @@
#include "mainwindowimp.h"
#include "addconnectionimp.h"
#include "interfaceinformationimp.h"
#include "interfacesetupimp.h"
#include "interfaces.h"
#include "module.h"
#include "kprocess.h"
#include <qpushbutton.h>
-#include <qtabwidget.h>
#include <qlistbox.h>
#include <qlineedit.h>
#include <qlistview.h>
#include <qheader.h>
#include <qlabel.h>
#include <qmainwindow.h>
#include <qmessagebox.h>
#include <qpe/config.h>
#include <qpe/qlibrary.h>
#include <qpe/resource.h>
#include <qpe/qpeapplication.h>
#include <qlist.h>
#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
#define TEMP_ALL "/tmp/ifconfig-a"
#define TEMP_UP "/tmp/ifconfig"
#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){
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()));
connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
// Load connections.
loadModules(QPEApplication::qpeDir() + "/plugins/networksetup");
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);
QFile file(scheme);
if ( file.open(IO_ReadOnly) ) { // file opened successfully
QTextStream stream( &file ); // use a text stream
while ( !stream.eof() ) { // until end of file...
QString line = stream.readLine(); // line of text excluding '\n'
if(line.contains("SCHEME")){
line = line.mid(7, line.length());
currentProfileLabel->setText(line);
break;
}
}
file.close();
}
}
/**
* Deconstructor. Save profiles. Delete loaded libraries.
*/
MainWindowImp::~MainWindowImp(){
// Save profiles.
Config cfg("NetworkSetup");
cfg.setGroup("General");
cfg.writeEntry("Profiles", profiles.join(" "));
// Delete all interfaces that don't have owners.
QMap<Interface*, QListViewItem*>::Iterator iIt;
for( iIt = items.begin(); iIt != items.end(); ++iIt ){
if(iIt.key()->getModuleOwner() == NULL)
delete iIt.key();
}
// Delete Modules and Libraries
QMap<Module*, QLibrary*>::Iterator it;
for( it = libraries.begin(); it != libraries.end(); ++it ){
delete it.key();
// I wonder why I can't delete the libraries
+ // What fucking shit this is.
//delete it.data();
}
}
/**
* Load all modules that are found in the path
* @param path a directory that is scaned for any plugins that can be loaded
* and attempts to load them
*/
void MainWindowImp::loadModules(QString path){
//qDebug(path.latin1());
QDir d(path);
if(!d.exists())
return;
// Don't want sym links
d.setFilter( QDir::Files | QDir::NoSymLinks );
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
while ( (fi=it.current()) ) {
if(fi->fileName().contains(".so")){
loadPlugin(path + "/" + fi->fileName());
}
++it;
}
}
/**
* Attempt to load a function and resolve a function.
* @param pluginFileName - the name of the file in which to attempt to load
* @param resolveString - function pointer to resolve
* @return pointer to the function with name resolveString or NULL
*/
Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){
//qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
QLibrary *lib = new QLibrary(pluginFileName);
void *functionPointer = lib->resolve(resolveString);
if( !functionPointer ){
qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
delete lib;
return NULL;
}
// Try to get an object.
Module *object = ((Module* (*)()) functionPointer)();
if(object == NULL){
qDebug("MainWindowImp: Couldn't create object, but did load library!");
@@ -176,172 +176,158 @@ void MainWindowImp::addClicked(){
addNewConnection.addConnections(list);
addNewConnection.showMaximized();
if(QDialog::Accepted == addNewConnection.exec()){
QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
if(!item)
return;
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()){
Interface *i = (it.key())->addNewInterface(item->text(0));
if(i){
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
}
}
}
}
}
/**
* Prompt the user to see if they really want to do this.
* If they do then remove from the list and unload.
*/
void MainWindowImp::removeClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item) {
QMessageBox::information(this, "Sorry","Please select an interface First.", "Ok");
return;
}
Interface *i = interfaceItems[item];
if(i->getModuleOwner() == NULL){
QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok");
}
else{
if(!i->getModuleOwner()->remove(i))
QMessageBox::information(this, "Error", "Unable to remove.", "Ok");
else{
QMessageBox::information(this, "Success", "Interface was removed.", "Ok");
// TODO memory managment....
// who deletes the interface?
}
}
}
/**
* Pull up the configure about the currently selected interface.
* Report an error if no interface is selected.
- * If the interface has a module owner then request its configure with a empty
- * tab. If tab is !NULL then append the interfaces setup widget to it.
+ * If the interface has a module owner then request its configure.
*/
void MainWindowImp::configureClicked(){
QListViewItem *item = connectionList->currentItem();
if(!item){
QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok);
return;
}
QString currentProfile = currentProfileLabel->text();
if(profilesList->count() <= 1 || currentProfile == "All"){
currentProfile = "";
}
Interface *i = interfaceItems[item];
if(i->getModuleOwner()){
i->getModuleOwner()->setProfile(currentProfile);
- QTabWidget *tabWidget = NULL;
- QWidget *moduleConfigure = i->getModuleOwner()->configure(i, &tabWidget);
+ QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
if(moduleConfigure != NULL){
- if(tabWidget != NULL){
- InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, false, Qt::WDestructiveClose);
- configure->setProfile(currentProfile);
- tabWidget->insertTab(configure, "TCP/IP");
- }
moduleConfigure->showMaximized();
moduleConfigure->show();
return;
}
}
- InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, false, Qt::WDestructiveClose);
- configure->setProfile(currentProfile);
+ InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(0, "InterfaceSetupImp", i, true, Qt::WDestructiveClose);
+ //configure->setProfile(currentProfile);
configure->showMaximized();
configure->show();
}
/**
* 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 with a empty
- * tab. If tab is !NULL then append the interfaces setup widget to it.
+ * 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;
}
QStringList list;
for(uint i = 0; i < profilesList->count(); i++){
list.append(profilesList->text(i));
}
if(i->getModuleOwner()){
- QTabWidget *tabWidget = NULL;
- QWidget *moduleInformation = i->getModuleOwner()->information(i, &tabWidget);
+ QWidget *moduleInformation = i->getModuleOwner()->information(i);
if(moduleInformation != NULL){
- if(tabWidget != NULL){
- InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true);
- tabWidget->insertTab(information, "TCP/IP");
- }
moduleInformation->showMaximized();
moduleInformation->show();
return;
}
}
-
InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
information->showMaximized();
information->show();
}
/**
* Aquire the list of active interfaces from ifconfig
* Call ifconfig and ifconfig -a
*/
void MainWindowImp::getInterfaceList(){
KShellProcess *processAll = new KShellProcess();
*processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
connect(processAll, SIGNAL(processExited(KProcess *)),
this, SLOT(jobDone(KProcess *)));
threads.insert(processAll, TEMP_ALL);
KShellProcess *process = new KShellProcess();
*process << "/sbin/ifconfig" << " > " TEMP_UP;
connect(process, SIGNAL(processExited(KProcess *)),
this, SLOT(jobDone(KProcess *)));
threads.insert(process, TEMP_UP);
processAll->start(KShellProcess::NotifyOnExit);
process->start(KShellProcess::NotifyOnExit);
}
void MainWindowImp::jobDone(KProcess *process){
QString fileName = threads[process];
threads.remove(process);
delete process;
QFile file(fileName);
if (!file.open(IO_ReadOnly)){
qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
return;
}
QTextStream stream( &file );
QString line;
while ( !stream.eof() ) {
line = stream.readLine();
int space = line.find(" ");
if(space > 1){
// We have found an interface
QString interfaceName = line.mid(0, space);
Interface *i;
// We have found an interface
//qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());