summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index 50131d8..7e24cda 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -146,98 +146,96 @@ MainWindowImp::~MainWindowImp(){
146} 146}
147 147
148/** 148/**
149 * Query the kernel for all of the interfaces. 149 * Query the kernel for all of the interfaces.
150 */ 150 */
151void MainWindowImp::getAllInterfaces(){ 151void MainWindowImp::getAllInterfaces(){
152 int sockfd = socket(PF_INET, SOCK_DGRAM, 0); 152 int sockfd = socket(PF_INET, SOCK_DGRAM, 0);
153 if(sockfd == -1) 153 if(sockfd == -1)
154 return; 154 return;
155 155
156 struct ifreq ifr; 156 struct ifreq ifr;
157 QStringList ifaces; 157 QStringList ifaces;
158 QFile procFile(QString(_PROCNETDEV)); 158 QFile procFile(QString(_PROCNETDEV));
159 int result; 159 int result;
160 160
161 if (! procFile.exists()) { 161 if (! procFile.exists()) {
162 struct ifreq ifrs[100]; 162 struct ifreq ifrs[100];
163 struct ifconf ifc; 163 struct ifconf ifc;
164 ifc.ifc_len = sizeof(ifrs); 164 ifc.ifc_len = sizeof(ifrs);
165 ifc.ifc_req = ifrs; 165 ifc.ifc_req = ifrs;
166 result = ioctl(sockfd, SIOCGIFCONF, &ifc); 166 result = ioctl(sockfd, SIOCGIFCONF, &ifc);
167 167
168 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) { 168 for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) {
169 struct ifreq *pifr = &ifrs[i]; 169 struct ifreq *pifr = &ifrs[i];
170 170
171 ifaces += pifr->ifr_name; 171 ifaces += pifr->ifr_name;
172 } 172 }
173 } else { 173 } else {
174 procFile.open(IO_ReadOnly); 174 procFile.open(IO_ReadOnly);
175 QString line; 175 QString line;
176 QTextStream procTs(&procFile); 176 QTextStream procTs(&procFile);
177 int loc = -1; 177 int loc = -1;
178 178
179 procTs.readLine(); // eat a line 179 procTs.readLine(); // eat a line
180 procTs.readLine(); // eat a line 180 procTs.readLine(); // eat a line
181 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { 181 while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
182 if((loc = line.find(":")) != -1) { 182 if((loc = line.find(":")) != -1) {
183 ifaces += line.left(loc); 183 ifaces += line.left(loc);
184 } 184 }
185 } 185 }
186 } 186 }
187 187
188 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) { 188 for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) {
189 int flags = 0, family; 189 int flags = 0, family;
190 Interface *i = NULL; 190 Interface *i = NULL;
191 191
192 strcpy(ifr.ifr_name, (*it).latin1()); 192 strcpy(ifr.ifr_name, (*it).latin1());
193 193
194 qWarning("ifr.ifr_name=%s\n", ifr.ifr_name);
195
196 struct ifreq ifcopy; 194 struct ifreq ifcopy;
197 ifcopy = ifr; 195 ifcopy = ifr;
198 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); 196 result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
199 flags = ifcopy.ifr_flags; 197 flags = ifcopy.ifr_flags;
200 i = new Interface(this, ifr.ifr_name, false); 198 i = new Interface(this, ifr.ifr_name, false);
201 i->setAttached(true); 199 i->setAttached(true);
202 if ((flags & IFF_UP) == IFF_UP) 200 if ((flags & IFF_UP) == IFF_UP)
203 i->setStatus(true); 201 i->setStatus(true);
204 else 202 else
205 i->setStatus(false); 203 i->setStatus(false);
206 204
207 if ((flags & IFF_BROADCAST) == IFF_BROADCAST) 205 if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
208 i->setHardwareName("Ethernet"); 206 i->setHardwareName("Ethernet");
209 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) 207 else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
210 i->setHardwareName("Point to Point"); 208 i->setHardwareName("Point to Point");
211 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) 209 else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
212 i->setHardwareName("Multicast"); 210 i->setHardwareName("Multicast");
213 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) 211 else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
214 i->setHardwareName("Loopback"); 212 i->setHardwareName("Loopback");
215 else 213 else
216 i->setHardwareName("Unknown"); 214 i->setHardwareName("Unknown");
217 215
218 qWarning("Adding interface %s to interfaceNames\n", ifr.ifr_name); 216 qWarning("Adding interface %s to interfaceNames\n", ifr.ifr_name);
219 interfaceNames.insert(i->getInterfaceName(), i); 217 interfaceNames.insert(i->getInterfaceName(), i);
220 updateInterface(i); 218 updateInterface(i);
221 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 219 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
222 } 220 }
223} 221}
224 222
225/** 223/**
226 * Load all modules that are found in the path 224 * Load all modules that are found in the path
227 * @param path a directory that is scaned for any plugins that can be loaded 225 * @param path a directory that is scaned for any plugins that can be loaded
228 * and attempts to load them 226 * and attempts to load them
229 */ 227 */
230void MainWindowImp::loadModules(const QString &path){ 228void MainWindowImp::loadModules(const QString &path){
231#ifdef DEBUG 229#ifdef DEBUG
232 qDebug("MainWindowImp::loadModules: %s", path.latin1()); 230 qDebug("MainWindowImp::loadModules: %s", path.latin1());
233#endif 231#endif
234 QDir d(path); 232 QDir d(path);
235 if(!d.exists()) 233 if(!d.exists())
236 return; 234 return;
237 235
238 // Don't want sym links 236 // Don't want sym links
239 d.setFilter( QDir::Files | QDir::NoSymLinks ); 237 d.setFilter( QDir::Files | QDir::NoSymLinks );
240 const QFileInfoList *list = d.entryInfoList(); 238 const QFileInfoList *list = d.entryInfoList();
241 QFileInfoListIterator it( *list ); 239 QFileInfoListIterator it( *list );
242 QFileInfo *fi; 240 QFileInfo *fi;
243 while ( (fi=it.current()) ) { 241 while ( (fi=it.current()) ) {
@@ -344,109 +342,112 @@ void MainWindowImp::addClicked(){
344 Interface *i = (it.key())->addNewInterface(item->text(0)); 342 Interface *i = (it.key())->addNewInterface(item->text(0));
345 if(i){ 343 if(i){
346 interfaceNames.insert(i->getInterfaceName(), i); 344 interfaceNames.insert(i->getInterfaceName(), i);
347 updateInterface(i); 345 updateInterface(i);
348 } 346 }
349 } 347 }
350 } 348 }
351 } 349 }
352} 350}
353 351
354/** 352/**
355 * Prompt the user to see if they really want to do this. 353 * Prompt the user to see if they really want to do this.
356 * If they do then remove from the list and unload. 354 * If they do then remove from the list and unload.
357 */ 355 */
358void MainWindowImp::removeClicked(){ 356void MainWindowImp::removeClicked(){
359 QListViewItem *item = connectionList->currentItem(); 357 QListViewItem *item = connectionList->currentItem();
360 if(!item) { 358 if(!item) {
361 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 359 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
362 return; 360 return;
363 } 361 }
364 362
365 Interface *i = interfaceItems[item]; 363 Interface *i = interfaceItems[item];
366 if(i->getModuleOwner() == NULL){ 364 if(i->getModuleOwner() == NULL){
367 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); 365 QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok);
368 } 366 }
369 else{ 367 else{
370 if(!i->getModuleOwner()->remove(i)) 368 if(!i->getModuleOwner()->remove(i))
371 QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok); 369 QMessageBox::information(this, "Error", "Unable to remove.", QMessageBox::Ok);
372 else{ 370 else{
373 QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); 371 QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok);
374 // TODO memory managment.... 372 // TODO memory managment....
375 // who deletes the interface? 373 // who deletes the interface?
376 } 374 }
377 } 375 }
378} 376}
379 377
380/** 378/**
381 * Pull up the configure about the currently selected interface. 379 * Pull up the configure about the currently selected interface.
382 * Report an error if no interface is selected. 380 * Report an error if no interface is selected.
383 * If the interface has a module owner then request its configure. 381 * If the interface has a module owner then request its configure.
384 */ 382 */
385void MainWindowImp::configureClicked(){ 383void MainWindowImp::configureClicked(){
386 QListViewItem *item = connectionList->currentItem(); 384 QListViewItem *item = connectionList->currentItem();
387 if(!item){ 385 if(!item){
388 QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok); 386 QMessageBox::information(this, "Sorry","Please select an interface first.", QMessageBox::Ok);
389 return; 387 return;
390 } 388 }
391 389
390 QString currentProfileText = currentProfileLabel->text();
391 if(currentProfileText.upper() == "ALL");
392 currentProfileText = "";
393
392 Interface *i = interfaceItems[item]; 394 Interface *i = interfaceItems[item];
395
393 if(i->getModuleOwner()){ 396 if(i->getModuleOwner()){
394 QWidget *moduleConfigure = i->getModuleOwner()->configure(i); 397 QWidget *moduleConfigure = i->getModuleOwner()->configure(i);
395 if(moduleConfigure != NULL){ 398 if(moduleConfigure != NULL){
399 i->getModuleOwner()->setProfile(currentProfileText);
396 moduleConfigure->showMaximized(); 400 moduleConfigure->showMaximized();
397 return; 401 return;
398 } 402 }
399 } 403 }
400 404
401 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose ); 405 InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose );
402 QString currentProfileText = currentProfileLabel->text();
403 if(currentProfileText.upper() == "ALL");
404 currentProfileText = "";
405 configure->setProfile(currentProfileText); 406 configure->setProfile(currentProfileText);
406 configure->showMaximized(); 407 configure->showMaximized();
407} 408}
408 409
409/** 410/**
410 * Pull up the information about the currently selected interface. 411 * Pull up the information about the currently selected interface.
411 * Report an error if no interface is selected. 412 * Report an error if no interface is selected.
412 * If the interface has a module owner then request its configure. 413 * If the interface has a module owner then request its configure.
413 */ 414 */
414void MainWindowImp::informationClicked(){ 415void MainWindowImp::informationClicked(){
415 QListViewItem *item = connectionList->currentItem(); 416 QListViewItem *item = connectionList->currentItem();
416 if(!item){ 417 if(!item){
417 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); 418 QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok);
418 return; 419 return;
419 } 420 }
420 421
421 Interface *i = interfaceItems[item]; 422 Interface *i = interfaceItems[item];
422 if(!i->isAttached()){ 423 if(!i->isAttached()){
423 QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); 424 QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok);
424 return; 425 return;
425 } 426 }
426 427
427 if(i->getModuleOwner()){ 428 if(i->getModuleOwner()){
428 QWidget *moduleInformation = i->getModuleOwner()->information(i); 429 QWidget *moduleInformation = i->getModuleOwner()->information(i);
429 if(moduleInformation != NULL){ 430 if(moduleInformation != NULL){
430 moduleInformation->showMaximized(); 431 moduleInformation->showMaximized();
431#ifdef DEBUG 432#ifdef DEBUG
432 qDebug("MainWindowImp::informationClicked:: Module owner has created, we showed."); 433 qDebug("MainWindowImp::informationClicked:: Module owner has created, we showed.");
433#endif 434#endif
434 return; 435 return;
435 } 436 }
436 } 437 }
437 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog); 438 InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog);
438 information->showMaximized(); 439 information->showMaximized();
439} 440}
440 441
441/** 442/**
442 * Update this interface. If no QListViewItem exists create one. 443 * Update this interface. If no QListViewItem exists create one.
443 * @param Interface* pointer to the interface that needs to be updated. 444 * @param Interface* pointer to the interface that needs to be updated.
444 */ 445 */
445void MainWindowImp::updateInterface(Interface *i){ 446void MainWindowImp::updateInterface(Interface *i){
446 if(!advancedUserMode){ 447 if(!advancedUserMode){
447 if(i->getInterfaceName() == "lo") 448 if(i->getInterfaceName() == "lo")
448 return; 449 return;
449 } 450 }
450 451
451 QListViewItem *item = NULL; 452 QListViewItem *item = NULL;
452 453