]> rtime.felk.cvut.cz Git - coffee/qtwebbrowser.git/blob - src/main.cpp
Clean up the application after integration for b2qt
[coffee/qtwebbrowser.git] / src / main.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtBrowser project.
7 **
8 ** $QT_BEGIN_LICENSE:GPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 2 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.GPLv2 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU General Public License version 2 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 3.0 as published by the Free Software
28 ** Foundation and appearing in the file LICENSE.GPL included in the
29 ** packaging of this file. Please review the following information to
30 ** ensure the GNU General Public License version 3.0 requirements will be
31 ** met: http://www.gnu.org/copyleft/gpl.html.
32 **
33 **
34 ** $QT_END_LICENSE$
35 **
36 ****************************************************************************/
37
38 #include "appengine.h"
39 #include "navigationhistoryproxymodel.h"
40 #include "touchtracker.h"
41
42 #if defined(DESKTOP_BUILD)
43 #include "touchmockingapplication.h"
44 #endif
45
46 #include <QGuiApplication>
47 #include <QQmlContext>
48 #include <QQmlEngine>
49 #include <QQuickView>
50 #include <QtWebEngine/qtwebengineglobal.h>
51
52 static QObject *engine_factory(QQmlEngine *engine, QJSEngine *scriptEngine)
53 {
54     Q_UNUSED(engine);
55     Q_UNUSED(scriptEngine);
56     AppEngine *eng = new AppEngine();
57     return eng;
58 }
59
60 int main(int argc, char **argv)
61 {
62     qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
63
64     //do not use any plugins installed on the device
65     qputenv("QML2_IMPORT_PATH", QByteArray());
66
67     // We use touch mocking on desktop and apply all the mobile switches.
68     QByteArrayList args = QByteArrayList()
69             << QByteArrayLiteral("--enable-embedded-switches")
70             << QByteArrayLiteral("--log-level=0");
71     const int count = args.size() + argc;
72     QVector<char*> qargv(count);
73
74     qargv[0] = argv[0];
75     for (int i = 0; i < args.size(); ++i)
76         qargv[i + 1] = args[i].data();
77     for (int i = args.size() + 1; i < count; ++i)
78         qargv[i] = argv[i - args.size()];
79
80     int qAppArgCount = qargv.size();
81
82 #if defined(DESKTOP_BUILD)
83     TouchMockingApplication app(qAppArgCount, qargv.data());
84 #else
85     QGuiApplication app(qAppArgCount, qargv.data());
86 #endif
87
88     qmlRegisterType<NavigationHistoryProxyModel>("WebBrowser", 1, 0, "SearchProxyModel");
89     qmlRegisterType<TouchTracker>("WebBrowser", 1, 0, "TouchTracker");
90     qmlRegisterSingletonType<AppEngine>("WebBrowser", 1, 0, "AppEngine", engine_factory);
91
92     QtWebEngine::initialize();
93
94     app.setOrganizationName("The Qt Company");
95     app.setOrganizationDomain("qt.io");
96     app.setApplicationName("qtwebbrowser");
97
98     QQuickView view;
99     view.setTitle("Yet Another Browser");
100     view.setFlags(Qt::Window | Qt::WindowTitleHint);
101     view.setResizeMode(QQuickView::SizeRootObjectToView);
102     view.setColor(Qt::black);
103     view.setSource(QUrl("qrc:///qml/BrowserWindow.qml"));
104
105     QObject::connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));
106
107 #if defined(DESKTOP_BUILD)
108     view.show();
109     if (view.size().isEmpty())
110         view.setGeometry(0, 0, 800, 600);
111 #else
112     view.showFullScreen();
113 #endif
114
115     app.exec();
116 }