author | benmeyer <benmeyer> | 2002-10-02 19:23:45 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-10-02 19:23:45 (UTC) |
commit | 2d0c6327dd40ab6847ce055c40ca59893bc8b9b2 (patch) (unidiff) | |
tree | 260222139bb322f24d058cba10db0f7d1c43858f /noncore/settings/networksettings/mainwindowimp.cpp | |
parent | c997983c6917885f6c487b942a9b294fa50ae618 (diff) | |
download | opie-2d0c6327dd40ab6847ce055c40ca59893bc8b9b2.zip opie-2d0c6327dd40ab6847ce055c40ca59893bc8b9b2.tar.gz opie-2d0c6327dd40ab6847ce055c40ca59893bc8b9b2.tar.bz2 |
Fixes
Diffstat (limited to 'noncore/settings/networksettings/mainwindowimp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/mainwindowimp.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index e9429e3..e895971 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp | |||
@@ -1,109 +1,111 @@ | |||
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 "module.h" | 5 | #include "module.h" |
6 | 6 | ||
7 | #include "kprocess.h" | 7 | #include "kprocess.h" |
8 | #include "namedialog.h" | ||
9 | 8 | ||
10 | #include <qpushbutton.h> | 9 | #include <qpushbutton.h> |
11 | #include <qtabwidget.h> | 10 | #include <qtabwidget.h> |
12 | #include <qlistbox.h> | 11 | #include <qlistbox.h> |
12 | #include <qlineedit.h> | ||
13 | #include <qlistview.h> | 13 | #include <qlistview.h> |
14 | #include <qheader.h> | 14 | #include <qheader.h> |
15 | #include <qlabel.h> | 15 | #include <qlabel.h> |
16 | 16 | ||
17 | #include <qmainwindow.h> | 17 | #include <qmainwindow.h> |
18 | #include <qmessagebox.h> | 18 | #include <qmessagebox.h> |
19 | 19 | ||
20 | #include <qpe/config.h> | 20 | #include <qpe/config.h> |
21 | #include <qpe/qlibrary.h> | 21 | #include <qpe/qlibrary.h> |
22 | #include <qpe/resource.h> | 22 | #include <qpe/resource.h> |
23 | 23 | ||
24 | #include <qlist.h> | 24 | #include <qlist.h> |
25 | #include <qdir.h> | 25 | #include <qdir.h> |
26 | #include <qfile.h> | 26 | #include <qfile.h> |
27 | #include <qtextstream.h> | 27 | #include <qtextstream.h> |
28 | 28 | ||
29 | #define TEMP_ALL "/tmp/ifconfig-a" | 29 | #define TEMP_ALL "/tmp/ifconfig-a" |
30 | #define TEMP_UP "/tmp/ifconfig" | 30 | #define TEMP_UP "/tmp/ifconfig" |
31 | 31 | ||
32 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ | 32 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name, true), advancedUserMode(false){ |
33 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); | 33 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); |
34 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | 34 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); |
35 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | 35 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); |
36 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | 36 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); |
37 | 37 | ||
38 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); | 38 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); |
39 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); | 39 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); |
40 | connect(profilesList, SIGNAL(highlighted(const QString&)), this, SLOT(changeProfile(const QString&))); | 40 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); |
41 | 41 | ||
42 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); | ||
42 | // Load connections. | 43 | // Load connections. |
43 | loadModules(QDir::homeDirPath() + "/.networksetup/plugins"); | 44 | loadModules(QDir::homeDirPath() + "/.networksetup/plugins"); |
44 | getInterfaceList(); | 45 | getInterfaceList(); |
45 | connectionList->header()->hide(); | 46 | connectionList->header()->hide(); |
46 | 47 | ||
47 | 48 | ||
48 | Config cfg("NetworkSetup"); | 49 | Config cfg("NetworkSetup"); |
49 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); | 50 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); |
50 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 51 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
51 | profilesList->insertItem((*it)); | 52 | profilesList->insertItem((*it)); |
52 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); | 53 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); |
53 | } | 54 | } |
54 | 55 | ||
55 | /** | 56 | /** |
56 | * Deconstructor. Save profiles. Delete loaded libraries. | 57 | * Deconstructor. Save profiles. Delete loaded libraries. |
57 | */ | 58 | */ |
58 | MainWindowImp::~MainWindowImp(){ | 59 | MainWindowImp::~MainWindowImp(){ |
59 | // Save profiles. | 60 | // Save profiles. |
60 | if(profiles.count() > 1){ | 61 | if(profiles.count() > 1){ |
61 | Config cfg("NetworkSetup"); | 62 | Config cfg("NetworkSetup"); |
63 | cfg.setGroup("General"); | ||
62 | cfg.writeEntry("Profiles", profiles.join(" ")); | 64 | cfg.writeEntry("Profiles", profiles.join(" ")); |
63 | } | 65 | } |
64 | // Delete Modules and Libraries | 66 | // Delete Modules and Libraries |
65 | QMap<Module*, QLibrary*>::Iterator it; | 67 | QMap<Module*, QLibrary*>::Iterator it; |
66 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 68 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
67 | delete it.key(); | 69 | delete it.key(); |
68 | delete it.data(); | 70 | delete it.data(); |
69 | } | 71 | } |
70 | } | 72 | } |
71 | 73 | ||
72 | /** | 74 | /** |
73 | * Load all modules that are found in the path | 75 | * Load all modules that are found in the path |
74 | * @param path a directory that is scaned for any plugins that can be loaded | 76 | * @param path a directory that is scaned for any plugins that can be loaded |
75 | * and attempts to load them | 77 | * and attempts to load them |
76 | */ | 78 | */ |
77 | void MainWindowImp::loadModules(QString path){ | 79 | void MainWindowImp::loadModules(QString path){ |
78 | qDebug(path.latin1()); | 80 | qDebug(path.latin1()); |
79 | QDir d(path); | 81 | QDir d(path); |
80 | if(!d.exists()) | 82 | if(!d.exists()) |
81 | return; | 83 | return; |
82 | 84 | ||
83 | // Don't want sym links | 85 | // Don't want sym links |
84 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 86 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
85 | const QFileInfoList *list = d.entryInfoList(); | 87 | const QFileInfoList *list = d.entryInfoList(); |
86 | QFileInfoListIterator it( *list ); | 88 | QFileInfoListIterator it( *list ); |
87 | QFileInfo *fi; | 89 | QFileInfo *fi; |
88 | while ( (fi=it.current()) ) { | 90 | while ( (fi=it.current()) ) { |
89 | if(fi->fileName().contains(".so")){ | 91 | if(fi->fileName().contains(".so")){ |
90 | loadPlugin(path + "/" + fi->fileName()); | 92 | loadPlugin(path + "/" + fi->fileName()); |
91 | } | 93 | } |
92 | ++it; | 94 | ++it; |
93 | } | 95 | } |
94 | } | 96 | } |
95 | 97 | ||
96 | /** | 98 | /** |
97 | * Attempt to load a function and resolve a function. | 99 | * Attempt to load a function and resolve a function. |
98 | * @param pluginFileName - the name of the file in which to attempt to load | 100 | * @param pluginFileName - the name of the file in which to attempt to load |
99 | * @param resolveString - function pointer to resolve | 101 | * @param resolveString - function pointer to resolve |
100 | * @return pointer to the function with name resolveString or NULL | 102 | * @return pointer to the function with name resolveString or NULL |
101 | */ | 103 | */ |
102 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ | 104 | Module* MainWindowImp::loadPlugin(QString pluginFileName, QString resolveString){ |
103 | qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); | 105 | qDebug(QString("MainWindowImp::loadPlugin: %1").arg(pluginFileName).latin1()); |
104 | QLibrary *lib = new QLibrary(pluginFileName); | 106 | QLibrary *lib = new QLibrary(pluginFileName); |
105 | void *functionPointer = lib->resolve(resolveString); | 107 | void *functionPointer = lib->resolve(resolveString); |
106 | if( !functionPointer ){ | 108 | if( !functionPointer ){ |
107 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 109 | qDebug(QString("MainWindowImp: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
108 | delete lib; | 110 | delete lib; |
109 | return NULL; | 111 | return NULL; |
@@ -327,96 +329,99 @@ void MainWindowImp::jobDone(KProcess *process){ | |||
327 | updateInterface(i); | 329 | updateInterface(i); |
328 | } | 330 | } |
329 | } | 331 | } |
330 | file.close(); | 332 | file.close(); |
331 | QFile::remove(fileName); | 333 | QFile::remove(fileName); |
332 | } | 334 | } |
333 | 335 | ||
334 | /** | 336 | /** |
335 | * Update this interface. If no QListViewItem exists create one. | 337 | * Update this interface. If no QListViewItem exists create one. |
336 | * @param Interface* pointer to the interface that needs to be updated. | 338 | * @param Interface* pointer to the interface that needs to be updated. |
337 | */ | 339 | */ |
338 | void MainWindowImp::updateInterface(Interface *i){ | 340 | void MainWindowImp::updateInterface(Interface *i){ |
339 | QListViewItem *item = NULL; | 341 | QListViewItem *item = NULL; |
340 | 342 | ||
341 | // Find the interface, making it if needed. | 343 | // Find the interface, making it if needed. |
342 | if(items.find(i) == items.end()){ | 344 | if(items.find(i) == items.end()){ |
343 | item = new QListViewItem(connectionList, "", "", ""); | 345 | item = new QListViewItem(connectionList, "", "", ""); |
344 | // See if you can't find a module owner for this interface | 346 | // See if you can't find a module owner for this interface |
345 | QMap<Module*, QLibrary*>::Iterator it; | 347 | QMap<Module*, QLibrary*>::Iterator it; |
346 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 348 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
347 | if(it.key()->isOwner(i)) | 349 | if(it.key()->isOwner(i)) |
348 | i->setModuleOwner(it.key()); | 350 | i->setModuleOwner(it.key()); |
349 | } | 351 | } |
350 | items.insert(i, item); | 352 | items.insert(i, item); |
351 | interfaceItems.insert(item, i); | 353 | interfaceItems.insert(item, i); |
352 | } | 354 | } |
353 | else | 355 | else |
354 | item = items[i]; | 356 | item = items[i]; |
355 | 357 | ||
356 | // Update the icons and information | 358 | // Update the icons and information |
357 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 359 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
358 | 360 | ||
359 | QString typeName = "lan"; | 361 | QString typeName = "lan"; |
360 | if(i->getHardwareName().contains("Local Loopback")) | 362 | if(i->getHardwareName().contains("Local Loopback")) |
361 | typeName = "lo"; | 363 | typeName = "lo"; |
362 | if(i->getInterfaceName().contains("irda")) | 364 | if(i->getInterfaceName().contains("irda")) |
363 | typeName = "irda"; | 365 | typeName = "irda"; |
364 | if(i->getInterfaceName().contains("wlan")) | 366 | if(i->getInterfaceName().contains("wlan")) |
365 | typeName = "wlan"; | 367 | typeName = "wlan"; |
366 | // Actually try to use the Module | 368 | // Actually try to use the Module |
367 | if(i->getModuleOwner() != NULL) | 369 | if(i->getModuleOwner() != NULL) |
368 | typeName = i->getModuleOwner()->getPixmapName(i); | 370 | typeName = i->getModuleOwner()->getPixmapName(i); |
369 | 371 | ||
370 | item->setPixmap(1, (Resource::loadPixmap(typeName))); | 372 | item->setPixmap(1, (Resource::loadPixmap(typeName))); |
371 | item->setText(2, i->getHardwareName()); | 373 | item->setText(2, i->getHardwareName()); |
372 | item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); | 374 | item->setText(3, (i->getStatus()) ? i->getIp() : QString("")); |
373 | } | 375 | } |
374 | 376 | ||
377 | void MainWindowImp::newProfileChanged(const QString& newText){ | ||
378 | if(newText.length() > 0) | ||
379 | newProfileButton->setEnabled(true); | ||
380 | else | ||
381 | newProfileButton->setEnabled(false); | ||
382 | } | ||
383 | |||
375 | /** | 384 | /** |
376 | * Adds a new profile to the list of profiles. | 385 | * Adds a new profile to the list of profiles. |
377 | * Don't add profiles that already exists. | 386 | * Don't add profiles that already exists. |
378 | * Appends to the list and QStringList | 387 | * Appends to the list and QStringList |
379 | */ | 388 | */ |
380 | void MainWindowImp::addProfile(){ | 389 | void MainWindowImp::addProfile(){ |
381 | NameDialog foo(this, "namedialog", true); | 390 | QString newProfileName = newProfile->text(); |
382 | QString newProfileName = foo.go(); | ||
383 | if(newProfileName.length() == 0) | ||
384 | return; | ||
385 | |||
386 | if(profiles.grep(newProfileName).count() > 0){ | 391 | if(profiles.grep(newProfileName).count() > 0){ |
387 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); | 392 | QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok"); |
388 | return; | 393 | return; |
389 | } | 394 | } |
390 | profiles.append(newProfileName); | 395 | profiles.append(newProfileName); |
391 | profilesList->insertItem(newProfileName); | 396 | profilesList->insertItem(newProfileName); |
392 | } | 397 | } |
393 | 398 | ||
394 | /** | 399 | /** |
395 | * Removes the currently selected profile in the combo. | 400 | * Removes the currently selected profile in the combo. |
396 | * Doesn't delete if there are less then 2 profiles. | 401 | * Doesn't delete if there are less then 2 profiles. |
397 | */ | 402 | */ |
398 | void MainWindowImp::removeProfile(){ | 403 | void MainWindowImp::removeProfile(){ |
399 | if(profilesList->count() <= 1){ | 404 | if(profilesList->count() <= 1){ |
400 | QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); | 405 | QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok"); |
401 | return; | 406 | return; |
402 | } | 407 | } |
403 | QString profileToRemove = profilesList->currentText(); | 408 | QString profileToRemove = profilesList->currentText(); |
404 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ | 409 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ |
405 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); | 410 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); |
406 | profilesList->clear(); | 411 | profilesList->clear(); |
407 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 412 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
408 | profilesList->insertItem((*it)); | 413 | profilesList->insertItem((*it)); |
409 | } | 414 | } |
410 | 415 | ||
411 | } | 416 | } |
412 | 417 | ||
413 | /** | 418 | /** |
414 | * A new profile has been selected, change. | 419 | * A new profile has been selected, change. |
415 | * @param newProfile the new profile. | 420 | * @param newProfile the new profile. |
416 | */ | 421 | */ |
417 | void MainWindowImp::changeProfile(const QString& newProfile){ | 422 | void MainWindowImp::changeProfile(){ |
418 | currentProfileLabel->setText(newProfile); | 423 | currentProfileLabel->setText(profilesList->text(profilesList->currentItem())); |
419 | } | 424 | } |
420 | 425 | ||
421 | // mainwindowimp.cpp | 426 | // mainwindowimp.cpp |
422 | 427 | ||