Salome HOME
6621a6928cebb1597bf1ec2bb254bedba8315592
[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   // destructor
151   virtual ~SALOME_InstallWizard( );
152
153   // event filter
154   bool eventFilter( QObject* object, QEvent* event );
155
156   // set dependancies
157   void setDependancies( QCheckListItem* item, Dependancies dep);
158
159   // add button for the <Finish> page
160   void addFinishButton( const QString& label, 
161                         const QString& tooltip, 
162                         const QString& script);
163
164   // set version
165   void setVersion( const QString& version ) { myVersion = version; }
166   // set caption
167   void setCaption( const QString& caption ) { myCaption = caption; updateCaption(); }
168   // set copyright
169   void setCopyright( const QString& copyright ) { myCopyright = copyright; }
170   // set license
171   void setLicense( const QString& license ) { myLicense = license; }
172   // set OS
173   void setOS( const QString& OS ) { myOS = OS; }
174
175   // get version
176   QString getVersion() { return myVersion; }
177   // get caption
178   QString getCaption() { return myCaption; }
179   // get copyright
180   QString getCopyright() { return myCopyright; }
181   // get license
182   QString getLicense() { return myLicense; }
183   // get OS
184   QString getOS() { return myOS; }
185   // get InstallWizard's name
186   QString getIWName() { return myIWName; }
187
188   // process validation event (<val> is validation code)
189   void processValidateEvent( const int val, void* data );
190
191  public slots:
192   // polishing of the widget
193   void polish();
194   
195   // save install log to file
196   void saveLog();
197
198  protected:
199   // updates caption according to the current page number
200   void updateCaption();
201   // close event handler
202   void closeEvent( QCloseEvent* ce );
203   // creates introduction page
204   void setupIntroPage();   
205   // creates products page
206   void setupProductsPage();
207   // creates directories page
208   void setupDirPage();
209   // creates prestart page
210   void setupCheckPage();
211   // creates progress page
212   void setupProgressPage();
213   // creates readme page
214   void setupReadmePage();
215   // displays choice info
216   void showChoiceInfo();
217   // validates page when <Next> button is clicked
218   bool acceptData( const QString& ); 
219   // calculates disk space required for the installation, returns true if any product selected to be installed (src, bin or native)
220   bool checkSize( long* totSize = 0, long* tempSize = 0 );
221   // checks products page validity (directories and products selection)
222   void checkProductPage();
223   // sets the product and all products this one depends on to be checked ( recursively )
224   void setPrerequisites( QCheckListItem* item );
225   // runs installation script
226   void launchScript(); 
227   // searches product listview item with given symbolic name 
228   QCheckListItem* findItem( const QString& sName );
229   // sets progress state to Aborted
230   void abort();
231   // clears and (optionally) removes temporary directory
232   void clean(bool rmDir = false);
233
234  protected slots:
235   // reject slot
236   void reject();
237   // accept slot
238   void accept();
239   
240  private slots:
241   // called when user moves from page to page
242   void pageChanged( const QString & mytitle);
243   // invokes Help window
244   void helpClicked();
245   // invokes directory selection dialog box
246   void browseDirectory();
247   // called when directory path (target or temp) is changed
248   void directoryChanged( const QString& text );
249   // <Start> button's slot - runs installation
250   void onStart();
251   // called when users tries to pass parameters for the script
252   void onReturnPressed();
253   // callback function - as response for the script finishing
254   void productInstalled();
255   // called when <Cancel> button is clicked during installation script running
256   void tryTerminate();
257   // kills installation process and quits application
258   void onCancel();
259   // called when selection is changed in the products list view
260   void onSelectionChanged();
261   // called when user checks/unchecks any product item
262   void onItemToggled( QCheckListItem* );
263   // <SALOME sources>, <SALOME binaries>, <Unselect All> buttons slot
264   void onProdBtn();
265   // <More...> button slot
266   void onMoreBtn();
267   // <Install all products from sources> check box
268   void onBuildAll();
269
270   // <Finish> page buttons slot
271   void onFinishButton();
272
273   // reset to default state
274   void resetToDefaultState();
275
276   // <About> button slot
277   void onAbout();
278
279   // QProcess slots:
280   // -->something was written to stdin
281   void wroteToStdin();
282   // -->something was written to stout
283   void readFromStdout();
284   // -->something was written to stderr
285   void readFromStderr();
286
287  private:
288   QString          myIWName;       // Installation Wizard's name
289   QString          myVersion;      // version info
290   QString          myCaption;      // application name
291   QString          myCopyright;    // copyright info 
292   QString          myLicense;      // license info
293   QString          myOS;           // operation system
294   
295   HelpWindow*      helpWindow;     // help window
296   QProcess*        shellProcess;   // shell process (install script)
297   MapProducts      productsMap;    // products info (name, dependancies, disk space )
298   QStringList      toInstall;      // list of products being installed
299   QString          xmlFileName;    // xml file
300   QString          targetDirPath;  // target directory
301   QString          tmpDirPath;     // temporary directory
302   bool             moreMode;       // advanced mode flag
303   QWidget*         previousPage;   // previous page
304   QString          tmpCreated;     // created temporary directory
305   bool             exitConfirmed;  // flag: "Exit confirmed"
306   // Widgets
307   // --> introduction page
308   QWidget*         introPage;      // page itself
309   QLabel*          logoLab;        // logo pixmap
310   QLabel*          versionLab;     // vesrsion info
311   QLabel*          copyrightLab;   // copyright info
312   QLabel*          licenseLab;     // license info
313   QLabel*          info;           // program info
314   // --> products page
315   QWidget*         productsPage;   // page itself
316   QLineEdit*       targetFolder;   // target directory for installing of products
317   QPushButton*     targetBtn;      // browse target directory button
318   QLineEdit*       tempFolder;     // directory for the temporary files: /tmp by default
319   QPushButton*     tempBtn;        // browse temp directory button
320   QLabel*          requiredSize;   // <Total disk space required> label
321   QLabel*          requiredTemp;   // <Space required for temporary files> label
322   QPushButton*     moreBtn;        // <More...> button
323   QWidget*         moreBox;        // container for the <More...> mode widgets
324   ProductsView*    productsView;   // products list view
325   QTextBrowser*    productsInfo;   // products info box
326   QCheckBox*       prerequisites;  // <Auto check prerequisites products> checkbox
327   QMyCheckBox*     selectSrcBtn;   // <SALOME sources> check box 
328   QMyCheckBox*     buildSrcBtn;    // <Build SALOME sources> check box 
329   QMyCheckBox*     selectBinBtn;   // <SALOME binaries> check box 
330   QPushButton*     unselectBtn;    // <Unselect All> button
331   QWidget*         lessBox;        // container for the <Less...> mode widgets
332   QMyCheckBox*     allFromSrcBtn;  // <Install all products from sources> check box
333   // --> prestart page
334   QWidget*         prestartPage;   // page itself
335   QTextEdit*       choices;        // choice text view
336   // --> progress page
337   QWidget*         progressPage;   // page itself
338   QSplitter*       splitter;       // splitter window
339   InstallInfo*     installInfo;    // information about running installation scripts
340   QLabel*          parametersLab;  // answer field's label
341   QLineEdit*       passedParams;   // user can pass data to running script
342   QTextEdit*       installProgress;// contains information about progress of installing selected products
343   ProgressView*    progressView;   // displays information about progress of installing selected products
344   // --> finish page
345   QWidget*         readmePage;     // page itself
346   QTextEdit*       readme;         // Readme information window
347   ButtonList       buttons;        // operation buttons
348
349   ProcessThread*   myThread;       // validation thread
350 };
351
352 #endif