author | wimpie <wimpie> | 2005-01-04 01:35:26 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-04 01:35:26 (UTC) |
commit | a9c188235c97e07b0eb96b13adbcdfd4bad64767 (patch) (unidiff) | |
tree | 13f6ae5c499dc0c1d1bd4b763a1973a0fa8635cf /noncore/settings/networksettings2/editconnection.cpp | |
parent | 48b6cd5966ec6cc0b968edf10ba1a1ad96ef165f (diff) | |
download | opie-a9c188235c97e07b0eb96b13adbcdfd4bad64767.zip opie-a9c188235c97e07b0eb96b13adbcdfd4bad64767.tar.gz opie-a9c188235c97e07b0eb96b13adbcdfd4bad64767.tar.bz2 |
CONTROL files : changed version string
NS2 many changes and first release of OT2
Diffstat (limited to 'noncore/settings/networksettings2/editconnection.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/editconnection.cpp | 188 |
1 files changed, 121 insertions, 67 deletions
diff --git a/noncore/settings/networksettings2/editconnection.cpp b/noncore/settings/networksettings2/editconnection.cpp index 77826d1..3f8a53f 100644 --- a/noncore/settings/networksettings2/editconnection.cpp +++ b/noncore/settings/networksettings2/editconnection.cpp | |||
@@ -1,441 +1,494 @@ | |||
1 | #include <opie2/odebug.h> | ||
1 | #include <qlistview.h> | 2 | #include <qlistview.h> |
2 | #include <qwidgetstack.h> | 3 | #include <qwidgetstack.h> |
3 | #include <qframe.h> | 4 | #include <qframe.h> |
4 | #include <qcombobox.h> | 5 | #include <qcombobox.h> |
5 | #include <qtabwidget.h> | 6 | #include <qtabwidget.h> |
6 | #include <qmessagebox.h> | 7 | #include <qmessagebox.h> |
7 | #include <qpushbutton.h> | 8 | #include <qpushbutton.h> |
8 | #include <qlineedit.h> | 9 | #include <qlineedit.h> |
9 | #include <qheader.h> | 10 | #include <qheader.h> |
10 | #include <qpainter.h> | 11 | #include <qpainter.h> |
11 | #include <qcheckbox.h> | 12 | #include <qcheckbox.h> |
12 | #include <qlabel.h> | 13 | #include <qlabel.h> |
13 | 14 | ||
14 | #include "editconnection.h" | 15 | #include "editconnection.h" |
15 | #include "resources.h" | 16 | #include "resources.h" |
16 | #include "netnode.h" | 17 | #include "netnode.h" |
17 | 18 | ||
18 | // | 19 | // |
19 | // | 20 | // |
20 | // THESE TO GIVE BETTER FEEDBACK ABOUT DISABLED ITEMS | 21 | // THESE TO GIVE BETTER FEEDBACK ABOUT DISABLED ITEMS |
21 | // | 22 | // |
22 | // | 23 | // |
23 | 24 | ||
24 | class MyQCheckListItem : public QCheckListItem | 25 | class MyQCheckListItem : public QCheckListItem |
25 | { | 26 | { |
26 | public: | 27 | public: |
27 | MyQCheckListItem( QListView *parent, const QString & S, Type T ) : | 28 | MyQCheckListItem( QListView *parent, const QString & S, Type T ) : |
28 | QCheckListItem( parent, S, T ) { } | 29 | QCheckListItem( parent, S, T ) { } |
29 | MyQCheckListItem( QCheckListItem *parent, const QString & S, Type T ) : | 30 | MyQCheckListItem( QCheckListItem *parent, const QString & S, Type T ) : |
30 | QCheckListItem( parent, S, T ) { } | 31 | QCheckListItem( parent, S, T ) { } |
31 | MyQCheckListItem( QListViewItem *parent, const QString & S, Type T ) : | 32 | MyQCheckListItem( QListViewItem *parent, const QString & S, Type T ) : |
32 | QCheckListItem( parent, S, T ) { } | 33 | QCheckListItem( parent, S, T ) { } |
33 | 34 | ||
35 | MyQCheckListItem( QListView *parent, const QString & S ) : | ||
36 | QCheckListItem( parent, S, QCheckListItem::Controller ) { } | ||
37 | MyQCheckListItem( QCheckListItem *parent, const QString & S ) : | ||
38 | QCheckListItem( parent, S, QCheckListItem::Controller ) { } | ||
39 | MyQCheckListItem( QListViewItem *parent, const QString & S ) : | ||
40 | QCheckListItem( parent, S, QCheckListItem::Controller ) { } | ||
41 | |||
34 | virtual void paintCell( QPainter *p, const QColorGroup &cg, | 42 | virtual void paintCell( QPainter *p, const QColorGroup &cg, |
35 | int column, int width, int alignment ); | 43 | int column, int width, int alignment ); |
36 | 44 | ||
37 | }; | 45 | }; |
38 | 46 | ||
39 | void MyQCheckListItem::paintCell( QPainter *p, const QColorGroup &cg, | 47 | void MyQCheckListItem::paintCell( QPainter *p, const QColorGroup &cg, |
40 | int column, int width, int alignment ) | 48 | int column, int width, int alignment ) |
41 | { | 49 | { |
42 | QColorGroup _cg( cg ); | 50 | QColorGroup _cg( cg ); |
43 | QColor c = _cg.text(); | 51 | QColor c = _cg.text(); |
44 | if ( ! isSelectable() ) | 52 | if ( ! isSelectable() ) |
45 | _cg.setColor( QColorGroup::Text, Qt::lightGray ); | 53 | _cg.setColor( QColorGroup::Text, Qt::lightGray ); |
46 | QCheckListItem::paintCell( p, _cg, column, width, alignment ); | 54 | QCheckListItem::paintCell( p, _cg, column, width, alignment ); |
47 | _cg.setColor( QColorGroup::Text, c ); | 55 | _cg.setColor( QColorGroup::Text, c ); |
48 | } | 56 | } |
49 | 57 | ||
50 | class MyQListViewItem : public QListViewItem | 58 | class MyQListViewItem : public QListViewItem |
51 | { | 59 | { |
52 | public: | 60 | public: |
53 | MyQListViewItem( QListView *parent, const QString & S ) : | 61 | MyQListViewItem( QListView *parent, const QString & S ) : |
54 | QListViewItem( parent, S ) { } | 62 | QListViewItem( parent, S ) { } |
55 | MyQListViewItem( QListViewItem *parent, const QString & S ) : | 63 | MyQListViewItem( QListViewItem *parent, const QString & S ) : |
56 | QListViewItem( parent, S ) { } | 64 | QListViewItem( parent, S ) { } |
57 | 65 | ||
58 | virtual void paintCell( QPainter *p, const QColorGroup &cg, | 66 | virtual void paintCell( QPainter *p, const QColorGroup &cg, |
59 | int column, int width, int alignment ); | 67 | int column, int width, int alignment ); |
60 | 68 | ||
61 | }; | 69 | }; |
62 | 70 | ||
63 | void MyQListViewItem::paintCell( QPainter *p, const QColorGroup &cg, | 71 | void MyQListViewItem::paintCell( QPainter *p, const QColorGroup &cg, |
64 | int column, int width, int alignment ) | 72 | int column, int width, int alignment ) |
65 | { | 73 | { |
66 | QColorGroup _cg( cg ); | 74 | QColorGroup _cg( cg ); |
67 | QColor c = _cg.text(); | 75 | QColor c = _cg.text(); |
68 | if ( ! isSelectable() ) | 76 | if ( ! isSelectable() ) |
69 | _cg.setColor( QColorGroup::Text, Qt::lightGray ); | 77 | _cg.setColor( QColorGroup::Text, Qt::lightGray ); |
70 | QListViewItem::paintCell( p, _cg, column, width, alignment ); | 78 | QListViewItem::paintCell( p, _cg, column, width, alignment ); |
71 | _cg.setColor( QColorGroup::Text, c ); | 79 | _cg.setColor( QColorGroup::Text, c ); |
72 | } | 80 | } |
73 | 81 | ||
74 | // | 82 | // |
75 | // | 83 | // |
76 | // REAL GUI | 84 | // REAL GUI |
77 | // | 85 | // |
78 | // | 86 | // |
79 | 87 | ||
80 | bool EditConnection::AutoCollapse = 1; | 88 | bool EditConnection::AutoCollapse = 1; |
81 | 89 | ||
82 | EditConnection::EditConnection( QWidget* parent ) : | 90 | EditConnection::EditConnection( QWidget* parent ) : |
83 | EditConnectionGUI( parent, 0, TRUE ), TmpCollection() { | 91 | EditConnectionGUI( parent, 0, TRUE ), TmpCollection() { |
84 | 92 | ||
85 | Tab_TB->setTabEnabled( Setup_FRM, FALSE ); | 93 | Tab_TB->setTabEnabled( Setup_FRM, FALSE ); |
86 | Setup_FRM->setEnabled( FALSE ); | 94 | Setup_FRM->setEnabled( FALSE ); |
87 | 95 | ||
88 | TmpIsValid = 0; | 96 | TmpIsValid = 0; |
89 | SelectedNodes = 0; | 97 | SelectedNodes = 0; |
90 | 98 | ||
91 | AutoCollapse_CB->setChecked( AutoCollapse ); | 99 | AutoCollapse_CB->setChecked( AutoCollapse ); |
92 | 100 | ||
93 | Mapping = new QPtrDict<ANetNode>; | 101 | Mapping = new QPtrDict<ANetNode>; |
94 | Mapping->setAutoDelete( FALSE ); | 102 | Mapping->setAutoDelete( FALSE ); |
95 | Nodes_LV->header()->hide(); | 103 | Nodes_LV->header()->hide(); |
96 | // popluate tree with all NetNodes | 104 | // popluate tree with all NetNodes |
97 | buildFullTree(); | 105 | buildFullTree(); |
98 | } | 106 | } |
99 | 107 | ||
100 | NodeCollection * EditConnection::getTmpCollection( void ) { | 108 | NodeCollection * EditConnection::getTmpCollection( void ) { |
101 | 109 | ||
102 | if( TmpIsValid ) | 110 | if( TmpIsValid ) |
103 | // content is stil OK | 111 | // content is stil OK |
104 | return &(TmpCollection); | 112 | return &(TmpCollection); |
105 | 113 | ||
106 | // reset collection -> delete all NEW NetNodes | 114 | // reset collection -> delete all NEW NetNodes |
107 | for( QListIterator<ANetNodeInstance> it(TmpCollection); | 115 | for( QListIterator<ANetNodeInstance> it(TmpCollection); |
108 | it.current(); | 116 | it.current(); |
109 | ++it ) { | 117 | ++it ) { |
110 | if( it.current()->isNew() ) { | 118 | if( it.current()->isNew() ) { |
111 | delete it.current(); | 119 | delete it.current(); |
112 | } | 120 | } |
113 | } | 121 | } |
114 | TmpCollection.clear(); | 122 | TmpCollection.clear(); |
115 | 123 | ||
116 | // update content | 124 | // update content |
117 | QListViewItem * it = Nodes_LV->firstChild(); | 125 | QListViewItem * it = Nodes_LV->firstChild(); |
118 | ANetNode * NN; | 126 | ANetNode * NN; |
119 | // start iter | 127 | |
128 | // start iter (if there is a collection) | ||
129 | /* | ||
130 | |||
131 | a node collection is sorted from the toplevel | ||
132 | node to the deepest node | ||
133 | |||
134 | */ | ||
120 | ANetNodeInstance * NNI = | 135 | ANetNodeInstance * NNI = |
121 | (SelectedNodes) ? SelectedNodes->first() : 0 ; | 136 | (SelectedNodes) ? SelectedNodes->first() : 0 ; |
122 | 137 | ||
123 | TmpCollection.setModified( 0 ); | 138 | TmpCollection.setModified( 0 ); |
124 | 139 | ||
140 | // the listview always starts with the toplevel | ||
141 | // hierarchy. This is always a controller item | ||
125 | while ( it ) { | 142 | while ( it ) { |
126 | NN = (*Mapping)[it]; | 143 | NN = (*Mapping)[it]; |
127 | if( NN == 0 ) { | 144 | if( NN == 0 ) { |
128 | // child is controller -> has sub radio | 145 | // this item is a controller -> |
129 | // check if one radio is selected | 146 | // has radio items as children -> |
147 | // find selected one | ||
130 | it = it->firstChild(); | 148 | it = it->firstChild(); |
131 | while( it ) { | 149 | while( it ) { |
132 | if( ((QCheckListItem *)it)->isOn() ) { | 150 | if( ((QCheckListItem *)it)->isOn() ) { |
133 | // this radio is selected -> go deeper | 151 | // this radio is selected -> go deeper |
134 | if( SelectedNodes == 0 || | ||
135 | NNI == 0 || | ||
136 | it->text(0) != NNI->nodeClass()->name() ) { | ||
137 | // new item not in previous collection | ||
138 | ANetNodeInstance * NNI = (*Mapping)[it]->createInstance(); | ||
139 | NNI->initialize(); | ||
140 | // this node type not in collection | ||
141 | TmpCollection.append( NNI ); | ||
142 | // master collection changed because new item in it | ||
143 | TmpCollection.setModified( 1 ); | ||
144 | // no more valid items in old list | ||
145 | NNI = 0; | ||
146 | } else { | ||
147 | // already in list -> copy pointer | ||
148 | TmpCollection.append( NNI ); | ||
149 | NNI = SelectedNodes->next(); | ||
150 | } | ||
151 | it = it->firstChild(); | ||
152 | // do not bother to check other items | ||
153 | break; | 152 | break; |
154 | } | 153 | } |
155 | it = it->nextSibling(); | 154 | it = it->nextSibling(); |
156 | } | 155 | } |
156 | |||
157 | if( ! it ) { | ||
158 | owarn << "Radio not selected" << oendl; | ||
159 | TmpIsValid = 0; | ||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | // it now contains selected radio | ||
164 | NN = (*Mapping)[it]; | ||
165 | } | ||
166 | |||
167 | // NN here contains the netnode of the | ||
168 | // current item -> this node needs to | ||
169 | // be stored in the collection | ||
170 | if( NNI == 0 || | ||
171 | it->text(0) != NNI->nodeClass()->name() ) { | ||
172 | // new item not in previous collection | ||
173 | ANetNodeInstance * NNI = NN->createInstance(); | ||
174 | NNI->initialize(); | ||
175 | // this node type not in collection | ||
176 | TmpCollection.append( NNI ); | ||
177 | // master collection changed because new item in it | ||
178 | TmpCollection.setModified( 1 ); | ||
179 | // no more valid items in old list | ||
180 | NNI = 0; | ||
157 | } else { | 181 | } else { |
158 | // check children | 182 | // already in list -> copy pointer |
159 | it = it->firstChild(); | 183 | TmpCollection.append( NNI ); |
184 | NNI = SelectedNodes->next(); | ||
160 | } | 185 | } |
186 | |||
187 | // go deeper to next level | ||
188 | // this level is can be a new controller | ||
189 | // or an item | ||
190 | it = it->firstChild(); | ||
161 | } | 191 | } |
162 | 192 | ||
163 | TmpIsValid = 1; | 193 | TmpIsValid = 1; |
164 | return &(TmpCollection); | 194 | return &(TmpCollection); |
165 | } | 195 | } |
166 | 196 | ||
167 | // pass a connection NodeCollection to be edited | 197 | // pass a connection NodeCollection to be edited |
168 | void EditConnection::setConnection( NodeCollection * NC ) { | 198 | void EditConnection::setConnection( NodeCollection * NC ) { |
169 | ANetNodeInstance * NNI; | 199 | ANetNodeInstance * NNI; |
170 | ANetNode * NN; | 200 | ANetNode * NN; |
171 | 201 | ||
172 | SelectedNodes = NC; | 202 | SelectedNodes = NC; |
173 | Name_LE->setText( NC->name() ); | 203 | Name_LE->setText( NC->name() ); |
174 | NNI = NC->first(); | 204 | NNI = NC->first(); |
175 | 205 | ||
176 | // show configure tabl | 206 | // show configure tabl |
177 | Tab_TB->setCurrentPage( 1 ); | 207 | Tab_TB->setCurrentPage( 1 ); |
178 | 208 | ||
179 | // valid colledction | 209 | // valid colledction |
180 | Tab_TB->setTabEnabled( Setup_FRM, FALSE ); | 210 | Tab_TB->setTabEnabled( Setup_FRM, FALSE ); |
181 | Setup_FRM->setEnabled( FALSE ); | 211 | Setup_FRM->setEnabled( FALSE ); |
182 | 212 | ||
183 | // select items in collection | 213 | // select items in collection |
184 | QListViewItem * it = Nodes_LV->firstChild(); | 214 | QListViewItem * it = Nodes_LV->firstChild(); |
185 | bool Found; | 215 | bool Found; |
186 | 216 | ||
187 | TmpIsValid = 0; | 217 | TmpIsValid = 0; |
188 | 218 | ||
189 | while ( it ) { | 219 | while ( it ) { |
190 | // listitem corresponds to netnode | ||
191 | NN = (*Mapping)[it]; | 220 | NN = (*Mapping)[it]; |
192 | if( NN == 0 ) { | 221 | if( NN == 0 ) { |
193 | // child is controller -> has sub radio | 222 | // this item is a controller -> |
194 | QString Ctr = it->text(0); | 223 | // has radio items as children -> |
195 | // check if one radio is selected | 224 | // find selected one |
196 | it = it->firstChild(); | 225 | it = it->firstChild(); |
197 | Found = 0; | 226 | Found = 0; |
198 | while( it ) { | 227 | while( it ) { |
199 | if( NNI && it->text(0) == NNI->nodeClass()->name() ) { | 228 | if( NNI && it->text(0) == NNI->nodeClass()->name() ) { |
200 | // this radio is part of the collection | 229 | // this radio is part of the collection |
201 | ((QCheckListItem *)it)->setOn( 1 ); | 230 | ((QCheckListItem *)it)->setOn( 1 ); |
202 | updateGUI( it, NNI->nodeClass() ); | 231 | updateGUI( it, NNI->nodeClass() ); |
203 | // check its children | 232 | // check its children |
204 | Found = 1; | 233 | Found = 1; |
205 | it = it->firstChild(); | 234 | it = it->firstChild(); |
206 | NNI = SelectedNodes->next(); | 235 | NNI = SelectedNodes->next(); |
207 | // do not bother to check other items | 236 | // do not bother to check other items |
208 | break; | 237 | break; |
209 | } | 238 | } |
210 | it = it->nextSibling(); | 239 | it = it->nextSibling(); |
211 | } | 240 | } |
241 | |||
212 | if( ! Found ) { | 242 | if( ! Found ) { |
213 | // this means that this level is NOT present in collection | 243 | // this means that this level is NOT present in collection |
214 | // probably INCOMPATIBEL collection OR Missing plugin | 244 | // probably INCOMPATIBEL collection OR Missing plugin |
215 | QMessageBox::warning( | 245 | QMessageBox::warning( |
216 | 0, | 246 | 0, |
217 | tr( "Error presentig Connection" ), | 247 | tr( "Error presentig Connection" ), |
218 | tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ). | 248 | tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ). |
219 | arg(Ctr) ); | 249 | arg(NNI->nodeClass()->name()) ); |
220 | return; | 250 | return; |
221 | } | 251 | } |
252 | |||
253 | // it now contains selected radio | ||
254 | NN = (*Mapping)[it]; | ||
222 | } else { | 255 | } else { |
223 | // automatic item -> check children | 256 | // automatic selection |
257 | if( NNI == 0 || it->text(0) != NNI->nodeClass()->name() ) { | ||
258 | // should exist and be the same | ||
259 | if( NNI ) { | ||
260 | QMessageBox::warning( | ||
261 | 0, | ||
262 | tr( "Error presentig Connection" ), | ||
263 | tr( "<p>Old connection or missing plugin \"<i>%1</i>\"</p>" ). | ||
264 | arg(NNI->nodeClass()->name()) ); | ||
265 | } else { | ||
266 | QMessageBox::warning( | ||
267 | 0, | ||
268 | tr( "Error presentig Connection" ), | ||
269 | tr( "<p>Missing connection\"<i>%1</i>\"</p>" ). | ||
270 | arg(it->text(0)) ); | ||
271 | } | ||
272 | return; | ||
273 | } | ||
224 | it = it->firstChild(); | 274 | it = it->firstChild(); |
225 | } | 275 | } |
226 | } | 276 | } |
227 | } | 277 | } |
228 | 278 | ||
229 | // get result of editing (either new OR updated collection | 279 | // get result of editing (either new OR updated collection |
230 | NodeCollection * EditConnection::connection( void ) { | 280 | NodeCollection * EditConnection::connection( void ) { |
231 | 281 | ||
232 | if( SelectedNodes == 0 ) { | 282 | if( SelectedNodes == 0 ) { |
233 | // new collection | 283 | // new collection |
234 | SelectedNodes = new NodeCollection; | 284 | SelectedNodes = new NodeCollection; |
235 | } | 285 | } |
236 | 286 | ||
237 | // clean out old entries | 287 | // clean out old entries |
238 | SelectedNodes->clear(); | 288 | SelectedNodes->clear(); |
239 | 289 | ||
240 | // transfer | 290 | // transfer |
241 | for( QListIterator<ANetNodeInstance> it(TmpCollection); | 291 | for( QListIterator<ANetNodeInstance> it(TmpCollection); |
242 | it.current(); | 292 | it.current(); |
243 | ++it ) { | 293 | ++it ) { |
244 | SelectedNodes->append( it.current() ); | 294 | SelectedNodes->append( it.current() ); |
245 | } | 295 | } |
246 | 296 | ||
247 | if( TmpCollection.isModified() ) | 297 | if( TmpCollection.isModified() ) |
248 | SelectedNodes->setModified( 1 ); | 298 | SelectedNodes->setModified( 1 ); |
249 | 299 | ||
250 | if( SelectedNodes->name() != Name_LE->text() ) { | 300 | if( SelectedNodes->name() != Name_LE->text() ) { |
251 | SelectedNodes->setName( Name_LE->text() ); | 301 | SelectedNodes->setName( Name_LE->text() ); |
252 | SelectedNodes->setModified( 1 ); | 302 | SelectedNodes->setModified( 1 ); |
253 | } | 303 | } |
254 | 304 | ||
255 | return SelectedNodes; | 305 | return SelectedNodes; |
256 | } | 306 | } |
257 | 307 | ||
258 | // Build device tree -> start | 308 | // Build device tree -> start |
259 | void EditConnection::buildFullTree( void ) { | 309 | void EditConnection::buildFullTree( void ) { |
260 | ANetNode * NN; | 310 | ANetNode * NN; |
261 | 311 | ||
262 | // toplevel item | 312 | // toplevel item |
263 | MyQCheckListItem * TheTop = new MyQCheckListItem( | 313 | MyQCheckListItem * TheTop = new MyQCheckListItem( |
264 | Nodes_LV, | 314 | Nodes_LV, |
265 | NSResources->netNode2Name("fullsetup"), | 315 | NSResources->netNode2Name("fullsetup"), |
266 | QCheckListItem::Controller ); | 316 | QCheckListItem::Controller ); |
267 | TheTop->setOpen( TRUE ); | 317 | TheTop->setOpen( TRUE ); |
268 | Description_LBL->setText( | 318 | Description_LBL->setText( |
269 | NSResources->netNode2Description( "fullsetup" ) ); | 319 | NSResources->netNode2Description( "fullsetup" ) ); |
270 | Nodes_LV->setSelected( TheTop, TRUE ); | 320 | Nodes_LV->setSelected( TheTop, TRUE ); |
271 | 321 | ||
272 | // find all Nodes that care toplevel nodes -> ie provide | 322 | // find all Nodes that are toplevel nodes -> ie provide |
273 | // TCP/IP Connection | 323 | // TCP/IP Connection |
274 | for( QDictIterator<NetNode_t> Iter(NSResources->netNodes()); | 324 | for( QDictIterator<NetNode_t> Iter(NSResources->netNodes()); |
275 | Iter.current(); | 325 | Iter.current(); |
276 | ++Iter ) { | 326 | ++Iter ) { |
277 | 327 | ||
278 | NN = Iter.current()->NetNode; | 328 | NN = Iter.current()->NetNode; |
279 | 329 | ||
280 | if( ! NN->isToplevel() ) { | 330 | if( ! NN->isToplevel() ) { |
281 | continue; | 331 | continue; |
282 | } | 332 | } |
283 | 333 | ||
284 | MyQCheckListItem * it = new MyQCheckListItem( TheTop, | 334 | MyQCheckListItem * it = new MyQCheckListItem( TheTop, |
285 | NN->name(), | 335 | NN->name(), |
286 | QCheckListItem::RadioButton ); | 336 | QCheckListItem::RadioButton ); |
287 | it->setPixmap( 0, NSResources->getPixmap( "Devices/commprofile" ) ); | 337 | it->setPixmap( 0, |
338 | NSResources->getPixmap( NN->pixmapName() ) | ||
339 | ); | ||
288 | // remember that this node maps to this listitem | 340 | // remember that this node maps to this listitem |
289 | Mapping->insert( it, NN ); | 341 | Mapping->insert( it, NN ); |
290 | buildSubTree( it, NN ); | 342 | buildSubTree( it, NN ); |
291 | } | 343 | } |
292 | } | 344 | } |
293 | 345 | ||
294 | // Build device tree -> help function | 346 | // Build device tree -> help function |
295 | void EditConnection::buildSubTree( QListViewItem * it, ANetNode *NN ) { | 347 | void EditConnection::buildSubTree( QListViewItem * it, ANetNode *NN ) { |
296 | ANetNode::NetNodeList & NNL = NN->alternatives(); | 348 | ANetNode::NetNodeList & NNL = NN->alternatives(); |
297 | 349 | ||
298 | if( NNL.size() > 1 ) { | 350 | if( NNL.size() > 1 ) { |
299 | // this node has alternatives -> needs radio buttons | 351 | // this node has alternatives -> needs radio buttons |
300 | it = new MyQCheckListItem( | 352 | it = new MyQCheckListItem( |
301 | it, | 353 | it, |
302 | NSResources->netNode2Name(NNL[0]->provides()), | 354 | NSResources->netNode2Name(NN->needs()[0]), |
303 | QCheckListItem::Controller ); | 355 | QCheckListItem::Controller ); |
304 | it->setSelectable( FALSE ); | 356 | it->setSelectable( FALSE ); |
305 | } | 357 | } |
306 | 358 | ||
307 | for ( unsigned int i=0; i < NNL.size(); i++ ) { | 359 | for ( unsigned int i=0; i < NNL.size(); i++ ) { |
308 | QListViewItem * CI; | 360 | QListViewItem * CI; |
309 | if( NNL.size() > 1 ) { | 361 | if( NNL.size() > 1 ) { |
310 | // generate radio buttons | 362 | // generate radio buttons |
311 | CI = new MyQCheckListItem( | 363 | CI = new MyQCheckListItem( |
312 | (QCheckListItem *)it, | 364 | (QCheckListItem *)it, |
313 | NNL[i]->name(), QCheckListItem::RadioButton ); | 365 | NNL[i]->name(), QCheckListItem::RadioButton ); |
314 | // remember that this node maps to this listitem | 366 | // remember that this node maps to this listitem |
315 | CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); | 367 | CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); |
316 | Mapping->insert( CI, NNL[i] ); | 368 | Mapping->insert( CI, NNL[i] ); |
317 | CI->setSelectable( FALSE ); | 369 | CI->setSelectable( FALSE ); |
318 | } else { | 370 | } else { |
319 | // Single item | 371 | // Single item |
320 | CI = new MyQListViewItem( it, NNL[i]->name() ); | 372 | CI = new MyQListViewItem( it, NNL[i]->name() ); |
321 | // remember that this node maps to this listitem | 373 | // remember that this node maps to this listitem |
322 | Mapping->insert( CI, NNL[i] ); | 374 | Mapping->insert( CI, NNL[i] ); |
323 | CI->setSelectable( FALSE ); | 375 | CI->setSelectable( FALSE ); |
324 | CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); | 376 | CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); |
325 | } | 377 | } |
326 | buildSubTree( CI, NNL[i] ); | 378 | buildSubTree( CI, NNL[i] ); |
327 | } | 379 | } |
328 | } | 380 | } |
329 | 381 | ||
330 | // Clicked ok OK button | 382 | // Clicked ok OK button |
331 | void EditConnection::accept( void ) { | 383 | void EditConnection::accept( void ) { |
332 | if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) { | 384 | if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) { |
333 | QMessageBox::warning( | 385 | QMessageBox::warning( |
334 | 0, | 386 | 0, |
335 | tr( "Closing Connection Setup" ), | 387 | tr( "Closing Connection Setup" ), |
336 | tr( "Definition not complete or no name" ) ); | 388 | tr( "Definition not complete or no name" ) ); |
337 | return; | 389 | return; |
338 | } | 390 | } |
339 | 391 | ||
340 | // check if all devices have acceptable input | 392 | // check if all devices have acceptable input |
341 | getTmpCollection(); | 393 | getTmpCollection(); |
342 | { ANetNodeInstance * NNI; | 394 | { ANetNodeInstance * NNI; |
343 | QString S; | 395 | QString S; |
344 | 396 | ||
345 | for( QListIterator<ANetNodeInstance> it(TmpCollection); | 397 | for( QListIterator<ANetNodeInstance> it(TmpCollection); |
346 | it.current(); | 398 | it.current(); |
347 | ++it ) { | 399 | ++it ) { |
348 | NNI = it.current(); | 400 | NNI = it.current(); |
349 | // widget must show its own problems | 401 | // widget must show its own problems |
350 | S = NNI->acceptable(); | 402 | S = NNI->acceptable(); |
351 | if( ! S.isEmpty() ) { | 403 | if( ! S.isEmpty() ) { |
352 | QMessageBox::warning( | 404 | QMessageBox::warning( |
353 | 0, | 405 | 0, |
354 | tr( "Cannot save" ), | 406 | tr( "Cannot save" ), |
355 | S ); | 407 | S ); |
356 | return; | 408 | return; |
357 | } | 409 | } |
358 | NNI->commit(); | 410 | NNI->commit(); |
359 | 411 | ||
360 | if( NNI->isModified() ) { | 412 | if( NNI->isModified() ) { |
361 | TmpCollection.setModified( 1 ); | 413 | TmpCollection.setModified( 1 ); |
362 | // commit the data | 414 | // commit the data |
363 | } | 415 | } |
364 | } | 416 | } |
365 | } | 417 | } |
366 | 418 | ||
367 | QDialog::accept(); | 419 | QDialog::accept(); |
368 | } | 420 | } |
369 | 421 | ||
370 | // triggered by CB | 422 | // triggered by CB |
371 | void EditConnection::SLOT_AutoCollapse( bool b ) { | 423 | void EditConnection::SLOT_AutoCollapse( bool b ) { |
372 | AutoCollapse = b; | 424 | AutoCollapse = b; |
373 | } | 425 | } |
374 | 426 | ||
375 | // clicked on node in tree -> update GUI | 427 | // clicked on node in tree -> update GUI |
376 | void EditConnection::SLOT_SelectNode( QListViewItem * it ) { | 428 | void EditConnection::SLOT_SelectNode( QListViewItem * it ) { |
377 | ANetNode * NN; | 429 | ANetNode * NN; |
378 | if( it == 0 || it->depth() == 0 ) { | 430 | if( it == 0 || it->depth() == 0 ) { |
379 | Description_LBL->setText( | 431 | Description_LBL->setText( |
380 | NSResources->netNode2Description( "fullsetup" ) ); | 432 | NSResources->netNode2Description( "fullsetup" ) ); |
381 | // topevel or no selection | 433 | // topevel or no selection |
382 | return; | 434 | return; |
383 | } | 435 | } |
384 | 436 | ||
385 | // store conversion from lvitem to node | 437 | // store conversion from lvitem to node |
386 | NN = (*Mapping)[ it ]; | 438 | NN = (*Mapping)[ it ]; |
387 | 439 | ||
388 | if( ! NN ) { | 440 | if( ! NN ) { |
389 | // intermediate node | 441 | // intermediate node |
390 | NN = (*Mapping)[ it->firstChild() ]; | 442 | NN = (*Mapping)[ it->parent() ]; |
391 | if( NN ) { | 443 | if( NN ) { |
392 | // figure out type of this node -> produce mesage | 444 | // figure out type of this node -> produce mesage |
393 | Description_LBL->setText( NSResources->netNode2Description(NN->provides()) ); | 445 | Description_LBL->setText( NSResources->netNode2Description( |
446 | NN->needs()[0]) ); | ||
394 | } else { | 447 | } else { |
395 | Description_LBL->setText( "" ); | 448 | Description_LBL->setText( "" ); |
396 | } | 449 | } |
397 | return; | 450 | return; |
398 | } | 451 | } |
399 | 452 | ||
400 | Description_LBL->setText( NN->nodeDescription() ); | 453 | Description_LBL->setText( NN->nodeDescription() ); |
401 | 454 | ||
402 | if( ! it->isSelectable() ) { | 455 | if( ! it->isSelectable() ) { |
403 | return; | 456 | return; |
404 | } | 457 | } |
405 | 458 | ||
406 | if( ! ((QCheckListItem *)it)->isOn() ) { | 459 | if( ! ((QCheckListItem *)it)->isOn() ) { |
407 | // clicked on line but NOT on Check or Radio item | 460 | // clicked on line but NOT on Check or Radio item |
408 | return; | 461 | return; |
409 | } | 462 | } |
410 | 463 | ||
411 | // item has really changed -> update | 464 | // item has really changed -> update |
412 | TmpIsValid = 0; | 465 | TmpIsValid = 0; |
413 | updateGUI( it, NN ); | 466 | updateGUI( it, NN ); |
414 | } | 467 | } |
415 | 468 | ||
416 | // cliecked on TAB to go to setup | 469 | // cliecked on TAB to go to setup |
417 | void EditConnection::SLOT_AlterTab( const QString & S ) { | 470 | void EditConnection::SLOT_AlterTab( const QString & S ) { |
418 | if( S == tr( "Setup" ) && Setup_FRM->isEnabled() ) { | 471 | if( S == tr( "Setup" ) && Setup_FRM->isEnabled() ) { |
419 | // switched to setup -> update CB and populate ws with | 472 | // switched to setup -> update CB and populate ws with |
420 | // forms for devices | 473 | // forms for devices |
421 | 474 | ||
422 | if( ! TmpIsValid ) { | 475 | if( ! TmpIsValid ) { |
423 | getTmpCollection(); | 476 | getTmpCollection(); |
424 | 477 | ||
425 | // clear CB and Ws | 478 | // clear CB and Ws |
426 | { QWidget * W; | 479 | { QWidget * W; |
427 | int i = 0; | 480 | int i = 0; |
428 | 481 | ||
429 | Devices_CB->clear(); | 482 | Devices_CB->clear(); |
430 | while( ( W = Setup_WS->widget( i ) ) ) { | 483 | while( ( W = Setup_WS->widget( i ) ) ) { |
431 | Setup_WS->removeWidget( W ); | 484 | Setup_WS->removeWidget( W ); |
432 | i ++; | 485 | i ++; |
433 | } | 486 | } |
434 | } | 487 | } |
435 | 488 | ||
436 | // update CB | 489 | // update CB |
437 | // and populate WidgetStack | 490 | // and populate WidgetStack |
438 | { ANetNodeInstance * NNI; | 491 | { ANetNodeInstance * NNI; |
439 | QListIterator<ANetNodeInstance> it(TmpCollection); | 492 | QListIterator<ANetNodeInstance> it(TmpCollection); |
440 | int i = 0; | 493 | int i = 0; |
441 | QWidget * W; | 494 | QWidget * W; |
@@ -494,84 +547,85 @@ void EditConnection::disableTree( QListViewItem * it, bool Mode ) { | |||
494 | // disable sbl's chidren | 547 | // disable sbl's chidren |
495 | it->setSelectable( Mode ); | 548 | it->setSelectable( Mode ); |
496 | if( AutoCollapse ) | 549 | if( AutoCollapse ) |
497 | it->setOpen( Mode ); | 550 | it->setOpen( Mode ); |
498 | disableTree( it->firstChild(), Mode ); | 551 | disableTree( it->firstChild(), Mode ); |
499 | it = it->nextSibling(); | 552 | it = it->nextSibling(); |
500 | } | 553 | } |
501 | } | 554 | } |
502 | 555 | ||
503 | // pah : ParentHasAlternatives | 556 | // pah : ParentHasAlternatives |
504 | void EditConnection::enablePath( QListViewItem * it, bool pha ) { | 557 | void EditConnection::enablePath( QListViewItem * it, bool pha ) { |
505 | while( it ) { | 558 | while( it ) { |
506 | ANetNode * NN; | 559 | ANetNode * NN; |
507 | NN = (*Mapping)[it]; | 560 | NN = (*Mapping)[it]; |
508 | if( NN ) { | 561 | if( NN ) { |
509 | if( pha ) { | 562 | if( pha ) { |
510 | bool doOn = ((QCheckListItem *)it)->isOn(); | 563 | bool doOn = ((QCheckListItem *)it)->isOn(); |
511 | // we are a checklistitem for sure | 564 | // we are a checklistitem for sure |
512 | it->setSelectable( TRUE ); | 565 | it->setSelectable( TRUE ); |
513 | if( AutoCollapse && ! doOn ) | 566 | if( AutoCollapse && ! doOn ) |
514 | it->setOpen( doOn ); | 567 | it->setOpen( doOn ); |
515 | if( doOn ) { | 568 | if( doOn ) { |
516 | // selected alternative | 569 | // selected alternative |
517 | enablePath( it->firstChild(), | 570 | enablePath( it->firstChild(), |
518 | NN->alternatives().size() > 1); | 571 | NN->alternatives().size() > 1); |
519 | } else { | 572 | } else { |
520 | // non-selected alternative | 573 | // non-selected alternative |
521 | disableTree( it->firstChild(), FALSE); | 574 | disableTree( it->firstChild(), FALSE); |
522 | } | 575 | } |
523 | } else { | 576 | } else { |
524 | // we are single subitem | 577 | // we are single subitem |
525 | it->setSelectable( TRUE ); | 578 | it->setSelectable( TRUE ); |
526 | it->setOpen( TRUE ); | 579 | it->setOpen( TRUE ); |
527 | enablePath( it->firstChild(), | 580 | enablePath( it->firstChild(), |
528 | NN->alternatives().size() > 1); | 581 | NN->alternatives().size() > 1); |
529 | } | 582 | } |
530 | } else { | 583 | } else { |
531 | // controller node | 584 | // controller node |
532 | it->setSelectable( TRUE ); | 585 | it->setSelectable( TRUE ); |
533 | it->setOpen( TRUE ); | 586 | it->setOpen( TRUE ); |
534 | enablePath( it->firstChild(), pha ); | 587 | enablePath( it->firstChild(), pha ); |
535 | } | 588 | } |
536 | it = it->nextSibling(); | 589 | it = it->nextSibling(); |
537 | } | 590 | } |
538 | } | 591 | } |
539 | 592 | ||
540 | // do we have a complete configuration (all needs are provided for ?) | 593 | // do we have a complete configuration (all needs are provided for ?) |
541 | bool EditConnection::haveCompleteConfig( QListViewItem * it ) { | 594 | bool EditConnection::haveCompleteConfig( QListViewItem * it ) { |
542 | if( it == 0 || ((QCheckListItem *)it)->isOn() ) { | 595 | |
543 | // check children | 596 | // check if all below this level is selected |
544 | it = (it) ? it->firstChild() : Nodes_LV->firstChild() ; | 597 | it = ( it ) ?it : Nodes_LV->firstChild(); |
545 | while ( it ) { | 598 | ANetNode *NN; |
546 | if( ((QCheckListItem *)it)->type() == | 599 | bool Found; |
547 | QCheckListItem::Controller ) { | 600 | |
548 | // child is controller -> has sub radio | 601 | while ( it ) { |
549 | // check if one radio is selected | 602 | NN = (*Mapping)[it]; |
550 | it = it->firstChild(); | 603 | if( NN == 0 ) { |
551 | while( it ) { | 604 | // this item is a controller -> |
552 | if( ((QCheckListItem *)it)->isOn() ) { | 605 | // has radio items as children -> |
553 | // this radio is selected -> go deeper | 606 | // find selected one |
554 | it = it->firstChild(); | 607 | it = it->firstChild(); |
555 | if( ! it ) { | 608 | Found = 0; |
556 | // was deepest level | 609 | while( it ) { |
557 | return 1; | 610 | if( ((QCheckListItem *)it)->isOn() ) { |
558 | } | 611 | Found = 1; |
559 | // do not bother to check other items | 612 | // go deeper |
560 | break; | 613 | it = it->firstChild(); |
561 | } | 614 | break; |
562 | it = it->nextSibling(); | ||
563 | } | ||
564 | if( ! it ) { | ||
565 | // no radio selected | ||
566 | return 0; | ||
567 | } | 615 | } |
568 | } else { | 616 | it = it->nextSibling(); |
569 | // check children | ||
570 | it = it->firstChild(); | ||
571 | } | 617 | } |
618 | |||
619 | if( ! Found ) { | ||
620 | return 0; // no not complete -> a radio should have been chkd | ||
621 | } | ||
622 | |||
623 | // it now contains selected radio | ||
624 | NN = (*Mapping)[it]; | ||
625 | } else { | ||
626 | // automatic selection | ||
627 | it = it->firstChild(); | ||
572 | } | 628 | } |
573 | // deepest level -> all is still OK | 629 | } |
574 | return 1; | 630 | return 1; |
575 | } // was not ON | ||
576 | return 0; | ||
577 | } | 631 | } |