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