Salome HOME
5044556e653ed53a3ecd973915b15b2a8a96e7a3
[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-2006 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
35 /*! 
36   Class Dependancies : Products info
37   This class stores all product dependancies for correct work of installation procedure
38 */
39 class Dependancies
40 {
41  public:
42   // default constructor, necessary for map
43   Dependancies() {}
44   // constructor
45   Dependancies( const QString&     name, 
46                 const QStringList& depend, 
47                 const long         Binsize,  
48                 const long         Sourcessize, 
49                 const long         tempsize, 
50                 const QString&     def = QString::null,
51                 const QString&     descr = QString::null,
52                 const QString&     ctx = QString::null,
53                 bool               pickup = false )
54     : smbName( name ), 
55       dependsOn( depend ), 
56       sizeSourcesTotal( Sourcessize ), 
57       sizeBinaryTotal( Binsize ), 
58       sizeTemp( tempsize ),
59       defaultMode( def ),
60       description( descr ),
61       context( ctx ),
62       pickupEnv( pickup ) {}
63
64   // gets symbolic name
65   QString     getName() const         { return smbName;   }
66   // gets dependancies
67   QStringList getDependancies() const { return dependsOn; }
68   // gets disk space required
69   long        getSize(bool sources = false) const 
70   { 
71     return ( sources ? sizeSourcesTotal : sizeBinaryTotal ); 
72   }
73   // gets temporary disk space required
74   long        getTempSize() const     { return sizeTemp;   }
75   // gets product's description
76   QString     getDescription() const  { return description; }
77   // gets product's context
78   QString     getContext() const      { return context; }
79   // returns true if product supports given context
80   bool        hasContext( const QString& ctx ) const
81   {
82     QStringList cl = QStringList::split(",",context);
83     return cl.find( ctx ) != cl.end();
84   }
85   // gets default mode
86   QString     getDefault() const      { return defaultMode; }
87   // returns true if this product needs to pick-up environment
88   bool        pickUpEnvironment()     { return pickupEnv; }
89
90  private:
91   QString     smbName;          // symbolic name
92   QStringList dependsOn;        // prerequisites list
93   long        sizeSourcesTotal; // disk space required
94   long        sizeBinaryTotal;  // disk space required
95   long        sizeTemp;         // disk space for temporary files required
96   QString     defaultMode;      // default installation mode
97   QString     description;      // product's description
98   QString     context;          // product's context (salome sources, binaries or prerequisite)
99   bool        pickupEnv;        // "Pick-up environment" flag
100 };
101
102 /*! 
103   Class Button : Operation button info
104   This class stores information about the custom operation buttons which appear on
105   the <Finish> page of the Install Wizard.
106 */
107 class Button
108 {
109  public:
110   // default constructor, required for list
111   Button() : myButton( 0 ) {}
112   // constructor
113   Button( const QString& label, const QString& tooltip, const QString& script )
114     : myLabel( label ), myTootip( tooltip ), myScript( script ), myButton( 0 ) {}
115
116   // set operation button
117   void setButton( QButton* btn ) { myButton = btn; }
118
119   // get label
120   QString  label()  const { return myLabel;  } 
121   // get tooltip
122   QString  tootip() const { return myTootip; }
123   // get script name
124   QString  script() const { return myScript; }
125   // get operation button
126   QButton* button() const { return myButton; }
127
128  private:
129   QString  myLabel;    // button label
130   QString  myTootip;   // button tooltip
131   QString  myScript;   // operation script
132   QButton* myButton;   // operation button
133 };
134
135 typedef QMap<QCheckListItem*, Dependancies> MapProducts;
136 typedef QValueList<Button>                  ButtonList;
137
138 /*!
139   Class SALOME_InstallWizard : Installation Wizard's main window
140 */
141 class SALOME_InstallWizard: public InstallWizard
142 {
143   Q_OBJECT
144     
145  public:
146   // constructor
147   SALOME_InstallWizard(const QString& aXmlFileName,
148                        const QString& aTargetDir = QString::null,
149                        const QString& aTmpDir    = QString::null,
150                        const bool     aForceSrc  = false);
151   // destructor
152   virtual ~SALOME_InstallWizard( );
153
154   // event filter
155   bool eventFilter( QObject* object, QEvent* event );
156
157   // set dependancies
158   void setDependancies( QCheckListItem* item, Dependancies dep);
159
160   // add button for the <Finish> page
161   void addFinishButton( const QString& label, 
162                         const QString& tooltip, 
163                         const QString& script);
164
165   // set version
166   void setVersion( const QString& version ) { myVersion = version; }
167   // set caption
168   void setCaption( const QString& caption ) { myCaption = caption; updateCaption(); }
169   // set copyright
170   void setCopyright( const QString& copyright ) { myCopyright = copyright; }
171   // set license
172   void setLicense( const QString& license ) { myLicense = license; }
173   // set OS
174   void setOS( const QString& OS ) { myOS = OS; }
175
176   // get version
177   QString getVersion() { return myVersion; }
178   // get caption
179   QString getCaption() { return myCaption; }
180   // get copyright
181   QString getCopyright() { return myCopyright; }
182   // get license
183   QString getLicense() { return myLicense; }
184   // get OS
185   QString getOS() { return myOS; }
186   // get InstallWizard's name
187   QString getIWName() { return myIWName; }
188
189   // process validation event (<val> is validation code)
190   void processValidateEvent( const int val, void* data );
191
192  public slots:
193   // polishing of the widget
194   void polish();
195   
196   // save install log to file
197   void saveLog();
198
199  protected:
200   // updates caption according to the current page number
201   void updateCaption();
202   // close event handler
203   void closeEvent( QCloseEvent* ce );
204   // creates introduction page
205   void setupIntroPage();   
206   // creates products page
207   void setupProductsPage(const bool forceSrc = false);
208   // creates directories page
209   void setupDirPage();
210   // creates prestart page
211   void setupCheckPage();
212   // creates progress page
213   void setupProgressPage();
214   // creates readme page
215   void setupReadmePage();
216   // displays choice info
217   void showChoiceInfo();
218   // validates page when <Next> button is clicked
219   bool acceptData( const QString& ); 
220   // calculates disk space required for the installation, returns true if any product selected to be installed (src, bin or native)
221   bool checkSize( long* totSize = 0, long* tempSize = 0 );
222   // checks products page validity (directories and products selection)
223   void checkProductPage();
224   // sets the product and all products this one depends on to be checked ( recursively )
225   void setPrerequisites( QCheckListItem* item );
226   // runs installation script
227   void launchScript(); 
228   // searches product listview item with given symbolic name 
229   QCheckListItem* findItem( const QString& sName );
230   // sets progress state to Aborted
231   void abort();
232   // clears and (optionally) removes temporary directory
233   void clean(bool rmDir = false);
234
235  protected slots:
236   // reject slot
237   void reject();
238   // accept slot
239   void accept();
240   
241  private slots:
242   // called when user moves from page to page
243   void pageChanged( const QString & mytitle);
244   // invokes Help window
245   void helpClicked();
246   // invokes directory selection dialog box
247   void browseDirectory();
248   // called when directory path (target or temp) is changed
249   void directoryChanged( const QString& text );
250   // <Start> button's slot - runs installation
251   void onStart();
252   // called when users tries to pass parameters for the script
253   void onReturnPressed();
254   // callback function - as response for the script finishing
255   void productInstalled();
256   // called when <Cancel> button is clicked during installation script running
257   void tryTerminate();
258   // kills installation process and quits application
259   void onCancel();
260   // called when selection is changed in the products list view
261   void onSelectionChanged();
262   // called when user checks/unchecks any product item
263   void onItemToggled( QCheckListItem* );
264   // <SALOME sources>, <SALOME binaries>, <Unselect All> buttons slot
265   void onProdBtn();
266   // <More...> button slot
267   void onMoreBtn();
268   // <Install all products from sources> check box
269   void onBuildAll();
270
271   // <Finish> page buttons slot
272   void onFinishButton();
273
274   // reset to default state
275   void resetToDefaultState();
276
277   // <About> button slot
278   void onAbout();
279
280   // QProcess slots:
281   // -->something was written to stdin
282   void wroteToStdin();
283   // -->something was written to stout
284   void readFromStdout();
285   // -->something was written to stderr
286   void readFromStderr();
287
288  private:
289   QString          myIWName;       // Installation Wizard's name
290   QString          myVersion;      // version info
291   QString          myCaption;      // application name
292   QString          myCopyright;    // copyright info 
293   QString          myLicense;      // license info
294   QString          myOS;           // operation system
295   
296   HelpWindow*      helpWindow;     // help window
297   QProcess*        shellProcess;   // shell process (install script)
298   MapProducts      productsMap;    // products info (name, dependancies, disk space )
299   QStringList      toInstall;      // list of products being installed
300   QString          xmlFileName;    // xml file
301   QString          targetDirPath;  // target directory
302   QString          tmpDirPath;     // temporary directory
303   bool             moreMode;       // advanced mode flag
304   QWidget*         previousPage;   // previous page
305   QString          tmpCreated;     // created temporary directory
306   bool             exitConfirmed;  // flag: "Exit confirmed"
307   // Widgets
308   // --> introduction page
309   QWidget*         introPage;      // page itself
310   QLabel*          logoLab;        // logo pixmap
311   QLabel*          versionLab;     // vesrsion info
312   QLabel*          copyrightLab;   // copyright info
313   QLabel*          licenseLab;     // license info
314   QLabel*          info;           // program info
315   // --> products page
316   QWidget*         productsPage;   // page itself
317   QLineEdit*       targetFolder;   // target directory for installing of products
318   QPushButton*     targetBtn;      // browse target directory button
319   QLineEdit*       tempFolder;     // directory for the temporary files: /tmp by default
320   QPushButton*     tempBtn;        // browse temp directory button
321   QLabel*          requiredSize;   // <Total disk space required> label
322   QLabel*          requiredTemp;   // <Space required for temporary files> label
323   QPushButton*     moreBtn;        // <More...> button
324   QWidget*         moreBox;        // container for the <More...> mode widgets
325   ProductsView*    productsView;   // products list view
326   QTextBrowser*    productsInfo;   // products info box
327   QCheckBox*       prerequisites;  // <Auto check prerequisites products> checkbox
328   QMyCheckBox*     selectSrcBtn;   // <SALOME sources> check box 
329   QMyCheckBox*     buildSrcBtn;    // <Build SALOME sources> check box 
330   QMyCheckBox*     selectBinBtn;   // <SALOME binaries> check box 
331   QPushButton*     unselectBtn;    // <Unselect All> button
332   QWidget*         lessBox;        // container for the <Less...> mode widgets
333   QMyCheckBox*     allFromSrcBtn;  // <Install all products from sources> check box
334   // --> prestart page
335   QWidget*         prestartPage;   // page itself
336   QTextEdit*       choices;        // choice text view
337   // --> progress page
338   QWidget*         progressPage;   // page itself
339   QSplitter*       splitter;       // splitter window
340   InstallInfo*     installInfo;    // information about running installation scripts
341   QLabel*          parametersLab;  // answer field's label
342   QLineEdit*       passedParams;   // user can pass data to running script
343   QTextEdit*       installProgress;// contains information about progress of installing selected products
344   ProgressView*    progressView;   // displays information about progress of installing selected products
345   // --> finish page
346   QWidget*         readmePage;     // page itself
347   QTextEdit*       readme;         // Readme information window
348   ButtonList       buttons;        // operation buttons
349
350   ProcessThread*   myThread;       // validation thread
351 };
352
353 #endif