libyui  3.9.3
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::string;
41 
42 string YSettings::_progDir = "";
43 string YSettings::_iconDir = "";
44 string YSettings::_themeDir = "";
45 string YSettings::_localeDir = "";
46 string YSettings::_loadedUI = "";
47 
48 
49 YSettings::YSettings()
50 {
51 }
52 
53 
54 YSettings::~YSettings ()
55 {
56 }
57 
58 void YSettings::setProgDir( string directory )
59 {
60  if ( _progDir.empty() )
61  {
62  _progDir = directory;
63  yuiDebug () << "Set progDir to \"" << directory << "\"" << endl;
64  yuiDebug () << "progDir is now locked." << endl;
65  }
66  else
67  {
68  yuiDebug () << "Can't set progDir to \"" << directory << "\"" << endl;
69  yuiDebug () << "It is locked to: \"" << _progDir << "\"" << endl;
70  YUI_THROW ( YUIException ( "progSubDir is locked to: \"" + _progDir + "\"" ) );
71  }
72 }
73 
75 {
76  yuiDebug () << "progDir: \"" << _progDir << "\"" << endl;
77 
78  return _progDir;
79 }
80 
81 
82 void YSettings::setIconDir( string directory )
83 {
84  if ( _iconDir.empty() )
85  {
86  _iconDir = directory;
87  yuiDebug () << "Set iconDir to \"" << directory << "\"" << endl;
88  yuiDebug () << "iconDir is now locked." << endl;
89  }
90  else
91  {
92  yuiDebug () << "Can't set iconDir to \"" << directory << "\"" << endl;
93  yuiDebug () << "It is locked to: \"" << _iconDir << "\"" << endl;
94  YUI_THROW ( YUIException ( "progIconDir is locked to: \"" + _iconDir + "\"" ) );
95  }
96 }
97 
98 
100 {
101  if (_iconDir.size())
102  {
103  yuiDebug () << "iconDir: \"" << _iconDir << "\"" << endl;
104  return _iconDir;
105  }
106  else if (_progDir.size())
107  return _progDir + "/icons/";
108 
109  return THEMEDIR "/icons/";
110 }
111 
112 
113 void YSettings::setThemeDir( string directory )
114 {
115  if ( _themeDir.empty() )
116  {
117  _themeDir = directory;
118  yuiDebug () << "Set themeDir to \"" << directory << "\"" << endl;
119  yuiDebug () << "themeDir is now locked." << endl;
120  }
121  else
122  {
123  yuiDebug () << "Can't set themeDir to \"" << directory << "\"" << endl;
124  yuiDebug () << "It is locked to: \"" << _themeDir << "\"" << endl;
125  YUI_THROW ( YUIException ( "themeDir is locked to: \"" + _themeDir + "\"" ) );
126  }
127 }
128 
129 
131 {
132  if ( _themeDir.size() )
133  {
134  yuiDebug () << "themeDir: \"" << _themeDir << "\"" << endl;
135  return _themeDir;
136  }
137  else if ( _progDir.size() )
138  {
139  //back compatibility if setProgSubDir is set to "/usr/share/YaST2"
140  return _progDir + "/theme/current/wizard/";
141  }
142 
143  return THEMEDIR "/current/wizard/";
144 }
145 
146 
147 void YSettings::setLocaleDir( string directory )
148 {
149  if ( _localeDir.empty() )
150  {
151  _localeDir = directory;
152  yuiDebug () << "Set localeDir to \"" << directory << "\"" << endl;
153  yuiDebug () << "localeDir is now locked." << endl;
154  }
155  else
156  {
157  yuiDebug () << "Can't set localeDir to \"" << directory << "\"" << endl;
158  yuiDebug () << "It is locked to: \"" << _localeDir << "\"" << endl;
159  YUI_THROW ( YUIException ( "localeDir is locked to: \"" + _localeDir + "\"" ) );
160  }
161 }
162 
164 {
165  if ( _localeDir.size() )
166  {
167  yuiDebug () << "localeDir: \"" << _localeDir << "\"" << endl;
168  return _localeDir;
169  }
170  else if ( _progDir.size() )
171  {
172  //back compatibility if ProgDir is set to "/usr/share/YaST2"
173  return _progDir + "/locale/";
174  }
175 
176  return "/usr/share/locale/";
177 }
178 
179 void YSettings::loadedUI( string ui, bool force )
180 {
181  if ( _loadedUI.empty() || force )
182  {
183  _loadedUI = ui;
184  yuiDebug () << "Set loadedUI to \"" << ui << "\"" << endl;
185  yuiDebug () << "loadedUI is now locked." << endl;
186  }
187  else
188  {
189  yuiDebug () << "Can't set loadedUI to \"" << ui << "\"" << endl;
190  yuiDebug () << "It is locked to: \"" << _loadedUI << "\"" << endl;
191  YUI_THROW ( YUIException ( "loadedUI is locked to: \"" + _loadedUI + "\"" ) );
192  }
193 }
194 
195 
196 void YSettings::loadedUI( string ui )
197 {
198  loadedUI( ui, false );
199 }
200 
201 
203 {
204  yuiDebug () << "loadedUI: \"" << _loadedUI << "\"" << endl;
205 
206  return _loadedUI;
207 }
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:82
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:113
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:58
static void setLocaleDir(std::string directory)
This can be used to set a subdir LOCALEDIR, where your program stores translations.
Definition: YSettings.cc:147
static std::string themeDir()
Returns the value of your program&#39;s theme subdir.
Definition: YSettings.cc:130
static std::string progDir()
Returns the value of your program&#39;s subdir.
Definition: YSettings.cc:74
static std::string loadedUI()
Returns the value of the loaded UI-backend.
Definition: YSettings.cc:202
static std::string iconDir()
Returns the value of your program&#39;s icons subdir.
Definition: YSettings.cc:99
static std::string localeDir()
Returns the value of your program&#39;s locale subdir.
Definition: YSettings.cc:163
Base class for UI Exceptions.
Definition: YUIException.h:297