Salome HOME
Copyright update 2022
[modules/gui.git] / src / Style / Style_ResourceMgr.cxx
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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, or (at your option) any later version.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File   : Style_ResourceMgr.cxx
21 // Author : Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com)
22 //
23 #include "Style_ResourceMgr.h"
24
25 /*!
26   \class Style_ResourceMgr
27   \brief SALOME style resources manager.
28
29   This class is used to manage the SALOME style themes throughout the application
30   in the similar way as QtxResourceMgr does it with application preferences.
31
32   Standard SALOME themes are stored in the global application settings files
33   (named as SalomeStyle.xml). User-defined themes are stored in user's home
34   directory - in the file .SalomeStylerc.
35
36   The Style_ResourceMgr class is used by SALOME style preferences dialog box
37   (Style_PrefDlg class).
38 */
39
40 /*!
41   \brief Constructor
42 */
43 Style_ResourceMgr::Style_ResourceMgr()
44   : QtxResourceMgr( "SalomeStyle", "%1Config" )
45 {
46   QString gui_root = Qtx::getenv( "GUI_ROOT_DIR" );
47   if ( dirList().isEmpty() && !gui_root.isEmpty() )
48     setDirList( QStringList() << Qtx::addSlash( gui_root ) + "share/salome/resources/gui" );
49   setCurrentFormat( "xml" );
50 }
51
52 /*!
53   \brief Destructor
54 */
55 Style_ResourceMgr::~Style_ResourceMgr()
56 {
57 }
58
59 /*!
60   \brief Get list of avaiable SALOME themes
61   \param type themes type
62   \param sort if \c true (default), returns a list of themes sorted by name
63   \return list of avaiable themes names
64 */
65 QStringList Style_ResourceMgr::styles( StyleType type, bool sort )
66 {
67   QStringList sl;
68   
69   WorkingMode m = workingMode();
70
71   switch ( type ) {
72   case Global:
73     setWorkingMode( IgnoreUserValues );
74     sl = sections();
75     break;
76   case User:
77     {
78       setWorkingMode( AllowUserValues );
79       sl = sections();
80       setWorkingMode( IgnoreUserValues );
81       QMutableListIterator<QString> it( sl );
82       while ( it.hasNext() ) {
83         QString s = it.next();
84         if ( hasSection( s ) ) it.remove();
85       }
86     }
87     break;
88   case All:
89     setWorkingMode( AllowUserValues );
90     sl = sections();
91     break;
92   default:
93     break;
94   }
95
96   setWorkingMode( m );
97
98   if ( sort )
99     qSort( sl );
100
101   return sl;
102 }