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