summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/gprs/GPRSedit.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/gprs/GPRSedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/gprs/GPRSedit.cpp164
1 files changed, 164 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/gprs/GPRSedit.cpp b/noncore/settings/networksettings2/gprs/GPRSedit.cpp
new file mode 100644
index 0000000..d72b9a2
--- a/dev/null
+++ b/noncore/settings/networksettings2/gprs/GPRSedit.cpp
@@ -0,0 +1,164 @@
1#include <qtoolbutton.h>
2#include <qlistview.h>
3#include <qheader.h>
4#include <qspinbox.h>
5#include <qradiobutton.h>
6#include <qcheckbox.h>
7#include <qtabwidget.h>
8#include <qlineedit.h>
9#include <qlistbox.h>
10#include <GUIUtils.h>
11#include <resources.h>
12#include "GPRSedit.h"
13
14GPRSEdit::GPRSEdit( QWidget * Parent ) : GPRSGUI( Parent ){
15 Routing_LV->header()->hide();
16 Add_TB->setPixmap( NSResources->getPixmap( "add" ) );
17 Delete_TB->setPixmap( NSResources->getPixmap( "delete" ) );
18 Routing_LV->setColumnAlignment( 1, Qt::AlignRight );
19}
20
21QString GPRSEdit::acceptable( void ) {
22 if( APN_LE->text().isEmpty() ) {
23 return tr("APN is required");
24 }
25
26 return QString();
27}
28
29bool GPRSEdit::commit( GPRSData & Data ) {
30 bool SM = 0;
31 bool RM;
32
33 TXTM( Data.APN, APN_LE, SM );
34 TXTM( Data.User, User_LE, SM );
35 TXTM( Data.Password, Password_LE, SM );
36
37 if( AssignedByServer_CB->isChecked() ) {
38 if( ! Data.DNS1.isEmpty() ) {
39 SM = 1;
40 Data.DNS1 = "";
41 }
42 if( ! Data.DNS2.isEmpty() ) {
43 SM = 1;
44 Data.DNS2 = "";
45 }
46 } else {
47 TXTM( Data.DNS1, DNS1_LE, SM );
48 TXTM( Data.DNS2, DNS2_LE, SM );
49 }
50
51 CBM( Data.DefaultGateway, DefaultGateway_RB, SM );
52 CBM( Data.SetIfSet, SetIfSet_CB, SM );
53
54 // find new routes
55 unsigned int i;
56
57 RM = 0; // routing modified
58 QListViewItem * it = Routing_LV->firstChild();
59 while( ! RM && it ) {
60 for( i = 0; i < Data.Routing.count(); i ++ ) {
61 if( it->text(0) == Data.Routing[i]->Address ) {
62 // still exists
63 break;
64 }
65 }
66 if( i == Data.Routing.count() ) {
67 // modified
68 RM = 1;
69 }
70 it = it->nextSibling();
71 }
72
73 // find obsoleted
74 for( i = 0; ! RM && i < Data.Routing.count(); i ++ ) {
75 it = Routing_LV->firstChild();
76 while( it ) {
77 if( it->text(0) == Data.Routing[i]->Address ) {
78 // still exists
79 break;
80 }
81 it = it->nextSibling();
82 }
83
84 if( it == 0 ) {
85 RM = 1;
86 }
87 }
88
89 if( RM ) {
90 unsigned int i = 0;
91 GPRSRoutingEntry * E;
92 // update routing table
93 Data.Routing.resize(0);
94 Data.Routing.resize( Routing_LV->childCount() );
95
96 it = Routing_LV->firstChild();
97 while( it ) {
98 E = new GPRSRoutingEntry;
99 E->Address = it->text(0);
100 E->Mask = it->text(1).toShort();
101 Data.Routing.insert( i, E );
102 i ++;
103 it = it->nextSibling();
104 }
105 }
106
107 SBM( Data.Debug, Debug_SB, SM );
108 return SM;
109}
110
111void GPRSEdit::showData( GPRSData & Data ) {
112 STXT( Data.APN, APN_LE );
113 STXT( Data.User, User_LE );
114 STXT( Data.Password, Password_LE );
115
116 SCB( ( Data.DNS1.isEmpty() && Data.DNS2.isEmpty() ),
117 AssignedByServer_CB );
118 STXT( Data.DNS1, DNS1_LE );
119 STXT( Data.DNS2, DNS2_LE );
120
121 SCB( Data.DefaultGateway, DefaultGateway_RB );
122 SCB( (! Data.DefaultGateway), FixedGateway_RB );
123 SCB( Data.SetIfSet, SetIfSet_CB );
124
125 for( unsigned int i = 0; i < Data.Routing.count(); i ++ ) {
126 QListViewItem * it;
127 it = new QListViewItem( Routing_LV );
128
129 it->setText( 0, Data.Routing[i]->Address );
130 it->setText( 1, QString().setNum( Data.Routing[i]->Mask ) );
131 }
132
133 SSB( Data.Debug, Debug_SB );
134}
135
136void GPRSEdit::SLOT_AddRoute( void ) {
137 QListViewItem * it, *last;
138 QListViewItem * after = Routing_LV->firstChild();
139 last = 0;
140 while( after ) {
141 if( after->isSelected() ) {
142 break;
143 }
144 last = after;
145 after = after->nextSibling();
146 }
147
148 it = new QListViewItem( Routing_LV, (after) ? after : last );
149
150 it->setText( 0, Net_LE->text() );
151 it->setText( 1, QString().setNum( Mask_SB->value() ) );
152}
153
154void GPRSEdit::SLOT_DeleteRoute( void ) {
155 QListViewItem * nit;
156 QListViewItem * it = Routing_LV->firstChild();
157 while( it ) {
158 nit = it->nextSibling();
159 if( it->isSelected() ) {
160 delete it;
161 }
162 it = nit;
163 }
164}