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