-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
64 lines (57 loc) · 2.08 KB
/
main.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <QApplication>
#include <QWebEngineView>
#include <QCommandLineParser>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QIcon>
#include "Page.h"
int main(int argc, char **argv) {
QApplication app(argc, argv);
app.setApplicationVersion("1.2.0");
QCommandLineParser cl;
cl.setApplicationDescription(QCoreApplication::translate("main", "HTML Script Runner"));
cl.addHelpOption();
cl.addVersionOption();
cl.addPositionalArgument("startpage", QCoreApplication::translate("main", "Start page"));
QCommandLineOption size("s", QCoreApplication::translate("size", "Initial size"), "size", "870x520");
QCommandLineOption icon("i", QCoreApplication::translate("icon", "Application icon"), "icon", "/usr/share/icons/openmandriva.svg");
QCommandLineOption c("c", QCoreApplication::translate("main", "Ignored, for compatibility with old version"));
QCommandLineOption title("t", QCoreApplication::translate("main", "Application title"), "title", "HTML Script Runner");
cl.addOptions(QList<QCommandLineOption>() << size << icon << c << title);
cl.process(app);
QString t=cl.value(title);
if(!t.isEmpty())
// We allow overriding the application name because that's the
// window title -- and we want OM Welcome to have a different
// title than Control Center and whatever else may use
// htmlscript in the future
app.setApplicationName(t);
unsigned int w, h;
QString s=cl.value(size);
if(s.contains('x')) {
w=s.section('x', 0, 0).toUInt();
h=s.section('x', 1, 1).toUInt();
}
QString arg = cl.positionalArguments().empty() ? QDir::currentPath() : cl.positionalArguments().at(0), dir, startpage;
QFileInfo fi(arg);
if(fi.isDir()) {
dir = arg;
if(QFile::exists(dir + "/index.sh.html"))
startpage = dir + "/index.sh.html";
else
startpage = dir + "/index.sh.htm";
} else {
dir = fi.absolutePath();
startpage = fi.fileName();
}
QWebEngineView *l=new QWebEngineView(static_cast<QWidget*>(nullptr));
l->setWindowIcon(QIcon(cl.value(icon)));
Page *p=new Page(dir, l);
l->setPage(p);
p->open(startpage);
l->resize(w, h);
l->show();
app.exec();
delete l;
}