Salome HOME
Modify the way the application is generated within KERNEL module installation procedure
[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-2014 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   bool single_dir = false;
60   for( int i = 1; i < argc; i++ ) {
61     QString a = QString( argv[i] );
62     if ( a == "--version" || a == "-v" ) {
63       printf("SALOME Installation Wizard version %d.%d.%d (Qt version %d.%d.%d)\n",
64              ( __IW_VERSION__ / 10000 ),
65              ( __IW_VERSION__ / 100 % 100 ),
66              ( __IW_VERSION__ % 100 ) ,
67              ( QT_VERSION >> 16 ) & 0xFF,
68              ( QT_VERSION >> 8  ) & 0xFF,
69              ( QT_VERSION       ) & 0xFF );
70       printf("Copyright (C) 2002-2014 CEA\n");
71       return 0;
72     }
73     else if ( a == "--target" || a == "-d" ) {
74       has_target = true;
75       if ( i < argc-1 && !QString( argv[i+1] ).startsWith("-") ) {
76         targetDirPath = argv[i+1]; 
77         i++;
78       }
79       else {
80         targetDirPath = QString::null;
81       }
82     }
83     else if ( a == "--tmp" || a == "-t" ) {
84       has_tmp = true;
85       if ( i < argc-1 && !QString( argv[i+1] ).startsWith("-") ) {
86         tmpDirPath = argv[i+1]; 
87         i++;
88       }
89       else {
90         tmpDirPath = QString::null;
91       }
92     }
93     else if ( a == "--file" || a == "-f" ) {
94       has_xml = true;
95       if ( i < argc-1 && !QString( argv[i+1] ).startsWith("-") ) {
96         xmlFileName = argv[i+1]; 
97         i++;
98       }
99       else {
100         xmlFileName = QString::null;
101       }
102     }
103     else if ( a == "--all-from-sources" || a == "-a" ) {
104       force_src = true;
105     }
106     else if ( a == "--single-directory" || a == "-s" ) {
107       single_dir = true;
108     }
109   }
110   if ( has_xml && xmlFileName.isEmpty() ) {
111     printf("Please specify the configuration XML file!\n");
112     return 1;
113   }
114   if ( has_target && targetDirPath.isEmpty() ) {
115     printf("Please specify the target directory path!\n");
116     return 1;
117   }
118   if ( has_tmp && tmpDirPath.isEmpty() ) {
119     printf("Please specify the temprary directory path!\n");
120     return 1;
121   }
122
123   QApplication a( argc, argv );
124   a.setFont( QFont( "Sans", 12 ) );
125
126   if ( has_xml ) {
127     QFile xmlfile(xmlFileName);
128     if ( !xmlfile.exists() ) {
129       QMessageBox::critical( 0, 
130                              QObject::tr( "Error" ), 
131                              QObject::tr( "Can't open config file:\n%1\n\nQuitting...").arg( xmlFileName ), 
132                              QMessageBox::Ok,
133                              QMessageBox::NoButton, 
134                              QMessageBox::NoButton );
135       return -1;
136     }
137   }
138   SALOME_InstallWizard wizard(xmlFileName, targetDirPath, tmpDirPath, force_src, single_dir);
139   a.setMainWidget( &wizard );
140   wizard.show();
141   return a.exec();
142 }
143