From: vsr Date: Thu, 11 Dec 2008 16:59:58 +0000 (+0000) Subject: Porting HXX2SALOME module to Qt4 X-Git-Tag: V5_1_0~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=05bce9c8b75133347a3ef4420f7766117a7237f0;p=tools%2Fhxx2salome.git Porting HXX2SALOME module to Qt4 --- diff --git a/src/hxx2salome.cpp b/src/hxx2salome.cpp index 09ed969..480a687 100644 --- a/src/hxx2salome.cpp +++ b/src/hxx2salome.cpp @@ -8,6 +8,9 @@ #include "hxx2salome.h" +// VSR: uncomment for debug mode +// #define __DEBUG__ + static QString quote( const QString& val ) { QString v = val; @@ -24,6 +27,29 @@ static QString unquote( const QString& val ) return v; } +static QString relFileNameFromDir( const QString& dir, const QString& filename ) +{ +#ifdef __DEBUG__ + printf( "0. dir: %s, filename: %s\n", qPrintable( dir ), qPrintable( filename ) ); +#endif + if ( !filename.isEmpty() ) { + QString dirpath = QFileInfo( dir.isEmpty() ? QDir::currentPath() : dir ).absoluteFilePath(); + QString filepath = QFileInfo( filename ).absoluteFilePath(); +#ifdef __DEBUG__ + printf( "1. dirpath: %s, filepath: %s\n", qPrintable( dirpath ), qPrintable( filepath ) ); +#endif + if ( filepath.startsWith( dirpath ) ) { + QString fpath = filepath.mid( dirpath.length() ); + if ( fpath.startsWith( "/" ) ) fpath.remove( 0, 1 ); +#ifdef __DEBUG__ + printf( "2. fpath: %s\n", qPrintable( fpath ) ); +#endif + return fpath; + } + } + return filename; +} + HXX2Salome::HXX2Salome() : QDialog() { setupUi( this ); @@ -100,10 +126,7 @@ void HXX2Salome::on_IncludeButton_clicked() IncludeText->text(), tr( "Include files (*.h *.hh *.hxx *.hpp)" ) ); if ( !s.isEmpty() ) { - QString CppDir = SourceTreeText->text().trimmed(); - QFileInfo fid( CppDir.isEmpty() ? QString( "." ) : CppDir ); - QFileInfo fif( s ); - IncludeText->setText( fid.canonicalFilePath() == fif.canonicalPath() ? fif.fileName() : s ); + IncludeText->setText( relFileNameFromDir( SourceTreeText->text().trimmed(), s ) ); } } @@ -114,10 +137,7 @@ void HXX2Salome::on_LibraryButton_clicked() LibraryText->text(), tr( "Shared Libraries (*.so *.dll)" ) ); if ( !s.isEmpty() ) { - QString CppDir = SourceTreeText->text().trimmed(); - QFileInfo fid( CppDir.isEmpty() ? QString( "." ) : CppDir ); - QFileInfo fif( s ); - LibraryText->setText( fid.canonicalFilePath() == fif.canonicalPath() ? fif.fileName() : s ); + LibraryText->setText( relFileNameFromDir( SourceTreeText->text().trimmed(), s ) ); } } @@ -160,8 +180,8 @@ void HXX2Salome::on_GenerateButton_clicked() tr( "Component C++ include file is not specified!" ) ); return; } - QFileInfo fifinc( CppInc ); - if ( fifinc.fileName() != CppInc && fid.canonicalFilePath() != fifinc.canonicalPath() ) { + if ( QFileInfo( CppInc ).isAbsolute() ) CppInc = relFileNameFromDir( CppDir, CppInc ); + if ( QFileInfo( CppInc ).isAbsolute() ) { QMessageBox::critical( this, tr( "Error" ), tr( "Component C++ include file is specified in directory other than\n%1!" ).arg( CppDir ) ); @@ -175,8 +195,8 @@ void HXX2Salome::on_GenerateButton_clicked() tr( "Component shared library is not specified!" ) ); return; } - QFileInfo fiflib( CppLib ); - if ( fiflib.fileName() != CppLib && fid.canonicalFilePath() != fiflib.canonicalPath() ) { + if ( QFileInfo( CppLib ).isAbsolute() ) CppLib = relFileNameFromDir( CppDir, CppLib ); + if ( QFileInfo( CppLib ).isAbsolute() ) { QMessageBox::critical( this, tr( "Error" ), tr( "Component shared library is specified in directory other than\n%1!" ).arg( CppDir ) ); @@ -212,12 +232,15 @@ void HXX2Salome::on_GenerateButton_clicked() cmdlist << quote( fienv.absoluteFilePath() ); } cmdlist << quote( fid.absoluteFilePath() ); - cmdlist << quote( fifinc.fileName() ); - cmdlist << quote( fiflib.fileName() ); + cmdlist << quote( CppInc ); + cmdlist << quote( CppLib ); cmdlist << quote( fis.absoluteFilePath() ); QString command = cmdlist.join( " " ); // execute command +#ifdef __DEBUG__ + printf( "command: %s\n", qPrintable( command ) ); +#endif QApplication::setOverrideCursor( Qt::WaitCursor ); std::system( command.toLatin1().constData() ); QApplication::restoreOverrideCursor();