-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include <stdlib.h>
+/* XPM for the default pixmap */
+static const char* pixmap_not_found_xpm[] = {
+"16 16 3 1",
+" c None",
+". c #000000",
+"+ c #A80000",
+" ",
+" ",
+" . . ",
+" .+. .+. ",
+" .+++. .+++. ",
+" .+++.+++. ",
+" .+++++. ",
+" .+++. ",
+" .+++++. ",
+" .+++.+++. ",
+" .+++. .+++. ",
+" .+. .+. ",
+" . . ",
+" ",
+" ",
+" "};
+
/*!
\class QtxResourceMgr::Resources
\internal
QString QtxResourceMgr::Resources::fileName( const QString& sect, const QString& prefix, const QString& name ) const
{
QString path;
- if ( hasValue( sect, prefix ) )
+ if ( !QFileInfo( name ).isRelative() )
{
- path = value( sect, prefix, true );
- if ( !path.isEmpty() )
+ path = name;
+ }
+ else
+ {
+ if ( hasValue( sect, prefix ) )
{
- if ( QFileInfo( path ).isRelative() )
- path = Qtx::addSlash( Qtx::dir( myFileName, true ) ) + path;
-
- path = Qtx::addSlash( path ) + name;
+ path = value( sect, prefix, true );
+ if ( !path.isEmpty() )
+ {
+ if ( QFileInfo( path ).isRelative() )
+ path = Qtx::addSlash( Qtx::dir( myFileName, true ) ) + path;
+
+ path = Qtx::addSlash( path ) + name;
+ }
}
}
if( !path.isEmpty() )
Note, that setValue() method always put the value to the user settings file.
\param mode new working mode
+ \return previous working mode
\sa workingMode(), value(), hasValue(), hasSection(), setValue()
*/
-void QtxResourceMgr::setWorkingMode( WorkingMode mode )
+QtxResourceMgr::WorkingMode QtxResourceMgr::setWorkingMode( WorkingMode mode )
{
+ WorkingMode m = myWorkingMode;
myWorkingMode = mode;
+ return m;
}
/*!
if ( myResources.isEmpty() || !myHasUserValues )
return true;
- return fmt->save( myResources[0] );
+ bool result = fmt->save( myResources[0] );
+
+ saved();
+
+ return result;
}
/*!
*/
QPixmap QtxResourceMgr::defaultPixmap() const
{
- QPixmap res;
- if ( myDefaultPix && !myDefaultPix->isNull() )
- res = *myDefaultPix;
- return res;
+ static QPixmap* defpx = 0;
+ if ( !defpx )
+ defpx = new QPixmap( pixmap_not_found_xpm );
+
+ return myDefaultPix ? *myDefaultPix : *defpx;
}
/*!
if ( pref.isEmpty() && lang != "en" ) {
// load Qt resources
QString qt_translations = QLibraryInfo::location( QLibraryInfo::TranslationsPath );
- QString qt_dir_trpath;
- if ( ::getenv( "QTDIR" ) )
- qt_dir_trpath = QString( ::getenv( "QTDIR" ) );
+ QString qt_dir_trpath = qgetenv( "QT_ROOT_DIR" );
+ if ( qt_dir_trpath.isEmpty() )
+ qt_dir_trpath = qgetenv( "QTDIR" );
if ( !qt_dir_trpath.isEmpty() )
qt_dir_trpath = QDir( qt_dir_trpath ).absoluteFilePath( "translations" );
QTranslator* trans = new QtxTranslator( 0 );
- if ( trans->load( QString("qt_%1").arg( lang ), qt_translations ) || trans->load( QString("qt_%1").arg( lang ), qt_dir_trpath ) )
- QApplication::instance()->installTranslator( trans );
+ if ( trans->load( QString("qt_%1").arg( lang ), qt_translations ) || trans->load( QString("qt_%1").arg( lang ), qt_dir_trpath ) ) {
+ if ( QApplication::instance() ) QApplication::instance()->installTranslator( trans );
+ }
}
for ( QStringList::ConstIterator iter = prefixList.begin(); iter != prefixList.end(); ++iter )
{
if ( !myTranslator[prefix].contains( trans ) )
myTranslator[prefix].append( trans );
- QApplication::instance()->installTranslator( trans );
+ if ( QApplication::instance() ) QApplication::instance()->installTranslator( trans );
}
}
}
{
if ( !myTranslator[prefix].contains( trans ) )
myTranslator[prefix].append( trans );
- QApplication::instance()->installTranslator( trans );
+ if ( QApplication::instance() ) QApplication::instance()->installTranslator( trans );
}
}
}
for ( TransList::Iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it )
{
- QApplication::instance()->removeTranslator( *it );
+ if ( QApplication::instance() ) QApplication::instance()->removeTranslator( *it );
delete *it;
}
for ( TransList::Iterator it = myTranslator[prefix].begin(); it != myTranslator[prefix].end(); ++it )
{
- QApplication::instance()->removeTranslator( *it );
- QApplication::instance()->installTranslator( *it );
+ if ( QApplication::instance() ) {
+ QApplication::instance()->removeTranslator( *it );
+ QApplication::instance()->installTranslator( *it );
+ }
}
}
{
QString fileName;
QString pathName = QDir::homePath();
-
QString cfgAppName = QApplication::applicationName();
if ( !cfgAppName.isEmpty() )
pathName = Qtx::addSlash( Qtx::addSlash( pathName ) + QString( ".config" ) ) + cfgAppName;
#ifdef WIN32
fileName = QString( "%1.%2" ).arg( appName ).arg( currentFormat() );
#else
- fileName = QString( ".%1rc" ).arg( appName );
+ fileName = QString( "%1rc" ).arg( appName );
+ // VSR 24/09/2012: issue 0021781: do not prepend filename with "."
+ // when user file is stored in ~/.config/<appname> directory
+ if ( cfgAppName.isEmpty() )
+ fileName.prepend( "." );
#endif
if ( !fileName.isEmpty() )
return QString( "%1.%2" ).arg( appName ).arg( currentFormat() );
}
+/*!
+ \brief This function is called after user configuration file is saved.
+ Can be redefined in the successor classes, default implementation does nothing.
+*/
+void QtxResourceMgr::saved()
+{
+}
+
/*!
\brief Perform substitution of the patterns like \%A, \%B, etc by values from the map.