author | benmeyer <benmeyer> | 2002-09-30 19:41:41 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-09-30 19:41:41 (UTC) |
commit | a0f88d7d0fb0ffaf8d1aa7b753b0d48ee344e34f (patch) (unidiff) | |
tree | 10e1141777f657881af01cab036962c128109ec2 /noncore/settings/networksettings/mainwindowimp.cpp | |
parent | d49bd63f3b15795a1ee2497960f00eb3fb075e69 (diff) | |
download | opie-a0f88d7d0fb0ffaf8d1aa7b753b0d48ee344e34f.zip opie-a0f88d7d0fb0ffaf8d1aa7b753b0d48ee344e34f.tar.gz opie-a0f88d7d0fb0ffaf8d1aa7b753b0d48ee344e34f.tar.bz2 |
ui cleanup with groupboxes
Diffstat (limited to 'noncore/settings/networksettings/mainwindowimp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 76 |
1 files changed, 37 insertions, 39 deletions
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index 2f821a9..0f48a4b 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp | |||
@@ -1,225 +1,219 @@ | |||
1 | #include "mainwindowimp.h" | 1 | #include "mainwindowimp.h" |
2 | #include "addserviceimp.h" | 2 | #include "addserviceimp.h" |
3 | #include "interfaceinformationimp.h" | 3 | #include "interfaceinformationimp.h" |
4 | #include "interfacesetupimp.h" | 4 | #include "interfacesetupimp.h" |
5 | #include "interface.h" | ||
6 | #include "kprocess.h" | 5 | #include "kprocess.h" |
7 | #include "module.h" | 6 | #include "module.h" |
8 | 7 | ||
8 | |||
9 | #include <qpushbutton.h> | 9 | #include <qpushbutton.h> |
10 | #include <qtabwidget.h> | 10 | #include <qtabwidget.h> |
11 | #include <qlistbox.h> | 11 | #include <qlistbox.h> |
12 | #include <qlistview.h> | 12 | #include <qlistview.h> |
13 | #include <qheader.h> | 13 | #include <qheader.h> |
14 | #include <qlabel.h> | 14 | #include <qlabel.h> |
15 | 15 | ||
16 | #include <qmainwindow.h> | 16 | #include <qmainwindow.h> |
17 | #include <qmessagebox.h> | 17 | #include <qmessagebox.h> |
18 | 18 | ||
19 | #include <qpe/config.h> | 19 | #include <qpe/config.h> |
20 | #include <qpe/qlibrary.h> | 20 | #include <qpe/qlibrary.h> |
21 | #include <qpe/resource.h> | 21 | #include <qpe/resource.h> |
22 | 22 | ||
23 | #include <qlist.h> | 23 | #include <qlist.h> |
24 | #include <qdir.h> | 24 | #include <qdir.h> |
25 | #include <qfile.h> | 25 | #include <qfile.h> |
26 | #include <qtextstream.h> | 26 | #include <qtextstream.h> |
27 | 27 | ||
28 | // For library loading. | 28 | // For library loading. |
29 | #include <dlfcn.h> | 29 | #include <dlfcn.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 NO_SELECT_ERROR_AND_RETURN { \ | ||
35 | QMessageBox::information(this, "Error","Please select an interface.", "Ok"); \ | ||
36 | return; \ | ||
37 | } | ||
38 | |||
39 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true) { | 34 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true) { |
40 | connect(addServiceButton, SIGNAL(clicked()), this, SLOT(addClicked())); | 35 | connect(addServiceButton, SIGNAL(clicked()), this, SLOT(addClicked())); |
41 | connect(removeServiceButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | 36 | connect(removeServiceButton, SIGNAL(clicked()), this, SLOT(removeClicked())); |
42 | connect(informationServiceButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | 37 | connect(informationServiceButton, SIGNAL(clicked()), this, SLOT(informationClicked())); |
43 | connect(configureServiceButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | 38 | connect(configureServiceButton, SIGNAL(clicked()), this, SLOT(configureClicked())); |
44 | 39 | ||
45 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); | 40 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); |
46 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); | 41 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); |
47 | connect(profilesList, SIGNAL(highlighted(const QString&)), this, SLOT(changeProfile(const QString&))); | 42 | connect(profilesList, SIGNAL(highlighted(const QString&)), this, SLOT(changeProfile(const QString&))); |
48 | 43 | ||
49 | // Make sure we have a plugin directory to scan. | 44 | // Make sure we have a plugin directory to scan. |
50 | QString DirStr = QDir::homeDirPath() + "/.networksetup/" ; | 45 | QString DirStr = QDir::homeDirPath() + "/.networksetup/" ; |
51 | QDir pluginDir( DirStr ); | 46 | QDir pluginDir( DirStr ); |
52 | pluginDir.mkdir( DirStr ); | 47 | pluginDir.mkdir( DirStr ); |
53 | pluginDir.mkdir( ( DirStr + "plugins/" ) ); | 48 | pluginDir.mkdir( ( DirStr + "plugins/" ) ); |
54 | QString path = DirStr + "plugins"; | 49 | QString path = DirStr + "plugins"; |
55 | pluginDir.setPath(path); | 50 | pluginDir.setPath(path); |
56 | if(!pluginDir.exists()){ | 51 | if(!pluginDir.exists()){ |
57 | qDebug(QString("MainWindowImp: ERROR: %1 %2").arg(__FILE__).arg(__LINE__).latin1()); | 52 | qDebug(QString("MainWindowImp: ERROR: %1 %2").arg(__FILE__).arg(__LINE__).latin1()); |
58 | return; | 53 | return; |
59 | } | 54 | } |
60 | 55 | ||
61 | // Load any saved services. | 56 | // Load any saved services. |
62 | loadModules(path); | 57 | loadModules(path); |
63 | getInterfaceList(); | 58 | getInterfaceList(); |
64 | serviceList->header()->hide(); | 59 | serviceList->header()->hide(); |
65 | 60 | ||
66 | 61 | ||
67 | Config cfg("NetworkSetup"); | 62 | Config cfg("NetworkSetup"); |
68 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); | 63 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); |
69 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 64 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
70 | profilesList->insertItem((*it)); | 65 | profilesList->insertItem((*it)); |
71 | } | 66 | } |
72 | 67 | ||
73 | /** | 68 | /** |
74 | * Deconstructor. Unload libraries and save profile list. | 69 | * Deconstructor. Unload libraries and save profile list. |
75 | */ | 70 | */ |
76 | MainWindowImp::~MainWindowImp(){ | 71 | MainWindowImp::~MainWindowImp(){ |
77 | if(profiles.count() > 1){ | 72 | if(profiles.count() > 1){ |
78 | Config cfg("NetworkSetup"); | 73 | Config cfg("NetworkSetup"); |
79 | cfg.writeEntry("Profiles", profiles.join(" ")); | 74 | cfg.writeEntry("Profiles", profiles.join(" ")); |
80 | } | 75 | } |
81 | } | 76 | } |
82 | 77 | ||
83 | void MainWindowImp::loadModules(QString path){ | 78 | void MainWindowImp::loadModules(QString path){ |
79 | qDebug(path.latin1()); | ||
80 | QDir d; | ||
81 | d.setPath(path); | ||
82 | if(!d.exists()){ | ||
83 | qDebug("MainWindowImp:: Path doesn't exists"); | ||
84 | return; | ||
85 | } | ||
86 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | ||
87 | const QFileInfoList *list = d.entryInfoList(); | ||
88 | QFileInfoListIterator it( *list ); | ||
89 | QFileInfo *fi; | ||
90 | while ( (fi=it.current()) ) { | ||
91 | if(fi->fileName().contains(".so")){ | ||
92 | qDebug("Found"); | ||
93 | Module *foo = loadPlugin(path + "/" + fi->fileName()); | ||
94 | } | ||
95 | ++it; | ||
96 | } | ||
84 | } | 97 | } |
85 | 98 | ||
86 | /** | 99 | /** |
87 | * Attempt to load a function and resolve a function. | 100 | * Attempt to load a function and resolve a function. |
88 | * @param pluginFileName - the name of the file in which to attempt to load | 101 | * @param pluginFileName - the name of the file in which to attempt to load |
89 | * @param resolveString - function pointer to resolve | 102 | * @param resolveString - function pointer to resolve |
90 | * @return pointer to the function with name resolveString or NULL | 103 | * @return pointer to the function with name resolveString or NULL |
91 | */ | 104 | */ |
92 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | 105 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ |
93 | //qDebug(pluginFileName.latin1()); | 106 | qDebug(pluginFileName.latin1()); |
94 | QLibrary *lib = new QLibrary(pluginFileName); | 107 | QLibrary *lib = new QLibrary(pluginFileName); |
95 | void *functionPointer = lib->resolve(resolveString); | 108 | void *functionPointer = lib->resolve(resolveString); |
96 | if( !functionPointer ){ | 109 | if( !functionPointer ){ |
97 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 110 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
98 | delete lib; | 111 | delete lib; |
99 | return NULL; | 112 | return NULL; |
100 | } | 113 | } |
101 | 114 | ||
102 | // Try to get an object. | 115 | // Try to get an object. |
103 | Module *object = ((Module* (*)()) functionPointer)(); | 116 | Module *object = ((Module* (*)()) functionPointer)(); |
104 | if(object == NULL){ | 117 | if(object == NULL){ |
105 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 118 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
106 | delete lib; | 119 | delete lib; |
107 | return NULL; | 120 | return NULL; |
108 | } | 121 | } |
109 | 122 | ||
110 | // Store for reference | 123 | // Store for reference |
111 | libraries.insert(object, lib); | 124 | libraries.insert(object, lib); |
112 | return object; | 125 | return object; |
113 | } | 126 | } |
114 | 127 | ||
115 | /* | ||
116 | QList<QString> MainWindowImp::retrieveUnloadedPluginList(){ | ||
117 | QString DirStr = QDir::homeDirPath() + "/.networksetup/" ; | ||
118 | QString path = DirStr + "plugins"; | ||
119 | QDir d(path); | ||
120 | d.setFilter( QDir::Files | QDir::Hidden ); | ||
121 | |||
122 | QMap<QObject*, QLibrary*>::Iterator libraryIt; | ||
123 | QList<QString> rlist; | ||
124 | rlist.setAutoDelete(false); | ||
125 | |||
126 | const QFileInfoList *list = d.entryInfoList(); | ||
127 | QFileInfoListIterator it( *list ); | ||
128 | QFileInfo *fi; | ||
129 | while ( (fi=it.current()) ) { | ||
130 | if(fi->fileName().contains(".so")){ | ||
131 | for( libraryIt = libraries.begin(); libraryIt != libraries.end(); ++libraryIt ) | ||
132 | if((path + "/" + fi->fileName()) != (libraryIt.data())->library()){ | ||
133 | QString *s = new QString(path + "/" + fi->fileName()); | ||
134 | rlist.append(s); | ||
135 | } | ||
136 | } | ||
137 | ++it; | ||
138 | } | ||
139 | return rlist; | ||
140 | } | ||
141 | */ | ||
142 | |||
143 | /** | 128 | /** |
144 | * The Add button was clicked. Bring up the add dialog and if OK is hit | 129 | * The Add button was clicked. Bring up the add dialog and if OK is hit |
145 | * load the plugin and append it to the list | 130 | * load the plugin and append it to the list |
146 | */ | 131 | */ |
147 | void MainWindowImp::addClicked(){ | 132 | void MainWindowImp::addClicked(){ |
148 | // Now that we have a list of all of the protocals, list them. | 133 | // Now that we have a list of all of the protocals, list them. |
149 | { | 134 | { |
150 | QMessageBox::information(this, "No Modules", "Nothing to add.", "Ok"); | 135 | QMessageBox::information(this, "No Modules", "Nothing to add.", "Ok"); |
151 | return; | 136 | return; |
152 | } | 137 | } |
153 | AddServiceImp service(this, "AddService", true); | 138 | AddServiceImp service(this, "AddService", true); |
154 | service.showMaximized(); | 139 | service.showMaximized(); |
155 | service.exec(); | 140 | service.exec(); |
156 | } | 141 | } |
157 | 142 | ||
158 | /** | 143 | /** |
159 | * Prompt the user to see if they really want to do this. | 144 | * Prompt the user to see if they really want to do this. |
160 | * If they do then remove from the list and unload. | 145 | * If they do then remove from the list and unload. |
161 | */ | 146 | */ |
162 | void MainWindowImp::removeClicked(){ | 147 | void MainWindowImp::removeClicked(){ |
163 | QListViewItem *item = serviceList->currentItem(); | 148 | QListViewItem *item = serviceList->currentItem(); |
164 | if(item == NULL) NO_SELECT_ERROR_AND_RETURN | 149 | if(item == NULL) { |
150 | QMessageBox::information(this, "Error","Please select an interface.", "Ok"); | ||
151 | return; | ||
152 | } | ||
165 | 153 | ||
166 | if(modules.find(interfaceItems[item]) == modules.end()){ | 154 | if(modules.find(interfaceItems[item]) == modules.end()){ |
167 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); | 155 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", "Ok"); |
168 | } | 156 | } |
169 | else{ | 157 | else{ |
170 | // Try to remove. | 158 | // Try to remove. |
171 | } | 159 | } |
172 | 160 | ||
173 | } | 161 | } |
174 | 162 | ||
175 | /** | 163 | /** |
176 | * See if there is a configuration for the selected protocal. | 164 | * See if there is a configuration for the selected protocal. |
177 | * Prompt with errors. | 165 | * Prompt with errors. |
178 | */ | 166 | */ |
179 | void MainWindowImp::configureClicked(){ | 167 | void MainWindowImp::configureClicked(){ |
180 | QListViewItem *item = serviceList->currentItem(); | 168 | QListViewItem *item = serviceList->currentItem(); |
181 | if(item == NULL) NO_SELECT_ERROR_AND_RETURN | 169 | if(item == NULL){ |
170 | QMessageBox::information(this, "Error","Please select an interface.", "Ok"); | ||
171 | return; | ||
172 | } | ||
182 | 173 | ||
183 | if(modules.find(interfaceItems[item]) == modules.end()){ | 174 | if(modules.find(interfaceItems[item]) == modules.end()){ |
184 | InterfaceSetupImp *conf = new InterfaceSetupImp(0, "InterfaceConfiguration", interfaceItems[item]); | 175 | InterfaceSetupImp *conf = new InterfaceSetupImp(0, "InterfaceConfiguration", interfaceItems[item]); |
185 | conf->showMaximized(); | 176 | conf->showMaximized(); |
186 | conf->show(); | 177 | conf->show(); |
187 | } | 178 | } |
188 | else{ | 179 | else{ |
189 | InterfaceSetupImp *conf = new InterfaceSetupImp(this, "InterfaceConfiguration"); | 180 | InterfaceSetupImp *conf = new InterfaceSetupImp(this, "InterfaceConfiguration"); |
190 | conf->show(); | 181 | conf->show(); |
191 | } | 182 | } |
192 | } | 183 | } |
193 | 184 | ||
194 | /** | 185 | /** |
195 | * Pull up the information about the selected interface | 186 | * Pull up the information about the selected interface |
196 | * Report an error | 187 | * Report an error |
197 | */ | 188 | */ |
198 | void MainWindowImp::informationClicked(){ | 189 | void MainWindowImp::informationClicked(){ |
199 | QListViewItem *item = serviceList->currentItem(); | 190 | QListViewItem *item = serviceList->currentItem(); |
200 | if(item == NULL)NO_SELECT_ERROR_AND_RETURN | 191 | if(item == NULL){ |
201 | 192 | QMessageBox::information(this, "Error","Please select an interface.", "Ok"); | |
193 | return; | ||
194 | } | ||
195 | |||
202 | if(modules.find(interfaceItems[item]) == modules.end()){ | 196 | if(modules.find(interfaceItems[item]) == modules.end()){ |
203 | InterfaceInformationImp *i = new InterfaceInformationImp(0, "InterfaceInformationImp", interfaceItems[item]); | 197 | InterfaceInformationImp *i = new InterfaceInformationImp(0, "InterfaceInformationImp", interfaceItems[item]); |
204 | i->showMaximized(); | 198 | i->showMaximized(); |
205 | i->show(); | 199 | i->show(); |
206 | } | 200 | } |
207 | else{ | 201 | else{ |
208 | QTabWidget *t = new QTabWidget(this, "InterfaceInformationTAB"); | 202 | QTabWidget *t = new QTabWidget(this, "InterfaceInformationTAB"); |
209 | InterfaceInformationImp *i = new InterfaceInformationImp(t, "TCPIPInformation", interfaceItems[item], true); | 203 | InterfaceInformationImp *i = new InterfaceInformationImp(t, "TCPIPInformation", interfaceItems[item], true); |
210 | t->insertTab(i, "TCP/IP"); | 204 | t->insertTab(i, "TCP/IP"); |
211 | t->show(); | 205 | t->show(); |
212 | } | 206 | } |
213 | } | 207 | } |
214 | 208 | ||
215 | /** | 209 | /** |
216 | * Aquire the list of active interfaces from ifconfig | 210 | * Aquire the list of active interfaces from ifconfig |
217 | * Call ifconfig and ifconfig -a | 211 | * Call ifconfig and ifconfig -a |
218 | */ | 212 | */ |
219 | void MainWindowImp::getInterfaceList(){ | 213 | void MainWindowImp::getInterfaceList(){ |
220 | KShellProcess *processAll = new KShellProcess(); | 214 | KShellProcess *processAll = new KShellProcess(); |
221 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; | 215 | *processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL; |
222 | connect(processAll, SIGNAL(processExited(KProcess *)), | 216 | connect(processAll, SIGNAL(processExited(KProcess *)), |
223 | this, SLOT(jobDone(KProcess *))); | 217 | this, SLOT(jobDone(KProcess *))); |
224 | threads.insert(processAll, TEMP_ALL); | 218 | threads.insert(processAll, TEMP_ALL); |
225 | processAll->start(KShellProcess::NotifyOnExit); | 219 | processAll->start(KShellProcess::NotifyOnExit); |
@@ -290,48 +284,52 @@ void MainWindowImp::updateInterface(Interface *i){ | |||
290 | 284 | ||
291 | // See if we already have it | 285 | // See if we already have it |
292 | if(items.find(i) == items.end()){ | 286 | if(items.find(i) == items.end()){ |
293 | item = new QListViewItem(serviceList, "", "", ""); | 287 | item = new QListViewItem(serviceList, "", "", ""); |
294 | // See if you can't find a module owner for this interface | 288 | // See if you can't find a module owner for this interface |
295 | //EmployeeMap::Iterator it; | 289 | //EmployeeMap::Iterator it; |
296 | //for( it = map.begin(); it != map.end(); ++it ) | 290 | //for( it = map.begin(); it != map.end(); ++it ) |
297 | // printf( "%s, %s earns %d\n", it.key().latin1(), it.data().name().latin1(), it.data().salary() ); | 291 | // printf( "%s, %s earns %d\n", it.key().latin1(), it.data().name().latin1(), it.data().salary() ); |
298 | 292 | ||
299 | items.insert(i, item); | 293 | items.insert(i, item); |
300 | interfaceItems.insert(item, i); | 294 | interfaceItems.insert(item, i); |
301 | } | 295 | } |
302 | else | 296 | else |
303 | item = items[i]; | 297 | item = items[i]; |
304 | 298 | ||
305 | QString statusImage = "down"; | 299 | QString statusImage = "down"; |
306 | if(i->getStatus()) | 300 | if(i->getStatus()) |
307 | statusImage = "up"; | 301 | statusImage = "up"; |
308 | QPixmap status = (Resource::loadPixmap(statusImage)); | 302 | QPixmap status = (Resource::loadPixmap(statusImage)); |
309 | item->setPixmap(0, status); | 303 | item->setPixmap(0, status); |
310 | 304 | ||
311 | QString typeName = "lan"; | 305 | QString typeName = "lan"; |
312 | if(i->getHardwareName().contains("Local Loopback")) | 306 | if(i->getHardwareName().contains("Local Loopback")) |
313 | typeName = "lo"; | 307 | typeName = "lo"; |
308 | if(i->getInterfaceName().contains("irda")) | ||
309 | typeName = "irda"; | ||
310 | if(i->getInterfaceName().contains("wlan")) | ||
311 | typeName = "wlan"; | ||
314 | QPixmap type = (Resource::loadPixmap(typeName)); | 312 | QPixmap type = (Resource::loadPixmap(typeName)); |
315 | item->setPixmap(1, type); | 313 | item->setPixmap(1, type); |
316 | 314 | ||
317 | item->setText(2, i->getHardwareName()); | 315 | item->setText(2, i->getHardwareName()); |
318 | 316 | ||
319 | } | 317 | } |
320 | 318 | ||
321 | /** | 319 | /** |
322 | * Adds a new profile to the list of profiles. | 320 | * Adds a new profile to the list of profiles. |
323 | * Don't add profiles that already exists. | 321 | * Don't add profiles that already exists. |
324 | * Appends to the combo and QStringList | 322 | * Appends to the combo and QStringList |
325 | */ | 323 | */ |
326 | void MainWindowImp::addProfile(){ | 324 | void MainWindowImp::addProfile(){ |
327 | QString newProfileName = "New"; | 325 | QString newProfileName = "New"; |
328 | if(profiles.grep(newProfileName).count() > 0){ | 326 | if(profiles.grep(newProfileName).count() > 0){ |
329 | QMessageBox::information(this, "Can't Add.","Profile already exists.", "Ok"); | 327 | QMessageBox::information(this, "Can't Add.","Profile already exists.", "Ok"); |
330 | return; | 328 | return; |
331 | } | 329 | } |
332 | profiles.append(newProfileName); | 330 | profiles.append(newProfileName); |
333 | profilesList->insertItem(newProfileName); | 331 | profilesList->insertItem(newProfileName); |
334 | 332 | ||
335 | } | 333 | } |
336 | 334 | ||
337 | /** | 335 | /** |