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