summaryrefslogtreecommitdiff
authorkergoth <kergoth>2003-04-14 17:14:45 (UTC)
committer kergoth <kergoth>2003-04-14 17:14:45 (UTC)
commit4c0ff8a1bdc4750ee36c713392d0842e9eb9eeb3 (patch) (unidiff)
tree86648bb91854c4c94ddabff7c4b57aa5215a1073
parent1b4605559dfb77f2bb69903d7e6a982c764aadbe (diff)
downloadopie-4c0ff8a1bdc4750ee36c713392d0842e9eb9eeb3.zip
opie-4c0ff8a1bdc4750ee36c713392d0842e9eb9eeb3.tar.gz
opie-4c0ff8a1bdc4750ee36c713392d0842e9eb9eeb3.tar.bz2
BUGFIX: obtaining a network interface list via an ioctl does not always
return all available interfaces. Per busybox ifconfig, use /proc/net/dev as a preferred interface list if it exists, and fall back to the ioctl method if it does not.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp125
1 files changed, 71 insertions, 54 deletions
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index 765b522..50131d8 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -1,587 +1,604 @@
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#include "module.h" 6#include "module.h"
7 7
8#include <qpushbutton.h> 8#include <qpushbutton.h>
9#include <qlistbox.h> 9#include <qlistbox.h>
10#include <qlineedit.h> 10#include <qlineedit.h>
11#include <qlistview.h> 11#include <qlistview.h>
12#include <qheader.h> 12#include <qheader.h>
13#include <qlabel.h> 13#include <qlabel.h>
14 14
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16 16
17#ifdef QWS 17#ifdef QWS
18 #include <qpe/config.h> 18 #include <qpe/config.h>
19 #include <qpe/qlibrary.h> 19 #include <qpe/qlibrary.h>
20 #include <qpe/resource.h> 20 #include <qpe/resource.h>
21 #include <qpe/qpeapplication.h> 21 #include <qpe/qpeapplication.h>
22#else 22#else
23 #include <klibloader.h> 23 #include <klibloader.h>
24 #define QLibrary KLibrary 24 #define QLibrary KLibrary
25 #include <kconfig.h> 25 #include <kconfig.h>
26 #define Config KConfig 26 #define Config KConfig
27 #include <kapplication.h> 27 #include <kapplication.h>
28 #include <kstandarddirs.h> 28 #include <kstandarddirs.h>
29 #include <kiconloader.h> 29 #include <kiconloader.h>
30 #define showMaximized show 30 #define showMaximized show
31#endif 31#endif
32 32
33#if QT_VERSION < 300 33#if QT_VERSION < 300
34#include <qlist.h> 34#include <qlist.h>
35#else 35#else
36#include <qptrlist.h> 36#include <qptrlist.h>
37#endif 37#endif
38#include <qdir.h> 38#include <qdir.h>
39#include <qfile.h> 39#include <qfile.h>
40#include <qtextstream.h> 40#include <qtextstream.h>
41#include <qregexp.h> 41#include <qregexp.h>
42 42
43#include <net/if.h> 43#include <net/if.h>
44#include <sys/ioctl.h> 44#include <sys/ioctl.h>
45#include <sys/socket.h>
45 46
46#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" 47#define DEFAULT_SCHEME "/var/lib/pcmcia/scheme"
48#define _PROCNETDEV "/proc/net/dev"
47 49
48MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name), advancedUserMode(true), scheme(DEFAULT_SCHEME){ 50MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name), advancedUserMode(true), scheme(DEFAULT_SCHEME){
49 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 51 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
50 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 52 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
51 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 53 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
52 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 54 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
53 55
54 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); 56 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
55 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); 57 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
56 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); 58 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
57 59
58 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); 60 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
59 // Load connections. 61 // Load connections.
60 // /usr/local/kde/lib/libinterfaces.la 62 // /usr/local/kde/lib/libinterfaces.la
61#ifdef QWS 63#ifdef QWS
62 loadModules(QPEApplication::qpeDir() + "/plugins/networksettings"); 64 loadModules(QPEApplication::qpeDir() + "/plugins/networksettings");
63#else 65#else
64 loader = KLibLoader::self(); 66 loader = KLibLoader::self();
65 loadModules(QString("/usr/")+KStandardDirs::kde_default("lib")); 67 loadModules(QString("/usr/")+KStandardDirs::kde_default("lib"));
66#endif 68#endif
67 getAllInterfaces(); 69 getAllInterfaces();
68 70
69 Interfaces i; 71 Interfaces i;
70 QStringList list = i.getInterfaceList(); 72 QStringList list = i.getInterfaceList();
71 QMap<QString, Interface*>::Iterator it; 73 QMap<QString, Interface*>::Iterator it;
72 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { 74 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
73 bool found = false; 75 bool found = false;
74 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ 76 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
75 if(it.key() == (*ni)) 77 if(it.key() == (*ni))
76 found = true; 78 found = true;
77 } 79 }
78 if(!found){ 80 if(!found){
79 if(!(*ni).contains("_")){ 81 if(!(*ni).contains("_")){
80 Interface *i = new Interface(this, *ni, false); 82 Interface *i = new Interface(this, *ni, false);
81 i->setAttached(false); 83 i->setAttached(false);
82 i->setHardwareName("Disconnected"); 84 i->setHardwareName("Disconnected");
83 interfaceNames.insert(i->getInterfaceName(), i); 85 interfaceNames.insert(i->getInterfaceName(), i);
84 updateInterface(i); 86 updateInterface(i);
85 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 87 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
86 } 88 }
87 } 89 }
88 } 90 }
89 91
90 //getInterfaceList(); 92 //getInterfaceList();
91 connectionList->header()->hide(); 93 connectionList->header()->hide();
92 94
93 Config cfg("NetworkSetup"); 95 Config cfg("NetworkSetup");
94 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 96 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
95 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 97 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
96 profilesList->insertItem((*it)); 98 profilesList->insertItem((*it));
97 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); 99 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
98 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 100 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
99 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); 101 scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME);
100 102
101 QFile file(scheme); 103 QFile file(scheme);
102 if ( file.open(IO_ReadOnly) ) { // file opened successfully 104 if ( file.open(IO_ReadOnly) ) { // file opened successfully
103 QTextStream stream( &file ); // use a text stream 105 QTextStream stream( &file ); // use a text stream
104 while ( !stream.eof() ) { // until end of file... 106 while ( !stream.eof() ) { // until end of file...
105 QString line = stream.readLine(); // line of text excluding '\n' 107 QString line = stream.readLine(); // line of text excluding '\n'
106 if(line.contains("SCHEME")){ 108 if(line.contains("SCHEME")){
107 line = line.mid(7, line.length()); 109 line = line.mid(7, line.length());
108 currentProfileLabel->setText(line); 110 currentProfileLabel->setText(line);
109 break; 111 break;
110 } 112 }
111 } 113 }
112 file.close(); 114 file.close();
113 } 115 }
114} 116}
115 117
116/** 118/**
117 * Deconstructor. Save profiles. Delete loaded libraries. 119 * Deconstructor. Save profiles. Delete loaded libraries.
118 */ 120 */
119MainWindowImp::~MainWindowImp(){ 121MainWindowImp::~MainWindowImp(){
120 // Save profiles. 122 // Save profiles.
121 Config cfg("NetworkSetup"); 123 Config cfg("NetworkSetup");
122 cfg.setGroup("General"); 124 cfg.setGroup("General");
123 cfg.writeEntry("Profiles", profiles.join(" ")); 125 cfg.writeEntry("Profiles", profiles.join(" "));
124 126
125 // Delete all interfaces that don't have owners. 127 // Delete all interfaces that don't have owners.
126 QMap<Interface*, QListViewItem*>::Iterator iIt; 128 QMap<Interface*, QListViewItem*>::Iterator iIt;
127 for( iIt = items.begin(); iIt != items.end(); ++iIt ){ 129 for( iIt = items.begin(); iIt != items.end(); ++iIt ){
128 if(iIt.key()->getModuleOwner() == NULL) 130 if(iIt.key()->getModuleOwner() == NULL)
129 delete iIt.key(); 131 delete iIt.key();
130 } 132 }
131 133
132#ifdef QWS 134#ifdef QWS
133 // Delete Modules and Libraries 135 // Delete Modules and Libraries
134 QMap<Module*, QLibrary*>::Iterator it; 136 QMap<Module*, QLibrary*>::Iterator it;
135 for( it = libraries.begin(); it != libraries.end(); ++it ){ 137 for( it = libraries.begin(); it != libraries.end(); ++it ){
136 delete it.key(); 138 delete it.key();
137 // I wonder why I can't delete the libraries 139 // I wonder why I can't delete the libraries
138 // What fucking shit this is. 140 // What fucking shit this is.
139 //delete it.data(); 141 //delete it.data();
140 } 142 }
141#else 143#else
142 // klibloader automaticly deletes the libraries for us... 144 // klibloader automaticly deletes the libraries for us...
143#endif 145#endif
144} 146}
145 147
146/** 148/**
147 * Query the kernel for all of the interfaces. 149 * Query the kernel for all of the interfaces.
148 */ 150 */
149void MainWindowImp::getAllInterfaces(){ 151void MainWindowImp::getAllInterfaces(){
150 int sockfd = socket(AF_INET, SOCK_DGRAM, 0); 152 int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
151 if(sockfd == -1) 153 if(sockfd == -1)
152 return; 154 return;
153 155
154 char buf[8*1024]; 156 struct ifreq ifr;
155 struct ifconf ifc; 157 QStringList ifaces;
156 ifc.ifc_len = sizeof(buf); 158 QFile procFile(QString(_PROCNETDEV));
157 ifc.ifc_req = (struct ifreq *) buf; 159 int result;
158 int result=ioctl(sockfd, SIOCGIFCONF, &ifc); 160
159 161 if (! procFile.exists()) {
160 for (char* ptr = buf; ptr < buf + ifc.ifc_len; ){ 162 struct ifreq ifrs[100];
161 struct ifreq *ifr =(struct ifreq *) ptr; 163 struct ifconf ifc;
162 int len = sizeof(struct sockaddr); 164 ifc.ifc_len = sizeof(ifrs);
163#ifdef HAVE_SOCKADDR_SA_LEN 165 ifc.ifc_req = ifrs;
164 if (ifr->ifr_addr.sa_len > len) 166 result = ioctl(sockfd, SIOCGIFCONF, &ifc);
165 len = ifr->ifr_addr.sa_len; /* length > 16 */ 167
166#endif 168 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) {
167 ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */ 169 struct ifreq *pifr = &ifrs[i];
170
171 ifaces += pifr->ifr_name;
172 }
173 } else {
174 procFile.open(IO_ReadOnly);
175 QString line;
176 QTextStream procTs(&procFile);
177 int loc = -1;
178
179 procTs.readLine(); // eat a line
180 procTs.readLine(); // eat a line
181 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
182 if((loc = line.find(":")) != -1) {
183 ifaces += line.left(loc);
184 }
185 }
186 }
168 187
169 int flags; 188 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) {
170 struct sockaddr_in *sinptr; 189 int flags = 0, family;
171 Interface *i = NULL; 190 Interface *i = NULL;
172 switch (ifr->ifr_addr.sa_family){
173 case AF_INET:
174 sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
175 flags=0;
176
177 struct ifreq ifcopy;
178 ifcopy=*ifr;
179 result=ioctl(sockfd,SIOCGIFFLAGS,&ifcopy);
180 flags=ifcopy.ifr_flags;
181 i = new Interface(this, ifr->ifr_name, false);
182 i->setAttached(true);
183 if ((flags & IFF_UP) == IFF_UP)
184 i->setStatus(true);
185 else
186 i->setStatus(false);
187
188 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
189 i->setHardwareName("Ethernet");
190 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
191 i->setHardwareName("Point to Point");
192 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
193 i->setHardwareName("Multicast");
194 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
195 i->setHardwareName("Loopback");
196 else
197 i->setHardwareName("Unknown");
198 191
199 interfaceNames.insert(i->getInterfaceName(), i); 192 strcpy(ifr.ifr_name, (*it).latin1());
200 updateInterface(i);
201 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
202 break;
203 193
204 default: 194 qWarning("ifr.ifr_name=%s\n", ifr.ifr_name);
205 qDebug(ifr->ifr_name); 195
206 qDebug(QString("%1").arg(ifr->ifr_addr.sa_family).latin1()); 196 struct ifreq ifcopy;
207 break; 197 ifcopy = ifr;
208 } 198 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
199 flags = ifcopy.ifr_flags;
200 i = new Interface(this, ifr.ifr_name, false);
201 i->setAttached(true);
202 if ((flags & IFF_UP) == IFF_UP)
203 i->setStatus(true);
204 else
205 i->setStatus(false);
206
207 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
208 i->setHardwareName("Ethernet");
209 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
210 i->setHardwareName("Point to Point");
211 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
212 i->setHardwareName("Multicast");
213 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
214 i->setHardwareName("Loopback");
215 else
216 i->setHardwareName("Unknown");
217
218 qWarning("Adding interface %s to interfaceNames\n", ifr.ifr_name);
219 interfaceNames.insert(i->getInterfaceName(), i);
220 updateInterface(i);
221 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
209 } 222 }
210} 223}
211 224
212/** 225/**
213 * Load all modules that are found in the path 226 * Load all modules that are found in the path
214 * @param path a directory that is scaned for any plugins that can be loaded 227 * @param path a directory that is scaned for any plugins that can be loaded
215 * and attempts to load them 228 * and attempts to load them
216 */ 229 */
217void MainWindowImp::loadModules(const QString &path){ 230void MainWindowImp::loadModules(const QString &path){
218#ifdef DEBUG 231#ifdef DEBUG
219 qDebug("MainWindowImp::loadModules: %s", path.latin1()); 232 qDebug("MainWindowImp::loadModules: %s", path.latin1());
220#endif 233#endif
221 QDir d(path); 234 QDir d(path);
222 if(!d.exists()) 235 if(!d.exists())
223 return; 236 return;
224 237
225 // Don't want sym links 238 // Don't want sym links
226 d.setFilter( QDir::Files | QDir::NoSymLinks ); 239 d.setFilter( QDir::Files | QDir::NoSymLinks );
227 const QFileInfoList *list = d.entryInfoList(); 240 const QFileInfoList *list = d.entryInfoList();
228 QFileInfoListIterator it( *list ); 241 QFileInfoListIterator it( *list );
229 QFileInfo *fi; 242 QFileInfo *fi;
230 while ( (fi=it.current()) ) { 243 while ( (fi=it.current()) ) {
244#ifdef QWS
245 if(fi->fileName().contains(".so")){
246#else
231 if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")){ 247 if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")){
248#endif
232 loadPlugin(path + "/" + fi->fileName()); 249 loadPlugin(path + "/" + fi->fileName());
233 } 250 }
234 ++it; 251 ++it;
235 } 252 }
236} 253}
237 254
238/** 255/**
239 * Attempt to load a function and resolve a function. 256 * Attempt to load a function and resolve a function.
240 * @param pluginFileName - the name of the file in which to attempt to load 257 * @param pluginFileName - the name of the file in which to attempt to load
241 * @param resolveString - function pointer to resolve 258 * @param resolveString - function pointer to resolve
242 * @return pointer to the function with name resolveString or NULL 259 * @return pointer to the function with name resolveString or NULL
243 */ 260 */
244Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){ 261Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){
245#ifdef DEBUG 262#ifdef DEBUG
246 qDebug("MainWindowImp::loadPlugin: %s", pluginFileName.latin1()); 263 qDebug("MainWindowImp::loadPlugin: %s: resolving %s", pluginFileName.latin1(), resolveString.latin1());
247#endif 264#endif
248#ifdef QWS 265#ifdef QWS
249 QLibrary *lib = new QLibrary(pluginFileName); 266 QLibrary *lib = new QLibrary(pluginFileName);
250 void *functionPointer = lib->resolve(resolveString); 267 void *functionPointer = lib->resolve(resolveString);
251 if( !functionPointer ){ 268 if( !functionPointer ){
252#ifdef DEBUG 269#ifdef DEBUG
253 qDebug("MainWindowImp::loadPlugin: File: %s is not a plugin, but though was.", pluginFileName.latin1()); 270 qDebug("MainWindowImp::loadPlugin: Warning: %s is not a plugin", pluginFileName.latin1());
254#endif 271#endif
255 delete lib; 272 delete lib;
256 return NULL; 273 return NULL;
257 } 274 }
258 // Try to get an object. 275 // Try to get an object.
259 Module *object = ((Module* (*)()) functionPointer)(); 276 Module *object = ((Module* (*)()) functionPointer)();
260 if(object == NULL){ 277 if(object == NULL){
261#ifdef DEBUG 278#ifdef DEBUG
262 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 279 qDebug("MainWindowImp: Couldn't create object, but did load library!");
263#endif 280#endif
264 delete lib; 281 delete lib;
265 return NULL; 282 return NULL;
266 } 283 }
267 284
268 // Store for deletion later 285 // Store for deletion later
269 libraries.insert(object, lib); 286 libraries.insert(object, lib);
270 return object; 287 return object;
271 288
272#else 289#else
273 QLibrary *lib = loader->library(pluginFileName); 290 QLibrary *lib = loader->library(pluginFileName);
274 if( !lib || !lib->hasSymbol(resolveString) ){ 291 if( !lib || !lib->hasSymbol(resolveString) ){
275#ifdef DEBUG 292#ifdef DEBUG
276 qDebug(QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); 293 qDebug(QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1());
277#endif 294#endif
278 return NULL; 295 return NULL;
279 } 296 }
280 // Try to get an object. 297 // Try to get an object.
281 Module *object = ((Module* (*)()) lib->symbol(resolveString))(); 298 Module *object = ((Module* (*)()) lib->symbol(resolveString))();
282 if(object == NULL){ 299 if(object == NULL){
283#ifdef DEBUG 300#ifdef DEBUG
284 qDebug("MainWindowImp: Couldn't create object, but did load library!"); 301 qDebug("MainWindowImp: Couldn't create object, but did load library!");
285#endif 302#endif
286 return NULL; 303 return NULL;
287 } 304 }
288#ifdef DEBUG 305#ifdef DEBUG
289 qDebug("MainWindowImp::loadPlugin:: Found object, storing."); 306 qDebug("MainWindowImp::loadPlugin:: Found object, storing.");
290#endif 307#endif
291 // Store for deletion later 308 // Store for deletion later
292 libraries.insert(object, lib); 309 libraries.insert(object, lib);
293 return object; 310 return object;
294#endif 311#endif
295} 312}
296 313
297/** 314/**
298 * The Add button was clicked. Bring up the add dialog and if OK is hit 315 * The Add button was clicked. Bring up the add dialog and if OK is hit
299 * load the plugin and append it to the list 316 * load the plugin and append it to the list
300 */ 317 */
301void MainWindowImp::addClicked(){ 318void MainWindowImp::addClicked(){
302 QMap<Module*, QLibrary*>::Iterator it; 319 QMap<Module*, QLibrary*>::Iterator it;
303 QMap<QString, QString> list; 320 QMap<QString, QString> list;
304 QMap<QString, Module*> newInterfaceOwners; 321 QMap<QString, Module*> newInterfaceOwners;
305 //list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port"); 322 //list.insert("USB (PPP) / (ADD_TEST)", "A dialup connection over the USB port");
306 //list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port"); 323 //list.insert("IrDa (PPP) / (ADD_TEST)", "A dialup connection over the IdDa port");
307 for( it = libraries.begin(); it != libraries.end(); ++it ){ 324 for( it = libraries.begin(); it != libraries.end(); ++it ){
308 if(it.key()){ 325 if(it.key()){
309 (it.key())->possibleNewInterfaces(list); 326 (it.key())->possibleNewInterfaces(list);
310 } 327 }
311 } 328 }
312 // See if the list has anything that we can add. 329 // See if the list has anything that we can add.
313 if(list.count() == 0){ 330 if(list.count() == 0){
314 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); 331 QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok);
315 return; 332 return;
316 } 333 }
317 AddConnectionImp addNewConnection(this, "AddConnectionImp", true); 334 AddConnectionImp addNewConnection(this, "AddConnectionImp", true);
318 addNewConnection.addConnections(list); 335 addNewConnection.addConnections(list);
319 addNewConnection.showMaximized(); 336 addNewConnection.showMaximized();
320 if(QDialog::Accepted == addNewConnection.exec()){ 337 if(QDialog::Accepted == addNewConnection.exec()){
321 QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); 338 QListViewItem *item = addNewConnection.registeredServicesList->currentItem();
322 if(!item) 339 if(!item)
323 return; 340 return;
324 341
325 for( it = libraries.begin(); it != libraries.end(); ++it ){ 342 for( it = libraries.begin(); it != libraries.end(); ++it ){
326 if(it.key()){ 343 if(it.key()){
327 Interface *i = (it.key())->addNewInterface(item->text(0)); 344 Interface *i = (it.key())->addNewInterface(item->text(0));
328 if(i){ 345 if(i){
329 interfaceNames.insert(i->getInterfaceName(), i); 346 interfaceNames.insert(i->getInterfaceName(), i);
330 updateInterface(i); 347 updateInterface(i);
331 } 348 }
332 } 349 }
333 } 350 }
334 } 351 }
335} 352}
336 353
337/** 354/**
338 * Prompt the user to see if they really want to do this. 355 * Prompt the user to see if they really want to do this.
339 * If they do then remove from the list and unload. 356 * If they do then remove from the list and unload.
340 */ 357 */
341void MainWindowImp::removeClicked(){ 358void MainWindowImp::removeClicked(){
342 QListViewItem *item = connectionList->currentItem(); 359 QListViewItem *item = connectionList->currentItem();
343 if(!item) { 360 if(!item) {
344 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 361 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
345 return; 362 return;
346 } 363 }
347 364
348 Interface *i = interfaceItems[item]; 365 Interface *i = interfaceItems[item];
349 if(i->getModuleOwner() == NULL){ 366 if(i->getModuleOwner() == NULL){
350 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); 367 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
351 } 368 }
352 else{ 369 else{
353 if(!i->getModuleOwner()->remove(i)) 370 if(!i->getModuleOwner()->remove(i))
354 QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok); 371 QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok);
355 else{ 372 else{
356 QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); 373 QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
357 // TODO memory managment.... 374 // TODO memory managment....
358 // who deletes the interface? 375 // who deletes the interface?
359 } 376 }
360 } 377 }
361} 378}
362 379
363/** 380/**
364 * Pull up the configure about the currently selected interface. 381 * Pull up the configure about the currently selected interface.
365 * Report an error if no interface is selected. 382 * Report an error if no interface is selected.
366 * If the interface has a module owner then request its configure. 383 * If the interface has a module owner then request its configure.
367 */ 384 */
368void MainWindowImp::configureClicked(){ 385void MainWindowImp::configureClicked(){
369 QListViewItem *item = connectionList->currentItem(); 386 QListViewItem *item = connectionList->currentItem();
370 if(!item){ 387 if(!item){
371 QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); 388 QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok);
372 return; 389 return;
373 } 390 }
374 391
375 Interface *i = interfaceItems[item]; 392 Interface *i = interfaceItems[item];
376 if(i->getModuleOwner()){ 393 if(i->getModuleOwner()){
377 QWidget *moduleConfigure = i->getModuleOwner()->configure(i); 394 QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
378 if(moduleConfigure != NULL){ 395 if(moduleConfigure != NULL){
379 moduleConfigure->showMaximized(); 396 moduleConfigure->showMaximized();
380 return; 397 return;
381 } 398 }
382 } 399 }
383 400
384 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose ); 401 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose );
385 QString currentProfileText = currentProfileLabel->text(); 402 QString currentProfileText = currentProfileLabel->text();
386 if(currentProfileText.upper() == "ALL"); 403 if(currentProfileText.upper() == "ALL");
387 currentProfileText = ""; 404 currentProfileText = "";
388 configure->setProfile(currentProfileText); 405 configure->setProfile(currentProfileText);
389 configure->showMaximized(); 406 configure->showMaximized();
390} 407}
391 408
392/** 409/**
393 * Pull up the information about the currently selected interface. 410 * Pull up the information about the currently selected interface.
394 * Report an error if no interface is selected. 411 * Report an error if no interface is selected.
395 * If the interface has a module owner then request its configure. 412 * If the interface has a module owner then request its configure.
396 */ 413 */
397void MainWindowImp::informationClicked(){ 414void MainWindowImp::informationClicked(){
398 QListViewItem *item = connectionList->currentItem(); 415 QListViewItem *item = connectionList->currentItem();
399 if(!item){ 416 if(!item){
400 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 417 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
401 return; 418 return;
402 } 419 }
403 420
404 Interface *i = interfaceItems[item]; 421 Interface *i = interfaceItems[item];
405 if(!i->isAttached()){ 422 if(!i->isAttached()){
406 QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); 423 QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
407 return; 424 return;
408 } 425 }
409 426
410 if(i->getModuleOwner()){ 427 if(i->getModuleOwner()){
411 QWidget *moduleInformation = i->getModuleOwner()->information(i); 428 QWidget *moduleInformation = i->getModuleOwner()->information(i);
412 if(moduleInformation != NULL){ 429 if(moduleInformation != NULL){
413 moduleInformation->showMaximized(); 430 moduleInformation->showMaximized();
414#ifdef DEBUG 431#ifdef DEBUG
415 qDebug("MainWindowImp::informationClicked:: Module owner has created, we showed."); 432 qDebug("MainWindowImp::informationClicked:: Module owner has created, we showed.");
416#endif 433#endif
417 return; 434 return;
418 } 435 }
419 } 436 }
420 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog); 437 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog);
421 information->showMaximized(); 438 information->showMaximized();
422} 439}
423 440
424/** 441/**
425 * Update this interface. If no QListViewItem exists create one. 442 * Update this interface. If no QListViewItem exists create one.
426 * @param Interface* pointer to the interface that needs to be updated. 443 * @param Interface* pointer to the interface that needs to be updated.
427 */ 444 */
428void MainWindowImp::updateInterface(Interface *i){ 445void MainWindowImp::updateInterface(Interface *i){
429 if(!advancedUserMode){ 446 if(!advancedUserMode){
430 if(i->getInterfaceName() == "lo") 447 if(i->getInterfaceName() == "lo")
431 return; 448 return;
432 } 449 }
433 450
434 QListViewItem *item = NULL; 451 QListViewItem *item = NULL;
435 452
436 // Find the interface, making it if needed. 453 // Find the interface, making it if needed.
437 if(items.find(i) == items.end()){ 454 if(items.find(i) == items.end()){
438 item = new QListViewItem(connectionList, "", "", ""); 455 item = new QListViewItem(connectionList, "", "", "");
439 // See if you can't find a module owner for this interface 456 // See if you can't find a module owner for this interface
440 QMap<Module*, QLibrary*>::Iterator it; 457 QMap<Module*, QLibrary*>::Iterator it;
441 for( it = libraries.begin(); it != libraries.end(); ++it ){ 458 for( it = libraries.begin(); it != libraries.end(); ++it ){
442 if(it.key()->isOwner(i)) 459 if(it.key()->isOwner(i))
443 i->setModuleOwner(it.key()); 460 i->setModuleOwner(it.key());
444 } 461 }
445 items.insert(i, item); 462 items.insert(i, item);
446 interfaceItems.insert(item, i); 463 interfaceItems.insert(item, i);
447 } 464 }
448 else 465 else
449 item = items[i]; 466 item = items[i];
450 467
451 // Update the icons and information 468 // Update the icons and information
452#ifdef QWS 469#ifdef QWS
453 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); 470 item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
454#else 471#else
455 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); 472 item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down")));
456#endif 473#endif
457 474
458 QString typeName = "lan"; 475 QString typeName = "lan";
459 if(i->getHardwareName().contains("Local Loopback")) 476 if(i->getHardwareName().contains("Local Loopback"))
460 typeName = "lo"; 477 typeName = "lo";
461 if(i->getInterfaceName().contains("irda")) 478 if(i->getInterfaceName().contains("irda"))
462 typeName = "irda"; 479 typeName = "irda";
463 if(i->getInterfaceName().contains("wlan")) 480 if(i->getInterfaceName().contains("wlan"))
464 typeName = "wlan"; 481 typeName = "wlan";
465 if(i->getInterfaceName().contains("usb")) 482 if(i->getInterfaceName().contains("usb"))
466 typeName = "usb"; 483 typeName = "usb";
467 484
468 if(!i->isAttached()) 485 if(!i->isAttached())
469 typeName = "connect_no"; 486 typeName = "connect_no";
470 // Actually try to use the Module 487 // Actually try to use the Module
471 if(i->getModuleOwner() != NULL) 488 if(i->getModuleOwner() != NULL)
472 typeName = i->getModuleOwner()->getPixmapName(i); 489 typeName = i->getModuleOwner()->getPixmapName(i);
473 490
474#ifdef QWS 491#ifdef QWS
475 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); 492 item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName)));
476#else 493#else
477 item->setPixmap(1, (SmallIcon(typeName))); 494 item->setPixmap(1, (SmallIcon(typeName)));
478#endif 495#endif
479 item->setText(2, i->getHardwareName()); 496 item->setText(2, i->getHardwareName());
480 item->setText(3, QString("(%1)").arg(i->getInterfaceName())); 497 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
481 item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); 498 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
482} 499}
483 500
484void MainWindowImp::newProfileChanged(const QString& newText){ 501void MainWindowImp::newProfileChanged(const QString& newText){
485 if(newText.length() > 0) 502 if(newText.length() > 0)
486 newProfileButton->setEnabled(true); 503 newProfileButton->setEnabled(true);
487 else 504 else
488 newProfileButton->setEnabled(false); 505 newProfileButton->setEnabled(false);
489} 506}
490 507
491/** 508/**
492 * Adds a new profile to the list of profiles. 509 * Adds a new profile to the list of profiles.
493 * Don't add profiles that already exists. 510 * Don't add profiles that already exists.
494 * Appends to the list and QStringList 511 * Appends to the list and QStringList
495 */ 512 */
496void MainWindowImp::addProfile(){ 513void MainWindowImp::addProfile(){
497 QString newProfileName = newProfile->text(); 514 QString newProfileName = newProfile->text();
498 if(profiles.grep(newProfileName).count() > 0){ 515 if(profiles.grep(newProfileName).count() > 0){
499 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); 516 QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok);
500 return; 517 return;
501 } 518 }
502 profiles.append(newProfileName); 519 profiles.append(newProfileName);
503 profilesList->insertItem(newProfileName); 520 profilesList->insertItem(newProfileName);
504} 521}
505 522
506/** 523/**
507 * Removes the currently selected profile in the combo. 524 * Removes the currently selected profile in the combo.
508 * Doesn't delete if there are less then 2 profiles. 525 * Doesn't delete if there are less then 2 profiles.
509 */ 526 */
510void MainWindowImp::removeProfile(){ 527void MainWindowImp::removeProfile(){
511 if(profilesList->count() <= 1){ 528 if(profilesList->count() <= 1){
512 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); 529 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok);
513 return; 530 return;
514 } 531 }
515 QString profileToRemove = profilesList->currentText(); 532 QString profileToRemove = profilesList->currentText();
516 if(profileToRemove == "All"){ 533 if(profileToRemove == "All"){
517 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); 534 QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok);
518 return; 535 return;
519 } 536 }
520 // Can't remove the curent profile 537 // Can't remove the curent profile
521 if(profileToRemove == currentProfileLabel->text()){ 538 if(profileToRemove == currentProfileLabel->text()){
522 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); 539 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok);
523 return; 540 return;
524 541
525 } 542 }
526 543
527 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 544 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
528 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 545 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
529 profilesList->clear(); 546 profilesList->clear();
530 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 547 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
531 profilesList->insertItem((*it)); 548 profilesList->insertItem((*it));
532 549
533 // Remove any interface settings and mappings. 550 // Remove any interface settings and mappings.
534 Interfaces interfaces; 551 Interfaces interfaces;
535 // Go through them one by one 552 // Go through them one by one
536 QMap<Interface*, QListViewItem*>::Iterator it; 553 QMap<Interface*, QListViewItem*>::Iterator it;
537 for( it = items.begin(); it != items.end(); ++it ){ 554 for( it = items.begin(); it != items.end(); ++it ){
538 QString interfaceName = it.key()->getInterfaceName(); 555 QString interfaceName = it.key()->getInterfaceName();
539 qDebug(interfaceName.latin1()); 556 qDebug(interfaceName.latin1());
540 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ 557 if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){
541 interfaces.removeInterface(); 558 interfaces.removeInterface();
542 if(interfaces.setMapping(interfaceName)){ 559 if(interfaces.setMapping(interfaceName)){
543 if(profilesList->count() == 1) 560 if(profilesList->count() == 1)
544 interfaces.removeMapping(); 561 interfaces.removeMapping();
545 else{ 562 else{
546 interfaces.removeMap("map", interfaceName + "_" + profileToRemove); 563 interfaces.removeMap("map", interfaceName + "_" + profileToRemove);
547 } 564 }
548 } 565 }
549 interfaces.write(); 566 interfaces.write();
550 break; 567 break;
551 } 568 }
552 } 569 }
553 } 570 }
554} 571}
555 572
556/** 573/**
557 * A new profile has been selected, change. 574 * A new profile has been selected, change.
558 * @param newProfile the new profile. 575 * @param newProfile the new profile.
559 */ 576 */
560void MainWindowImp::changeProfile(){ 577void MainWindowImp::changeProfile(){
561 if(profilesList->currentItem() == -1){ 578 if(profilesList->currentItem() == -1){
562 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); 579 QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok);
563 return; 580 return;
564 } 581 }
565 QString newProfile = profilesList->text(profilesList->currentItem()); 582 QString newProfile = profilesList->text(profilesList->currentItem());
566 if(newProfile != currentProfileLabel->text()){ 583 if(newProfile != currentProfileLabel->text()){
567 currentProfileLabel->setText(newProfile); 584 currentProfileLabel->setText(newProfile);
568 QFile::remove(scheme); 585 QFile::remove(scheme);
569 QFile file(scheme); 586 QFile file(scheme);
570 if ( file.open(IO_ReadWrite) ) { 587 if ( file.open(IO_ReadWrite) ) {
571 QTextStream stream( &file ); 588 QTextStream stream( &file );
572 stream << QString("SCHEME=%1").arg(newProfile); 589 stream << QString("SCHEME=%1").arg(newProfile);
573 file.close(); 590 file.close();
574 } 591 }
575 // restart all up devices? 592 // restart all up devices?
576 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ 593 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){
577 // Go through them one by one 594 // Go through them one by one
578 QMap<Interface*, QListViewItem*>::Iterator it; 595 QMap<Interface*, QListViewItem*>::Iterator it;
579 for( it = items.begin(); it != items.end(); ++it ){ 596 for( it = items.begin(); it != items.end(); ++it ){
580 if(it.key()->getStatus() == true) 597 if(it.key()->getStatus() == true)
581 it.key()->restart(); 598 it.key()->restart();
582 } 599 }
583 } 600 }
584 } 601 }
585 // TODO change the profile in the modules 602 // TODO change the profile in the modules
586} 603}
587 604