author | tille <tille> | 2003-06-17 13:05:55 (UTC) |
---|---|---|
committer | tille <tille> | 2003-06-17 13:05:55 (UTC) |
commit | 154d6deef15b9f7f83ea7a25f2079d9fca034910 (patch) (unidiff) | |
tree | 2cb0428922d8d2a4a2adc49b2c62e44cbbdd3b82 | |
parent | e3aff4e49db15c44faf874ee96d666ad56c1d37a (diff) | |
download | opie-154d6deef15b9f7f83ea7a25f2079d9fca034910.zip opie-154d6deef15b9f7f83ea7a25f2079d9fca034910.tar.gz opie-154d6deef15b9f7f83ea7a25f2079d9fca034910.tar.bz2 |
wellenreiter qcop call works now
dns are saved and read in again
3 files changed, 42 insertions, 27 deletions
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp index 49a47ae..8de30de 100644 --- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp +++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp | |||
@@ -1,196 +1,199 @@ | |||
1 | #include "interfacesetupimp.h" | 1 | #include "interfacesetupimp.h" |
2 | #include "interface.h" | 2 | #include "interface.h" |
3 | 3 | ||
4 | #include <qcheckbox.h> | 4 | #include <qcheckbox.h> |
5 | #include <qlineedit.h> | 5 | #include <qlineedit.h> |
6 | #include <qspinbox.h> | 6 | #include <qspinbox.h> |
7 | #include <qgroupbox.h> | 7 | #include <qgroupbox.h> |
8 | #include <qlabel.h> | 8 | #include <qlabel.h> |
9 | 9 | ||
10 | #include <qmessagebox.h> | 10 | #include <qmessagebox.h> |
11 | 11 | ||
12 | #include <opie/oprocess.h> | 12 | #include <opie/oprocess.h> |
13 | 13 | ||
14 | #ifdef QWS | 14 | #ifdef QWS |
15 | #include <opie/owait.h> | 15 | #include <opie/owait.h> |
16 | #include <qpe/global.h> | 16 | #include <qpe/global.h> |
17 | #include <qapplication.h> | 17 | #include <qapplication.h> |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | #define DNSSCRIPT "changedns" | 20 | #define DNSSCRIPT "changedns" |
21 | 21 | ||
22 | /** | 22 | /** |
23 | * Constuctor. Set up the connection. A profile must be set. | 23 | * Constuctor. Set up the connection. A profile must be set. |
24 | */ | 24 | */ |
25 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, Interfaces *j, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i), interfaces(j), delInterfaces(false){ | 25 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, Interfaces *j, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i), interfaces(j), delInterfaces(false){ |
26 | if (j == 0) { | 26 | if (j == 0) { |
27 | delInterfaces = true; | 27 | delInterfaces = true; |
28 | interfaces = new Interfaces; | 28 | interfaces = new Interfaces; |
29 | } | 29 | } |
30 | } | 30 | } |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Destructor | 33 | * Destructor |
34 | */ | 34 | */ |
35 | InterfaceSetupImp::~InterfaceSetupImp(){ | 35 | InterfaceSetupImp::~InterfaceSetupImp(){ |
36 | if(delInterfaces) { | 36 | if(delInterfaces) { |
37 | delete interfaces; | 37 | delete interfaces; |
38 | } | 38 | } |
39 | } | 39 | } |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Save the current settings, then write out the interfaces file and close. | 42 | * Save the current settings, then write out the interfaces file and close. |
43 | */ | 43 | */ |
44 | bool InterfaceSetupImp::saveChanges(){ | 44 | bool InterfaceSetupImp::saveChanges(){ |
45 | bool error; | 45 | bool error; |
46 | QString iface = interfaces->getInterfaceName(error); | 46 | QString iface = interfaces->getInterfaceName(error); |
47 | if(!saveSettings()) | 47 | if(!saveSettings()) |
48 | return false; | 48 | return false; |
49 | 49 | ||
50 | interfaces->write(); | 50 | interfaces->write(); |
51 | 51 | ||
52 | if (interface->getStatus()) { | 52 | if (interface->getStatus()) { |
53 | QString ifup; | 53 | QString ifup; |
54 | ifup += "ifdown "; | 54 | ifup += "ifdown "; |
55 | ifup += iface; | 55 | ifup += iface; |
56 | ifup += "; ifup "; | 56 | ifup += "; ifup "; |
57 | ifup += iface; | 57 | ifup += iface; |
58 | ifup += ";"; | 58 | ifup += ";"; |
59 | 59 | ||
60 | OProcess restart; | 60 | OProcess restart; |
61 | restart << "sh"; | 61 | restart << "sh"; |
62 | restart << "-c"; | 62 | restart << "-c"; |
63 | restart << ifup; | 63 | restart << ifup; |
64 | 64 | ||
65 | OWait *owait = new OWait(); | 65 | OWait *owait = new OWait(); |
66 | Global::statusMessage( tr( "Restarting interface" ) ); | 66 | Global::statusMessage( tr( "Restarting interface" ) ); |
67 | 67 | ||
68 | owait->show(); | 68 | owait->show(); |
69 | qApp->processEvents(); | 69 | qApp->processEvents(); |
70 | 70 | ||
71 | if (!restart.start(OProcess::Block, OProcess::NoCommunication) ) { | 71 | if (!restart.start(OProcess::Block, OProcess::NoCommunication) ) { |
72 | qWarning("unstable to spawn ifdown/ifup"); | 72 | qWarning("unstable to spawn ifdown/ifup"); |
73 | } | 73 | } |
74 | 74 | ||
75 | owait->hide(); | 75 | owait->hide(); |
76 | delete owait; | 76 | delete owait; |
77 | 77 | ||
78 | interface->refresh(); | 78 | interface->refresh(); |
79 | } | 79 | } |
80 | return true; | 80 | return true; |
81 | } | 81 | } |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Save the settings for the current Interface. | 84 | * Save the settings for the current Interface. |
85 | * @return bool true if successfull, false otherwise | 85 | * @return bool true if successfull, false otherwise |
86 | */ | 86 | */ |
87 | bool InterfaceSetupImp::saveSettings(){ | 87 | bool InterfaceSetupImp::saveSettings(){ |
88 | // eh can't really do anything about it other then return. :-D | 88 | // eh can't really do anything about it other then return. :-D |
89 | if(!interfaces->isInterfaceSet()) | 89 | if(!interfaces->isInterfaceSet()) |
90 | return true; | 90 | return true; |
91 | 91 | ||
92 | bool error = false; | 92 | bool error = false; |
93 | // Loopback case | 93 | // Loopback case |
94 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | 94 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ |
95 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 95 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
96 | return true; | 96 | return true; |
97 | } | 97 | } |
98 | 98 | ||
99 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){ | 99 | if(!dhcpCheckBox->isChecked() && (ipAddressEdit->text().isEmpty() || subnetMaskEdit->text().isEmpty())){ |
100 | QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok); | 100 | QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok); |
101 | return false; | 101 | return false; |
102 | } | 102 | } |
103 | // DHCP | 103 | // DHCP |
104 | if(dhcpCheckBox->isChecked()) { | 104 | if(dhcpCheckBox->isChecked()) { |
105 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); | 105 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); |
106 | interfaces->removeInterfaceOption("address"); | 106 | interfaces->removeInterfaceOption("address"); |
107 | interfaces->removeInterfaceOption("netmask"); | 107 | interfaces->removeInterfaceOption("netmask"); |
108 | interfaces->removeInterfaceOption("gateway"); | 108 | interfaces->removeInterfaceOption("gateway"); |
109 | interfaces->removeInterfaceOption("up "DNSSCRIPT" -a "); | 109 | interfaces->removeInterfaceOption("up "DNSSCRIPT" -a "); |
110 | interfaces->removeInterfaceOption("down "DNSSCRIPT" -r "); | 110 | interfaces->removeInterfaceOption("down "DNSSCRIPT" -r "); |
111 | } else{ | 111 | } else{ |
112 | interfaces->setInterfaceMethod("static"); | 112 | interfaces->setInterfaceMethod("static"); |
113 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); | 113 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); |
114 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); | 114 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); |
115 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); | 115 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); |
116 | if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ | 116 | if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ |
117 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); | 117 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); |
118 | interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns); | 118 | interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns); |
119 | interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns); | 119 | interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns); |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | // IP Information | 123 | // IP Information |
124 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 124 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
125 | return true; | 125 | return true; |
126 | } | 126 | } |
127 | 127 | ||
128 | /** | 128 | /** |
129 | * The Profile has changed. | 129 | * The Profile has changed. |
130 | * @param QString profile the new profile. | 130 | * @param QString profile the new profile. |
131 | */ | 131 | */ |
132 | void InterfaceSetupImp::setProfile(const QString &profile){ | 132 | void InterfaceSetupImp::setProfile(const QString &profile){ |
133 | /* | 133 | /* |
134 | bool error = false; | 134 | bool error = false; |
135 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | 135 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ |
136 | staticGroupBox->hide(); | 136 | staticGroupBox->hide(); |
137 | dhcpCheckBox->hide(); | 137 | dhcpCheckBox->hide(); |
138 | leaseTime->hide(); | 138 | leaseTime->hide(); |
139 | leaseHoursLabel->hide(); | 139 | leaseHoursLabel->hide(); |
140 | } | 140 | } |
141 | */ | 141 | */ |
142 | 142 | ||
143 | QString newInterfaceName = interface->getInterfaceName(); | 143 | QString newInterfaceName = interface->getInterfaceName(); |
144 | if(profile.length() > 0) | 144 | if(profile.length() > 0) |
145 | newInterfaceName += "_" + profile; | 145 | newInterfaceName += "_" + profile; |
146 | // See if we have to make a interface. | 146 | // See if we have to make a interface. |
147 | if(!interfaces->setInterface(newInterfaceName)){ | 147 | if(!interfaces->setInterface(newInterfaceName)){ |
148 | // Add making for this new interface if need too | 148 | // Add making for this new interface if need too |
149 | if(profile != ""){ | 149 | if(profile != ""){ |
150 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); | 150 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); |
151 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 151 | if(!interfaces->setMapping(interface->getInterfaceName())){ |
152 | interfaces->addMapping(interface->getInterfaceName()); | 152 | interfaces->addMapping(interface->getInterfaceName()); |
153 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 153 | if(!interfaces->setMapping(interface->getInterfaceName())){ |
154 | qDebug("InterfaceSetupImp: Added Mapping, but still can't setInterface."); | 154 | qDebug("InterfaceSetupImp: Added Mapping, but still can't setInterface."); |
155 | return; | 155 | return; |
156 | } | 156 | } |
157 | } | 157 | } |
158 | interfaces->setMap("map", newInterfaceName); | 158 | interfaces->setMap("map", newInterfaceName); |
159 | interfaces->setScript("getprofile.sh"); | 159 | interfaces->setScript("getprofile.sh"); |
160 | } | 160 | } |
161 | else{ | 161 | else{ |
162 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); | 162 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); |
163 | if(!interfaces->setInterface(newInterfaceName)){ | 163 | if(!interfaces->setInterface(newInterfaceName)){ |
164 | qDebug("InterfaceSetupImp: Added interface, but still can't setInterface."); | 164 | qDebug("InterfaceSetupImp: Added interface, but still can't setInterface."); |
165 | return; | 165 | return; |
166 | } | 166 | } |
167 | } | 167 | } |
168 | } | 168 | } |
169 | 169 | ||
170 | // We must have a valid interface to get this far so read some settings. | 170 | // We must have a valid interface to get this far so read some settings. |
171 | 171 | ||
172 | // DHCP | 172 | // DHCP |
173 | bool error = false; | 173 | bool error = false; |
174 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) | 174 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) |
175 | dhcpCheckBox->setChecked(true); | 175 | dhcpCheckBox->setChecked(true); |
176 | else | 176 | else |
177 | dhcpCheckBox->setChecked(false); | 177 | dhcpCheckBox->setChecked(false); |
178 | 178 | ||
179 | // IP Information | 179 | // IP Information |
180 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); | 180 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); |
181 | QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); | 181 | QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); |
182 | qDebug("dns >%s<",dns.latin1()); | ||
182 | if(dns.contains(" ")){ | 183 | if(dns.contains(" ")){ |
183 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); | 184 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); |
184 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); | 185 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); |
185 | } | 186 | } |
186 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); | 187 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); |
187 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); | 188 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); |
188 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); | 189 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); |
190 | |||
191 | |||
189 | 192 | ||
190 | qWarning("InterfaceSetupImp::setProfile(%s)\n", profile.latin1()); | 193 | qWarning("InterfaceSetupImp::setProfile(%s)\n", profile.latin1()); |
191 | qWarning("InterfaceSetupImp::setProfile: iface is %s\n", interfaces->getInterfaceName(error).latin1()); | 194 | qWarning("InterfaceSetupImp::setProfile: iface is %s\n", interfaces->getInterfaceName(error).latin1()); |
192 | 195 | ||
193 | } | 196 | } |
194 | 197 | ||
195 | // interfacesetup.cpp | 198 | // interfacesetup.cpp |
196 | 199 | ||
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp index 8ea241d..2d714ca 100644 --- a/noncore/settings/networksettings/mainwindowimp.cpp +++ b/noncore/settings/networksettings/mainwindowimp.cpp | |||
@@ -1,660 +1,665 @@ | |||
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 | #include <qpe/qcopenvelope_qws.h> | 14 | #include <qpe/qcopenvelope_qws.h> |
15 | #include <qtabwidget.h> // in order to disable the profiles tab | 15 | #include <qtabwidget.h> // in order to disable the profiles tab |
16 | 16 | ||
17 | #include <qmessagebox.h> | 17 | #include <qmessagebox.h> |
18 | 18 | ||
19 | #ifdef QWS | 19 | #ifdef QWS |
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 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
24 | #else | 24 | #else |
25 | #include <klibloader.h> | 25 | #include <klibloader.h> |
26 | #define QLibrary KLibrary | 26 | #define QLibrary KLibrary |
27 | #include <kconfig.h> | 27 | #include <kconfig.h> |
28 | #define Config KConfig | 28 | #define Config KConfig |
29 | #include <kapplication.h> | 29 | #include <kapplication.h> |
30 | #include <kstandarddirs.h> | 30 | #include <kstandarddirs.h> |
31 | #include <kiconloader.h> | 31 | #include <kiconloader.h> |
32 | #define showMaximized show | 32 | #define showMaximized show |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #if QT_VERSION < 300 | 35 | #if QT_VERSION < 300 |
36 | #include <qlist.h> | 36 | #include <qlist.h> |
37 | #else | 37 | #else |
38 | #include <qptrlist.h> | 38 | #include <qptrlist.h> |
39 | #endif | 39 | #endif |
40 | #include <qdir.h> | 40 | #include <qdir.h> |
41 | #include <qfile.h> | 41 | #include <qfile.h> |
42 | #include <qtextstream.h> | 42 | #include <qtextstream.h> |
43 | #include <qregexp.h> | 43 | #include <qregexp.h> |
44 | 44 | ||
45 | #include <net/if.h> | 45 | #include <net/if.h> |
46 | #include <sys/ioctl.h> | 46 | #include <sys/ioctl.h> |
47 | #include <sys/socket.h> | 47 | #include <sys/socket.h> |
48 | 48 | ||
49 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" | 49 | #define DEFAULT_SCHEME "/var/lib/pcmcia/scheme" |
50 | #define _PROCNETDEV "/proc/net/dev" | 50 | #define _PROCNETDEV "/proc/net/dev" |
51 | 51 | ||
52 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name), advancedUserMode(true), scheme(DEFAULT_SCHEME){ | 52 | MainWindowImp::MainWindowImp(QWidget *parent, const char *name) : MainWindow(parent, name), advancedUserMode(true), scheme(DEFAULT_SCHEME){ |
53 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); | 53 | connect(addConnectionButton, SIGNAL(clicked()), this, SLOT(addClicked())); |
54 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); | 54 | connect(removeConnectionButton, SIGNAL(clicked()), this, SLOT(removeClicked())); |
55 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); | 55 | connect(informationConnectionButton, SIGNAL(clicked()), this, SLOT(informationClicked())); |
56 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); | 56 | connect(configureConnectionButton, SIGNAL(clicked()), this, SLOT(configureClicked())); |
57 | 57 | ||
58 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); | 58 | connect(newProfileButton, SIGNAL(clicked()), this, SLOT(addProfile())); |
59 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); | 59 | connect(removeProfileButton, SIGNAL(clicked()), this, SLOT(removeProfile())); |
60 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); | 60 | connect(setCurrentProfileButton, SIGNAL(clicked()), this, SLOT(changeProfile())); |
61 | 61 | ||
62 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); | 62 | connect(newProfile, SIGNAL(textChanged(const QString&)), this, SLOT(newProfileChanged(const QString&))); |
63 | 63 | ||
64 | //FIXME: disable profiles for the moment: | 64 | //FIXME: disable profiles for the moment: |
65 | // tabWidget->setTabEnabled( tab, false ); | 65 | // tabWidget->setTabEnabled( tab, false ); |
66 | 66 | ||
67 | // Load connections. | 67 | // Load connections. |
68 | // /usr/local/kde/lib/libinterfaces.la | 68 | // /usr/local/kde/lib/libinterfaces.la |
69 | #ifdef QWS | 69 | #ifdef QWS |
70 | loadModules(QPEApplication::qpeDir() + "plugins/networksettings"); | 70 | loadModules(QPEApplication::qpeDir() + "plugins/networksettings"); |
71 | #else | 71 | #else |
72 | loader = KLibLoader::self(); | 72 | loader = KLibLoader::self(); |
73 | loadModules(QString("/usr/")+KStandardDirs::kde_default("lib")); | 73 | loadModules(QString("/usr/")+KStandardDirs::kde_default("lib")); |
74 | #endif | 74 | #endif |
75 | getAllInterfaces(); | 75 | getAllInterfaces(); |
76 | 76 | ||
77 | Interfaces i; | 77 | Interfaces i; |
78 | QStringList list = i.getInterfaceList(); | 78 | QStringList list = i.getInterfaceList(); |
79 | QMap<QString, Interface*>::Iterator it; | 79 | QMap<QString, Interface*>::Iterator it; |
80 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { | 80 | for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) { |
81 | bool found = false; | 81 | bool found = false; |
82 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ | 82 | for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){ |
83 | if(it.key() == (*ni)) | 83 | if(it.key() == (*ni)) |
84 | found = true; | 84 | found = true; |
85 | } | 85 | } |
86 | if(!found){ | 86 | if(!found){ |
87 | if(!(*ni).contains("_")){ | 87 | if(!(*ni).contains("_")){ |
88 | Interface *i = new Interface(this, *ni, false); | 88 | Interface *i = new Interface(this, *ni, false); |
89 | i->setAttached(false); | 89 | i->setAttached(false); |
90 | i->setHardwareName(tr("Disconnected")); | 90 | i->setHardwareName(tr("Disconnected")); |
91 | interfaceNames.insert(i->getInterfaceName(), i); | 91 | interfaceNames.insert(i->getInterfaceName(), i); |
92 | updateInterface(i); | 92 | updateInterface(i); |
93 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); | 93 | connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *))); |
94 | } | 94 | } |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | //getInterfaceList(); | 98 | //getInterfaceList(); |
99 | connectionList->header()->hide(); | 99 | connectionList->header()->hide(); |
100 | 100 | ||
101 | Config cfg("NetworkSetup"); | 101 | Config cfg("NetworkSetup"); |
102 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); | 102 | profiles = QStringList::split(" ", cfg.readEntry("Profiles", "All")); |
103 | for ( QStringList::Iterator it = profiles.begin(); | 103 | for ( QStringList::Iterator it = profiles.begin(); |
104 | it != profiles.end(); ++it) | 104 | it != profiles.end(); ++it) |
105 | profilesList->insertItem((*it)); | 105 | profilesList->insertItem((*it)); |
106 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); | 106 | currentProfileLabel->setText(cfg.readEntry("CurrentProfile", "All")); |
107 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); | 107 | advancedUserMode = cfg.readBoolEntry("AdvancedUserMode", false); |
108 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); | 108 | scheme = cfg.readEntry("SchemeFile", DEFAULT_SCHEME); |
109 | 109 | ||
110 | QFile file(scheme); | 110 | QFile file(scheme); |
111 | if ( file.open(IO_ReadOnly) ) { // file opened successfully | 111 | if ( file.open(IO_ReadOnly) ) { // file opened successfully |
112 | QTextStream stream( &file ); // use a text stream | 112 | QTextStream stream( &file ); // use a text stream |
113 | while ( !stream.eof() ) { // until end of file... | 113 | while ( !stream.eof() ) { // until end of file... |
114 | QString line = stream.readLine(); // line of text excluding '\n' | 114 | QString line = stream.readLine(); // line of text excluding '\n' |
115 | if(line.contains("SCHEME")){ | 115 | if(line.contains("SCHEME")){ |
116 | line = line.mid(7, line.length()); | 116 | line = line.mid(7, line.length()); |
117 | currentProfileLabel->setText(line); | 117 | currentProfileLabel->setText(line); |
118 | break; | 118 | break; |
119 | } | 119 | } |
120 | } | 120 | } |
121 | file.close(); | 121 | file.close(); |
122 | } | 122 | } |
123 | makeChannel(); | 123 | makeChannel(); |
124 | } | 124 | } |
125 | 125 | ||
126 | /** | 126 | /** |
127 | * Deconstructor. Save profiles. Delete loaded libraries. | 127 | * Deconstructor. Save profiles. Delete loaded libraries. |
128 | */ | 128 | */ |
129 | MainWindowImp::~MainWindowImp(){ | 129 | MainWindowImp::~MainWindowImp(){ |
130 | // Save profiles. | 130 | // Save profiles. |
131 | Config cfg("NetworkSetup"); | 131 | Config cfg("NetworkSetup"); |
132 | cfg.setGroup("General"); | 132 | cfg.setGroup("General"); |
133 | cfg.writeEntry("Profiles", profiles.join(" ")); | 133 | cfg.writeEntry("Profiles", profiles.join(" ")); |
134 | 134 | ||
135 | // Delete all interfaces that don't have owners. | 135 | // Delete all interfaces that don't have owners. |
136 | QMap<Interface*, QListViewItem*>::Iterator iIt; | 136 | QMap<Interface*, QListViewItem*>::Iterator iIt; |
137 | for( iIt = items.begin(); iIt != items.end(); ++iIt ){ | 137 | for( iIt = items.begin(); iIt != items.end(); ++iIt ){ |
138 | if(iIt.key()->getModuleOwner() == NULL) | 138 | if(iIt.key()->getModuleOwner() == NULL) |
139 | delete iIt.key(); | 139 | delete iIt.key(); |
140 | } | 140 | } |
141 | 141 | ||
142 | #ifdef QWS | 142 | #ifdef QWS |
143 | // Delete Modules and Libraries | 143 | // Delete Modules and Libraries |
144 | QMap<Module*, QLibrary*>::Iterator it; | 144 | QMap<Module*, QLibrary*>::Iterator it; |
145 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 145 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
146 | delete it.key(); | 146 | delete it.key(); |
147 | // I wonder why I can't delete the libraries | 147 | // I wonder why I can't delete the libraries |
148 | // What fucking shit this is. | 148 | // What fucking shit this is. |
149 | //delete it.data(); | 149 | //delete it.data(); |
150 | } | 150 | } |
151 | #else | 151 | #else |
152 | // klibloader automaticly deletes the libraries for us... | 152 | // klibloader automaticly deletes the libraries for us... |
153 | #endif | 153 | #endif |
154 | } | 154 | } |
155 | 155 | ||
156 | /** | 156 | /** |
157 | * Query the kernel for all of the interfaces. | 157 | * Query the kernel for all of the interfaces. |
158 | */ | 158 | */ |
159 | void MainWindowImp::getAllInterfaces(){ | 159 | void MainWindowImp::getAllInterfaces(){ |
160 | int sockfd = socket(PF_INET, SOCK_DGRAM, 0); | 160 | int sockfd = socket(PF_INET, SOCK_DGRAM, 0); |
161 | if(sockfd == -1) | 161 | if(sockfd == -1) |
162 | return; | 162 | return; |
163 | 163 | ||
164 | struct ifreq ifr; | 164 | struct ifreq ifr; |
165 | QStringList ifaces; | 165 | QStringList ifaces; |
166 | QFile procFile(QString(_PROCNETDEV)); | 166 | QFile procFile(QString(_PROCNETDEV)); |
167 | int result; | 167 | int result; |
168 | Interface *i; | 168 | Interface *i; |
169 | 169 | ||
170 | if (! procFile.exists()) { | 170 | if (! procFile.exists()) { |
171 | struct ifreq ifrs[100]; | 171 | struct ifreq ifrs[100]; |
172 | struct ifconf ifc; | 172 | struct ifconf ifc; |
173 | ifc.ifc_len = sizeof(ifrs); | 173 | ifc.ifc_len = sizeof(ifrs); |
174 | ifc.ifc_req = ifrs; | 174 | ifc.ifc_req = ifrs; |
175 | result = ioctl(sockfd, SIOCGIFCONF, &ifc); | 175 | result = ioctl(sockfd, SIOCGIFCONF, &ifc); |
176 | 176 | ||
177 | for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) { | 177 | for (unsigned int i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++) { |
178 | struct ifreq *pifr = &ifrs[i]; | 178 | struct ifreq *pifr = &ifrs[i]; |
179 | 179 | ||
180 | ifaces += pifr->ifr_name; | 180 | ifaces += pifr->ifr_name; |
181 | } | 181 | } |
182 | } else { | 182 | } else { |
183 | procFile.open(IO_ReadOnly); | 183 | procFile.open(IO_ReadOnly); |
184 | QString line; | 184 | QString line; |
185 | QTextStream procTs(&procFile); | 185 | QTextStream procTs(&procFile); |
186 | int loc = -1; | 186 | int loc = -1; |
187 | 187 | ||
188 | procTs.readLine(); // eat a line | 188 | procTs.readLine(); // eat a line |
189 | procTs.readLine(); // eat a line | 189 | procTs.readLine(); // eat a line |
190 | while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { | 190 | while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { |
191 | if((loc = line.find(":")) != -1) { | 191 | if((loc = line.find(":")) != -1) { |
192 | ifaces += line.left(loc); | 192 | ifaces += line.left(loc); |
193 | } | 193 | } |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) { | 197 | for (QStringList::Iterator it = ifaces.begin(); it != ifaces.end(); ++it) { |
198 | int flags = 0; | 198 | int flags = 0; |
199 | // int family; | 199 | // int family; |
200 | i = NULL; | 200 | i = NULL; |
201 | 201 | ||
202 | strcpy(ifr.ifr_name, (*it).latin1()); | 202 | strcpy(ifr.ifr_name, (*it).latin1()); |
203 | 203 | ||
204 | struct ifreq ifcopy; | 204 | struct ifreq ifcopy; |
205 | ifcopy = ifr; | 205 | ifcopy = ifr; |
206 | result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); | 206 | result = ioctl(sockfd, SIOCGIFFLAGS, &ifcopy); |
207 | flags = ifcopy.ifr_flags; | 207 | flags = ifcopy.ifr_flags; |
208 | i = new Interface(this, ifr.ifr_name, false); | 208 | i = new Interface(this, ifr.ifr_name, false); |
209 | i->setAttached(true); | 209 | i->setAttached(true); |
210 | if ((flags & IFF_UP) == IFF_UP) | 210 | if ((flags & IFF_UP) == IFF_UP) |
211 | i->setStatus(true); | 211 | i->setStatus(true); |
212 | else | 212 | else |
213 | i->setStatus(false); | 213 | i->setStatus(false); |
214 | 214 | ||
215 | if ((flags & IFF_BROADCAST) == IFF_BROADCAST) | 215 | if ((flags & IFF_BROADCAST) == IFF_BROADCAST) |
216 | i->setHardwareName("Ethernet"); | 216 | i->setHardwareName("Ethernet"); |
217 | else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) | 217 | else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT) |
218 | i->setHardwareName("Point to Point"); | 218 | i->setHardwareName("Point to Point"); |
219 | else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) | 219 | else if ((flags & IFF_MULTICAST) == IFF_MULTICAST) |
220 | i->setHardwareName("Multicast"); | 220 | i->setHardwareName("Multicast"); |
221 | else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) | 221 | else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK) |
222 | i->setHardwareName("Loopback"); | 222 | i->setHardwareName("Loopback"); |
223 | else | 223 | else |
224 | i->setHardwareName("Unknown"); | 224 | i->setHardwareName("Unknown"); |
225 | 225 | ||
226 | qWarning("Adding interface %s to interfaceNames\n", ifr.ifr_name); | 226 | qWarning("Adding interface %s to interfaceNames\n", ifr.ifr_name); |
227 | interfaceNames.insert(i->getInterfaceName(), i); | 227 | interfaceNames.insert(i->getInterfaceName(), i); |
228 | updateInterface(i); | 228 | updateInterface(i); |
229 | connect(i, SIGNAL(updateInterface(Interface *)), | 229 | connect(i, SIGNAL(updateInterface(Interface *)), |
230 | this, SLOT(updateInterface(Interface *))); | 230 | this, SLOT(updateInterface(Interface *))); |
231 | } | 231 | } |
232 | // now lets ask the plugins too ;) | 232 | // now lets ask the plugins too ;) |
233 | QMap<Module*, QLibrary*>::Iterator it; | 233 | QMap<Module*, QLibrary*>::Iterator it; |
234 | QList<Interface> ilist; | 234 | QList<Interface> ilist; |
235 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 235 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
236 | if(it.key()){ | 236 | if(it.key()){ |
237 | ilist = it.key()->getInterfaces(); | 237 | ilist = it.key()->getInterfaces(); |
238 | for( i = ilist.first(); i != 0; i = ilist.next() ){ | 238 | for( i = ilist.first(); i != 0; i = ilist.next() ){ |
239 | qWarning("Adding interface %s to interfaceNames\n", i->getInterfaceName().latin1() ); | 239 | qWarning("Adding interface %s to interfaceNames\n", i->getInterfaceName().latin1() ); |
240 | interfaceNames.insert(i->getInterfaceName(), i); | 240 | interfaceNames.insert(i->getInterfaceName(), i); |
241 | updateInterface(i); | 241 | updateInterface(i); |
242 | connect(i, SIGNAL(updateInterface(Interface *)), | 242 | connect(i, SIGNAL(updateInterface(Interface *)), |
243 | this, SLOT(updateInterface(Interface *))); | 243 | this, SLOT(updateInterface(Interface *))); |
244 | } | 244 | } |
245 | } | 245 | } |
246 | } | 246 | } |
247 | } | 247 | } |
248 | 248 | ||
249 | /** | 249 | /** |
250 | * Load all modules that are found in the path | 250 | * Load all modules that are found in the path |
251 | * @param path a directory that is scaned for any plugins that can be loaded | 251 | * @param path a directory that is scaned for any plugins that can be loaded |
252 | * and attempts to load them | 252 | * and attempts to load them |
253 | */ | 253 | */ |
254 | void MainWindowImp::loadModules(const QString &path){ | 254 | void MainWindowImp::loadModules(const QString &path){ |
255 | #ifdef DEBUG | 255 | #ifdef DEBUG |
256 | qDebug("MainWindowImp::loadModules: %s", path.latin1()); | 256 | qDebug("MainWindowImp::loadModules: %s", path.latin1()); |
257 | #endif | 257 | #endif |
258 | QDir d(path); | 258 | QDir d(path); |
259 | if(!d.exists()) | 259 | if(!d.exists()) |
260 | return; | 260 | return; |
261 | 261 | ||
262 | // Don't want sym links | 262 | // Don't want sym links |
263 | d.setFilter( QDir::Files | QDir::NoSymLinks ); | 263 | d.setFilter( QDir::Files | QDir::NoSymLinks ); |
264 | const QFileInfoList *list = d.entryInfoList(); | 264 | const QFileInfoList *list = d.entryInfoList(); |
265 | QFileInfoListIterator it( *list ); | 265 | QFileInfoListIterator it( *list ); |
266 | QFileInfo *fi; | 266 | QFileInfo *fi; |
267 | while ( (fi=it.current()) ) { | 267 | while ( (fi=it.current()) ) { |
268 | #ifdef QWS | 268 | #ifdef QWS |
269 | if(fi->fileName().contains(".so")){ | 269 | if(fi->fileName().contains(".so")){ |
270 | #else | 270 | #else |
271 | if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")){ | 271 | if(fi->fileName().contains(".so") && fi->fileName().contains("networksettings_")){ |
272 | #endif | 272 | #endif |
273 | loadPlugin(path + "/" + fi->fileName()); | 273 | loadPlugin(path + "/" + fi->fileName()); |
274 | qDebug("loaded plugin: >%s< ",QString(path + "/" + fi->fileName()).latin1()); | 274 | qDebug("loaded plugin: >%s< ",QString(path + "/" + fi->fileName()).latin1()); |
275 | } | 275 | } |
276 | ++it; | 276 | ++it; |
277 | } | 277 | } |
278 | } | 278 | } |
279 | 279 | ||
280 | /** | 280 | /** |
281 | * Attempt to load a function and resolve a function. | 281 | * Attempt to load a function and resolve a function. |
282 | * @param pluginFileName - the name of the file in which to attempt to load | 282 | * @param pluginFileName - the name of the file in which to attempt to load |
283 | * @param resolveString - function pointer to resolve | 283 | * @param resolveString - function pointer to resolve |
284 | * @return pointer to the function with name resolveString or NULL | 284 | * @return pointer to the function with name resolveString or NULL |
285 | */ | 285 | */ |
286 | Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){ | 286 | Module* MainWindowImp::loadPlugin(const QString &pluginFileName, const QString &resolveString){ |
287 | #ifdef DEBUG | 287 | #ifdef DEBUG |
288 | qDebug("MainWindowImp::loadPlugin: %s: resolving %s", pluginFileName.latin1(), resolveString.latin1()); | 288 | qDebug("MainWindowImp::loadPlugin: %s: resolving %s", pluginFileName.latin1(), resolveString.latin1()); |
289 | #endif | 289 | #endif |
290 | #ifdef QWS | 290 | #ifdef QWS |
291 | QLibrary *lib = new QLibrary(pluginFileName); | 291 | QLibrary *lib = new QLibrary(pluginFileName); |
292 | void *functionPointer = lib->resolve(resolveString); | 292 | void *functionPointer = lib->resolve(resolveString); |
293 | if( !functionPointer ){ | 293 | if( !functionPointer ){ |
294 | #ifdef DEBUG | 294 | #ifdef DEBUG |
295 | qDebug("MainWindowImp::loadPlugin: Warning: %s is not a plugin", pluginFileName.latin1()); | 295 | qDebug("MainWindowImp::loadPlugin: Warning: %s is not a plugin", pluginFileName.latin1()); |
296 | #endif | 296 | #endif |
297 | delete lib; | 297 | delete lib; |
298 | return NULL; | 298 | return NULL; |
299 | } | 299 | } |
300 | // Try to get an object. | 300 | // Try to get an object. |
301 | Module *object = ((Module* (*)()) functionPointer)(); | 301 | Module *object = ((Module* (*)()) functionPointer)(); |
302 | if(object == NULL){ | 302 | if(object == NULL){ |
303 | #ifdef DEBUG | 303 | #ifdef DEBUG |
304 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 304 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
305 | #endif | 305 | #endif |
306 | delete lib; | 306 | delete lib; |
307 | return NULL; | 307 | return NULL; |
308 | } | 308 | } |
309 | 309 | ||
310 | // Store for deletion later | 310 | // Store for deletion later |
311 | libraries.insert(object, lib); | 311 | libraries.insert(object, lib); |
312 | return object; | 312 | return object; |
313 | 313 | ||
314 | #else | 314 | #else |
315 | QLibrary *lib = loader->library(pluginFileName); | 315 | QLibrary *lib = loader->library(pluginFileName); |
316 | if( !lib || !lib->hasSymbol(resolveString) ){ | 316 | if( !lib || !lib->hasSymbol(resolveString) ){ |
317 | qDebug(QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); | 317 | qDebug(QString("MainWindowImp::loadPlugin: File: %1 is not a plugin, but though was.").arg(pluginFileName).latin1()); |
318 | return NULL; | 318 | return NULL; |
319 | } | 319 | } |
320 | // Try to get an object. | 320 | // Try to get an object. |
321 | Module *object = ((Module* (*)()) lib->symbol(resolveString))(); | 321 | Module *object = ((Module* (*)()) lib->symbol(resolveString))(); |
322 | if(object == NULL){ | 322 | if(object == NULL){ |
323 | #ifdef DEBUG | 323 | #ifdef DEBUG |
324 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); | 324 | qDebug("MainWindowImp: Couldn't create object, but did load library!"); |
325 | #endif | 325 | #endif |
326 | return NULL; | 326 | return NULL; |
327 | } | 327 | } |
328 | #ifdef DEBUG | 328 | #ifdef DEBUG |
329 | qDebug("MainWindowImp::loadPlugin:: Found object, storing."); | 329 | qDebug("MainWindowImp::loadPlugin:: Found object, storing."); |
330 | #endif | 330 | #endif |
331 | // Store for deletion later | 331 | // Store for deletion later |
332 | libraries.insert(object, lib); | 332 | libraries.insert(object, lib); |
333 | return object; | 333 | return object; |
334 | #endif | 334 | #endif |
335 | } | 335 | } |
336 | 336 | ||
337 | /** | 337 | /** |
338 | * The Add button was clicked. Bring up the add dialog and if OK is hit | 338 | * The Add button was clicked. Bring up the add dialog and if OK is hit |
339 | * load the plugin and append it to the list | 339 | * load the plugin and append it to the list |
340 | */ | 340 | */ |
341 | void MainWindowImp::addClicked(){ | 341 | void MainWindowImp::addClicked(){ |
342 | QMap<Module*, QLibrary*>::Iterator it; | 342 | QMap<Module*, QLibrary*>::Iterator it; |
343 | QMap<QString, QString> list; | 343 | QMap<QString, QString> list; |
344 | QMap<QString, Module*> newInterfaceOwners; | 344 | QMap<QString, Module*> newInterfaceOwners; |
345 | 345 | ||
346 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 346 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
347 | if(it.key()){ | 347 | if(it.key()){ |
348 | (it.key())->possibleNewInterfaces(list); | 348 | (it.key())->possibleNewInterfaces(list); |
349 | } | 349 | } |
350 | } | 350 | } |
351 | // See if the list has anything that we can add. | 351 | // See if the list has anything that we can add. |
352 | if(list.count() == 0){ | 352 | if(list.count() == 0){ |
353 | QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); | 353 | QMessageBox::information(this, "Sorry", "Nothing to add.", QMessageBox::Ok); |
354 | return; | 354 | return; |
355 | } | 355 | } |
356 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); | 356 | AddConnectionImp addNewConnection(this, "AddConnectionImp", true); |
357 | addNewConnection.addConnections(list); | 357 | addNewConnection.addConnections(list); |
358 | addNewConnection.showMaximized(); | 358 | addNewConnection.showMaximized(); |
359 | if(QDialog::Accepted == addNewConnection.exec()){ | 359 | if(QDialog::Accepted == addNewConnection.exec()){ |
360 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); | 360 | QListViewItem *item = addNewConnection.registeredServicesList->currentItem(); |
361 | if(!item) | 361 | if(!item) |
362 | return; | 362 | return; |
363 | 363 | ||
364 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 364 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
365 | if(it.key()){ | 365 | if(it.key()){ |
366 | Interface *i = (it.key())->addNewInterface(item->text(0)); | 366 | Interface *i = (it.key())->addNewInterface(item->text(0)); |
367 | if(i){ | 367 | if(i){ |
368 | qDebug("iface name %s",i->getInterfaceName().latin1()); | 368 | qDebug("iface name %s",i->getInterfaceName().latin1()); |
369 | interfaceNames.insert(i->getInterfaceName(), i); | 369 | interfaceNames.insert(i->getInterfaceName(), i); |
370 | updateInterface(i); | 370 | updateInterface(i); |
371 | } | 371 | } |
372 | } | 372 | } |
373 | } | 373 | } |
374 | } | 374 | } |
375 | } | 375 | } |
376 | 376 | ||
377 | /** | 377 | /** |
378 | * Prompt the user to see if they really want to do this. | 378 | * Prompt the user to see if they really want to do this. |
379 | * If they do then remove from the list and unload. | 379 | * If they do then remove from the list and unload. |
380 | */ | 380 | */ |
381 | void MainWindowImp::removeClicked(){ | 381 | void MainWindowImp::removeClicked(){ |
382 | QListViewItem *item = connectionList->currentItem(); | 382 | QListViewItem *item = connectionList->currentItem(); |
383 | if(!item) { | 383 | if(!item) { |
384 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); | 384 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
385 | return; | 385 | return; |
386 | } | 386 | } |
387 | 387 | ||
388 | Interface *i = interfaceItems[item]; | 388 | Interface *i = interfaceItems[item]; |
389 | if(i->getModuleOwner() == NULL){ | 389 | if(i->getModuleOwner() == NULL){ |
390 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); | 390 | QMessageBox::information(this, "Can't remove interface.", "Interface is built in.", QMessageBox::Ok); |
391 | } | 391 | } |
392 | else{ | 392 | else{ |
393 | if(!i->getModuleOwner()->remove(i)) | 393 | if(!i->getModuleOwner()->remove(i)) |
394 | QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok); | 394 | QMessageBox::information(this, tr("Error"), tr("Unable to remove."), QMessageBox::Ok); |
395 | else{ | 395 | else{ |
396 | delete item; | 396 | delete item; |
397 | // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); | 397 | // QMessageBox::information(this, "Success", "Interface was removed.", QMessageBox::Ok); |
398 | } | 398 | } |
399 | } | 399 | } |
400 | } | 400 | } |
401 | 401 | ||
402 | /** | 402 | /** |
403 | * Pull up the configure about the currently selected interface. | 403 | * Pull up the configure about the currently selected interface. |
404 | * Report an error if no interface is selected. | 404 | * Report an error if no interface is selected. |
405 | * If the interface has a module owner then request its configure. | 405 | * If the interface has a module owner then request its configure. |
406 | */ | 406 | */ |
407 | void MainWindowImp::configureClicked(){ | 407 | void MainWindowImp::configureClicked(){ |
408 | QListViewItem *item = connectionList->currentItem(); | 408 | QListViewItem *item = connectionList->currentItem(); |
409 | if(!item){ | 409 | if(!item){ |
410 | QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok); | 410 | QMessageBox::information(this, tr("Sorry"),tr("Please select an interface first."), QMessageBox::Ok); |
411 | return; | 411 | return; |
412 | } | 412 | } |
413 | 413 | ||
414 | QString currentProfileText = currentProfileLabel->text(); | 414 | QString currentProfileText = currentProfileLabel->text(); |
415 | if(currentProfileText.upper() == "ALL"); | 415 | if(currentProfileText.upper() == "ALL"); |
416 | currentProfileText = ""; | 416 | currentProfileText = ""; |
417 | 417 | ||
418 | Interface *i = interfaceItems[item]; | 418 | Interface *i = interfaceItems[item]; |
419 | 419 | ||
420 | if(i->getModuleOwner()){ | 420 | if(i->getModuleOwner()){ |
421 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i); | 421 | QWidget *moduleConfigure = i->getModuleOwner()->configure(i); |
422 | if(moduleConfigure != NULL){ | 422 | if(moduleConfigure != NULL){ |
423 | i->getModuleOwner()->setProfile(currentProfileText); | 423 | i->getModuleOwner()->setProfile(currentProfileText); |
424 | moduleConfigure->showMaximized(); | 424 | moduleConfigure->showMaximized(); |
425 | return; | 425 | return; |
426 | } | 426 | } |
427 | } | 427 | } |
428 | 428 | ||
429 | InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose ); | 429 | InterfaceSetupImpDialog *configure = new InterfaceSetupImpDialog(this, "InterfaceSetupImp", i, true, Qt::WDestructiveClose ); |
430 | configure->setProfile(currentProfileText); | 430 | configure->setProfile(currentProfileText); |
431 | configure->showMaximized(); | 431 | configure->showMaximized(); |
432 | } | 432 | } |
433 | 433 | ||
434 | /** | 434 | /** |
435 | * Pull up the information about the currently selected interface. | 435 | * Pull up the information about the currently selected interface. |
436 | * Report an error if no interface is selected. | 436 | * Report an error if no interface is selected. |
437 | * If the interface has a module owner then request its configure. | 437 | * If the interface has a module owner then request its configure. |
438 | */ | 438 | */ |
439 | void MainWindowImp::informationClicked(){ | 439 | void MainWindowImp::informationClicked(){ |
440 | QListViewItem *item = connectionList->currentItem(); | 440 | QListViewItem *item = connectionList->currentItem(); |
441 | if(!item){ | 441 | if(!item){ |
442 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); | 442 | QMessageBox::information(this, "Sorry","Please select an interface First.", QMessageBox::Ok); |
443 | return; | 443 | return; |
444 | } | 444 | } |
445 | 445 | ||
446 | Interface *i = interfaceItems[item]; | 446 | Interface *i = interfaceItems[item]; |
447 | // if(!i->isAttached()){ | 447 | // if(!i->isAttached()){ |
448 | // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); | 448 | // QMessageBox::information(this, "Sorry","No information about\na disconnected interface.", QMessageBox::Ok); |
449 | // return; | 449 | // return; |
450 | // } | 450 | // } |
451 | 451 | ||
452 | if(i->getModuleOwner()){ | 452 | if(i->getModuleOwner()){ |
453 | QWidget *moduleInformation = i->getModuleOwner()->information(i); | 453 | QWidget *moduleInformation = i->getModuleOwner()->information(i); |
454 | if(moduleInformation != NULL){ | 454 | if(moduleInformation != NULL){ |
455 | moduleInformation->showMaximized(); | 455 | moduleInformation->showMaximized(); |
456 | #ifdef DEBUG | 456 | #ifdef DEBUG |
457 | qDebug("MainWindowImp::informationClicked:: Module owner has created, we showed."); | 457 | qDebug("MainWindowImp::informationClicked:: Module owner has created, we showed."); |
458 | #endif | 458 | #endif |
459 | return; | 459 | return; |
460 | } | 460 | } |
461 | } | 461 | } |
462 | InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog); | 462 | InterfaceInformationImp *information = new InterfaceInformationImp(this, "InterfaceSetupImp", i, Qt::WType_Modal | Qt::WDestructiveClose | Qt::WStyle_Dialog); |
463 | information->showMaximized(); | 463 | information->showMaximized(); |
464 | } | 464 | } |
465 | 465 | ||
466 | /** | 466 | /** |
467 | * Update this interface. If no QListViewItem exists create one. | 467 | * Update this interface. If no QListViewItem exists create one. |
468 | * @param Interface* pointer to the interface that needs to be updated. | 468 | * @param Interface* pointer to the interface that needs to be updated. |
469 | */ | 469 | */ |
470 | void MainWindowImp::updateInterface(Interface *i){ | 470 | void MainWindowImp::updateInterface(Interface *i){ |
471 | if(!advancedUserMode){ | 471 | if(!advancedUserMode){ |
472 | if(i->getInterfaceName() == "lo") | 472 | if(i->getInterfaceName() == "lo") |
473 | return; | 473 | return; |
474 | } | 474 | } |
475 | 475 | ||
476 | QListViewItem *item = NULL; | 476 | QListViewItem *item = NULL; |
477 | 477 | ||
478 | // Find the interface, making it if needed. | 478 | // Find the interface, making it if needed. |
479 | if(items.find(i) == items.end()){ | 479 | if(items.find(i) == items.end()){ |
480 | item = new QListViewItem(connectionList, "", "", ""); | 480 | item = new QListViewItem(connectionList, "", "", ""); |
481 | // See if you can't find a module owner for this interface | 481 | // See if you can't find a module owner for this interface |
482 | QMap<Module*, QLibrary*>::Iterator it; | 482 | QMap<Module*, QLibrary*>::Iterator it; |
483 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 483 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
484 | if(it.key()->isOwner(i)) | 484 | if(it.key()->isOwner(i)) |
485 | i->setModuleOwner(it.key()); | 485 | i->setModuleOwner(it.key()); |
486 | } | 486 | } |
487 | items.insert(i, item); | 487 | items.insert(i, item); |
488 | interfaceItems.insert(item, i); | 488 | interfaceItems.insert(item, i); |
489 | } | 489 | } |
490 | else | 490 | else |
491 | item = items[i]; | 491 | item = items[i]; |
492 | 492 | ||
493 | // Update the icons and information | 493 | // Update the icons and information |
494 | #ifdef QWS | 494 | #ifdef QWS |
495 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); | 495 | item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down"))); |
496 | #else | 496 | #else |
497 | item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); | 497 | item->setPixmap(0, (SmallIcon(i->getStatus() ? "up": "down"))); |
498 | #endif | 498 | #endif |
499 | 499 | ||
500 | QString typeName = "lan"; | 500 | QString typeName = "lan"; |
501 | if(i->getInterfaceName() == "lo") | 501 | if(i->getInterfaceName() == "lo") |
502 | typeName = "lo"; | 502 | typeName = "lo"; |
503 | if(i->getInterfaceName().contains("irda")) | 503 | if(i->getInterfaceName().contains("irda")) |
504 | typeName = "irda"; | 504 | typeName = "irda"; |
505 | if(i->getInterfaceName().contains("wlan")) | 505 | if(i->getInterfaceName().contains("wlan")) |
506 | typeName = "wlan"; | 506 | typeName = "wlan"; |
507 | if(i->getInterfaceName().contains("usb")) | 507 | if(i->getInterfaceName().contains("usb")) |
508 | typeName = "usb"; | 508 | typeName = "usb"; |
509 | 509 | ||
510 | if(!i->isAttached()) | 510 | if(!i->isAttached()) |
511 | typeName = "connect_no"; | 511 | typeName = "connect_no"; |
512 | // Actually try to use the Module | 512 | // Actually try to use the Module |
513 | if(i->getModuleOwner() != NULL) | 513 | if(i->getModuleOwner() != NULL) |
514 | typeName = i->getModuleOwner()->getPixmapName(i); | 514 | typeName = i->getModuleOwner()->getPixmapName(i); |
515 | 515 | ||
516 | #ifdef QWS | 516 | #ifdef QWS |
517 | item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); | 517 | item->setPixmap(1, (Resource::loadPixmap(QString("networksettings/") + typeName))); |
518 | #else | 518 | #else |
519 | item->setPixmap(1, (SmallIcon(typeName))); | 519 | item->setPixmap(1, (SmallIcon(typeName))); |
520 | #endif | 520 | #endif |
521 | item->setText(2, i->getHardwareName()); | 521 | item->setText(2, i->getHardwareName()); |
522 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); | 522 | item->setText(3, QString("(%1)").arg(i->getInterfaceName())); |
523 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); | 523 | item->setText(4, (i->getStatus()) ? i->getIp() : QString("")); |
524 | } | 524 | } |
525 | 525 | ||
526 | void MainWindowImp::newProfileChanged(const QString& newText){ | 526 | void MainWindowImp::newProfileChanged(const QString& newText){ |
527 | if(newText.length() > 0) | 527 | if(newText.length() > 0) |
528 | newProfileButton->setEnabled(true); | 528 | newProfileButton->setEnabled(true); |
529 | else | 529 | else |
530 | newProfileButton->setEnabled(false); | 530 | newProfileButton->setEnabled(false); |
531 | } | 531 | } |
532 | 532 | ||
533 | /** | 533 | /** |
534 | * Adds a new profile to the list of profiles. | 534 | * Adds a new profile to the list of profiles. |
535 | * Don't add profiles that already exists. | 535 | * Don't add profiles that already exists. |
536 | * Appends to the list and QStringList | 536 | * Appends to the list and QStringList |
537 | */ | 537 | */ |
538 | void MainWindowImp::addProfile(){ | 538 | void MainWindowImp::addProfile(){ |
539 | QString newProfileName = newProfile->text(); | 539 | QString newProfileName = newProfile->text(); |
540 | if(profiles.grep(newProfileName).count() > 0){ | 540 | if(profiles.grep(newProfileName).count() > 0){ |
541 | QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); | 541 | QMessageBox::information(this, "Can't Add","Profile already exists.", QMessageBox::Ok); |
542 | return; | 542 | return; |
543 | } | 543 | } |
544 | profiles.append(newProfileName); | 544 | profiles.append(newProfileName); |
545 | profilesList->insertItem(newProfileName); | 545 | profilesList->insertItem(newProfileName); |
546 | } | 546 | } |
547 | 547 | ||
548 | /** | 548 | /** |
549 | * Removes the currently selected profile in the combo. | 549 | * Removes the currently selected profile in the combo. |
550 | * Doesn't delete if there are less then 2 profiles. | 550 | * Doesn't delete if there are less then 2 profiles. |
551 | */ | 551 | */ |
552 | void MainWindowImp::removeProfile(){ | 552 | void MainWindowImp::removeProfile(){ |
553 | if(profilesList->count() <= 1){ | 553 | if(profilesList->count() <= 1){ |
554 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); | 554 | QMessageBox::information(this, "Can't remove.","At least one profile\nis needed.", QMessageBox::Ok); |
555 | return; | 555 | return; |
556 | } | 556 | } |
557 | QString profileToRemove = profilesList->currentText(); | 557 | QString profileToRemove = profilesList->currentText(); |
558 | if(profileToRemove == "All"){ | 558 | if(profileToRemove == "All"){ |
559 | QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); | 559 | QMessageBox::information(this, "Can't remove.","Can't remove default.", QMessageBox::Ok); |
560 | return; | 560 | return; |
561 | } | 561 | } |
562 | // Can't remove the curent profile | 562 | // Can't remove the curent profile |
563 | if(profileToRemove == currentProfileLabel->text()){ | 563 | if(profileToRemove == currentProfileLabel->text()){ |
564 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); | 564 | QMessageBox::information(this, "Can't remove.",QString("%1 is the current profile.").arg(profileToRemove), QMessageBox::Ok); |
565 | return; | 565 | return; |
566 | 566 | ||
567 | } | 567 | } |
568 | 568 | ||
569 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ | 569 | if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){ |
570 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); | 570 | profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), "")); |
571 | profilesList->clear(); | 571 | profilesList->clear(); |
572 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) | 572 | for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it) |
573 | profilesList->insertItem((*it)); | 573 | profilesList->insertItem((*it)); |
574 | 574 | ||
575 | // Remove any interface settings and mappings. | 575 | // Remove any interface settings and mappings. |
576 | Interfaces interfaces; | 576 | Interfaces interfaces; |
577 | // Go through them one by one | 577 | // Go through them one by one |
578 | QMap<Interface*, QListViewItem*>::Iterator it; | 578 | QMap<Interface*, QListViewItem*>::Iterator it; |
579 | for( it = items.begin(); it != items.end(); ++it ){ | 579 | for( it = items.begin(); it != items.end(); ++it ){ |
580 | QString interfaceName = it.key()->getInterfaceName(); | 580 | QString interfaceName = it.key()->getInterfaceName(); |
581 | qDebug(interfaceName.latin1()); | 581 | qDebug(interfaceName.latin1()); |
582 | if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ | 582 | if(interfaces.setInterface(interfaceName + "_" + profileToRemove)){ |
583 | interfaces.removeInterface(); | 583 | interfaces.removeInterface(); |
584 | if(interfaces.setMapping(interfaceName)){ | 584 | if(interfaces.setMapping(interfaceName)){ |
585 | if(profilesList->count() == 1) | 585 | if(profilesList->count() == 1) |
586 | interfaces.removeMapping(); | 586 | interfaces.removeMapping(); |
587 | else{ | 587 | else{ |
588 | interfaces.removeMap("map", interfaceName + "_" + profileToRemove); | 588 | interfaces.removeMap("map", interfaceName + "_" + profileToRemove); |
589 | } | 589 | } |
590 | } | 590 | } |
591 | interfaces.write(); | 591 | interfaces.write(); |
592 | break; | 592 | break; |
593 | } | 593 | } |
594 | } | 594 | } |
595 | } | 595 | } |
596 | } | 596 | } |
597 | 597 | ||
598 | /** | 598 | /** |
599 | * A new profile has been selected, change. | 599 | * A new profile has been selected, change. |
600 | * @param newProfile the new profile. | 600 | * @param newProfile the new profile. |
601 | */ | 601 | */ |
602 | void MainWindowImp::changeProfile(){ | 602 | void MainWindowImp::changeProfile(){ |
603 | if(profilesList->currentItem() == -1){ | 603 | if(profilesList->currentItem() == -1){ |
604 | QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); | 604 | QMessageBox::information(this, "Can't Change.","Please select a profile.", QMessageBox::Ok); |
605 | return; | 605 | return; |
606 | } | 606 | } |
607 | QString newProfile = profilesList->text(profilesList->currentItem()); | 607 | QString newProfile = profilesList->text(profilesList->currentItem()); |
608 | if(newProfile != currentProfileLabel->text()){ | 608 | if(newProfile != currentProfileLabel->text()){ |
609 | currentProfileLabel->setText(newProfile); | 609 | currentProfileLabel->setText(newProfile); |
610 | QFile::remove(scheme); | 610 | QFile::remove(scheme); |
611 | QFile file(scheme); | 611 | QFile file(scheme); |
612 | if ( file.open(IO_ReadWrite) ) { | 612 | if ( file.open(IO_ReadWrite) ) { |
613 | QTextStream stream( &file ); | 613 | QTextStream stream( &file ); |
614 | stream << QString("SCHEME=%1").arg(newProfile); | 614 | stream << QString("SCHEME=%1").arg(newProfile); |
615 | file.close(); | 615 | file.close(); |
616 | } | 616 | } |
617 | // restart all up devices? | 617 | // restart all up devices? |
618 | if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ | 618 | if(QMessageBox::information(this, "Question","Restart all running interfaces?", QMessageBox::Ok, QMessageBox::No) == QMessageBox::Ok){ |
619 | // Go through them one by one | 619 | // Go through them one by one |
620 | QMap<Interface*, QListViewItem*>::Iterator it; | 620 | QMap<Interface*, QListViewItem*>::Iterator it; |
621 | for( it = items.begin(); it != items.end(); ++it ){ | 621 | for( it = items.begin(); it != items.end(); ++it ){ |
622 | if(it.key()->getStatus() == true) | 622 | if(it.key()->getStatus() == true) |
623 | it.key()->restart(); | 623 | it.key()->restart(); |
624 | } | 624 | } |
625 | } | 625 | } |
626 | } | 626 | } |
627 | // TODO change the profile in the modules | 627 | // TODO change the profile in the modules |
628 | } | 628 | } |
629 | 629 | ||
630 | 630 | ||
631 | void MainWindowImp::makeChannel() | 631 | void MainWindowImp::makeChannel() |
632 | { | 632 | { |
633 | channel = new QCopChannel( "QPE/Application/networksettings", this ); | 633 | channel = new QCopChannel( "QPE/Application/networksettings", this ); |
634 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 634 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
635 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 635 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
636 | } | 636 | } |
637 | 637 | ||
638 | void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) | 638 | void MainWindowImp::receive(const QCString &msg, const QByteArray &arg) |
639 | { | 639 | { |
640 | bool found = false; | 640 | bool found = false; |
641 | qDebug("MainWindowImp::receive QCop msg >"+msg+"<"); | 641 | qDebug("MainWindowImp::receive QCop msg >"+msg+"<"); |
642 | 642 | ||
643 | if (msg == "raise") { | ||
644 | raise(); | ||
645 | return; | ||
646 | } | ||
647 | |||
643 | QString dest = msg.left(msg.find("(")); | 648 | QString dest = msg.left(msg.find("(")); |
644 | QCString param = msg.right(msg.length() - msg.find("(") - 1); | 649 | QCString param = msg.right(msg.length() - msg.find("(") - 1); |
645 | param = param.left( param.length() - 1 ); | 650 | param = param.left( param.length() - 1 ); |
646 | qDebug("dest >%s< param >"+param+"<",dest.latin1()); | 651 | qDebug("dest >%s< param >"+param+"<",dest.latin1()); |
647 | 652 | ||
648 | QMap<Module*, QLibrary*>::Iterator it; | 653 | QMap<Module*, QLibrary*>::Iterator it; |
649 | for( it = libraries.begin(); it != libraries.end(); ++it ){ | 654 | for( it = libraries.begin(); it != libraries.end(); ++it ){ |
650 | qDebug("plugin >%s<", it.key()->type().latin1() ); | 655 | qDebug("plugin >%s<", it.key()->type().latin1() ); |
651 | if(it.key()->type() == dest){ | 656 | if(it.key()->type() == dest){ |
652 | it.key()->receive( param, arg ); | 657 | it.key()->receive( param, arg ); |
653 | found = true; | 658 | found = true; |
654 | } | 659 | } |
655 | } | 660 | } |
656 | 661 | ||
657 | 662 | ||
658 | if (found) QPEApplication::setKeepRunning(); | 663 | if (found) QPEApplication::setKeepRunning(); |
659 | else qDebug("Huh what do ya want"); | 664 | else qDebug("Huh what do ya want"); |
660 | } | 665 | } |
diff --git a/noncore/settings/networksettings/wlan/wlanmodule.cpp b/noncore/settings/networksettings/wlan/wlanmodule.cpp index 371b689..7bded85 100644 --- a/noncore/settings/networksettings/wlan/wlanmodule.cpp +++ b/noncore/settings/networksettings/wlan/wlanmodule.cpp | |||
@@ -1,215 +1,222 @@ | |||
1 | #include "wlanmodule.h" | 1 | #include "wlanmodule.h" |
2 | #include "wlanimp.h" | 2 | #include "wlanimp.h" |
3 | #include "infoimp.h" | 3 | #include "infoimp.h" |
4 | #include "wextensions.h" | 4 | #include "wextensions.h" |
5 | #include "interfaceinformationimp.h" | 5 | #include "interfaceinformationimp.h" |
6 | 6 | ||
7 | #include <qcheckbox.h> | 7 | #include <qcheckbox.h> |
8 | #include <qcombobox.h> | 8 | #include <qcombobox.h> |
9 | #include <qlabel.h> | 9 | #include <qlabel.h> |
10 | #include <qlineedit.h> | 10 | #include <qlineedit.h> |
11 | #include <qprogressbar.h> | 11 | #include <qprogressbar.h> |
12 | #include <qspinbox.h> | 12 | #include <qspinbox.h> |
13 | #include <qtabwidget.h> | 13 | #include <qtabwidget.h> |
14 | 14 | ||
15 | 15 | ||
16 | 16 | ||
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Constructor, find all of the possible interfaces | 19 | * Constructor, find all of the possible interfaces |
20 | */ | 20 | */ |
21 | WLANModule::WLANModule() | 21 | WLANModule::WLANModule() |
22 | : Module(), | 22 | : Module(), |
23 | wlanconfigWiget(0) | 23 | wlanconfigWiget(0) |
24 | { | 24 | { |
25 | } | 25 | } |
26 | 26 | ||
27 | /** | 27 | /** |
28 | * Delete any interfaces that we own. | 28 | * Delete any interfaces that we own. |
29 | */ | 29 | */ |
30 | WLANModule::~WLANModule(){ | 30 | WLANModule::~WLANModule(){ |
31 | Interface *i; | 31 | Interface *i; |
32 | for ( i=list.first(); i != 0; i=list.next() ) | 32 | for ( i=list.first(); i != 0; i=list.next() ) |
33 | delete i; | 33 | delete i; |
34 | 34 | ||
35 | } | 35 | } |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Change the current profile | 38 | * Change the current profile |
39 | */ | 39 | */ |
40 | void WLANModule::setProfile(const QString &newProfile){ | 40 | void WLANModule::setProfile(const QString &newProfile){ |
41 | profile = newProfile; | 41 | profile = newProfile; |
42 | } | 42 | } |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * get the icon name for this device. | 45 | * get the icon name for this device. |
46 | * @param Interface* can be used in determining the icon. | 46 | * @param Interface* can be used in determining the icon. |
47 | * @return QString the icon name (minus .png, .gif etc) | 47 | * @return QString the icon name (minus .png, .gif etc) |
48 | */ | 48 | */ |
49 | QString WLANModule::getPixmapName(Interface* ){ | 49 | QString WLANModule::getPixmapName(Interface* ){ |
50 | return "wlan"; | 50 | return "wlan"; |
51 | } | 51 | } |
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Check to see if the interface i is owned by this module. | 54 | * Check to see if the interface i is owned by this module. |
55 | * @param Interface* interface to check against | 55 | * @param Interface* interface to check against |
56 | * @return bool true if i is owned by this module, false otherwise. | 56 | * @return bool true if i is owned by this module, false otherwise. |
57 | */ | 57 | */ |
58 | bool WLANModule::isOwner(Interface *i){ | 58 | bool WLANModule::isOwner(Interface *i){ |
59 | WExtensions we(i->getInterfaceName()); | 59 | WExtensions we(i->getInterfaceName()); |
60 | if(!we.doesHaveWirelessExtensions()) | 60 | if(!we.doesHaveWirelessExtensions()) |
61 | return false; | 61 | return false; |
62 | 62 | ||
63 | i->setHardwareName("802.11b"); | 63 | i->setHardwareName("802.11b"); |
64 | list.append(i); | 64 | list.append(i); |
65 | return true; | 65 | return true; |
66 | } | 66 | } |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Create, and return the WLANConfigure Module | 69 | * Create, and return the WLANConfigure Module |
70 | * @return QWidget* pointer to this modules configure. | 70 | * @return QWidget* pointer to this modules configure. |
71 | */ | 71 | */ |
72 | QWidget *WLANModule::configure(Interface *i){ | 72 | QWidget *WLANModule::configure(Interface *i){ |
73 | WLANImp *wlanconfig = new WLANImp(0, "WlanConfig", i, false, Qt::WDestructiveClose); | 73 | WLANImp *wlanconfig = new WLANImp(0, "WlanConfig", i, true, Qt::WDestructiveClose); |
74 | wlanconfig->setProfile(profile); | 74 | wlanconfig->setProfile(profile); |
75 | return wlanconfig; | 75 | return wlanconfig; |
76 | } | 76 | } |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * Create, and return the Information Module | 79 | * Create, and return the Information Module |
80 | * @return QWidget* pointer to this modules info. | 80 | * @return QWidget* pointer to this modules info. |
81 | */ | 81 | */ |
82 | QWidget *WLANModule::information(Interface *i){ | 82 | QWidget *WLANModule::information(Interface *i){ |
83 | WExtensions we(i->getInterfaceName()); | 83 | WExtensions we(i->getInterfaceName()); |
84 | if(!we.doesHaveWirelessExtensions()) | 84 | if(!we.doesHaveWirelessExtensions()) |
85 | return NULL; | 85 | return NULL; |
86 | 86 | ||
87 | return getInfo( i ); | 87 | return getInfo( i ); |
88 | } | 88 | } |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * Get all active (up or down) interfaces | 91 | * Get all active (up or down) interfaces |
92 | * @return QList<Interface> A list of interfaces that exsist that havn't | 92 | * @return QList<Interface> A list of interfaces that exsist that havn't |
93 | * been called by isOwner() | 93 | * been called by isOwner() |
94 | */ | 94 | */ |
95 | QList<Interface> WLANModule::getInterfaces(){ | 95 | QList<Interface> WLANModule::getInterfaces(){ |
96 | return list; | 96 | return list; |
97 | } | 97 | } |
98 | 98 | ||
99 | /** | 99 | /** |
100 | * Attempt to add a new interface as defined by name | 100 | * Attempt to add a new interface as defined by name |
101 | * @param name the name of the type of interface that should be created given | 101 | * @param name the name of the type of interface that should be created given |
102 | * by possibleNewInterfaces(); | 102 | * by possibleNewInterfaces(); |
103 | * @return Interface* NULL if it was unable to be created. | 103 | * @return Interface* NULL if it was unable to be created. |
104 | */ | 104 | */ |
105 | Interface *WLANModule::addNewInterface(const QString &){ | 105 | Interface *WLANModule::addNewInterface(const QString &){ |
106 | // We can't add a 802.11 interface, either the hardware will be there | 106 | // We can't add a 802.11 interface, either the hardware will be there |
107 | // or it wont. | 107 | // or it wont. |
108 | return NULL; | 108 | return NULL; |
109 | } | 109 | } |
110 | 110 | ||
111 | /** | 111 | /** |
112 | * Attempts to remove the interface, doesn't delete i | 112 | * Attempts to remove the interface, doesn't delete i |
113 | * @return bool true if successfull, false otherwise. | 113 | * @return bool true if successfull, false otherwise. |
114 | */ | 114 | */ |
115 | bool WLANModule::remove(Interface*){ | 115 | bool WLANModule::remove(Interface*){ |
116 | // Can't remove a hardware device, you can stop it though. | 116 | // Can't remove a hardware device, you can stop it though. |
117 | return false; | 117 | return false; |
118 | } | 118 | } |
119 | 119 | ||
120 | void WLANModule::receive(const QCString ¶m, const QByteArray &arg) | 120 | void WLANModule::receive(const QCString ¶m, const QByteArray &arg) |
121 | { | 121 | { |
122 | qDebug("WLANModule::receive "+param); | 122 | qDebug("WLANModule::receive "+param); |
123 | QStringList params = QStringList::split(",",param); | 123 | QStringList params = QStringList::split(",",param); |
124 | int count = params.count(); | 124 | int count = params.count(); |
125 | qDebug("WLANModule got %i params", count ); | 125 | qDebug("WLANModule got %i params", count ); |
126 | if (count < 2){ | 126 | if (count < 2){ |
127 | qDebug("Erorr less than 2 parameter"); | 127 | qDebug("Erorr less than 2 parameter"); |
128 | qDebug("RETURNING"); | 128 | qDebug("RETURNING"); |
129 | return; | 129 | return; |
130 | } | 130 | } |
131 | 131 | ||
132 | QDataStream stream(arg,IO_ReadOnly); | 132 | QDataStream stream(arg,IO_ReadOnly); |
133 | QString interface; | 133 | QString interface; |
134 | QString action; | 134 | QString action; |
135 | QDialog *toShow; | ||
135 | while (! stream.atEnd() ){ | 136 | while (! stream.atEnd() ){ |
136 | stream >> interface; | 137 | stream >> interface; |
137 | stream >> action; | 138 | stream >> action; |
138 | qDebug("WLANModule got interface %s and acion %s", interface.latin1(), action.latin1()); | 139 | qDebug("WLANModule got interface %s and acion %s", interface.latin1(), action.latin1()); |
139 | // find interfaces | 140 | // find interfaces |
140 | Interface *ifa=0; | 141 | Interface *ifa=0; |
141 | for ( Interface *i=list.first(); i != 0; i=list.next() ){ | 142 | for ( Interface *i=list.first(); i != 0; i=list.next() ){ |
142 | if (i->getInterfaceName() == interface){ | 143 | if (i->getInterfaceName() == interface){ |
143 | qDebug("WLANModule found interface %s",interface.latin1()); | 144 | qDebug("WLANModule found interface %s",interface.latin1()); |
144 | ifa = i; | 145 | ifa = i; |
145 | } | 146 | } |
146 | } | 147 | } |
147 | 148 | ||
148 | if (ifa == 0){ | 149 | if (ifa == 0){ |
149 | qDebug("WLANModule Did not find %s",interface.latin1()); | 150 | qDebug("WLANModule Did not find %s",interface.latin1()); |
150 | qDebug("returning"); | 151 | qDebug("skipping"); |
151 | return; | 152 | count = 0; |
152 | } | 153 | } |
153 | 154 | ||
154 | if (count == 2){ | 155 | if (count == 2){ |
155 | // those should call the interface directly | 156 | // those should call the interface directly |
156 | QWidget *info = getInfo( ifa ); | 157 | QWidget *info = getInfo( ifa ); |
157 | info->showMaximized(); | 158 | info->showMaximized(); |
158 | 159 | ||
159 | if ( action.contains("start" ) ){ | 160 | if ( action.contains("start" ) ){ |
160 | ifa->start(); | 161 | ifa->start(); |
161 | } else if ( action.contains("restart" ) ){ | 162 | } else if ( action.contains("restart" ) ){ |
162 | ifa->restart(); | 163 | ifa->restart(); |
163 | } else if ( action.contains("stop" ) ){ | 164 | } else if ( action.contains("stop" ) ){ |
164 | ifa->stop(); | 165 | ifa->stop(); |
165 | }else if ( action.contains("refresh" ) ){ | 166 | }else if ( action.contains("refresh" ) ){ |
166 | ifa->refresh(); | 167 | ifa->refresh(); |
167 | } | 168 | } |
168 | }else if (count == 3){ | 169 | }else if (count == 3){ |
169 | QString value; | 170 | QString value; |
170 | if (!wlanconfigWiget){ | 171 | if (!wlanconfigWiget){ |
171 | //FIXME: what if it got closed meanwhile? | 172 | //FIXME: what if it got closed meanwhile? |
172 | wlanconfigWiget = (WLANImp*) configure(ifa); | 173 | wlanconfigWiget = (WLANImp*) configure(ifa); |
174 | toShow = (QDialog*) wlanconfigWiget; | ||
173 | } | 175 | } |
174 | wlanconfigWiget->showMaximized(); | 176 | wlanconfigWiget->showMaximized(); |
175 | stream >> value; | 177 | stream >> value; |
176 | qDebug("WLANModule is setting %s of %s to %s", action.latin1(), interface.latin1(), value.latin1() ); | 178 | qDebug("WLANModule is setting %s of %s to %s", action.latin1(), interface.latin1(), value.latin1() ); |
177 | if ( action.contains("ESSID") ){ | 179 | if ( action.contains("ESSID") ){ |
178 | QComboBox *combo = wlanconfigWiget->essid; | 180 | QComboBox *combo = wlanconfigWiget->essid; |
179 | bool found = false; | 181 | bool found = false; |
180 | for ( int i = 0; i < combo->count(); i++) | 182 | for ( int i = 0; i < combo->count(); i++) |
181 | if ( combo->text( i ) == value ){ | 183 | if ( combo->text( i ) == value ){ |
182 | combo->setCurrentItem( i ); | 184 | combo->setCurrentItem( i ); |
183 | found = true; | 185 | found = true; |
184 | } | 186 | } |
185 | if (!found) combo->insertItem( value, 0 ); | 187 | if (!found) combo->insertItem( value, 0 ); |
186 | }else if ( action.contains("Mode") ){ | 188 | }else if ( action.contains("Mode") ){ |
187 | QComboBox *combo = wlanconfigWiget->mode; | 189 | QComboBox *combo = wlanconfigWiget->mode; |
188 | for ( int i = 0; i < combo->count(); i++) | 190 | for ( int i = 0; i < combo->count(); i++) |
189 | if ( combo->text( i ) == value ){ | 191 | if ( combo->text( i ) == value ){ |
190 | combo->setCurrentItem( i ); | 192 | combo->setCurrentItem( i ); |
191 | } | 193 | } |
192 | 194 | ||
193 | }else if (action.contains("Channel")){ | 195 | }else if (action.contains("Channel")){ |
194 | wlanconfigWiget->specifyChan->setChecked( true ); | 196 | bool ok; |
195 | wlanconfigWiget->networkChannel->setValue( value.toInt() ); | 197 | int chan = value.toInt( &ok ); |
198 | if (ok){ | ||
199 | wlanconfigWiget->specifyChan->setChecked( true ); | ||
200 | wlanconfigWiget->networkChannel->setValue( chan ); | ||
201 | } | ||
196 | }else if (action.contains("MacAddr")){ | 202 | }else if (action.contains("MacAddr")){ |
197 | wlanconfigWiget->specifyAp->setChecked( true ); | 203 | wlanconfigWiget->specifyAp->setChecked( true ); |
198 | wlanconfigWiget->macEdit->setText( value ); | 204 | wlanconfigWiget->macEdit->setText( value ); |
199 | }else | 205 | }else |
200 | qDebug("wlan plugin has no clue"); | 206 | qDebug("wlan plugin has no clue"); |
201 | } | 207 | } |
202 | }// while stream | 208 | }// while stream |
209 | if (toShow) toShow->exec(); | ||
203 | } | 210 | } |
204 | 211 | ||
205 | QWidget *WLANModule::getInfo( Interface *i) | 212 | QWidget *WLANModule::getInfo( Interface *i) |
206 | { | 213 | { |
207 | qDebug("WLANModule::getInfo start"); | 214 | qDebug("WLANModule::getInfo start"); |
208 | WlanInfoImp *info = new WlanInfoImp(0, i->getInterfaceName(), Qt::WDestructiveClose); | 215 | WlanInfoImp *info = new WlanInfoImp(0, i->getInterfaceName(), Qt::WDestructiveClose); |
209 | InterfaceInformationImp *information = new InterfaceInformationImp(info->tabWidget, "InterfaceSetupImp", i); | 216 | InterfaceInformationImp *information = new InterfaceInformationImp(info->tabWidget, "InterfaceSetupImp", i); |
210 | info->tabWidget->insertTab(information, "TCP/IP", 0); | 217 | info->tabWidget->insertTab(information, "TCP/IP", 0); |
211 | 218 | ||
212 | qDebug("WLANModule::getInfo return"); | 219 | qDebug("WLANModule::getInfo return"); |
213 | return info; | 220 | return info; |
214 | } | 221 | } |
215 | 222 | ||