summaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: 494153e01f79c29ce4c8b14dd5a4daf112dcdb6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <QApplication>
#include "mainwindow/mainwindow.h"
#include <QCommandLineParser>

inline MainWindow *openWindow(const QString &path)
{
    auto *window = new MainWindow;
    window->setAttribute(Qt::WA_DeleteOnClose, true);

    if(!path.isEmpty())
        window->open(path);

    window->show();
    return window;
}

int main(int argc, char** argv)
{
    QApplication app(argc, argv);
    QCoreApplication::setApplicationName(QLatin1Literal("cpdf"));
    QCoreApplication::setApplicationVersion(QLatin1Literal("0.1.0"));

    QCommandLineParser parser;
    parser.setApplicationDescription(QLatin1Literal("Simple PDF viewer"));
    parser.addHelpOption();
    parser.addVersionOption();
    parser.addPositionalArgument(QLatin1Literal("URLs"), QLatin1Literal("PDF files to open"));

    parser.process(app);

    {
        const auto files = parser.positionalArguments();
        if(files.count() == 0) {
            openWindow(QString());
        } else {
            for(const auto file : files) {
                openWindow(file);
            }
        }
    }

    return app.exec();
}