Salome HOME
2d3ff6c919660d0bc51c8272b0dd01480ce63f86
[tools/install.git] / src / SALOME_InstallWizard.hxx
1 //  File      : SALOME_InstallWizard.hxx
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-2012 CEA
7
8 #ifndef __SALOME_InstallWizard
9 #define __SALOME_InstallWizard
10
11 #include "InstallWizard.h"
12
13 #include <qmap.h>
14 #include <qvaluelist.h>
15 #include <qstringlist.h> 
16
17 class QLineEdit;
18 class QPushButton;
19 class QListViewItem;
20 class QCheckListItem;
21 class QLabel;
22 class QTextEdit;
23 class QTextBrowser;
24 class QProcess;
25 class QCheckBox;
26 class QSplitter;
27 class QMyCheckBox;
28 class ProcessThread;
29 class ProductsView;
30 class ProgressView;
31 class HelpWindow;
32 class InstallInfo;
33 class QButton;
34 class QRadioButton;
35 class QButtonGroup;
36
37 // This enum describes the possible types of the SALOME installation
38 enum InstallationType { Binaries, Sources, Compile };
39 // This enum describes the possible states of a tristate parameter
40 enum BoolTristate { False, True, NotDefined };
41
42 /*! 
43   Class Dependancies : Products info
44   This class stores all product dependancies for correct work of installation procedure
45 */
46 class Dependancies
47 {
48  public:
49   // default constructor, necessary for map
50   Dependancies() {}
51   // constructor
52   Dependancies( const QString&     name, 
53                 const QStringList& depend, 
54                 const long         Binsize,  
55                 const long         Sourcessize, 
56                 const long         SrcBuildsize, 
57                 const long         tempsize, 
58                 const QString&     vers = QString::null,
59                 const QString&     descr = QString::null,
60                 const QString&     tp = QString::null,
61                 bool               pickup = false,
62                 BoolTristate       woGui = NotDefined )
63     : smbName( name ), 
64       dependsOn( depend ), 
65       sizeBinaryTotal( Binsize ), 
66       sizeSourcesTotal( Sourcessize ), 
67       sizeSrcBuildTotal( SrcBuildsize ), 
68       sizeTemp( tempsize ),
69       version( vers ),
70       description( descr ),
71       type( tp ),
72       pickupEnv( pickup ),
73       woGuiMode( woGui ) {}
74
75   // gets symbolic name
76   QString     getName() const         { return smbName;   }
77   // gets dependancies
78   QStringList getDependancies() const { return dependsOn; }
79   // gets disk space required
80   long        getSize( InstallationType instType ) const 
81   { 
82     return instType == Binaries ? sizeBinaryTotal : 
83       instType == Sources ? sizeSourcesTotal : 
84       sizeSrcBuildTotal;
85   }
86   // gets temporary disk space required
87   long        getTempSize( InstallationType instType ) const     
88   { 
89     return ( instType == Binaries ? 0 : instType == Sources ? 0 : sizeTemp );
90   }
91   // gets product's version
92   QString     getVersion() const      { return version; }
93   // gets product's description
94   QString     getDescription() const  { return description; }
95   // gets product's type
96   QString     getType() const         { return type; }
97   // returns true if this product needs to pick-up environment
98   bool        pickUpEnvironment()     { return pickupEnv; }
99   // returns true if this product supports installation without GUI mode
100   BoolTristate supportWoGuiMode()     { return woGuiMode; }
101
102  private:
103   QString     smbName;           // symbolic name
104   QStringList dependsOn;         // prerequisites list
105   long        sizeBinaryTotal;   // disk space for binaries required
106   long        sizeSourcesTotal;  // disk space for sources required
107   long        sizeSrcBuildTotal; // disk space for compiled sources required
108   long        sizeTemp;          // disk space for temporary files required
109   QString     version;           // product's version
110   QString     description;       // product's description
111   QString     type;              // product's type (salome sources, binaries or prerequisite)
112   bool        pickupEnv;        // "Pick-up environment" flag
113   BoolTristate woGuiMode;        // support of installation without GUI flag
114 };
115
116 /*! 
117   Class Button : Operation button info
118   This class stores information about the custom operation buttons which appear on
119   the <Finish> page of the Install Wizard.
120 */
121 class Button
122 {
123  public:
124   // default constructor, required for list
125   Button() : myButton( 0 ) {}
126   // constructor
127   Button( const QString& label, const QString& tooltip, const QString& script )
128     : myLabel( label ), myTootip( tooltip ), myScript( script ), myButton( 0 ) {}
129
130   // set operation button
131   void setButton( QButton* btn ) { myButton = btn; }
132
133   // get label
134   QString  label()  const { return myLabel;  } 
135   // get tooltip
136   QString  tootip() const { return myTootip; }
137   // get script name
138   QString  script() const { return myScript; }
139   // get operation button
140   QButton* button() const { return myButton; }
141
142  private:
143   QString  myLabel;    // button label
144   QString  myTootip;   // button tooltip
145   QString  myScript;   // operation script
146   QButton* myButton;   // operation button
147 };
148
149 typedef QMap<QCheckListItem*, Dependancies> MapProducts;
150 typedef QValueList<Button>                  ButtonList;
151 typedef QMap<QString, QString>              MapXmlFiles;
152 typedef QMap<QString, BoolTristate>         MapAttrStates;
153
154 /*!
155   Class SALOME_InstallWizard : Installation Wizard's main window
156 */
157 class SALOME_InstallWizard: public InstallWizard
158 {
159   Q_OBJECT
160     
161  public:
162   // constructor
163   SALOME_InstallWizard( const QString& aXmlFileName = QString::null,
164                         const QString& aTargetDir   = QString::null,
165                         const QString& aTmpDir      = QString::null,
166                         const bool     aForceSrc    = false,
167                         const bool     aSingleDir   = false );
168   // destructor
169   virtual ~SALOME_InstallWizard( );
170
171   // get base platform to install binaries package
172   QString getBasePlatform();
173   // get current platform
174   static QStringList currentPlatform();
175   // get application root dir
176   static QString     rootDirPath();
177
178   // get binaries path
179   QString getBinPath() const { return binPath; }
180   // get sources path
181   QString getSrcPath() const { return srcPath; }
182   // get platform binaries path
183   QString getPlatformBinPath( const QString& ) const;
184
185   // get map of supported platforms and corresponding XML files
186   MapXmlFiles getXmlMap( const QString& aXmlFileName = QString::null );
187   // check/get XML file and current platform
188   void getXmlAndPlatform();
189
190   // event filter
191   bool eventFilter( QObject* object, QEvent* event );
192
193   // set dependancies
194   void setDependancies( QCheckListItem* item, Dependancies dep);
195
196   // executes some actions after finish of installation process (successful or not)
197   void doPostActions( const QString& btnText,
198                       const QString& btnAboutInfo );
199
200   // add button for the <Finish> page
201   void addFinishButton( const QString& label, 
202                         const QString& tooltip, 
203                         const QString& script,
204                         bool toClear = false );
205
206   // set version
207   void setVersion( const QString& version ) { myVersion = version; }
208   // set caption
209   void setCaption( const QString& caption ) { myCaption = caption; updateCaption(); }
210   // set copyright
211   void setCopyright( const QString& copyright ) { myCopyright = copyright; }
212   // set license
213   void setLicense( const QString& license ) { myLicense = license; }
214   // set list of optional libraries
215   void setOptionalLibs( const QString& optlibs ) { myOptLibs = QStringList::split( ",", optlibs ); }
216
217   // get version
218   QString getVersion() { return myVersion; }
219   // get caption
220   QString getCaption() { return myCaption; }
221   // get copyright
222   QString getCopyright() { return myCopyright; }
223   // get license
224   QString getLicense() { return myLicense; }
225   // get list of optional libraries
226   QStringList getOptionalLibs() { return myOptLibs; }
227   // get platform
228   QString getPlatform() { return !refPlatform.isEmpty() ? refPlatform : curPlatform; }
229   // get corresponding XML file
230   QString getXmlFile( const QString& platform ) {
231     return (platformsMap.find( platform ) != platformsMap.end() ) ? 
232       platformsMap[ platform ] : 
233       QString("");
234   }
235   // get InstallWizard's name
236   QString getIWName() { return myIWName; }
237
238   // process validation event (<val> is validation code)
239   void processValidateEvent( const int val, void* data );
240   // get private installation type
241   InstallationType getInstType() { return installType; };
242
243  public slots:
244   // polishing of the widget
245   void polish();
246   
247   // save install log to file
248   void saveLog();
249
250  protected:
251   // updates caption according to the current page number
252   void updateCaption();
253   // close event handler
254   void closeEvent( QCloseEvent* ce );
255   // creates introduction page
256   void setupIntroPage();   
257   // create installation types page
258   void setupTypePage();
259   // create platforms page
260   void setupPlatformPage();
261   // create directories page
262   void setupDirPage();
263   // creates products page
264   void setupProductsPage();
265   // creates prestart page
266   void setupCheckPage();
267   // creates progress page
268   void setupProgressPage();
269   // creates readme page
270   void setupReadmePage();
271   // displays choice info
272   void showChoiceInfo();
273   // validates page when <Next> button is clicked
274   bool acceptData( const QString& );
275   // calculates disk space required for the installation, returns true if any product selected to be installed (src, bin or native)
276   bool checkSize( long* totSize = 0, long* tempSize = 0 );
277   // checks products page validity (directories and products selection)
278   void checkProductPage();
279   // sets the product and all products this one depends on to be checked
280   void setPrerequisites( QCheckListItem* item );
281   // unsets all products which depend of unchecked product ( recursively )
282   void unsetPrerequisites( QCheckListItem* item );
283   // runs installation script
284   void launchScript(); 
285   // searches product listview item with given symbolic name 
286   QCheckListItem* findItem( const QString& sName );
287   // sets progress state to Aborted
288   void abort();
289   // clears and (optionally) removes temporary directory
290   void clean(bool rmDir = false);
291   // Update GUI and check installation errors
292   void completeInstallation();
293   // Run the modification of SALOME *.la files
294   void runModifyLaFiles();
295   // Run the Fortran libraries checking
296   void runCheckFLib();
297
298  protected slots:
299   // reject slot
300   void reject();
301   // accept slot
302   void accept();
303   
304  private slots:
305   // called when user moves from page to page
306   void pageChanged( const QString & mytitle);
307   // called when user selected either installation type or installation platform
308   void onButtonGroup( int index );
309   // invokes Help window
310   void helpClicked();
311   // invokes directory selection dialog box
312   void browseDirectory();
313   // called when directory path (target or temp) is changed
314   void directoryChanged( const QString& text );
315   // <Start> button's slot - runs installation
316   void onStart();
317   // called when users tries to pass parameters for the script
318   void onReturnPressed();
319   // callback function - as response for the script finishing
320   void productInstalled();
321   // called when <Cancel> button is clicked during installation script running
322   void tryTerminate();
323   // kills installation process and quits application
324   void onCancel();
325   // called when selection is changed in the products list view
326   void onSelectionChanged();
327   // called when user checks/unchecks any product item
328   void onItemToggled( QCheckListItem* );
329   // <Installation with GUI> check-box slot
330   void onInstallGuiBtn();
331   // <More...> button slot
332   void onMoreBtn();
333   // Slot to update 'Available disk space' field
334   void updateAvailableSpace();
335   // Slot to take result of modification SALOME *.la files
336   void checkModifyLaResult();
337   // Slot to take result of Fortran libraries checking
338   void checkFLibResult();
339   // Slot to update 'Size' column for modules and prerequisites
340   void updateSizeColumn();
341
342   // <Finish> page buttons slot
343   void onFinishButton();
344
345   // <About> button slot
346   void onAbout();
347
348   // QProcess slots:
349   // -->something was written to stdin
350   void wroteToStdin();
351   // -->something was written to stout
352   void readFromStdout();
353   // -->something was written to stderr
354   void readFromStderr();
355   // -->stop installation process if there is an error in stderr
356   void manageInstProc();
357
358  private:
359   QString          myIWName;       // Installation Wizard's name
360   QString          myVersion;      // version info
361   QString          myCaption;      // application name
362   QString          myCopyright;    // copyright info 
363   QString          myLicense;      // license info
364   QString          myTargetPath;   // target directory path
365   QString          myTmpPath;      // temporary directory path
366   QStringList      myOptLibs;      // list of optional libraries
367   
368   HelpWindow*      helpWindow;     // help window
369   QProcess*        shellProcess;   // shell process (install script)
370   QProcess*        diskSpaceProc;  // shell process (to get available disk space script)
371   QProcess*        modifyLaProc;   // shell process (to modify SALOME *.la files script)
372   QProcess*        checkFLibProc;  // shell process (to check Fortran libraries script)
373   MapProducts      productsMap;    // products info (name, dependancies, disk space )
374   MapXmlFiles      extraProducts;  // additional products to be installed
375   QStringList      toInstall;      // list of products being installed
376   QStringList      notInstall;     // list of products being not installed
377   QStringList      prodSequence;   // specified list of products being installed
378   MapAttrStates    woGuiModules;   // map of SALOME modules names, that can support installation without GUI mode
379   InstallationType installType;    // type of the installation
380   QString          curPlatform;    // current operating system
381   QString          refPlatform;    // referenced operating system (selected by user). It is defined, 
382                                    //   if current OS is not determined or not supported only
383   MapXmlFiles      platformsMap;   // supported operating systems and corresponding XML files
384   QString          xmlFileName;    // xml file
385   QString          binPath;        // binaries path
386   QString          srcPath;        // sources path
387   QString          oneProdDirName; // name of the single directory for binaries of prerequisites
388   QString          commonPlatform; // platform with universal binaries
389   bool             moreMode;       // advanced mode flag
390   QWidget*         previousPage;   // previous page
391   QString          tmpCreated;     // created temporary directory
392   bool             stateChanged;   // flag: whether installation type or platform was changed
393   bool             exitConfirmed;  // flag: "Exit confirmed"
394   bool             rmSrcPrevState; // flag: status of "Remove SRC & TMP files" is changed ?
395   // Widgets
396   // --> introduction page
397   QWidget*         introPage;      // page itself
398   QLabel*          logoLab;        // logo pixmap
399   QLabel*          versionLab;     // version info
400   QLabel*          copyrightLab;   // copyright info
401   QLabel*          licenseLab;     // license info
402   QLabel*          info;           // program info
403   // --> installation types page
404   QWidget*         typePage;       // page itself
405   QButtonGroup*    buttonGrp;      // group of the available installation types radio-buttons
406   QRadioButton*    binBtn;         // install binaries button
407   QRadioButton*    srcBtn;         // install sources button
408   QRadioButton*    srcCompileBtn;  // install sources and compile button
409   QCheckBox*       removeSrcBtn;   // <Remove sources & tmp files> checkbox
410   bool             forceSrc;       // Force all products to be compiled from sources
411   // --> installation platform page
412   QWidget*         platformsPage;  // page itself
413   QButtonGroup*    platBtnGrp;     // group of platforms for selection
414   QString          warnMsg;        // warning message
415   QLabel*          warnLab;        // warning label
416   QLabel*          warnLab3;       // additional warning label
417   // --> installation directories page
418   QWidget*         dirPage;        // page itself
419   QLineEdit*       targetFolder;   // target directory for installing of products
420   QPushButton*     targetBtn;      // browse target directory button
421   QLineEdit*       tempFolder;     // directory for the temporary files: /tmp by default
422   QPushButton*     tempBtn;        // browse temp directory button
423   // --> products page
424   QWidget*         productsPage;   // page itself
425   ProductsView*    modulesView;    // modules list view
426   QMyCheckBox*     installGuiBtn;  // <Installation with GUI> checkbox
427   ProductsView*    prereqsView;    // prerequisites list view
428   QMyCheckBox*     oneModDirBtn;   // <Install SALOME modules to a single directory> checkbox
429   QMyCheckBox*     oneProdDirBtn;  // <Install prerequisites to a single directory> checkbox
430   QPushButton*     moreBtn;        // <Show/Hide prerequisites> button
431   QTextBrowser*    productInfo;    // products info box
432   QLabel*          requiredSize;   // <Total disk space required> label
433   QLabel*          requiredTemp;   // <Space required for temporary files> label
434   QLabel*          availableSize;  // <Available disk space> label
435   bool             singleDir;      // Force all SALOME modules to be installed into single directory
436   // --> prestart page
437   QWidget*         prestartPage;   // page itself
438   QTextEdit*       choices;        // choice text view
439   // --> progress page
440   QWidget*         progressPage;   // page itself
441   QSplitter*       splitter;       // splitter window
442   InstallInfo*     installInfo;    // information about running installation scripts
443   QLabel*          parametersLab;  // answer field's label
444   QLineEdit*       passedParams;   // user can pass data to running script
445   QTextEdit*       installProgress;// contains information about progress of installing selected products
446   ProgressView*    progressView;   // displays information about progress of installing selected products
447   QCheckBox*       ignoreErrCBox;  // checkbox to ignore installation errors
448   QLabel*          statusLab;      // displays currently performed action
449   // --> finish page
450   QWidget*         readmePage;     // page itself
451   QTextEdit*       readme;         // Readme information window
452   ButtonList       buttons;        // operation buttons
453
454   ProcessThread*   myThread;       // validation thread
455   bool             hasErrors;      // flag: if there were any errors or warnings during the installation
456 };
457
458 #endif