Update Turkish translation
[dasher.git] / Src / Gtk2 / GenerateSchema.cpp
blobd979617ac8ddb8c53a0d1ef1167dfcc6df0306f8
1 #include "../Common/Common.h"
3 #include "../DasherCore/Parameters.h"
4 #include "../Common/AppSettingsData.h"
6 #include <algorithm>
7 #include <string>
8 #include <sstream>
9 #include <iostream>
10 #include <iomanip>
12 using namespace Dasher::Settings;
14 enum EValType { TYPE_BOOL, TYPE_LONG, TYPE_STRING };
15 enum EOutput { GCONF_OUTPUT, GSETTINGS_OUTPUT, TEXT_OUTPUT };
17 class CSchema {
18 public:
19 CSchema(const std::string &strKeyName, EValType iType,
20 const std::string &strDefault, const std::string &strShort,
21 const std::string &strLong);
23 void Dump(EOutput);
24 private:
25 std::string m_strKeyName;
26 EValType m_iType;
27 std::string m_strDefault;
28 std::string m_strShort;
29 std::string m_strLong;
32 struct lower_char
34 void operator()(char &c) {c = tolower(c);}
37 std::string lower(const std::string& in)
39 std::string out(in);
40 for_each(out.begin(), out.end(), lower_char());
41 return out;
44 CSchema::CSchema(const std::string &strKeyName, EValType iType,
45 const std::string &strDefault, const std::string &strShort,
46 const std::string &strLong) {
47 m_strKeyName = strKeyName;
48 m_iType = iType;
49 m_strDefault = strDefault;
50 m_strShort = strShort;
51 m_strLong = strLong;
54 void CSchema::Dump(EOutput output_type) {
55 switch(output_type) {
56 case GCONF_OUTPUT:
57 std::cout << "<schema>" << std::endl;
58 std::cout << "<key>/schemas/apps/dasher4/" << m_strKeyName << "</key>" << std::endl;
59 std::cout << "<applyto>/apps/dasher4/" << m_strKeyName << "</applyto>" << std::endl;
60 std::cout << "<owner>dasher</owner>" << std::endl;
62 std::cout << "<type>";
63 switch(m_iType) {
64 case TYPE_BOOL:
65 std::cout << "bool";
66 break;
67 case TYPE_LONG:
68 std::cout << "int";
69 break;
70 case TYPE_STRING:
71 std::cout << "string";
72 break;
74 std::cout << "</type>" << std::endl;
76 std::cout << "<default>" << m_strDefault << "</default>" << std::endl;
77 std::cout << "<locale name=\"C\">" << std::endl;
78 std::cout << "<short>" << m_strShort << "</short>" << std::endl;
79 std::cout << "<long>" << m_strLong << "</long>" << std::endl;
80 std::cout << "</locale>" << std::endl;
81 std::cout << "</schema>" << std::endl;
82 break;
83 case GSETTINGS_OUTPUT:
84 std::cout << " <key name=\"" << m_strKeyName << "\" type=\"";
85 switch(m_iType) {
86 case TYPE_BOOL:
87 std::cout << 'b';
88 break;
89 case TYPE_LONG:
90 std::cout << 'i';
91 break;
92 case TYPE_STRING:
93 std::cout << 's';
94 break;
96 std::cout << "\">\n";
98 std::cout << " <default>" << (m_iType==TYPE_STRING?"'":"");
99 if (m_iType==TYPE_BOOL)
100 std::cout << lower(m_strDefault);
101 else
102 std::cout << m_strDefault;
103 std::cout << (m_iType==TYPE_STRING?"'":"") << "</default>\n";
105 if (!m_strShort.empty())
106 std::cout << " <summary>" << m_strShort << "</summary>\n";
107 if (!m_strLong.empty())
108 std::cout << " <description>" << m_strLong << "</description>\n";
109 std::cout << " </key>\n";
111 break;
112 case TEXT_OUTPUT:
113 std::cout << std::setw(30)
114 << m_strKeyName << '\t';
115 switch(m_iType) {
116 case TYPE_BOOL:
117 std::cout << "bool\t";
118 break;
119 case TYPE_LONG:
120 std::cout << "int\t";
121 break;
122 case TYPE_STRING:
123 std::cout << "string\t";
124 break;
126 std::cout << m_strDefault << '\t'
127 << m_strShort << '\n';
128 break;
132 void usage(char *progname) {
133 std::cerr << "usage: " << progname
134 << " [-cst]\n-c: GConf\n-s: GSettings\n-t: text\n";
137 int main(int argc, char **argv) {
139 EOutput output;
141 if (argc != 2) {
142 usage(argv[0]);
143 return 1;
145 if (argv[1][0] != '-' || argv[1][2] != '\0') {
146 usage(argv[0]);
147 return 1;
149 switch(argv[1][1]) {
150 case 'c':
151 output = GCONF_OUTPUT;
152 break;
153 case 's':
154 output = GSETTINGS_OUTPUT;
155 break;
156 case 't':
157 output = TEXT_OUTPUT;
158 break;
159 default:
160 usage(argv[0]);
161 return 1;
164 switch (output) {
165 case GCONF_OUTPUT:
166 std::cout << "<gconfschemafile>" << std::endl;
167 std::cout << "<schemalist>" << std::endl;
168 std::cout << "Is this really main? -- Who knows?" << std::endl;
169 break;
170 case GSETTINGS_OUTPUT:
171 std::cout << "<schemalist>\n"
172 " <schema id=\"org.gnome.Dasher\" path=\"/apps/dasher4/\">\n";
173 break;
176 for(int i(0); i < NUM_OF_BPS; ++i) {
177 std::string strDefault(boolparamtable[i].defaultValue ? "TRUE" : "FALSE");
179 CSchema oSchema( boolparamtable[i].regName,
180 TYPE_BOOL,
181 strDefault,
183 boolparamtable[i].humanReadable );
185 oSchema.Dump(output);
188 for(int i(0); i < END_OF_APP_BPS - END_OF_SPS; ++i) {
190 if(app_boolparamtable[i].persistent == Persistence::PERSISTENT) {
191 std::string strDefault;
193 if(app_boolparamtable[i].defaultValue)
194 strDefault = "TRUE";
195 else
196 strDefault = "FALSE";
198 CSchema oSchema( app_boolparamtable[i].regName,
199 TYPE_BOOL,
200 strDefault,
202 app_boolparamtable[i].humanReadable );
204 oSchema.Dump(output);
208 for(int i(0); i < NUM_OF_LPS; ++i) {
209 std::stringstream ssDefault;
211 ssDefault << longparamtable[i].defaultValue;
214 CSchema oSchema( longparamtable[i].regName,
215 TYPE_LONG,
216 ssDefault.str(),
218 longparamtable[i].humanReadable );
220 oSchema.Dump(output);
223 for(int i(0); i < END_OF_APP_LPS - END_OF_APP_BPS; ++i) {
224 if(app_longparamtable[i].persistent == Persistence::PERSISTENT) {
226 std::stringstream ssDefault;
228 ssDefault << app_longparamtable[i].defaultValue;
231 CSchema oSchema( app_longparamtable[i].regName,
232 TYPE_LONG,
233 ssDefault.str(),
235 app_longparamtable[i].humanReadable );
237 oSchema.Dump(output);
241 for(int i(0); i < NUM_OF_SPS; ++i) {
242 CSchema oSchema( stringparamtable[i].regName,
243 TYPE_STRING,
244 stringparamtable[i].defaultValue,
246 stringparamtable[i].humanReadable );
248 oSchema.Dump(output);
251 for(int i(0); i < END_OF_APP_SPS - END_OF_APP_LPS; ++i) {
252 if(app_stringparamtable[i].persistent == Persistence::PERSISTENT) {
253 CSchema oSchema( app_stringparamtable[i].regName,
254 TYPE_STRING,
255 app_stringparamtable[i].defaultValue,
257 app_stringparamtable[i].humanReadable );
259 oSchema.Dump(output);
263 switch (output) {
264 case GCONF_OUTPUT:
265 std::cout << "</schemalist>" << std::endl;
266 std::cout << "</gconfschemafile>" << std::endl;
267 break;
268 case GSETTINGS_OUTPUT:
269 std::cout << " </schema>\n</schemalist>" << std::endl;
272 return 0;
274 // struct bp_table {
275 // int key;
276 // char *regName;
277 // bool persistent;
278 // bool defaultValue;
279 // char *humanReadable;
280 // };