author | benmeyer <benmeyer> | 2002-10-18 18:31:02 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-10-18 18:31:02 (UTC) |
commit | 081001a515f23626b6299e39af4511f36db46d07 (patch) (unidiff) | |
tree | b27ce76464c60452c54c10dca9bcd95b34bd56a9 | |
parent | 83a8418d4d4eb94a2cf0d8c89742aef2dfc3ed40 (diff) | |
download | opie-081001a515f23626b6299e39af4511f36db46d07.zip opie-081001a515f23626b6299e39af4511f36db46d07.tar.gz opie-081001a515f23626b6299e39af4511f36db46d07.tar.bz2 |
Updated TODO
-rw-r--r-- | noncore/net/networksetup/TODO | 13 | ||||
-rw-r--r-- | noncore/net/networksetup/mainwindowimp.cpp | 8 | ||||
-rw-r--r-- | noncore/settings/networksettings/TODO | 13 | ||||
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 8 |
4 files changed, 26 insertions, 16 deletions
diff --git a/noncore/net/networksetup/TODO b/noncore/net/networksetup/TODO index c587f58..7a71142 100644 --- a/noncore/net/networksetup/TODO +++ b/noncore/net/networksetup/TODO | |||
@@ -1,6 +1,11 @@ | |||
1 | Write a class that parses /proc and not ifconfig | ||
2 | WLAN needs to be re-written to not use Config | 1 | WLAN needs to be re-written to not use Config |
3 | remove WLAN Config item | 2 | -remove WLAN Config item |
3 | -sub class out the wlan info | ||
4 | -check if an interface supports wireless extensions before config. | ||
5 | |||
6 | PPP module needs to be written | ||
7 | |||
8 | Write a class that parses /proc and not ifconfig | ||
9 | |||
10 | Possible other modules: ipsec, bluetooth | ||
4 | 11 | ||
5 | [ ] Wlanmodule needs to check if an interface supports wireless | ||
6 | extensions. | ||
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp index 8e4e898..843f630 100644 --- a/noncore/net/networksetup/mainwindowimp.cpp +++ b/noncore/net/networksetup/mainwindowimp.cpp | |||
@@ -1,551 +1,551 @@ | |||
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 Modules and Libraries | 86 | // Delete Modules and Libraries |
87 | QMap<Module*, QLibrary*>::Iterator it; | 87 | QMap<Module*, QLibrary*>::Iterator it; |
88 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 88 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
89 | delete it.key(); | 89 | delete it.key(); |
90 | delete it.data(); | 90 | delete it.data(); |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * Load all modules that are found in the path | 95 | * Load all modules that are found in the path |
96 | * @param path a directory that is scaned for any plugins that can be loaded | 96 | * @param path a directory that is scaned for any plugins that can be loaded |
97 | * and attempts to load them | 97 | * and attempts to load them |
98 | */ | 98 | */ |
99 | void MainWindowImp::loadModules(QString path){ | 99 | void MainWindowImp::loadModules(QString path){ |
100 | //qDebug(path.latin1()); | 100 | //qDebug(path.latin1()); |
101 | QDir d(path); | 101 | QDir d(path); |
102 | if(!d.exists()) | 102 | if(!d.exists()) |
103 | return; | 103 | return; |
104 | 104 | ||
105 | // Don't want sym links | 105 | // Don't want sym links |
106 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 106 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
107 | const QFileInfoList *list = d.entryInfoList(); | 107 | const QFileInfoList *list = d.entryInfoList(); |
108 | QFileInfoListIterator it( *list ); | 108 | QFileInfoListIterator it( *list ); |
109 | QFileInfo *fi; | 109 | QFileInfo *fi; |
110 | while ( (fi=it.current()) ) { | 110 | while ( (fi=it.current()) ) { |
111 | if(fi->fileName().contains(".so")){ | 111 | if(fi->fileName().contains(".so")){ |
112 | loadPlugin(path + "/" + fi->fileName()); | 112 | loadPlugin(path + "/" + fi->fileName()); |
113 | } | 113 | } |
114 | ++it; | 114 | ++it; |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | /** | 118 | /** |
119 | * Attempt to load a function and resolve a function. | 119 | * Attempt to load a function and resolve a function. |
120 | * @param pluginFileName - the name of the file in which to attempt to load | 120 | * @param pluginFileName - the name of the file in which to attempt to load |
121 | * @param resolveString - function pointer to resolve | 121 | * @param resolveString - function pointer to resolve |
122 | * @return pointer to the function with name resolveString or NULL | 122 | * @return pointer to the function with name resolveString or NULL |
123 | */ | 123 | */ |
124 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | 124 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ |
125 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); | 125 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); |
126 | QLibrary *lib = new QLibrary(pluginFileName); | 126 | QLibrary *lib = new QLibrary(pluginFileName); |
127 | void *functionPointer = lib->resolve(resolveString); | 127 | void *functionPointer = lib->resolve(resolveString); |
128 | if( !functionPointer ){ | 128 | if( !functionPointer ){ |
129 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 129 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
130 | delete lib; | 130 | delete lib; |
131 | return NULL; | 131 | return NULL; |
132 | } | 132 | } |
133 | 133 | ||
134 | // Try to get an object. | 134 | // Try to get an object. |
135 | Module *object = ((Module* (*)()) functionPointer)(); | 135 | Module *object = ((Module* (*)()) functionPointer)(); |
136 | if(object == NULL){ | 136 | if(object == NULL){ |
137 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 137 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
138 | delete lib; | 138 | delete lib; |
139 | return NULL; | 139 | return NULL; |
140 | } | 140 | } |
141 | 141 | ||
142 | // Store for deletion later | 142 | // Store for deletion later |
143 | libraries.insert(object, lib); | 143 | libraries.insert(object, lib); |
144 | return object; | 144 | return object; |
145 | } | 145 | } |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * The Add button was clicked. Bring up the add dialog and if OK is hit | 148 | * 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 | 149 | * load the plugin and append it to the list |
150 | */ | 150 | */ |
151 | void MainWindowImp::addClicked(){ | 151 | void MainWindowImp::addClicked(){ |
152 | QMap<Module*, QLibrary*>::Iterator it; | 152 | QMap<Module*, QLibrary*>::Iterator it; |
153 | QMap<QString, QString> list; | 153 | QMap<QString, QString> list; |
154 | QMap<QString, Module*> newInterfaceOwners; | 154 | QMap<QString, Module*> newInterfaceOwners; |
155 | list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); | 155 | 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"); | 156 | list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); |
157 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 157 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
158 | if(it.key()){ | 158 | if(it.key()){ |
159 | (it.key())->possibleNewInterfaces(list); | 159 | (it.key())->possibleNewInterfaces(list); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | // See if the list has anything that we can add. | 162 | // See if the list has anything that we can add. |
163 | if(list.count() == 0){ | 163 | if(list.count() == 0){ |
164 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); | 164 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); |
165 | return; | 165 | return; |
166 | } | 166 | } |
167 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); | 167 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); |
168 | addNewConnection.addConnections(list); | 168 | addNewConnection.addConnections(list); |
169 | addNewConnection.showMaximized(); | 169 | addNewConnection.showMaximized(); |
170 | if(QDialog::Accepted == addNewConnection.exec()){ | 170 | if(QDialog::Accepted == addNewConnection.exec()){ |
171 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); | 171 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); |
172 | if(!item) | 172 | if(!item) |
173 | return; | 173 | return; |
174 | 174 | ||
175 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 175 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
176 | if(it.key()){ | 176 | if(it.key()){ |
177 | Interface *i = (it.key())->addNewInterface(item->text(0)); | 177 | Interface *i = (it.key())->addNewInterface(item->text(0)); |
178 | if(i){ | 178 | if(i){ |
179 | interfaceNames.insert(i->getInterfaceName(), i); | 179 | interfaceNames.insert(i->getInterfaceName(), i); |
180 | updateInterface(i); | 180 | updateInterface(i); |
181 | } | 181 | } |
182 | } | 182 | } |
183 | } | 183 | } |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | /** | 187 | /** |
188 | * Prompt the user to see if they really want to do this. | 188 | * Prompt the user to see if they really want to do this. |
189 | * If they do then remove from the list and unload. | 189 | * If they do then remove from the list and unload. |
190 | */ | 190 | */ |
191 | void MainWindowImp::removeClicked(){ | 191 | void MainWindowImp::removeClicked(){ |
192 | QListViewItem *item = connectionList->currentItem(); | 192 | QListViewItem *item = connectionList->currentItem(); |
193 | if(!item) { | 193 | if(!item) { |
194 | QMessageBox::information(this, "Error","Please select an interface.", "Ok"); | 194 | QMessageBox::information(this, "Sorry","Please select an interface First.", "Ok"); |
195 | return; | 195 | return; |
196 | } | 196 | } |
197 | 197 | ||
198 | Interface *i = interfaceItems[item]; | 198 | Interface *i = interfaceItems[item]; |
199 | if(i->getModuleOwner() == NULL){ | 199 | if(i->getModuleOwner() == NULL){ |
200 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); | 200 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); |
201 | } | 201 | } |
202 | else{ | 202 | else{ |
203 | if(!i->getModuleOwner()->remove(i)) | 203 | if(!i->getModuleOwner()->remove(i)) |
204 | QMessageBox::information(this, "Error", "Unable to remove.", "Ok"); | 204 | QMessageBox::information(this, "Error", "Unable to remove.", "Ok"); |
205 | else{ | 205 | else{ |
206 | QMessageBox::information(this, "Success", "Interface was removed.", "Ok"); | 206 | QMessageBox::information(this, "Success", "Interface was removed.", "Ok"); |
207 | // TODO memory managment.... | 207 | // TODO memory managment.... |
208 | // who deletes the interface? | 208 | // who deletes the interface? |
209 | } | 209 | } |
210 | } | 210 | } |
211 | } | 211 | } |
212 | 212 | ||
213 | /** | 213 | /** |
214 | * Pull up the configure about the currently selected interface. | 214 | * Pull up the configure about the currently selected interface. |
215 | * Report an error if no interface is selected. | 215 | * Report an error if no interface is selected. |
216 | * If the interface has a module owner then request its configure with a empty | 216 | * 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. | 217 | * tab. If tab is !NULL then append the interfaces setup widget to it. |
218 | */ | 218 | */ |
219 | void MainWindowImp::configureClicked(){ | 219 | void MainWindowImp::configureClicked(){ |
220 | QListViewItem *item = connectionList->currentItem(); | 220 | QListViewItem *item = connectionList->currentItem(); |
221 | if(!item){ | 221 | if(!item){ |
222 | QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); | 222 | QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); |
223 | return; | 223 | return; |
224 | } | 224 | } |
225 | 225 | ||
226 | QString currentProfile = currentProfileLabel->text(); | 226 | QString currentProfile = currentProfileLabel->text(); |
227 | if(profilesList->count() <= 1 || currentProfile == "All"){ | 227 | if(profilesList->count() <= 1 || currentProfile == "All"){ |
228 | currentProfile = ""; | 228 | currentProfile = ""; |
229 | } | 229 | } |
230 | 230 | ||
231 | Interface *i = interfaceItems[item]; | 231 | Interface *i = interfaceItems[item]; |
232 | if(i->getModuleOwner()){ | 232 | if(i->getModuleOwner()){ |
233 | i->getModuleOwner()->setProfile(currentProfile); | 233 | i->getModuleOwner()->setProfile(currentProfile); |
234 | QTabWidget *tabWidget = NULL; | 234 | QTabWidget *tabWidget = NULL; |
235 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i, &tabWidget); | 235 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i, &tabWidget); |
236 | if(moduleConfigure != NULL){ | 236 | if(moduleConfigure != NULL){ |
237 | if(tabWidget != NULL){ | 237 | if(tabWidget != NULL){ |
238 | InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); | 238 | InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); |
239 | configure->setProfile(currentProfile); | 239 | configure->setProfile(currentProfile); |
240 | tabWidget->insertTab(configure, "TCP/IP"); | 240 | tabWidget->insertTab(configure, "TCP/IP"); |
241 | 241 | ||
242 | } | 242 | } |
243 | moduleConfigure->showMaximized(); | 243 | moduleConfigure->showMaximized(); |
244 | moduleConfigure->show(); | 244 | moduleConfigure->show(); |
245 | return; | 245 | return; |
246 | } | 246 | } |
247 | } | 247 | } |
248 | 248 | ||
249 | InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); | 249 | InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); |
250 | configure->setProfile(currentProfile); | 250 | configure->setProfile(currentProfile); |
251 | configure->showMaximized(); | 251 | configure->showMaximized(); |
252 | configure->show(); | 252 | configure->show(); |
253 | } | 253 | } |
254 | 254 | ||
255 | /** | 255 | /** |
256 | * Pull up the information about the currently selected interface. | 256 | * Pull up the information about the currently selected interface. |
257 | * Report an error if no interface is selected. | 257 | * Report an error if no interface is selected. |
258 | * If the interface has a module owner then request its configure with a empty | 258 | * 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. | 259 | * tab. If tab is !NULL then append the interfaces setup widget to it. |
260 | */ | 260 | */ |
261 | void MainWindowImp::informationClicked(){ | 261 | void MainWindowImp::informationClicked(){ |
262 | QListViewItem *item = connectionList->currentItem(); | 262 | QListViewItem *item = connectionList->currentItem(); |
263 | if(!item){ | 263 | if(!item){ |
264 | QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); | 264 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
265 | return; | 265 | return; |
266 | } | 266 | } |
267 | 267 | ||
268 | Interface *i = interfaceItems[item]; | 268 | Interface *i = interfaceItems[item]; |
269 | if(!i->isAttached()){ | 269 | if(!i->isAttached()){ |
270 | QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok); | 270 | QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); |
271 | return; | 271 | return; |
272 | } | 272 | } |
273 | 273 | ||
274 | QStringList list; | 274 | QStringList list; |
275 | for(uint i = 0; i < profilesList->count(); i++){ | 275 | for(uint i = 0; i < profilesList->count(); i++){ |
276 | list.append(profilesList->text(i)); | 276 | list.append(profilesList->text(i)); |
277 | } | 277 | } |
278 | 278 | ||
279 | if(i->getModuleOwner()){ | 279 | if(i->getModuleOwner()){ |
280 | QTabWidget *tabWidget = NULL; | 280 | QTabWidget *tabWidget = NULL; |
281 | QWidget *moduleInformation = i->getModuleOwner()->information(i, &tabWidget); | 281 | QWidget *moduleInformation = i->getModuleOwner()->information(i, &tabWidget); |
282 | if(moduleInformation != NULL){ | 282 | if(moduleInformation != NULL){ |
283 | if(tabWidget != NULL){ | 283 | if(tabWidget != NULL){ |
284 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); | 284 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); |
285 | tabWidget->insertTab(information, "TCP/IP"); | 285 | tabWidget->insertTab(information, "TCP/IP"); |
286 | } | 286 | } |
287 | moduleInformation->showMaximized(); | 287 | moduleInformation->showMaximized(); |
288 | moduleInformation->show(); | 288 | moduleInformation->show(); |
289 | return; | 289 | return; |
290 | } | 290 | } |
291 | } | 291 | } |
292 | 292 | ||
293 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); | 293 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); |
294 | information->showMaximized(); | 294 | information->showMaximized(); |
295 | information->show(); | 295 | information->show(); |
296 | } | 296 | } |
297 | 297 | ||
298 | /** | 298 | /** |
299 | * Aquire the list of active interfaces from ifconfig | 299 | * Aquire the list of active interfaces from ifconfig |
300 | * Call ifconfig and ifconfig -a | 300 | * Call ifconfig and ifconfig -a |
301 | */ | 301 | */ |
302 | void MainWindowImp::getInterfaceList(){ | 302 | void MainWindowImp::getInterfaceList(){ |
303 | KShellProcess *processAll = new KShellProcess(); | 303 | KShellProcess *processAll = new KShellProcess(); |
304 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; | 304 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; |
305 | connect(processAll, SIGNAL(processExited(KProcess *)), | 305 | connect(processAll, SIGNAL(processExited(KProcess *)), |
306 | this, SLOT(jobDone(KProcess *))); | 306 | this, SLOT(jobDone(KProcess *))); |
307 | threads.insert(processAll, TEMP_ALL); | 307 | threads.insert(processAll, TEMP_ALL); |
308 | 308 | ||
309 | KShellProcess *process = new KShellProcess(); | 309 | KShellProcess *process = new KShellProcess(); |
310 | *process << "/sbin/ifconfig" << " > " TEMP_UP; | 310 | *process << "/sbin/ifconfig" << " > " TEMP_UP; |
311 | connect(process, SIGNAL(processExited(KProcess *)), | 311 | connect(process, SIGNAL(processExited(KProcess *)), |
312 | this, SLOT(jobDone(KProcess *))); | 312 | this, SLOT(jobDone(KProcess *))); |
313 | threads.insert(process, TEMP_UP); | 313 | threads.insert(process, TEMP_UP); |
314 | 314 | ||
315 | processAll->start(KShellProcess::NotifyOnExit); | 315 | processAll->start(KShellProcess::NotifyOnExit); |
316 | process->start(KShellProcess::NotifyOnExit); | 316 | process->start(KShellProcess::NotifyOnExit); |
317 | } | 317 | } |
318 | 318 | ||
319 | void MainWindowImp::jobDone(KProcess *process){ | 319 | void MainWindowImp::jobDone(KProcess *process){ |
320 | QString fileName = threads[process]; | 320 | QString fileName = threads[process]; |
321 | threads.remove(process); | 321 | threads.remove(process); |
322 | delete process; | 322 | delete process; |
323 | 323 | ||
324 | QFile file(fileName); | 324 | QFile file(fileName); |
325 | if (!file.open(IO_ReadOnly)){ | 325 | if (!file.open(IO_ReadOnly)){ |
326 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); | 326 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); |
327 | return; | 327 | return; |
328 | } | 328 | } |
329 | 329 | ||
330 | QTextStream stream( &file ); | 330 | QTextStream stream( &file ); |
331 | QString line; | 331 | QString line; |
332 | while ( !stream.eof() ) { | 332 | while ( !stream.eof() ) { |
333 | line = stream.readLine(); | 333 | line = stream.readLine(); |
334 | int space = line.find(" "); | 334 | int space = line.find(" "); |
335 | if(space > 1){ | 335 | if(space > 1){ |
336 | // We have found an interface | 336 | // We have found an interface |
337 | QString interfaceName = line.mid(0, space); | 337 | QString interfaceName = line.mid(0, space); |
338 | Interface *i; | 338 | Interface *i; |
339 | // We have found an interface | 339 | // We have found an interface |
340 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | 340 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); |
341 | // See if we already have it | 341 | // See if we already have it |
342 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ | 342 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ |
343 | if(fileName == TEMP_ALL) | 343 | if(fileName == TEMP_ALL) |
344 | i = new Interface(this, interfaceName, false); | 344 | i = new Interface(this, interfaceName, false); |
345 | else | 345 | else |
346 | i = new Interface(this, interfaceName, true); | 346 | i = new Interface(this, interfaceName, true); |
347 | i->setAttached(true); | 347 | i->setAttached(true); |
348 | 348 | ||
349 | QString hardName = "Ethernet"; | 349 | QString hardName = "Ethernet"; |
350 | int hardwareName = line.find("Link encap:"); | 350 | int hardwareName = line.find("Link encap:"); |
351 | int macAddress = line.find("HWaddr"); | 351 | int macAddress = line.find("HWaddr"); |
352 | if(macAddress == -1) | 352 | if(macAddress == -1) |
353 | macAddress = line.length(); | 353 | macAddress = line.length(); |
354 | if(hardwareName != -1) | 354 | if(hardwareName != -1) |
355 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) ); | 355 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) ); |
356 | 356 | ||
357 | interfaceNames.insert(i->getInterfaceName(), i); | 357 | interfaceNames.insert(i->getInterfaceName(), i); |
358 | updateInterface(i); | 358 | updateInterface(i); |
359 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 359 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
360 | } | 360 | } |
361 | // It was an interface we already had. | 361 | // It was an interface we already had. |
362 | else{ | 362 | else{ |
363 | if(fileName != TEMP_ALL) | 363 | if(fileName != TEMP_ALL) |
364 | (interfaceNames[interfaceName])->setStatus(true); | 364 | (interfaceNames[interfaceName])->setStatus(true); |
365 | } | 365 | } |
366 | } | 366 | } |
367 | } | 367 | } |
368 | file.close(); | 368 | file.close(); |
369 | QFile::remove(fileName); | 369 | QFile::remove(fileName); |
370 | 370 | ||
371 | if(threads.count() == 0){ | 371 | if(threads.count() == 0){ |
372 | Interfaces i; | 372 | Interfaces i; |
373 | QStringList list = i.getInterfaceList(); | 373 | QStringList list = i.getInterfaceList(); |
374 | QMap<QString, Interface*>::Iterator it; | 374 | QMap<QString, Interface*>::Iterator it; |
375 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | 375 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { |
376 | bool found = false; | 376 | bool found = false; |
377 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | 377 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ |
378 | if(it.key() == (*ni)) | 378 | if(it.key() == (*ni)) |
379 | found = true; | 379 | found = true; |
380 | } | 380 | } |
381 | if(!found){ | 381 | if(!found){ |
382 | if(!(*ni).contains("_")){ | 382 | if(!(*ni).contains("_")){ |
383 | Interface *i = new Interface(this, *ni, false); | 383 | Interface *i = new Interface(this, *ni, false); |
384 | i->setAttached(false); | 384 | i->setAttached(false); |
385 | i->setHardwareName("Disconnected"); | 385 | i->setHardwareName("Disconnected"); |
386 | interfaceNames.insert(i->getInterfaceName(), i); | 386 | interfaceNames.insert(i->getInterfaceName(), i); |
387 | updateInterface(i); | 387 | updateInterface(i); |
388 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 388 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
389 | } | 389 | } |
390 | } | 390 | } |
391 | } | 391 | } |
392 | } | 392 | } |
393 | } | 393 | } |
394 | 394 | ||
395 | /** | 395 | /** |
396 | * Update this interface. If no QListViewItem exists create one. | 396 | * Update this interface. If no QListViewItem exists create one. |
397 | * @param Interface* pointer to the interface that needs to be updated. | 397 | * @param Interface* pointer to the interface that needs to be updated. |
398 | */ | 398 | */ |
399 | void MainWindowImp::updateInterface(Interface *i){ | 399 | void MainWindowImp::updateInterface(Interface *i){ |
400 | if(!advancedUserMode){ | 400 | if(!advancedUserMode){ |
401 | if(i->getInterfaceName() == "lo") | 401 | if(i->getInterfaceName() == "lo") |
402 | return; | 402 | return; |
403 | } | 403 | } |
404 | 404 | ||
405 | QListViewItem *item = NULL; | 405 | QListViewItem *item = NULL; |
406 | 406 | ||
407 | // Find the interface, making it if needed. | 407 | // Find the interface, making it if needed. |
408 | if(items.find(i) == items.end()){ | 408 | if(items.find(i) == items.end()){ |
409 | item = new QListViewItem(connectionList, "", "", ""); | 409 | item = new QListViewItem(connectionList, "", "", ""); |
410 | // See if you can't find a module owner for this interface | 410 | // See if you can't find a module owner for this interface |
411 | QMap<Module*, QLibrary*>::Iterator it; | 411 | QMap<Module*, QLibrary*>::Iterator it; |
412 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 412 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
413 | if(it.key()->isOwner(i)) | 413 | if(it.key()->isOwner(i)) |
414 | i->setModuleOwner(it.key()); | 414 | i->setModuleOwner(it.key()); |
415 | } | 415 | } |
416 | items.insert(i, item); | 416 | items.insert(i, item); |
417 | interfaceItems.insert(item, i); | 417 | interfaceItems.insert(item, i); |
418 | } | 418 | } |
419 | else | 419 | else |
420 | item = items[i]; | 420 | item = items[i]; |
421 | 421 | ||
422 | // Update the icons and information | 422 | // Update the icons and information |
423 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 423 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
424 | 424 | ||
425 | QString typeName = "lan"; | 425 | QString typeName = "lan"; |
426 | if(i->getHardwareName().contains("Local Loopback")) | 426 | if(i->getHardwareName().contains("Local Loopback")) |
427 | typeName = "lo"; | 427 | typeName = "lo"; |
428 | if(i->getInterfaceName().contains("irda")) | 428 | if(i->getInterfaceName().contains("irda")) |
429 | typeName = "irda"; | 429 | typeName = "irda"; |
430 | if(i->getInterfaceName().contains("wlan")) | 430 | if(i->getInterfaceName().contains("wlan")) |
431 | typeName = "wlan"; | 431 | typeName = "wlan"; |
432 | if(i->getInterfaceName().contains("usb")) | 432 | if(i->getInterfaceName().contains("usb")) |
433 | typeName = "usb"; | 433 | typeName = "usb"; |
434 | 434 | ||
435 | if(!i->isAttached()) | 435 | if(!i->isAttached()) |
436 | typeName = "connect_no"; | 436 | typeName = "connect_no"; |
437 | // Actually try to use the Module | 437 | // Actually try to use the Module |
438 | if(i->getModuleOwner() != NULL) | 438 | if(i->getModuleOwner() != NULL) |
439 | typeName = i->getModuleOwner()->getPixmapName(i); | 439 | typeName = i->getModuleOwner()->getPixmapName(i); |
440 | 440 | ||
441 | item->setPixmap(1, (Resource::loadPixmap(typeName))); | 441 | item->setPixmap(1, (Resource::loadPixmap(typeName))); |
442 | item->setText(2, i->getHardwareName()); | 442 | item->setText(2, i->getHardwareName()); |
443 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); | 443 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); |
444 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); | 444 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); |
445 | } | 445 | } |
446 | 446 | ||
447 | void MainWindowImp::newProfileChanged(const QString& newText){ | 447 | void MainWindowImp::newProfileChanged(const QString& newText){ |
448 | if(newText.length() > 0) | 448 | if(newText.length() > 0) |
449 | newProfileButton->setEnabled(true); | 449 | newProfileButton->setEnabled(true); |
450 | else | 450 | else |
451 | newProfileButton->setEnabled(false); | 451 | newProfileButton->setEnabled(false); |
452 | } | 452 | } |
453 | 453 | ||
454 | /** | 454 | /** |
455 | * Adds a new profile to the list of profiles. | 455 | * Adds a new profile to the list of profiles. |
456 | * Don't add profiles that already exists. | 456 | * Don't add profiles that already exists. |
457 | * Appends to the list and QStringList | 457 | * Appends to the list and QStringList |
458 | */ | 458 | */ |
459 | void MainWindowImp::addProfile(){ | 459 | void MainWindowImp::addProfile(){ |
460 | QString newProfileName = newProfile->text(); | 460 | QString newProfileName = newProfile->text(); |
461 | if(profiles.grep(newProfileName).count() > 0){ | 461 | if(profiles.grep(newProfileName).count() > 0){ |
462 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); | 462 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); |
463 | return; | 463 | return; |
464 | } | 464 | } |
465 | profiles.append(newProfileName); | 465 | profiles.append(newProfileName); |
466 | profilesList->insertItem(newProfileName); | 466 | profilesList->insertItem(newProfileName); |
467 | } | 467 | } |
468 | 468 | ||
469 | /** | 469 | /** |
470 | * Removes the currently selected profile in the combo. | 470 | * Removes the currently selected profile in the combo. |
471 | * Doesn't delete if there are less then 2 profiles. | 471 | * Doesn't delete if there are less then 2 profiles. |
472 | */ | 472 | */ |
473 | void MainWindowImp::removeProfile(){ | 473 | void MainWindowImp::removeProfile(){ |
474 | if(profilesList->count() <= 1){ | 474 | if(profilesList->count() <= 1){ |
475 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); | 475 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); |
476 | return; | 476 | return; |
477 | } | 477 | } |
478 | QString profileToRemove = profilesList->currentText(); | 478 | QString profileToRemove = profilesList->currentText(); |
479 | if(profileToRemove == "All"){ | 479 | if(profileToRemove == "All"){ |
480 | QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); | 480 | QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); |
481 | return; | 481 | return; |
482 | } | 482 | } |
483 | // Can't remove the curent profile | 483 | // Can't remove the curent profile |
484 | if(profileToRemove == currentProfileLabel->text()){ | 484 | if(profileToRemove == currentProfileLabel->text()){ |
485 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); | 485 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); |
486 | return; | 486 | return; |
487 | 487 | ||
488 | } | 488 | } |
489 | 489 | ||
490 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ | 490 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ |
491 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); | 491 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); |
492 | profilesList->clear(); | 492 | profilesList->clear(); |
493 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 493 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
494 | profilesList->insertItem((*it)); | 494 | profilesList->insertItem((*it)); |
495 | 495 | ||
496 | // Remove any interface settings and mappings. | 496 | // Remove any interface settings and mappings. |
497 | Interfaces interfaces; | 497 | Interfaces interfaces; |
498 | // Go through them one by one | 498 | // Go through them one by one |
499 | QMap<Interface*, QListViewItem*>::Iterator it; | 499 | QMap<Interface*, QListViewItem*>::Iterator it; |
500 | for( it = items.begin(); it != items.end(); ++it ){ | 500 | for( it = items.begin(); it != items.end(); ++it ){ |
501 | QString interfaceName = it.key()->getInterfaceName(); | 501 | QString interfaceName = it.key()->getInterfaceName(); |
502 | qDebug(interfaceName.latin1()); | 502 | qDebug(interfaceName.latin1()); |
503 | if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ | 503 | if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ |
504 | interfaces.removeInterface(); | 504 | interfaces.removeInterface(); |
505 | if(interfaces.setMapping(interfaceName)){ | 505 | if(interfaces.setMapping(interfaceName)){ |
506 | if(profilesList->count() == 1) | 506 | if(profilesList->count() == 1) |
507 | interfaces.removeMapping(); | 507 | interfaces.removeMapping(); |
508 | else{ | 508 | else{ |
509 | interfaces.removeMap("map", interfaceName + "_" + profileToRemove); | 509 | interfaces.removeMap("map", interfaceName + "_" + profileToRemove); |
510 | } | 510 | } |
511 | } | 511 | } |
512 | interfaces.write(); | 512 | interfaces.write(); |
513 | break; | 513 | break; |
514 | } | 514 | } |
515 | } | 515 | } |
516 | } | 516 | } |
517 | } | 517 | } |
518 | 518 | ||
519 | /** | 519 | /** |
520 | * A new profile has been selected, change. | 520 | * A new profile has been selected, change. |
521 | * @param newProfile the new profile. | 521 | * @param newProfile the new profile. |
522 | */ | 522 | */ |
523 | void MainWindowImp::changeProfile(){ | 523 | void MainWindowImp::changeProfile(){ |
524 | if(profilesList->currentItem() == -1){ | 524 | if(profilesList->currentItem() == -1){ |
525 | QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); | 525 | QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); |
526 | return; | 526 | return; |
527 | } | 527 | } |
528 | QString newProfile = profilesList->text(profilesList->currentItem()); | 528 | QString newProfile = profilesList->text(profilesList->currentItem()); |
529 | if(newProfile != currentProfileLabel->text()){ | 529 | if(newProfile != currentProfileLabel->text()){ |
530 | currentProfileLabel->setText(newProfile); | 530 | currentProfileLabel->setText(newProfile); |
531 | QFile::remove(scheme); | 531 | QFile::remove(scheme); |
532 | QFile file(scheme); | 532 | QFile file(scheme); |
533 | if ( file.open(IO_ReadWrite) ) { | 533 | if ( file.open(IO_ReadWrite) ) { |
534 | QTextStream stream( &file ); | 534 | QTextStream stream( &file ); |
535 | stream << QString("SCHEME=%1").arg(newProfile); | 535 | stream << QString("SCHEME=%1").arg(newProfile); |
536 | file.close(); | 536 | file.close(); |
537 | } | 537 | } |
538 | // restart all up devices? | 538 | // restart all up devices? |
539 | if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ | 539 | if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ |
540 | // Go through them one by one | 540 | // Go through them one by one |
541 | QMap<Interface*, QListViewItem*>::Iterator it; | 541 | QMap<Interface*, QListViewItem*>::Iterator it; |
542 | for( it = items.begin(); it != items.end(); ++it ){ | 542 | for( it = items.begin(); it != items.end(); ++it ){ |
543 | if(it.key()->getStatus() == true) | 543 | if(it.key()->getStatus() == true) |
544 | it.key()->restart(); | 544 | it.key()->restart(); |
545 | } | 545 | } |
546 | } | 546 | } |
547 | } | 547 | } |
548 | } | 548 | } |
549 | 549 | ||
550 | // mainwindowimp.cpp | 550 | // mainwindowimp.cpp |
551 | 551 | ||
diff --git a/noncore/settings/networksettings/TODO b/noncore/settings/networksettings/TODO index c587f58..7a71142 100644 --- a/noncore/settings/networksettings/TODO +++ b/noncore/settings/networksettings/TODO | |||
@@ -1,6 +1,11 @@ | |||
1 | Write a class that parses /proc and not ifconfig | ||
2 | WLAN needs to be re-written to not use Config | 1 | WLAN needs to be re-written to not use Config |
3 | remove WLAN Config item | 2 | -remove WLAN Config item |
3 | -sub class out the wlan info | ||
4 | -check if an interface supports wireless extensions before config. | ||
5 | |||
6 | PPP module needs to be written | ||
7 | |||
8 | Write a class that parses /proc and not ifconfig | ||
9 | |||
10 | Possible other modules: ipsec, bluetooth | ||
4 | 11 | ||
5 | [ ] Wlanmodule needs to check if an interface supports wireless | ||
6 | extensions. | ||
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index 8e4e898..843f630 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp | |||
@@ -1,551 +1,551 @@ | |||
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 Modules and Libraries | 86 | // Delete Modules and Libraries |
87 | QMap<Module*, QLibrary*>::Iterator it; | 87 | QMap<Module*, QLibrary*>::Iterator it; |
88 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 88 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
89 | delete it.key(); | 89 | delete it.key(); |
90 | delete it.data(); | 90 | delete it.data(); |
91 | } | 91 | } |
92 | } | 92 | } |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * Load all modules that are found in the path | 95 | * Load all modules that are found in the path |
96 | * @param path a directory that is scaned for any plugins that can be loaded | 96 | * @param path a directory that is scaned for any plugins that can be loaded |
97 | * and attempts to load them | 97 | * and attempts to load them |
98 | */ | 98 | */ |
99 | void MainWindowImp::loadModules(QString path){ | 99 | void MainWindowImp::loadModules(QString path){ |
100 | //qDebug(path.latin1()); | 100 | //qDebug(path.latin1()); |
101 | QDir d(path); | 101 | QDir d(path); |
102 | if(!d.exists()) | 102 | if(!d.exists()) |
103 | return; | 103 | return; |
104 | 104 | ||
105 | // Don't want sym links | 105 | // Don't want sym links |
106 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 106 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
107 | const QFileInfoList *list = d.entryInfoList(); | 107 | const QFileInfoList *list = d.entryInfoList(); |
108 | QFileInfoListIterator it( *list ); | 108 | QFileInfoListIterator it( *list ); |
109 | QFileInfo *fi; | 109 | QFileInfo *fi; |
110 | while ( (fi=it.current()) ) { | 110 | while ( (fi=it.current()) ) { |
111 | if(fi->fileName().contains(".so")){ | 111 | if(fi->fileName().contains(".so")){ |
112 | loadPlugin(path + "/" + fi->fileName()); | 112 | loadPlugin(path + "/" + fi->fileName()); |
113 | } | 113 | } |
114 | ++it; | 114 | ++it; |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | /** | 118 | /** |
119 | * Attempt to load a function and resolve a function. | 119 | * Attempt to load a function and resolve a function. |
120 | * @param pluginFileName - the name of the file in which to attempt to load | 120 | * @param pluginFileName - the name of the file in which to attempt to load |
121 | * @param resolveString - function pointer to resolve | 121 | * @param resolveString - function pointer to resolve |
122 | * @return pointer to the function with name resolveString or NULL | 122 | * @return pointer to the function with name resolveString or NULL |
123 | */ | 123 | */ |
124 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | 124 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ |
125 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); | 125 | //qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); |
126 | QLibrary *lib = new QLibrary(pluginFileName); | 126 | QLibrary *lib = new QLibrary(pluginFileName); |
127 | void *functionPointer = lib->resolve(resolveString); | 127 | void *functionPointer = lib->resolve(resolveString); |
128 | if( !functionPointer ){ | 128 | if( !functionPointer ){ |
129 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 129 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
130 | delete lib; | 130 | delete lib; |
131 | return NULL; | 131 | return NULL; |
132 | } | 132 | } |
133 | 133 | ||
134 | // Try to get an object. | 134 | // Try to get an object. |
135 | Module *object = ((Module* (*)()) functionPointer)(); | 135 | Module *object = ((Module* (*)()) functionPointer)(); |
136 | if(object == NULL){ | 136 | if(object == NULL){ |
137 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 137 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
138 | delete lib; | 138 | delete lib; |
139 | return NULL; | 139 | return NULL; |
140 | } | 140 | } |
141 | 141 | ||
142 | // Store for deletion later | 142 | // Store for deletion later |
143 | libraries.insert(object, lib); | 143 | libraries.insert(object, lib); |
144 | return object; | 144 | return object; |
145 | } | 145 | } |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * The Add button was clicked. Bring up the add dialog and if OK is hit | 148 | * 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 | 149 | * load the plugin and append it to the list |
150 | */ | 150 | */ |
151 | void MainWindowImp::addClicked(){ | 151 | void MainWindowImp::addClicked(){ |
152 | QMap<Module*, QLibrary*>::Iterator it; | 152 | QMap<Module*, QLibrary*>::Iterator it; |
153 | QMap<QString, QString> list; | 153 | QMap<QString, QString> list; |
154 | QMap<QString, Module*> newInterfaceOwners; | 154 | QMap<QString, Module*> newInterfaceOwners; |
155 | list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); | 155 | 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"); | 156 | list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); |
157 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 157 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
158 | if(it.key()){ | 158 | if(it.key()){ |
159 | (it.key())->possibleNewInterfaces(list); | 159 | (it.key())->possibleNewInterfaces(list); |
160 | } | 160 | } |
161 | } | 161 | } |
162 | // See if the list has anything that we can add. | 162 | // See if the list has anything that we can add. |
163 | if(list.count() == 0){ | 163 | if(list.count() == 0){ |
164 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); | 164 | QMessageBox::information(this, "Sorry", "Nothing to add.", "Ok"); |
165 | return; | 165 | return; |
166 | } | 166 | } |
167 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); | 167 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); |
168 | addNewConnection.addConnections(list); | 168 | addNewConnection.addConnections(list); |
169 | addNewConnection.showMaximized(); | 169 | addNewConnection.showMaximized(); |
170 | if(QDialog::Accepted == addNewConnection.exec()){ | 170 | if(QDialog::Accepted == addNewConnection.exec()){ |
171 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); | 171 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); |
172 | if(!item) | 172 | if(!item) |
173 | return; | 173 | return; |
174 | 174 | ||
175 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 175 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
176 | if(it.key()){ | 176 | if(it.key()){ |
177 | Interface *i = (it.key())->addNewInterface(item->text(0)); | 177 | Interface *i = (it.key())->addNewInterface(item->text(0)); |
178 | if(i){ | 178 | if(i){ |
179 | interfaceNames.insert(i->getInterfaceName(), i); | 179 | interfaceNames.insert(i->getInterfaceName(), i); |
180 | updateInterface(i); | 180 | updateInterface(i); |
181 | } | 181 | } |
182 | } | 182 | } |
183 | } | 183 | } |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | /** | 187 | /** |
188 | * Prompt the user to see if they really want to do this. | 188 | * Prompt the user to see if they really want to do this. |
189 | * If they do then remove from the list and unload. | 189 | * If they do then remove from the list and unload. |
190 | */ | 190 | */ |
191 | void MainWindowImp::removeClicked(){ | 191 | void MainWindowImp::removeClicked(){ |
192 | QListViewItem *item = connectionList->currentItem(); | 192 | QListViewItem *item = connectionList->currentItem(); |
193 | if(!item) { | 193 | if(!item) { |
194 | QMessageBox::information(this, "Error","Please select an interface.", "Ok"); | 194 | QMessageBox::information(this, "Sorry","Please select an interface First.", "Ok"); |
195 | return; | 195 | return; |
196 | } | 196 | } |
197 | 197 | ||
198 | Interface *i = interfaceItems[item]; | 198 | Interface *i = interfaceItems[item]; |
199 | if(i->getModuleOwner() == NULL){ | 199 | if(i->getModuleOwner() == NULL){ |
200 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); | 200 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); |
201 | } | 201 | } |
202 | else{ | 202 | else{ |
203 | if(!i->getModuleOwner()->remove(i)) | 203 | if(!i->getModuleOwner()->remove(i)) |
204 | QMessageBox::information(this, "Error", "Unable to remove.", "Ok"); | 204 | QMessageBox::information(this, "Error", "Unable to remove.", "Ok"); |
205 | else{ | 205 | else{ |
206 | QMessageBox::information(this, "Success", "Interface was removed.", "Ok"); | 206 | QMessageBox::information(this, "Success", "Interface was removed.", "Ok"); |
207 | // TODO memory managment.... | 207 | // TODO memory managment.... |
208 | // who deletes the interface? | 208 | // who deletes the interface? |
209 | } | 209 | } |
210 | } | 210 | } |
211 | } | 211 | } |
212 | 212 | ||
213 | /** | 213 | /** |
214 | * Pull up the configure about the currently selected interface. | 214 | * Pull up the configure about the currently selected interface. |
215 | * Report an error if no interface is selected. | 215 | * Report an error if no interface is selected. |
216 | * If the interface has a module owner then request its configure with a empty | 216 | * 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. | 217 | * tab. If tab is !NULL then append the interfaces setup widget to it. |
218 | */ | 218 | */ |
219 | void MainWindowImp::configureClicked(){ | 219 | void MainWindowImp::configureClicked(){ |
220 | QListViewItem *item = connectionList->currentItem(); | 220 | QListViewItem *item = connectionList->currentItem(); |
221 | if(!item){ | 221 | if(!item){ |
222 | QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); | 222 | QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); |
223 | return; | 223 | return; |
224 | } | 224 | } |
225 | 225 | ||
226 | QString currentProfile = currentProfileLabel->text(); | 226 | QString currentProfile = currentProfileLabel->text(); |
227 | if(profilesList->count() <= 1 || currentProfile == "All"){ | 227 | if(profilesList->count() <= 1 || currentProfile == "All"){ |
228 | currentProfile = ""; | 228 | currentProfile = ""; |
229 | } | 229 | } |
230 | 230 | ||
231 | Interface *i = interfaceItems[item]; | 231 | Interface *i = interfaceItems[item]; |
232 | if(i->getModuleOwner()){ | 232 | if(i->getModuleOwner()){ |
233 | i->getModuleOwner()->setProfile(currentProfile); | 233 | i->getModuleOwner()->setProfile(currentProfile); |
234 | QTabWidget *tabWidget = NULL; | 234 | QTabWidget *tabWidget = NULL; |
235 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i, &tabWidget); | 235 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i, &tabWidget); |
236 | if(moduleConfigure != NULL){ | 236 | if(moduleConfigure != NULL){ |
237 | if(tabWidget != NULL){ | 237 | if(tabWidget != NULL){ |
238 | InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); | 238 | InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); |
239 | configure->setProfile(currentProfile); | 239 | configure->setProfile(currentProfile); |
240 | tabWidget->insertTab(configure, "TCP/IP"); | 240 | tabWidget->insertTab(configure, "TCP/IP"); |
241 | 241 | ||
242 | } | 242 | } |
243 | moduleConfigure->showMaximized(); | 243 | moduleConfigure->showMaximized(); |
244 | moduleConfigure->show(); | 244 | moduleConfigure->show(); |
245 | return; | 245 | return; |
246 | } | 246 | } |
247 | } | 247 | } |
248 | 248 | ||
249 | InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); | 249 | InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); |
250 | configure->setProfile(currentProfile); | 250 | configure->setProfile(currentProfile); |
251 | configure->showMaximized(); | 251 | configure->showMaximized(); |
252 | configure->show(); | 252 | configure->show(); |
253 | } | 253 | } |
254 | 254 | ||
255 | /** | 255 | /** |
256 | * Pull up the information about the currently selected interface. | 256 | * Pull up the information about the currently selected interface. |
257 | * Report an error if no interface is selected. | 257 | * Report an error if no interface is selected. |
258 | * If the interface has a module owner then request its configure with a empty | 258 | * 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. | 259 | * tab. If tab is !NULL then append the interfaces setup widget to it. |
260 | */ | 260 | */ |
261 | void MainWindowImp::informationClicked(){ | 261 | void MainWindowImp::informationClicked(){ |
262 | QListViewItem *item = connectionList->currentItem(); | 262 | QListViewItem *item = connectionList->currentItem(); |
263 | if(!item){ | 263 | if(!item){ |
264 | QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); | 264 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
265 | return; | 265 | return; |
266 | } | 266 | } |
267 | 267 | ||
268 | Interface *i = interfaceItems[item]; | 268 | Interface *i = interfaceItems[item]; |
269 | if(!i->isAttached()){ | 269 | if(!i->isAttached()){ |
270 | QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok); | 270 | QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); |
271 | return; | 271 | return; |
272 | } | 272 | } |
273 | 273 | ||
274 | QStringList list; | 274 | QStringList list; |
275 | for(uint i = 0; i < profilesList->count(); i++){ | 275 | for(uint i = 0; i < profilesList->count(); i++){ |
276 | list.append(profilesList->text(i)); | 276 | list.append(profilesList->text(i)); |
277 | } | 277 | } |
278 | 278 | ||
279 | if(i->getModuleOwner()){ | 279 | if(i->getModuleOwner()){ |
280 | QTabWidget *tabWidget = NULL; | 280 | QTabWidget *tabWidget = NULL; |
281 | QWidget *moduleInformation = i->getModuleOwner()->information(i, &tabWidget); | 281 | QWidget *moduleInformation = i->getModuleOwner()->information(i, &tabWidget); |
282 | if(moduleInformation != NULL){ | 282 | if(moduleInformation != NULL){ |
283 | if(tabWidget != NULL){ | 283 | if(tabWidget != NULL){ |
284 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); | 284 | InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); |
285 | tabWidget->insertTab(information, "TCP/IP"); | 285 | tabWidget->insertTab(information, "TCP/IP"); |
286 | } | 286 | } |
287 | moduleInformation->showMaximized(); | 287 | moduleInformation->showMaximized(); |
288 | moduleInformation->show(); | 288 | moduleInformation->show(); |
289 | return; | 289 | return; |
290 | } | 290 | } |
291 | } | 291 | } |
292 | 292 | ||
293 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); | 293 | InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true); |
294 | information->showMaximized(); | 294 | information->showMaximized(); |
295 | information->show(); | 295 | information->show(); |
296 | } | 296 | } |
297 | 297 | ||
298 | /** | 298 | /** |
299 | * Aquire the list of active interfaces from ifconfig | 299 | * Aquire the list of active interfaces from ifconfig |
300 | * Call ifconfig and ifconfig -a | 300 | * Call ifconfig and ifconfig -a |
301 | */ | 301 | */ |
302 | void MainWindowImp::getInterfaceList(){ | 302 | void MainWindowImp::getInterfaceList(){ |
303 | KShellProcess *processAll = new KShellProcess(); | 303 | KShellProcess *processAll = new KShellProcess(); |
304 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; | 304 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; |
305 | connect(processAll, SIGNAL(processExited(KProcess *)), | 305 | connect(processAll, SIGNAL(processExited(KProcess *)), |
306 | this, SLOT(jobDone(KProcess *))); | 306 | this, SLOT(jobDone(KProcess *))); |
307 | threads.insert(processAll, TEMP_ALL); | 307 | threads.insert(processAll, TEMP_ALL); |
308 | 308 | ||
309 | KShellProcess *process = new KShellProcess(); | 309 | KShellProcess *process = new KShellProcess(); |
310 | *process << "/sbin/ifconfig" << " > " TEMP_UP; | 310 | *process << "/sbin/ifconfig" << " > " TEMP_UP; |
311 | connect(process, SIGNAL(processExited(KProcess *)), | 311 | connect(process, SIGNAL(processExited(KProcess *)), |
312 | this, SLOT(jobDone(KProcess *))); | 312 | this, SLOT(jobDone(KProcess *))); |
313 | threads.insert(process, TEMP_UP); | 313 | threads.insert(process, TEMP_UP); |
314 | 314 | ||
315 | processAll->start(KShellProcess::NotifyOnExit); | 315 | processAll->start(KShellProcess::NotifyOnExit); |
316 | process->start(KShellProcess::NotifyOnExit); | 316 | process->start(KShellProcess::NotifyOnExit); |
317 | } | 317 | } |
318 | 318 | ||
319 | void MainWindowImp::jobDone(KProcess *process){ | 319 | void MainWindowImp::jobDone(KProcess *process){ |
320 | QString fileName = threads[process]; | 320 | QString fileName = threads[process]; |
321 | threads.remove(process); | 321 | threads.remove(process); |
322 | delete process; | 322 | delete process; |
323 | 323 | ||
324 | QFile file(fileName); | 324 | QFile file(fileName); |
325 | if (!file.open(IO_ReadOnly)){ | 325 | if (!file.open(IO_ReadOnly)){ |
326 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); | 326 | qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1()); |
327 | return; | 327 | return; |
328 | } | 328 | } |
329 | 329 | ||
330 | QTextStream stream( &file ); | 330 | QTextStream stream( &file ); |
331 | QString line; | 331 | QString line; |
332 | while ( !stream.eof() ) { | 332 | while ( !stream.eof() ) { |
333 | line = stream.readLine(); | 333 | line = stream.readLine(); |
334 | int space = line.find(" "); | 334 | int space = line.find(" "); |
335 | if(space > 1){ | 335 | if(space > 1){ |
336 | // We have found an interface | 336 | // We have found an interface |
337 | QString interfaceName = line.mid(0, space); | 337 | QString interfaceName = line.mid(0, space); |
338 | Interface *i; | 338 | Interface *i; |
339 | // We have found an interface | 339 | // We have found an interface |
340 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); | 340 | //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1()); |
341 | // See if we already have it | 341 | // See if we already have it |
342 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ | 342 | if(interfaceNames.find(interfaceName) == interfaceNames.end()){ |
343 | if(fileName == TEMP_ALL) | 343 | if(fileName == TEMP_ALL) |
344 | i = new Interface(this, interfaceName, false); | 344 | i = new Interface(this, interfaceName, false); |
345 | else | 345 | else |
346 | i = new Interface(this, interfaceName, true); | 346 | i = new Interface(this, interfaceName, true); |
347 | i->setAttached(true); | 347 | i->setAttached(true); |
348 | 348 | ||
349 | QString hardName = "Ethernet"; | 349 | QString hardName = "Ethernet"; |
350 | int hardwareName = line.find("Link encap:"); | 350 | int hardwareName = line.find("Link encap:"); |
351 | int macAddress = line.find("HWaddr"); | 351 | int macAddress = line.find("HWaddr"); |
352 | if(macAddress == -1) | 352 | if(macAddress == -1) |
353 | macAddress = line.length(); | 353 | macAddress = line.length(); |
354 | if(hardwareName != -1) | 354 | if(hardwareName != -1) |
355 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) ); | 355 | i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) ); |
356 | 356 | ||
357 | interfaceNames.insert(i->getInterfaceName(), i); | 357 | interfaceNames.insert(i->getInterfaceName(), i); |
358 | updateInterface(i); | 358 | updateInterface(i); |
359 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 359 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
360 | } | 360 | } |
361 | // It was an interface we already had. | 361 | // It was an interface we already had. |
362 | else{ | 362 | else{ |
363 | if(fileName != TEMP_ALL) | 363 | if(fileName != TEMP_ALL) |
364 | (interfaceNames[interfaceName])->setStatus(true); | 364 | (interfaceNames[interfaceName])->setStatus(true); |
365 | } | 365 | } |
366 | } | 366 | } |
367 | } | 367 | } |
368 | file.close(); | 368 | file.close(); |
369 | QFile::remove(fileName); | 369 | QFile::remove(fileName); |
370 | 370 | ||
371 | if(threads.count() == 0){ | 371 | if(threads.count() == 0){ |
372 | Interfaces i; | 372 | Interfaces i; |
373 | QStringList list = i.getInterfaceList(); | 373 | QStringList list = i.getInterfaceList(); |
374 | QMap<QString, Interface*>::Iterator it; | 374 | QMap<QString, Interface*>::Iterator it; |
375 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | 375 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { |
376 | bool found = false; | 376 | bool found = false; |
377 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | 377 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ |
378 | if(it.key() == (*ni)) | 378 | if(it.key() == (*ni)) |
379 | found = true; | 379 | found = true; |
380 | } | 380 | } |
381 | if(!found){ | 381 | if(!found){ |
382 | if(!(*ni).contains("_")){ | 382 | if(!(*ni).contains("_")){ |
383 | Interface *i = new Interface(this, *ni, false); | 383 | Interface *i = new Interface(this, *ni, false); |
384 | i->setAttached(false); | 384 | i->setAttached(false); |
385 | i->setHardwareName("Disconnected"); | 385 | i->setHardwareName("Disconnected"); |
386 | interfaceNames.insert(i->getInterfaceName(), i); | 386 | interfaceNames.insert(i->getInterfaceName(), i); |
387 | updateInterface(i); | 387 | updateInterface(i); |
388 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 388 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
389 | } | 389 | } |
390 | } | 390 | } |
391 | } | 391 | } |
392 | } | 392 | } |
393 | } | 393 | } |
394 | 394 | ||
395 | /** | 395 | /** |
396 | * Update this interface. If no QListViewItem exists create one. | 396 | * Update this interface. If no QListViewItem exists create one. |
397 | * @param Interface* pointer to the interface that needs to be updated. | 397 | * @param Interface* pointer to the interface that needs to be updated. |
398 | */ | 398 | */ |
399 | void MainWindowImp::updateInterface(Interface *i){ | 399 | void MainWindowImp::updateInterface(Interface *i){ |
400 | if(!advancedUserMode){ | 400 | if(!advancedUserMode){ |
401 | if(i->getInterfaceName() == "lo") | 401 | if(i->getInterfaceName() == "lo") |
402 | return; | 402 | return; |
403 | } | 403 | } |
404 | 404 | ||
405 | QListViewItem *item = NULL; | 405 | QListViewItem *item = NULL; |
406 | 406 | ||
407 | // Find the interface, making it if needed. | 407 | // Find the interface, making it if needed. |
408 | if(items.find(i) == items.end()){ | 408 | if(items.find(i) == items.end()){ |
409 | item = new QListViewItem(connectionList, "", "", ""); | 409 | item = new QListViewItem(connectionList, "", "", ""); |
410 | // See if you can't find a module owner for this interface | 410 | // See if you can't find a module owner for this interface |
411 | QMap<Module*, QLibrary*>::Iterator it; | 411 | QMap<Module*, QLibrary*>::Iterator it; |
412 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 412 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
413 | if(it.key()->isOwner(i)) | 413 | if(it.key()->isOwner(i)) |
414 | i->setModuleOwner(it.key()); | 414 | i->setModuleOwner(it.key()); |
415 | } | 415 | } |
416 | items.insert(i, item); | 416 | items.insert(i, item); |
417 | interfaceItems.insert(item, i); | 417 | interfaceItems.insert(item, i); |
418 | } | 418 | } |
419 | else | 419 | else |
420 | item = items[i]; | 420 | item = items[i]; |
421 | 421 | ||
422 | // Update the icons and information | 422 | // Update the icons and information |
423 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 423 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
424 | 424 | ||
425 | QString typeName = "lan"; | 425 | QString typeName = "lan"; |
426 | if(i->getHardwareName().contains("Local Loopback")) | 426 | if(i->getHardwareName().contains("Local Loopback")) |
427 | typeName = "lo"; | 427 | typeName = "lo"; |
428 | if(i->getInterfaceName().contains("irda")) | 428 | if(i->getInterfaceName().contains("irda")) |
429 | typeName = "irda"; | 429 | typeName = "irda"; |
430 | if(i->getInterfaceName().contains("wlan")) | 430 | if(i->getInterfaceName().contains("wlan")) |
431 | typeName = "wlan"; | 431 | typeName = "wlan"; |
432 | if(i->getInterfaceName().contains("usb")) | 432 | if(i->getInterfaceName().contains("usb")) |
433 | typeName = "usb"; | 433 | typeName = "usb"; |
434 | 434 | ||
435 | if(!i->isAttached()) | 435 | if(!i->isAttached()) |
436 | typeName = "connect_no"; | 436 | typeName = "connect_no"; |
437 | // Actually try to use the Module | 437 | // Actually try to use the Module |
438 | if(i->getModuleOwner() != NULL) | 438 | if(i->getModuleOwner() != NULL) |
439 | typeName = i->getModuleOwner()->getPixmapName(i); | 439 | typeName = i->getModuleOwner()->getPixmapName(i); |
440 | 440 | ||
441 | item->setPixmap(1, (Resource::loadPixmap(typeName))); | 441 | item->setPixmap(1, (Resource::loadPixmap(typeName))); |
442 | item->setText(2, i->getHardwareName()); | 442 | item->setText(2, i->getHardwareName()); |
443 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); | 443 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); |
444 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); | 444 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); |
445 | } | 445 | } |
446 | 446 | ||
447 | void MainWindowImp::newProfileChanged(const QString& newText){ | 447 | void MainWindowImp::newProfileChanged(const QString& newText){ |
448 | if(newText.length() > 0) | 448 | if(newText.length() > 0) |
449 | newProfileButton->setEnabled(true); | 449 | newProfileButton->setEnabled(true); |
450 | else | 450 | else |
451 | newProfileButton->setEnabled(false); | 451 | newProfileButton->setEnabled(false); |
452 | } | 452 | } |
453 | 453 | ||
454 | /** | 454 | /** |
455 | * Adds a new profile to the list of profiles. | 455 | * Adds a new profile to the list of profiles. |
456 | * Don't add profiles that already exists. | 456 | * Don't add profiles that already exists. |
457 | * Appends to the list and QStringList | 457 | * Appends to the list and QStringList |
458 | */ | 458 | */ |
459 | void MainWindowImp::addProfile(){ | 459 | void MainWindowImp::addProfile(){ |
460 | QString newProfileName = newProfile->text(); | 460 | QString newProfileName = newProfile->text(); |
461 | if(profiles.grep(newProfileName).count() > 0){ | 461 | if(profiles.grep(newProfileName).count() > 0){ |
462 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); | 462 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); |
463 | return; | 463 | return; |
464 | } | 464 | } |
465 | profiles.append(newProfileName); | 465 | profiles.append(newProfileName); |
466 | profilesList->insertItem(newProfileName); | 466 | profilesList->insertItem(newProfileName); |
467 | } | 467 | } |
468 | 468 | ||
469 | /** | 469 | /** |
470 | * Removes the currently selected profile in the combo. | 470 | * Removes the currently selected profile in the combo. |
471 | * Doesn't delete if there are less then 2 profiles. | 471 | * Doesn't delete if there are less then 2 profiles. |
472 | */ | 472 | */ |
473 | void MainWindowImp::removeProfile(){ | 473 | void MainWindowImp::removeProfile(){ |
474 | if(profilesList->count() <= 1){ | 474 | if(profilesList->count() <= 1){ |
475 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); | 475 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok"); |
476 | return; | 476 | return; |
477 | } | 477 | } |
478 | QString profileToRemove = profilesList->currentText(); | 478 | QString profileToRemove = profilesList->currentText(); |
479 | if(profileToRemove == "All"){ | 479 | if(profileToRemove == "All"){ |
480 | QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); | 480 | QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok"); |
481 | return; | 481 | return; |
482 | } | 482 | } |
483 | // Can't remove the curent profile | 483 | // Can't remove the curent profile |
484 | if(profileToRemove == currentProfileLabel->text()){ | 484 | if(profileToRemove == currentProfileLabel->text()){ |
485 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); | 485 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok"); |
486 | return; | 486 | return; |
487 | 487 | ||
488 | } | 488 | } |
489 | 489 | ||
490 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ | 490 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ |
491 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); | 491 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); |
492 | profilesList->clear(); | 492 | profilesList->clear(); |
493 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 493 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
494 | profilesList->insertItem((*it)); | 494 | profilesList->insertItem((*it)); |
495 | 495 | ||
496 | // Remove any interface settings and mappings. | 496 | // Remove any interface settings and mappings. |
497 | Interfaces interfaces; | 497 | Interfaces interfaces; |
498 | // Go through them one by one | 498 | // Go through them one by one |
499 | QMap<Interface*, QListViewItem*>::Iterator it; | 499 | QMap<Interface*, QListViewItem*>::Iterator it; |
500 | for( it = items.begin(); it != items.end(); ++it ){ | 500 | for( it = items.begin(); it != items.end(); ++it ){ |
501 | QString interfaceName = it.key()->getInterfaceName(); | 501 | QString interfaceName = it.key()->getInterfaceName(); |
502 | qDebug(interfaceName.latin1()); | 502 | qDebug(interfaceName.latin1()); |
503 | if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ | 503 | if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ |
504 | interfaces.removeInterface(); | 504 | interfaces.removeInterface(); |
505 | if(interfaces.setMapping(interfaceName)){ | 505 | if(interfaces.setMapping(interfaceName)){ |
506 | if(profilesList->count() == 1) | 506 | if(profilesList->count() == 1) |
507 | interfaces.removeMapping(); | 507 | interfaces.removeMapping(); |
508 | else{ | 508 | else{ |
509 | interfaces.removeMap("map", interfaceName + "_" + profileToRemove); | 509 | interfaces.removeMap("map", interfaceName + "_" + profileToRemove); |
510 | } | 510 | } |
511 | } | 511 | } |
512 | interfaces.write(); | 512 | interfaces.write(); |
513 | break; | 513 | break; |
514 | } | 514 | } |
515 | } | 515 | } |
516 | } | 516 | } |
517 | } | 517 | } |
518 | 518 | ||
519 | /** | 519 | /** |
520 | * A new profile has been selected, change. | 520 | * A new profile has been selected, change. |
521 | * @param newProfile the new profile. | 521 | * @param newProfile the new profile. |
522 | */ | 522 | */ |
523 | void MainWindowImp::changeProfile(){ | 523 | void MainWindowImp::changeProfile(){ |
524 | if(profilesList->currentItem() == -1){ | 524 | if(profilesList->currentItem() == -1){ |
525 | QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); | 525 | QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok"); |
526 | return; | 526 | return; |
527 | } | 527 | } |
528 | QString newProfile = profilesList->text(profilesList->currentItem()); | 528 | QString newProfile = profilesList->text(profilesList->currentItem()); |
529 | if(newProfile != currentProfileLabel->text()){ | 529 | if(newProfile != currentProfileLabel->text()){ |
530 | currentProfileLabel->setText(newProfile); | 530 | currentProfileLabel->setText(newProfile); |
531 | QFile::remove(scheme); | 531 | QFile::remove(scheme); |
532 | QFile file(scheme); | 532 | QFile file(scheme); |
533 | if ( file.open(IO_ReadWrite) ) { | 533 | if ( file.open(IO_ReadWrite) ) { |
534 | QTextStream stream( &file ); | 534 | QTextStream stream( &file ); |
535 | stream << QString("SCHEME=%1").arg(newProfile); | 535 | stream << QString("SCHEME=%1").arg(newProfile); |
536 | file.close(); | 536 | file.close(); |
537 | } | 537 | } |
538 | // restart all up devices? | 538 | // restart all up devices? |
539 | if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ | 539 | if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ |
540 | // Go through them one by one | 540 | // Go through them one by one |
541 | QMap<Interface*, QListViewItem*>::Iterator it; | 541 | QMap<Interface*, QListViewItem*>::Iterator it; |
542 | for( it = items.begin(); it != items.end(); ++it ){ | 542 | for( it = items.begin(); it != items.end(); ++it ){ |
543 | if(it.key()->getStatus() == true) | 543 | if(it.key()->getStatus() == true) |
544 | it.key()->restart(); | 544 | it.key()->restart(); |
545 | } | 545 | } |
546 | } | 546 | } |
547 | } | 547 | } |
548 | } | 548 | } |
549 | 549 | ||
550 | // mainwindowimp.cpp | 550 | // mainwindowimp.cpp |
551 | 551 | ||