1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "SUIT_ResourceMgr.h"
21 #include <qfileinfo.h>
23 #include <qapplication.h>
29 SUIT_ResourceMgr::SUIT_ResourceMgr( const QString& app, const QString& resVarTemplate )
30 : QtxResourceMgr( app, resVarTemplate )
37 SUIT_ResourceMgr::~SUIT_ResourceMgr()
42 Returns the version of application
44 QString SUIT_ResourceMgr::version() const
50 Sets the version of application
52 void SUIT_ResourceMgr::setVersion( const QString& ver )
58 Loads a doc page from 'prefix' resources and indetified by 'id'
60 QString SUIT_ResourceMgr::loadDoc( const QString& prefix, const QString& id ) const
62 QString docSection = option( "doc_section_name" );
63 if ( docSection.isEmpty() )
64 docSection = QString( "docs" );
66 return path( docSection, prefix, id );
73 Returns the user file name for specified application
75 QString SUIT_ResourceMgr::userFileName( const QString& appName, const bool for_load ) const
79 // Try config file, given in arguments
80 for (int i = 1; i < qApp->argc(); i++) {
81 QRegExp rx ("--resources=(.+)");
82 if ( rx.search( QString(qApp->argv()[i]) ) >= 0 && rx.capturedTexts().count() > 1 ) {
83 QString file = rx.capturedTexts()[1];
85 pathName = fi.absFilePath();
89 if (!pathName.isEmpty())
92 // QtxResourceMgr::userFileName() + '.' + version()
93 pathName = QtxResourceMgr::userFileName( appName );
95 if ( !version().isEmpty() )
96 pathName += QString( "." ) + version();
98 if ( !QFileInfo( pathName ).exists() && for_load )
100 QString newName = findAppropriateUserFile( pathName );
101 if ( !newName.isEmpty() )
109 Finds other the most appropriate user file instead missing one
111 QString SUIT_ResourceMgr::findAppropriateUserFile( const QString& fname ) const
113 QDir d( QFileInfo( fname ).dir( true ) );
114 d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
115 QStringList l = d.entryList();
117 int id0 = userFileId( fname ), id, appr=-1;
121 for( QStringList::const_iterator anIt = l.begin(), aLast = l.end(); anIt!=aLast; anIt++ )
123 id = userFileId( *anIt );
127 if( appr < 0 || abs( id-id0 ) < abs( appr-id0 ) )
130 appr_file = d.absFilePath( *anIt );
137 Calculates integer extended version number by user file name for comparing
139 int SUIT_ResourceMgr::userFileId( const QString& ) const