-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (38 loc) · 1.22 KB
/
main.cpp
File metadata and controls
50 lines (38 loc) · 1.22 KB
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
45
46
47
48
49
50
/*
SPDX-FileCopyrightText: 2021 Gary Wang <wzc782970009@gmail.com>
SPDX-License-Identifier: GPL-2.0-only
*/
#include "mainwindow.h"
#include <QApplication>
#include <QCommandLineParser>
#include <QUrl>
QList<QUrl> convertToUrlList(const QStringList &files)
{
QList<QUrl> urlList;
for (const QString & str : std::as_const(files)) {
QUrl url = QUrl::fromLocalFile(str);
if (url.isValid()) {
urlList.append(url);
}
}
return urlList;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setApplicationName(QStringLiteral("Pineapple Chapter Tool"));
a.setApplicationDisplayName(QCoreApplication::translate("main", "Pineapple Chapter Tool"));
// parse commandline arguments
QCommandLineParser parser;
parser.addPositionalArgument("File list", QCoreApplication::translate("main", "File list."));
parser.addHelpOption();
parser.process(a);
QStringList urlStrList = parser.positionalArguments();
QList<QUrl> && urlList = convertToUrlList(urlStrList);
MainWindow w;
w.show();
if (!urlList.isEmpty()) {
w.loadFile(urlList.first());
}
return a.exec();
}