summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/mainwindowimp.cpp2
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp
index e895971..3715da0 100644
--- a/noncore/net/networksetup/mainwindowimp.cpp
+++ b/noncore/net/networksetup/mainwindowimp.cpp
@@ -1,427 +1,427 @@
1#include "mainwindowimp.h" 1#include "mainwindowimp.h"
2#include "addconnectionimp.h" 2#include "addconnectionimp.h"
3#include "interfaceinformationimp.h" 3#include "interfaceinformationimp.h"
4#include "interfacesetupimp.h" 4#include "interfacesetupimp.h"
5#include "module.h" 5#include "module.h"
6 6
7#include "kprocess.h" 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 <qlineedit.h> 12#include <qlineedit.h>
13#include <qlistview.h> 13#include <qlistview.h>
14#include <qheader.h> 14#include <qheader.h>
15#include <qlabel.h> 15#include <qlabel.h>
16 16
17#include <qmainwindow.h> 17#include <qmainwindow.h>
18#include <qmessagebox.h> 18#include <qmessagebox.h>
19 19
20#include <qpe/config.h> 20#include <qpe/config.h>
21#include <qpe/qlibrary.h> 21#include <qpe/qlibrary.h>
22#include <qpe/resource.h> 22#include <qpe/resource.h>
23 23
24#include <qlist.h> 24#include <qlist.h>
25#include <qdir.h> 25#include <qdir.h>
26#include <qfile.h> 26#include <qfile.h>
27#include <qtextstream.h> 27#include <qtextstream.h>
28 28
29#define TEMP_ALL "/tmp/ifconfig-a" 29#define TEMP_ALL "/tmp/ifconfig-a"
30#define TEMP_UP "/tmp/ifconfig" 30#define TEMP_UP "/tmp/ifconfig"
31 31
32MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ 32MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){
33 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 33 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
34 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 34 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
35 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 35 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
36 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 36 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
37 37
38 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); 38 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
39 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); 39 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
40 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); 40 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
41 41
42 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); 42 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
43 // Load connections. 43 // Load connections.
44 loadModules(QDir::homeDirPath() + "/.networksetup/plugins"); 44 loadModules(QPEApplication::qpeDir() + "/plugins/networksetup");
45 getInterfaceList(); 45 getInterfaceList();
46 connectionList->header()->hide(); 46 connectionList->header()->hide();
47 47
48 48
49 Config cfg("NetworkSetup"); 49 Config cfg("NetworkSetup");
50 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 50 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
51 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 51 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
52 profilesList->insertItem((*it)); 52 profilesList->insertItem((*it));
53 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 53 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
54} 54}
55 55
56/** 56/**
57 * Deconstructor. Save profiles. Delete loaded libraries. 57 * Deconstructor. Save profiles. Delete loaded libraries.
58 */ 58 */
59MainWindowImp::~MainWindowImp(){ 59MainWindowImp::~MainWindowImp(){
60 // Save profiles. 60 // Save profiles.
61 if(profiles.count() > 1){ 61 if(profiles.count() > 1){
62 Config cfg("NetworkSetup"); 62 Config cfg("NetworkSetup");
63 cfg.setGroup("General"); 63 cfg.setGroup("General");
64 cfg.writeEntry("Profiles", profiles.join(" ")); 64 cfg.writeEntry("Profiles", profiles.join(" "));
65 } 65 }
66 // Delete Modules and Libraries 66 // Delete Modules and Libraries
67 QMap<Module*, QLibrary*>::Iterator it; 67 QMap<Module*, QLibrary*>::Iterator it;
68 for( it = libraries.begin(); it != libraries.end(); ++it ){ 68 for( it = libraries.begin(); it != libraries.end(); ++it ){
69 delete it.key(); 69 delete it.key();
70 delete it.data(); 70 delete it.data();
71 } 71 }
72} 72}
73 73
74/** 74/**
75 * Load all modules that are found in the path 75 * Load all modules that are found in the path
76 * @param path a directory that is scaned for any plugins that can be loaded 76 * @param path a directory that is scaned for any plugins that can be loaded
77 * and attempts to load them 77 * and attempts to load them
78 */ 78 */
79void MainWindowImp::loadModules(QString path){ 79void MainWindowImp::loadModules(QString path){
80 qDebug(path.latin1()); 80 qDebug(path.latin1());
81 QDir d(path); 81 QDir d(path);
82 if(!d.exists()) 82 if(!d.exists())
83 return; 83 return;
84 84
85 // Don't want sym links 85 // Don't want sym links
86 d.setFilter( QDir::Files | QDir::NoSymLinks ); 86 d.setFilter( QDir::Files | QDir::NoSymLinks );
87 const QFileInfoList *list = d.entryInfoList(); 87 const QFileInfoList *list = d.entryInfoList();
88 QFileInfoListIterator it( *list ); 88 QFileInfoListIterator it( *list );
89 QFileInfo *fi; 89 QFileInfo *fi;
90 while ( (fi=it.current()) ) { 90 while ( (fi=it.current()) ) {
91 if(fi->fileName().contains(".so")){ 91 if(fi->fileName().contains(".so")){
92 loadPlugin(path + "/" + fi->fileName()); 92 loadPlugin(path + "/" + fi->fileName());
93 } 93 }
94 ++it; 94 ++it;
95 } 95 }
96} 96}
97 97
98/** 98/**
99 * Attempt to load a function and resolve a function. 99 * Attempt to load a function and resolve a function.
100 * @param pluginFileName - the name of the file in which to attempt to load 100 * @param pluginFileName - the name of the file in which to attempt to load
101 * @param resolveString - function pointer to resolve 101 * @param resolveString - function pointer to resolve
102 * @return pointer to the function with name resolveString or NULL 102 * @return pointer to the function with name resolveString or NULL
103 */ 103 */
104Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ 104Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){
105 qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); 105 qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
106 QLibrary *lib = new QLibrary(pluginFileName); 106 QLibrary *lib = new QLibrary(pluginFileName);
107 void *functionPointer = lib->resolve(resolveString); 107 void *functionPointer = lib->resolve(resolveString);
108 if( !functionPointer ){ 108 if( !functionPointer ){
109 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); 109 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
110 delete lib; 110 delete lib;
111 return NULL; 111 return NULL;
112 } 112 }
113 113
114 // Try to get an object. 114 // Try to get an object.
115 Module *object = ((Module* (*)()) functionPointer)(); 115 Module *object = ((Module* (*)()) functionPointer)();
116 if(object == NULL){ 116 if(object == NULL){
117 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 117 qDebug("MainWindowImp: Couldn't create object, but did load library!");
118 delete lib; 118 delete lib;
119 return NULL; 119 return NULL;
120 } 120 }
121 121
122 // Store for deletion later 122 // Store for deletion later
123 libraries.insert(object, lib); 123 libraries.insert(object, lib);
124 return object; 124 return object;
125} 125}
126 126
127/** 127/**
128 * The Add button was clicked. Bring up the add dialog and if OK is hit 128 * The Add button was clicked. Bring up the add dialog and if OK is hit
129 * load the plugin and append it to the list 129 * load the plugin and append it to the list
130 */ 130 */
131void MainWindowImp::addClicked(){ 131void MainWindowImp::addClicked(){
132 QMap<Module*, QLibrary*>::Iterator it; 132 QMap<Module*, QLibrary*>::Iterator it;
133 QMap<QString, QString> list; 133 QMap<QString, QString> list;
134 QMap<QString, Module*> newInterfaceOwners; 134 QMap<QString, Module*> newInterfaceOwners;
135 list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); 135 list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port");
136 list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); 136 list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port");
137 for( it = libraries.begin(); it != libraries.end(); ++it ){ 137 for( it = libraries.begin(); it != libraries.end(); ++it ){
138 if(it.key()){ 138 if(it.key()){
139 (it.key())->possibleNewInterfaces(list); 139 (it.key())->possibleNewInterfaces(list);
140 } 140 }
141 } 141 }
142 // See if the list has anything that we can add. 142 // See if the list has anything that we can add.
143 if(list.count() == 0){ 143 if(list.count() == 0){
144 QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); 144 QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok");
145 return; 145 return;
146 } 146 }
147 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 147 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
148 addNewConnection.addConnections(list); 148 addNewConnection.addConnections(list);
149 addNewConnection.showMaximized(); 149 addNewConnection.showMaximized();
150 if(QDialog::Accepted == addNewConnection.exec()){ 150 if(QDialog::Accepted == addNewConnection.exec()){
151 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 151 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
152 if(!item) 152 if(!item)
153 return; 153 return;
154 154
155 for( it = libraries.begin(); it != libraries.end(); ++it ){ 155 for( it = libraries.begin(); it != libraries.end(); ++it ){
156 if(it.key()){ 156 if(it.key()){
157 Interface *i = (it.key())->addNewInterface(item->text(0)); 157 Interface *i = (it.key())->addNewInterface(item->text(0));
158 if(i){ 158 if(i){
159 interfaceNames.insert(i->getInterfaceName(), i); 159 interfaceNames.insert(i->getInterfaceName(), i);
160 updateInterface(i); 160 updateInterface(i);
161 } 161 }
162 } 162 }
163 } 163 }
164 } 164 }
165} 165}
166 166
167/** 167/**
168 * Prompt the user to see if they really want to do this. 168 * Prompt the user to see if they really want to do this.
169 * If they do then remove from the list and unload. 169 * If they do then remove from the list and unload.
170 */ 170 */
171void MainWindowImp::removeClicked(){ 171void MainWindowImp::removeClicked(){
172 QListViewItem *item = connectionList->currentItem(); 172 QListViewItem *item = connectionList->currentItem();
173 if(!item) { 173 if(!item) {
174 QMessageBox::information(this, "Error","Please select an interface.", "Ok"); 174 QMessageBox::information(this, "Error","Please select an interface.", "Ok");
175 return; 175 return;
176 } 176 }
177 177
178 Interface *i = interfaceItems[item]; 178 Interface *i = interfaceItems[item];
179 if(i->getModuleOwner() == NULL){ 179 if(i->getModuleOwner() == NULL){
180 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); 180 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok");
181 } 181 }
182 else{ 182 else{
183 if(!i->getModuleOwner()->remove(i)) 183 if(!i->getModuleOwner()->remove(i))
184 QMessageBox::information(this, "Error", "Unable to remove.", "Ok"); 184 QMessageBox::information(this, "Error", "Unable to remove.", "Ok");
185 else{ 185 else{
186 QMessageBox::information(this, "Success", "Interface was removed.", "Ok"); 186 QMessageBox::information(this, "Success", "Interface was removed.", "Ok");
187 // TODO memory managment.... 187 // TODO memory managment....
188 // who deletes the interface? 188 // who deletes the interface?
189 } 189 }
190 } 190 }
191} 191}
192 192
193/** 193/**
194 * Pull up the configure about the currently selected interface. 194 * Pull up the configure about the currently selected interface.
195 * Report an error if no interface is selected. 195 * Report an error if no interface is selected.
196 * If the interface has a module owner then request its configure with a empty 196 * If the interface has a module owner then request its configure with a empty
197 * tab. If tab is !NULL then append the interfaces setup widget to it. 197 * tab. If tab is !NULL then append the interfaces setup widget to it.
198 */ 198 */
199void MainWindowImp::configureClicked(){ 199void MainWindowImp::configureClicked(){
200 QListViewItem *item = connectionList->currentItem(); 200 QListViewItem *item = connectionList->currentItem();
201 if(!item){ 201 if(!item){
202 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 202 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
203 return; 203 return;
204 } 204 }
205 205
206 Interface *i = interfaceItems[item]; 206 Interface *i = interfaceItems[item];
207 if(i->getModuleOwner()){ 207 if(i->getModuleOwner()){
208 QTabWidget *tabWidget = NULL; 208 QTabWidget *tabWidget = NULL;
209 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget); 209 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
210 if(moduleConfigure != NULL){ 210 if(moduleConfigure != NULL){
211 if(tabWidget != NULL){ 211 if(tabWidget != NULL){
212 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); 212 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
213 tabWidget->insertTab(configure, "TCP/IP"); 213 tabWidget->insertTab(configure, "TCP/IP");
214 } 214 }
215 moduleConfigure->showMaximized(); 215 moduleConfigure->showMaximized();
216 moduleConfigure->show(); 216 moduleConfigure->show();
217 return; 217 return;
218 } 218 }
219 } 219 }
220 220
221 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); 221 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
222 configure->showMaximized(); 222 configure->showMaximized();
223 configure->show(); 223 configure->show();
224} 224}
225 225
226/** 226/**
227 * Pull up the information about the currently selected interface. 227 * Pull up the information about the currently selected interface.
228 * Report an error if no interface is selected. 228 * Report an error if no interface is selected.
229 * If the interface has a module owner then request its configure with a empty 229 * If the interface has a module owner then request its configure with a empty
230 * tab. If tab is !NULL then append the interfaces setup widget to it. 230 * tab. If tab is !NULL then append the interfaces setup widget to it.
231 */ 231 */
232void MainWindowImp::informationClicked(){ 232void MainWindowImp::informationClicked(){
233 QListViewItem *item = connectionList->currentItem(); 233 QListViewItem *item = connectionList->currentItem();
234 if(!item){ 234 if(!item){
235 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 235 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
236 return; 236 return;
237 } 237 }
238 238
239 Interface *i = interfaceItems[item]; 239 Interface *i = interfaceItems[item];
240 if(i->getModuleOwner()){ 240 if(i->getModuleOwner()){
241 QTabWidget *tabWidget = NULL; 241 QTabWidget *tabWidget = NULL;
242 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget); 242 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget);
243 if(moduleInformation != NULL){ 243 if(moduleInformation != NULL){
244 if(tabWidget != NULL){ 244 if(tabWidget != NULL){
245 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); 245 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true);
246 tabWidget->insertTab(information, "TCP/IP"); 246 tabWidget->insertTab(information, "TCP/IP");
247 } 247 }
248 moduleInformation->showMaximized(); 248 moduleInformation->showMaximized();
249 moduleInformation->show(); 249 moduleInformation->show();
250 return; 250 return;
251 } 251 }
252 } 252 }
253 253
254 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); 254 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
255 information->showMaximized(); 255 information->showMaximized();
256 information->show(); 256 information->show();
257} 257}
258 258
259/** 259/**
260 * Aquire the list of active interfaces from ifconfig 260 * Aquire the list of active interfaces from ifconfig
261 * Call ifconfig and ifconfig -a 261 * Call ifconfig and ifconfig -a
262 */ 262 */
263void MainWindowImp::getInterfaceList(){ 263void MainWindowImp::getInterfaceList(){
264 KShellProcess *processAll = new KShellProcess(); 264 KShellProcess *processAll = new KShellProcess();
265 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; 265 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
266 connect(processAll, SIGNAL(processExited(KProcess *)), 266 connect(processAll, SIGNAL(processExited(KProcess *)),
267 this, SLOT(jobDone(KProcess *))); 267 this, SLOT(jobDone(KProcess *)));
268 threads.insert(processAll, TEMP_ALL); 268 threads.insert(processAll, TEMP_ALL);
269 processAll->start(KShellProcess::NotifyOnExit); 269 processAll->start(KShellProcess::NotifyOnExit);
270 270
271 KShellProcess *process = new KShellProcess(); 271 KShellProcess *process = new KShellProcess();
272 *process << "/sbin/ifconfig" << " > " TEMP_UP; 272 *process << "/sbin/ifconfig" << " > " TEMP_UP;
273 connect(process, SIGNAL(processExited(KProcess *)), 273 connect(process, SIGNAL(processExited(KProcess *)),
274 this, SLOT(jobDone(KProcess *))); 274 this, SLOT(jobDone(KProcess *)));
275 threads.insert(process, TEMP_UP); 275 threads.insert(process, TEMP_UP);
276 process->start(KShellProcess::NotifyOnExit); 276 process->start(KShellProcess::NotifyOnExit);
277} 277}
278 278
279void MainWindowImp::jobDone(KProcess *process){ 279void MainWindowImp::jobDone(KProcess *process){
280 QString fileName = threads[process]; 280 QString fileName = threads[process];
281 threads.remove(process); 281 threads.remove(process);
282 delete process; 282 delete process;
283 283
284 QFile file(fileName); 284 QFile file(fileName);
285 if (!file.open(IO_ReadOnly)){ 285 if (!file.open(IO_ReadOnly)){
286 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); 286 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
287 return; 287 return;
288 } 288 }
289 289
290 QTextStream stream( &file ); 290 QTextStream stream( &file );
291 QString line; 291 QString line;
292 while ( !stream.eof() ) { 292 while ( !stream.eof() ) {
293 line = stream.readLine(); 293 line = stream.readLine();
294 int space = line.find(" "); 294 int space = line.find(" ");
295 if(space > 1){ 295 if(space > 1){
296 // We have found an interface 296 // We have found an interface
297 QString interfaceName = line.mid(0, space); 297 QString interfaceName = line.mid(0, space);
298 if(!advancedUserMode){ 298 if(!advancedUserMode){
299 if(interfaceName == "lo") 299 if(interfaceName == "lo")
300 break; 300 break;
301 } 301 }
302 Interface *i; 302 Interface *i;
303 // See if we already have it 303 // See if we already have it
304 if(interfaceNames.find(interfaceName) == interfaceNames.end()){ 304 if(interfaceNames.find(interfaceName) == interfaceNames.end()){
305 if(fileName == TEMP_ALL) 305 if(fileName == TEMP_ALL)
306 i = new Interface(interfaceName, false); 306 i = new Interface(interfaceName, false);
307 else 307 else
308 i = new Interface(interfaceName, true); 308 i = new Interface(interfaceName, true);
309 } 309 }
310 else{ 310 else{
311 i = interfaceNames[interfaceName]; 311 i = interfaceNames[interfaceName];
312 if(fileName != TEMP_ALL) 312 if(fileName != TEMP_ALL)
313 i->setStatus(true); 313 i->setStatus(true);
314 } 314 }
315 315
316 i->setAttached(true); 316 i->setAttached(true);
317 i->setInterfaceName(interfaceName); 317 i->setInterfaceName(interfaceName);
318 318
319 QString hardName = "Ethernet"; 319 QString hardName = "Ethernet";
320 int hardwareName = line.find("Link encap:"); 320 int hardwareName = line.find("Link encap:");
321 int macAddress = line.find("HWaddr"); 321 int macAddress = line.find("HWaddr");
322 if(macAddress == -1) 322 if(macAddress == -1)
323 macAddress = line.length(); 323 macAddress = line.length();
324 if(hardwareName != -1) 324 if(hardwareName != -1)
325 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); 325 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName()));
326 // We have found an interface 326 // We have found an interface
327 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); 327 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
328 interfaceNames.insert(i->getInterfaceName(), i); 328 interfaceNames.insert(i->getInterfaceName(), i);
329 updateInterface(i); 329 updateInterface(i);
330 } 330 }
331 } 331 }
332 file.close(); 332 file.close();
333 QFile::remove(fileName); 333 QFile::remove(fileName);
334} 334}
335 335
336/** 336/**
337 * Update this interface. If no QListViewItem exists create one. 337 * Update this interface. If no QListViewItem exists create one.
338 * @param Interface* pointer to the interface that needs to be updated. 338 * @param Interface* pointer to the interface that needs to be updated.
339 */ 339 */
340void MainWindowImp::updateInterface(Interface *i){ 340void MainWindowImp::updateInterface(Interface *i){
341 QListViewItem *item = NULL; 341 QListViewItem *item = NULL;
342 342
343 // Find the interface, making it if needed. 343 // Find the interface, making it if needed.
344 if(items.find(i) == items.end()){ 344 if(items.find(i) == items.end()){
345 item = new QListViewItem(connectionList, "", "", ""); 345 item = new QListViewItem(connectionList, "", "", "");
346 // See if you can't find a module owner for this interface 346 // See if you can't find a module owner for this interface
347 QMap<Module*, QLibrary*>::Iterator it; 347 QMap<Module*, QLibrary*>::Iterator it;
348 for( it = libraries.begin(); it != libraries.end(); ++it ){ 348 for( it = libraries.begin(); it != libraries.end(); ++it ){
349 if(it.key()->isOwner(i)) 349 if(it.key()->isOwner(i))
350 i->setModuleOwner(it.key()); 350 i->setModuleOwner(it.key());
351 } 351 }
352 items.insert(i, item); 352 items.insert(i, item);
353 interfaceItems.insert(item, i); 353 interfaceItems.insert(item, i);
354 } 354 }
355 else 355 else
356 item = items[i]; 356 item = items[i];
357 357
358 // Update the icons and information 358 // Update the icons and information
359 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 359 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
360 360
361 QString typeName = "lan"; 361 QString typeName = "lan";
362 if(i->getHardwareName().contains("Local Loopback")) 362 if(i->getHardwareName().contains("Local Loopback"))
363 typeName = "lo"; 363 typeName = "lo";
364 if(i->getInterfaceName().contains("irda")) 364 if(i->getInterfaceName().contains("irda"))
365 typeName = "irda"; 365 typeName = "irda";
366 if(i->getInterfaceName().contains("wlan")) 366 if(i->getInterfaceName().contains("wlan"))
367 typeName = "wlan"; 367 typeName = "wlan";
368 // Actually try to use the Module 368 // Actually try to use the Module
369 if(i->getModuleOwner() != NULL) 369 if(i->getModuleOwner() != NULL)
370 typeName = i->getModuleOwner()->getPixmapName(i); 370 typeName = i->getModuleOwner()->getPixmapName(i);
371 371
372 item->setPixmap(1, (Resource::loadPixmap(typeName))); 372 item->setPixmap(1, (Resource::loadPixmap(typeName)));
373 item->setText(2, i->getHardwareName()); 373 item->setText(2, i->getHardwareName());
374 item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); 374 item->setText(3, (i->getStatus()) ? i->getIp() : QString(""));
375} 375}
376 376
377void MainWindowImp::newProfileChanged(const QString& newText){ 377void MainWindowImp::newProfileChanged(const QString& newText){
378 if(newText.length() > 0) 378 if(newText.length() > 0)
379 newProfileButton->setEnabled(true); 379 newProfileButton->setEnabled(true);
380 else 380 else
381 newProfileButton->setEnabled(false); 381 newProfileButton->setEnabled(false);
382} 382}
383 383
384/** 384/**
385 * Adds a new profile to the list of profiles. 385 * Adds a new profile to the list of profiles.
386 * Don't add profiles that already exists. 386 * Don't add profiles that already exists.
387 * Appends to the list and QStringList 387 * Appends to the list and QStringList
388 */ 388 */
389void MainWindowImp::addProfile(){ 389void MainWindowImp::addProfile(){
390 QString newProfileName = newProfile->text(); 390 QString newProfileName = newProfile->text();
391 if(profiles.grep(newProfileName).count() > 0){ 391 if(profiles.grep(newProfileName).count() > 0){
392 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); 392 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok");
393 return; 393 return;
394 } 394 }
395 profiles.append(newProfileName); 395 profiles.append(newProfileName);
396 profilesList->insertItem(newProfileName); 396 profilesList->insertItem(newProfileName);
397} 397}
398 398
399/** 399/**
400 * Removes the currently selected profile in the combo. 400 * Removes the currently selected profile in the combo.
401 * Doesn't delete if there are less then 2 profiles. 401 * Doesn't delete if there are less then 2 profiles.
402 */ 402 */
403void MainWindowImp::removeProfile(){ 403void MainWindowImp::removeProfile(){
404 if(profilesList->count() <= 1){ 404 if(profilesList->count() <= 1){
405 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); 405 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok");
406 return; 406 return;
407 } 407 }
408 QString profileToRemove = profilesList->currentText(); 408 QString profileToRemove = profilesList->currentText();
409 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 409 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
410 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 410 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
411 profilesList->clear(); 411 profilesList->clear();
412 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 412 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
413 profilesList->insertItem((*it)); 413 profilesList->insertItem((*it));
414 } 414 }
415 415
416} 416}
417 417
418/** 418/**
419 * A new profile has been selected, change. 419 * A new profile has been selected, change.
420 * @param newProfile the new profile. 420 * @param newProfile the new profile.
421 */ 421 */
422void MainWindowImp::changeProfile(){ 422void MainWindowImp::changeProfile(){
423 currentProfileLabel->setText(profilesList->text(profilesList->currentItem())); 423 currentProfileLabel->setText(profilesList->text(profilesList->currentItem()));
424} 424}
425 425
426// mainwindowimp.cpp 426// mainwindowimp.cpp
427 427
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index e895971..3715da0 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -1,427 +1,427 @@
1#include "mainwindowimp.h" 1#include "mainwindowimp.h"
2#include "addconnectionimp.h" 2#include "addconnectionimp.h"
3#include "interfaceinformationimp.h" 3#include "interfaceinformationimp.h"
4#include "interfacesetupimp.h" 4#include "interfacesetupimp.h"
5#include "module.h" 5#include "module.h"
6 6
7#include "kprocess.h" 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 <qlineedit.h> 12#include <qlineedit.h>
13#include <qlistview.h> 13#include <qlistview.h>
14#include <qheader.h> 14#include <qheader.h>
15#include <qlabel.h> 15#include <qlabel.h>
16 16
17#include <qmainwindow.h> 17#include <qmainwindow.h>
18#include <qmessagebox.h> 18#include <qmessagebox.h>
19 19
20#include <qpe/config.h> 20#include <qpe/config.h>
21#include <qpe/qlibrary.h> 21#include <qpe/qlibrary.h>
22#include <qpe/resource.h> 22#include <qpe/resource.h>
23 23
24#include <qlist.h> 24#include <qlist.h>
25#include <qdir.h> 25#include <qdir.h>
26#include <qfile.h> 26#include <qfile.h>
27#include <qtextstream.h> 27#include <qtextstream.h>
28 28
29#define TEMP_ALL "/tmp/ifconfig-a" 29#define TEMP_ALL "/tmp/ifconfig-a"
30#define TEMP_UP "/tmp/ifconfig" 30#define TEMP_UP "/tmp/ifconfig"
31 31
32MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ 32MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){
33 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 33 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
34 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 34 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
35 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 35 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
36 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 36 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
37 37
38 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); 38 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
39 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); 39 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
40 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); 40 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
41 41
42 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); 42 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
43 // Load connections. 43 // Load connections.
44 loadModules(QDir::homeDirPath() + "/.networksetup/plugins"); 44 loadModules(QPEApplication::qpeDir() + "/plugins/networksetup");
45 getInterfaceList(); 45 getInterfaceList();
46 connectionList->header()->hide(); 46 connectionList->header()->hide();
47 47
48 48
49 Config cfg("NetworkSetup"); 49 Config cfg("NetworkSetup");
50 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 50 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
51 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 51 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
52 profilesList->insertItem((*it)); 52 profilesList->insertItem((*it));
53 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 53 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
54} 54}
55 55
56/** 56/**
57 * Deconstructor. Save profiles. Delete loaded libraries. 57 * Deconstructor. Save profiles. Delete loaded libraries.
58 */ 58 */
59MainWindowImp::~MainWindowImp(){ 59MainWindowImp::~MainWindowImp(){
60 // Save profiles. 60 // Save profiles.
61 if(profiles.count() > 1){ 61 if(profiles.count() > 1){
62 Config cfg("NetworkSetup"); 62 Config cfg("NetworkSetup");
63 cfg.setGroup("General"); 63 cfg.setGroup("General");
64 cfg.writeEntry("Profiles", profiles.join(" ")); 64 cfg.writeEntry("Profiles", profiles.join(" "));
65 } 65 }
66 // Delete Modules and Libraries 66 // Delete Modules and Libraries
67 QMap<Module*, QLibrary*>::Iterator it; 67 QMap<Module*, QLibrary*>::Iterator it;
68 for( it = libraries.begin(); it != libraries.end(); ++it ){ 68 for( it = libraries.begin(); it != libraries.end(); ++it ){
69 delete it.key(); 69 delete it.key();
70 delete it.data(); 70 delete it.data();
71 } 71 }
72} 72}
73 73
74/** 74/**
75 * Load all modules that are found in the path 75 * Load all modules that are found in the path
76 * @param path a directory that is scaned for any plugins that can be loaded 76 * @param path a directory that is scaned for any plugins that can be loaded
77 * and attempts to load them 77 * and attempts to load them
78 */ 78 */
79void MainWindowImp::loadModules(QString path){ 79void MainWindowImp::loadModules(QString path){
80 qDebug(path.latin1()); 80 qDebug(path.latin1());
81 QDir d(path); 81 QDir d(path);
82 if(!d.exists()) 82 if(!d.exists())
83 return; 83 return;
84 84
85 // Don't want sym links 85 // Don't want sym links
86 d.setFilter( QDir::Files | QDir::NoSymLinks ); 86 d.setFilter( QDir::Files | QDir::NoSymLinks );
87 const QFileInfoList *list = d.entryInfoList(); 87 const QFileInfoList *list = d.entryInfoList();
88 QFileInfoListIterator it( *list ); 88 QFileInfoListIterator it( *list );
89 QFileInfo *fi; 89 QFileInfo *fi;
90 while ( (fi=it.current()) ) { 90 while ( (fi=it.current()) ) {
91 if(fi->fileName().contains(".so")){ 91 if(fi->fileName().contains(".so")){
92 loadPlugin(path + "/" + fi->fileName()); 92 loadPlugin(path + "/" + fi->fileName());
93 } 93 }
94 ++it; 94 ++it;
95 } 95 }
96} 96}
97 97
98/** 98/**
99 * Attempt to load a function and resolve a function. 99 * Attempt to load a function and resolve a function.
100 * @param pluginFileName - the name of the file in which to attempt to load 100 * @param pluginFileName - the name of the file in which to attempt to load
101 * @param resolveString - function pointer to resolve 101 * @param resolveString - function pointer to resolve
102 * @return pointer to the function with name resolveString or NULL 102 * @return pointer to the function with name resolveString or NULL
103 */ 103 */
104Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ 104Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){
105 qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); 105 qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1());
106 QLibrary *lib = new QLibrary(pluginFileName); 106 QLibrary *lib = new QLibrary(pluginFileName);
107 void *functionPointer = lib->resolve(resolveString); 107 void *functionPointer = lib->resolve(resolveString);
108 if( !functionPointer ){ 108 if( !functionPointer ){
109 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); 109 qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
110 delete lib; 110 delete lib;
111 return NULL; 111 return NULL;
112 } 112 }
113 113
114 // Try to get an object. 114 // Try to get an object.
115 Module *object = ((Module* (*)()) functionPointer)(); 115 Module *object = ((Module* (*)()) functionPointer)();
116 if(object == NULL){ 116 if(object == NULL){
117 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 117 qDebug("MainWindowImp: Couldn't create object, but did load library!");
118 delete lib; 118 delete lib;
119 return NULL; 119 return NULL;
120 } 120 }
121 121
122 // Store for deletion later 122 // Store for deletion later
123 libraries.insert(object, lib); 123 libraries.insert(object, lib);
124 return object; 124 return object;
125} 125}
126 126
127/** 127/**
128 * The Add button was clicked. Bring up the add dialog and if OK is hit 128 * The Add button was clicked. Bring up the add dialog and if OK is hit
129 * load the plugin and append it to the list 129 * load the plugin and append it to the list
130 */ 130 */
131void MainWindowImp::addClicked(){ 131void MainWindowImp::addClicked(){
132 QMap<Module*, QLibrary*>::Iterator it; 132 QMap<Module*, QLibrary*>::Iterator it;
133 QMap<QString, QString> list; 133 QMap<QString, QString> list;
134 QMap<QString, Module*> newInterfaceOwners; 134 QMap<QString, Module*> newInterfaceOwners;
135 list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); 135 list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port");
136 list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); 136 list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port");
137 for( it = libraries.begin(); it != libraries.end(); ++it ){ 137 for( it = libraries.begin(); it != libraries.end(); ++it ){
138 if(it.key()){ 138 if(it.key()){
139 (it.key())->possibleNewInterfaces(list); 139 (it.key())->possibleNewInterfaces(list);
140 } 140 }
141 } 141 }
142 // See if the list has anything that we can add. 142 // See if the list has anything that we can add.
143 if(list.count() == 0){ 143 if(list.count() == 0){
144 QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); 144 QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok");
145 return; 145 return;
146 } 146 }
147 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 147 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
148 addNewConnection.addConnections(list); 148 addNewConnection.addConnections(list);
149 addNewConnection.showMaximized(); 149 addNewConnection.showMaximized();
150 if(QDialog::Accepted == addNewConnection.exec()){ 150 if(QDialog::Accepted == addNewConnection.exec()){
151 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 151 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
152 if(!item) 152 if(!item)
153 return; 153 return;
154 154
155 for( it = libraries.begin(); it != libraries.end(); ++it ){ 155 for( it = libraries.begin(); it != libraries.end(); ++it ){
156 if(it.key()){ 156 if(it.key()){
157 Interface *i = (it.key())->addNewInterface(item->text(0)); 157 Interface *i = (it.key())->addNewInterface(item->text(0));
158 if(i){ 158 if(i){
159 interfaceNames.insert(i->getInterfaceName(), i); 159 interfaceNames.insert(i->getInterfaceName(), i);
160 updateInterface(i); 160 updateInterface(i);
161 } 161 }
162 } 162 }
163 } 163 }
164 } 164 }
165} 165}
166 166
167/** 167/**
168 * Prompt the user to see if they really want to do this. 168 * Prompt the user to see if they really want to do this.
169 * If they do then remove from the list and unload. 169 * If they do then remove from the list and unload.
170 */ 170 */
171void MainWindowImp::removeClicked(){ 171void MainWindowImp::removeClicked(){
172 QListViewItem *item = connectionList->currentItem(); 172 QListViewItem *item = connectionList->currentItem();
173 if(!item) { 173 if(!item) {
174 QMessageBox::information(this, "Error","Please select an interface.", "Ok"); 174 QMessageBox::information(this, "Error","Please select an interface.", "Ok");
175 return; 175 return;
176 } 176 }
177 177
178 Interface *i = interfaceItems[item]; 178 Interface *i = interfaceItems[item];
179 if(i->getModuleOwner() == NULL){ 179 if(i->getModuleOwner() == NULL){
180 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); 180 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok");
181 } 181 }
182 else{ 182 else{
183 if(!i->getModuleOwner()->remove(i)) 183 if(!i->getModuleOwner()->remove(i))
184 QMessageBox::information(this, "Error", "Unable to remove.", "Ok"); 184 QMessageBox::information(this, "Error", "Unable to remove.", "Ok");
185 else{ 185 else{
186 QMessageBox::information(this, "Success", "Interface was removed.", "Ok"); 186 QMessageBox::information(this, "Success", "Interface was removed.", "Ok");
187 // TODO memory managment.... 187 // TODO memory managment....
188 // who deletes the interface? 188 // who deletes the interface?
189 } 189 }
190 } 190 }
191} 191}
192 192
193/** 193/**
194 * Pull up the configure about the currently selected interface. 194 * Pull up the configure about the currently selected interface.
195 * Report an error if no interface is selected. 195 * Report an error if no interface is selected.
196 * If the interface has a module owner then request its configure with a empty 196 * If the interface has a module owner then request its configure with a empty
197 * tab. If tab is !NULL then append the interfaces setup widget to it. 197 * tab. If tab is !NULL then append the interfaces setup widget to it.
198 */ 198 */
199void MainWindowImp::configureClicked(){ 199void MainWindowImp::configureClicked(){
200 QListViewItem *item = connectionList->currentItem(); 200 QListViewItem *item = connectionList->currentItem();
201 if(!item){ 201 if(!item){
202 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 202 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
203 return; 203 return;
204 } 204 }
205 205
206 Interface *i = interfaceItems[item]; 206 Interface *i = interfaceItems[item];
207 if(i->getModuleOwner()){ 207 if(i->getModuleOwner()){
208 QTabWidget *tabWidget = NULL; 208 QTabWidget *tabWidget = NULL;
209 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget); 209 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
210 if(moduleConfigure != NULL){ 210 if(moduleConfigure != NULL){
211 if(tabWidget != NULL){ 211 if(tabWidget != NULL){
212 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); 212 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
213 tabWidget->insertTab(configure, "TCP/IP"); 213 tabWidget->insertTab(configure, "TCP/IP");
214 } 214 }
215 moduleConfigure->showMaximized(); 215 moduleConfigure->showMaximized();
216 moduleConfigure->show(); 216 moduleConfigure->show();
217 return; 217 return;
218 } 218 }
219 } 219 }
220 220
221 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); 221 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
222 configure->showMaximized(); 222 configure->showMaximized();
223 configure->show(); 223 configure->show();
224} 224}
225 225
226/** 226/**
227 * Pull up the information about the currently selected interface. 227 * Pull up the information about the currently selected interface.
228 * Report an error if no interface is selected. 228 * Report an error if no interface is selected.
229 * If the interface has a module owner then request its configure with a empty 229 * If the interface has a module owner then request its configure with a empty
230 * tab. If tab is !NULL then append the interfaces setup widget to it. 230 * tab. If tab is !NULL then append the interfaces setup widget to it.
231 */ 231 */
232void MainWindowImp::informationClicked(){ 232void MainWindowImp::informationClicked(){
233 QListViewItem *item = connectionList->currentItem(); 233 QListViewItem *item = connectionList->currentItem();
234 if(!item){ 234 if(!item){
235 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 235 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
236 return; 236 return;
237 } 237 }
238 238
239 Interface *i = interfaceItems[item]; 239 Interface *i = interfaceItems[item];
240 if(i->getModuleOwner()){ 240 if(i->getModuleOwner()){
241 QTabWidget *tabWidget = NULL; 241 QTabWidget *tabWidget = NULL;
242 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget); 242 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget);
243 if(moduleInformation != NULL){ 243 if(moduleInformation != NULL){
244 if(tabWidget != NULL){ 244 if(tabWidget != NULL){
245 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); 245 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true);
246 tabWidget->insertTab(information, "TCP/IP"); 246 tabWidget->insertTab(information, "TCP/IP");
247 } 247 }
248 moduleInformation->showMaximized(); 248 moduleInformation->showMaximized();
249 moduleInformation->show(); 249 moduleInformation->show();
250 return; 250 return;
251 } 251 }
252 } 252 }
253 253
254 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); 254 InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
255 information->showMaximized(); 255 information->showMaximized();
256 information->show(); 256 information->show();
257} 257}
258 258
259/** 259/**
260 * Aquire the list of active interfaces from ifconfig 260 * Aquire the list of active interfaces from ifconfig
261 * Call ifconfig and ifconfig -a 261 * Call ifconfig and ifconfig -a
262 */ 262 */
263void MainWindowImp::getInterfaceList(){ 263void MainWindowImp::getInterfaceList(){
264 KShellProcess *processAll = new KShellProcess(); 264 KShellProcess *processAll = new KShellProcess();
265 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; 265 *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
266 connect(processAll, SIGNAL(processExited(KProcess *)), 266 connect(processAll, SIGNAL(processExited(KProcess *)),
267 this, SLOT(jobDone(KProcess *))); 267 this, SLOT(jobDone(KProcess *)));
268 threads.insert(processAll, TEMP_ALL); 268 threads.insert(processAll, TEMP_ALL);
269 processAll->start(KShellProcess::NotifyOnExit); 269 processAll->start(KShellProcess::NotifyOnExit);
270 270
271 KShellProcess *process = new KShellProcess(); 271 KShellProcess *process = new KShellProcess();
272 *process << "/sbin/ifconfig" << " > " TEMP_UP; 272 *process << "/sbin/ifconfig" << " > " TEMP_UP;
273 connect(process, SIGNAL(processExited(KProcess *)), 273 connect(process, SIGNAL(processExited(KProcess *)),
274 this, SLOT(jobDone(KProcess *))); 274 this, SLOT(jobDone(KProcess *)));
275 threads.insert(process, TEMP_UP); 275 threads.insert(process, TEMP_UP);
276 process->start(KShellProcess::NotifyOnExit); 276 process->start(KShellProcess::NotifyOnExit);
277} 277}
278 278
279void MainWindowImp::jobDone(KProcess *process){ 279void MainWindowImp::jobDone(KProcess *process){
280 QString fileName = threads[process]; 280 QString fileName = threads[process];
281 threads.remove(process); 281 threads.remove(process);
282 delete process; 282 delete process;
283 283
284 QFile file(fileName); 284 QFile file(fileName);
285 if (!file.open(IO_ReadOnly)){ 285 if (!file.open(IO_ReadOnly)){
286 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); 286 qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
287 return; 287 return;
288 } 288 }
289 289
290 QTextStream stream( &file ); 290 QTextStream stream( &file );
291 QString line; 291 QString line;
292 while ( !stream.eof() ) { 292 while ( !stream.eof() ) {
293 line = stream.readLine(); 293 line = stream.readLine();
294 int space = line.find(" "); 294 int space = line.find(" ");
295 if(space > 1){ 295 if(space > 1){
296 // We have found an interface 296 // We have found an interface
297 QString interfaceName = line.mid(0, space); 297 QString interfaceName = line.mid(0, space);
298 if(!advancedUserMode){ 298 if(!advancedUserMode){
299 if(interfaceName == "lo") 299 if(interfaceName == "lo")
300 break; 300 break;
301 } 301 }
302 Interface *i; 302 Interface *i;
303 // See if we already have it 303 // See if we already have it
304 if(interfaceNames.find(interfaceName) == interfaceNames.end()){ 304 if(interfaceNames.find(interfaceName) == interfaceNames.end()){
305 if(fileName == TEMP_ALL) 305 if(fileName == TEMP_ALL)
306 i = new Interface(interfaceName, false); 306 i = new Interface(interfaceName, false);
307 else 307 else
308 i = new Interface(interfaceName, true); 308 i = new Interface(interfaceName, true);
309 } 309 }
310 else{ 310 else{
311 i = interfaceNames[interfaceName]; 311 i = interfaceNames[interfaceName];
312 if(fileName != TEMP_ALL) 312 if(fileName != TEMP_ALL)
313 i->setStatus(true); 313 i->setStatus(true);
314 } 314 }
315 315
316 i->setAttached(true); 316 i->setAttached(true);
317 i->setInterfaceName(interfaceName); 317 i->setInterfaceName(interfaceName);
318 318
319 QString hardName = "Ethernet"; 319 QString hardName = "Ethernet";
320 int hardwareName = line.find("Link encap:"); 320 int hardwareName = line.find("Link encap:");
321 int macAddress = line.find("HWaddr"); 321 int macAddress = line.find("HWaddr");
322 if(macAddress == -1) 322 if(macAddress == -1)
323 macAddress = line.length(); 323 macAddress = line.length();
324 if(hardwareName != -1) 324 if(hardwareName != -1)
325 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); 325 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName()));
326 // We have found an interface 326 // We have found an interface
327 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); 327 //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
328 interfaceNames.insert(i->getInterfaceName(), i); 328 interfaceNames.insert(i->getInterfaceName(), i);
329 updateInterface(i); 329 updateInterface(i);
330 } 330 }
331 } 331 }
332 file.close(); 332 file.close();
333 QFile::remove(fileName); 333 QFile::remove(fileName);
334} 334}
335 335
336/** 336/**
337 * Update this interface. If no QListViewItem exists create one. 337 * Update this interface. If no QListViewItem exists create one.
338 * @param Interface* pointer to the interface that needs to be updated. 338 * @param Interface* pointer to the interface that needs to be updated.
339 */ 339 */
340void MainWindowImp::updateInterface(Interface *i){ 340void MainWindowImp::updateInterface(Interface *i){
341 QListViewItem *item = NULL; 341 QListViewItem *item = NULL;
342 342
343 // Find the interface, making it if needed. 343 // Find the interface, making it if needed.
344 if(items.find(i) == items.end()){ 344 if(items.find(i) == items.end()){
345 item = new QListViewItem(connectionList, "", "", ""); 345 item = new QListViewItem(connectionList, "", "", "");
346 // See if you can't find a module owner for this interface 346 // See if you can't find a module owner for this interface
347 QMap<Module*, QLibrary*>::Iterator it; 347 QMap<Module*, QLibrary*>::Iterator it;
348 for( it = libraries.begin(); it != libraries.end(); ++it ){ 348 for( it = libraries.begin(); it != libraries.end(); ++it ){
349 if(it.key()->isOwner(i)) 349 if(it.key()->isOwner(i))
350 i->setModuleOwner(it.key()); 350 i->setModuleOwner(it.key());
351 } 351 }
352 items.insert(i, item); 352 items.insert(i, item);
353 interfaceItems.insert(item, i); 353 interfaceItems.insert(item, i);
354 } 354 }
355 else 355 else
356 item = items[i]; 356 item = items[i];
357 357
358 // Update the icons and information 358 // Update the icons and information
359 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 359 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
360 360
361 QString typeName = "lan"; 361 QString typeName = "lan";
362 if(i->getHardwareName().contains("Local Loopback")) 362 if(i->getHardwareName().contains("Local Loopback"))
363 typeName = "lo"; 363 typeName = "lo";
364 if(i->getInterfaceName().contains("irda")) 364 if(i->getInterfaceName().contains("irda"))
365 typeName = "irda"; 365 typeName = "irda";
366 if(i->getInterfaceName().contains("wlan")) 366 if(i->getInterfaceName().contains("wlan"))
367 typeName = "wlan"; 367 typeName = "wlan";
368 // Actually try to use the Module 368 // Actually try to use the Module
369 if(i->getModuleOwner() != NULL) 369 if(i->getModuleOwner() != NULL)
370 typeName = i->getModuleOwner()->getPixmapName(i); 370 typeName = i->getModuleOwner()->getPixmapName(i);
371 371
372 item->setPixmap(1, (Resource::loadPixmap(typeName))); 372 item->setPixmap(1, (Resource::loadPixmap(typeName)));
373 item->setText(2, i->getHardwareName()); 373 item->setText(2, i->getHardwareName());
374 item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); 374 item->setText(3, (i->getStatus()) ? i->getIp() : QString(""));
375} 375}
376 376
377void MainWindowImp::newProfileChanged(const QString& newText){ 377void MainWindowImp::newProfileChanged(const QString& newText){
378 if(newText.length() > 0) 378 if(newText.length() > 0)
379 newProfileButton->setEnabled(true); 379 newProfileButton->setEnabled(true);
380 else 380 else
381 newProfileButton->setEnabled(false); 381 newProfileButton->setEnabled(false);
382} 382}
383 383
384/** 384/**
385 * Adds a new profile to the list of profiles. 385 * Adds a new profile to the list of profiles.
386 * Don't add profiles that already exists. 386 * Don't add profiles that already exists.
387 * Appends to the list and QStringList 387 * Appends to the list and QStringList
388 */ 388 */
389void MainWindowImp::addProfile(){ 389void MainWindowImp::addProfile(){
390 QString newProfileName = newProfile->text(); 390 QString newProfileName = newProfile->text();
391 if(profiles.grep(newProfileName).count() > 0){ 391 if(profiles.grep(newProfileName).count() > 0){
392 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); 392 QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok");
393 return; 393 return;
394 } 394 }
395 profiles.append(newProfileName); 395 profiles.append(newProfileName);
396 profilesList->insertItem(newProfileName); 396 profilesList->insertItem(newProfileName);
397} 397}
398 398
399/** 399/**
400 * Removes the currently selected profile in the combo. 400 * Removes the currently selected profile in the combo.
401 * Doesn't delete if there are less then 2 profiles. 401 * Doesn't delete if there are less then 2 profiles.
402 */ 402 */
403void MainWindowImp::removeProfile(){ 403void MainWindowImp::removeProfile(){
404 if(profilesList->count() <= 1){ 404 if(profilesList->count() <= 1){
405 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); 405 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok");
406 return; 406 return;
407 } 407 }
408 QString profileToRemove = profilesList->currentText(); 408 QString profileToRemove = profilesList->currentText();
409 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 409 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
410 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 410 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
411 profilesList->clear(); 411 profilesList->clear();
412 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 412 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
413 profilesList->insertItem((*it)); 413 profilesList->insertItem((*it));
414 } 414 }
415 415
416} 416}
417 417
418/** 418/**
419 * A new profile has been selected, change. 419 * A new profile has been selected, change.
420 * @param newProfile the new profile. 420 * @param newProfile the new profile.
421 */ 421 */
422void MainWindowImp::changeProfile(){ 422void MainWindowImp::changeProfile(){
423 currentProfileLabel->setText(profilesList->text(profilesList->currentItem())); 423 currentProfileLabel->setText(profilesList->text(profilesList->currentItem()));
424} 424}
425 425
426// mainwindowimp.cpp 426// mainwindowimp.cpp
427 427