mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 03:58:56 -04:00
Use dialog to select a zim file if no zim as been provide on command line.
It is better than crashing.
This commit is contained in:
parent
a248348452
commit
84e5124ae6
19
main.cpp
19
main.cpp
@ -2,23 +2,34 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
KiwixApp a(argc, argv);
|
KiwixApp a(argc, argv);
|
||||||
KiwixApp::setApplicationName("kiwix-desktop");
|
KiwixApp::setApplicationName("kiwix-desktop");
|
||||||
|
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.addPositionalArgument("zimfile", "The zim file");
|
parser.addPositionalArgument("zimfile", "The zim file");
|
||||||
|
|
||||||
parser.process(a);
|
parser.process(a);
|
||||||
const QString zimfile = parser.positionalArguments().at(0);
|
QString zimfile;
|
||||||
|
auto positionalArguments = parser.positionalArguments();
|
||||||
a.openZimFile(zimfile);
|
if (positionalArguments.size() < 1){
|
||||||
|
zimfile = QFileDialog::getOpenFileName(nullptr,
|
||||||
|
"Open Zim",
|
||||||
|
QString(),
|
||||||
|
"ZimFile (*.zim*)");
|
||||||
|
} else {
|
||||||
|
zimfile = parser.positionalArguments().at(0);
|
||||||
|
}
|
||||||
|
std::string f = zimfile.toUtf8().constData();
|
||||||
|
std::cout << f << std::endl;
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.show();
|
w.show();
|
||||||
|
a.openZimFile(zimfile);
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user