X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSUIT%2FSUIT_ResourceMgr.cxx;h=0c98e4a2dc1daed5bf62a1461ef715677a13598b;hb=efe3cdefadc31ad9cdaa9fd7fc368e2931cebdf1;hp=b2fa90dcf41cb6f1db3fd78c729bcdfb33bfafca;hpb=e07448c48ea5b2127e34fc7b8c3427d01c7ce17b;p=modules%2Fgui.git diff --git a/src/SUIT/SUIT_ResourceMgr.cxx b/src/SUIT/SUIT_ResourceMgr.cxx index b2fa90dcf..0c98e4a2d 100755 --- a/src/SUIT/SUIT_ResourceMgr.cxx +++ b/src/SUIT/SUIT_ResourceMgr.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 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 @@ -6,7 +6,7 @@ // 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 @@ -21,6 +21,7 @@ // #include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" #include #include @@ -81,11 +82,12 @@ QString SUIT_ResourceMgr::userFileName( const QString& appName, const bool for_l { QString pathName; - QStringList arguments = QApplication::arguments(); + QStringList arguments; + if ( SUIT_Session::session() ) arguments = SUIT_Session::session()->arguments(); // Try config file, given in arguments for (int i = 1; i < arguments.count(); i++) { QRegExp rx ("--resources=(.+)"); - if ( rx.indexIn( arguments[i] ) >= 0 && rx.numCaptures() > 1 ) { + if ( rx.indexIn( arguments[i] ) >= 0 && rx.captureCount() > 0 ) { QString file = rx.cap(1); QFileInfo fi (file); pathName = fi.absoluteFilePath(); @@ -125,40 +127,45 @@ QString SUIT_ResourceMgr::findAppropriateUserFile( const QString& fname ) const long id, appr = -1; + QStringList all_files; + // get all files from the same dir where use file is (should be) situated QDir d( QFileInfo( fname ).dir() ); if ( d.exists() ) { d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks ); QStringList l = d.entryList(); - for( QStringList::const_iterator anIt = l.begin(), aLast = l.end(); anIt!=aLast; anIt++ ) - { - id = userFileId( *anIt ); - if ( id < 0 ) - continue; - if( appr < 0 || qAbs( id-id0 ) < qAbs( appr-id0 ) ) - { - appr = id; - appr_file = d.absoluteFilePath( *anIt ); - } - } + foreach( QString ll, l ) + all_files << d.absoluteFilePath( ll ); } - // backward compatibility: check also user's home directory (if it differs from above one) QDir home = QDir::home(); if ( home.exists() && d.canonicalPath() != home.canonicalPath() ) { home.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks ); QStringList l = home.entryList(); + foreach( QString ll, l ) + all_files << home.absoluteFilePath( ll ); + } + + for( QStringList::const_iterator anIt = all_files.begin(), aLast = all_files.end(); anIt!=aLast; anIt++ ) + { + id = userFileId( *anIt ); + if ( id < 0 ) + continue; - for( QStringList::const_iterator anIt = l.begin(), aLast = l.end(); anIt!=aLast; anIt++ ) + if( appr < 0 || qAbs( id-id0 ) < qAbs( appr-id0 ) ) { - id = userFileId( *anIt ); - if ( id < 0 ) - continue; - if( appr < 0 || qAbs( id-id0 ) < qAbs( appr-id0 ) ) - { - appr = id; + appr = id; + appr_file = d.absoluteFilePath( *anIt ); + } + else if ( qAbs( id-id0 ) == qAbs( appr-id0 ) ) { + // appr == id that means that another file with equal version id is detected + // this can happen, e.g. if one file begins with "." and other one - not + // ... + // VSR 24/09/2012: issue 0021781: since version 6.6.0 user filename is not prepended with "." + // when it is stored in the ~/.config/ directory; + // for backward compatibility we also check files prepended with "." with lower priority + if ( !QFileInfo( *anIt ).fileName().startsWith(".") ) appr_file = home.absoluteFilePath( *anIt ); - } } } @@ -172,3 +179,21 @@ long SUIT_ResourceMgr::userFileId( const QString& ) const { return -1; } + +/*! + \brief Specify default language for the application. +*/ +QString SUIT_ResourceMgr::defaultLanguage() const +{ + QStringList arguments; + QString language; + if ( SUIT_Session::session() ) arguments = SUIT_Session::session()->arguments(); + // Try language, given in arguments + for (int i = 1; i < arguments.count(); i++) { + QRegExp rx ("--language=(.+)"); + if ( rx.indexIn( arguments[i] ) >= 0 && rx.captureCount() > 0 ) { + language = rx.cap(1); + } + } + return language; +}