Diffstat (limited to 'noncore/settings/networksettings/mainwindowimp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 205 |
1 files changed, 106 insertions, 99 deletions
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index 89dac6f..66ec8b5 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp | |||
@@ -1,13 +1,13 @@ | |||
1 | #include "mainwindowimp.h" | 1 | #include "mainwindowimp.h" |
2 | #include "addserviceimp.h" | 2 | #include "addconnectionimp.h" |
3 | #include "interfaceinformationimp.h" | 3 | #include "interfaceinformationimp.h" |
4 | #include "interfacesetupimp.h" | 4 | #include "interfacesetupimp.h" |
5 | #include "kprocess.h" | ||
6 | #include "module.h" | 5 | #include "module.h" |
7 | 6 | ||
7 | #include "kprocess.h" | ||
8 | 8 | ||
9 | #include <qpushbutton.h> | 9 | #include <qpushbutton.h> |
10 | #include <qtabwidget.h> | 10 | #include <qtabwidget.h> |
11 | #include <qlistbox.h> | 11 | #include <qlistbox.h> |
12 | #include <qlistview.h> | 12 | #include <qlistview.h> |
13 | #include <qheader.h> | 13 | #include <qheader.h> |
@@ -22,91 +22,87 @@ | |||
22 | 22 | ||
23 | #include <qlist.h> | 23 | #include <qlist.h> |
24 | #include <qdir.h> | 24 | #include <qdir.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #include <qtextstream.h> | 26 | #include <qtextstream.h> |
27 | 27 | ||
28 | // For library loading. | ||
29 | #include <dlfcn.h> | ||
30 | |||
31 | #define TEMP_ALL "/tmp/ifconfig-a" | 28 | #define TEMP_ALL "/tmp/ifconfig-a" |
32 | #define TEMP_UP "/tmp/ifconfig" | 29 | #define TEMP_UP "/tmp/ifconfig" |
33 | 30 | ||
34 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true) { | 31 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ |
35 | connect(addServiceButton, SIGNAL(clicked()), this, SLOT(addClicked())); | 32 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); |
36 | connect(removeServiceButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | 33 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); |
37 | connect(informationServiceButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | 34 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); |
38 | connect(configureServiceButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | 35 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); |
39 | 36 | ||
40 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); | 37 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); |
41 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); | 38 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); |
42 | connect(profilesList, SIGNAL(highlighted(const QString&)), this, SLOT(changeProfile(const QString&))); | 39 | connect(profilesList, SIGNAL(highlighted(const QString&)), this, SLOT(changeProfile(const QString&))); |
43 | 40 | ||
44 | // Make sure we have a plugin directory to scan. | 41 | // Load connections. |
45 | QString DirStr = QDir::homeDirPath() + "/.networksetup/" ; | 42 | loadModules(QDir::homeDirPath() + "/.networksetup/plugins"); |
46 | QDir pluginDir( DirStr ); | ||
47 | pluginDir.mkdir( DirStr ); | ||
48 | pluginDir.mkdir( ( DirStr + "plugins/" ) ); | ||
49 | QString path = DirStr + "plugins"; | ||
50 | pluginDir.setPath(path); | ||
51 | if(!pluginDir.exists()){ | ||
52 | qDebug(QString("MainWindowImp: ERROR: %1 %2").arg(__FILE__).arg(__LINE__).latin1()); | ||
53 | return; | ||
54 | } | ||
55 | |||
56 | // Load any saved services. | ||
57 | loadModules(path); | ||
58 | getInterfaceList(); | 43 | getInterfaceList(); |
59 | serviceList->header()->hide(); | 44 | connectionList->header()->hide(); |
60 | 45 | ||
61 | 46 | ||
62 | Config cfg("NetworkSetup"); | 47 | Config cfg("NetworkSetup"); |
63 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); | 48 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); |
64 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 49 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
65 | profilesList->insertItem((*it)); | 50 | profilesList->insertItem((*it)); |
51 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); | ||
66 | } | 52 | } |
67 | 53 | ||
68 | /** | 54 | /** |
69 | * Deconstructor. Unload libraries and save profile list. | 55 | * Deconstructor. Save profiles. Delete loaded libraries. |
70 | */ | 56 | */ |
71 | MainWindowImp::~MainWindowImp(){ | 57 | MainWindowImp::~MainWindowImp(){ |
58 | // Save profiles. | ||
72 | if(profiles.count() > 1){ | 59 | if(profiles.count() > 1){ |
73 | Config cfg("NetworkSetup"); | 60 | Config cfg("NetworkSetup"); |
74 | cfg.writeEntry("Profiles", profiles.join(" ")); | 61 | cfg.writeEntry("Profiles", profiles.join(" ")); |
75 | } | 62 | } |
63 | // Delete Modules and Libraries | ||
64 | QMap<Module*, QLibrary*>::Iterator it; | ||
65 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | ||
66 | delete it.key(); | ||
67 | delete it.data(); | ||
68 | } | ||
76 | } | 69 | } |
77 | 70 | ||
71 | /** | ||
72 | * Load all modules that are found in the path | ||
73 | * @param path a directory that is scaned for any plugins that can be loaded | ||
74 | * and attempts to load them | ||
75 | */ | ||
78 | void MainWindowImp::loadModules(QString path){ | 76 | void MainWindowImp::loadModules(QString path){ |
79 | qDebug(path.latin1()); | 77 | qDebug(path.latin1()); |
80 | QDir d; | 78 | QDir d(path); |
81 | d.setPath(path); | 79 | if(!d.exists()) |
82 | if(!d.exists()){ | ||
83 | qDebug("MainWindowImp:: Path doesn't exists"); | ||
84 | return; | 80 | return; |
85 | } | 81 | |
82 | // Don't want sym links | ||
86 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 83 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
87 | const QFileInfoList *list = d.entryInfoList(); | 84 | const QFileInfoList *list = d.entryInfoList(); |
88 | QFileInfoListIterator it( *list ); | 85 | QFileInfoListIterator it( *list ); |
89 | QFileInfo *fi; | 86 | QFileInfo *fi; |
90 | while ( (fi=it.current()) ) { | 87 | while ( (fi=it.current()) ) { |
91 | if(fi->fileName().contains(".so")){ | 88 | if(fi->fileName().contains(".so")){ |
92 | qDebug("Found"); | 89 | loadPlugin(path + "/" + fi->fileName()); |
93 | Module *foo = loadPlugin(path + "/" + fi->fileName()); | ||
94 | } | 90 | } |
95 | ++it; | 91 | ++it; |
96 | } | 92 | } |
97 | } | 93 | } |
98 | 94 | ||
99 | /** | 95 | /** |
100 | * Attempt to load a function and resolve a function. | 96 | * Attempt to load a function and resolve a function. |
101 | * @param pluginFileName - the name of the file in which to attempt to load | 97 | * @param pluginFileName - the name of the file in which to attempt to load |
102 | * @param resolveString - function pointer to resolve | 98 | * @param resolveString - function pointer to resolve |
103 | * @return pointer to the function with name resolveString or NULL | 99 | * @return pointer to the function with name resolveString or NULL |
104 | */ | 100 | */ |
105 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | 101 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ |
106 | qDebug(pluginFileName.latin1()); | 102 | qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); |
107 | QLibrary *lib = new QLibrary(pluginFileName); | 103 | QLibrary *lib = new QLibrary(pluginFileName); |
108 | void *functionPointer = lib->resolve(resolveString); | 104 | void *functionPointer = lib->resolve(resolveString); |
109 | if( !functionPointer ){ | 105 | if( !functionPointer ){ |
110 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 106 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
111 | delete lib; | 107 | delete lib; |
112 | return NULL; | 108 | return NULL; |
@@ -117,38 +113,49 @@ Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString) | |||
117 | if(object == NULL){ | 113 | if(object == NULL){ |
118 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 114 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
119 | delete lib; | 115 | delete lib; |
120 | return NULL; | 116 | return NULL; |
121 | } | 117 | } |
122 | 118 | ||
123 | // Store for reference | 119 | // Store for deletion later |
124 | libraries.insert(object, lib); | 120 | libraries.insert(object, lib); |
125 | return object; | 121 | return object; |
126 | } | 122 | } |
127 | 123 | ||
128 | /** | 124 | /** |
129 | * The Add button was clicked. Bring up the add dialog and if OK is hit | 125 | * The Add button was clicked. Bring up the add dialog and if OK is hit |
130 | * load the plugin and append it to the list | 126 | * load the plugin and append it to the list |
131 | */ | 127 | */ |
132 | void MainWindowImp::addClicked(){ | 128 | void MainWindowImp::addClicked(){ |
133 | // Now that we have a list of all of the protocals, list them. | 129 | QMap<Module*, QLibrary*>::Iterator it; |
134 | { | 130 | QMap<QString, QString> list; |
135 | QMessageBox::information(this, "No Modules", "Nothing to add.", "Ok"); | 131 | list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); |
132 | list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); | ||
133 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | ||
134 | if(it.key()) | ||
135 | (it.key())->possibleNewInterfaces(list); | ||
136 | } | ||
137 | // See if the list has anything that we can add. | ||
138 | if(list.count() == 0){ | ||
139 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); | ||
136 | return; | 140 | return; |
137 | } | 141 | } |
138 | AddServiceImp service(this, "AddService", true); | 142 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); |
139 | service.showMaximized(); | 143 | addNewConnection.addConnections(list); |
140 | service.exec(); | 144 | addNewConnection.showMaximized(); |
145 | if(QDialog::Accepted == addNewConnection.exec()){ | ||
146 | |||
147 | } | ||
141 | } | 148 | } |
142 | 149 | ||
143 | /** | 150 | /** |
144 | * Prompt the user to see if they really want to do this. | 151 | * Prompt the user to see if they really want to do this. |
145 | * If they do then remove from the list and unload. | 152 | * If they do then remove from the list and unload. |
146 | */ | 153 | */ |
147 | void MainWindowImp::removeClicked(){ | 154 | void MainWindowImp::removeClicked(){ |
148 | QListViewItem *item = serviceList->currentItem(); | 155 | QListViewItem *item = connectionList->currentItem(); |
149 | if(item == NULL) { | 156 | if(item == NULL) { |
150 | QMessageBox::information(this, "Error","Please select an interface.", "Ok"); | 157 | QMessageBox::information(this, "Error","Please select an interface.", "Ok"); |
151 | return; | 158 | return; |
152 | } | 159 | } |
153 | 160 | ||
154 | if((interfaceItems[item])->getModuleOwner() == NULL){ | 161 | if((interfaceItems[item])->getModuleOwner() == NULL){ |
@@ -158,82 +165,75 @@ void MainWindowImp::removeClicked(){ | |||
158 | // Try to remove. | 165 | // Try to remove. |
159 | } | 166 | } |
160 | 167 | ||
161 | } | 168 | } |
162 | 169 | ||
163 | /** | 170 | /** |
164 | * See if there is a configuration for the selected protocal. | 171 | * Pull up the configure about the currently selected interface. |
165 | * Prompt with errors. | 172 | * Report an error if no interface is selected. |
173 | * If the interface has a module owner then request its configure with a empty | ||
174 | * tab. If tab is !NULL then append the interfaces setup widget to it. | ||
166 | */ | 175 | */ |
167 | void MainWindowImp::configureClicked(){ | 176 | void MainWindowImp::configureClicked(){ |
168 | QListViewItem *item = serviceList->currentItem(); | 177 | QListViewItem *item = connectionList->currentItem(); |
169 | if(item == NULL){ | 178 | if(!item){ |
170 | QMessageBox::information(this, "Error","Please select an interface.", "Ok"); | 179 | QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); |
171 | return; | 180 | return; |
172 | } | 181 | } |
173 | 182 | ||
174 | if((interfaceItems[item])->getModuleOwner() == NULL){ | 183 | Interface *i = interfaceItems[item]; |
175 | InterfaceSetupImp *conf = new InterfaceSetupImp(0, "InterfaceConfiguration", interfaceItems[item]); | 184 | if(i->getModuleOwner()){ |
176 | conf->showMaximized(); | 185 | QTabWidget *tabWidget = NULL; |
177 | conf->show(); | 186 | QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget); |
178 | } | 187 | if(moduleConfigure != NULL){ |
179 | else{ | 188 | if(tabWidget != NULL){ |
180 | QTabWidget *t = NULL; | 189 | InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); |
181 | QWidget *conf = (interfaceItems[item])->getModuleOwner()->configure(&t); | 190 | tabWidget->insertTab(configure, "TCP/IP"); |
182 | if(conf != NULL){ | ||
183 | qDebug("Conf found"); | ||
184 | if(t != NULL){ | ||
185 | qDebug("Adding Interface"); | ||
186 | InterfaceSetupImp *i = new InterfaceSetupImp(t, "TCPIPInformation", interfaceItems[item], true); | ||
187 | t->insertTab(i, "TCP/IP"); | ||
188 | } | 191 | } |
189 | conf->showMaximized(); | 192 | moduleConfigure->showMaximized(); |
190 | conf->show(); | 193 | moduleConfigure->show(); |
191 | } | 194 | return; |
192 | else{ | ||
193 | InterfaceSetupImp *i = new InterfaceSetupImp(0, "TCPIPInformation", interfaceItems[item], true); | ||
194 | i->showMaximized(); | ||
195 | i->show(); | ||
196 | } | 195 | } |
197 | } | 196 | } |
197 | |||
198 | InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); | ||
199 | configure->showMaximized(); | ||
200 | configure->show(); | ||
198 | } | 201 | } |
199 | 202 | ||
200 | /** | 203 | /** |
201 | * Pull up the information about the selected interface | 204 | * Pull up the information about the currently selected interface. |
202 | * Report an error | 205 | * Report an error if no interface is selected. |
206 | * If the interface has a module owner then request its configure with a empty | ||
207 | * tab. If tab is !NULL then append the interfaces setup widget to it. | ||
203 | */ | 208 | */ |
204 | void MainWindowImp::informationClicked(){ | 209 | void MainWindowImp::informationClicked(){ |
205 | QListViewItem *item = serviceList->currentItem(); | 210 | QListViewItem *item = connectionList->currentItem(); |
206 | if(item == NULL){ | 211 | if(!item){ |
207 | QMessageBox::information(this, "Error","Please select an interface.", "Ok"); | 212 | QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); |
208 | return; | 213 | return; |
209 | } | 214 | } |
210 | 215 | ||
211 | if( (interfaceItems[item])->getModuleOwner() == NULL){ | 216 | Interface *i = interfaceItems[item]; |
212 | InterfaceInformationImp *i = new InterfaceInformationImp(0, "InterfaceInformationImp", interfaceItems[item]); | 217 | if(i->getModuleOwner()){ |
213 | i->showMaximized(); | 218 | QTabWidget *tabWidget = NULL; |
214 | i->show(); | 219 | QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget); |
215 | } | 220 | if(moduleInformation != NULL){ |
216 | else{ | 221 | if(tabWidget != NULL){ |
217 | QTabWidget *t = NULL; | 222 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); |
218 | QWidget *conf = (interfaceItems[item])->getModuleOwner()->information(&t); | 223 | tabWidget->insertTab(information, "TCP/IP"); |
219 | if(conf != NULL){ | ||
220 | if(t){ | ||
221 | qDebug("Adding Interface"); | ||
222 | InterfaceInformationImp *i = new InterfaceInformationImp(t, "TCPIPInformation", interfaceItems[item], true); | ||
223 | t->insertTab(i, "TCP/IP"); | ||
224 | } | 224 | } |
225 | conf->showMaximized(); | 225 | moduleInformation->showMaximized(); |
226 | conf->show(); | 226 | moduleInformation->show(); |
227 | return; | ||
227 | } | 228 | } |
228 | else{ | 229 | } |
229 | InterfaceInformationImp *i = new InterfaceInformationImp(0, "TCPIPInformation", interfaceItems[item], true); | 230 | |
230 | i->showMaximized(); | 231 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); |
231 | i->show(); | 232 | information->showMaximized(); |
232 | } | 233 | information->show(); |
233 | } | ||
234 | } | 234 | } |
235 | 235 | ||
236 | /** | 236 | /** |
237 | * Aquire the list of active interfaces from ifconfig | 237 | * Aquire the list of active interfaces from ifconfig |
238 | * Call ifconfig and ifconfig -a | 238 | * Call ifconfig and ifconfig -a |
239 | */ | 239 | */ |
@@ -269,12 +269,16 @@ void MainWindowImp::jobDone(KProcess *process){ | |||
269 | while ( !stream.eof() ) { | 269 | while ( !stream.eof() ) { |
270 | line = stream.readLine(); | 270 | line = stream.readLine(); |
271 | int space = line.find(" "); | 271 | int space = line.find(" "); |
272 | if(space > 1){ | 272 | if(space > 1){ |
273 | // We have found an interface | 273 | // We have found an interface |
274 | QString interfaceName = line.mid(0, space); | 274 | QString interfaceName = line.mid(0, space); |
275 | if(!advancedUserMode){ | ||
276 | if(interfaceName == "lo") | ||
277 | break; | ||
278 | } | ||
275 | Interface *i; | 279 | Interface *i; |
276 | // See if we already have it | 280 | // See if we already have it |
277 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ | 281 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ |
278 | if(fileName == TEMP_ALL) | 282 | if(fileName == TEMP_ALL) |
279 | i = new Interface(interfaceName, false); | 283 | i = new Interface(interfaceName, false); |
280 | else | 284 | else |
@@ -303,18 +307,21 @@ void MainWindowImp::jobDone(KProcess *process){ | |||
303 | } | 307 | } |
304 | } | 308 | } |
305 | file.close(); | 309 | file.close(); |
306 | QFile::remove(fileName); | 310 | QFile::remove(fileName); |
307 | } | 311 | } |
308 | 312 | ||
313 | /** | ||
314 | * | ||
315 | */ | ||
309 | void MainWindowImp::updateInterface(Interface *i){ | 316 | void MainWindowImp::updateInterface(Interface *i){ |
310 | QListViewItem *item = NULL; | 317 | QListViewItem *item = NULL; |
311 | 318 | ||
312 | // See if we already have it | 319 | // See if we already have it |
313 | if(items.find(i) == items.end()){ | 320 | if(items.find(i) == items.end()){ |
314 | item = new QListViewItem(serviceList, "", "", ""); | 321 | item = new QListViewItem(connectionList, "", "", ""); |
315 | // See if you can't find a module owner for this interface | 322 | // See if you can't find a module owner for this interface |
316 | QMap<Module*, QLibrary*>::Iterator it; | 323 | QMap<Module*, QLibrary*>::Iterator it; |
317 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 324 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
318 | if(it.key()->isOwner(i)) | 325 | if(it.key()->isOwner(i)) |
319 | i->setModuleOwner(it.key()); | 326 | i->setModuleOwner(it.key()); |
320 | } | 327 | } |