-rw-r--r-- | noncore/net/networksetup/mainwindow.ui | 89 | ||||
-rw-r--r-- | noncore/net/networksetup/mainwindowimp.cpp | 56 | ||||
-rw-r--r-- | noncore/net/networksetup/mainwindowimp.h | 1 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindow.ui | 89 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 56 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.h | 1 |
6 files changed, 198 insertions, 94 deletions
diff --git a/noncore/net/networksetup/mainwindow.ui b/noncore/net/networksetup/mainwindow.ui index b8c0675..f7efe99 100644 --- a/noncore/net/networksetup/mainwindow.ui +++ b/noncore/net/networksetup/mainwindow.ui @@ -1,321 +1,326 @@ <!DOCTYPE UI><UI> <class>MainWindow</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>MainWindow</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>222</width> + <width>218</width> <height>289</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Network Setup</string> </property> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QTabWidget</class> <property stdset="1"> <name>name</name> <cstring>tabWidget</cstring> </property> <property> <name>layoutMargin</name> </property> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>Widget3</cstring> </property> <attribute> <name>title</name> <string>Interfaces</string> </attribute> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QListView</class> <column> <property> <name>text</name> <string>i</string> </property> <property> <name>clickable</name> <bool>true</bool> </property> <property> <name>resizeable</name> <bool>true</bool> </property> </column> <column> <property> <name>text</name> <string>t</string> </property> <property> <name>clickable</name> <bool>true</bool> </property> <property> <name>resizeable</name> <bool>true</bool> </property> </column> <column> <property> <name>text</name> <string>Name</string> </property> <property> <name>clickable</name> <bool>true</bool> </property> <property> <name>resizeable</name> <bool>true</bool> </property> </column> <property stdset="1"> <name>name</name> <cstring>serviceList</cstring> </property> <property stdset="1"> <name>allColumnsShowFocus</name> <bool>true</bool> </property> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout2</cstring> </property> <property> <name>layoutMargin</name> </property> <grid> <property stdset="1"> <name>margin</name> <number>5</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget row="1" column="0" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>addServiceButton</cstring> </property> <property stdset="1"> <name>text</name> <string>&Add</string> </property> </widget> <widget row="0" column="0" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>informationServiceButton</cstring> </property> <property stdset="1"> <name>text</name> <string>&Information</string> </property> </widget> <widget row="0" column="1" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>configureServiceButton</cstring> </property> <property stdset="1"> <name>text</name> <string>&Configure</string> </property> </widget> <widget row="1" column="1" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>removeServiceButton</cstring> </property> <property stdset="1"> <name>text</name> <string>&Remove</string> </property> </widget> </grid> </widget> </vbox> </widget> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>tab</cstring> </property> <attribute> <name>title</name> <string>Profiles</string> </attribute> <grid> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> - <widget row="1" column="0" rowspan="1" colspan="2" > - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel3</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Change Profile To</string> - </property> - </widget> <widget row="0" column="0" rowspan="1" colspan="2" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel1</cstring> </property> <property stdset="1"> <name>text</name> <string>Current Profile</string> </property> </widget> <widget row="0" column="2" > <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel2</cstring> + <cstring>currentProfileLabel</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Sunken</enum> </property> <property stdset="1"> <name>text</name> <string>All</string> </property> </widget> - <widget row="1" column="2" > - <class>QComboBox</class> - <item> - <property> - <name>text</name> - <string>All</string> - </property> - </item> - <property stdset="1"> - <name>name</name> - <cstring>ComboBox10</cstring> - </property> - </widget> - <widget row="2" column="1" rowspan="1" colspan="2" > - <class>QPushButton</class> - <property stdset="1"> - <name>name</name> - <cstring>removeProfileButton</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>&Remove</string> - </property> - </widget> - <widget row="2" column="0" > - <class>QPushButton</class> + <widget row="1" column="0" > + <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>newProfileButton</cstring> + <cstring>TextLabel1_2</cstring> </property> <property stdset="1"> <name>text</name> - <string>&New</string> + <string>Profiles</string> </property> </widget> - <spacer row="3" column="2" > + <spacer row="5" column="2" > <property> <name>name</name> <cstring>Spacer16</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> + <widget row="2" column="0" rowspan="3" colspan="1" > + <class>QListBox</class> + <property stdset="1"> + <name>name</name> + <cstring>profilesList</cstring> + </property> + </widget> + <widget row="4" column="1" rowspan="1" colspan="2" > + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>PushButton7</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Set Current</string> + </property> + </widget> + <widget row="3" column="1" rowspan="1" colspan="2" > + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>removeProfileButton</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>&Remove</string> + </property> + </widget> + <widget row="2" column="1" rowspan="1" colspan="2" > + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>newProfileButton</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>&New</string> + </property> + </widget> </grid> </widget> </widget> </vbox> </widget> <customwidgets> <customwidget> <class>QWidget</class> <header location="local">qwidget.h</header> <sizehint> <width>100</width> <height>100</height> </sizehint> <container>0</container> <sizepolicy> <hordata>7</hordata> <verdata>7</verdata> </sizepolicy> <pixmap>image0</pixmap> </customwidget> </customwidgets> <images> <image> <name>image0</name> <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> </image> </images> </UI> diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp index ad9362f..2f821a9 100644 --- a/noncore/net/networksetup/mainwindowimp.cpp +++ b/noncore/net/networksetup/mainwindowimp.cpp @@ -1,155 +1,166 @@ #include "mainwindowimp.h"
#include "addserviceimp.h"
#include "interfaceinformationimp.h"
#include "interfacesetupimp.h"
#include "interface.h"
#include "kprocess.h"
#include "module.h"
#include <qpushbutton.h>
-#include <qdir.h>
#include <qtabwidget.h>
+#include <qlistbox.h>
+#include <qlistview.h>
+#include <qheader.h>
+#include <qlabel.h>
+
#include <qmainwindow.h>
#include <qmessagebox.h>
-#include <qlistbox.h>
+
#include <qpe/config.h>
#include <qpe/qlibrary.h>
#include <qpe/resource.h>
-#include <qlist.h>
+#include <qlist.h>
+#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
-#include <qlistview.h>
-#include <qheader.h>
+
// For library loading.
#include <dlfcn.h>
#define TEMP_ALL "/tmp/ifconfig-a"
#define TEMP_UP "/tmp/ifconfig"
#define NO_SELECT_ERROR_AND_RETURN { \
QMessageBox::information(this, "Error","Please select an interface.", "Ok"); \
return; \
}
MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true) {
connect(addServiceButton, SIGNAL(clicked()), this, SLOT(addClicked()));
connect(removeServiceButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
connect(informationServiceButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
connect(configureServiceButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
+
+ connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
+ connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
+ connect(profilesList, SIGNAL(highlighted(const QString&)), this, SLOT(changeProfile(const QString&)));
+
// Make sure we have a plugin directory to scan.
QString DirStr = QDir::homeDirPath() + "/.networksetup/" ;
QDir pluginDir( DirStr );
pluginDir.mkdir( DirStr );
pluginDir.mkdir( ( DirStr + "plugins/" ) );
QString path = DirStr + "plugins";
pluginDir.setPath(path);
if(!pluginDir.exists()){
qDebug(QString("MainWindowImp: ERROR: %1 %2").arg(__FILE__).arg(__LINE__).latin1());
return;
}
// Load any saved services.
loadModules(path);
getInterfaceList();
serviceList->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));
}
/**
* Deconstructor. Unload libraries and save profile list.
*/
MainWindowImp::~MainWindowImp(){
if(profiles.count() > 1){
Config cfg("NetworkSetup");
cfg.writeEntry("Profiles", profiles.join(" "));
}
}
void MainWindowImp::loadModules(QString path){
}
/**
* 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(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!");
delete lib;
return NULL;
}
// Store for reference
libraries.insert(object, lib);
return object;
}
/*
QList<QString> MainWindowImp::retrieveUnloadedPluginList(){
QString DirStr = QDir::homeDirPath() + "/.networksetup/" ;
QString path = DirStr + "plugins";
QDir d(path);
d.setFilter( QDir::Files | QDir::Hidden );
QMap<QObject*, QLibrary*>::Iterator libraryIt;
QList<QString> rlist;
rlist.setAutoDelete(false);
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
while ( (fi=it.current()) ) {
if(fi->fileName().contains(".so")){
for( libraryIt = libraries.begin(); libraryIt != libraries.end(); ++libraryIt )
if((path + "/" + fi->fileName()) != (libraryIt.data())->library()){
QString *s = new QString(path + "/" + fi->fileName());
rlist.append(s);
}
}
++it;
}
return rlist;
}
*/
/**
* The Add button was clicked. Bring up the add dialog and if OK is hit
* load the plugin and append it to the list
*/
void MainWindowImp::addClicked(){
// Now that we have a list of all of the protocals, list them.
{
QMessageBox::information(this, "No Modules", "Nothing to add.", "Ok");
return;
}
AddServiceImp service(this, "AddService", true);
service.showMaximized();
service.exec();
}
/**
* 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 = serviceList->currentItem();
if(item == NULL) NO_SELECT_ERROR_AND_RETURN
if(modules.find(interfaceItems[item]) == modules.end()){
@@ -214,106 +225,141 @@ void MainWindowImp::getInterfaceList(){ processAll->start(KShellProcess::NotifyOnExit);
KShellProcess *process = new KShellProcess();
*process << "/sbin/ifconfig" << " > " TEMP_UP;
connect(process, SIGNAL(processExited(KProcess *)),
this, SLOT(jobDone(KProcess *)));
threads.insert(process, TEMP_UP);
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;
// See if we already have it
if(interfaceNames.find(interfaceName) == interfaceNames.end()){
if(fileName == TEMP_ALL)
i = new Interface(interfaceName, false);
else
i = new Interface(interfaceName, true);
}
else{
i = interfaceNames[interfaceName];
if(fileName != TEMP_ALL)
i->setStatus(true);
}
i->setAttached(true);
i->setInterfaceName(interfaceName);
QString hardName = "Ethernet";
int hardwareName = line.find("Link encap:");
int macAddress = line.find("HWaddr");
if(macAddress == -1)
macAddress = line.length();
if(hardwareName != -1)
i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName()));
// We have found an interface
//qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
}
}
file.close();
QFile::remove(fileName);
}
void MainWindowImp::updateInterface(Interface *i){
QListViewItem *item = NULL;
// See if we already have it
if(items.find(i) == items.end()){
item = new QListViewItem(serviceList, "", "", "");
// See if you can't find a module owner for this interface
//EmployeeMap::Iterator it;
//for( it = map.begin(); it != map.end(); ++it )
// printf( "%s, %s earns %d\n", it.key().latin1(), it.data().name().latin1(), it.data().salary() );
items.insert(i, item);
interfaceItems.insert(item, i);
}
else
item = items[i];
QString statusImage = "down";
if(i->getStatus())
statusImage = "up";
QPixmap status = (Resource::loadPixmap(statusImage));
item->setPixmap(0, status);
QString typeName = "lan";
if(i->getHardwareName().contains("Local Loopback"))
typeName = "lo";
QPixmap type = (Resource::loadPixmap(typeName));
item->setPixmap(1, type);
item->setText(2, i->getHardwareName());
}
+/**
+ * Adds a new profile to the list of profiles.
+ * Don't add profiles that already exists.
+ * Appends to the combo and QStringList
+ */
void MainWindowImp::addProfile(){
+ QString newProfileName = "New";
+ if(profiles.grep(newProfileName).count() > 0){
+ QMessageBox::information(this, "Can't Add.","Profile already exists.", "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 anything.","Need One Profile.", "Ok");
+ return;
+ }
+ QString profileToRemove = profilesList->currentText();
+ 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));
+ }
}
+/**
+ * A new profile has been selected, change.
+ * @param newProfile the new profile.
+ */
+void MainWindowImp::changeProfile(const QString& newProfile){
+ currentProfileLabel->setText(newProfile);
+}
+
// mainwindowimp.cpp
diff --git a/noncore/net/networksetup/mainwindowimp.h b/noncore/net/networksetup/mainwindowimp.h index 0618dd2..8e300bf 100644 --- a/noncore/net/networksetup/mainwindowimp.h +++ b/noncore/net/networksetup/mainwindowimp.h @@ -1,56 +1,57 @@ #ifndef MAINWINOWIMP_H
#define MAINWINOWIMP_H
#include "mainwindow.h"
#include <qmap.h>
#include <qstringlist.h>
class Module;
class Interface;
class QLibrary;
class KProcess;
class MainWindowImp : public MainWindow {
Q_OBJECT
public:
MainWindowImp(QWidget *parent=0, const char *name=0);
~MainWindowImp();
private slots:
void addClicked();
void removeClicked();
void configureClicked();
void informationClicked();
void jobDone(KProcess *process);
void getInterfaceList();
void addProfile();
void removeProfile();
+ void changeProfile(const QString&);
void updateInterface(Interface *i);
private:
void loadModules(QString path);
Module* loadPlugin(QString pluginFileName,
QString resolveString = "create_plugin");
// For our local list of names
QMap<QString, Interface*> interfaceNames;
QMap<Module*, QLibrary*> libraries;
QMap<Interface*, Module*> modules;
QMap<Interface*, QListViewItem*> items;
QMap<QListViewItem*, Interface*> interfaceItems;
QMap<KProcess*, QString> threads;
QStringList profiles;
};
#endif
// mainwindowimp.h
diff --git a/noncore/settings/networksettings/mainwindow.ui b/noncore/settings/networksettings/mainwindow.ui index b8c0675..f7efe99 100644 --- a/noncore/settings/networksettings/mainwindow.ui +++ b/noncore/settings/networksettings/mainwindow.ui @@ -1,321 +1,326 @@ <!DOCTYPE UI><UI> <class>MainWindow</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>MainWindow</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>222</width> + <width>218</width> <height>289</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Network Setup</string> </property> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QTabWidget</class> <property stdset="1"> <name>name</name> <cstring>tabWidget</cstring> </property> <property> <name>layoutMargin</name> </property> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>Widget3</cstring> </property> <attribute> <name>title</name> <string>Interfaces</string> </attribute> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QListView</class> <column> <property> <name>text</name> <string>i</string> </property> <property> <name>clickable</name> <bool>true</bool> </property> <property> <name>resizeable</name> <bool>true</bool> </property> </column> <column> <property> <name>text</name> <string>t</string> </property> <property> <name>clickable</name> <bool>true</bool> </property> <property> <name>resizeable</name> <bool>true</bool> </property> </column> <column> <property> <name>text</name> <string>Name</string> </property> <property> <name>clickable</name> <bool>true</bool> </property> <property> <name>resizeable</name> <bool>true</bool> </property> </column> <property stdset="1"> <name>name</name> <cstring>serviceList</cstring> </property> <property stdset="1"> <name>allColumnsShowFocus</name> <bool>true</bool> </property> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout2</cstring> </property> <property> <name>layoutMargin</name> </property> <grid> <property stdset="1"> <name>margin</name> <number>5</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget row="1" column="0" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>addServiceButton</cstring> </property> <property stdset="1"> <name>text</name> <string>&Add</string> </property> </widget> <widget row="0" column="0" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>informationServiceButton</cstring> </property> <property stdset="1"> <name>text</name> <string>&Information</string> </property> </widget> <widget row="0" column="1" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>configureServiceButton</cstring> </property> <property stdset="1"> <name>text</name> <string>&Configure</string> </property> </widget> <widget row="1" column="1" > <class>QPushButton</class> <property stdset="1"> <name>name</name> <cstring>removeServiceButton</cstring> </property> <property stdset="1"> <name>text</name> <string>&Remove</string> </property> </widget> </grid> </widget> </vbox> </widget> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>tab</cstring> </property> <attribute> <name>title</name> <string>Profiles</string> </attribute> <grid> <property stdset="1"> <name>margin</name> <number>11</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> - <widget row="1" column="0" rowspan="1" colspan="2" > - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel3</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Change Profile To</string> - </property> - </widget> <widget row="0" column="0" rowspan="1" colspan="2" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel1</cstring> </property> <property stdset="1"> <name>text</name> <string>Current Profile</string> </property> </widget> <widget row="0" column="2" > <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel2</cstring> + <cstring>currentProfileLabel</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Sunken</enum> </property> <property stdset="1"> <name>text</name> <string>All</string> </property> </widget> - <widget row="1" column="2" > - <class>QComboBox</class> - <item> - <property> - <name>text</name> - <string>All</string> - </property> - </item> - <property stdset="1"> - <name>name</name> - <cstring>ComboBox10</cstring> - </property> - </widget> - <widget row="2" column="1" rowspan="1" colspan="2" > - <class>QPushButton</class> - <property stdset="1"> - <name>name</name> - <cstring>removeProfileButton</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>&Remove</string> - </property> - </widget> - <widget row="2" column="0" > - <class>QPushButton</class> + <widget row="1" column="0" > + <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>newProfileButton</cstring> + <cstring>TextLabel1_2</cstring> </property> <property stdset="1"> <name>text</name> - <string>&New</string> + <string>Profiles</string> </property> </widget> - <spacer row="3" column="2" > + <spacer row="5" column="2" > <property> <name>name</name> <cstring>Spacer16</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> + <widget row="2" column="0" rowspan="3" colspan="1" > + <class>QListBox</class> + <property stdset="1"> + <name>name</name> + <cstring>profilesList</cstring> + </property> + </widget> + <widget row="4" column="1" rowspan="1" colspan="2" > + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>PushButton7</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Set Current</string> + </property> + </widget> + <widget row="3" column="1" rowspan="1" colspan="2" > + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>removeProfileButton</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>&Remove</string> + </property> + </widget> + <widget row="2" column="1" rowspan="1" colspan="2" > + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>newProfileButton</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>&New</string> + </property> + </widget> </grid> </widget> </widget> </vbox> </widget> <customwidgets> <customwidget> <class>QWidget</class> <header location="local">qwidget.h</header> <sizehint> <width>100</width> <height>100</height> </sizehint> <container>0</container> <sizepolicy> <hordata>7</hordata> <verdata>7</verdata> </sizepolicy> <pixmap>image0</pixmap> </customwidget> </customwidgets> <images> <image> <name>image0</name> <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> </image> </images> </UI> diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index ad9362f..2f821a9 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp @@ -1,155 +1,166 @@ #include "mainwindowimp.h"
#include "addserviceimp.h"
#include "interfaceinformationimp.h"
#include "interfacesetupimp.h"
#include "interface.h"
#include "kprocess.h"
#include "module.h"
#include <qpushbutton.h>
-#include <qdir.h>
#include <qtabwidget.h>
+#include <qlistbox.h>
+#include <qlistview.h>
+#include <qheader.h>
+#include <qlabel.h>
+
#include <qmainwindow.h>
#include <qmessagebox.h>
-#include <qlistbox.h>
+
#include <qpe/config.h>
#include <qpe/qlibrary.h>
#include <qpe/resource.h>
-#include <qlist.h>
+#include <qlist.h>
+#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
-#include <qlistview.h>
-#include <qheader.h>
+
// For library loading.
#include <dlfcn.h>
#define TEMP_ALL "/tmp/ifconfig-a"
#define TEMP_UP "/tmp/ifconfig"
#define NO_SELECT_ERROR_AND_RETURN { \
QMessageBox::information(this, "Error","Please select an interface.", "Ok"); \
return; \
}
MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true) {
connect(addServiceButton, SIGNAL(clicked()), this, SLOT(addClicked()));
connect(removeServiceButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
connect(informationServiceButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
connect(configureServiceButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
+
+ connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
+ connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
+ connect(profilesList, SIGNAL(highlighted(const QString&)), this, SLOT(changeProfile(const QString&)));
+
// Make sure we have a plugin directory to scan.
QString DirStr = QDir::homeDirPath() + "/.networksetup/" ;
QDir pluginDir( DirStr );
pluginDir.mkdir( DirStr );
pluginDir.mkdir( ( DirStr + "plugins/" ) );
QString path = DirStr + "plugins";
pluginDir.setPath(path);
if(!pluginDir.exists()){
qDebug(QString("MainWindowImp: ERROR: %1 %2").arg(__FILE__).arg(__LINE__).latin1());
return;
}
// Load any saved services.
loadModules(path);
getInterfaceList();
serviceList->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));
}
/**
* Deconstructor. Unload libraries and save profile list.
*/
MainWindowImp::~MainWindowImp(){
if(profiles.count() > 1){
Config cfg("NetworkSetup");
cfg.writeEntry("Profiles", profiles.join(" "));
}
}
void MainWindowImp::loadModules(QString path){
}
/**
* 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(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!");
delete lib;
return NULL;
}
// Store for reference
libraries.insert(object, lib);
return object;
}
/*
QList<QString> MainWindowImp::retrieveUnloadedPluginList(){
QString DirStr = QDir::homeDirPath() + "/.networksetup/" ;
QString path = DirStr + "plugins";
QDir d(path);
d.setFilter( QDir::Files | QDir::Hidden );
QMap<QObject*, QLibrary*>::Iterator libraryIt;
QList<QString> rlist;
rlist.setAutoDelete(false);
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
while ( (fi=it.current()) ) {
if(fi->fileName().contains(".so")){
for( libraryIt = libraries.begin(); libraryIt != libraries.end(); ++libraryIt )
if((path + "/" + fi->fileName()) != (libraryIt.data())->library()){
QString *s = new QString(path + "/" + fi->fileName());
rlist.append(s);
}
}
++it;
}
return rlist;
}
*/
/**
* The Add button was clicked. Bring up the add dialog and if OK is hit
* load the plugin and append it to the list
*/
void MainWindowImp::addClicked(){
// Now that we have a list of all of the protocals, list them.
{
QMessageBox::information(this, "No Modules", "Nothing to add.", "Ok");
return;
}
AddServiceImp service(this, "AddService", true);
service.showMaximized();
service.exec();
}
/**
* 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 = serviceList->currentItem();
if(item == NULL) NO_SELECT_ERROR_AND_RETURN
if(modules.find(interfaceItems[item]) == modules.end()){
@@ -214,106 +225,141 @@ void MainWindowImp::getInterfaceList(){ processAll->start(KShellProcess::NotifyOnExit);
KShellProcess *process = new KShellProcess();
*process << "/sbin/ifconfig" << " > " TEMP_UP;
connect(process, SIGNAL(processExited(KProcess *)),
this, SLOT(jobDone(KProcess *)));
threads.insert(process, TEMP_UP);
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;
// See if we already have it
if(interfaceNames.find(interfaceName) == interfaceNames.end()){
if(fileName == TEMP_ALL)
i = new Interface(interfaceName, false);
else
i = new Interface(interfaceName, true);
}
else{
i = interfaceNames[interfaceName];
if(fileName != TEMP_ALL)
i->setStatus(true);
}
i->setAttached(true);
i->setInterfaceName(interfaceName);
QString hardName = "Ethernet";
int hardwareName = line.find("Link encap:");
int macAddress = line.find("HWaddr");
if(macAddress == -1)
macAddress = line.length();
if(hardwareName != -1)
i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName()));
// We have found an interface
//qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
}
}
file.close();
QFile::remove(fileName);
}
void MainWindowImp::updateInterface(Interface *i){
QListViewItem *item = NULL;
// See if we already have it
if(items.find(i) == items.end()){
item = new QListViewItem(serviceList, "", "", "");
// See if you can't find a module owner for this interface
//EmployeeMap::Iterator it;
//for( it = map.begin(); it != map.end(); ++it )
// printf( "%s, %s earns %d\n", it.key().latin1(), it.data().name().latin1(), it.data().salary() );
items.insert(i, item);
interfaceItems.insert(item, i);
}
else
item = items[i];
QString statusImage = "down";
if(i->getStatus())
statusImage = "up";
QPixmap status = (Resource::loadPixmap(statusImage));
item->setPixmap(0, status);
QString typeName = "lan";
if(i->getHardwareName().contains("Local Loopback"))
typeName = "lo";
QPixmap type = (Resource::loadPixmap(typeName));
item->setPixmap(1, type);
item->setText(2, i->getHardwareName());
}
+/**
+ * Adds a new profile to the list of profiles.
+ * Don't add profiles that already exists.
+ * Appends to the combo and QStringList
+ */
void MainWindowImp::addProfile(){
+ QString newProfileName = "New";
+ if(profiles.grep(newProfileName).count() > 0){
+ QMessageBox::information(this, "Can't Add.","Profile already exists.", "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 anything.","Need One Profile.", "Ok");
+ return;
+ }
+ QString profileToRemove = profilesList->currentText();
+ 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));
+ }
}
+/**
+ * A new profile has been selected, change.
+ * @param newProfile the new profile.
+ */
+void MainWindowImp::changeProfile(const QString& newProfile){
+ currentProfileLabel->setText(newProfile);
+}
+
// mainwindowimp.cpp
diff --git a/noncore/settings/networksettings/mainwindowimp.h b/noncore/settings/networksettings/mainwindowimp.h index 0618dd2..8e300bf 100644 --- a/noncore/settings/networksettings/mainwindowimp.h +++ b/noncore/settings/networksettings/mainwindowimp.h @@ -1,56 +1,57 @@ #ifndef MAINWINOWIMP_H
#define MAINWINOWIMP_H
#include "mainwindow.h"
#include <qmap.h>
#include <qstringlist.h>
class Module;
class Interface;
class QLibrary;
class KProcess;
class MainWindowImp : public MainWindow {
Q_OBJECT
public:
MainWindowImp(QWidget *parent=0, const char *name=0);
~MainWindowImp();
private slots:
void addClicked();
void removeClicked();
void configureClicked();
void informationClicked();
void jobDone(KProcess *process);
void getInterfaceList();
void addProfile();
void removeProfile();
+ void changeProfile(const QString&);
void updateInterface(Interface *i);
private:
void loadModules(QString path);
Module* loadPlugin(QString pluginFileName,
QString resolveString = "create_plugin");
// For our local list of names
QMap<QString, Interface*> interfaceNames;
QMap<Module*, QLibrary*> libraries;
QMap<Interface*, Module*> modules;
QMap<Interface*, QListViewItem*> items;
QMap<QListViewItem*, Interface*> interfaceItems;
QMap<KProcess*, QString> threads;
QStringList profiles;
};
#endif
// mainwindowimp.h
|