1 // File : SALOME_InstallWizard.h
2 // Created : Thu Dec 18 12:01:00 2002
3 // Author : Vadim SANDLER
4 // Project : SALOME Professional
5 // Module : InstallWizard
6 // Copyright : 2003 CEA/DEN, EDF R&D
10 #include <qpushbutton.h>
11 #include <qradiobutton.h>
13 #include <qlistview.h>
15 #include <qtextedit.h>
17 #include <qlineedit.h>
18 #include <qcheckbox.h>
20 #include <qsplitter.h>
23 #include <qstringlist.h>
26 #include "InstallWizard.h"
27 #include "helpwindow.h"
30 Class Dependancies : Products info
31 This class stores all product dependancies for correct work of installation procedure
32 smbName - parameter for launching install shell script (e.g. cas for CASCADE4.0).
33 dependsOn - list of products needed for correct installation of product
34 (e.g tcl is checked during installation of CASCADE 4).
35 sizeTotal - amount of disk space in Kbytes required for installation
37 sizeTemp - amount of disk space in Kbytes required for the temporary files
42 // default constructor, necessary for map
45 Dependancies( const QString& name, const QStringList& depend, const long Binsize, const long Sourcessize, const long tempsize )
46 : smbName( name ), dependsOn( depend ), sizeSourcesTotal( Sourcessize ), sizeBinaryTotal( Binsize ), sizeTemp( tempsize ) {}
49 QString getName() const { return smbName; }
51 QStringList getDependancies() const { return dependsOn; }
52 // gets disk space required
53 long getSize(bool sources = false) const {
55 return sizeSourcesTotal;
57 return sizeBinaryTotal;
59 // gets temporary disk space required
60 long getTempSize() const { return sizeTemp; }
63 QString smbName; // symbolic name
64 QStringList dependsOn; // prerequisites list
65 long sizeSourcesTotal; // disk space required
66 long sizeBinaryTotal; // disk space required
67 long sizeTemp; // disk space for temporary files required
69 typedef QMap<QCheckListItem*, Dependancies> MapProducts;
74 Class SALOME_InstallWizard : Installation Wizard's main window
76 class SALOME_InstallWizard: public InstallWizard
82 SALOME_InstallWizard(QString aXmlFileName);
84 virtual ~SALOME_InstallWizard( );
87 bool eventFilter( QObject* object, QEvent* event );
90 void setDependancies( QCheckListItem* item, Dependancies dep);
93 // polishing of the widget
97 // close event handler
98 void closeEvent( QCloseEvent* ce );
99 // creates introduction page
100 void setupIntroPage();
101 // creates products page
102 void setupProductsPage();
103 // creates directories page
105 // creates prestart page
106 void setupCheckPage();
107 // creates progress page
108 void setupProgressPage();
109 // creates readme page
110 void setupReadmePage();
111 // displays choice info
112 void showChoiceInfo();
113 // validates page when <Next> button is clicked
114 bool acceptData( const QString& );
115 // calculates disk space required for the installation
116 void checkSize( long* totSize = 0, long* tempSize = 0 );
117 // checks directories validity
119 // sets the product and all products this one depends on to be checked ( recursively )
120 void setProductOn( QCheckListItem* item, int install = 1 );
121 // runs installation script
123 // searches product listview item with given symbolic name
124 QCheckListItem* findItem( const QString& sName );
125 // sets progress state to Aborted
127 // clears and removes temporary directory
137 // called when user moves from page to page
138 void pageChanged( const QString & mytitle);
139 // invokes Help window
141 // invokes directory selection dialog box
142 void browseDirectory();
143 // called when directory path (target or temp) is changed
144 void directoryChanged( const QString& text );
145 // <Start> button's slot - runs installation
147 // called when users tries to pass parameters for the script
148 void onReturnPressed();
149 // callback function - as response for the script finishing
150 void productInstalled();
151 // called when <Cancel> button is clicked during installation script running
153 // kills installation process and quits application
155 // called when selection is changed in the products list view
156 void onSelectionChanged( QListViewItem* );
157 // called when user checks/unchecks any product item
158 void onItemToggled( QCheckListItem* );
159 // <Select Sources>, <Select Binaries>, <Unselect All> buttons slot
161 // <More...> button slot
163 // <Launch Salome> button slot
164 void onLaunchSalome();
167 // -->something was written to stdin
169 // -->something was written to stout
170 void readFromStdout();
171 // -->something was written to stderr
172 void readFromStderr();
175 HelpWindow* helpWindow; // help window
176 QProcess* shellProcess; // shell process (install script)
177 MapProducts productsMap; // products info (name, dependancies, disk space )
178 QStringList toInstall; // list of products being installed
179 QString xmlFileName; // xml file
180 bool moreMode; // advanced mode flag
181 QWidget* previousPage; // previous page
182 QString tmpCreated; // created temporary directory
183 bool exitConfirmed; // flag: "Exit confirmed"
185 // --> introduction page
186 QWidget* introPage; // page itself
187 QLabel* logoLab; // SALOME PRO logo
188 QLabel* versionLab; // vesrsion info
189 QLabel* copyrightLab; // copyright info
190 QLabel* licenseLab; // license info
191 QLabel* info; // program info
193 QWidget* productsPage; // page itself
194 QLineEdit* targetFolder; // target directory for installing of products
195 QPushButton* targetBtn; // browse target directory button
196 QLineEdit* tempFolder; // directory for the temporary files: /tmp by default
197 QPushButton* tempBtn; // browse temp directory button
198 QLabel* requiredSize; // <Total disk space required> label
199 QLabel* requiredTemp; // <Space required for temporary files> label
200 QPushButton* moreBtn; // <More...> button
201 QWidget* moreBox; // container for the <More...> mode widgets
202 MyListView* productsView; // products list view
203 QTextBrowser* productsInfo; // products info box
204 QCheckBox* prerequisites; // <Auto check prerequisites products> checkbox
205 QPushButton* selectSrcBtn; // <Select Sources> button - NOT USED CURRENTLY
206 QPushButton* selectBinBtn; // <Select Binaries> button - NOT USED CURRENTLY
207 QPushButton* unselectBtn; // <Unselect All> button
209 QWidget* prestartPage; // page itself
210 QTextEdit* choices; // choice text view
212 QWidget* progressPage; // page itself
213 QSplitter* splitter; // splitter window
214 QTextEdit* installInfo; // information about running installation scripts
215 QLabel* parametersLab; // answer field's label
216 QLineEdit* passedParams; // user can pass data to running script
217 QTextEdit* installProgress;// contains information about progress of installing selected products
218 ProgressView* progressView; // displays information about progress of installing selected products
220 QWidget* readmePage; // page itself
221 QTextEdit* readme; // Readme information window
222 QPushButton* runSalomeBtn; // <Launch Salome> buttnon
226 Class MyListView : Products list view
228 class MyListView : public QListView
232 // Class MyListViewItem: to define custom products list view item
233 class MyListViewItem : public QCheckListItem
237 MyListViewItem( MyListView* parent, const QString& text, Type tt ) : QCheckListItem( parent, text, tt ) {}
239 MyListViewItem( QCheckListItem* parent, const QString& text, Type tt ) : QCheckListItem( parent, text, tt ) {}
241 // called when users switches item on/off
242 void stateChange( bool on ) {
243 QCheckListItem::stateChange( on );
244 ((MyListView*)listView())->itemActivated( (QCheckListItem*)this );
250 MyListView( QWidget* parent ) : QListView( parent )
252 setRootIsDecorated( false );
253 addColumn( "Products" );
254 addColumn( "Version" );
255 setResizeMode( LastColumn );
256 setSorting( -1, false );
258 // adds product item(s) into the list
259 QCheckListItem* addItem( const QString& name,
260 const QString& version,
261 const QString& install,
262 const QStringList& supported,
263 const QString& script )
265 QCheckListItem* item = 0;
266 QListViewItem* lItem = this->firstChild();
267 while( lItem && lItem->nextSibling() )
268 lItem = lItem->nextSibling();
270 if ( install.isNull() || install.isEmpty() ) {
271 item = new MyListViewItem( this, name, QCheckListItem::CheckBox );
272 item->setText( 1, version );
273 item->setText( 2, script );
274 item->moveItem( lItem );
276 item = new MyListViewItem( this, name, QCheckListItem::Controller );
277 item->setText( 1, version );
278 item->setText( 2, script );
280 QCheckListItem* subitem = 0;
281 subitem = new MyListViewItem( item, tr( "not install" ), QCheckListItem::RadioButton );
282 subitem->setOn( true );
283 QCheckListItem* previtem = subitem;
284 subitem->moveItem( previtem );
285 for ( int i = 0; i < (int)supported.count(); i++ ) {
286 subitem = new MyListViewItem( item, supported[ i ], QCheckListItem::RadioButton );
287 if ( supported[i] == install )
288 subitem->setOn( true );
289 subitem->moveItem( previtem );
292 item->moveItem( lItem );
293 item->setOpen( true );
297 // event filter - prevents collapsing/expanding of items
298 bool eventFilter( QObject* o, QEvent* e )
300 if ( o == viewport() && e->type() == QEvent::MouseButtonDblClick )
302 return QListView::eventFilter(o, e);
304 // emits signal when checkbox or radiobutton is switched
305 void itemActivated( QCheckListItem* item ) {
306 emit itemToggled( item );
308 // returns true if "install binaries" is on for the item
309 bool isBinaries( QCheckListItem* item )
311 if ( item->childCount() > 0 ) {
312 // not SALOME sources, binaries or docs
313 QCheckListItem* subItem = (QCheckListItem*)(item->firstChild());
315 if ( subItem->isOn() )
316 return subItem->text() == tr( "install binaries" );
317 subItem = (QCheckListItem*)(subItem->nextSibling());
320 // for SALOME sources, binaries and docs return false
323 // returns true if "install sources" is on for the item
324 bool isSources( QCheckListItem* item )
326 if ( item->childCount() > 0 ) {
327 // not SALOME sources, binaries or docs item
328 QCheckListItem* subItem = (QCheckListItem*)(item->firstChild());
330 if ( subItem->isOn() )
331 return subItem->text() == tr( "install sources" );
332 subItem = (QCheckListItem*)(subItem->nextSibling());
336 // for SALOME sources, binaries or docs item return true if checked
341 // returns true if "use native" is on for the item
342 bool isNative( QCheckListItem* item )
344 if ( item->childCount() > 0 ) {
345 // not SALOME sources, binaries or docs item
346 QCheckListItem* subItem = (QCheckListItem*)(item->firstChild());
348 if ( subItem->isOn() )
349 return subItem->text() == tr( "use native" );
350 subItem = (QCheckListItem*)(subItem->nextSibling());
355 // returns true if "not install" is on for the item
356 bool isNone( QCheckListItem* item )
358 return !isBinaries( item ) && !isSources( item ) && !isNative( item );
360 // sets "install binaries" on for the item; if "binaries" item is absent, set "install sources" on if it is present
361 void setBinaries( QCheckListItem* item ) {
362 if ( item->childCount() > 0 ) {
363 // not SALOME sources, binaries or docs item
364 QCheckListItem* subItem = (QCheckListItem*)(item->firstChild());
365 QCheckListItem* srcItem = 0;
366 QCheckListItem* nativeItem = 0;
368 if ( subItem->text() == tr( "install sources" ) )
370 if ( subItem->text() == tr( "use native" ) )
371 nativeItem = subItem;
372 if ( subItem->text() == tr( "install binaries" ) ) {
373 subItem->setOn( true );
376 subItem = (QCheckListItem*)(subItem->nextSibling());
379 srcItem->setOn( true );
381 nativeItem->setOn( true );
384 // for SALOME sources, binaries and docs items set true
388 // sets "install sources" on for the item; if "sources" item is absent, set "install binaries" on if it is present
389 void setSources( QCheckListItem* item ) {
390 if ( item->childCount() > 0 ) {
391 // not SALOME sources, binaries or docs item
392 QCheckListItem* subItem = (QCheckListItem*)(item->firstChild());
393 QCheckListItem* binItem = 0;
395 if ( subItem->text() == tr( "install binaries" ) )
397 if ( subItem->text() == tr( "install sources" ) ) {
398 subItem->setOn( true );
401 subItem = (QCheckListItem*)(subItem->nextSibling());
404 binItem->setOn( true );
407 // for SALOME sources, binaries and docs items set true
411 // sets "use native" on for the item; if "sources" item is absent, set "install binaries" on if it is present
412 void setNative( QCheckListItem* item ) {
413 if ( item->childCount() > 0 ) {
414 // not SALOME sources, binaries or docs item
415 QCheckListItem* subItem = (QCheckListItem*)(item->firstChild());
416 QCheckListItem* binItem = 0;
418 if ( subItem->text() == tr( "install binaries" ) )
420 if ( subItem->text() == tr( "use native" ) ) {
421 subItem->setOn( true );
424 subItem = (QCheckListItem*)(subItem->nextSibling());
427 binItem->setOn( true );
430 // for SALOME sources, binaries and docs items set true
434 // sets "not install" on for the item
435 void setNone( QCheckListItem* item ) {
436 if ( item->childCount() > 0 ) {
437 // not SALOME sources, binaries or docs item
438 QCheckListItem* subItem = (QCheckListItem*)(item->firstChild());
440 if ( subItem->text() == tr( "not install" ) ) {
441 subItem->setOn( true );
444 subItem = (QCheckListItem*)(subItem->nextSibling());
448 // for SALOME sources, binaries and docs items set false
449 item->setOn( false );
453 // emitted when checkbox or radiobutton is switched
454 void itemToggled( QCheckListItem* item );
458 Class ProgressViewItem: Progress list view item
460 enum Status { Waiting, Processing, Completed, Aborted };
462 class ProgressViewItem : public QListViewItem
466 ProgressViewItem( ProgressView* parent,
468 const QString installType,
469 const QString scriptName,
470 Status status = Waiting );
472 // sets product status
473 void setStatus( Status status );
474 // gets product status
475 Status getStatus() const { return myStatus; }
477 QString getProduct() const { return text( 0 ); }
478 // gets product script
479 QString getScript() const { return myScript; }
480 // gets type of the installation: 'binaries', 'source', 'native' or 'not install'
481 QString getInstallType() const { return text( 1 ); }
484 // paints cell of the item
485 void paintCell( QPainter* painter, const QColorGroup& cg, int column, int width, int align );
488 Status myStatus; // status
489 QString myScript; // alias
493 Class ProgressView: Progress list view
495 class ProgressView : public QListView
499 ProgressView( QWidget* parent );
501 // sets/gets status colors
502 void setColors( QColor wColor, QColor pColor, QColor cColor );
503 QColor getWaitingColor() { return myWaitingColor; }
504 QColor getProcessingColor() { return myProcessingColor; }
505 QColor getCompletedColor() { return myCompletedColor; }
508 void addProduct( const QString smbName, const QString type, const QString product );
509 // finds the first item with given status
510 QString findStatus( Status status );
511 // sets new status for the product item
512 void setStatus( const QString product, Status status );
513 // scrolls the view to make item visible if necessary
514 void ensureVisible( const QString product );
515 // gets the product script
516 QString getScript( const QString product );
519 // finds the item by the product name
520 ProgressViewItem* findItem( const QString product );
523 QColor myWaitingColor; // 'Waiting' color
524 QColor myProcessingColor; // 'Processing' color
525 QColor myCompletedColor; // 'Completed' color
529 Class StructureParser: parses xml-description file and populates the list of the products
531 class StructureParser: public QXmlDefaultHandler
536 // begins parsing of the xml dom-element
537 bool startElement( const QString&, const QString&, const QString& ,
538 const QXmlAttributes& );
539 // finishes parsing of the xml dom-element of the xml dom-element
540 bool endElement( const QString&, const QString&, const QString& );
541 // set control widgets
542 void setListView ( MyListView* view );
543 void setWizard ( SALOME_InstallWizard* wiz );
544 void setTargetDir( QLineEdit* dir );
545 void setTempDir ( QLineEdit* dir );
548 MyListView* tree; // products list view
549 SALOME_InstallWizard* wizard; // Salome Pro installation wizard's main window
550 QLineEdit* targetdir; // target directory widget
551 QLineEdit* tempdir; // temp directory widget