Salome HOME
Improvement: support <button> tag to customize the buttons (to perform specific actio...
[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
4 //  Project   : SALOME
5 //  Module    : Installation Wizard
6 //  Copyright : 2004-2005 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
268   // <Finish> page buttons slot
269   void onFinishButton();
270
271   // <About> button slot
272   void onAbout();
273
274   // QProcess slots:
275   // -->something was written to stdin
276   void wroteToStdin();
277   // -->something was written to stout
278   void readFromStdout();
279   // -->something was written to stderr
280   void readFromStderr();
281
282  private:
283   QString          myIWName;       // Installation Wizard's name
284   QString          myVersion;      // version info
285   QString          myCaption;      // application name
286   QString          myCopyright;    // copyright info 
287   QString          myLicense;      // license info
288   QString          myOS;           // operation system
289   
290   HelpWindow*      helpWindow;     // help window
291   QProcess*        shellProcess;   // shell process (install script)
292   MapProducts      productsMap;    // products info (name, dependancies, disk space )
293   QStringList      toInstall;      // list of products being installed
294   QString          xmlFileName;    // xml file
295   QString          targetDirPath;  // target directory
296   QString          tmpDirPath;     // temporary directory
297   bool             moreMode;       // advanced mode flag
298   QWidget*         previousPage;   // previous page
299   QString          tmpCreated;     // created temporary directory
300   bool             exitConfirmed;  // flag: "Exit confirmed"
301   // Widgets
302   // --> introduction page
303   QWidget*         introPage;      // page itself
304   QLabel*          logoLab;        // logo pixmap
305   QLabel*          versionLab;     // vesrsion info
306   QLabel*          copyrightLab;   // copyright info
307   QLabel*          licenseLab;     // license info
308   QLabel*          info;           // program info
309   // --> products page
310   QWidget*         productsPage;   // page itself
311   QLineEdit*       targetFolder;   // target directory for installing of products
312   QPushButton*     targetBtn;      // browse target directory button
313   QLineEdit*       tempFolder;     // directory for the temporary files: /tmp by default
314   QPushButton*     tempBtn;        // browse temp directory button
315   QLabel*          requiredSize;   // <Total disk space required> label
316   QLabel*          requiredTemp;   // <Space required for temporary files> label
317   QPushButton*     moreBtn;        // <More...> button
318   QWidget*         moreBox;        // container for the <More...> mode widgets
319   ProductsView*    productsView;   // products list view
320   QTextBrowser*    productsInfo;   // products info box
321   QCheckBox*       prerequisites;  // <Auto check prerequisites products> checkbox
322   QMyCheckBox*     selectSrcBtn;   // <SALOME sources> check box 
323   QMyCheckBox*     selectBinBtn;   // <SALOME binaries> check box 
324   QPushButton*     unselectBtn;    // <Unselect All> button
325   // --> prestart page
326   QWidget*         prestartPage;   // page itself
327   QTextEdit*       choices;        // choice text view
328   // --> progress page
329   QWidget*         progressPage;   // page itself
330   QSplitter*       splitter;       // splitter window
331   InstallInfo*     installInfo;    // information about running installation scripts
332   QLabel*          parametersLab;  // answer field's label
333   QLineEdit*       passedParams;   // user can pass data to running script
334   QTextEdit*       installProgress;// contains information about progress of installing selected products
335   ProgressView*    progressView;   // displays information about progress of installing selected products
336   // --> finish page
337   QWidget*         readmePage;     // page itself
338   QTextEdit*       readme;         // Readme information window
339   ButtonList       buttons;        // operation buttons
340
341   ProcessThread*   myThread;       // validation thread
342 };
343
344 #endif