-rw-r--r-- | noncore/net/networksetup/mainwindowimp.cpp | 7 | ||||
-rw-r--r-- | noncore/net/networksetup/wlan/wlanmodule.cpp | 5 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 7 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanmodule.cpp | 5 |
4 files changed, 18 insertions, 6 deletions
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp index 843f630..9d81ab1 100644 --- a/noncore/net/networksetup/mainwindowimp.cpp +++ b/noncore/net/networksetup/mainwindowimp.cpp | |||
@@ -1,469 +1,476 @@ | |||
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 "interfaces.h" | 5 | #include "interfaces.h" |
6 | 6 | ||
7 | #include "module.h" | 7 | #include "module.h" |
8 | 8 | ||
9 | #include "kprocess.h" | 9 | #include "kprocess.h" |
10 | 10 | ||
11 | #include <qpushbutton.h> | 11 | #include <qpushbutton.h> |
12 | #include <qtabwidget.h> | 12 | #include <qtabwidget.h> |
13 | #include <qlistbox.h> | 13 | #include <qlistbox.h> |
14 | #include <qlineedit.h> | 14 | #include <qlineedit.h> |
15 | #include <qlistview.h> | 15 | #include <qlistview.h> |
16 | #include <qheader.h> | 16 | #include <qheader.h> |
17 | #include <qlabel.h> | 17 | #include <qlabel.h> |
18 | 18 | ||
19 | #include <qmainwindow.h> | 19 | #include <qmainwindow.h> |
20 | #include <qmessagebox.h> | 20 | #include <qmessagebox.h> |
21 | 21 | ||
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | #include <qpe/qlibrary.h> | 23 | #include <qpe/qlibrary.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | 26 | ||
27 | #include <qlist.h> | 27 | #include <qlist.h> |
28 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | 31 | ||
32 | #define TEMP_ALL "/tmp/ifconfig-a" | 32 | #define TEMP_ALL "/tmp/ifconfig-a" |
33 | #define TEMP_UP "/tmp/ifconfig" | 33 | #define TEMP_UP "/tmp/ifconfig" |
34 | 34 | ||
35 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" | 35 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" |
36 | 36 | ||
37 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ | 37 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ |
38 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); | 38 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); |
39 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | 39 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); |
40 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | 40 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); |
41 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | 41 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); |
42 | 42 | ||
43 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); | 43 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); |
44 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); | 44 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); |
45 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); | 45 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); |
46 | 46 | ||
47 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); | 47 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); |
48 | // Load connections. | 48 | // Load connections. |
49 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); | 49 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); |
50 | getInterfaceList(); | 50 | getInterfaceList(); |
51 | connectionList->header()->hide(); | 51 | connectionList->header()->hide(); |
52 | 52 | ||
53 | 53 | ||
54 | Config cfg("NetworkSetup"); | 54 | Config cfg("NetworkSetup"); |
55 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); | 55 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); |
56 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 56 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
57 | profilesList->insertItem((*it)); | 57 | profilesList->insertItem((*it)); |
58 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); | 58 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); |
59 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); | 59 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); |
60 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); | 60 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); |
61 | 61 | ||
62 | QFile file(scheme); | 62 | QFile file(scheme); |
63 | if ( file.open(IO_ReadOnly) ) { // file opened successfully | 63 | if ( file.open(IO_ReadOnly) ) { // file opened successfully |
64 | QTextStream stream( &file ); // use a text stream | 64 | QTextStream stream( &file ); // use a text stream |
65 | while ( !stream.eof() ) { // until end of file... | 65 | while ( !stream.eof() ) { // until end of file... |
66 | QString line = stream.readLine(); // line of text excluding '\n' | 66 | QString line = stream.readLine(); // line of text excluding '\n' |
67 | if(line.contains("SCHEME")){ | 67 | if(line.contains("SCHEME")){ |
68 | line = line.mid(7, line.length()); | 68 | line = line.mid(7, line.length()); |
69 | currentProfileLabel->setText(line); | 69 | currentProfileLabel->setText(line); |
70 | break; | 70 | break; |
71 | } | 71 | } |
72 | } | 72 | } |
73 | file.close(); | 73 | file.close(); |
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Deconstructor. Save profiles. Delete loaded libraries. | 78 | * Deconstructor. Save profiles. Delete loaded libraries. |
79 | */ | 79 | */ |
80 | MainWindowImp::~MainWindowImp(){ | 80 | MainWindowImp::~MainWindowImp(){ |
81 | // Save profiles. | 81 | // Save profiles. |
82 | Config cfg("NetworkSetup"); | 82 | Config cfg("NetworkSetup"); |
83 | cfg.setGroup("General"); | 83 | cfg.setGroup("General"); |
84 | cfg.writeEntry("Profiles", profiles.join(" ")); | 84 | cfg.writeEntry("Profiles", profiles.join(" ")); |
85 | 85 | ||
86 | // Delete all interfaces that don't have owners. | ||
87 | QMap<Interface*, QListViewItem*>::Iterator iIt; | ||
88 | for( iIt = items.begin(); iIt != items.end(); ++iIt ){ | ||
89 | if(iIt.key()->getModuleOwner() == NULL) | ||
90 | delete iIt.key(); | ||
91 | } | ||
92 | |||
86 | // Delete Modules and Libraries | 93 | // Delete Modules and Libraries |
87 | QMap<Module*, QLibrary*>::Iterator it; | 94 | QMap<Module*, QLibrary*>::Iterator it; |
88 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 95 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
89 | delete it.key(); | 96 | delete it.key(); |
90 | delete it.data(); | 97 | delete it.data(); |
91 | } | 98 | } |
92 | } | 99 | } |
93 | 100 | ||
94 | /** | 101 | /** |
95 | * Load all modules that are found in the path | 102 | * Load all modules that are found in the path |
96 | * @param path a directory that is scaned for any plugins that can be loaded | 103 | * @param path a directory that is scaned for any plugins that can be loaded |
97 | * and attempts to load them | 104 | * and attempts to load them |
98 | */ | 105 | */ |
99 | void MainWindowImp::loadModules(QString path){ | 106 | void MainWindowImp::loadModules(QString path){ |
100 | //qDebug(path.latin1()); | 107 | //qDebug(path.latin1()); |
101 | QDir d(path); | 108 | QDir d(path); |
102 | if(!d.exists()) | 109 | if(!d.exists()) |
103 | return; | 110 | return; |
104 | 111 | ||
105 | // Don't want sym links | 112 | // Don't want sym links |
106 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 113 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
107 | const QFileInfoList *list = d.entryInfoList(); | 114 | const QFileInfoList *list = d.entryInfoList(); |
108 | QFileInfoListIterator it( *list ); | 115 | QFileInfoListIterator it( *list ); |
109 | QFileInfo *fi; | 116 | QFileInfo *fi; |
110 | while ( (fi=it.current()) ) { | 117 | while ( (fi=it.current()) ) { |
111 | if(fi->fileName().contains(".so")){ | 118 | if(fi->fileName().contains(".so")){ |
112 | loadPlugin(path + "/" + fi->fileName()); | 119 | loadPlugin(path + "/" + fi->fileName()); |
113 | } | 120 | } |
114 | ++it; | 121 | ++it; |
115 | } | 122 | } |
116 | } | 123 | } |
117 | 124 | ||
118 | /** | 125 | /** |
119 | * Attempt to load a function and resolve a function. | 126 | * Attempt to load a function and resolve a function. |
120 | * @param pluginFileName - the name of the file in which to attempt to load | 127 | * @param pluginFileName - the name of the file in which to attempt to load |
121 | * @param resolveString - function pointer to resolve | 128 | * @param resolveString - function pointer to resolve |
122 | * @return pointer to the function with name resolveString or NULL | 129 | * @return pointer to the function with name resolveString or NULL |
123 | */ | 130 | */ |
124 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | 131 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ |
125 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); | 132 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); |
126 | QLibrary *lib = new QLibrary(pluginFileName); | 133 | QLibrary *lib = new QLibrary(pluginFileName); |
127 | void *functionPointer = lib->resolve(resolveString); | 134 | void *functionPointer = lib->resolve(resolveString); |
128 | if( !functionPointer ){ | 135 | if( !functionPointer ){ |
129 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 136 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
130 | delete lib; | 137 | delete lib; |
131 | return NULL; | 138 | return NULL; |
132 | } | 139 | } |
133 | 140 | ||
134 | // Try to get an object. | 141 | // Try to get an object. |
135 | Module *object = ((Module* (*)()) functionPointer)(); | 142 | Module *object = ((Module* (*)()) functionPointer)(); |
136 | if(object == NULL){ | 143 | if(object == NULL){ |
137 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 144 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
138 | delete lib; | 145 | delete lib; |
139 | return NULL; | 146 | return NULL; |
140 | } | 147 | } |
141 | 148 | ||
142 | // Store for deletion later | 149 | // Store for deletion later |
143 | libraries.insert(object, lib); | 150 | libraries.insert(object, lib); |
144 | return object; | 151 | return object; |
145 | } | 152 | } |
146 | 153 | ||
147 | /** | 154 | /** |
148 | * The Add button was clicked. Bring up the add dialog and if OK is hit | 155 | * The Add button was clicked. Bring up the add dialog and if OK is hit |
149 | * load the plugin and append it to the list | 156 | * load the plugin and append it to the list |
150 | */ | 157 | */ |
151 | void MainWindowImp::addClicked(){ | 158 | void MainWindowImp::addClicked(){ |
152 | QMap<Module*, QLibrary*>::Iterator it; | 159 | QMap<Module*, QLibrary*>::Iterator it; |
153 | QMap<QString, QString> list; | 160 | QMap<QString, QString> list; |
154 | QMap<QString, Module*> newInterfaceOwners; | 161 | QMap<QString, Module*> newInterfaceOwners; |
155 | list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); | 162 | list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); |
156 | list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); | 163 | list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); |
157 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 164 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
158 | if(it.key()){ | 165 | if(it.key()){ |
159 | (it.key())->possibleNewInterfaces(list); | 166 | (it.key())->possibleNewInterfaces(list); |
160 | } | 167 | } |
161 | } | 168 | } |
162 | // See if the list has anything that we can add. | 169 | // See if the list has anything that we can add. |
163 | if(list.count() == 0){ | 170 | if(list.count() == 0){ |
164 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); | 171 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); |
165 | return; | 172 | return; |
166 | } | 173 | } |
167 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); | 174 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); |
168 | addNewConnection.addConnections(list); | 175 | addNewConnection.addConnections(list); |
169 | addNewConnection.showMaximized(); | 176 | addNewConnection.showMaximized(); |
170 | if(QDialog::Accepted == addNewConnection.exec()){ | 177 | if(QDialog::Accepted == addNewConnection.exec()){ |
171 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); | 178 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); |
172 | if(!item) | 179 | if(!item) |
173 | return; | 180 | return; |
174 | 181 | ||
175 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 182 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
176 | if(it.key()){ | 183 | if(it.key()){ |
177 | Interface *i = (it.key())->addNewInterface(item->text(0)); | 184 | Interface *i = (it.key())->addNewInterface(item->text(0)); |
178 | if(i){ | 185 | if(i){ |
179 | interfaceNames.insert(i->getInterfaceName(), i); | 186 | interfaceNames.insert(i->getInterfaceName(), i); |
180 | updateInterface(i); | 187 | updateInterface(i); |
181 | } | 188 | } |
182 | } | 189 | } |
183 | } | 190 | } |
184 | } | 191 | } |
185 | } | 192 | } |
186 | 193 | ||
187 | /** | 194 | /** |
188 | * Prompt the user to see if they really want to do this. | 195 | * Prompt the user to see if they really want to do this. |
189 | * If they do then remove from the list and unload. | 196 | * If they do then remove from the list and unload. |
190 | */ | 197 | */ |
191 | void MainWindowImp::removeClicked(){ | 198 | void MainWindowImp::removeClicked(){ |
192 | QListViewItem *item = connectionList->currentItem(); | 199 | QListViewItem *item = connectionList->currentItem(); |
193 | if(!item) { | 200 | if(!item) { |
194 | QMessageBox::information(this, "Sorry","Please select an interface First.", "Ok"); | 201 | QMessageBox::information(this, "Sorry","Please select an interface First.", "Ok"); |
195 | return; | 202 | return; |
196 | } | 203 | } |
197 | 204 | ||
198 | Interface *i = interfaceItems[item]; | 205 | Interface *i = interfaceItems[item]; |
199 | if(i->getModuleOwner() == NULL){ | 206 | if(i->getModuleOwner() == NULL){ |
200 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); | 207 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); |
201 | } | 208 | } |
202 | else{ | 209 | else{ |
203 | if(!i->getModuleOwner()->remove(i)) | 210 | if(!i->getModuleOwner()->remove(i)) |
204 | QMessageBox::information(this, "Error", "Unable to remove.", "Ok"); | 211 | QMessageBox::information(this, "Error", "Unable to remove.", "Ok"); |
205 | else{ | 212 | else{ |
206 | QMessageBox::information(this, "Success", "Interface was removed.", "Ok"); | 213 | QMessageBox::information(this, "Success", "Interface was removed.", "Ok"); |
207 | // TODO memory managment.... | 214 | // TODO memory managment.... |
208 | // who deletes the interface? | 215 | // who deletes the interface? |
209 | } | 216 | } |
210 | } | 217 | } |
211 | } | 218 | } |
212 | 219 | ||
213 | /** | 220 | /** |
214 | * Pull up the configure about the currently selected interface. | 221 | * Pull up the configure about the currently selected interface. |
215 | * Report an error if no interface is selected. | 222 | * Report an error if no interface is selected. |
216 | * If the interface has a module owner then request its configure with a empty | 223 | * If the interface has a module owner then request its configure with a empty |
217 | * tab. If tab is !NULL then append the interfaces setup widget to it. | 224 | * tab. If tab is !NULL then append the interfaces setup widget to it. |
218 | */ | 225 | */ |
219 | void MainWindowImp::configureClicked(){ | 226 | void MainWindowImp::configureClicked(){ |
220 | QListViewItem *item = connectionList->currentItem(); | 227 | QListViewItem *item = connectionList->currentItem(); |
221 | if(!item){ | 228 | if(!item){ |
222 | QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); | 229 | QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); |
223 | return; | 230 | return; |
224 | } | 231 | } |
225 | 232 | ||
226 | QString currentProfile = currentProfileLabel->text(); | 233 | QString currentProfile = currentProfileLabel->text(); |
227 | if(profilesList->count() <= 1 || currentProfile == "All"){ | 234 | if(profilesList->count() <= 1 || currentProfile == "All"){ |
228 | currentProfile = ""; | 235 | currentProfile = ""; |
229 | } | 236 | } |
230 | 237 | ||
231 | Interface *i = interfaceItems[item]; | 238 | Interface *i = interfaceItems[item]; |
232 | if(i->getModuleOwner()){ | 239 | if(i->getModuleOwner()){ |
233 | i->getModuleOwner()->setProfile(currentProfile); | 240 | i->getModuleOwner()->setProfile(currentProfile); |
234 | QTabWidget *tabWidget = NULL; | 241 | QTabWidget *tabWidget = NULL; |
235 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i, &tabWidget); | 242 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i, &tabWidget); |
236 | if(moduleConfigure != NULL){ | 243 | if(moduleConfigure != NULL){ |
237 | if(tabWidget != NULL){ | 244 | if(tabWidget != NULL){ |
238 | InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); | 245 | InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); |
239 | configure->setProfile(currentProfile); | 246 | configure->setProfile(currentProfile); |
240 | tabWidget->insertTab(configure, "TCP/IP"); | 247 | tabWidget->insertTab(configure, "TCP/IP"); |
241 | 248 | ||
242 | } | 249 | } |
243 | moduleConfigure->showMaximized(); | 250 | moduleConfigure->showMaximized(); |
244 | moduleConfigure->show(); | 251 | moduleConfigure->show(); |
245 | return; | 252 | return; |
246 | } | 253 | } |
247 | } | 254 | } |
248 | 255 | ||
249 | InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); | 256 | InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); |
250 | configure->setProfile(currentProfile); | 257 | configure->setProfile(currentProfile); |
251 | configure->showMaximized(); | 258 | configure->showMaximized(); |
252 | configure->show(); | 259 | configure->show(); |
253 | } | 260 | } |
254 | 261 | ||
255 | /** | 262 | /** |
256 | * Pull up the information about the currently selected interface. | 263 | * Pull up the information about the currently selected interface. |
257 | * Report an error if no interface is selected. | 264 | * Report an error if no interface is selected. |
258 | * If the interface has a module owner then request its configure with a empty | 265 | * If the interface has a module owner then request its configure with a empty |
259 | * tab. If tab is !NULL then append the interfaces setup widget to it. | 266 | * tab. If tab is !NULL then append the interfaces setup widget to it. |
260 | */ | 267 | */ |
261 | void MainWindowImp::informationClicked(){ | 268 | void MainWindowImp::informationClicked(){ |
262 | QListViewItem *item = connectionList->currentItem(); | 269 | QListViewItem *item = connectionList->currentItem(); |
263 | if(!item){ | 270 | if(!item){ |
264 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); | 271 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
265 | return; | 272 | return; |
266 | } | 273 | } |
267 | 274 | ||
268 | Interface *i = interfaceItems[item]; | 275 | Interface *i = interfaceItems[item]; |
269 | if(!i->isAttached()){ | 276 | if(!i->isAttached()){ |
270 | QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); | 277 | QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); |
271 | return; | 278 | return; |
272 | } | 279 | } |
273 | 280 | ||
274 | QStringList list; | 281 | QStringList list; |
275 | for(uint i = 0; i < profilesList->count(); i++){ | 282 | for(uint i = 0; i < profilesList->count(); i++){ |
276 | list.append(profilesList->text(i)); | 283 | list.append(profilesList->text(i)); |
277 | } | 284 | } |
278 | 285 | ||
279 | if(i->getModuleOwner()){ | 286 | if(i->getModuleOwner()){ |
280 | QTabWidget *tabWidget = NULL; | 287 | QTabWidget *tabWidget = NULL; |
281 | QWidget *moduleInformation = i->getModuleOwner()->information(i, &tabWidget); | 288 | QWidget *moduleInformation = i->getModuleOwner()->information(i, &tabWidget); |
282 | if(moduleInformation != NULL){ | 289 | if(moduleInformation != NULL){ |
283 | if(tabWidget != NULL){ | 290 | if(tabWidget != NULL){ |
284 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); | 291 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); |
285 | tabWidget->insertTab(information, "TCP/IP"); | 292 | tabWidget->insertTab(information, "TCP/IP"); |
286 | } | 293 | } |
287 | moduleInformation->showMaximized(); | 294 | moduleInformation->showMaximized(); |
288 | moduleInformation->show(); | 295 | moduleInformation->show(); |
289 | return; | 296 | return; |
290 | } | 297 | } |
291 | } | 298 | } |
292 | 299 | ||
293 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); | 300 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); |
294 | information->showMaximized(); | 301 | information->showMaximized(); |
295 | information->show(); | 302 | information->show(); |
296 | } | 303 | } |
297 | 304 | ||
298 | /** | 305 | /** |
299 | * Aquire the list of active interfaces from ifconfig | 306 | * Aquire the list of active interfaces from ifconfig |
300 | * Call ifconfig and ifconfig -a | 307 | * Call ifconfig and ifconfig -a |
301 | */ | 308 | */ |
302 | void MainWindowImp::getInterfaceList(){ | 309 | void MainWindowImp::getInterfaceList(){ |
303 | KShellProcess *processAll = new KShellProcess(); | 310 | KShellProcess *processAll = new KShellProcess(); |
304 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; | 311 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; |
305 | connect(processAll, SIGNAL(processExited(KProcess *)), | 312 | connect(processAll, SIGNAL(processExited(KProcess *)), |
306 | this, SLOT(jobDone(KProcess *))); | 313 | this, SLOT(jobDone(KProcess *))); |
307 | threads.insert(processAll, TEMP_ALL); | 314 | threads.insert(processAll, TEMP_ALL); |
308 | 315 | ||
309 | KShellProcess *process = new KShellProcess(); | 316 | KShellProcess *process = new KShellProcess(); |
310 | *process << "/sbin/ifconfig" << " > " TEMP_UP; | 317 | *process << "/sbin/ifconfig" << " > " TEMP_UP; |
311 | connect(process, SIGNAL(processExited(KProcess *)), | 318 | connect(process, SIGNAL(processExited(KProcess *)), |
312 | this, SLOT(jobDone(KProcess *))); | 319 | this, SLOT(jobDone(KProcess *))); |
313 | threads.insert(process, TEMP_UP); | 320 | threads.insert(process, TEMP_UP); |
314 | 321 | ||
315 | processAll->start(KShellProcess::NotifyOnExit); | 322 | processAll->start(KShellProcess::NotifyOnExit); |
316 | process->start(KShellProcess::NotifyOnExit); | 323 | process->start(KShellProcess::NotifyOnExit); |
317 | } | 324 | } |
318 | 325 | ||
319 | void MainWindowImp::jobDone(KProcess *process){ | 326 | void MainWindowImp::jobDone(KProcess *process){ |
320 | QString fileName = threads[process]; | 327 | QString fileName = threads[process]; |
321 | threads.remove(process); | 328 | threads.remove(process); |
322 | delete process; | 329 | delete process; |
323 | 330 | ||
324 | QFile file(fileName); | 331 | QFile file(fileName); |
325 | if (!file.open(IO_ReadOnly)){ | 332 | if (!file.open(IO_ReadOnly)){ |
326 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); | 333 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); |
327 | return; | 334 | return; |
328 | } | 335 | } |
329 | 336 | ||
330 | QTextStream stream( &file ); | 337 | QTextStream stream( &file ); |
331 | QString line; | 338 | QString line; |
332 | while ( !stream.eof() ) { | 339 | while ( !stream.eof() ) { |
333 | line = stream.readLine(); | 340 | line = stream.readLine(); |
334 | int space = line.find(" "); | 341 | int space = line.find(" "); |
335 | if(space > 1){ | 342 | if(space > 1){ |
336 | // We have found an interface | 343 | // We have found an interface |
337 | QString interfaceName = line.mid(0, space); | 344 | QString interfaceName = line.mid(0, space); |
338 | Interface *i; | 345 | Interface *i; |
339 | // We have found an interface | 346 | // We have found an interface |
340 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | 347 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); |
341 | // See if we already have it | 348 | // See if we already have it |
342 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ | 349 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ |
343 | if(fileName == TEMP_ALL) | 350 | if(fileName == TEMP_ALL) |
344 | i = new Interface(this, interfaceName, false); | 351 | i = new Interface(this, interfaceName, false); |
345 | else | 352 | else |
346 | i = new Interface(this, interfaceName, true); | 353 | i = new Interface(this, interfaceName, true); |
347 | i->setAttached(true); | 354 | i->setAttached(true); |
348 | 355 | ||
349 | QString hardName = "Ethernet"; | 356 | QString hardName = "Ethernet"; |
350 | int hardwareName = line.find("Link encap:"); | 357 | int hardwareName = line.find("Link encap:"); |
351 | int macAddress = line.find("HWaddr"); | 358 | int macAddress = line.find("HWaddr"); |
352 | if(macAddress == -1) | 359 | if(macAddress == -1) |
353 | macAddress = line.length(); | 360 | macAddress = line.length(); |
354 | if(hardwareName != -1) | 361 | if(hardwareName != -1) |
355 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) ); | 362 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) ); |
356 | 363 | ||
357 | interfaceNames.insert(i->getInterfaceName(), i); | 364 | interfaceNames.insert(i->getInterfaceName(), i); |
358 | updateInterface(i); | 365 | updateInterface(i); |
359 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 366 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
360 | } | 367 | } |
361 | // It was an interface we already had. | 368 | // It was an interface we already had. |
362 | else{ | 369 | else{ |
363 | if(fileName != TEMP_ALL) | 370 | if(fileName != TEMP_ALL) |
364 | (interfaceNames[interfaceName])->setStatus(true); | 371 | (interfaceNames[interfaceName])->setStatus(true); |
365 | } | 372 | } |
366 | } | 373 | } |
367 | } | 374 | } |
368 | file.close(); | 375 | file.close(); |
369 | QFile::remove(fileName); | 376 | QFile::remove(fileName); |
370 | 377 | ||
371 | if(threads.count() == 0){ | 378 | if(threads.count() == 0){ |
372 | Interfaces i; | 379 | Interfaces i; |
373 | QStringList list = i.getInterfaceList(); | 380 | QStringList list = i.getInterfaceList(); |
374 | QMap<QString, Interface*>::Iterator it; | 381 | QMap<QString, Interface*>::Iterator it; |
375 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | 382 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { |
376 | bool found = false; | 383 | bool found = false; |
377 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | 384 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ |
378 | if(it.key() == (*ni)) | 385 | if(it.key() == (*ni)) |
379 | found = true; | 386 | found = true; |
380 | } | 387 | } |
381 | if(!found){ | 388 | if(!found){ |
382 | if(!(*ni).contains("_")){ | 389 | if(!(*ni).contains("_")){ |
383 | Interface *i = new Interface(this, *ni, false); | 390 | Interface *i = new Interface(this, *ni, false); |
384 | i->setAttached(false); | 391 | i->setAttached(false); |
385 | i->setHardwareName("Disconnected"); | 392 | i->setHardwareName("Disconnected"); |
386 | interfaceNames.insert(i->getInterfaceName(), i); | 393 | interfaceNames.insert(i->getInterfaceName(), i); |
387 | updateInterface(i); | 394 | updateInterface(i); |
388 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 395 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
389 | } | 396 | } |
390 | } | 397 | } |
391 | } | 398 | } |
392 | } | 399 | } |
393 | } | 400 | } |
394 | 401 | ||
395 | /** | 402 | /** |
396 | * Update this interface. If no QListViewItem exists create one. | 403 | * Update this interface. If no QListViewItem exists create one. |
397 | * @param Interface* pointer to the interface that needs to be updated. | 404 | * @param Interface* pointer to the interface that needs to be updated. |
398 | */ | 405 | */ |
399 | void MainWindowImp::updateInterface(Interface *i){ | 406 | void MainWindowImp::updateInterface(Interface *i){ |
400 | if(!advancedUserMode){ | 407 | if(!advancedUserMode){ |
401 | if(i->getInterfaceName() == "lo") | 408 | if(i->getInterfaceName() == "lo") |
402 | return; | 409 | return; |
403 | } | 410 | } |
404 | 411 | ||
405 | QListViewItem *item = NULL; | 412 | QListViewItem *item = NULL; |
406 | 413 | ||
407 | // Find the interface, making it if needed. | 414 | // Find the interface, making it if needed. |
408 | if(items.find(i) == items.end()){ | 415 | if(items.find(i) == items.end()){ |
409 | item = new QListViewItem(connectionList, "", "", ""); | 416 | item = new QListViewItem(connectionList, "", "", ""); |
410 | // See if you can't find a module owner for this interface | 417 | // See if you can't find a module owner for this interface |
411 | QMap<Module*, QLibrary*>::Iterator it; | 418 | QMap<Module*, QLibrary*>::Iterator it; |
412 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 419 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
413 | if(it.key()->isOwner(i)) | 420 | if(it.key()->isOwner(i)) |
414 | i->setModuleOwner(it.key()); | 421 | i->setModuleOwner(it.key()); |
415 | } | 422 | } |
416 | items.insert(i, item); | 423 | items.insert(i, item); |
417 | interfaceItems.insert(item, i); | 424 | interfaceItems.insert(item, i); |
418 | } | 425 | } |
419 | else | 426 | else |
420 | item = items[i]; | 427 | item = items[i]; |
421 | 428 | ||
422 | // Update the icons and information | 429 | // Update the icons and information |
423 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 430 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
424 | 431 | ||
425 | QString typeName = "lan"; | 432 | QString typeName = "lan"; |
426 | if(i->getHardwareName().contains("Local Loopback")) | 433 | if(i->getHardwareName().contains("Local Loopback")) |
427 | typeName = "lo"; | 434 | typeName = "lo"; |
428 | if(i->getInterfaceName().contains("irda")) | 435 | if(i->getInterfaceName().contains("irda")) |
429 | typeName = "irda"; | 436 | typeName = "irda"; |
430 | if(i->getInterfaceName().contains("wlan")) | 437 | if(i->getInterfaceName().contains("wlan")) |
431 | typeName = "wlan"; | 438 | typeName = "wlan"; |
432 | if(i->getInterfaceName().contains("usb")) | 439 | if(i->getInterfaceName().contains("usb")) |
433 | typeName = "usb"; | 440 | typeName = "usb"; |
434 | 441 | ||
435 | if(!i->isAttached()) | 442 | if(!i->isAttached()) |
436 | typeName = "connect_no"; | 443 | typeName = "connect_no"; |
437 | // Actually try to use the Module | 444 | // Actually try to use the Module |
438 | if(i->getModuleOwner() != NULL) | 445 | if(i->getModuleOwner() != NULL) |
439 | typeName = i->getModuleOwner()->getPixmapName(i); | 446 | typeName = i->getModuleOwner()->getPixmapName(i); |
440 | 447 | ||
441 | item->setPixmap(1, (Resource::loadPixmap(typeName))); | 448 | item->setPixmap(1, (Resource::loadPixmap(typeName))); |
442 | item->setText(2, i->getHardwareName()); | 449 | item->setText(2, i->getHardwareName()); |
443 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); | 450 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); |
444 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); | 451 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); |
445 | } | 452 | } |
446 | 453 | ||
447 | void MainWindowImp::newProfileChanged(const QString& newText){ | 454 | void MainWindowImp::newProfileChanged(const QString& newText){ |
448 | if(newText.length() > 0) | 455 | if(newText.length() > 0) |
449 | newProfileButton->setEnabled(true); | 456 | newProfileButton->setEnabled(true); |
450 | else | 457 | else |
451 | newProfileButton->setEnabled(false); | 458 | newProfileButton->setEnabled(false); |
452 | } | 459 | } |
453 | 460 | ||
454 | /** | 461 | /** |
455 | * Adds a new profile to the list of profiles. | 462 | * Adds a new profile to the list of profiles. |
456 | * Don't add profiles that already exists. | 463 | * Don't add profiles that already exists. |
457 | * Appends to the list and QStringList | 464 | * Appends to the list and QStringList |
458 | */ | 465 | */ |
459 | void MainWindowImp::addProfile(){ | 466 | void MainWindowImp::addProfile(){ |
460 | QString newProfileName = newProfile->text(); | 467 | QString newProfileName = newProfile->text(); |
461 | if(profiles.grep(newProfileName).count() > 0){ | 468 | if(profiles.grep(newProfileName).count() > 0){ |
462 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); | 469 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); |
463 | return; | 470 | return; |
464 | } | 471 | } |
465 | profiles.append(newProfileName); | 472 | profiles.append(newProfileName); |
466 | profilesList->insertItem(newProfileName); | 473 | profilesList->insertItem(newProfileName); |
467 | } | 474 | } |
468 | 475 | ||
469 | /** | 476 | /** |
diff --git a/noncore/net/networksetup/wlan/wlanmodule.cpp b/noncore/net/networksetup/wlan/wlanmodule.cpp index cbb520d..24cb1cd 100644 --- a/noncore/net/networksetup/wlan/wlanmodule.cpp +++ b/noncore/net/networksetup/wlan/wlanmodule.cpp | |||
@@ -1,223 +1,222 @@ | |||
1 | #include "wlanmodule.h" | 1 | #include "wlanmodule.h" |
2 | #include <qpe/config.h> | ||
3 | #include "wlanimp.h" | 2 | #include "wlanimp.h" |
4 | #include "info.h" | 3 | #include "info.h" |
5 | 4 | ||
6 | |||
7 | #include <arpa/inet.h> | 5 | #include <arpa/inet.h> |
8 | #include <sys/socket.h> | 6 | #include <sys/socket.h> |
9 | #include <linux/if_ether.h> | 7 | #include <linux/if_ether.h> |
10 | #include <netinet/ip.h> | 8 | #include <netinet/ip.h> |
11 | #include <sys/ioctl.h> | 9 | #include <sys/ioctl.h> |
12 | #include <linux/wireless.h> | 10 | #include <linux/wireless.h> |
13 | 11 | ||
14 | #include <unistd.h> | 12 | #include <unistd.h> |
15 | #include <math.h> | 13 | #include <math.h> |
16 | #include <errno.h> | 14 | #include <errno.h> |
17 | #include <string.h> | 15 | #include <string.h> |
18 | #include <stdio.h> | 16 | #include <stdio.h> |
19 | 17 | ||
20 | #include <stdlib.h> | 18 | #include <stdlib.h> |
21 | 19 | ||
22 | #include <qlabel.h> | 20 | #include <qlabel.h> |
23 | 21 | ||
24 | /** | 22 | /** |
25 | * Constructor, find all of the possible interfaces | 23 | * Constructor, find all of the possible interfaces |
26 | */ | 24 | */ |
27 | WLANModule::WLANModule() : Module() { | 25 | WLANModule::WLANModule() : Module() { |
28 | // get output from iwconfig | 26 | // get output from iwconfig |
29 | } | 27 | } |
30 | 28 | ||
31 | /** | 29 | /** |
32 | * Change the current profile | 30 | * Change the current profile |
33 | */ | 31 | */ |
34 | void WLANModule::setProfile(QString newProfile){ | 32 | void WLANModule::setProfile(QString newProfile){ |
35 | profile = newProfile; | 33 | profile = newProfile; |
36 | } | 34 | } |
37 | 35 | ||
38 | /** | 36 | /** |
39 | * get the icon name for this device. | 37 | * get the icon name for this device. |
40 | * @param Interface* can be used in determining the icon. | 38 | * @param Interface* can be used in determining the icon. |
41 | * @return QString the icon name (minus .png, .gif etc) | 39 | * @return QString the icon name (minus .png, .gif etc) |
42 | */ | 40 | */ |
43 | QString WLANModule::getPixmapName(Interface* ){ | 41 | QString WLANModule::getPixmapName(Interface* ){ |
44 | return "wlan"; | 42 | return "wlan"; |
45 | } | 43 | } |
46 | 44 | ||
47 | /** | 45 | /** |
48 | * Check to see if the interface i is owned by this module. | 46 | * Check to see if the interface i is owned by this module. |
49 | * @param Interface* interface to check against | 47 | * @param Interface* interface to check against |
50 | * @return bool true if i is owned by this module, false otherwise. | 48 | * @return bool true if i is owned by this module, false otherwise. |
51 | */ | 49 | */ |
52 | bool WLANModule::isOwner(Interface *i){ | 50 | bool WLANModule::isOwner(Interface *i){ |
53 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ | 51 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ |
54 | i->setHardwareName("802.11b"); | 52 | i->setHardwareName("802.11b"); |
55 | return true; | 53 | return true; |
56 | } | 54 | } |
57 | return false; | 55 | return false; |
58 | } | 56 | } |
59 | 57 | ||
60 | /** | 58 | /** |
61 | * Create, set tabWiget and return the WLANConfigure Module | 59 | * Create, set tabWiget and return the WLANConfigure Module |
62 | * @param tabWidget a pointer to the tab widget that this configure has. | 60 | * @param tabWidget a pointer to the tab widget that this configure has. |
63 | * @return QWidget* pointer to the tab widget in this modules configure. | 61 | * @return QWidget* pointer to the tab widget in this modules configure. |
64 | */ | 62 | */ |
65 | QWidget *WLANModule::configure(Interface *i, QTabWidget **tabWidget){ | 63 | QWidget *WLANModule::configure(Interface *i, QTabWidget **tabWidget){ |
66 | WLANImp *wlanconfig = new WLANImp( ); | 64 | WLANImp *wlanconfig = new WLANImp(0, "WlanConfig"); |
67 | (*tabWidget) = wlanconfig->tabWidget; | 65 | (*tabWidget) = wlanconfig->tabWidget; |
68 | return wlanconfig; | 66 | return wlanconfig; |
69 | } | 67 | } |
70 | 68 | ||
71 | /** | 69 | /** |
72 | * Create, set tabWiget and return the Information Module | 70 | * Create, set tabWiget and return the Information Module |
73 | * @param tabWidget a pointer to the tab widget that this information has. | 71 | * @param tabWidget a pointer to the tab widget that this information has. |
74 | * @return QWidget* pointer to the tab widget in this modules info. | 72 | * @return QWidget* pointer to the tab widget in this modules info. |
75 | */ | 73 | */ |
76 | QWidget *WLANModule::information(Interface *i, QTabWidget **tabWidget){ | 74 | QWidget *WLANModule::information(Interface *i, QTabWidget **tabWidget){ |
75 | return NULL; | ||
77 | WlanInfo *info = new WlanInfo(0, "wireless info"); | 76 | WlanInfo *info = new WlanInfo(0, "wireless info"); |
78 | (*tabWidget) = info->tabWidget; | 77 | (*tabWidget) = info->tabWidget; |
79 | 78 | ||
80 | struct ifreq ifr; | 79 | struct ifreq ifr; |
81 | struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; | 80 | struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; |
82 | int fd = socket( AF_INET, SOCK_DGRAM, 0 ); | 81 | int fd = socket( AF_INET, SOCK_DGRAM, 0 ); |
83 | 82 | ||
84 | const char* buffer[200]; | 83 | const char* buffer[200]; |
85 | struct iwreq iwr; | 84 | struct iwreq iwr; |
86 | memset( &iwr, 0, sizeof( iwr ) ); | 85 | memset( &iwr, 0, sizeof( iwr ) ); |
87 | iwr.u.essid.pointer = (caddr_t) buffer; | 86 | iwr.u.essid.pointer = (caddr_t) buffer; |
88 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 87 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
89 | iwr.u.essid.flags = 0; | 88 | iwr.u.essid.flags = 0; |
90 | 89 | ||
91 | // check if it is an IEEE 802.11 standard conform | 90 | // check if it is an IEEE 802.11 standard conform |
92 | // wireless device by sending SIOCGIWESSID | 91 | // wireless device by sending SIOCGIWESSID |
93 | // which also gives back the Extended Service Set ID | 92 | // which also gives back the Extended Service Set ID |
94 | // (see IEEE 802.11 for more information) | 93 | // (see IEEE 802.11 for more information) |
95 | 94 | ||
96 | QString n = (i->getInterfaceName()); | 95 | QString n = (i->getInterfaceName()); |
97 | const char* iname = n.latin1(); | 96 | const char* iname = n.latin1(); |
98 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); | 97 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); |
99 | int result = ioctl( fd, SIOCGIWESSID, &iwr ); | 98 | int result = ioctl( fd, SIOCGIWESSID, &iwr ); |
100 | if ( result == 0 ){ | 99 | if ( result == 0 ){ |
101 | //hasWirelessExtensions = true; | 100 | //hasWirelessExtensions = true; |
102 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; | 101 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; |
103 | info->essidLabel->setText(QString(iwr.u.essid.pointer)); | 102 | info->essidLabel->setText(QString(iwr.u.essid.pointer)); |
104 | } | 103 | } |
105 | else | 104 | else |
106 | return info; | 105 | return info; |
107 | //info->essidLabel->setText("*** Unknown ***"); | 106 | //info->essidLabel->setText("*** Unknown ***"); |
108 | 107 | ||
109 | // Address of associated access-point | 108 | // Address of associated access-point |
110 | result = ioctl( fd, SIOCGIWAP, &iwr ); | 109 | result = ioctl( fd, SIOCGIWAP, &iwr ); |
111 | if ( result == 0 ){ | 110 | if ( result == 0 ){ |
112 | QString foo = foo.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 111 | QString foo = foo.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
113 | iwr.u.ap_addr.sa_data[0]&0xff, | 112 | iwr.u.ap_addr.sa_data[0]&0xff, |
114 | iwr.u.ap_addr.sa_data[1]&0xff, | 113 | iwr.u.ap_addr.sa_data[1]&0xff, |
115 | iwr.u.ap_addr.sa_data[2]&0xff, | 114 | iwr.u.ap_addr.sa_data[2]&0xff, |
116 | iwr.u.ap_addr.sa_data[3]&0xff, | 115 | iwr.u.ap_addr.sa_data[3]&0xff, |
117 | iwr.u.ap_addr.sa_data[4]&0xff, | 116 | iwr.u.ap_addr.sa_data[4]&0xff, |
118 | iwr.u.ap_addr.sa_data[5]&0xff ); | 117 | iwr.u.ap_addr.sa_data[5]&0xff ); |
119 | info->apLabel->setText(foo); | 118 | info->apLabel->setText(foo); |
120 | } | 119 | } |
121 | else info->apLabel->setText("*** Unknown ***"); | 120 | else info->apLabel->setText("*** Unknown ***"); |
122 | 121 | ||
123 | iwr.u.data.pointer = (caddr_t) buffer; | 122 | iwr.u.data.pointer = (caddr_t) buffer; |
124 | iwr.u.data.length = IW_ESSID_MAX_SIZE; | 123 | iwr.u.data.length = IW_ESSID_MAX_SIZE; |
125 | iwr.u.data.flags = 0; | 124 | iwr.u.data.flags = 0; |
126 | result = ioctl( fd, SIOCGIWNICKN, &iwr ); | 125 | result = ioctl( fd, SIOCGIWNICKN, &iwr ); |
127 | if ( result == 0 ){ | 126 | if ( result == 0 ){ |
128 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; | 127 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; |
129 | info->stationLabel->setText(iwr.u.data.pointer); | 128 | info->stationLabel->setText(iwr.u.data.pointer); |
130 | } | 129 | } |
131 | else info->stationLabel->setText("*** Unknown ***"); | 130 | else info->stationLabel->setText("*** Unknown ***"); |
132 | 131 | ||
133 | result = ioctl( fd, SIOCGIWMODE, &iwr ); | 132 | result = ioctl( fd, SIOCGIWMODE, &iwr ); |
134 | if ( result == 0 ) | 133 | if ( result == 0 ) |
135 | info->modeLabel->setText( QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed")); | 134 | info->modeLabel->setText( QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed")); |
136 | else | 135 | else |
137 | info->modeLabel->setText("*** Unknown ***"); | 136 | info->modeLabel->setText("*** Unknown ***"); |
138 | 137 | ||
139 | result = ioctl( fd, SIOCGIWFREQ, &iwr ); | 138 | result = ioctl( fd, SIOCGIWFREQ, &iwr ); |
140 | if ( result == 0 ) | 139 | if ( result == 0 ) |
141 | info->freqLabel->setText(QString("%1").arg((double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000))); | 140 | info->freqLabel->setText(QString("%1").arg((double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000))); |
142 | else | 141 | else |
143 | info->freqLabel->setText("*** Unknown ***"); | 142 | info->freqLabel->setText("*** Unknown ***"); |
144 | 143 | ||
145 | /* | 144 | /* |
146 | // gather link quality from /proc/net/wireless | 145 | // gather link quality from /proc/net/wireless |
147 | 146 | ||
148 | char c; | 147 | char c; |
149 | QString status; | 148 | QString status; |
150 | QString name; | 149 | QString name; |
151 | QFile wfile( PROCNETWIRELESS ); | 150 | QFile wfile( PROCNETWIRELESS ); |
152 | bool hasFile = wfile.open( IO_ReadOnly ); | 151 | bool hasFile = wfile.open( IO_ReadOnly ); |
153 | QTextStream wstream( &wfile ); | 152 | QTextStream wstream( &wfile ); |
154 | if ( hasFile ) | 153 | if ( hasFile ) |
155 | { | 154 | { |
156 | wstream.readLine(); // skip the first two lines | 155 | wstream.readLine(); // skip the first two lines |
157 | wstream.readLine(); // because they only contain headers | 156 | wstream.readLine(); // because they only contain headers |
158 | } | 157 | } |
159 | if ( ( !hasFile ) || ( wstream.atEnd() ) ) | 158 | if ( ( !hasFile ) || ( wstream.atEnd() ) ) |
160 | { | 159 | { |
161 | #ifdef MDEBUG | 160 | #ifdef MDEBUG |
162 | qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); | 161 | qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); |
163 | #endif | 162 | #endif |
164 | quality = -1; | 163 | quality = -1; |
165 | signal = IW_LOWER; | 164 | signal = IW_LOWER; |
166 | noise = IW_LOWER; | 165 | noise = IW_LOWER; |
167 | return false; | 166 | return false; |
168 | } | 167 | } |
169 | 168 | ||
170 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; | 169 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; |
171 | 170 | ||
172 | if ( quality > 92 ) | 171 | if ( quality > 92 ) |
173 | #ifdef MDEBUG | 172 | #ifdef MDEBUG |
174 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); | 173 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); |
175 | #endif | 174 | #endif |
176 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) | 175 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) |
177 | #ifdef MDEBUG | 176 | #ifdef MDEBUG |
178 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); | 177 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); |
179 | #endif | 178 | #endif |
180 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) | 179 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) |
181 | #ifdef MDEBUG | 180 | #ifdef MDEBUG |
182 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); | 181 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); |
183 | #endif | 182 | #endif |
184 | 183 | ||
185 | return true; | 184 | return true; |
186 | 185 | ||
187 | } | 186 | } |
188 | */ | 187 | */ |
189 | return info; | 188 | return info; |
190 | } | 189 | } |
191 | 190 | ||
192 | /** | 191 | /** |
193 | * Get all active (up or down) interfaces | 192 | * Get all active (up or down) interfaces |
194 | * @return QList<Interface> A list of interfaces that exsist that havn't | 193 | * @return QList<Interface> A list of interfaces that exsist that havn't |
195 | * been called by isOwner() | 194 | * been called by isOwner() |
196 | */ | 195 | */ |
197 | QList<Interface> WLANModule::getInterfaces(){ | 196 | QList<Interface> WLANModule::getInterfaces(){ |
198 | return list; | 197 | return list; |
199 | } | 198 | } |
200 | 199 | ||
201 | /** | 200 | /** |
202 | * Attempt to add a new interface as defined by name | 201 | * Attempt to add a new interface as defined by name |
203 | * @param name the name of the type of interface that should be created given | 202 | * @param name the name of the type of interface that should be created given |
204 | * by possibleNewInterfaces(); | 203 | * by possibleNewInterfaces(); |
205 | * @return Interface* NULL if it was unable to be created. | 204 | * @return Interface* NULL if it was unable to be created. |
206 | */ | 205 | */ |
207 | Interface *WLANModule::addNewInterface(QString ){ | 206 | Interface *WLANModule::addNewInterface(QString ){ |
208 | // We can't add a 802.11 interface, either the hardware will be there | 207 | // We can't add a 802.11 interface, either the hardware will be there |
209 | // or it wont. | 208 | // or it wont. |
210 | return NULL; | 209 | return NULL; |
211 | } | 210 | } |
212 | 211 | ||
213 | /** | 212 | /** |
214 | * Attempts to remove the interface, doesn't delete i | 213 | * Attempts to remove the interface, doesn't delete i |
215 | * @return bool true if successfull, false otherwise. | 214 | * @return bool true if successfull, false otherwise. |
216 | */ | 215 | */ |
217 | bool WLANModule::remove(Interface*){ | 216 | bool WLANModule::remove(Interface*){ |
218 | // Can't remove a hardware device, you can stop it though. | 217 | // Can't remove a hardware device, you can stop it though. |
219 | return false; | 218 | return false; |
220 | } | 219 | } |
221 | 220 | ||
222 | // wlanmodule.cpp | 221 | // wlanmodule.cpp |
223 | 222 | ||
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index 843f630..9d81ab1 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp | |||
@@ -1,469 +1,476 @@ | |||
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 "interfaces.h" | 5 | #include "interfaces.h" |
6 | 6 | ||
7 | #include "module.h" | 7 | #include "module.h" |
8 | 8 | ||
9 | #include "kprocess.h" | 9 | #include "kprocess.h" |
10 | 10 | ||
11 | #include <qpushbutton.h> | 11 | #include <qpushbutton.h> |
12 | #include <qtabwidget.h> | 12 | #include <qtabwidget.h> |
13 | #include <qlistbox.h> | 13 | #include <qlistbox.h> |
14 | #include <qlineedit.h> | 14 | #include <qlineedit.h> |
15 | #include <qlistview.h> | 15 | #include <qlistview.h> |
16 | #include <qheader.h> | 16 | #include <qheader.h> |
17 | #include <qlabel.h> | 17 | #include <qlabel.h> |
18 | 18 | ||
19 | #include <qmainwindow.h> | 19 | #include <qmainwindow.h> |
20 | #include <qmessagebox.h> | 20 | #include <qmessagebox.h> |
21 | 21 | ||
22 | #include <qpe/config.h> | 22 | #include <qpe/config.h> |
23 | #include <qpe/qlibrary.h> | 23 | #include <qpe/qlibrary.h> |
24 | #include <qpe/resource.h> | 24 | #include <qpe/resource.h> |
25 | #include <qpe/qpeapplication.h> | 25 | #include <qpe/qpeapplication.h> |
26 | 26 | ||
27 | #include <qlist.h> | 27 | #include <qlist.h> |
28 | #include <qdir.h> | 28 | #include <qdir.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | 31 | ||
32 | #define TEMP_ALL "/tmp/ifconfig-a" | 32 | #define TEMP_ALL "/tmp/ifconfig-a" |
33 | #define TEMP_UP "/tmp/ifconfig" | 33 | #define TEMP_UP "/tmp/ifconfig" |
34 | 34 | ||
35 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" | 35 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" |
36 | 36 | ||
37 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ | 37 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ |
38 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); | 38 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); |
39 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | 39 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); |
40 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | 40 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); |
41 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | 41 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); |
42 | 42 | ||
43 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); | 43 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); |
44 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); | 44 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); |
45 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); | 45 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); |
46 | 46 | ||
47 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); | 47 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); |
48 | // Load connections. | 48 | // Load connections. |
49 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); | 49 | loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); |
50 | getInterfaceList(); | 50 | getInterfaceList(); |
51 | connectionList->header()->hide(); | 51 | connectionList->header()->hide(); |
52 | 52 | ||
53 | 53 | ||
54 | Config cfg("NetworkSetup"); | 54 | Config cfg("NetworkSetup"); |
55 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); | 55 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); |
56 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 56 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
57 | profilesList->insertItem((*it)); | 57 | profilesList->insertItem((*it)); |
58 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); | 58 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); |
59 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); | 59 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); |
60 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); | 60 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); |
61 | 61 | ||
62 | QFile file(scheme); | 62 | QFile file(scheme); |
63 | if ( file.open(IO_ReadOnly) ) { // file opened successfully | 63 | if ( file.open(IO_ReadOnly) ) { // file opened successfully |
64 | QTextStream stream( &file ); // use a text stream | 64 | QTextStream stream( &file ); // use a text stream |
65 | while ( !stream.eof() ) { // until end of file... | 65 | while ( !stream.eof() ) { // until end of file... |
66 | QString line = stream.readLine(); // line of text excluding '\n' | 66 | QString line = stream.readLine(); // line of text excluding '\n' |
67 | if(line.contains("SCHEME")){ | 67 | if(line.contains("SCHEME")){ |
68 | line = line.mid(7, line.length()); | 68 | line = line.mid(7, line.length()); |
69 | currentProfileLabel->setText(line); | 69 | currentProfileLabel->setText(line); |
70 | break; | 70 | break; |
71 | } | 71 | } |
72 | } | 72 | } |
73 | file.close(); | 73 | file.close(); |
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Deconstructor. Save profiles. Delete loaded libraries. | 78 | * Deconstructor. Save profiles. Delete loaded libraries. |
79 | */ | 79 | */ |
80 | MainWindowImp::~MainWindowImp(){ | 80 | MainWindowImp::~MainWindowImp(){ |
81 | // Save profiles. | 81 | // Save profiles. |
82 | Config cfg("NetworkSetup"); | 82 | Config cfg("NetworkSetup"); |
83 | cfg.setGroup("General"); | 83 | cfg.setGroup("General"); |
84 | cfg.writeEntry("Profiles", profiles.join(" ")); | 84 | cfg.writeEntry("Profiles", profiles.join(" ")); |
85 | 85 | ||
86 | // Delete all interfaces that don't have owners. | ||
87 | QMap<Interface*, QListViewItem*>::Iterator iIt; | ||
88 | for( iIt = items.begin(); iIt != items.end(); ++iIt ){ | ||
89 | if(iIt.key()->getModuleOwner() == NULL) | ||
90 | delete iIt.key(); | ||
91 | } | ||
92 | |||
86 | // Delete Modules and Libraries | 93 | // Delete Modules and Libraries |
87 | QMap<Module*, QLibrary*>::Iterator it; | 94 | QMap<Module*, QLibrary*>::Iterator it; |
88 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 95 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
89 | delete it.key(); | 96 | delete it.key(); |
90 | delete it.data(); | 97 | delete it.data(); |
91 | } | 98 | } |
92 | } | 99 | } |
93 | 100 | ||
94 | /** | 101 | /** |
95 | * Load all modules that are found in the path | 102 | * Load all modules that are found in the path |
96 | * @param path a directory that is scaned for any plugins that can be loaded | 103 | * @param path a directory that is scaned for any plugins that can be loaded |
97 | * and attempts to load them | 104 | * and attempts to load them |
98 | */ | 105 | */ |
99 | void MainWindowImp::loadModules(QString path){ | 106 | void MainWindowImp::loadModules(QString path){ |
100 | //qDebug(path.latin1()); | 107 | //qDebug(path.latin1()); |
101 | QDir d(path); | 108 | QDir d(path); |
102 | if(!d.exists()) | 109 | if(!d.exists()) |
103 | return; | 110 | return; |
104 | 111 | ||
105 | // Don't want sym links | 112 | // Don't want sym links |
106 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 113 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
107 | const QFileInfoList *list = d.entryInfoList(); | 114 | const QFileInfoList *list = d.entryInfoList(); |
108 | QFileInfoListIterator it( *list ); | 115 | QFileInfoListIterator it( *list ); |
109 | QFileInfo *fi; | 116 | QFileInfo *fi; |
110 | while ( (fi=it.current()) ) { | 117 | while ( (fi=it.current()) ) { |
111 | if(fi->fileName().contains(".so")){ | 118 | if(fi->fileName().contains(".so")){ |
112 | loadPlugin(path + "/" + fi->fileName()); | 119 | loadPlugin(path + "/" + fi->fileName()); |
113 | } | 120 | } |
114 | ++it; | 121 | ++it; |
115 | } | 122 | } |
116 | } | 123 | } |
117 | 124 | ||
118 | /** | 125 | /** |
119 | * Attempt to load a function and resolve a function. | 126 | * Attempt to load a function and resolve a function. |
120 | * @param pluginFileName - the name of the file in which to attempt to load | 127 | * @param pluginFileName - the name of the file in which to attempt to load |
121 | * @param resolveString - function pointer to resolve | 128 | * @param resolveString - function pointer to resolve |
122 | * @return pointer to the function with name resolveString or NULL | 129 | * @return pointer to the function with name resolveString or NULL |
123 | */ | 130 | */ |
124 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | 131 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ |
125 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); | 132 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); |
126 | QLibrary *lib = new QLibrary(pluginFileName); | 133 | QLibrary *lib = new QLibrary(pluginFileName); |
127 | void *functionPointer = lib->resolve(resolveString); | 134 | void *functionPointer = lib->resolve(resolveString); |
128 | if( !functionPointer ){ | 135 | if( !functionPointer ){ |
129 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 136 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
130 | delete lib; | 137 | delete lib; |
131 | return NULL; | 138 | return NULL; |
132 | } | 139 | } |
133 | 140 | ||
134 | // Try to get an object. | 141 | // Try to get an object. |
135 | Module *object = ((Module* (*)()) functionPointer)(); | 142 | Module *object = ((Module* (*)()) functionPointer)(); |
136 | if(object == NULL){ | 143 | if(object == NULL){ |
137 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 144 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
138 | delete lib; | 145 | delete lib; |
139 | return NULL; | 146 | return NULL; |
140 | } | 147 | } |
141 | 148 | ||
142 | // Store for deletion later | 149 | // Store for deletion later |
143 | libraries.insert(object, lib); | 150 | libraries.insert(object, lib); |
144 | return object; | 151 | return object; |
145 | } | 152 | } |
146 | 153 | ||
147 | /** | 154 | /** |
148 | * The Add button was clicked. Bring up the add dialog and if OK is hit | 155 | * The Add button was clicked. Bring up the add dialog and if OK is hit |
149 | * load the plugin and append it to the list | 156 | * load the plugin and append it to the list |
150 | */ | 157 | */ |
151 | void MainWindowImp::addClicked(){ | 158 | void MainWindowImp::addClicked(){ |
152 | QMap<Module*, QLibrary*>::Iterator it; | 159 | QMap<Module*, QLibrary*>::Iterator it; |
153 | QMap<QString, QString> list; | 160 | QMap<QString, QString> list; |
154 | QMap<QString, Module*> newInterfaceOwners; | 161 | QMap<QString, Module*> newInterfaceOwners; |
155 | list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); | 162 | list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); |
156 | list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); | 163 | list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); |
157 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 164 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
158 | if(it.key()){ | 165 | if(it.key()){ |
159 | (it.key())->possibleNewInterfaces(list); | 166 | (it.key())->possibleNewInterfaces(list); |
160 | } | 167 | } |
161 | } | 168 | } |
162 | // See if the list has anything that we can add. | 169 | // See if the list has anything that we can add. |
163 | if(list.count() == 0){ | 170 | if(list.count() == 0){ |
164 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); | 171 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); |
165 | return; | 172 | return; |
166 | } | 173 | } |
167 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); | 174 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); |
168 | addNewConnection.addConnections(list); | 175 | addNewConnection.addConnections(list); |
169 | addNewConnection.showMaximized(); | 176 | addNewConnection.showMaximized(); |
170 | if(QDialog::Accepted == addNewConnection.exec()){ | 177 | if(QDialog::Accepted == addNewConnection.exec()){ |
171 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); | 178 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); |
172 | if(!item) | 179 | if(!item) |
173 | return; | 180 | return; |
174 | 181 | ||
175 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 182 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
176 | if(it.key()){ | 183 | if(it.key()){ |
177 | Interface *i = (it.key())->addNewInterface(item->text(0)); | 184 | Interface *i = (it.key())->addNewInterface(item->text(0)); |
178 | if(i){ | 185 | if(i){ |
179 | interfaceNames.insert(i->getInterfaceName(), i); | 186 | interfaceNames.insert(i->getInterfaceName(), i); |
180 | updateInterface(i); | 187 | updateInterface(i); |
181 | } | 188 | } |
182 | } | 189 | } |
183 | } | 190 | } |
184 | } | 191 | } |
185 | } | 192 | } |
186 | 193 | ||
187 | /** | 194 | /** |
188 | * Prompt the user to see if they really want to do this. | 195 | * Prompt the user to see if they really want to do this. |
189 | * If they do then remove from the list and unload. | 196 | * If they do then remove from the list and unload. |
190 | */ | 197 | */ |
191 | void MainWindowImp::removeClicked(){ | 198 | void MainWindowImp::removeClicked(){ |
192 | QListViewItem *item = connectionList->currentItem(); | 199 | QListViewItem *item = connectionList->currentItem(); |
193 | if(!item) { | 200 | if(!item) { |
194 | QMessageBox::information(this, "Sorry","Please select an interface First.", "Ok"); | 201 | QMessageBox::information(this, "Sorry","Please select an interface First.", "Ok"); |
195 | return; | 202 | return; |
196 | } | 203 | } |
197 | 204 | ||
198 | Interface *i = interfaceItems[item]; | 205 | Interface *i = interfaceItems[item]; |
199 | if(i->getModuleOwner() == NULL){ | 206 | if(i->getModuleOwner() == NULL){ |
200 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); | 207 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); |
201 | } | 208 | } |
202 | else{ | 209 | else{ |
203 | if(!i->getModuleOwner()->remove(i)) | 210 | if(!i->getModuleOwner()->remove(i)) |
204 | QMessageBox::information(this, "Error", "Unable to remove.", "Ok"); | 211 | QMessageBox::information(this, "Error", "Unable to remove.", "Ok"); |
205 | else{ | 212 | else{ |
206 | QMessageBox::information(this, "Success", "Interface was removed.", "Ok"); | 213 | QMessageBox::information(this, "Success", "Interface was removed.", "Ok"); |
207 | // TODO memory managment.... | 214 | // TODO memory managment.... |
208 | // who deletes the interface? | 215 | // who deletes the interface? |
209 | } | 216 | } |
210 | } | 217 | } |
211 | } | 218 | } |
212 | 219 | ||
213 | /** | 220 | /** |
214 | * Pull up the configure about the currently selected interface. | 221 | * Pull up the configure about the currently selected interface. |
215 | * Report an error if no interface is selected. | 222 | * Report an error if no interface is selected. |
216 | * If the interface has a module owner then request its configure with a empty | 223 | * If the interface has a module owner then request its configure with a empty |
217 | * tab. If tab is !NULL then append the interfaces setup widget to it. | 224 | * tab. If tab is !NULL then append the interfaces setup widget to it. |
218 | */ | 225 | */ |
219 | void MainWindowImp::configureClicked(){ | 226 | void MainWindowImp::configureClicked(){ |
220 | QListViewItem *item = connectionList->currentItem(); | 227 | QListViewItem *item = connectionList->currentItem(); |
221 | if(!item){ | 228 | if(!item){ |
222 | QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); | 229 | QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); |
223 | return; | 230 | return; |
224 | } | 231 | } |
225 | 232 | ||
226 | QString currentProfile = currentProfileLabel->text(); | 233 | QString currentProfile = currentProfileLabel->text(); |
227 | if(profilesList->count() <= 1 || currentProfile == "All"){ | 234 | if(profilesList->count() <= 1 || currentProfile == "All"){ |
228 | currentProfile = ""; | 235 | currentProfile = ""; |
229 | } | 236 | } |
230 | 237 | ||
231 | Interface *i = interfaceItems[item]; | 238 | Interface *i = interfaceItems[item]; |
232 | if(i->getModuleOwner()){ | 239 | if(i->getModuleOwner()){ |
233 | i->getModuleOwner()->setProfile(currentProfile); | 240 | i->getModuleOwner()->setProfile(currentProfile); |
234 | QTabWidget *tabWidget = NULL; | 241 | QTabWidget *tabWidget = NULL; |
235 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i, &tabWidget); | 242 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i, &tabWidget); |
236 | if(moduleConfigure != NULL){ | 243 | if(moduleConfigure != NULL){ |
237 | if(tabWidget != NULL){ | 244 | if(tabWidget != NULL){ |
238 | InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); | 245 | InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); |
239 | configure->setProfile(currentProfile); | 246 | configure->setProfile(currentProfile); |
240 | tabWidget->insertTab(configure, "TCP/IP"); | 247 | tabWidget->insertTab(configure, "TCP/IP"); |
241 | 248 | ||
242 | } | 249 | } |
243 | moduleConfigure->showMaximized(); | 250 | moduleConfigure->showMaximized(); |
244 | moduleConfigure->show(); | 251 | moduleConfigure->show(); |
245 | return; | 252 | return; |
246 | } | 253 | } |
247 | } | 254 | } |
248 | 255 | ||
249 | InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); | 256 | InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); |
250 | configure->setProfile(currentProfile); | 257 | configure->setProfile(currentProfile); |
251 | configure->showMaximized(); | 258 | configure->showMaximized(); |
252 | configure->show(); | 259 | configure->show(); |
253 | } | 260 | } |
254 | 261 | ||
255 | /** | 262 | /** |
256 | * Pull up the information about the currently selected interface. | 263 | * Pull up the information about the currently selected interface. |
257 | * Report an error if no interface is selected. | 264 | * Report an error if no interface is selected. |
258 | * If the interface has a module owner then request its configure with a empty | 265 | * If the interface has a module owner then request its configure with a empty |
259 | * tab. If tab is !NULL then append the interfaces setup widget to it. | 266 | * tab. If tab is !NULL then append the interfaces setup widget to it. |
260 | */ | 267 | */ |
261 | void MainWindowImp::informationClicked(){ | 268 | void MainWindowImp::informationClicked(){ |
262 | QListViewItem *item = connectionList->currentItem(); | 269 | QListViewItem *item = connectionList->currentItem(); |
263 | if(!item){ | 270 | if(!item){ |
264 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); | 271 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
265 | return; | 272 | return; |
266 | } | 273 | } |
267 | 274 | ||
268 | Interface *i = interfaceItems[item]; | 275 | Interface *i = interfaceItems[item]; |
269 | if(!i->isAttached()){ | 276 | if(!i->isAttached()){ |
270 | QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); | 277 | QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); |
271 | return; | 278 | return; |
272 | } | 279 | } |
273 | 280 | ||
274 | QStringList list; | 281 | QStringList list; |
275 | for(uint i = 0; i < profilesList->count(); i++){ | 282 | for(uint i = 0; i < profilesList->count(); i++){ |
276 | list.append(profilesList->text(i)); | 283 | list.append(profilesList->text(i)); |
277 | } | 284 | } |
278 | 285 | ||
279 | if(i->getModuleOwner()){ | 286 | if(i->getModuleOwner()){ |
280 | QTabWidget *tabWidget = NULL; | 287 | QTabWidget *tabWidget = NULL; |
281 | QWidget *moduleInformation = i->getModuleOwner()->information(i, &tabWidget); | 288 | QWidget *moduleInformation = i->getModuleOwner()->information(i, &tabWidget); |
282 | if(moduleInformation != NULL){ | 289 | if(moduleInformation != NULL){ |
283 | if(tabWidget != NULL){ | 290 | if(tabWidget != NULL){ |
284 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); | 291 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); |
285 | tabWidget->insertTab(information, "TCP/IP"); | 292 | tabWidget->insertTab(information, "TCP/IP"); |
286 | } | 293 | } |
287 | moduleInformation->showMaximized(); | 294 | moduleInformation->showMaximized(); |
288 | moduleInformation->show(); | 295 | moduleInformation->show(); |
289 | return; | 296 | return; |
290 | } | 297 | } |
291 | } | 298 | } |
292 | 299 | ||
293 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); | 300 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); |
294 | information->showMaximized(); | 301 | information->showMaximized(); |
295 | information->show(); | 302 | information->show(); |
296 | } | 303 | } |
297 | 304 | ||
298 | /** | 305 | /** |
299 | * Aquire the list of active interfaces from ifconfig | 306 | * Aquire the list of active interfaces from ifconfig |
300 | * Call ifconfig and ifconfig -a | 307 | * Call ifconfig and ifconfig -a |
301 | */ | 308 | */ |
302 | void MainWindowImp::getInterfaceList(){ | 309 | void MainWindowImp::getInterfaceList(){ |
303 | KShellProcess *processAll = new KShellProcess(); | 310 | KShellProcess *processAll = new KShellProcess(); |
304 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; | 311 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; |
305 | connect(processAll, SIGNAL(processExited(KProcess *)), | 312 | connect(processAll, SIGNAL(processExited(KProcess *)), |
306 | this, SLOT(jobDone(KProcess *))); | 313 | this, SLOT(jobDone(KProcess *))); |
307 | threads.insert(processAll, TEMP_ALL); | 314 | threads.insert(processAll, TEMP_ALL); |
308 | 315 | ||
309 | KShellProcess *process = new KShellProcess(); | 316 | KShellProcess *process = new KShellProcess(); |
310 | *process << "/sbin/ifconfig" << " > " TEMP_UP; | 317 | *process << "/sbin/ifconfig" << " > " TEMP_UP; |
311 | connect(process, SIGNAL(processExited(KProcess *)), | 318 | connect(process, SIGNAL(processExited(KProcess *)), |
312 | this, SLOT(jobDone(KProcess *))); | 319 | this, SLOT(jobDone(KProcess *))); |
313 | threads.insert(process, TEMP_UP); | 320 | threads.insert(process, TEMP_UP); |
314 | 321 | ||
315 | processAll->start(KShellProcess::NotifyOnExit); | 322 | processAll->start(KShellProcess::NotifyOnExit); |
316 | process->start(KShellProcess::NotifyOnExit); | 323 | process->start(KShellProcess::NotifyOnExit); |
317 | } | 324 | } |
318 | 325 | ||
319 | void MainWindowImp::jobDone(KProcess *process){ | 326 | void MainWindowImp::jobDone(KProcess *process){ |
320 | QString fileName = threads[process]; | 327 | QString fileName = threads[process]; |
321 | threads.remove(process); | 328 | threads.remove(process); |
322 | delete process; | 329 | delete process; |
323 | 330 | ||
324 | QFile file(fileName); | 331 | QFile file(fileName); |
325 | if (!file.open(IO_ReadOnly)){ | 332 | if (!file.open(IO_ReadOnly)){ |
326 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); | 333 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); |
327 | return; | 334 | return; |
328 | } | 335 | } |
329 | 336 | ||
330 | QTextStream stream( &file ); | 337 | QTextStream stream( &file ); |
331 | QString line; | 338 | QString line; |
332 | while ( !stream.eof() ) { | 339 | while ( !stream.eof() ) { |
333 | line = stream.readLine(); | 340 | line = stream.readLine(); |
334 | int space = line.find(" "); | 341 | int space = line.find(" "); |
335 | if(space > 1){ | 342 | if(space > 1){ |
336 | // We have found an interface | 343 | // We have found an interface |
337 | QString interfaceName = line.mid(0, space); | 344 | QString interfaceName = line.mid(0, space); |
338 | Interface *i; | 345 | Interface *i; |
339 | // We have found an interface | 346 | // We have found an interface |
340 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | 347 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); |
341 | // See if we already have it | 348 | // See if we already have it |
342 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ | 349 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ |
343 | if(fileName == TEMP_ALL) | 350 | if(fileName == TEMP_ALL) |
344 | i = new Interface(this, interfaceName, false); | 351 | i = new Interface(this, interfaceName, false); |
345 | else | 352 | else |
346 | i = new Interface(this, interfaceName, true); | 353 | i = new Interface(this, interfaceName, true); |
347 | i->setAttached(true); | 354 | i->setAttached(true); |
348 | 355 | ||
349 | QString hardName = "Ethernet"; | 356 | QString hardName = "Ethernet"; |
350 | int hardwareName = line.find("Link encap:"); | 357 | int hardwareName = line.find("Link encap:"); |
351 | int macAddress = line.find("HWaddr"); | 358 | int macAddress = line.find("HWaddr"); |
352 | if(macAddress == -1) | 359 | if(macAddress == -1) |
353 | macAddress = line.length(); | 360 | macAddress = line.length(); |
354 | if(hardwareName != -1) | 361 | if(hardwareName != -1) |
355 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) ); | 362 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) ); |
356 | 363 | ||
357 | interfaceNames.insert(i->getInterfaceName(), i); | 364 | interfaceNames.insert(i->getInterfaceName(), i); |
358 | updateInterface(i); | 365 | updateInterface(i); |
359 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 366 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
360 | } | 367 | } |
361 | // It was an interface we already had. | 368 | // It was an interface we already had. |
362 | else{ | 369 | else{ |
363 | if(fileName != TEMP_ALL) | 370 | if(fileName != TEMP_ALL) |
364 | (interfaceNames[interfaceName])->setStatus(true); | 371 | (interfaceNames[interfaceName])->setStatus(true); |
365 | } | 372 | } |
366 | } | 373 | } |
367 | } | 374 | } |
368 | file.close(); | 375 | file.close(); |
369 | QFile::remove(fileName); | 376 | QFile::remove(fileName); |
370 | 377 | ||
371 | if(threads.count() == 0){ | 378 | if(threads.count() == 0){ |
372 | Interfaces i; | 379 | Interfaces i; |
373 | QStringList list = i.getInterfaceList(); | 380 | QStringList list = i.getInterfaceList(); |
374 | QMap<QString, Interface*>::Iterator it; | 381 | QMap<QString, Interface*>::Iterator it; |
375 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | 382 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { |
376 | bool found = false; | 383 | bool found = false; |
377 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | 384 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ |
378 | if(it.key() == (*ni)) | 385 | if(it.key() == (*ni)) |
379 | found = true; | 386 | found = true; |
380 | } | 387 | } |
381 | if(!found){ | 388 | if(!found){ |
382 | if(!(*ni).contains("_")){ | 389 | if(!(*ni).contains("_")){ |
383 | Interface *i = new Interface(this, *ni, false); | 390 | Interface *i = new Interface(this, *ni, false); |
384 | i->setAttached(false); | 391 | i->setAttached(false); |
385 | i->setHardwareName("Disconnected"); | 392 | i->setHardwareName("Disconnected"); |
386 | interfaceNames.insert(i->getInterfaceName(), i); | 393 | interfaceNames.insert(i->getInterfaceName(), i); |
387 | updateInterface(i); | 394 | updateInterface(i); |
388 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 395 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
389 | } | 396 | } |
390 | } | 397 | } |
391 | } | 398 | } |
392 | } | 399 | } |
393 | } | 400 | } |
394 | 401 | ||
395 | /** | 402 | /** |
396 | * Update this interface. If no QListViewItem exists create one. | 403 | * Update this interface. If no QListViewItem exists create one. |
397 | * @param Interface* pointer to the interface that needs to be updated. | 404 | * @param Interface* pointer to the interface that needs to be updated. |
398 | */ | 405 | */ |
399 | void MainWindowImp::updateInterface(Interface *i){ | 406 | void MainWindowImp::updateInterface(Interface *i){ |
400 | if(!advancedUserMode){ | 407 | if(!advancedUserMode){ |
401 | if(i->getInterfaceName() == "lo") | 408 | if(i->getInterfaceName() == "lo") |
402 | return; | 409 | return; |
403 | } | 410 | } |
404 | 411 | ||
405 | QListViewItem *item = NULL; | 412 | QListViewItem *item = NULL; |
406 | 413 | ||
407 | // Find the interface, making it if needed. | 414 | // Find the interface, making it if needed. |
408 | if(items.find(i) == items.end()){ | 415 | if(items.find(i) == items.end()){ |
409 | item = new QListViewItem(connectionList, "", "", ""); | 416 | item = new QListViewItem(connectionList, "", "", ""); |
410 | // See if you can't find a module owner for this interface | 417 | // See if you can't find a module owner for this interface |
411 | QMap<Module*, QLibrary*>::Iterator it; | 418 | QMap<Module*, QLibrary*>::Iterator it; |
412 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 419 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
413 | if(it.key()->isOwner(i)) | 420 | if(it.key()->isOwner(i)) |
414 | i->setModuleOwner(it.key()); | 421 | i->setModuleOwner(it.key()); |
415 | } | 422 | } |
416 | items.insert(i, item); | 423 | items.insert(i, item); |
417 | interfaceItems.insert(item, i); | 424 | interfaceItems.insert(item, i); |
418 | } | 425 | } |
419 | else | 426 | else |
420 | item = items[i]; | 427 | item = items[i]; |
421 | 428 | ||
422 | // Update the icons and information | 429 | // Update the icons and information |
423 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 430 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
424 | 431 | ||
425 | QString typeName = "lan"; | 432 | QString typeName = "lan"; |
426 | if(i->getHardwareName().contains("Local Loopback")) | 433 | if(i->getHardwareName().contains("Local Loopback")) |
427 | typeName = "lo"; | 434 | typeName = "lo"; |
428 | if(i->getInterfaceName().contains("irda")) | 435 | if(i->getInterfaceName().contains("irda")) |
429 | typeName = "irda"; | 436 | typeName = "irda"; |
430 | if(i->getInterfaceName().contains("wlan")) | 437 | if(i->getInterfaceName().contains("wlan")) |
431 | typeName = "wlan"; | 438 | typeName = "wlan"; |
432 | if(i->getInterfaceName().contains("usb")) | 439 | if(i->getInterfaceName().contains("usb")) |
433 | typeName = "usb"; | 440 | typeName = "usb"; |
434 | 441 | ||
435 | if(!i->isAttached()) | 442 | if(!i->isAttached()) |
436 | typeName = "connect_no"; | 443 | typeName = "connect_no"; |
437 | // Actually try to use the Module | 444 | // Actually try to use the Module |
438 | if(i->getModuleOwner() != NULL) | 445 | if(i->getModuleOwner() != NULL) |
439 | typeName = i->getModuleOwner()->getPixmapName(i); | 446 | typeName = i->getModuleOwner()->getPixmapName(i); |
440 | 447 | ||
441 | item->setPixmap(1, (Resource::loadPixmap(typeName))); | 448 | item->setPixmap(1, (Resource::loadPixmap(typeName))); |
442 | item->setText(2, i->getHardwareName()); | 449 | item->setText(2, i->getHardwareName()); |
443 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); | 450 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); |
444 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); | 451 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); |
445 | } | 452 | } |
446 | 453 | ||
447 | void MainWindowImp::newProfileChanged(const QString& newText){ | 454 | void MainWindowImp::newProfileChanged(const QString& newText){ |
448 | if(newText.length() > 0) | 455 | if(newText.length() > 0) |
449 | newProfileButton->setEnabled(true); | 456 | newProfileButton->setEnabled(true); |
450 | else | 457 | else |
451 | newProfileButton->setEnabled(false); | 458 | newProfileButton->setEnabled(false); |
452 | } | 459 | } |
453 | 460 | ||
454 | /** | 461 | /** |
455 | * Adds a new profile to the list of profiles. | 462 | * Adds a new profile to the list of profiles. |
456 | * Don't add profiles that already exists. | 463 | * Don't add profiles that already exists. |
457 | * Appends to the list and QStringList | 464 | * Appends to the list and QStringList |
458 | */ | 465 | */ |
459 | void MainWindowImp::addProfile(){ | 466 | void MainWindowImp::addProfile(){ |
460 | QString newProfileName = newProfile->text(); | 467 | QString newProfileName = newProfile->text(); |
461 | if(profiles.grep(newProfileName).count() > 0){ | 468 | if(profiles.grep(newProfileName).count() > 0){ |
462 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); | 469 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); |
463 | return; | 470 | return; |
464 | } | 471 | } |
465 | profiles.append(newProfileName); | 472 | profiles.append(newProfileName); |
466 | profilesList->insertItem(newProfileName); | 473 | profilesList->insertItem(newProfileName); |
467 | } | 474 | } |
468 | 475 | ||
469 | /** | 476 | /** |
diff --git a/noncore/settings/networksettings/wlan/wlanmodule.cpp b/noncore/settings/networksettings/wlan/wlanmodule.cpp index cbb520d..24cb1cd 100644 --- a/noncore/settings/networksettings/wlan/wlanmodule.cpp +++ b/noncore/settings/networksettings/wlan/wlanmodule.cpp | |||
@@ -1,223 +1,222 @@ | |||
1 | #include "wlanmodule.h" | 1 | #include "wlanmodule.h" |
2 | #include <qpe/config.h> | ||
3 | #include "wlanimp.h" | 2 | #include "wlanimp.h" |
4 | #include "info.h" | 3 | #include "info.h" |
5 | 4 | ||
6 | |||
7 | #include <arpa/inet.h> | 5 | #include <arpa/inet.h> |
8 | #include <sys/socket.h> | 6 | #include <sys/socket.h> |
9 | #include <linux/if_ether.h> | 7 | #include <linux/if_ether.h> |
10 | #include <netinet/ip.h> | 8 | #include <netinet/ip.h> |
11 | #include <sys/ioctl.h> | 9 | #include <sys/ioctl.h> |
12 | #include <linux/wireless.h> | 10 | #include <linux/wireless.h> |
13 | 11 | ||
14 | #include <unistd.h> | 12 | #include <unistd.h> |
15 | #include <math.h> | 13 | #include <math.h> |
16 | #include <errno.h> | 14 | #include <errno.h> |
17 | #include <string.h> | 15 | #include <string.h> |
18 | #include <stdio.h> | 16 | #include <stdio.h> |
19 | 17 | ||
20 | #include <stdlib.h> | 18 | #include <stdlib.h> |
21 | 19 | ||
22 | #include <qlabel.h> | 20 | #include <qlabel.h> |
23 | 21 | ||
24 | /** | 22 | /** |
25 | * Constructor, find all of the possible interfaces | 23 | * Constructor, find all of the possible interfaces |
26 | */ | 24 | */ |
27 | WLANModule::WLANModule() : Module() { | 25 | WLANModule::WLANModule() : Module() { |
28 | // get output from iwconfig | 26 | // get output from iwconfig |
29 | } | 27 | } |
30 | 28 | ||
31 | /** | 29 | /** |
32 | * Change the current profile | 30 | * Change the current profile |
33 | */ | 31 | */ |
34 | void WLANModule::setProfile(QString newProfile){ | 32 | void WLANModule::setProfile(QString newProfile){ |
35 | profile = newProfile; | 33 | profile = newProfile; |
36 | } | 34 | } |
37 | 35 | ||
38 | /** | 36 | /** |
39 | * get the icon name for this device. | 37 | * get the icon name for this device. |
40 | * @param Interface* can be used in determining the icon. | 38 | * @param Interface* can be used in determining the icon. |
41 | * @return QString the icon name (minus .png, .gif etc) | 39 | * @return QString the icon name (minus .png, .gif etc) |
42 | */ | 40 | */ |
43 | QString WLANModule::getPixmapName(Interface* ){ | 41 | QString WLANModule::getPixmapName(Interface* ){ |
44 | return "wlan"; | 42 | return "wlan"; |
45 | } | 43 | } |
46 | 44 | ||
47 | /** | 45 | /** |
48 | * Check to see if the interface i is owned by this module. | 46 | * Check to see if the interface i is owned by this module. |
49 | * @param Interface* interface to check against | 47 | * @param Interface* interface to check against |
50 | * @return bool true if i is owned by this module, false otherwise. | 48 | * @return bool true if i is owned by this module, false otherwise. |
51 | */ | 49 | */ |
52 | bool WLANModule::isOwner(Interface *i){ | 50 | bool WLANModule::isOwner(Interface *i){ |
53 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ | 51 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ |
54 | i->setHardwareName("802.11b"); | 52 | i->setHardwareName("802.11b"); |
55 | return true; | 53 | return true; |
56 | } | 54 | } |
57 | return false; | 55 | return false; |
58 | } | 56 | } |
59 | 57 | ||
60 | /** | 58 | /** |
61 | * Create, set tabWiget and return the WLANConfigure Module | 59 | * Create, set tabWiget and return the WLANConfigure Module |
62 | * @param tabWidget a pointer to the tab widget that this configure has. | 60 | * @param tabWidget a pointer to the tab widget that this configure has. |
63 | * @return QWidget* pointer to the tab widget in this modules configure. | 61 | * @return QWidget* pointer to the tab widget in this modules configure. |
64 | */ | 62 | */ |
65 | QWidget *WLANModule::configure(Interface *i, QTabWidget **tabWidget){ | 63 | QWidget *WLANModule::configure(Interface *i, QTabWidget **tabWidget){ |
66 | WLANImp *wlanconfig = new WLANImp( ); | 64 | WLANImp *wlanconfig = new WLANImp(0, "WlanConfig"); |
67 | (*tabWidget) = wlanconfig->tabWidget; | 65 | (*tabWidget) = wlanconfig->tabWidget; |
68 | return wlanconfig; | 66 | return wlanconfig; |
69 | } | 67 | } |
70 | 68 | ||
71 | /** | 69 | /** |
72 | * Create, set tabWiget and return the Information Module | 70 | * Create, set tabWiget and return the Information Module |
73 | * @param tabWidget a pointer to the tab widget that this information has. | 71 | * @param tabWidget a pointer to the tab widget that this information has. |
74 | * @return QWidget* pointer to the tab widget in this modules info. | 72 | * @return QWidget* pointer to the tab widget in this modules info. |
75 | */ | 73 | */ |
76 | QWidget *WLANModule::information(Interface *i, QTabWidget **tabWidget){ | 74 | QWidget *WLANModule::information(Interface *i, QTabWidget **tabWidget){ |
75 | return NULL; | ||
77 | WlanInfo *info = new WlanInfo(0, "wireless info"); | 76 | WlanInfo *info = new WlanInfo(0, "wireless info"); |
78 | (*tabWidget) = info->tabWidget; | 77 | (*tabWidget) = info->tabWidget; |
79 | 78 | ||
80 | struct ifreq ifr; | 79 | struct ifreq ifr; |
81 | struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; | 80 | struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; |
82 | int fd = socket( AF_INET, SOCK_DGRAM, 0 ); | 81 | int fd = socket( AF_INET, SOCK_DGRAM, 0 ); |
83 | 82 | ||
84 | const char* buffer[200]; | 83 | const char* buffer[200]; |
85 | struct iwreq iwr; | 84 | struct iwreq iwr; |
86 | memset( &iwr, 0, sizeof( iwr ) ); | 85 | memset( &iwr, 0, sizeof( iwr ) ); |
87 | iwr.u.essid.pointer = (caddr_t) buffer; | 86 | iwr.u.essid.pointer = (caddr_t) buffer; |
88 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 87 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
89 | iwr.u.essid.flags = 0; | 88 | iwr.u.essid.flags = 0; |
90 | 89 | ||
91 | // check if it is an IEEE 802.11 standard conform | 90 | // check if it is an IEEE 802.11 standard conform |
92 | // wireless device by sending SIOCGIWESSID | 91 | // wireless device by sending SIOCGIWESSID |
93 | // which also gives back the Extended Service Set ID | 92 | // which also gives back the Extended Service Set ID |
94 | // (see IEEE 802.11 for more information) | 93 | // (see IEEE 802.11 for more information) |
95 | 94 | ||
96 | QString n = (i->getInterfaceName()); | 95 | QString n = (i->getInterfaceName()); |
97 | const char* iname = n.latin1(); | 96 | const char* iname = n.latin1(); |
98 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); | 97 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); |
99 | int result = ioctl( fd, SIOCGIWESSID, &iwr ); | 98 | int result = ioctl( fd, SIOCGIWESSID, &iwr ); |
100 | if ( result == 0 ){ | 99 | if ( result == 0 ){ |
101 | //hasWirelessExtensions = true; | 100 | //hasWirelessExtensions = true; |
102 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; | 101 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; |
103 | info->essidLabel->setText(QString(iwr.u.essid.pointer)); | 102 | info->essidLabel->setText(QString(iwr.u.essid.pointer)); |
104 | } | 103 | } |
105 | else | 104 | else |
106 | return info; | 105 | return info; |
107 | //info->essidLabel->setText("*** Unknown ***"); | 106 | //info->essidLabel->setText("*** Unknown ***"); |
108 | 107 | ||
109 | // Address of associated access-point | 108 | // Address of associated access-point |
110 | result = ioctl( fd, SIOCGIWAP, &iwr ); | 109 | result = ioctl( fd, SIOCGIWAP, &iwr ); |
111 | if ( result == 0 ){ | 110 | if ( result == 0 ){ |
112 | QString foo = foo.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 111 | QString foo = foo.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
113 | iwr.u.ap_addr.sa_data[0]&0xff, | 112 | iwr.u.ap_addr.sa_data[0]&0xff, |
114 | iwr.u.ap_addr.sa_data[1]&0xff, | 113 | iwr.u.ap_addr.sa_data[1]&0xff, |
115 | iwr.u.ap_addr.sa_data[2]&0xff, | 114 | iwr.u.ap_addr.sa_data[2]&0xff, |
116 | iwr.u.ap_addr.sa_data[3]&0xff, | 115 | iwr.u.ap_addr.sa_data[3]&0xff, |
117 | iwr.u.ap_addr.sa_data[4]&0xff, | 116 | iwr.u.ap_addr.sa_data[4]&0xff, |
118 | iwr.u.ap_addr.sa_data[5]&0xff ); | 117 | iwr.u.ap_addr.sa_data[5]&0xff ); |
119 | info->apLabel->setText(foo); | 118 | info->apLabel->setText(foo); |
120 | } | 119 | } |
121 | else info->apLabel->setText("*** Unknown ***"); | 120 | else info->apLabel->setText("*** Unknown ***"); |
122 | 121 | ||
123 | iwr.u.data.pointer = (caddr_t) buffer; | 122 | iwr.u.data.pointer = (caddr_t) buffer; |
124 | iwr.u.data.length = IW_ESSID_MAX_SIZE; | 123 | iwr.u.data.length = IW_ESSID_MAX_SIZE; |
125 | iwr.u.data.flags = 0; | 124 | iwr.u.data.flags = 0; |
126 | result = ioctl( fd, SIOCGIWNICKN, &iwr ); | 125 | result = ioctl( fd, SIOCGIWNICKN, &iwr ); |
127 | if ( result == 0 ){ | 126 | if ( result == 0 ){ |
128 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; | 127 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; |
129 | info->stationLabel->setText(iwr.u.data.pointer); | 128 | info->stationLabel->setText(iwr.u.data.pointer); |
130 | } | 129 | } |
131 | else info->stationLabel->setText("*** Unknown ***"); | 130 | else info->stationLabel->setText("*** Unknown ***"); |
132 | 131 | ||
133 | result = ioctl( fd, SIOCGIWMODE, &iwr ); | 132 | result = ioctl( fd, SIOCGIWMODE, &iwr ); |
134 | if ( result == 0 ) | 133 | if ( result == 0 ) |
135 | info->modeLabel->setText( QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed")); | 134 | info->modeLabel->setText( QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed")); |
136 | else | 135 | else |
137 | info->modeLabel->setText("*** Unknown ***"); | 136 | info->modeLabel->setText("*** Unknown ***"); |
138 | 137 | ||
139 | result = ioctl( fd, SIOCGIWFREQ, &iwr ); | 138 | result = ioctl( fd, SIOCGIWFREQ, &iwr ); |
140 | if ( result == 0 ) | 139 | if ( result == 0 ) |
141 | info->freqLabel->setText(QString("%1").arg((double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000))); | 140 | info->freqLabel->setText(QString("%1").arg((double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000))); |
142 | else | 141 | else |
143 | info->freqLabel->setText("*** Unknown ***"); | 142 | info->freqLabel->setText("*** Unknown ***"); |
144 | 143 | ||
145 | /* | 144 | /* |
146 | // gather link quality from /proc/net/wireless | 145 | // gather link quality from /proc/net/wireless |
147 | 146 | ||
148 | char c; | 147 | char c; |
149 | QString status; | 148 | QString status; |
150 | QString name; | 149 | QString name; |
151 | QFile wfile( PROCNETWIRELESS ); | 150 | QFile wfile( PROCNETWIRELESS ); |
152 | bool hasFile = wfile.open( IO_ReadOnly ); | 151 | bool hasFile = wfile.open( IO_ReadOnly ); |
153 | QTextStream wstream( &wfile ); | 152 | QTextStream wstream( &wfile ); |
154 | if ( hasFile ) | 153 | if ( hasFile ) |
155 | { | 154 | { |
156 | wstream.readLine(); // skip the first two lines | 155 | wstream.readLine(); // skip the first two lines |
157 | wstream.readLine(); // because they only contain headers | 156 | wstream.readLine(); // because they only contain headers |
158 | } | 157 | } |
159 | if ( ( !hasFile ) || ( wstream.atEnd() ) ) | 158 | if ( ( !hasFile ) || ( wstream.atEnd() ) ) |
160 | { | 159 | { |
161 | #ifdef MDEBUG | 160 | #ifdef MDEBUG |
162 | qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); | 161 | qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); |
163 | #endif | 162 | #endif |
164 | quality = -1; | 163 | quality = -1; |
165 | signal = IW_LOWER; | 164 | signal = IW_LOWER; |
166 | noise = IW_LOWER; | 165 | noise = IW_LOWER; |
167 | return false; | 166 | return false; |
168 | } | 167 | } |
169 | 168 | ||
170 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; | 169 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; |
171 | 170 | ||
172 | if ( quality > 92 ) | 171 | if ( quality > 92 ) |
173 | #ifdef MDEBUG | 172 | #ifdef MDEBUG |
174 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); | 173 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); |
175 | #endif | 174 | #endif |
176 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) | 175 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) |
177 | #ifdef MDEBUG | 176 | #ifdef MDEBUG |
178 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); | 177 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); |
179 | #endif | 178 | #endif |
180 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) | 179 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) |
181 | #ifdef MDEBUG | 180 | #ifdef MDEBUG |
182 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); | 181 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); |
183 | #endif | 182 | #endif |
184 | 183 | ||
185 | return true; | 184 | return true; |
186 | 185 | ||
187 | } | 186 | } |
188 | */ | 187 | */ |
189 | return info; | 188 | return info; |
190 | } | 189 | } |
191 | 190 | ||
192 | /** | 191 | /** |
193 | * Get all active (up or down) interfaces | 192 | * Get all active (up or down) interfaces |
194 | * @return QList<Interface> A list of interfaces that exsist that havn't | 193 | * @return QList<Interface> A list of interfaces that exsist that havn't |
195 | * been called by isOwner() | 194 | * been called by isOwner() |
196 | */ | 195 | */ |
197 | QList<Interface> WLANModule::getInterfaces(){ | 196 | QList<Interface> WLANModule::getInterfaces(){ |
198 | return list; | 197 | return list; |
199 | } | 198 | } |
200 | 199 | ||
201 | /** | 200 | /** |
202 | * Attempt to add a new interface as defined by name | 201 | * Attempt to add a new interface as defined by name |
203 | * @param name the name of the type of interface that should be created given | 202 | * @param name the name of the type of interface that should be created given |
204 | * by possibleNewInterfaces(); | 203 | * by possibleNewInterfaces(); |
205 | * @return Interface* NULL if it was unable to be created. | 204 | * @return Interface* NULL if it was unable to be created. |
206 | */ | 205 | */ |
207 | Interface *WLANModule::addNewInterface(QString ){ | 206 | Interface *WLANModule::addNewInterface(QString ){ |
208 | // We can't add a 802.11 interface, either the hardware will be there | 207 | // We can't add a 802.11 interface, either the hardware will be there |
209 | // or it wont. | 208 | // or it wont. |
210 | return NULL; | 209 | return NULL; |
211 | } | 210 | } |
212 | 211 | ||
213 | /** | 212 | /** |
214 | * Attempts to remove the interface, doesn't delete i | 213 | * Attempts to remove the interface, doesn't delete i |
215 | * @return bool true if successfull, false otherwise. | 214 | * @return bool true if successfull, false otherwise. |
216 | */ | 215 | */ |
217 | bool WLANModule::remove(Interface*){ | 216 | bool WLANModule::remove(Interface*){ |
218 | // Can't remove a hardware device, you can stop it though. | 217 | // Can't remove a hardware device, you can stop it though. |
219 | return false; | 218 | return false; |
220 | } | 219 | } |
221 | 220 | ||
222 | // wlanmodule.cpp | 221 | // wlanmodule.cpp |
223 | 222 | ||