Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Philipp Erhardt
katarakt
Commits
98171e76
Commit
98171e76
authored
Sep 23, 2015
by
Thorsten Wißmann
🎸
Committed by
Philipp Erhardt
Sep 25, 2015
Browse files
Add --write-defaults command line switch
parent
5b895508
Changes
4
Hide whitespace changes
Inline
Side-by-side
doc/katarakt.txt
View file @
98171e76
...
...
@@ -43,6 +43,9 @@ OPTIONS
Quit on initialization failure.
*-h*, *--help* ::
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'::
Sets *single_instance_per_file* for the present katarakt instance only.
...
...
src/config.cpp
View file @
98171e76
...
...
@@ -5,7 +5,15 @@
CFG
::
CFG
()
:
settings
(
QSettings
::
IniFormat
,
QSettings
::
UserScope
,
"katarakt"
)
{
// 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"
);
// canvas options
defaults
[
"background_color"
]
=
"0xDF000000"
;
...
...
@@ -126,6 +134,15 @@ CFG *CFG::get_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
{
return
settings
.
value
(
QString
(
"Settings/"
)
+
key
,
defaults
[
key
]);
}
...
...
src/config.h
View file @
98171e76
...
...
@@ -12,9 +12,11 @@ class CFG {
private:
CFG
();
CFG
(
const
CFG
&
other
);
CFG
(
const
char
*
file
);
CFG
&
operator
=
(
const
CFG
&
other
);
~
CFG
();
void
init_defaults
();
void
set_defaults
();
QSettings
settings
;
...
...
@@ -24,6 +26,7 @@ private:
public:
static
CFG
*
get_instance
();
static
void
write_defaults
(
const
char
*
file
);
// write defaults to file
QVariant
get_value
(
const
char
*
key
)
const
;
void
set_value
(
const
char
*
key
,
QVariant
value
);
...
...
src/main.cpp
View file @
98171e76
...
...
@@ -22,6 +22,7 @@ static void print_help(char *name) {
cout
<<
" -f, --fullscreen Start in fullscreen mode"
<<
endl
;
cout
<<
" -q, --quit Quit on initialization failure"
<<
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
;
}
...
...
@@ -36,6 +37,7 @@ int main(int argc, char *argv[]) {
{
"quit"
,
no_argument
,
NULL
,
'q'
},
{
"help"
,
no_argument
,
NULL
,
'h'
},
{
"single-instance"
,
required_argument
,
NULL
,
0
},
{
"write-defaults"
,
required_argument
,
NULL
,
0
},
{
NULL
,
0
,
NULL
,
0
}
};
int
option_index
=
0
;
...
...
@@ -52,6 +54,9 @@ int main(int argc, char *argv[]) {
// (according to QVariant) any string can be converted to
// bool, so no type check needed here
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
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment