Commit 8c11ed62 authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

Add config option/command line: quit_on_init_fail

The config option controls whether katarakt should quit if the given
file fails to open.  The command line switch toggles this behaviour.
parent 15beff87
......@@ -25,6 +25,7 @@ CFG::CFG() :
// search options
defaults["rect_expansion"] = 2;
// viewer options
defaults["quit_on_init_fail"] = false;
defaults["icon_theme"] = "";
settings.endGroup();
......@@ -120,6 +121,10 @@ void CFG::set_tmp_value(const char *key, QVariant value) {
tmp_values[key] = value;
}
bool CFG::has_tmp_value(const char *key) const {
return tmp_values.contains(key);
}
QStringList CFG::get_keys(const char *action) const {
return settings.value(QString("Keys/") + action, keys[action]).toStringList();
}
......
......@@ -30,6 +30,7 @@ public:
QVariant get_tmp_value(const char *key) const;
void set_tmp_value(const char *key, QVariant value);
bool has_tmp_value(const char *key) const;
QStringList get_keys(const char *action) const;
};
......
......@@ -18,6 +18,7 @@ static void print_help(char *name) {
cout << "Options:" << endl;
cout << " -p, --page NUM Start showing page NUM" << endl;
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;
}
......@@ -28,13 +29,14 @@ int main(int argc, char *argv[]) {
struct option long_options[] = {
{"page", required_argument, NULL, 'p'},
{"fullscreen", no_argument, NULL, 'f'},
{"quit", no_argument, NULL, 'q'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};
int c;
int option_index = 0;
while (1) {
c = getopt_long(argc, argv, "+p:fh", long_options, &option_index);
c = getopt_long(argc, argv, "+p:fqh", long_options, &option_index);
if (c == -1) {
break;
}
......@@ -46,6 +48,9 @@ int main(int argc, char *argv[]) {
case 'f':
CFG::get_instance()->set_tmp_value("fullscreen", true);
break;
case 'q':
CFG::get_instance()->set_tmp_value("quit_on_init_fail", true);
break;
case 'h':
print_help(argv[0]);
return 0;
......
......@@ -12,6 +12,7 @@ search_padding=0.2
smooth_downscaling=true
thumbnail_size=32
rect_expansion=2
quit_on_init_fail=false
icon_theme=
[Keys]
......
......@@ -33,8 +33,12 @@ Viewer::Viewer(QString _file, QWidget *parent) :
valid(true) {
res = new ResourceManager(file);
if (!res->is_valid()) {
// valid = false;
// return;
// the command line option toggles the value set in the config
if (CFG::get_instance()->get_value("quit_on_init_fail").toBool() !=
CFG::get_instance()->has_tmp_value("quit_on_init_fail")) {
valid = false;
return;
}
}
canvas = new Canvas(this, this);
......@@ -46,8 +50,11 @@ Viewer::Viewer(QString _file, QWidget *parent) :
search_bar = new SearchBar(file, this, this);
if (!search_bar->is_valid()) {
// valid = false;
// return;
if (CFG::get_instance()->get_value("quit_on_init_fail").toBool() !=
CFG::get_instance()->has_tmp_value("quit_on_init_fail")) {
valid = false;
return;
}
}
search_bar->connect_canvas(canvas);
......
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