summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/mainwindowimp.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/mainwindowimp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp89
1 files changed, 76 insertions, 13 deletions
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index a446d29..3c0af6a 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -23,58 +23,73 @@
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#define SCHEME "/var/lib/pcmcia/scheme"
35MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ 36MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){
36 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); 37 connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked()));
37 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); 38 connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked()));
38 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); 39 connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked()));
39 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); 40 connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked()));
40 41
41 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); 42 connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile()));
42 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); 43 connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile()));
43 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); 44 connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile()));
44 45
45 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); 46 connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&)));
46 // Load connections. 47 // Load connections.
47 loadModules(QPEApplication::qpeDir() + "/plugins/networksetup"); 48 loadModules(QPEApplication::qpeDir() + "/plugins/networksetup");
48 getInterfaceList(); 49 getInterfaceList();
49 connectionList->header()->hide(); 50 connectionList->header()->hide();
50 51
51 52
52 Config cfg("NetworkSetup"); 53 Config cfg("NetworkSetup");
53 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); 54 profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All"));
54 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 55 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
55 profilesList->insertItem((*it)); 56 profilesList->insertItem((*it));
57 currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All"));
56 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); 58 advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false);
59
60 QFile file(SCHEME);
61 if ( file.open(IO_ReadOnly) ) { // file opened successfully
62 QTextStream stream( &file ); // use a text stream
63 while ( !stream.eof() ) { // until end of file...
64 QString line = stream.readLine(); // line of text excluding '\n'
65 if(line.contains("SCHEME")){
66 line = line.mid(7, line.length());
67 currentProfileLabel->setText(line);
68 break;
69 }
70 }
71 file.close();
72 }
57} 73}
58 74
59/** 75/**
60 * Deconstructor. Save profiles. Delete loaded libraries. 76 * Deconstructor. Save profiles. Delete loaded libraries.
61 */ 77 */
62MainWindowImp::~MainWindowImp(){ 78MainWindowImp::~MainWindowImp(){
63 // Save profiles. 79 // Save profiles.
64 if(profiles.count() > 1){ 80 Config cfg("NetworkSetup");
65 Config cfg("NetworkSetup"); 81 cfg.setGroup("General");
66 cfg.setGroup("General"); 82 cfg.writeEntry("Profiles", profiles.join(" "));
67 cfg.writeEntry("Profiles", profiles.join(" ")); 83
68 }
69 // Delete Modules and Libraries 84 // Delete Modules and Libraries
70 QMap<Module*, QLibrary*>::Iterator it; 85 QMap<Module*, QLibrary*>::Iterator it;
71 for( it = libraries.begin(); it != libraries.end(); ++it ){ 86 for( it = libraries.begin(); it != libraries.end(); ++it ){
72 delete it.key(); 87 delete it.key();
73 delete it.data(); 88 delete it.data();
74 } 89 }
75} 90}
76 91
77/** 92/**
78 * Load all modules that are found in the path 93 * Load all modules that are found in the path
79 * @param path a directory that is scaned for any plugins that can be loaded 94 * @param path a directory that is scaned for any plugins that can be loaded
80 * and attempts to load them 95 * and attempts to load them
@@ -196,63 +211,78 @@ void MainWindowImp::removeClicked(){
196/** 211/**
197 * Pull up the configure about the currently selected interface. 212 * Pull up the configure about the currently selected interface.
198 * Report an error if no interface is selected. 213 * Report an error if no interface is selected.
199 * If the interface has a module owner then request its configure with a empty 214 * 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. 215 * tab. If tab is !NULL then append the interfaces setup widget to it.
201 */ 216 */
202void MainWindowImp::configureClicked(){ 217void MainWindowImp::configureClicked(){
203 QListViewItem *item = connectionList->currentItem(); 218 QListViewItem *item = connectionList->currentItem();
204 if(!item){ 219 if(!item){
205 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 220 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
206 return; 221 return;
207 } 222 }
208 223
224 QString currentProfile = currentProfileLabel->text();
225 if(profilesList->count() <= 1 || currentProfile == "All"){
226 currentProfile = "";
227 }
228
209 Interface *i = interfaceItems[item]; 229 Interface *i = interfaceItems[item];
210 if(i->getModuleOwner()){ 230 if(i->getModuleOwner()){
231 i->getModuleOwner()->setProfile(currentProfileLabel->text());
211 QTabWidget *tabWidget = NULL; 232 QTabWidget *tabWidget = NULL;
212 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget); 233 QWidget *moduleConfigure = i->getModuleOwner()->configure(&tabWidget);
213 if(moduleConfigure != NULL){ 234 if(moduleConfigure != NULL){
214 if(tabWidget != NULL){ 235 if(tabWidget != NULL){
215 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true); 236 InterfaceSetupImp *configure = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, true);
216 tabWidget->insertTab(configure, "TCP/IP"); 237 configure->setProfile(currentProfileLabel->text());
238 tabWidget->insertTab(configure, "TCP/IP");
239
217 } 240 }
218 moduleConfigure->showMaximized(); 241 moduleConfigure->showMaximized();
219 moduleConfigure->show(); 242 moduleConfigure->show();
220 return; 243 return;
221 } 244 }
222 } 245 }
223 246
224 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true); 247 InterfaceSetupImp *configure = new InterfaceSetupImp(0, "InterfaceSetupImp", i, true);
248 configure->setProfile(currentProfileLabel->text());
225 configure->showMaximized(); 249 configure->showMaximized();
226 configure->show(); 250 configure->show();
227} 251}
228 252
229/** 253/**
230 * Pull up the information about the currently selected interface. 254 * Pull up the information about the currently selected interface.
231 * Report an error if no interface is selected. 255 * Report an error if no interface is selected.
232 * If the interface has a module owner then request its configure with a empty 256 * 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. 257 * tab. If tab is !NULL then append the interfaces setup widget to it.
234 */ 258 */
235void MainWindowImp::informationClicked(){ 259void MainWindowImp::informationClicked(){
236 QListViewItem *item = connectionList->currentItem(); 260 QListViewItem *item = connectionList->currentItem();
237 if(!item){ 261 if(!item){
238 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok); 262 QMessageBox::information(this, "Error","Please select an interface.", QMessageBox::Ok);
239 return; 263 return;
240 } 264 }
241 265
242 Interface *i = interfaceItems[item]; 266 Interface *i = interfaceItems[item];
243 if(!i->isAttached()){ 267 if(!i->isAttached()){
244 QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok); 268 QMessageBox::information(this, "Error","No information about\na disconnected interface.", QMessageBox::Ok);
245 return; 269 return;
246 } 270 }
271
272 QStringList list;
273 for(uint i = 0; i < profilesList->count(); i++){
274 list.append(profilesList->text(i));
275 }
276
247 if(i->getModuleOwner()){ 277 if(i->getModuleOwner()){
248 QTabWidget *tabWidget = NULL; 278 QTabWidget *tabWidget = NULL;
249 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget); 279 QWidget *moduleInformation = i->getModuleOwner()->information(&tabWidget);
250 if(moduleInformation != NULL){ 280 if(moduleInformation != NULL){
251 if(tabWidget != NULL){ 281 if(tabWidget != NULL){
252 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true); 282 InterfaceInformationImp *information = new InterfaceInformationImp(tabWidget, "InterfaceSetupImp", i, true);
253 tabWidget->insertTab(information, "TCP/IP"); 283 tabWidget->insertTab(information, "TCP/IP");
254 } 284 }
255 moduleInformation->showMaximized(); 285 moduleInformation->showMaximized();
256 moduleInformation->show(); 286 moduleInformation->show();
257 return; 287 return;
258 } 288 }
@@ -311,25 +341,25 @@ void MainWindowImp::jobDone(KProcess *process){
311 if(fileName == TEMP_ALL) 341 if(fileName == TEMP_ALL)
312 i = new Interface(this, interfaceName, false); 342 i = new Interface(this, interfaceName, false);
313 else 343 else
314 i = new Interface(this, interfaceName, true); 344 i = new Interface(this, interfaceName, true);
315 i->setAttached(true); 345 i->setAttached(true);
316 346
317 QString hardName = "Ethernet"; 347 QString hardName = "Ethernet";
318 int hardwareName = line.find("Link encap:"); 348 int hardwareName = line.find("Link encap:");
319 int macAddress = line.find("HWaddr"); 349 int macAddress = line.find("HWaddr");
320 if(macAddress == -1) 350 if(macAddress == -1)
321 macAddress = line.length(); 351 macAddress = line.length();
322 if(hardwareName != -1) 352 if(hardwareName != -1)
323 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName())); 353 i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) );
324 354
325 interfaceNames.insert(i->getInterfaceName(), i); 355 interfaceNames.insert(i->getInterfaceName(), i);
326 updateInterface(i); 356 updateInterface(i);
327 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 357 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
328 } 358 }
329 // It was an interface we already had. 359 // It was an interface we already had.
330 else{ 360 else{
331 if(fileName != TEMP_ALL) 361 if(fileName != TEMP_ALL)
332 (interfaceNames[interfaceName])->setStatus(true); 362 (interfaceNames[interfaceName])->setStatus(true);
333 } 363 }
334 } 364 }
335 } 365 }
@@ -340,25 +370,25 @@ void MainWindowImp::jobDone(KProcess *process){
340 Interfaces i; 370 Interfaces i;
341 QStringList list = i.getInterfaceList(); 371 QStringList list = i.getInterfaceList();
342 QMap<QString, Interface*>::Iterator it; 372 QMap<QString, Interface*>::Iterator it;
343 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { 373 for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
344 bool found = false; 374 bool found = false;
345 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ 375 for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
346 if(it.key() == (*ni)) 376 if(it.key() == (*ni))
347 found = true; 377 found = true;
348 } 378 }
349 if(!found){ 379 if(!found){
350 Interface *i = new Interface(this, *ni, false); 380 Interface *i = new Interface(this, *ni, false);
351 i->setAttached(false); 381 i->setAttached(false);
352 i->setHardwareName(QString("Disconnected (%1)").arg(*ni)); 382 i->setHardwareName("Disconnected");
353 interfaceNames.insert(i->getInterfaceName(), i); 383 interfaceNames.insert(i->getInterfaceName(), i);
354 updateInterface(i); 384 updateInterface(i);
355 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); 385 connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
356 } 386 }
357 } 387 }
358 } 388 }
359} 389}
360 390
361/** 391/**
362 * Update this interface. If no QListViewItem exists create one. 392 * Update this interface. If no QListViewItem exists create one.
363 * @param Interface* pointer to the interface that needs to be updated. 393 * @param Interface* pointer to the interface that needs to be updated.
364 */ 394 */
@@ -397,25 +427,26 @@ void MainWindowImp::updateInterface(Interface *i){
397 typeName = "wlan"; 427 typeName = "wlan";
398 if(i->getInterfaceName().contains("usb")) 428 if(i->getInterfaceName().contains("usb"))
399 typeName = "usb"; 429 typeName = "usb";
400 430
401 if(!i->isAttached()) 431 if(!i->isAttached())
402 typeName = "connect_no"; 432 typeName = "connect_no";
403 // Actually try to use the Module 433 // Actually try to use the Module
404 if(i->getModuleOwner() != NULL) 434 if(i->getModuleOwner() != NULL)
405 typeName = i->getModuleOwner()->getPixmapName(i); 435 typeName = i->getModuleOwner()->getPixmapName(i);
406 436
407 item->setPixmap(1, (Resource::loadPixmap(typeName))); 437 item->setPixmap(1, (Resource::loadPixmap(typeName)));
408 item->setText(2, i->getHardwareName()); 438 item->setText(2, i->getHardwareName());
409 item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); 439 item->setText(3, QString("(%1)").arg(i->getInterfaceName()));
440 item->setText(4, (i->getStatus()) ? i->getIp() : QString(""));
410} 441}
411 442
412void MainWindowImp::newProfileChanged(const QString& newText){ 443void MainWindowImp::newProfileChanged(const QString& newText){
413 if(newText.length() > 0) 444 if(newText.length() > 0)
414 newProfileButton->setEnabled(true); 445 newProfileButton->setEnabled(true);
415 else 446 else
416 newProfileButton->setEnabled(false); 447 newProfileButton->setEnabled(false);
417} 448}
418 449
419/** 450/**
420 * Adds a new profile to the list of profiles. 451 * Adds a new profile to the list of profiles.
421 * Don't add profiles that already exists. 452 * Don't add profiles that already exists.
@@ -428,35 +459,67 @@ void MainWindowImp::addProfile(){
428 return; 459 return;
429 } 460 }
430 profiles.append(newProfileName); 461 profiles.append(newProfileName);
431 profilesList->insertItem(newProfileName); 462 profilesList->insertItem(newProfileName);
432} 463}
433 464
434/** 465/**
435 * Removes the currently selected profile in the combo. 466 * Removes the currently selected profile in the combo.
436 * Doesn't delete if there are less then 2 profiles. 467 * Doesn't delete if there are less then 2 profiles.
437 */ 468 */
438void MainWindowImp::removeProfile(){ 469void MainWindowImp::removeProfile(){
439 if(profilesList->count() <= 1){ 470 if(profilesList->count() <= 1){
440 QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); 471 QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", "Ok");
441 return; 472 return;
442 } 473 }
443 QString profileToRemove = profilesList->currentText(); 474 QString profileToRemove = profilesList->currentText();
475 if(profileToRemove == "All"){
476 QMessageBox::information(this, "Can't remove.","Can't remove default.", "Ok");
477 return;
478 }
479 // Can't remove the curent profile
480 if(profileToRemove == currentProfileLabel->text()){
481 QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), "Ok");
482 return;
483
484 }
485
444 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ 486 if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
445 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); 487 profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
446 profilesList->clear(); 488 profilesList->clear();
447 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) 489 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
448 profilesList->insertItem((*it)); 490 profilesList->insertItem((*it));
449 } 491 }
450
451} 492}
452 493
453/** 494/**
454 * A new profile has been selected, change. 495 * A new profile has been selected, change.
455 * @param newProfile the new profile. 496 * @param newProfile the new profile.
456 */ 497 */
457void MainWindowImp::changeProfile(){ 498void MainWindowImp::changeProfile(){
458 currentProfileLabel->setText(profilesList->text(profilesList->currentItem())); 499 if(profilesList->currentItem() == -1){
500 QMessageBox::information(this, "Can't Change.","Please select a profile.", "Ok");
501 return;
502 }
503 QString newProfile = profilesList->text(profilesList->currentItem());
504 if(newProfile != currentProfileLabel->text()){
505 currentProfileLabel->setText(newProfile);
506 QFile file(SCHEME);
507 if ( file.open(IO_ReadWrite) ) {
508 QTextStream stream( &file );
509 stream << QString("SCHEME=%1").arg(newProfile);
510 file.close();
511 }
512 // restart all up devices?
513 if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){
514 // Go through them one by one
515 QMap<Interface*, QListViewItem*>::Iterator it;
516 for( it = items.begin(); it != items.end(); ++it ){
517 if(it.key()->getStatus() == true)
518 it.key()->restart();
519 }
520 }
521 }
459} 522}
460 523
461// mainwindowimp.cpp 524// mainwindowimp.cpp
462 525