aboutsummaryrefslogtreecommitdiff
path: root/src/Resources.cc
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2010-05-23 10:25:47 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2010-05-23 10:25:47 (GMT)
commitfbcdd34b223174a28ff712b7d03e56339fa2fe07 (patch)
treeda036effaeeb5ba7788f4b0403151aa864e9d16d /src/Resources.cc
parentff9c68e247704bd1522ea7a2055b7fa4b2b0c568 (diff)
downloadfluxbox-fbcdd34b223174a28ff712b7d03e56339fa2fe07.zip
fluxbox-fbcdd34b223174a28ff712b7d03e56339fa2fe07.tar.bz2
mostly cosmetic fixes, mainly discovered by 'clang --analyze'
reordering of Resource-related stuff was because of "error: explicit specialization of 'getString' after instantiation" complaints.
Diffstat (limited to 'src/Resources.cc')
-rw-r--r--src/Resources.cc151
1 files changed, 76 insertions, 75 deletions
diff --git a/src/Resources.cc b/src/Resources.cc
index 60c7461..734cd75 100644
--- a/src/Resources.cc
+++ b/src/Resources.cc
@@ -49,6 +49,14 @@ using namespace FbTk;
49namespace FbTk { 49namespace FbTk {
50 50
51template<> 51template<>
52string FbTk::Resource<int>::
53getString() const {
54 char strval[256];
55 sprintf(strval, "%d", **this);
56 return string(strval);
57}
58
59template<>
52void FbTk::Resource<int>:: 60void FbTk::Resource<int>::
53setFromString(const char* strval) { 61setFromString(const char* strval) {
54 int val; 62 int val;
@@ -57,70 +65,16 @@ setFromString(const char* strval) {
57} 65}
58 66
59template<> 67template<>
60void FbTk::Resource<string>:: 68string FbTk::Resource<string>::
61setFromString(const char *strval) { 69getString() const { return **this; }
62 *this = strval;
63}
64
65template<>
66void FbTk::Resource<bool>::
67setFromString(char const *strval) {
68 *this = (bool)!strcasecmp(strval, "true");
69}
70
71template<>
72void FbTk::Resource<vector<WinButton::Type> >::
73setFromString(char const *strval) {
74 vector<string> val;
75 StringUtil::stringtok(val, strval);
76 //clear old values
77 m_value.clear();
78
79 std::string v;
80 for (size_t i = 0; i < val.size(); i++) {
81 v = FbTk::StringUtil::toLower(val[i]);
82 if (v == "maximize")
83 m_value.push_back(WinButton::MAXIMIZE);
84 else if (v == "minimize")
85 m_value.push_back(WinButton::MINIMIZE);
86 else if (v == "shade")
87 m_value.push_back(WinButton::SHADE);
88 else if (v == "stick")
89 m_value.push_back(WinButton::STICK);
90 else if (v == "menuIcon")
91 m_value.push_back(WinButton::MENUICON);
92 else if (v == "close")
93 m_value.push_back(WinButton::CLOSE);
94 }
95}
96
97template<>
98void FbTk::Resource<Fluxbox::TabsAttachArea>::
99setFromString(char const *strval) {
100 if (strcasecmp(strval, "Titlebar")==0)
101 m_value= Fluxbox::ATTACH_AREA_TITLEBAR;
102 else
103 m_value= Fluxbox::ATTACH_AREA_WINDOW;
104}
105
106template<>
107void FbTk::Resource<unsigned int>::
108setFromString(const char *strval) {
109 if (sscanf(strval, "%ul", &m_value) != 1)
110 setDefaultValue();
111}
112 70
113template<> 71template<>
114void FbTk::Resource<long long>:: 72void FbTk::Resource<string>::
115setFromString(const char *strval) { 73setFromString(const char *strval) {
116 if (sscanf(strval, "%lld", &m_value) != 1) 74 *this = strval;
117 setDefaultValue();
118} 75}
119 76
120 77
121//-----------------------------------------------------------------
122//---- manipulators for int, bool, and some enums with Resource ---
123//-----------------------------------------------------------------
124template<> 78template<>
125string FbTk::Resource<bool>:: 79string FbTk::Resource<bool>::
126getString() const { 80getString() const {
@@ -128,17 +82,11 @@ getString() const {
128} 82}
129 83
130template<> 84template<>
131string FbTk::Resource<int>:: 85void FbTk::Resource<bool>::
132getString() const { 86setFromString(char const *strval) {
133 char strval[256]; 87 *this = (bool)!strcasecmp(strval, "true");
134 sprintf(strval, "%d", **this);
135 return string(strval);
136} 88}
137 89
138template<>
139string FbTk::Resource<string>::
140getString() const { return **this; }
141
142 90
143template<> 91template<>
144string FbTk::Resource<vector<WinButton::Type> >:: 92string FbTk::Resource<vector<WinButton::Type> >::
@@ -173,6 +121,34 @@ getString() const {
173 return retval; 121 return retval;
174} 122}
175 123
124
125
126template<>
127void FbTk::Resource<vector<WinButton::Type> >::
128setFromString(char const *strval) {
129 vector<string> val;
130 StringUtil::stringtok(val, strval);
131 //clear old values
132 m_value.clear();
133
134 std::string v;
135 for (size_t i = 0; i < val.size(); i++) {
136 v = FbTk::StringUtil::toLower(val[i]);
137 if (v == "maximize")
138 m_value.push_back(WinButton::MAXIMIZE);
139 else if (v == "minimize")
140 m_value.push_back(WinButton::MINIMIZE);
141 else if (v == "shade")
142 m_value.push_back(WinButton::SHADE);
143 else if (v == "stick")
144 m_value.push_back(WinButton::STICK);
145 else if (v == "menuIcon")
146 m_value.push_back(WinButton::MENUICON);
147 else if (v == "close")
148 m_value.push_back(WinButton::CLOSE);
149 }
150}
151
176template<> 152template<>
177string FbTk::Resource<Fluxbox::TabsAttachArea>:: 153string FbTk::Resource<Fluxbox::TabsAttachArea>::
178getString() const { 154getString() const {
@@ -183,6 +159,15 @@ getString() const {
183} 159}
184 160
185template<> 161template<>
162void FbTk::Resource<Fluxbox::TabsAttachArea>::
163setFromString(char const *strval) {
164 if (strcasecmp(strval, "Titlebar")==0)
165 m_value= Fluxbox::ATTACH_AREA_TITLEBAR;
166 else
167 m_value= Fluxbox::ATTACH_AREA_WINDOW;
168}
169
170template<>
186string FbTk::Resource<unsigned int>:: 171string FbTk::Resource<unsigned int>::
187getString() const { 172getString() const {
188 char tmpstr[128]; 173 char tmpstr[128];
@@ -191,6 +176,14 @@ getString() const {
191} 176}
192 177
193template<> 178template<>
179void FbTk::Resource<unsigned int>::
180setFromString(const char *strval) {
181 if (sscanf(strval, "%ul", &m_value) != 1)
182 setDefaultValue();
183}
184
185
186template<>
194string FbTk::Resource<long long>:: 187string FbTk::Resource<long long>::
195getString() const { 188getString() const {
196 char tmpstr[128]; 189 char tmpstr[128];
@@ -199,13 +192,9 @@ getString() const {
199} 192}
200 193
201template<> 194template<>
202void FbTk::Resource<Layer>:: 195void FbTk::Resource<long long>::
203setFromString(const char *strval) { 196setFromString(const char *strval) {
204 string str(strval); 197 if (sscanf(strval, "%lld", &m_value) != 1)
205 int tempnum = ::Layer::getNumFromString(str);
206 if (tempnum >= 0 && tempnum < ::Layer::NUM_LAYERS)
207 m_value = tempnum;
208 else
209 setDefaultValue(); 198 setDefaultValue();
210} 199}
211 200
@@ -217,9 +206,13 @@ getString() const {
217} 206}
218 207
219template<> 208template<>
220void FbTk::Resource<long>:: 209void FbTk::Resource<Layer>::
221setFromString(const char *strval) { 210setFromString(const char *strval) {
222 if (sscanf(strval, "%ld", &m_value) != 1) 211 string str(strval);
212 int tempnum = ::Layer::getNumFromString(str);
213 if (tempnum >= 0 && tempnum < ::Layer::NUM_LAYERS)
214 m_value = tempnum;
215 else
223 setDefaultValue(); 216 setDefaultValue();
224} 217}
225 218
@@ -230,4 +223,12 @@ getString() const {
230 sprintf(tmpstr, "%ld", m_value); 223 sprintf(tmpstr, "%ld", m_value);
231 return string(tmpstr); 224 return string(tmpstr);
232} 225}
226
227template<>
228void FbTk::Resource<long>::
229setFromString(const char *strval) {
230 if (sscanf(strval, "%ld", &m_value) != 1)
231 setDefaultValue();
232}
233
233} // end namespace FbTk 234} // end namespace FbTk