Diffstat (limited to 'noncore/settings/networksettings/interfaces/interfacesetupimp.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/interfaces/interfacesetupimp.cpp | 103 |
1 files changed, 48 insertions, 55 deletions
diff --git a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp index 3b1a4de..4818e37 100644 --- a/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp +++ b/noncore/settings/networksettings/interfaces/interfacesetupimp.cpp | |||
@@ -1,9 +1,6 @@ | |||
1 | #include "interfacesetupimp.h" | 1 | #include "interfacesetupimp.h" |
2 | #include "interface.h" | 2 | #include "interface.h" |
3 | #include "interfaces.h" | ||
4 | 3 | ||
5 | #include <qdialog.h> | ||
6 | #include <qcombobox.h> | ||
7 | #include <qcheckbox.h> | 4 | #include <qcheckbox.h> |
8 | #include <qlineedit.h> | 5 | #include <qlineedit.h> |
9 | #include <qspinbox.h> | 6 | #include <qspinbox.h> |
@@ -12,25 +9,12 @@ | |||
12 | 9 | ||
13 | #include <qmessagebox.h> | 10 | #include <qmessagebox.h> |
14 | 11 | ||
15 | #include <assert.h> | ||
16 | |||
17 | #define DNSSCRIPT "changedns" | 12 | #define DNSSCRIPT "changedns" |
18 | 13 | ||
19 | /** | 14 | /** |
20 | * Constuctor. Set up the connection and load the first profile. | 15 | * Constuctor. Set up the connection. A profile must be set. |
21 | */ | 16 | */ |
22 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl){ | 17 | InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interface *i, WFlags fl) : InterfaceSetup(parent, name, fl), interface(i){ |
23 | assert(parent); | ||
24 | assert(i); | ||
25 | interface = i; | ||
26 | interfaces = new Interfaces(); | ||
27 | bool error = false; | ||
28 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | ||
29 | staticGroupBox->hide(); | ||
30 | dhcpCheckBox->hide(); | ||
31 | leaseTime->hide(); | ||
32 | leaseHoursLabel->hide(); | ||
33 | } | ||
34 | } | 18 | } |
35 | 19 | ||
36 | /** | 20 | /** |
@@ -39,7 +23,7 @@ InterfaceSetupImp::InterfaceSetupImp(QWidget* parent, const char* name, Interfac | |||
39 | bool InterfaceSetupImp::saveChanges(){ | 23 | bool InterfaceSetupImp::saveChanges(){ |
40 | if(!saveSettings()) | 24 | if(!saveSettings()) |
41 | return false; | 25 | return false; |
42 | interfaces->write(); | 26 | interfaces.write(); |
43 | return true; | 27 | return true; |
44 | } | 28 | } |
45 | 29 | ||
@@ -49,13 +33,13 @@ bool InterfaceSetupImp::saveChanges(){ | |||
49 | */ | 33 | */ |
50 | bool InterfaceSetupImp::saveSettings(){ | 34 | bool InterfaceSetupImp::saveSettings(){ |
51 | // eh can't really do anything about it other then return. :-D | 35 | // eh can't really do anything about it other then return. :-D |
52 | if(!interfaces->isInterfaceSet()) | 36 | if(!interfaces.isInterfaceSet()) |
53 | return true; | 37 | return true; |
54 | 38 | ||
55 | bool error = false; | 39 | bool error = false; |
56 | // Loopback case | 40 | // Loopback case |
57 | if(interfaces->getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | 41 | if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){ |
58 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 42 | interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
59 | return true; | 43 | return true; |
60 | } | 44 | } |
61 | 45 | ||
@@ -63,59 +47,68 @@ bool InterfaceSetupImp::saveSettings(){ | |||
63 | QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok); | 47 | QMessageBox::information(this, "Not Saved.", "Please fill in the IP address and\n subnet entries.", QMessageBox::Ok); |
64 | return false; | 48 | return false; |
65 | } | 49 | } |
66 | interfaces->removeAllInterfaceOptions(); | 50 | interfaces.removeAllInterfaceOptions(); |
67 | 51 | ||
68 | // DHCP | 52 | // DHCP |
69 | if(dhcpCheckBox->isChecked()){ | 53 | if(dhcpCheckBox->isChecked()){ |
70 | interfaces->setInterfaceMethod(INTERFACES_METHOD_DHCP); | 54 | interfaces.setInterfaceMethod(INTERFACES_METHOD_DHCP); |
71 | interfaces->setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); | 55 | interfaces.setInterfaceOption("leasehours", QString("%1").arg(leaseTime->value())); |
72 | interfaces->setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); | 56 | interfaces.setInterfaceOption("leasetime", QString("%1").arg(leaseTime->value()*60*60)); |
73 | } | 57 | } |
74 | else{ | 58 | else{ |
75 | interfaces->setInterfaceMethod("static"); | 59 | interfaces.setInterfaceMethod("static"); |
76 | interfaces->setInterfaceOption("address", ipAddressEdit->text()); | 60 | interfaces.setInterfaceOption("address", ipAddressEdit->text()); |
77 | interfaces->setInterfaceOption("netmask", subnetMaskEdit->text()); | 61 | interfaces.setInterfaceOption("netmask", subnetMaskEdit->text()); |
78 | interfaces->setInterfaceOption("gateway", gatewayEdit->text()); | 62 | interfaces.setInterfaceOption("gateway", gatewayEdit->text()); |
79 | if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ | 63 | if(!firstDNSLineEdit->text().isEmpty() || !secondDNSLineEdit->text().isEmpty()){ |
80 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); | 64 | QString dns = firstDNSLineEdit->text() + " " + secondDNSLineEdit->text(); |
81 | interfaces->setInterfaceOption("up "DNSSCRIPT" -a ", dns); | 65 | interfaces.setInterfaceOption("up "DNSSCRIPT" -a ", dns); |
82 | interfaces->setInterfaceOption("down "DNSSCRIPT" -r ", dns); | 66 | interfaces.setInterfaceOption("down "DNSSCRIPT" -r ", dns); |
83 | } | 67 | } |
84 | } | 68 | } |
85 | 69 | ||
86 | // IP Information | 70 | // IP Information |
87 | interfaces->setAuto(interface->getInterfaceName(), autoStart->isChecked()); | 71 | interfaces.setAuto(interface->getInterfaceName(), autoStart->isChecked()); |
88 | return true; | 72 | return true; |
89 | } | 73 | } |
90 | 74 | ||
91 | /** | 75 | /** |
92 | * The Profile has changed. | 76 | * The Profile has changed. |
93 | * @profile the new profile. | 77 | * @param QString profile the new profile. |
94 | */ | 78 | */ |
95 | void InterfaceSetupImp::setProfile(const QString &profile){ | 79 | void InterfaceSetupImp::setProfile(const QString &profile){ |
80 | /* | ||
81 | bool error = false; | ||
82 | if(interfaces.getInterfaceMethod(error) == INTERFACES_LOOPBACK){ | ||
83 | staticGroupBox->hide(); | ||
84 | dhcpCheckBox->hide(); | ||
85 | leaseTime->hide(); | ||
86 | leaseHoursLabel->hide(); | ||
87 | } | ||
88 | */ | ||
89 | |||
96 | QString newInterfaceName = interface->getInterfaceName(); | 90 | QString newInterfaceName = interface->getInterfaceName(); |
97 | if(profile.length() > 0) | 91 | if(profile.length() > 0) |
98 | newInterfaceName += "_" + profile; | 92 | newInterfaceName += "_" + profile; |
99 | qDebug("InterfaceSetupImp::setProfile"); | ||
100 | // See if we have to make a interface. | 93 | // See if we have to make a interface. |
101 | if(!interfaces->setInterface(newInterfaceName)){ | 94 | if(!interfaces.setInterface(newInterfaceName)){ |
102 | // Add making for this new interface if need too | 95 | // Add making for this new interface if need too |
103 | if(profile != ""){ | 96 | if(profile != ""){ |
104 | interfaces->copyInterface(interface->getInterfaceName(), newInterfaceName); | 97 | interfaces.copyInterface(interface->getInterfaceName(), newInterfaceName); |
105 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 98 | if(!interfaces.setMapping(interface->getInterfaceName())){ |
106 | interfaces->addMapping(interface->getInterfaceName()); | 99 | interfaces.addMapping(interface->getInterfaceName()); |
107 | if(!interfaces->setMapping(interface->getInterfaceName())){ | 100 | if(!interfaces.setMapping(interface->getInterfaceName())){ |
108 | qDebug("InterfaceSetupImp: Added Mapping, but still can't set."); | 101 | qDebug("InterfaceSetupImp: Added Mapping, but still can't setInterface."); |
109 | return; | 102 | return; |
110 | } | 103 | } |
111 | } | 104 | } |
112 | interfaces->setMap("map", newInterfaceName); | 105 | interfaces.setMap("map", newInterfaceName); |
113 | interfaces->setScript("getprofile.sh"); | 106 | interfaces.setScript("getprofile.sh"); |
114 | } | 107 | } |
115 | else{ | 108 | else{ |
116 | interfaces->addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); | 109 | interfaces.addInterface(newInterfaceName, INTERFACES_FAMILY_INET, INTERFACES_METHOD_DHCP); |
117 | if(!interfaces->setInterface(newInterfaceName)){ | 110 | if(!interfaces.setInterface(newInterfaceName)){ |
118 | qDebug("InterfaceSetupImp: Added interface, but still can't set."); | 111 | qDebug("InterfaceSetupImp: Added interface, but still can't setInterface."); |
119 | return; | 112 | return; |
120 | } | 113 | } |
121 | } | 114 | } |
@@ -125,28 +118,28 @@ void InterfaceSetupImp::setProfile(const QString &profile){ | |||
125 | 118 | ||
126 | // DHCP | 119 | // DHCP |
127 | bool error = false; | 120 | bool error = false; |
128 | if(interfaces->getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) | 121 | if(interfaces.getInterfaceMethod(error) == INTERFACES_METHOD_DHCP) |
129 | dhcpCheckBox->setChecked(true); | 122 | dhcpCheckBox->setChecked(true); |
130 | else | 123 | else |
131 | dhcpCheckBox->setChecked(false); | 124 | dhcpCheckBox->setChecked(false); |
132 | leaseTime->setValue(interfaces->getInterfaceOption("leasehours", error).toInt()); | 125 | leaseTime->setValue(interfaces.getInterfaceOption("leasehours", error).toInt()); |
133 | if(error) | 126 | if(error) |
134 | leaseTime->setValue(interfaces->getInterfaceOption("leasetime", error).toInt()/60/60); | 127 | leaseTime->setValue(interfaces.getInterfaceOption("leasetime", error).toInt()/60/60); |
135 | if(error) | 128 | if(error) |
136 | leaseTime->setValue(24); | 129 | leaseTime->setValue(24); |
137 | 130 | ||
138 | // IP Information | 131 | // IP Information |
139 | autoStart->setChecked(interfaces->isAuto(interface->getInterfaceName())); | 132 | autoStart->setChecked(interfaces.isAuto(interface->getInterfaceName())); |
140 | QString dns = interfaces->getInterfaceOption("up "DNSSCRIPT" -a", error); | 133 | QString dns = interfaces.getInterfaceOption("up "DNSSCRIPT" -a", error); |
141 | if(dns.contains(" ")){ | 134 | if(dns.contains(" ")){ |
142 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); | 135 | firstDNSLineEdit->setText(dns.mid(0, dns.find(" "))); |
143 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); | 136 | secondDNSLineEdit->setText(dns.mid(dns.find(" ")+1, dns.length())); |
144 | } | 137 | } |
145 | ipAddressEdit->setText(interfaces->getInterfaceOption("address", error)); | 138 | ipAddressEdit->setText(interfaces.getInterfaceOption("address", error)); |
146 | subnetMaskEdit->setText(interfaces->getInterfaceOption("netmask", error)); | 139 | subnetMaskEdit->setText(interfaces.getInterfaceOption("netmask", error)); |
147 | gatewayEdit->setText(interfaces->getInterfaceOption("gateway", error)); | 140 | gatewayEdit->setText(interfaces.getInterfaceOption("gateway", error)); |
148 | } | ||
149 | 141 | ||
142 | } | ||
150 | 143 | ||
151 | // interfacesetup.cpp | 144 | // interfacesetup.cpp |
152 | 145 | ||