summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/network/networkedit.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/network/networkedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/network/networkedit.cpp160
1 files changed, 160 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/network/networkedit.cpp b/noncore/settings/networksettings2/network/networkedit.cpp
new file mode 100644
index 0000000..b17d745
--- a/dev/null
+++ b/noncore/settings/networksettings2/network/networkedit.cpp
@@ -0,0 +1,160 @@
1#include <qtoolbutton.h>
2#include <qcheckbox.h>
3#include <qlineedit.h>
4#include <qlistbox.h>
5#include <GUIUtils.h>
6#include <resources.h>
7#include "networkedit.h"
8
9NetworkEdit::NetworkEdit( QWidget * Parent ) : NetworkGUI( Parent ){
10
11 AddPreDown_TB->setPixmap( NSResources->getPixmap( "add" ) );
12 AddPreUp_TB->setPixmap( NSResources->getPixmap( "add" ) );
13 AddPostDown_TB->setPixmap( NSResources->getPixmap( "add" ) );
14 AddPostUp_TB->setPixmap( NSResources->getPixmap( "add" ) );
15
16 DeletePreDown_TB->setPixmap( NSResources->getPixmap( "remove" ) );
17 DeletePreUp_TB->setPixmap( NSResources->getPixmap( "remove" ) );
18 DeletePostDown_TB->setPixmap( NSResources->getPixmap( "remove" ) );
19 DeletePostUp_TB->setPixmap( NSResources->getPixmap( "remove" ) );
20
21 UpPreDown_TB->setPixmap( NSResources->getPixmap( "up" ) );
22 UpPreUp_TB->setPixmap( NSResources->getPixmap( "up" ) );
23 UpPostDown_TB->setPixmap( NSResources->getPixmap( "up" ) );
24 UpPostUp_TB->setPixmap( NSResources->getPixmap( "up" ) );
25
26 DownPreDown_TB->setPixmap( NSResources->getPixmap( "down" ) );
27 DownPreUp_TB->setPixmap( NSResources->getPixmap( "down" ) );
28 DownPostDown_TB->setPixmap( NSResources->getPixmap( "down" ) );
29 DownPostUp_TB->setPixmap( NSResources->getPixmap( "down" ) );
30
31}
32
33QString NetworkEdit::acceptable( void ) {
34 if( DHCP_CB->isChecked() ) {
35 if( SendHostname_CB->isChecked() )
36 if( Hostname_LE->text().isEmpty() )
37 return tr("Hostname needed");
38 return QString();
39 }
40
41 if( IPAddress_LE->text().isEmpty() )
42 return tr("IPAddress needed");
43 if( Broadcast_LE->text().isEmpty() )
44 return tr("Broadcast needed");
45 if( SubnetMask_LE->text().isEmpty() )
46 return tr("Subnet mask needed");
47
48 // valid IP ?
49 if( ! validIP( IPAddress_LE->text() ) )
50 return tr("IPAddress not valid");
51 if( ! validIP( SubnetMask_LE->text() ) )
52 return tr("Subnet mask not valid");
53 if( ! validIP( Broadcast_LE->text() ) )
54 return tr("Broadcast address not valid");
55 if( Gateway_LE->text().isEmpty() &&
56 ! validIP( Gateway_LE->text() ) )
57 return tr("Gateway address not valid");
58 if( DNS1_LE->text().isEmpty() &&
59 ! validIP( DNS1_LE->text() ) )
60 return tr("DNS1 address not valid");
61 if( DNS2_LE->text().isEmpty() &&
62 ! validIP( DNS2_LE->text() ) )
63 return tr("DNS2 address not valid");
64 return QString();
65}
66
67bool NetworkEdit::commit( NetworkData_t & Data ) {
68 bool SM = 0;
69 CBM( Data.UseDHCP, DHCP_CB, SM );
70 TXTM( Data.IPAddress, IPAddress_LE, SM );
71 CBM( Data.SendHostname, SendHostname_CB, SM );
72 TXTM( Data.Hostname, Hostname_LE, SM );
73 TXTM( Data.Gateway, Gateway_LE, SM );
74 TXTM( Data.Broadcast, Broadcast_LE, SM );
75 TXTM( Data.NetMask, SubnetMask_LE, SM );
76 TXTM( Data.DNS1, DNS1_LE, SM );
77 TXTM( Data.DNS2, DNS2_LE, SM );
78
79 SM |= updateList( Data.PreUp_SL, PreUp_LB );
80 SM |= updateList( Data.PostUp_SL, PostUp_LB );
81 SM |= updateList( Data.PreDown_SL, PreDown_LB );
82 SM |= updateList( Data.PostDown_SL, PostDown_LB );
83
84 return SM;
85}
86
87void NetworkEdit::showData( NetworkData_t & Data ) {
88 DHCP_CB->setChecked( Data.UseDHCP );
89 SendHostname_CB->setChecked( Data.SendHostname );
90 Hostname_LE->setText( Data.Hostname );
91 IPAddress_LE->setText( Data.IPAddress );
92 Gateway_LE->setText( Data.Gateway );
93 SubnetMask_LE->setText( Data.NetMask );
94 Broadcast_LE->setText( Data.Broadcast );
95 DNS1_LE->setText( Data.DNS1 );
96 DNS2_LE->setText( Data.DNS2 );
97
98 populateList( Data.PreUp_SL, PreUp_LB );
99 populateList( Data.PostUp_SL, PostUp_LB );
100 populateList( Data.PreDown_SL, PreDown_LB );
101 populateList( Data.PostDown_SL, PostDown_LB );
102}
103
104bool NetworkEdit::updateList( QStringList & SL, QListBox * LB ) {
105 bool Changed;
106 QStringList NewSL;
107
108 // collect new list
109 for( unsigned int i = 0; i < LB->count() ; i ++ ) {
110 NewSL.append( LB->text(i) );
111 }
112
113 // check if at least ONE item in new list is NEW
114 Changed = 0;
115 for ( QStringList::Iterator it = NewSL.begin();
116 it != NewSL.end();
117 ++it ) {
118 if( SL.findIndex( (*it) ) < 0 ) {
119 // new or modified item
120 Changed = 1;
121 SL = NewSL;
122 break;
123 }
124 }
125 return Changed;
126}
127
128void NetworkEdit::populateList( QStringList & SL, QListBox * LB ) {
129 LB->clear();
130 for ( QStringList::Iterator it = SL.begin();
131 it != SL.end();
132 ++it ) {
133 LB->insertItem( (*it) );
134 }
135}
136
137void NetworkEdit::SLOT_NetmaskModified( const QString & ) {
138 QString IP, SN;
139 IP = IPAddress_LE->text();
140 SN = SubnetMask_LE->text();
141 if( IP.isEmpty() || SN.isEmpty() )
142 return;
143
144 if( ! validIP(IP) || ! validIP( SN ) )
145 return;
146
147 // if all ones
148 // broadcast = (IPAddress | ~netmask )
149 { QString NW;
150 QStringList ipal = QStringList::split( '.', IP );
151 QStringList nmal = QStringList::split( '.', SN );
152
153 NW = QString( "%1.%2.%3.%4" ).
154 arg( ipal[0].toShort() | ( ~ nmal[0].toShort() & 0x00ff) ).
155 arg( ipal[1].toShort() | ( ~ nmal[1].toShort() & 0x00ff) ).
156 arg( ipal[2].toShort() | ( ~ nmal[2].toShort() & 0x00ff) ).
157 arg( ipal[3].toShort() | ( ~ nmal[3].toShort() & 0x00ff) );
158 Broadcast_LE->setText( NW );
159 }
160}