]> SALOME platform Git repositories - tools/install.git/blob - src/SALOME_ProductsView.cxx
Salome HOME
update copyright notes (2007)
[tools/install.git] / src / SALOME_ProductsView.cxx
1 //  File      : SALOME_ProductsView.cxx
2 //  Created   : Thu Dec 18 12:01:00 2002
3 //  Author    : Vadim SANDLER, Open CASCADE SAS (vadim.sandler@opencascade.com)
4 //  Project   : SALOME
5 //  Module    : Installation Wizard
6 //  Copyright : 2002-2007 CEA
7
8 #include "SALOME_ProductsView.hxx"
9 #include <qstringlist.h>
10 #include <qregexp.h>
11
12 // ================================================================
13 /*!
14  *  ProductsViewItem::ProductsViewItem
15  *  Constructor
16  */
17 // ================================================================
18 ProductsViewItem::ProductsViewItem( ProductsView* parent, const QString& text, Type tt )
19      : QCheckListItem( parent, text, tt ) 
20 {
21 }
22 // ================================================================
23 /*!
24  *  ProductsViewItem::ProductsViewItem
25  *  Constructor
26  */
27 // ================================================================
28 ProductsViewItem::ProductsViewItem( QCheckListItem* parent, const QString& text, Type tt )
29      : QCheckListItem( parent, text, tt )
30 {
31 }
32 // ================================================================
33 /*!
34  *  ProductsViewItem::stateChange
35  *  Called when users switches item on/off
36  */
37 // ================================================================
38 void ProductsViewItem::stateChange( bool on ) {
39   QCheckListItem::stateChange( on );
40   ((ProductsView*)listView())->itemActivated( (QCheckListItem*)this );
41 }
42
43
44 // ================================================================
45 /*!
46  *  ProductsView::ProductsView
47  *  Constructor
48  */
49 // ================================================================
50 ProductsView::ProductsView( QWidget* parent ) : QListView( parent )
51 {
52   setRootIsDecorated( false );
53   addColumn( tr( "Product" ) );
54   addColumn( tr( "Version" ) );
55   setResizeMode( LastColumn );
56   setSorting( -1, false );
57 }
58 // ================================================================
59 /*!
60  *  ProductsView::addItem
61  *  Adds product item(s) into the list
62  */
63 // ================================================================
64 QCheckListItem* ProductsView::addItem( const QString& name, 
65                                        const QString& version, 
66                                        const QString& install, 
67                                        const QStringList& supported, 
68                                        const QString& script )
69 {
70   QCheckListItem* item = 0;
71   QListViewItem* lItem = this->firstChild();
72   while( lItem && lItem->nextSibling() )
73     lItem = lItem->nextSibling();
74   
75   if ( install.isNull() || install.isEmpty() ) {
76     item = new ProductsViewItem( this, name, QCheckListItem::CheckBox );
77     item->setText( 1, version );
78     item->setText( 2, script );
79     item->moveItem( lItem );
80   } 
81   else {
82     item = new ProductsViewItem( this, name, QCheckListItem::Controller );
83     item->setText( 1, version );
84     item->setText( 2, script );
85     
86     QCheckListItem* subitem  = 0;
87     subitem = new ProductsViewItem( item, tr( "not install" ), QCheckListItem::RadioButton );
88     subitem->setOn( true );
89     QCheckListItem* previtem = subitem;
90     subitem->moveItem( previtem );
91     for ( int i = 0; i < (int)supported.count(); i++ ) {
92       subitem = new ProductsViewItem( item, supported[ i ], QCheckListItem::RadioButton );
93       if ( supported[i] == install )
94         subitem->setOn( true );
95       subitem->moveItem( previtem );
96       previtem = subitem;
97     }
98     item->moveItem( lItem );
99     item->setOpen( true );
100   }
101   return item;
102 }
103 // ================================================================
104 /*!
105  *  ProductsView::eventFilter
106  *  Event filter - prevents collapsing/expanding of items
107  */
108 // ================================================================
109 bool ProductsView::eventFilter( QObject* o, QEvent* e )
110 {
111   if ( o == viewport() && e->type() == QEvent::MouseButtonDblClick )
112     return true;
113   return QListView::eventFilter( o, e );
114 }
115 // ================================================================
116 /*!
117  *  ProductsView::itemActivated
118  *  Emits signal when checkbox or radiobutton is switched
119  */
120 // ================================================================
121 void ProductsView::itemActivated( QCheckListItem* item ) {
122   emit itemToggled( item );
123 }
124 // ================================================================
125 /*!
126  *  ProductsView::isBinaries
127  *  Returns true if "install binaries" is on for the item
128  */
129 // ================================================================
130 bool ProductsView::isBinaries( QCheckListItem* item ) const
131 {
132   if ( item->childCount() > 0 && item->isEnabled() ) {
133     QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
134     while( subItem ) {
135       if ( subItem->isOn() )
136         return subItem->text() == tr( "install binaries" );
137       subItem = (QCheckListItem*)( subItem->nextSibling() );
138     }
139   }
140   return false;
141 }
142 // ================================================================
143 /*!
144  *  ProductsView::isSources
145  *  Returns true if "install sources" is on for the item
146  */
147 // ================================================================
148 bool ProductsView::isSources( QCheckListItem* item ) const
149 {
150   if ( item->childCount() > 0 && item->isEnabled() ) {
151     QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
152     while( subItem ) {
153       if ( subItem->isOn() )
154         return subItem->text() == tr( "install sources" );
155       subItem = (QCheckListItem*)( subItem->nextSibling() );
156     }
157   }
158   else {
159     return item->isOn();
160   }
161   return false;
162 }
163 // ================================================================
164 /*!
165  *  ProductsView::isNative
166  *  Returns true if "use native" is on for the item
167  */
168 // ================================================================
169 bool ProductsView::isNative( QCheckListItem* item ) const
170 {
171   if ( item->childCount() > 0 && item->isEnabled() ) {
172     QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
173     while( subItem ) {
174       if ( subItem->isOn() )
175         return subItem->text() == tr( "use native" );
176       subItem = (QCheckListItem*)( subItem->nextSibling() );
177     }
178   }
179   return false;
180 }
181 // ================================================================
182 /*!
183  *  ProductsView::isNone
184  *  Returns true if "not install" is on for the item
185  */
186 // ================================================================
187 bool ProductsView::isNone(  QCheckListItem* item ) const
188 {
189   return !isBinaries( item ) && !isSources( item ) && !isNative( item );
190 }
191 // ================================================================
192 /*!
193  *  ProductsView::setBinaries
194  *  Sets "install binaries" on for the item; if "binaries" item 
195  *  is absent, set "install sources" on if it is present 
196  */
197 // ================================================================
198 void ProductsView::setBinaries( QCheckListItem* item ) {
199   if ( item->childCount() > 0 ) {
200     QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
201     QCheckListItem* srcItem = 0;
202     QCheckListItem* nativeItem = 0;
203     while( subItem ) {
204       if ( subItem->text() == tr( "install sources" ) )
205         srcItem = subItem;
206       if ( subItem->text() == tr( "use native" ) )
207         nativeItem = subItem;
208       if ( subItem->text() == tr( "install binaries" ) ) {
209         subItem->setOn( true );
210         return;
211       }
212       subItem = (QCheckListItem*)( subItem->nextSibling() );
213     }
214     if ( nativeItem )           // prefer native item
215       nativeItem->setOn( true );
216     else if ( srcItem )
217       srcItem->setOn( true );
218   }
219   else {
220     item->setOn( true );
221   }
222 }
223 // ================================================================
224 /*!
225  *  ProductsView::setSources
226  *  Sets "install sources" on for the item; if "sources" item 
227  *  is absent, set "install binaries" on if it is present 
228  */
229 // ================================================================
230 void ProductsView::setSources( QCheckListItem* item )  {
231   if ( item->childCount() > 0 ) {
232     QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
233     QCheckListItem* binItem = 0;
234     QCheckListItem* nativeItem = 0;
235     while( subItem ) {
236       if ( subItem->text() == tr( "install binaries" ) )
237         binItem = binItem;
238       if ( subItem->text() == tr( "use native" ) )
239         nativeItem = subItem;
240       if ( subItem->text() == tr( "install sources" ) ) {
241         subItem->setOn( true );
242         return;
243       }
244       subItem = (QCheckListItem*)( subItem->nextSibling() );
245     }
246     if ( nativeItem )           // prefer native item
247       nativeItem->setOn( true );
248     else if ( binItem )
249       binItem->setOn( true );
250   }
251   else {
252     item->setOn( true );
253   }
254 }
255 // ================================================================
256 /*!
257  *  ProductsView::setNative
258  *  Sets "use native" on for the item; if "sources" item 
259  *  is absent, set "install binaries" on if it is present 
260  */
261 // ================================================================
262 void ProductsView::setNative( QCheckListItem* item )  {
263   if ( item->childCount() > 0 ) {
264     QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
265     QCheckListItem* binItem = 0;
266     QCheckListItem* srcItem = 0;
267     while( subItem ) {
268       if ( subItem->text() == tr( "install binaries" ) )
269         binItem = binItem;
270       if ( subItem->text() == tr( "install sources" ) )
271         srcItem = subItem;
272       if ( subItem->text() == tr( "use native" ) ) {
273         subItem->setOn( true );
274         return;
275       }
276       subItem = (QCheckListItem*)( subItem->nextSibling() );
277     }
278     if ( binItem )            // prefer binaries
279       binItem->setOn( true );
280     else if ( srcItem )
281       srcItem->setOn( true );
282   }
283   else {
284     item->setOn( true );
285   }
286 }
287 // ================================================================
288 /*!
289  *  ProductsView::setNone
290  *  Sets "not install" on for the item
291  */
292 // ================================================================
293 void ProductsView::setNone( QCheckListItem* item )  {
294   if ( item->childCount() > 0 ) {
295     QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
296     while( subItem ) {
297       if ( subItem->text() == tr( "not install" ) ) {
298         subItem->setOn( true );
299         return;
300       }
301       subItem = (QCheckListItem*)( subItem->nextSibling() );
302     }
303   }
304   else {
305     item->setOn( false );
306   }
307 }
308
309 // ================================================================
310 /*!
311  *  ProductsView::hasBinaries
312  *  Returns true if product supports "binaries" installation mode
313  */
314 // ================================================================
315 bool ProductsView::hasBinaries( QCheckListItem* item ) const
316 {
317   if ( item->childCount() > 0 ) {
318     QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
319     while( subItem ) {
320       if ( subItem->text() == tr( "install binaries" ) )
321         return true;
322       subItem = (QCheckListItem*)( subItem->nextSibling() );
323     }
324   }
325   return false;
326 }
327
328 // ================================================================
329 /*!
330  *  ProductsView::hasSources
331  *  Returns true if product supports "sources" installation mode
332  */
333 // ================================================================
334 bool ProductsView::hasSources( QCheckListItem* item ) const
335 {
336   if ( item->childCount() > 0 ) {
337     QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
338     while( subItem ) {
339       if ( subItem->text() == tr( "install sources" ) )
340         return true;
341       subItem = (QCheckListItem*)( subItem->nextSibling() );
342     }
343   }
344   return false;
345 }
346
347 // ================================================================
348 /*!
349  *  ProductsView::hasNative
350  *  Returns true if product supports "native" installation mode
351  */
352 // ================================================================
353 bool ProductsView::hasNative( QCheckListItem* item ) const
354 {
355   if ( item->childCount() > 0 ) {
356     QCheckListItem* subItem = (QCheckListItem*)( item->firstChild() );
357     while( subItem ) {
358       if ( subItem->text() == tr( "use native" ) )
359         return true;
360       subItem = (QCheckListItem*)( subItem->nextSibling() );
361     }
362   }
363   return false;
364 }
365
366 // ================================================================
367 /*!
368  *  ProductsView::setItemEnabled
369  *  Enable/disable item
370  */
371 // ================================================================
372 void ProductsView::setItemEnabled( QCheckListItem* item, const bool enable )
373 {
374   item->setEnabled( enable );
375   QListViewItem* subItem = item->firstChild();
376   while( subItem ) {
377     subItem->setEnabled( enable );
378     subItem = subItem->nextSibling();
379   }
380 }
381   
382 // ================================================================
383 /*!
384  *  ProductsView::findBinItem
385  *  Find bin item which corresponds to the src item
386  */
387 // ================================================================
388 QCheckListItem* ProductsView::findBinItem( const QString& srcName )
389 {
390   QString binName = srcName.lower().replace( QRegExp("src"), "bin" );
391   QCheckListItem* subItem = (QCheckListItem*)( firstChild() );
392   while( subItem ) {
393     if ( subItem->text().lower() == binName )
394       return subItem;
395     subItem = (QCheckListItem*)( subItem->nextSibling() );
396   }
397   return 0;
398 }
399