diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..494153e --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,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(); +} |