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