Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / Style / Style_ResourceMgr.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : Style_ResourceMgr.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com)
24 //
25 #include "Style_ResourceMgr.h"
26
27 /*!
28   \class Style_ResourceMgr
29   \brief SALOME style resources manager.
30
31   This class is used to manage the SALOME style themes throughout the application
32   in the similar way as QtxResourceMgr does it with application preferences.
33
34   Standard SALOME themes are stored in the global application settings files
35   (named as SalomeStyle.xml). User-defined themes are stored in user's home
36   directory - in the file .SalomeStylerc.
37
38   The Style_ResourceMgr class is used by SALOME style preferences dialog box
39   (Style_PrefDlg class).
40 */
41
42 /*!
43   \brief Constructor
44 */
45 Style_ResourceMgr::Style_ResourceMgr()
46   : QtxResourceMgr( "SalomeStyle", "%1Config" )
47 {
48   if ( dirList().isEmpty() && ::getenv( "GUI_ROOT_DIR" ) )
49     setDirList( QStringList() << Qtx::addSlash( ::getenv( "GUI_ROOT_DIR" ) ) + "share/salome/resources/gui" );
50   setCurrentFormat( "xml" );
51 }
52
53 /*!
54   \brief Destructor
55 */
56 Style_ResourceMgr::~Style_ResourceMgr()
57 {
58 }
59
60 /*!
61   \brief Get list of avaiable SALOME themes
62   \param type themes type
63   \param sort if \c true (default), returns a list of themes sorted by name
64   \return list of avaiable themes names
65 */
66 QStringList Style_ResourceMgr::styles( StyleType type, bool sort )
67 {
68   QStringList sl;
69   
70   WorkingMode m = workingMode();
71
72   switch ( type ) {
73   case Global:
74     setWorkingMode( IgnoreUserValues );
75     sl = sections();
76     break;
77   case User:
78     {
79       setWorkingMode( AllowUserValues );
80       sl = sections();
81       setWorkingMode( IgnoreUserValues );
82       QMutableListIterator<QString> it( sl );
83       while ( it.hasNext() ) {
84         QString s = it.next();
85         if ( hasSection( s ) ) it.remove();
86       }
87     }
88     break;
89   case All:
90     setWorkingMode( AllowUserValues );
91     sl = sections();
92     break;
93   default:
94     break;
95   }
96
97   setWorkingMode( m );
98
99   if ( sort )
100     qSort( sl );
101
102   return sl;
103 }