Salome HOME
Fedora 6 support
[tools/install.git] / src / main.cxx
1 //  File      : main.cxx 
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 #include "globals.h"
9
10 #include "SALOME_InstallWizard.hxx"
11 #include <qapplication.h>
12 #include <qfile.h>
13 #include <qmessagebox.h>
14
15 // ================================================================
16 /*!
17  *  MessageOutput
18  *  Qt's messages handler funcion
19  */
20 // ================================================================
21 void MessageOutput( QtMsgType type, 
22 #ifdef QT_DEBUG
23                     const char* msg
24 #else
25                     const char*
26 #endif
27                     )
28 {
29   switch ( type ) {
30   case QtDebugMsg:
31     ___DEBUG___( msg );
32     break;
33   case QtWarningMsg:
34     ___WARNING___( msg );
35     break;
36   case QtFatalMsg:
37     ___FATAL___( msg );
38     break;
39   }
40 }
41
42 // ================================================================
43 /*!
44  *  main
45  *  Program starts here
46  */
47 // ================================================================
48 int main( int argc, char **argv )
49 {
50   qInstallMsgHandler( MessageOutput );
51
52   QString xmlFileName;
53   QString targetDirPath;
54   QString tmpDirPath;
55   bool has_xml    = false;
56   bool has_target = false;
57   bool has_tmp    = false;
58   bool force_src  = false;
59   for( int i = 1; i < argc; i++ ) {
60     QString a = QString( argv[i] );
61     if ( a == "--version" || a == "-v" ) {
62       printf("SALOME Installation Wizard version %d.%d.%d ",
63              ( __IW_VERSION__ / 10000 ),
64              ( __IW_VERSION__ / 100 % 100 ),
65              ( __IW_VERSION__ % 100 ) );
66       printf("(Qt version %d.%d.%d)\n",
67              ( QT_VERSION >> 16 ) & 0xFF,
68              ( QT_VERSION >> 8  ) & 0xFF,
69              ( QT_VERSION       ) & 0xFF );
70       return 0;
71     }
72     else if ( a == "--target" || a == "-d" ) {
73       has_target = true;
74       if ( i < argc-1 && !QString( argv[i+1] ).startsWith("-") ) {
75         targetDirPath = argv[i+1]; 
76         i++;
77       }
78       else {
79         tmpDirPath = QString::null;
80       }
81     }
82     else if ( a == "--tmp" || a == "-t" ) {
83       has_tmp = true;
84       if ( i < argc-1 && !QString( argv[i+1] ).startsWith("-") ) {
85         tmpDirPath = argv[i+1]; 
86         i++;
87       }
88       else {
89         tmpDirPath = QString::null;
90       }
91     }
92     else if ( a == "--file" || a == "-f" ) {
93       has_xml = true;
94       if ( i < argc-1 && !QString( argv[i+1] ).startsWith("-") ) {
95         xmlFileName = argv[i+1]; 
96         i++;
97       }
98       else {
99         xmlFileName = QString::null;
100       }
101     }
102     else if ( a == "--all-from-sources" || a == "-a" ) {
103       force_src = true;
104     }
105   }
106   if ( has_xml && xmlFileName.isEmpty() ) {
107     printf("Please specify the configuration XML file!\n");
108     return 1;
109   }
110   if ( has_target && targetDirPath.isEmpty() ) {
111     printf("Please specify the target directory path!\n");
112     return 1;
113   }
114   if ( has_tmp && tmpDirPath.isEmpty() ) {
115     printf("Please specify the temprary directory path!\n");
116     return 1;
117   }
118
119   if ( xmlFileName.isEmpty() )
120     xmlFileName = "config.xml";
121
122   QApplication a( argc, argv );
123   a.setFont( QFont( "Sans", 12 ) );
124
125   int result = -1;
126   QFile xmlfile(xmlFileName);
127   if ( xmlfile.exists() ) {
128     SALOME_InstallWizard wizard(xmlFileName, targetDirPath, tmpDirPath, force_src);
129     a.setMainWidget( &wizard );
130     wizard.show();
131     result = a.exec();
132   }
133   else {
134     QMessageBox::critical( 0, 
135                            QObject::tr( "Error" ), 
136                            QObject::tr( "Can't open config file:\n%1\n\nQuitting...").arg( xmlFileName ), 
137                            QMessageBox::Ok,
138                            QMessageBox::NoButton, 
139                            QMessageBox::NoButton );
140   }
141   return result;
142 }
143