]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Implement ResourceExporter tool: provide command-line interface to modify user prefer...
authorvsr <vsr@opencascade.com>
Tue, 28 Jun 2005 08:39:09 +0000 (08:39 +0000)
committervsr <vsr@opencascade.com>
Tue, 28 Jun 2005 08:39:09 +0000 (08:39 +0000)
src/Makefile.in
src/ResExporter/Makefile.in [new file with mode: 0755]
src/ResExporter/ResourceExporter.cxx [new file with mode: 0644]

index 5851d83128bc6823d5e55de19248a1bfc4c2250e..e1899da8d0d615b090609a1454d2bd3269e73fc9 100755 (executable)
@@ -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 (executable)
index 0000000..d14c977
--- /dev/null
@@ -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 (file)
index 0000000..3cd9a1c
--- /dev/null
@@ -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-list>
+// Parameters have the following format:
+//    '<section>:<name>=<new_value>'            - to set <new_value> for the user 
+//                                                preference <name> from the <section> section;
+//    '<section>:<name>+=<value>[|<separator>]' - the <value> is appended to the current value 
+//                                                of the preference <name> from the <section> section;
+//                                                separator is used to concatenate old and new values,
+//                                                by default comma (',') symbol is used
+//    '-<section>:<name>'                       - to remove user preference <name> from the <section>
+//                                                section. Note that only use preference file is 
+//                                                influenced, you may need to use '<section>:<name>=""'
+//                                                option
+// The number of parameters is limeted only by maximum possible length of the command line.
+//======================================================================================================
+
+#include "SUIT_ResourceMgr.h"
+#include <qfile.h>
+#include <qdir.h>
+#include <qstringlist.h>
+#include <qapplication.h>
+#include <iostream>
+
+//============================================================
+// 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 <parameters-list>"                                                                << std::endl;
+  std::cout << "Parameters have the following format:"                                                                << std::endl;
+  std::cout << "   '<section>:<name>=<new_value>'            - to set <new_value> for the user "                      << std::endl;
+  std::cout << "                                               preference <name> from the <section> section;"         << std::endl;
+  std::cout << "   '<section>:<name>+=<value>[|<separator>]' - the <value> is appended to the current value "         << std::endl;
+  std::cout << "                                               of the preference <name> from the <section> 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 << "   '-<section>:<name>'                       - to remove user preference <name> from the <section>"   << std::endl;
+  std::cout << "                                               section. Note that only use preference file is "       << std::endl;
+  std::cout << "                                               influenced, you may need to use '<section>:<name>=""'" << 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;
+}