2 #include <QtCore/QFile>
3 #include <QtCore/QFileInfo>
4 #include <QtCore/QTextStream>
5 #include <QtGui/QApplication>
6 #include <QtGui/QFileDialog>
7 #include <QtGui/QMessageBox>
9 #include "hxx2salome.h"
11 static QString quote( const QString& val )
14 if ( !v.startsWith( "\"" ) ) v.prepend( "\"" );
15 if ( !v.endsWith( "\"" ) ) v.append( "\"" );
19 static QString unquote( const QString& val )
22 if ( v.startsWith( "\"" ) ) v = v.remove( 0, 1 );
23 if ( v.endsWith( "\"" ) ) v = v.remove( v.length()-1, 1 );
27 HXX2Salome::HXX2Salome() : QDialog()
33 HXX2Salome::~HXX2Salome()
38 void HXX2Salome::retrieve()
40 QFile file( QDir::home().absoluteFilePath( ".hxx2salome" ) );
41 if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) ) {
42 QTextStream in( &file );
43 while ( !in.atEnd() ) {
44 QString line = in.readLine();
45 QRegExp re( "^(.*)\\s+(.*)$" );
46 if ( re.exactMatch( line ) ) {
47 QString var = re.cap( 1 ).trimmed();
48 QString val = unquote( re.cap( 2 ).trimmed() );
49 if ( !var.isEmpty() && !val.isEmpty() ) {
50 if ( var == "CppDir" )
51 SourceTreeText->setText( val );
52 else if ( var == "CppInc" )
53 IncludeText->setText( val );
54 else if ( var == "CppLib" )
55 LibraryText->setText( val );
56 else if ( var == "EnvFile" )
57 EnvFileText->setText( val );
58 else if ( var == "SalomeDir" )
59 OutputTreeText->setText( val );
60 else if ( var == "Shell" )
61 ShellChoice->setCurrentIndex( val == "csh" ? 1 : 0 );
69 void HXX2Salome::dump()
71 QFile file( QDir::home().absoluteFilePath( ".hxx2salome" ) );
72 if ( file.open( QIODevice::WriteOnly | QIODevice::Text ) ) {
73 file.write( QString( "CppDir %1\n" ).arg( quote( SourceTreeText->text() ) ).toLatin1() );
74 file.write( QString( "CppInc %1\n" ).arg( quote( IncludeText->text() ) ).toLatin1() );
75 file.write( QString( "CppLib %1\n" ).arg( quote( LibraryText->text() ) ).toLatin1() );
76 file.write( QString( "SalomeDir %1\n" ).arg( quote( OutputTreeText->text() ) ).toLatin1() );
77 file.write( QString( "EnvFile %1\n" ).arg( quote( EnvFileText->text() ) ).toLatin1() );
78 file.write( QString( "Shell %1\n" ).arg( ShellChoice->currentIndex() == 1 ? "csh" : "bash" ).toLatin1() );
83 void HXX2Salome::on_CloseButton_clicked()
88 void HXX2Salome::on_SourceTreeButton_clicked()
90 QString s = QFileDialog::getExistingDirectory( this,
91 tr( "Get Existing directory" ),
92 SourceTreeText->text() );
93 if ( !s.isEmpty() ) SourceTreeText->setText( s );
96 void HXX2Salome::on_IncludeButton_clicked()
98 QString s = QFileDialog::getOpenFileName( this,
99 tr( "Choose a file to open" ),
101 tr( "Include files (*.h *.hh *.hxx *.hpp)" ) );
102 if ( !s.isEmpty() ) {
103 QString CppDir = SourceTreeText->text().trimmed();
104 QFileInfo fid( CppDir.isEmpty() ? QString( "." ) : CppDir );
106 IncludeText->setText( fid.canonicalFilePath() == fif.canonicalPath() ? fif.fileName() : s );
110 void HXX2Salome::on_LibraryButton_clicked()
112 QString s = QFileDialog::getOpenFileName( this,
113 tr( "Choose a file to open" ),
115 tr( "Shared Libraries (*.so *.dll)" ) );
116 if ( !s.isEmpty() ) {
117 QString CppDir = SourceTreeText->text().trimmed();
118 QFileInfo fid( CppDir.isEmpty() ? QString( "." ) : CppDir );
120 LibraryText->setText( fid.canonicalFilePath() == fif.canonicalPath() ? fif.fileName() : s );
124 void HXX2Salome::on_EnvFileButton_clicked()
126 QString s = QFileDialog::getSaveFileName( this,
127 tr( "Choose a script file to open" ),
129 tr( "Environment files (*.csh *.sh)" ) );
130 if ( !s.isEmpty() ) EnvFileText->setText( s );
133 void HXX2Salome::on_OutputTreeButton_clicked()
135 QString s = QFileDialog::getExistingDirectory( this,
136 tr( "Choose a directory" ),
137 OutputTreeText->text() );
138 if ( !s.isEmpty() ) OutputTreeText->setText( s );
141 void HXX2Salome::on_GenerateButton_clicked()
143 // check input validity
144 QString CppDir = SourceTreeText->text().trimmed();
145 QFileInfo fid( CppDir.isEmpty() ? QString( "." ) : CppDir );
147 if ( CppDir.isEmpty() ) {
148 QMessageBox::StandardButton btn =
149 QMessageBox::warning( this,
151 tr( "You are about to use the current directory for the C++ component tree!\nContinue?" ),
152 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
153 if ( btn != QMessageBox::Yes ) return;
156 QString CppInc = IncludeText->text().trimmed();
157 if ( CppInc.isEmpty() ) {
158 QMessageBox::critical( this,
160 tr( "Component C++ include file is not specified!" ) );
163 QFileInfo fifinc( CppInc );
164 if ( fifinc.fileName() != CppInc && fid.canonicalFilePath() != fifinc.canonicalPath() ) {
165 QMessageBox::critical( this,
167 tr( "Component C++ include file is specified in directory other than\n%1!" ).arg( CppDir ) );
171 QString CppLib = LibraryText->text().trimmed();
172 if ( CppLib.isEmpty() ) {
173 QMessageBox::critical( this,
175 tr( "Component shared library is not specified!" ) );
178 QFileInfo fiflib( CppLib );
179 if ( fiflib.fileName() != CppLib && fid.canonicalFilePath() != fiflib.canonicalPath() ) {
180 QMessageBox::critical( this,
182 tr( "Component shared library is specified in directory other than\n%1!" ).arg( CppDir ) );
186 QString SalomeDir = OutputTreeText->text().trimmed();
187 QFileInfo fis( SalomeDir.isEmpty() ? QString( "." ) : SalomeDir );
189 if ( SalomeDir.isEmpty() ) {
190 QMessageBox::StandardButton btn =
191 QMessageBox::warning( this,
193 tr( "You are about to use the current directory as the Salome component tree!\nContinue?" ),
194 QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
195 if ( btn != QMessageBox::Yes ) return;
198 QString EnvFile = EnvFileText->text().trimmed();
199 QFileInfo fienv( EnvFile );
201 // generate command line
203 cmdlist << "${HXX2SALOME_ROOT_DIR}/hxx2salome";
204 if ( MakeGUI->isChecked() )
206 if ( Compile->isChecked() )
208 if ( ShellChoice->currentIndex() == 1 )
210 if ( !EnvFile.isEmpty() ) {
212 cmdlist << quote( fienv.absoluteFilePath() );
214 cmdlist << quote( fid.absoluteFilePath() );
215 cmdlist << quote( fifinc.fileName() );
216 cmdlist << quote( fiflib.fileName() );
217 cmdlist << quote( fis.absoluteFilePath() );
218 QString command = cmdlist.join( " " );
221 QApplication::setOverrideCursor( Qt::WaitCursor );
222 std::system( command.toLatin1().constData() );
223 QApplication::restoreOverrideCursor();