Commit 98171e76 authored by Thorsten Wißmann's avatar Thorsten Wißmann 🎸 Committed by Philipp Erhardt
Browse files

Add --write-defaults command line switch

parent 5b895508
...@@ -43,6 +43,9 @@ OPTIONS ...@@ -43,6 +43,9 @@ OPTIONS
Quit on initialization failure. Quit on initialization failure.
*-h*, *--help* :: *-h*, *--help* ::
Print help and exit. Print help and exit.
*--write-defaults* 'FILE'::
Write the built-in default configuration to 'FILE' and exit. Hint: on unix
systems, you can use '--write-defaults /dev/stdout' to print the defaults.
*--single-instance* 'true'|'false':: *--single-instance* 'true'|'false'::
Sets *single_instance_per_file* for the present katarakt instance only. Sets *single_instance_per_file* for the present katarakt instance only.
......
...@@ -5,7 +5,15 @@ ...@@ -5,7 +5,15 @@
CFG::CFG() : CFG::CFG() :
settings(QSettings::IniFormat, QSettings::UserScope, "katarakt") { settings(QSettings::IniFormat, QSettings::UserScope, "katarakt") {
// TODO warn about invalid user input // TODO warn about invalid user input
init_defaults();
}
CFG::CFG(const char* file) :
settings(file, QSettings::IniFormat) {
init_defaults();
}
void CFG::init_defaults() {
settings.beginGroup("Settings"); settings.beginGroup("Settings");
// canvas options // canvas options
defaults["background_color"] = "0xDF000000"; defaults["background_color"] = "0xDF000000";
...@@ -126,6 +134,15 @@ CFG *CFG::get_instance() { ...@@ -126,6 +134,15 @@ CFG *CFG::get_instance() {
return &instance; return &instance;
} }
void CFG::write_defaults(const char *file) {
CFG inst(file);
inst.settings.clear();
inst.settings.setFallbacksEnabled(false);
inst.set_defaults();
inst.settings.sync();
get_instance();
}
QVariant CFG::get_value(const char *key) const { QVariant CFG::get_value(const char *key) const {
return settings.value(QString("Settings/") + key, defaults[key]); return settings.value(QString("Settings/") + key, defaults[key]);
} }
......
...@@ -12,9 +12,11 @@ class CFG { ...@@ -12,9 +12,11 @@ class CFG {
private: private:
CFG(); CFG();
CFG(const CFG &other); CFG(const CFG &other);
CFG(const char *file);
CFG &operator=(const CFG &other); CFG &operator=(const CFG &other);
~CFG(); ~CFG();
void init_defaults();
void set_defaults(); void set_defaults();
QSettings settings; QSettings settings;
...@@ -24,6 +26,7 @@ private: ...@@ -24,6 +26,7 @@ private:
public: public:
static CFG *get_instance(); static CFG *get_instance();
static void write_defaults(const char *file); // write defaults to file
QVariant get_value(const char *key) const; QVariant get_value(const char *key) const;
void set_value(const char *key, QVariant value); void set_value(const char *key, QVariant value);
......
...@@ -22,6 +22,7 @@ static void print_help(char *name) { ...@@ -22,6 +22,7 @@ static void print_help(char *name) {
cout << " -f, --fullscreen Start in fullscreen mode" << endl; cout << " -f, --fullscreen Start in fullscreen mode" << endl;
cout << " -q, --quit Quit on initialization failure" << endl; cout << " -q, --quit Quit on initialization failure" << endl;
cout << " -h, --help Print this help and exit" << endl; cout << " -h, --help Print this help and exit" << endl;
cout << " --write-defaults FILE Write the default configuration to FILE and exit" << endl;
cout << " --single-instance true|false Whether to have a single instance per file" << endl; cout << " --single-instance true|false Whether to have a single instance per file" << endl;
} }
...@@ -36,6 +37,7 @@ int main(int argc, char *argv[]) { ...@@ -36,6 +37,7 @@ int main(int argc, char *argv[]) {
{"quit", no_argument, NULL, 'q'}, {"quit", no_argument, NULL, 'q'},
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
{"single-instance", required_argument, NULL, 0}, {"single-instance", required_argument, NULL, 0},
{"write-defaults", required_argument, NULL, 0},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
}; };
int option_index = 0; int option_index = 0;
...@@ -52,6 +54,9 @@ int main(int argc, char *argv[]) { ...@@ -52,6 +54,9 @@ int main(int argc, char *argv[]) {
// (according to QVariant) any string can be converted to // (according to QVariant) any string can be converted to
// bool, so no type check needed here // bool, so no type check needed here
CFG::get_instance()->set_tmp_value("single_instance_per_file", optarg); CFG::get_instance()->set_tmp_value("single_instance_per_file", optarg);
} else if (!strcmp(option_name, "write-defaults")) {
CFG::write_defaults(optarg);
return 0;
} }
break; break;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment