Commit c1070e23 authored by Philipp Erhardt's avatar Philipp Erhardt
Browse files

Support opening more than one file via one command

The command line options right before each file will be used
individually.
parent 409b0176
......@@ -28,7 +28,7 @@ Canvas::Canvas(Viewer *v, QWidget *parent) :
// load config options
CFG *config = CFG::get_instance();
// apply start option
layout->scroll_page(config->get_value("start_page").toInt(), false);
layout->scroll_page(config->get_tmp_value("start_page").toInt(), false);
mouse_wheel_factor = config->get_value("mouse_wheel_factor").toInt();
smooth_scroll_delta = config->get_value("smooth_scroll_delta").toInt();
......
......@@ -72,10 +72,6 @@ CFG &CFG::operator=(const CFG &/*other*/) {
}
CFG::~CFG() {
// do not write temporary options to disk
settings.remove("start_page");
settings.remove("fullscreen");
// set_defaults(); // uncomment to create ini file with all the default settings
}
......@@ -88,6 +84,9 @@ void CFG::set_defaults() {
}
settings.endGroup();
tmp_values["start_page"] = 0;
tmp_values["fullscreen"] = false;
settings.beginGroup("Keys");
QHashIterator<QString,QStringList> i2(keys);
while (i2.hasNext()) {
......@@ -110,6 +109,14 @@ void CFG::set_value(const char *key, QVariant value) {
settings.setValue(QString("Settings/") + key, value);
}
QVariant CFG::get_tmp_value(const char *key) const {
return tmp_values[key];
}
void CFG::set_tmp_value(const char *key, QVariant value) {
tmp_values[key] = value;
}
QStringList CFG::get_keys(const char *action) const {
return settings.value(QString("Keys/") + action, keys[action]).toStringList();
}
......
......@@ -19,6 +19,7 @@ private:
QSettings settings;
QHash<QString,QVariant> defaults;
QHash<QString,QVariant> tmp_values; // not persistent
QHash<QString,QStringList> keys;
public:
......@@ -27,6 +28,9 @@ public:
QVariant get_value(const char *key) const;
void set_value(const char *key, QVariant value);
QVariant get_tmp_value(const char *key) const;
void set_tmp_value(const char *key, QVariant value);
QStringList get_keys(const char *action) const;
};
......
......@@ -10,7 +10,7 @@ katarakt - a simple PDF viewer with two layouts
SYNOPSIS
--------
*katarakt* ['OPTIONS'] 'FILE'|'URL'
*katarakt* (['OPTIONS'] 'FILE'|'URL')+
DESCRIPTION
-----------
......@@ -25,6 +25,8 @@ The 'grid layout' is much more advanced and offers continuous (smooth, per
pixel) scrolling, zooming and adjusting the column count. Pages keep their
correct relative size and are shown in a grid.
For every file passed on the command line a process is spawned.
OPTIONS
-------
*-p*, *--page* 'NUM'::
......
#include <QApplication>
#include <QString>
#include <QProcess>
#include <iostream>
#include <getopt.h>
#include "download.h"
......@@ -40,10 +41,10 @@ int main(int argc, char *argv[]) {
switch (c) {
case 'p':
// currently no warning message on wrong input
CFG::get_instance()->set_value("start_page", atoi(optarg) - 1);
CFG::get_instance()->set_tmp_value("start_page", atoi(optarg) - 1);
break;
case 'f':
CFG::get_instance()->set_value("fullscreen", true);
CFG::get_instance()->set_tmp_value("fullscreen", true);
break;
case 'h':
print_help(argv[0]);
......@@ -59,6 +60,15 @@ int main(int argc, char *argv[]) {
return 1;
}
// fork more processes if there are arguments left
if (optind < argc - 1) {
QStringList l;
for (int i = optind + 1; i < argc; i++) {
l << argv[i];
}
QProcess::startDetached(argv[0], l);
}
Download download;
QString file = download.load(QString::fromUtf8(argv[optind]));
if (file == NULL) {
......
......@@ -108,7 +108,7 @@ Viewer::Viewer(QString _file, QWidget *parent) :
search_bar->hide();
// apply start options
if (CFG::get_instance()->get_value("fullscreen").toBool()) {
if (CFG::get_instance()->get_tmp_value("fullscreen").toBool()) {
toggle_fullscreen();
}
}
......
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