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