1 #include "../Common/Common.h"
3 #include "../DasherCore/Parameters.h"
4 #include "../Common/AppSettingsData.h"
12 using namespace Dasher::Settings
;
14 enum EValType
{ TYPE_BOOL
, TYPE_LONG
, TYPE_STRING
};
15 enum EOutput
{ GCONF_OUTPUT
, GSETTINGS_OUTPUT
, TEXT_OUTPUT
};
19 CSchema(const std::string
&strKeyName
, EValType iType
,
20 const std::string
&strDefault
, const std::string
&strShort
,
21 const std::string
&strLong
);
25 std::string m_strKeyName
;
27 std::string m_strDefault
;
28 std::string m_strShort
;
29 std::string m_strLong
;
34 void operator()(char &c
) {c
= tolower(c
);}
37 std::string
lower(const std::string
& in
)
40 for_each(out
.begin(), out
.end(), lower_char());
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
;
49 m_strDefault
= strDefault
;
50 m_strShort
= strShort
;
54 void CSchema::Dump(EOutput output_type
) {
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>";
71 std::cout
<< "string";
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
;
83 case GSETTINGS_OUTPUT
:
84 std::cout
<< " <key name=\"" << m_strKeyName
<< "\" type=\"";
98 std::cout
<< " <default>" << (m_iType
==TYPE_STRING
?"'":"");
99 if (m_iType
==TYPE_BOOL
)
100 std::cout
<< lower(m_strDefault
);
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";
113 std::cout
<< std::setw(30)
114 << m_strKeyName
<< '\t';
117 std::cout
<< "bool\t";
120 std::cout
<< "int\t";
123 std::cout
<< "string\t";
126 std::cout
<< m_strDefault
<< '\t'
127 << m_strShort
<< '\n';
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
) {
145 if (argv
[1][0] != '-' || argv
[1][2] != '\0') {
151 output
= GCONF_OUTPUT
;
154 output
= GSETTINGS_OUTPUT
;
157 output
= TEXT_OUTPUT
;
166 std::cout
<< "<gconfschemafile>" << std::endl
;
167 std::cout
<< "<schemalist>" << std::endl
;
168 std::cout
<< "Is this really main? -- Who knows?" << std::endl
;
170 case GSETTINGS_OUTPUT
:
171 std::cout
<< "<schemalist>\n"
172 " <schema id=\"org.gnome.Dasher\" path=\"/apps/dasher4/\">\n";
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
,
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
)
196 strDefault
= "FALSE";
198 CSchema
oSchema( app_boolparamtable
[i
].regName
,
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
,
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
,
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
,
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
,
255 app_stringparamtable
[i
].defaultValue
,
257 app_stringparamtable
[i
].humanReadable
);
259 oSchema
.Dump(output
);
265 std::cout
<< "</schemalist>" << std::endl
;
266 std::cout
<< "</gconfschemafile>" << std::endl
;
268 case GSETTINGS_OUTPUT
:
269 std::cout
<< " </schema>\n</schemalist>" << std::endl
;
278 // bool defaultValue;
279 // char *humanReadable;