1
by Michał Sawicz
Inital unity8 commit. |
1 |
/*
|
2 |
* Copyright (C) 2012 Canonical, Ltd.
|
|
3 |
*
|
|
4 |
* Authors:
|
|
5 |
* Gerry Boland <gerry.boland@canonical.com>
|
|
6 |
*
|
|
7 |
* This program is free software; you can redistribute it and/or modify
|
|
8 |
* it under the terms of the GNU General Public License as published by
|
|
9 |
* the Free Software Foundation; version 3.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18 |
*/
|
|
19 |
||
20 |
// Qt
|
|
21 |
#include <QtQuick/QQuickView> |
|
22 |
#include <QtGui/QIcon> |
|
23 |
#include <QtGui/QGuiApplication> |
|
24 |
#include <QtQml/QQmlEngine> |
|
25 |
#include <qpa/qplatformnativeinterface.h> |
|
26 |
#include <QLibrary> |
|
27 |
#include <libintl.h> |
|
28 |
||
29 |
// local
|
|
30 |
#include "paths.h" |
|
31 |
#include "MouseTouchAdaptor.h" |
|
32 |
||
33 |
namespace { |
|
34 |
/* When you append and import path to the list of import paths it will be the *last*
|
|
35 |
place where Qt will search for QML modules.
|
|
36 |
The usual QQmlEngine::addImportPath() actually prepends the given path.*/
|
|
37 |
void appendImportPath(QQmlEngine *engine, const QString &path) |
|
38 |
{
|
|
39 |
QStringList importPathList = engine->importPathList(); |
|
40 |
importPathList.append(path); |
|
41 |
engine->setImportPathList(importPathList); |
|
42 |
}
|
|
43 |
||
44 |
void resolveIconTheme() { |
|
45 |
const char *ubuntuIconTheme = getenv("UBUNTU_ICON_THEME"); |
|
46 |
if (ubuntuIconTheme != NULL) { |
|
47 |
QIcon::setThemeName(ubuntuIconTheme); |
|
48 |
}
|
|
49 |
}
|
|
50 |
} // namespace { |
|
51 |
||
52 |
int main(int argc, char** argv) |
|
53 |
{
|
|
54 |
/* Workaround Qt platform integration plugin not advertising itself
|
|
55 |
as having the following capabilities:
|
|
56 |
- QPlatformIntegration::ThreadedOpenGL
|
|
57 |
- QPlatformIntegration::BufferQueueingOpenGL
|
|
58 |
*/
|
|
59 |
setenv("QML_FORCE_THREADED_RENDERER", "1", 1); |
|
60 |
setenv("QML_FIXED_ANIMATION_STEP", "1", 1); |
|
61 |
||
62 |
QGuiApplication::setApplicationName("Qml Phone Shell"); |
|
63 |
QGuiApplication application(argc, argv); |
|
64 |
||
65 |
resolveIconTheme(); |
|
66 |
||
67 |
QStringList args = application.arguments(); |
|
68 |
||
69 |
// The testability driver is only loaded by QApplication but not by QGuiApplication.
|
|
70 |
// However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
|
|
71 |
if (args.contains(QLatin1String("-testability"))) { |
|
72 |
QLibrary testLib(QLatin1String("qttestability")); |
|
73 |
if (testLib.load()) { |
|
74 |
typedef void (*TasInitialize)(void); |
|
75 |
TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init"); |
|
76 |
if (initFunction) { |
|
77 |
initFunction(); |
|
78 |
} else { |
|
79 |
qCritical("Library qttestability resolve failed!"); |
|
80 |
}
|
|
81 |
} else { |
|
82 |
qCritical("Library qttestability load failed!"); |
|
83 |
}
|
|
84 |
}
|
|
85 |
||
86 |
bindtextdomain("unity8", translationDirectory().toUtf8().data()); |
|
87 |
||
88 |
QQuickView* view = new QQuickView(); |
|
89 |
view->setResizeMode(QQuickView::SizeRootObjectToView); |
|
90 |
view->setTitle("Qml Phone Shell"); |
|
91 |
view->engine()->setBaseUrl(QUrl::fromLocalFile(shellAppDirectory())); |
|
92 |
if (args.contains(QLatin1String("-frameless"))) { |
|
93 |
view->setFlags(Qt::FramelessWindowHint); |
|
94 |
}
|
|
95 |
||
96 |
// You will need this if you want to interact with touch-only components using a mouse
|
|
97 |
// Needed only when manually testing on a desktop.
|
|
98 |
MouseTouchAdaptor *mouseTouchAdaptor = 0; |
|
99 |
if (args.contains(QLatin1String("-mousetouch"))) { |
|
100 |
mouseTouchAdaptor = new MouseTouchAdaptor; |
|
101 |
mouseTouchAdaptor->setTargetWindow(view); |
|
102 |
application.installNativeEventFilter(mouseTouchAdaptor); |
|
103 |
}
|
|
104 |
||
105 |
QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface(); |
|
106 |
/* Shell is declared as a system session so that it always receives all
|
|
107 |
input events.
|
|
108 |
FIXME: use the enum value corresponding to SYSTEM_SESSION_TYPE (= 1)
|
|
109 |
when it becomes available.
|
|
110 |
*/
|
|
111 |
nativeInterface->setProperty("ubuntuSessionType", 1); |
|
112 |
view->setProperty("role", 2); // INDICATOR_ACTOR_ROLE |
|
113 |
||
114 |
QObject::connect(view->engine(), SIGNAL(quit()), qApp, SLOT(quit())); |
|
115 |
||
116 |
QUrl source("Shell.qml"); |
|
117 |
view->engine()->addImportPath(shellAppDirectory()); |
|
118 |
view->engine()->addImportPath(shellImportPath()); |
|
119 |
appendImportPath(view->engine(), fakePluginsImportPath()); |
|
120 |
view->setSource(source); |
|
121 |
view->setColor("transparent"); |
|
122 |
||
123 |
if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || args.contains(QLatin1String("-fullscreen"))) { |
|
124 |
view->showFullScreen(); |
|
125 |
} else { |
|
126 |
if (args.contains(QLatin1String("-geometry")) && args.size() > args.indexOf(QLatin1String("-geometry")) + 1) { |
|
127 |
QStringList geometryArg = args.at(args.indexOf(QLatin1String("-geometry")) + 1).split('x'); |
|
128 |
if (geometryArg.size() == 2) { |
|
129 |
view->resize(geometryArg.at(0).toInt(), geometryArg.at(1).toInt()); |
|
130 |
}
|
|
131 |
}
|
|
132 |
view->show(); |
|
133 |
}
|
|
134 |
||
135 |
int result = application.exec(); |
|
136 |
||
137 |
delete mouseTouchAdaptor; |
|
138 |
||
139 |
return result; |
|
140 |
}
|