libyui  3.3.1
YSettings.cc
1 /*
2  Copyright (c) 2012 Björn Esser
3 
4  Permission is hereby granted, free of charge, to any person obtaining
5  a copy of this software and associated documentation files (the
6  "Software"), to deal in the Software without restriction, including
7  without limitation the rights to use, copy, modify, merge, publish,
8  distribute, sublicense, and/or sell
9  copies of the Software, and to permit persons to whom the Software is
10  furnished to do so, subject to the following conditions:
11 
12  The above copyright notice and this permission notice shall be
13  included in all copies or substantial portions of the Software.
14 
15  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
18  SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 
24 
25 /*-/
26 
27  File: YSettings.cc
28 
29  Author: Björn Esser <bjoern.esser@gmail.com>
30 
31 /-*/
32 
33 #include "YSettings.h"
34 #include "YUIException.h"
35 
36 #define YUILogComponent "ui"
37 #include "YUILog.h"
38 #include "Libyui_config.h"
39 
40 using std::endl;
41 
42 std::string YSettings::_progDir = "";
43 std::string YSettings::_iconDir = "";
44 std::string YSettings::_themeDir = "";
45 std::string YSettings::_localeDir = "";
46 std::string YSettings::_loadedUI = "";
47 
48 YSettings::YSettings()
49 {
50 }
51 
52 YSettings::~YSettings ()
53 {
54 }
55 
56 void YSettings::setProgDir( std::string directory )
57 {
58  if ( _progDir.empty() )
59  {
60  _progDir = directory;
61  yuiMilestone () << "Set progDir to \"" << directory << "\"" << endl;
62  yuiMilestone () << "progDir is now locked." << endl;
63  }
64  else
65  {
66  yuiMilestone () << "Can't set progDir to \"" << directory << "\"" << endl;
67  yuiMilestone () << "It is locked to: \"" << _progDir << "\"" << endl;
68  YUI_THROW ( YUIException ( "progSubDir is locked to: \"" + _progDir + "\"" ) );
69  }
70 }
71 
72 std::string YSettings::progDir ()
73 {
74  yuiMilestone () << "progDir: \"" << _progDir << "\"" << endl;
75 
76  return _progDir;
77 }
78 
79 
80 void YSettings::setIconDir( std::string directory )
81 {
82  if ( _iconDir.empty() )
83  {
84  _iconDir = directory;
85  yuiMilestone () << "Set iconDir to \"" << directory << "\"" << endl;
86  yuiMilestone () << "iconDir is now locked." << endl;
87  }
88  else
89  {
90  yuiMilestone () << "Can't set iconDir to \"" << directory << "\"" << endl;
91  yuiMilestone () << "It is locked to: \"" << _iconDir << "\"" << endl;
92  YUI_THROW ( YUIException ( "progIconDir is locked to: \"" + _iconDir + "\"" ) );
93  }
94 }
95 
96 std::string YSettings::iconDir ()
97 {
98  if (_iconDir.size())
99  {
100  yuiMilestone () << "iconDir: \"" << _iconDir << "\"" << endl;
101  return _iconDir;
102  }
103  else if (_progDir.size())
104  return _progDir + "/icons/";
105 
106  return THEMEDIR "/icons/";
107 }
108 
109 void YSettings::setThemeDir( std::string directory )
110 {
111  if ( _themeDir.empty() )
112  {
113  _themeDir = directory;
114  yuiMilestone () << "Set themeDir to \"" << directory << "\"" << endl;
115  yuiMilestone () << "themeDir is now locked." << endl;
116  }
117  else
118  {
119  yuiMilestone () << "Can't set themeDir to \"" << directory << "\"" << endl;
120  yuiMilestone () << "It is locked to: \"" << _themeDir << "\"" << endl;
121  YUI_THROW ( YUIException ( "themeDir is locked to: \"" + _themeDir + "\"" ) );
122  }
123 }
124 
125 std::string YSettings::themeDir ()
126 {
127  if ( _themeDir.size() )
128  {
129  yuiMilestone () << "themeDir: \"" << _themeDir << "\"" << endl;
130  return _themeDir;
131  }
132  else if ( _progDir.size() )
133  {
134  //back compatibility if setProgSubDir is set to "/usr/share/YaST2"
135  return _progDir + "/theme/current/wizard/";
136  }
137 
138  return THEMEDIR "/current/wizard/";
139 }
140 
141 
142 void YSettings::setLocaleDir( std::string directory )
143 {
144  if ( _localeDir.empty() )
145  {
146  _localeDir = directory;
147  yuiMilestone () << "Set localeDir to \"" << directory << "\"" << endl;
148  yuiMilestone () << "localeDir is now locked." << endl;
149  }
150  else
151  {
152  yuiMilestone () << "Can't set localeDir to \"" << directory << "\"" << endl;
153  yuiMilestone () << "It is locked to: \"" << _localeDir << "\"" << endl;
154  YUI_THROW ( YUIException ( "localeDir is locked to: \"" + _localeDir + "\"" ) );
155  }
156 }
157 
158 std::string YSettings::localeDir ()
159 {
160  if ( _localeDir.size() )
161  {
162  yuiMilestone () << "localeDir: \"" << _localeDir << "\"" << endl;
163  return _localeDir;
164  }
165  else if ( _progDir.size() )
166  {
167  //back compatibility if ProgDir is set to "/usr/share/YaST2"
168  return _progDir + "/locale/";
169  }
170 
171  return "/usr/share/locale/";
172 }
173 
174 void YSettings::loadedUI( std::string ui, bool force )
175 {
176  if ( _loadedUI.empty() || force )
177  {
178  _loadedUI = ui;
179  yuiMilestone () << "Set loadedUI to \"" << ui << "\"" << endl;
180  yuiMilestone () << "loadedUI is now locked." << endl;
181  }
182  else
183  {
184  yuiMilestone () << "Can't set loadedUI to \"" << ui << "\"" << endl;
185  yuiMilestone () << "It is locked to: \"" << _loadedUI << "\"" << endl;
186  YUI_THROW ( YUIException ( "loadedUI is locked to: \"" + _loadedUI + "\"" ) );
187  }
188 }
189 
190 void YSettings::loadedUI( std::string ui )
191 {
192  loadedUI( ui, false );
193 }
194 
195 std::string YSettings::loadedUI ()
196 {
197  yuiMilestone () << "loadedUI: \"" << _loadedUI << "\"" << endl;
198 
199  return _loadedUI;
200 }
static std::string localeDir()
Returns the value of your program&#39;s locale subdir.
Definition: YSettings.cc:158
static void setIconDir(std::string directory)
This can be used to set a subdir ICONDIR, where your program stores a custom icons.
Definition: YSettings.cc:80
static void setThemeDir(std::string directory)
This can be used to set a subdir THEMEDIR, where your program stores a custom icons.
Definition: YSettings.cc:109
static std::string loadedUI()
Returns the value of the loaded UI-backend.
Definition: YSettings.cc:195
static void setProgDir(std::string directory)
This can be used to set a subdir beneath PLUGINDIR or THEMEDIR, where your program stores a custom pl...
Definition: YSettings.cc:56
static void setLocaleDir(std::string directory)
This can be used to set a subdir LOCALEDIR, where your program stores translations.
Definition: YSettings.cc:142
static std::string iconDir()
Returns the value of your program&#39;s icons subdir.
Definition: YSettings.cc:96
static std::string themeDir()
Returns the value of your program&#39;s theme subdir.
Definition: YSettings.cc:125
static std::string progDir()
Returns the value of your program&#39;s subdir.
Definition: YSettings.cc:72
Base class for UI Exceptions.
Definition: YUIException.h:297