From 4aa915406f16413f41208431cd7904815c2e527b Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 19 Apr 2006 14:13:28 +0000 Subject: [PATCH] Improve modules configuration an launching procedure: - allow reading of user configuration files from previous SALOME versions on startup if current is not found - allow imporing additional configuration files from GUI - use own configuration file for each SALOME module --- src/LightApp/LightApp_PreferencesDlg.cxx | 26 +++++++++++- src/LightApp/LightApp_PreferencesDlg.h | 1 + src/Qtx/QtxResourceMgr.cxx | 51 +++++++++++++++++++++++- src/Qtx/QtxResourceMgr.h | 3 +- src/SUIT/SUIT_ResourceMgr.cxx | 48 +++++++++++++++++++++- src/SUIT/SUIT_ResourceMgr.h | 4 +- 6 files changed, 127 insertions(+), 6 deletions(-) diff --git a/src/LightApp/LightApp_PreferencesDlg.cxx b/src/LightApp/LightApp_PreferencesDlg.cxx index 981e9e616..bbd81314e 100644 --- a/src/LightApp/LightApp_PreferencesDlg.cxx +++ b/src/LightApp/LightApp_PreferencesDlg.cxx @@ -20,7 +20,6 @@ // Author: Sergey TELKOV #include "LightApp_PreferencesDlg.h" - #include "LightApp_Preferences.h" #include "QtxResourceMgr.h" @@ -29,6 +28,7 @@ #include #include #include +#include /*! Constructor. @@ -58,6 +58,9 @@ myPrefs( prefs ), mySaved ( false ) QButton* defBtn = userButton( insertButton( tr( "DEFAULT_BTN_TEXT" ) ) ); if ( defBtn ) connect( defBtn, SIGNAL( clicked() ), this, SLOT( onDefault() ) ); + QButton* impBtn = userButton( insertButton( tr( "IMPORT_BTN_TEXT" ) ) ); + if( impBtn ) + connect( impBtn, SIGNAL( clicked() ), this, SLOT( onImportPref() ) ); } /*! @@ -132,3 +135,24 @@ void LightApp_PreferencesDlg::onDefault() } } } + +/*! Import preferences from some file */ +void LightApp_PreferencesDlg::onImportPref() +{ + QtxResourceMgr* mgr = myPrefs->resourceMgr(); + if( !mgr ) + return; + + QFileDialog dlg( ".", "*", this, "", tr( "IMPORT_PREFERENCES" ) ); + dlg.setShowHiddenFiles( true ); + dlg.exec(); + QString fname = dlg.selectedFile(); + if( fname.isEmpty() ) + return; + + if( mgr->import( fname ) ) + { + myPrefs->retrieve(); + myPrefs->toBackup(); + } +} diff --git a/src/LightApp/LightApp_PreferencesDlg.h b/src/LightApp/LightApp_PreferencesDlg.h index 771714519..91c9d3439 100644 --- a/src/LightApp/LightApp_PreferencesDlg.h +++ b/src/LightApp/LightApp_PreferencesDlg.h @@ -47,6 +47,7 @@ private slots: void onHelp(); void onApply(); void onDefault(); + void onImportPref(); private: LightApp_Preferences* myPrefs; diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index d5376b7e0..c6c417498 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -408,7 +408,10 @@ bool QtxResourceMgr::XmlFormat::load( const QString& fname, QMapmyFileName ) ); - return save( res->myFileName, res->mySections ); + QtxResourceMgr* mgr = res->resMgr(); + QString name = mgr ? mgr->userFileName( mgr->appName(), false ) : res->myFileName; + return save( name, res->mySections ); } /*! @@ -1343,6 +1370,26 @@ bool QtxResourceMgr::load() return res; } +/*! + \brief Import some file with resources +*/ +bool QtxResourceMgr::import( const QString& fname ) +{ + Format* fmt = format( currentFormat() ); + if ( !fmt ) + return false; + + Resources* r = myResources.getFirst(); + if( !r ) + return false; + + QString old = r->file(); + r->setFile( fname ); + bool res = fmt->load( r ); + r->setFile( old ); + return res; +} + /*! \brief Save the changed resources in to the user resource file. */ @@ -1618,7 +1665,7 @@ void QtxResourceMgr::setResource( const QString& sect, const QString& name, cons myResources.first()->setValue( sect, name, val ); } -QString QtxResourceMgr::userFileName( const QString& appName ) const +QString QtxResourceMgr::userFileName( const QString& appName, const bool /*for_load*/ ) const { QString fileName; QString pathName = QDir::homeDirPath(); diff --git a/src/Qtx/QtxResourceMgr.h b/src/Qtx/QtxResourceMgr.h index f75345425..bcaa4ebf5 100644 --- a/src/Qtx/QtxResourceMgr.h +++ b/src/Qtx/QtxResourceMgr.h @@ -133,6 +133,7 @@ public: QString path( const QString&, const QString&, const QString& ) const; bool load(); + bool import( const QString& ); bool save(); QStringList sections() const; @@ -144,7 +145,7 @@ protected: virtual void setDirList( const QStringList& ); virtual void setResource( const QString&, const QString&, const QString& ); - virtual QString userFileName( const QString& ) const; + virtual QString userFileName( const QString&, const bool = true ) const; virtual QString globalFileName( const QString& ) const; private: diff --git a/src/SUIT/SUIT_ResourceMgr.cxx b/src/SUIT/SUIT_ResourceMgr.cxx index ed8f3a872..6ccda641e 100755 --- a/src/SUIT/SUIT_ResourceMgr.cxx +++ b/src/SUIT/SUIT_ResourceMgr.cxx @@ -18,6 +18,9 @@ // #include "SUIT_ResourceMgr.h" +#include +#include + /*! Constructor */ @@ -64,12 +67,55 @@ QString SUIT_ResourceMgr::loadDoc( const QString& prefix, const QString& id ) co /*! Returns the user file name for specified application */ -QString SUIT_ResourceMgr::userFileName( const QString& appName ) const +QString SUIT_ResourceMgr::userFileName( const QString& appName, const bool for_load ) const { QString pathName = QtxResourceMgr::userFileName( appName ); if ( !version().isEmpty() ) pathName += QString( "." ) + version(); + if( !QFileInfo( pathName ).exists() && for_load ) + { + QString newName = findAppropriateUserFile( pathName ); + if( !newName.isEmpty() ) + pathName = newName; + } + return pathName; } + +/*! + Finds other the most appropriate user file instead missing one +*/ +QString SUIT_ResourceMgr::findAppropriateUserFile( const QString& fname ) const +{ + QDir d( QFileInfo( fname ).dir( true ) ); + d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks ); + QStringList l = d.entryList(); + QString appr_file; + int id0 = userFileId( fname ), id, appr=-1; + if( id0<0 ) + return appr_file; + + for( QStringList::const_iterator anIt = l.begin(), aLast = l.end(); anIt!=aLast; anIt++ ) + { + id = userFileId( *anIt ); + if( id<0 ) + continue; + + if( abs( id-id0 ) < abs( appr-id0 ) ) + { + appr = id; + appr_file = d.absFilePath( *anIt ); + } + } + return appr_file; +} + +/*! + Calculates integer extended version number by user file name for comparing +*/ +int SUIT_ResourceMgr::userFileId( const QString& ) const +{ + return -1; +} diff --git a/src/SUIT/SUIT_ResourceMgr.h b/src/SUIT/SUIT_ResourceMgr.h index 2b1a18bec..ebb380446 100755 --- a/src/SUIT/SUIT_ResourceMgr.h +++ b/src/SUIT/SUIT_ResourceMgr.h @@ -35,7 +35,9 @@ public: QString loadDoc( const QString&, const QString& ) const; protected: - virtual QString userFileName( const QString& ) const; + virtual QString userFileName( const QString&, const bool = true ) const; + virtual QString findAppropriateUserFile( const QString& ) const; + virtual int userFileId( const QString& ) const; private: QString myVersion; -- 2.39.2