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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
/*
* Copyright (C) 2012 Canonical, Ltd.
*
* Authors:
* Gerry Boland <gerry.boland@canonical.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* 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 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 <http://www.gnu.org/licenses/>.
*/
// Qt
#include <QtQuick/QQuickView>
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlEngine>
#include <qpa/qplatformnativeinterface.h>
#include <QLibrary>
// local
#include "config.h"
int main(int argc, char** argv)
{
/* Workaround Qt platform integration plugin not advertising itself
as having the following capabilities:
- QPlatformIntegration::ThreadedOpenGL
- QPlatformIntegration::BufferQueueingOpenGL
*/
setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
QGuiApplication::setApplicationName("Qml Phone Shell");
QGuiApplication application(argc, argv);
QStringList args = application.arguments();
// The testability driver is only loaded by QApplication but not by QGuiApplication.
// However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
if (args.contains(QLatin1String("-testability"))) {
QLibrary testLib(QLatin1String("qttestability"));
if (testLib.load()) {
typedef void (*TasInitialize)(void);
TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
if (initFunction) {
initFunction();
} else {
qCritical("Library qttestability resolve failed!");
}
} else {
qCritical("Library qttestability load failed!");
}
}
QQuickView* view = new QQuickView();
view->setResizeMode(QQuickView::SizeRootObjectToView);
view->setTitle("Qml Phone Shell");
view->engine()->setBaseUrl(QUrl::fromLocalFile(shellAppDirectory()));
if (args.contains(QLatin1String("-frameless"))) {
view->setFlags(Qt::FramelessWindowHint);
}
QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
/* Shell is declared as a system session so that it always receives all
input events.
FIXME: use the enum value corresponding to SYSTEM_SESSION_TYPE (= 1)
when it becomes available.
*/
nativeInterface->setProperty("ubuntuSessionType", 1);
view->setProperty("role", 2); // INDICATOR_ACTOR_ROLE
QObject::connect(view->engine(), SIGNAL(quit()), qApp, SLOT(quit()));
QUrl source("Shell.qml");
view->engine()->addImportPath(shellAppDirectory());
view->engine()->addImportPath(shellImportPath());
view->setSource(source);
view->setColor("transparent");
if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || args.contains(QLatin1String("-fullscreen"))) {
view->showFullScreen();
} else {
if (args.contains(QLatin1String("-geometry")) && args.size() > args.indexOf(QLatin1String("-geometry")) + 1) {
QStringList geometryArg = args.at(args.indexOf(QLatin1String("-geometry")) + 1).split('x');
if (geometryArg.size() == 2) {
view->resize(geometryArg.at(0).toInt(), geometryArg.at(1).toInt());
}
}
view->show();
}
return application.exec();
}
|