Commit 3b8fad14 authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

Fix opening empty/no string, minor fixes

parent 80fe9db9
......@@ -2,7 +2,7 @@
default_layout=single
background_color=0xDF202020
background_color_fullscreen=0xFF000000
unrendered_page_color=0x80808080
unrendered_page_color=0x40FFFFFF
click_link_button=1
drag_view_button=2
select_text_button=1
......
......@@ -172,7 +172,12 @@ QVariant CFG::get_most_current_value(const char *key) const {
if (tmp_values.contains(key)) {
return tmp_values[key];
} else {
return settings.value(QString("Settings/") + key, defaults[key]);
#ifdef DEBUG
if (defaults.find(key) == defaults.end()) {
cout << "missing key " << key << endl;
}
#endif
return settings.value(key, defaults[key]);
}
}
......
......@@ -41,6 +41,11 @@ void dbus_init(Viewer *viewer) {
}
bool activate_katarakt_with_file(QString file) {
if (file.isNull()) {
// always start a new instance if no argument was given
return false;
}
QString filepath = QFileInfo(file).absoluteFilePath();
QDBusConnection bus = QDBusConnection::sessionBus();
QStringList services = bus.interface()->registeredServiceNames().value();
......
......@@ -67,7 +67,7 @@ int main(int argc, char *argv[]) {
CFG::get_instance()->set_tmp_value("fullscreen", true);
break;
case 'q':
CFG::get_instance()->set_tmp_value("Viewer/quit_on_init_fail", optarg);
CFG::get_instance()->set_tmp_value("Settings/quit_on_init_fail", optarg);
break;
case 'h':
print_help(argv[0]);
......@@ -75,7 +75,7 @@ int main(int argc, char *argv[]) {
case 's':
// (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);
CFG::get_instance()->set_tmp_value("Settings/single_instance_per_file", optarg);
break;
case 'c':
CFG::write_defaults(optarg);
......@@ -106,10 +106,13 @@ int main(int argc, char *argv[]) {
if (file.isNull()) {
return 1;
}
} else if (CFG::get_instance()->get_most_current_value("Settings/quit_on_init_fail").toBool()) {
print_help(argv[0]);
return 1;
}
// else no argument given, "open" empty string
// else: opens empty window without file
if (CFG::get_instance()->get_most_current_value("single_instance_per_file").toBool()) {
if (CFG::get_instance()->get_most_current_value("Settings/single_instance_per_file").toBool()) {
if (activate_katarakt_with_file(file)) {
return 0;
}
......
......@@ -44,7 +44,10 @@ void ResourceManager::initialize(const QString &file, const QByteArray &password
page_count = 0;
k_page = NULL;
doc = Poppler::Document::load(file, QByteArray(), password);
doc = NULL;
if (!file.isNull()) {
doc = Poppler::Document::load(file, QByteArray(), password);
}
worker = new Worker(this);
if (viewer->get_canvas() != NULL) {
......
......@@ -164,7 +164,11 @@ SearchBar::SearchBar(const QString &file, Viewer *v, QWidget *parent) :
void SearchBar::initialize(const QString &file, const QByteArray &password) {
worker = NULL;
doc = Poppler::Document::load(file, QByteArray(), password);
doc = NULL;
// if (!file.isNull()) { // don't print the poppler error message for the second time
if (!file.isEmpty()) {
doc = Poppler::Document::load(file, QByteArray(), password);
}
if (doc == NULL) {
// poppler already prints a debug message
......
......@@ -35,7 +35,7 @@ Viewer::Viewer(const QString &file, QWidget *parent) :
valid(true) {
res = new ResourceManager(file, this);
if (!res->is_valid()) {
if (CFG::get_instance()->get_most_current_value("Viewer/quit_on_init_fail").toBool()) {
if (CFG::get_instance()->get_most_current_value("Settings/quit_on_init_fail").toBool()) {
valid = false;
return;
}
......@@ -43,7 +43,7 @@ Viewer::Viewer(const QString &file, QWidget *parent) :
search_bar = new SearchBar(file, this, this);
if (!search_bar->is_valid()) {
if (CFG::get_instance()->get_most_current_value("Viewer/quit_on_init_fail").toBool()) {
if (CFG::get_instance()->get_most_current_value("Settings/quit_on_init_fail").toBool()) {
valid = false;
return;
}
......
Markdown is supported
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