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