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