main.cpp 2.58 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
    Copyright (C) 2019 Jonah Brüchert <jbb.prv@gmx.de>

    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

Jonah Brüchert's avatar
Jonah Brüchert committed
18
19
20
21
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QtQml>
#include <QUrl>
22
23
#include <QCommandLineParser>
#include <QCommandLineOption>
24
#include <QtWebEngine>
25

Pino Toscano's avatar
Pino Toscano committed
26
27
#include <KLocalizedString>

Jonah Brüchert's avatar
Jonah Brüchert committed
28
#include "browsermanager.h"
29
#include "urlfilterproxymodel.h"
30
#include "urlmodel.h"
31
#include "useragent.h"
32

Jonah Brüchert's avatar
Jonah Brüchert committed
33
Q_DECL_EXPORT int main(int argc, char *argv[])
34
{
Jonah Brüchert's avatar
Jonah Brüchert committed
35
36
37
    QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication app(argc, argv);
    QCoreApplication::setOrganizationName("KDE");
38
    QCoreApplication::setOrganizationDomain("mobile.kde.org");
Jonah Brüchert's avatar
Jonah Brüchert committed
39
    QCoreApplication::setApplicationName("angelfish");
40

41
42
    // Command line parser
    QCommandLineParser parser;
Pino Toscano's avatar
Pino Toscano committed
43
    parser.addPositionalArgument("url", i18n("URL to open"), "[url]");
Jonah Brüchert's avatar
Jonah Brüchert committed
44
    parser.addOption({ "webapp-container", i18n("Start without UI") });
Jonah Brüchert's avatar
Jonah Brüchert committed
45
46
    parser.addHelpOption();
    parser.process(app);
47
48

    // QML loading
Jonah Brüchert's avatar
Jonah Brüchert committed
49
    QQmlApplicationEngine engine;
50
51
52

    // Setup QtWebEngine
    qputenv("QTWEBENGINE_DIALOG_SET", "QtQuickControls2");
53
    QtWebEngine::initialize();
54
55

    // initial url command line parameter
Jonah Brüchert's avatar
Jonah Brüchert committed
56
    QUrl initialUrl;
57
    if (!parser.positionalArguments().isEmpty())
Jonah Brüchert's avatar
Jonah Brüchert committed
58
        initialUrl = QUrl::fromUserInput(parser.positionalArguments().first());
59
    engine.rootContext()->setContextProperty("initialUrl", initialUrl);
60

Jonah Brüchert's avatar
Jonah Brüchert committed
61
62
    engine.rootContext()->setContextProperty("webappcontainer", parser.isSet("webapp-container"));

Yuri Chornoivan's avatar
Yuri Chornoivan committed
63
    // Browser manager
Jonah Brüchert's avatar
Jonah Brüchert committed
64
65
66
    qmlRegisterType<AngelFish::BrowserManager>("org.kde.mobile.angelfish", 1, 0, "BrowserManager");
    qmlRegisterType<UrlFilterProxyModel>("org.kde.mobile.angelfish", 1, 0, "UrlFilterProxyModel");
    qmlRegisterType<UserAgent>("org.kde.mobile.angelfish", 1, 0, "UserAgentGenerator");
67
68
    engine.load(QUrl(QStringLiteral("qrc:///webbrowser.qml")));

69
    // Error handling
Jonah Brüchert's avatar
Jonah Brüchert committed
70
71
    if (engine.rootObjects().isEmpty()) {
        return -1;
72
    }
73

Jonah Brüchert's avatar
Jonah Brüchert committed
74
    return app.exec();
75
}