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