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