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