From: vsr Date: Tue, 28 Jun 2005 08:39:09 +0000 (+0000) Subject: Implement ResourceExporter tool: provide command-line interface to modify user prefer... X-Git-Tag: T3_0_0_a4~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c80104831c72b258e344dbe934a79f28ea39b18f;p=modules%2Fgui.git Implement ResourceExporter tool: provide command-line interface to modify user preferences. --- diff --git a/src/Makefile.in b/src/Makefile.in index 5851d8312..e1899da8d 100755 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -34,6 +34,6 @@ VPATH=.:@srcdir@ SUBDIRS = Qtx SUIT STD CAF CAM SUITApp VTKViewer OCCViewer GLViewer \ LogWindow Event OBJECT Prs PyInterp PythonConsole ObjBrowser \ - RegistryDisplay Plot2d TOOLSGUI SOCC SVTK SPlot2d Session SalomeApp SALOME_SWIG SALOME_PY SUPERVGraph SALOME_PYQT Style + RegistryDisplay Plot2d TOOLSGUI SOCC SVTK SPlot2d Session SalomeApp SALOME_SWIG SALOME_PY SUPERVGraph SALOME_PYQT Style ResExporter @MODULE@ diff --git a/src/ResExporter/Makefile.in b/src/ResExporter/Makefile.in new file mode 100755 index 000000000..d14c977ba --- /dev/null +++ b/src/ResExporter/Makefile.in @@ -0,0 +1,30 @@ +# File : Makefile.in +# Author : Vadim SANDLER (OCN) +# Module : SalomeApp +# $Header$ + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@srcdir@/resources + + +@COMMENCE@ + + +BIN = ResourceExporter +BIN_SRC = + +CPPFLAGS += $(QT_INCLUDES) + +LDFLAGS += $(QT_MT_LIBS) +LIBS += -lsuit -lqtx + +LDFLAGSFORBIN = ${LDFLAGS} +LIBSFORBIN = $(LIBS) +@CONCLUDE@ + + + + + diff --git a/src/ResExporter/ResourceExporter.cxx b/src/ResExporter/ResourceExporter.cxx new file mode 100644 index 000000000..3cd9a1cea --- /dev/null +++ b/src/ResExporter/ResourceExporter.cxx @@ -0,0 +1,156 @@ +//====================================================================================================== +// File: ResourceExporter.cxx +// Created: 27/06/05 +// Author: Vadim SANDLER +// Copyright (C) CEA 2005 +// +// This tool provides command-line interface allowing to modify user preferences. +// The tool can be used by the compilation procedures in order to set default preferences for the module. +// +// Usage: +// ResourceExporter +// Parameters have the following format: +// '
:=' - to set for the user +// preference from the
section; +// '
:+=[|]' - the is appended to the current value +// of the preference from the
section; +// separator is used to concatenate old and new values, +// by default comma (',') symbol is used +// '-
:' - to remove user preference from the
+// section. Note that only use preference file is +// influenced, you may need to use '
:=""' +// option +// The number of parameters is limeted only by maximum possible length of the command line. +//====================================================================================================== + +#include "SUIT_ResourceMgr.h" +#include +#include +#include +#include +#include + +//============================================================ +// salomeVersion(): get the SALOME version number +//============================================================ +static QString salomeVersion() +{ + QString path( ::getenv( "GUI_ROOT_DIR" ) ); + if ( !path.isEmpty() ) + path += QDir::separator(); + path += QString( "bin/salome/VERSION" ); + + QFile vf( path ); + if ( !vf.open( IO_ReadOnly ) ) + return QString::null; + + QString line; + vf.readLine( line, 1024 ); + vf.close(); + + if ( line.isEmpty() ) + return QString::null; + + while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) ) + line.remove( line.length() - 1, 1 ); + + QString ver; + int idx = line.findRev( ":" ); + if ( idx != -1 ) + ver = line.mid( idx + 1 ).stripWhiteSpace(); + + return ver; +} + +//============================================================ +// help(): print the help information +//============================================================ +static void help() +{ + std::cout << "" << std::endl; + std::cout << "ResourceExporter: provides command-line interface to modify user preferences." << std::endl; + std::cout << "" << std::endl; + std::cout << "Usage:" << std::endl; + std::cout << " ResourceExporter " << std::endl; + std::cout << "Parameters have the following format:" << std::endl; + std::cout << " '
:=' - to set for the user " << std::endl; + std::cout << " preference from the
section;" << std::endl; + std::cout << " '
:+=[|]' - the is appended to the current value " << std::endl; + std::cout << " of the preference from the
section;" << std::endl; + std::cout << " separator is used to concatenate old and new values," << std::endl; + std::cout << " by default comma (',') symbol is used" << std::endl; + std::cout << " '-
:' - to remove user preference from the
" << std::endl; + std::cout << " section. Note that only use preference file is " << std::endl; + std::cout << " influenced, you may need to use '
:=""'" << std::endl; + std::cout << " option" << std::endl; + std::cout << "The number of parameters is limeted only by maximum possible length of the command line." << std::endl; + std::cout << "" << std::endl; +} + +//============================================================ +// main(): application main() function +//============================================================ +int main( int argc, char** argv ) +{ + QApplication app( argc, argv ); + if ( argc > 1 ) { + SUIT_ResourceMgr* resMgr = new SUIT_ResourceMgr( QString( "SalomeApp" ), QString( "%1Config" ) ); + resMgr->setVersion( salomeVersion() ); + resMgr->setVersion( QString( "3.0.0" )); + resMgr->setCurrentFormat( QString( "xml" ) ); + resMgr->loadLanguage(); + for ( int i = 1; i < argc; i ++ ) { + QString anArg = QString( argv[i] ).stripWhiteSpace(); + if ( anArg.startsWith( "-" ) ) { + anArg.remove( 0, 1 ); + if ( anArg.contains( ":" ) ) { + QStringList vals = QStringList::split( ":", anArg ); + QString section = vals[ 0 ].stripWhiteSpace(); + QString param = vals[ 1 ].stripWhiteSpace(); + if ( section.isEmpty() || param.isEmpty() ) continue; + resMgr->remove( section, param ); + } + } + else if ( anArg.contains( "+=" ) ) { + QStringList vals = QStringList::split( "+=", anArg ); + if ( vals[ 0 ].contains( ":" ) ) { + QStringList vals1 = QStringList::split( ":", vals[ 0 ] ); + QString section = vals1[ 0 ].stripWhiteSpace(); + QString param = vals1[ 1 ].stripWhiteSpace(); + QString newValue = vals [ 1 ].stripWhiteSpace(); + QString separ = ","; // default separator + if ( newValue.contains( "|" ) ) { + QStringList vals2 = QStringList::split( "|", newValue ); + newValue = vals2[ 0 ].stripWhiteSpace(); + separ = vals2[ 1 ].stripWhiteSpace(); + } + if ( section.isEmpty() || param.isEmpty() || newValue.isEmpty() || separ.isEmpty() ) continue; + QString value = resMgr->stringValue( section, param ); + QStringList valsOld = QStringList::split( separ, value ); + QStringList valsNew = QStringList::split( separ, newValue ); + for ( int i = 0; i < valsNew.count(); i++ ) + if ( !valsOld.contains( valsNew[i] ) ) + valsOld.append( valsNew[i] ); + resMgr->setValue( section, param, valsOld.join( separ ) ); + } + } + else if ( anArg.contains( "=" ) ) { + QStringList vals = QStringList::split( "=", anArg ); + if ( vals[ 0 ].contains( ":" ) ) { + QStringList vals1 = QStringList::split( ":", vals[ 0 ] ); + QString section = vals1[ 0 ].stripWhiteSpace(); + QString param = vals1[ 1 ].stripWhiteSpace(); + QString value = vals [ 1 ].stripWhiteSpace(); + if ( section.isEmpty() || param.isEmpty() ) continue; + resMgr->setValue( section, param, value ); + } + } + } + resMgr->save(); + delete resMgr; + } + else { + help(); + } + return 0; +}