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/
19 #include "SUIT_ResourceMgr.h"
21 #include <qfileinfo.h>
27 SUIT_ResourceMgr::SUIT_ResourceMgr( const QString& app, const QString& resVarTemplate )
28 : QtxResourceMgr( app, resVarTemplate )
35 SUIT_ResourceMgr::~SUIT_ResourceMgr()
40 Returns the version of application
42 QString SUIT_ResourceMgr::version() const
48 Sets the version of application
50 void SUIT_ResourceMgr::setVersion( const QString& ver )
56 Loads a doc page from 'prefix' resources and indetified by 'id'
58 QString SUIT_ResourceMgr::loadDoc( const QString& prefix, const QString& id ) const
60 QString docSection = option( "doc_section_name" );
61 if ( docSection.isEmpty() )
62 docSection = QString( "docs" );
64 return path( docSection, prefix, id );
69 Returns the user file name for specified application
71 QString SUIT_ResourceMgr::userFileName( const QString& appName, const bool for_load ) const
73 QString pathName = QtxResourceMgr::userFileName( appName );
75 if ( !version().isEmpty() )
76 pathName += QString( "." ) + version();
78 if( !QFileInfo( pathName ).exists() && for_load )
80 QString newName = findAppropriateUserFile( pathName );
81 if( !newName.isEmpty() )
89 Finds other the most appropriate user file instead missing one
91 QString SUIT_ResourceMgr::findAppropriateUserFile( const QString& fname ) const
93 QDir d( QFileInfo( fname ).dir( true ) );
94 d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
95 QStringList l = d.entryList();
97 int id0 = userFileId( fname ), id, appr=-1;
101 for( QStringList::const_iterator anIt = l.begin(), aLast = l.end(); anIt!=aLast; anIt++ )
103 id = userFileId( *anIt );
107 if( abs( id-id0 ) < abs( appr-id0 ) )
110 appr_file = d.absFilePath( *anIt );
117 Calculates integer extended version number by user file name for comparing
119 int SUIT_ResourceMgr::userFileId( const QString& ) const