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