Salome HOME
Set default path to save an installation log equal to a target directory path instead...
[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 current platform
162   QString currentPlatform();
163
164   // get binaries path
165   QString getBinPath() { return binPath; }
166   // get sources path
167   QString getSrcPath() { return srcPath; }
168
169   // get map of supported platforms and corresponding XML files
170   MapXmlFiles getXmlMap( const QString& aXmlFileName = QString::null );
171   // check/get XML file and current platform
172   void getXmlAndPlatform();
173
174   // event filter
175   bool eventFilter( QObject* object, QEvent* event );
176
177   // set dependancies
178   void setDependancies( QCheckListItem* item, Dependancies dep);
179
180   // add button for the <Finish> page
181   void addFinishButton( const QString& label, 
182                         const QString& tooltip, 
183                         const QString& script,
184                         bool toClear = false );
185
186   // set version
187   void setVersion( const QString& version ) { myVersion = version; }
188   // set caption
189   void setCaption( const QString& caption ) { myCaption = caption; updateCaption(); }
190   // set copyright
191   void setCopyright( const QString& copyright ) { myCopyright = copyright; }
192   // set license
193   void setLicense( const QString& license ) { myLicense = license; }
194
195   // get version
196   QString getVersion() { return myVersion; }
197   // get caption
198   QString getCaption() { return myCaption; }
199   // get copyright
200   QString getCopyright() { return myCopyright; }
201   // get license
202   QString getLicense() { return myLicense; }
203   // get platform
204   QString getPlatform() { return refPlatform ? refPlatform : curPlatform; }
205   // get InstallWizard's name
206   QString getIWName() { return myIWName; }
207
208   // process validation event (<val> is validation code)
209   void processValidateEvent( const int val, void* data );
210   // get private installation type
211   InstallationType getInstType() { return installType; };
212
213  public slots:
214   // polishing of the widget
215   void polish();
216   
217   // save install log to file
218   void saveLog();
219
220  protected:
221   // updates caption according to the current page number
222   void updateCaption();
223   // close event handler
224   void closeEvent( QCloseEvent* ce );
225   // creates introduction page
226   void setupIntroPage();   
227   // create installation types page
228   void setupTypePage();
229   // create platforms page
230   void setupPlatformPage();
231   // create directories page
232   void setupDirPage();
233   // creates products page
234   void setupProductsPage();
235   // creates prestart page
236   void setupCheckPage();
237   // creates progress page
238   void setupProgressPage();
239   // creates readme page
240   void setupReadmePage();
241   // displays choice info
242   void showChoiceInfo();
243   // validates page when <Next> button is clicked
244   bool acceptData( const QString& );
245   // calculates disk space required for the installation, returns true if any product selected to be installed (src, bin or native)
246   bool checkSize( long* totSize = 0, long* tempSize = 0 );
247   // checks products page validity (directories and products selection)
248   void checkProductPage();
249   // sets the product and all products this one depends on to be checked
250   void setPrerequisites( QCheckListItem* item );
251   // unsets all products which depend of unchecked product ( recursively )
252   void unsetPrerequisites( QCheckListItem* item );
253   // runs installation script
254   void launchScript(); 
255   // searches product listview item with given symbolic name 
256   QCheckListItem* findItem( const QString& sName );
257   // sets progress state to Aborted
258   void abort();
259   // clears and (optionally) removes temporary directory
260   void clean(bool rmDir = false);
261   // Update GUI and check installation errors
262   void completeInstallation();
263
264  protected slots:
265   // reject slot
266   void reject();
267   // accept slot
268   void accept();
269   
270  private slots:
271   // called when user moves from page to page
272   void pageChanged( const QString & mytitle);
273   // called when user selected either installation type or installation platform
274   void onButtonGroup( int index );
275   // invokes Help window
276   void helpClicked();
277   // invokes directory selection dialog box
278   void browseDirectory();
279   // called when directory path (target or temp) is changed
280   void directoryChanged( const QString& text );
281   // <Start> button's slot - runs installation
282   void onStart();
283   // called when users tries to pass parameters for the script
284   void onReturnPressed();
285   // callback function - as response for the script finishing
286   void productInstalled();
287   // called when <Cancel> button is clicked during installation script running
288   void tryTerminate();
289   // kills installation process and quits application
290   void onCancel();
291   // called when selection is changed in the products list view
292   void onSelectionChanged();
293   // called when user checks/unchecks any product item
294   void onItemToggled( QCheckListItem* );
295   // <Installation with GUI> check-box slot
296   void onInstallGuiBtn();
297   // <More...> button slot
298   void onMoreBtn();
299   // Slot to update 'Available disk space' field
300   void updateAvailableSpace();
301   // Slot to take result of Fortran libraries checking
302   void checkFLibResult();
303   // Slot to update 'Size' column for modules and prerequisites
304   void updateSizeColumn();
305
306   // <Finish> page buttons slot
307   void onFinishButton();
308
309   // <About> button slot
310   void onAbout();
311
312   // QProcess slots:
313   // -->something was written to stdin
314   void wroteToStdin();
315   // -->something was written to stout
316   void readFromStdout();
317   // -->something was written to stderr
318   void readFromStderr();
319
320  private:
321   QString          myIWName;       // Installation Wizard's name
322   QString          myVersion;      // version info
323   QString          myCaption;      // application name
324   QString          myCopyright;    // copyright info 
325   QString          myLicense;      // license info
326   QString          myTargetPath;   // target directory path
327   QString          myTmpPath;      // temporary directory path
328   
329   HelpWindow*      helpWindow;     // help window
330   QProcess*        shellProcess;   // shell process (install script)
331   QProcess*        diskSpaceProc;  // shell process (to get available disk space script)
332   QProcess*        checkFLibProc;  // shell process (to get available disk space script)
333   MapProducts      productsMap;    // products info (name, dependancies, disk space )
334   QStringList      toInstall;      // list of products being installed
335   QStringList      notInstall;     // list of products being not installed
336   QStringList      prodSequence;   // specified list of products being installed
337   InstallationType installType;    // type of the installation
338   QString          curPlatform;    // current operating system
339   QString          refPlatform;    // referenced operating system (selected by user). It is defined, 
340                                    //   if current OS is not determined or not supported only
341   MapXmlFiles      platformsMap;   // supported operating systems and corresponding XML files
342   QString          xmlFileName;    // xml file
343   QString          binPath;        // binaries path
344   QString          srcPath;        // sources path
345   bool             moreMode;       // advanced mode flag
346   QWidget*         previousPage;   // previous page
347   QString          tmpCreated;     // created temporary directory
348   bool             stateChanged;   // flag: whether installation type or platform was changed
349   bool             exitConfirmed;  // flag: "Exit confirmed"
350   bool             rmSrcPrevState; // flag: status of "Remove SRC & TMP files" is changed ?
351   // Widgets
352   // --> introduction page
353   QWidget*         introPage;      // page itself
354   QLabel*          logoLab;        // logo pixmap
355   QLabel*          versionLab;     // version info
356   QLabel*          copyrightLab;   // copyright info
357   QLabel*          licenseLab;     // license info
358   QLabel*          info;           // program info
359   // --> installation types page
360   QWidget*         typePage;       // page itself
361   QButtonGroup*    buttonGrp;      // group of the available installation types radio-buttons
362   QRadioButton*    binBtn;         // install binaries button
363   QRadioButton*    srcBtn;         // install sources button
364   QRadioButton*    srcCompileBtn;  // install sources and compile button
365   QCheckBox*       removeSrcBtn;   // <Remove sources & tmp files> checkbox
366   // --> installation platform page
367   QWidget*         platformsPage;  // page itself
368   QButtonGroup*    platBtnGrp;     // group of platforms for selection
369   QString          warnMsg;        // warning message
370   QLabel*          warnLab;        // warning label
371   // --> installation directories page
372   QWidget*         dirPage;        // page itself
373   QLineEdit*       targetFolder;   // target directory for installing of products
374   QPushButton*     targetBtn;      // browse target directory button
375   QLineEdit*       tempFolder;     // directory for the temporary files: /tmp by default
376   QPushButton*     tempBtn;        // browse temp directory button
377   // --> products page
378   QWidget*         productsPage;   // page itself
379   ProductsView*    modulesView;    // modules list view
380   QMyCheckBox*     installGuiBtn;  // <Installation with GUI> checkbox
381   ProductsView*    prereqsView;    // prerequisites list view
382   QPushButton*     moreBtn;        // <More...> button
383   QTextBrowser*    productInfo;    // products info box
384   QLabel*          requiredSize;   // <Total disk space required> label
385   QLabel*          requiredTemp;   // <Space required for temporary files> label
386   QLabel*          availableSize;  // <Available disk space> label
387   // --> prestart page
388   QWidget*         prestartPage;   // page itself
389   QTextEdit*       choices;        // choice text view
390   // --> progress page
391   QWidget*         progressPage;   // page itself
392   QSplitter*       splitter;       // splitter window
393   InstallInfo*     installInfo;    // information about running installation scripts
394   QLabel*          parametersLab;  // answer field's label
395   QLineEdit*       passedParams;   // user can pass data to running script
396   QTextEdit*       installProgress;// contains information about progress of installing selected products
397   ProgressView*    progressView;   // displays information about progress of installing selected products
398   QLabel*          statusLab;      // displays currently performed action
399   // --> finish page
400   QWidget*         readmePage;     // page itself
401   QTextEdit*       readme;         // Readme information window
402   ButtonList       buttons;        // operation buttons
403
404   ProcessThread*   myThread;       // validation thread
405   bool             hasErrors;      // flag: if there were any errors or warnings during the installation
406 };
407
408 #endif