]> SALOME platform Git repositories - tools/install.git/blob - src/SALOME_InstallWizard.hxx
Salome HOME
Initial version
[tools/install.git] / src / SALOME_InstallWizard.hxx
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
7 //  $Header$ 
8
9 #include <qlineedit.h>
10 #include <qpushbutton.h>
11 #include <qradiobutton.h>
12 #include <qwidget.h>
13 #include <qlistview.h> 
14 #include <qlabel.h>
15 #include <qtextedit.h> 
16 #include <qprocess.h> 
17 #include <qlineedit.h> 
18 #include <qcheckbox.h>
19 #include <qheader.h>
20 #include <qsplitter.h>
21
22 #include <qmap.h>
23 #include <qstringlist.h> 
24 #include <qxml.h>
25
26 #include "InstallWizard.h"
27 #include "helpwindow.h"
28
29 /*! 
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 
36                  of this product
37      sizeTemp  - amount of disk space in Kbytes required for the temporary files
38 */
39 class Dependancies
40 {
41  public:
42   // default constructor, necessary for map
43   Dependancies() {}
44   // constructor
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 ) {}
47
48   // gets symbolic name
49   QString     getName() const         { return smbName;   }
50   // gets dependancies
51   QStringList getDependancies() const { return dependsOn; }
52   // gets disk space required
53   long        getSize(bool sources = false) const         { 
54     if (sources) 
55       return sizeSourcesTotal;
56     else
57       return sizeBinaryTotal;
58   }
59   // gets temporary disk space required
60   long        getTempSize() const     { return sizeTemp;  }
61
62  private:
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
68 };
69 typedef QMap<QCheckListItem*, Dependancies> MapProducts;
70
71 class MyListView;
72 class ProgressView;
73 /*!
74   Class SALOME_InstallWizard : Installation Wizard's main window
75 */
76 class SALOME_InstallWizard: public InstallWizard
77 {
78   Q_OBJECT
79     
80  public:
81   // constructor
82   SALOME_InstallWizard(QString aXmlFileName);
83   // destructor
84   virtual ~SALOME_InstallWizard( );
85
86   // event filter
87   bool eventFilter( QObject* object, QEvent* event );
88
89   // set dependancies
90   void setDependancies( QCheckListItem* item, Dependancies dep);
91
92  public slots:
93   // polishing of the widget
94   void polish();
95
96  protected:
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
104   void setupDirPage();
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
118   void checkDirs();
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
122   void launchScript(); 
123   // searches product listview item with given symbolic name 
124   QCheckListItem* findItem( const QString& sName );
125   // sets progress state to Aborted
126   void abort();
127   // clears and removes temporary directory
128   void clean();
129
130  protected slots:
131   // reject slot
132   void reject();
133   // accept slot
134   void accept();
135   
136  private slots:
137   // called when user moves from page to page
138   void pageChanged( const QString & mytitle);
139   // invokes Help window
140   void helpClicked();
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
146   void onStart();
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
152   void tryTerminate();
153   // kills installation process and quits application
154   void onCancel();
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
160   void onProdBtn();
161   // <More...> button slot
162   void onMoreBtn();
163   // <Launch Salome> button slot
164   void onLaunchSalome();
165
166   // QProcess slots:
167   // -->something was written to stdin
168   void wroteToStdin();
169   // -->something was written to stout
170   void readFromStdout();
171   // -->something was written to stderr
172   void readFromStderr();
173
174  private:
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"
184   // Widgets
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
192   // --> products page
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
208   // --> prestart page
209   QWidget*      prestartPage;   // page itself
210   QTextEdit*    choices;        // choice text view
211   // --> progress page
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
219   // --> readme page
220   QWidget*      readmePage;     // page itself
221   QTextEdit*    readme;         // Readme information window
222   QPushButton*  runSalomeBtn;   // <Launch Salome> buttnon
223 };
224
225 /*! 
226   Class MyListView : Products list view
227 */
228 class MyListView : public QListView 
229 {
230   Q_OBJECT
231   
232   // Class MyListViewItem: to define custom products list view item
233   class MyListViewItem : public QCheckListItem 
234   {
235   public:
236     // constructor
237     MyListViewItem( MyListView* parent, const QString& text, Type tt ) : QCheckListItem( parent, text, tt ) {}
238     // other constructor
239     MyListViewItem( QCheckListItem* parent, const QString& text, Type tt ) : QCheckListItem( parent, text, tt ) {}
240   protected:
241     // called when users switches item on/off
242     void stateChange( bool on ) {
243       QCheckListItem::stateChange( on );
244       ((MyListView*)listView())->itemActivated( (QCheckListItem*)this );
245     }
246   };
247
248 public:
249   // constructor
250   MyListView( QWidget* parent ) : QListView( parent )
251   {
252     setRootIsDecorated( false );
253     addColumn( "Products" );
254     addColumn( "Version" );
255     setResizeMode( LastColumn );
256     setSorting( -1, false );
257   }
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 )
264   {
265     QCheckListItem* item = 0;
266     QListViewItem* lItem = this->firstChild();
267     while( lItem && lItem->nextSibling() )
268       lItem = lItem->nextSibling();
269
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 );
275     } else {
276       item = new MyListViewItem( this, name, QCheckListItem::Controller );
277       item->setText( 1, version );
278       item->setText( 2, script );
279
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 );
290         previtem = subitem;
291       }
292       item->moveItem( lItem );
293       item->setOpen( true );
294     }
295     return item;
296   }
297   // event filter - prevents collapsing/expanding of items
298   bool eventFilter( QObject* o, QEvent* e )
299   {
300     if ( o == viewport() && e->type() == QEvent::MouseButtonDblClick )
301       return true;
302     return QListView::eventFilter(o, e);
303   }
304   // emits signal when checkbox or radiobutton is switched
305   void itemActivated( QCheckListItem* item ) {
306     emit itemToggled( item );
307   }
308   // returns true if "install binaries" is on for the item
309   bool isBinaries( QCheckListItem* item )
310   {
311     if ( item->childCount() > 0 ) {
312       // not SALOME sources, binaries or docs
313       QCheckListItem* subItem = (QCheckListItem*)(item->firstChild());
314       while( subItem ) {
315         if ( subItem->isOn() )
316           return subItem->text() == tr( "install binaries" );
317         subItem = (QCheckListItem*)(subItem->nextSibling());
318       }
319     }
320     // for SALOME sources, binaries and docs return false
321     return false;
322   }
323   // returns true if "install sources" is on for the item
324   bool isSources( QCheckListItem* item )
325   {
326     if ( item->childCount() > 0 ) {
327       // not SALOME sources, binaries or docs item
328       QCheckListItem* subItem = (QCheckListItem*)(item->firstChild());
329       while( subItem ) {
330         if ( subItem->isOn() )
331           return subItem->text() == tr( "install sources" );
332         subItem = (QCheckListItem*)(subItem->nextSibling());
333       }
334     }
335     else {
336       // for SALOME sources, binaries or docs item return true if checked
337       return item->isOn();
338     }
339     return false;
340   }
341   // returns true if "use native" is on for the item
342   bool isNative( QCheckListItem* item )
343   {
344     if ( item->childCount() > 0 ) {
345       // not SALOME sources, binaries or docs item
346       QCheckListItem* subItem = (QCheckListItem*)(item->firstChild());
347       while( subItem ) {
348         if ( subItem->isOn() )
349           return subItem->text() == tr( "use native" );
350         subItem = (QCheckListItem*)(subItem->nextSibling());
351       }
352     }
353     return false;
354   }
355   // returns true if "not install" is on for the item
356   bool isNone(  QCheckListItem* item )
357   {
358     return !isBinaries( item ) && !isSources( item ) && !isNative( item );
359   }
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;
367       while( subItem ) {
368         if ( subItem->text() == tr( "install sources" ) )
369           srcItem = subItem;
370         if ( subItem->text() == tr( "use native" ) )
371           nativeItem = subItem;
372         if ( subItem->text() == tr( "install binaries" ) ) {
373           subItem->setOn( true );
374           return;
375         }
376         subItem = (QCheckListItem*)(subItem->nextSibling());
377       }
378       if ( srcItem )
379         srcItem->setOn( true );
380       if ( nativeItem )
381         nativeItem->setOn( true );
382     }
383     else {
384       // for SALOME sources, binaries and docs items set true
385       item->setOn( true );
386     }
387   }
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;
394       while( subItem ) {
395         if ( subItem->text() == tr( "install binaries" ) )
396           binItem = binItem;
397         if ( subItem->text() == tr( "install sources" ) ) {
398           subItem->setOn( true );
399           return;
400         }
401         subItem = (QCheckListItem*)(subItem->nextSibling());
402       }
403       if ( binItem )
404         binItem->setOn( true );
405     }
406     else {
407       // for SALOME sources, binaries and docs items set true
408       item->setOn( true );
409     }
410   }
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;
417       while( subItem ) {
418         if ( subItem->text() == tr( "install binaries" ) )
419           binItem = binItem;
420         if ( subItem->text() == tr( "use native" ) ) {
421           subItem->setOn( true );
422           return;
423         }
424         subItem = (QCheckListItem*)(subItem->nextSibling());
425       }
426       if ( binItem )
427         binItem->setOn( true );
428     }
429     else {
430       // for SALOME sources, binaries and docs items set true
431       item->setOn( true );
432     }
433   }
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());
439       while( subItem ) {
440         if ( subItem->text() == tr( "not install" ) ) {
441           subItem->setOn( true );
442           return;
443         }
444         subItem = (QCheckListItem*)(subItem->nextSibling());
445       }
446     }
447     else {
448       // for SALOME sources, binaries and docs items set false
449       item->setOn( false );
450     }
451   }
452 signals:
453   // emitted when checkbox or radiobutton is switched
454   void itemToggled( QCheckListItem* item );
455 };
456
457 /*!
458   Class ProgressViewItem: Progress list view item
459 */
460 enum Status { Waiting, Processing, Completed, Aborted };
461 class ProgressView;
462 class ProgressViewItem : public QListViewItem
463 {
464 public:
465   // constructor
466   ProgressViewItem( ProgressView* parent, 
467                     QString       productName, 
468                     const QString installType, 
469                     const QString scriptName, 
470                     Status        status = Waiting );
471   
472   // sets product status
473   void    setStatus( Status status );
474   // gets product status
475   Status  getStatus()  const { return myStatus; }
476   // gets product name
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 ); }
482
483 protected:
484   // paints cell of the item
485   void paintCell( QPainter* painter, const QColorGroup& cg, int column, int width, int align );
486
487 private:
488   Status  myStatus;       // status
489   QString myScript;       // alias
490 };
491
492 /*!
493   Class ProgressView: Progress list view
494 */
495 class ProgressView : public QListView
496 {
497 public:
498   // constructor
499   ProgressView( QWidget* parent );
500
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;  }
506
507   // adds product item
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 );
517
518 protected:
519   // finds the item by the product name
520   ProgressViewItem* findItem( const QString product );
521
522 private:
523   QColor myWaitingColor;     // 'Waiting' color
524   QColor myProcessingColor;  // 'Processing' color
525   QColor myCompletedColor;   // 'Completed' color
526 };
527
528 /*!
529   Class StructureParser: parses xml-description file and populates the list of the products
530 */
531 class StructureParser: public QXmlDefaultHandler
532 {
533 public:
534   // constructor
535   StructureParser();
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 );
546
547 private:
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
552 };