17 #include "ShellApplication.h"
26 #include <hybris/properties/properties.h>
30 #include "CachingNetworkManagerFactory.h"
31 #include "MouseTouchAdaptor.h"
32 #include "UnityCommandLineParser.h"
34 ShellApplication::ShellApplication(
int & argc,
char ** argv,
bool isMirServer)
35 : QGuiApplication(argc, argv)
36 , m_shellView(nullptr)
37 , m_secondaryWindow(nullptr)
38 , m_mouseTouchAdaptor(nullptr)
39 , m_qmlEngine(nullptr)
42 setApplicationName(QStringLiteral(
"unity8"));
44 connect(
this, &QGuiApplication::screenAdded,
this, &ShellApplication::onScreenAdded);
46 setupQmlEngine(isMirServer);
48 UnityCommandLineParser parser(*
this);
50 if (!parser.deviceName().isEmpty()) {
51 m_deviceName = parser.deviceName();
54 property_get(
"ro.product.device", buffer ,
"desktop" );
55 m_deviceName = QString(buffer);
57 m_qmlArgs.setDeviceName(m_deviceName);
59 m_qmlArgs.setMode(parser.mode());
63 if (parser.hasTestability() || getenv(
"QT_LOAD_TESTABILITY")) {
64 QLibrary testLib(QStringLiteral(
"qttestability"));
66 typedef void (*TasInitialize)(void);
67 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
71 qCritical(
"Library qttestability resolve failed!");
74 qCritical(
"Library qttestability load failed!");
78 bindtextdomain(
"unity8", translationDirectory().toUtf8().data());
81 m_shellView =
new ShellView(m_qmlEngine, &m_qmlArgs);
83 if (parser.windowGeometry().isValid()) {
84 m_shellView->setWidth(parser.windowGeometry().width());
85 m_shellView->setHeight(parser.windowGeometry().height());
88 if (parser.hasFrameless()) {
89 m_shellView->setFlags(Qt::FramelessWindowHint);
94 if (parser.hasMouseToTouch()) {
95 m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
104 if (isMirServer && screens().count() == 2) {
105 m_shellView->setScreen(screens().at(1));
106 m_qmlArgs.setDeviceName(
"desktop");
108 m_secondaryWindow =
new SecondaryWindow(m_qmlEngine);
109 m_secondaryWindow->setScreen(screens().at(0));
111 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
112 m_secondaryWindow->setVisible(
true);
115 if (isMirServer || parser.hasFullscreen()) {
116 m_shellView->showFullScreen();
122 ShellApplication::~ShellApplication()
127 void ShellApplication::destroyResources()
132 m_shellView =
nullptr;
134 delete m_secondaryWindow;
135 m_secondaryWindow =
nullptr;
137 delete m_mouseTouchAdaptor;
138 m_mouseTouchAdaptor =
nullptr;
141 m_qmlEngine =
nullptr;
144 void ShellApplication::setupQmlEngine(
bool isMirServer)
146 m_qmlEngine =
new QQmlEngine(
this);
148 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
150 prependImportPaths(m_qmlEngine, ::overrideImportPaths());
152 prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
154 appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
156 m_qmlEngine->setNetworkAccessManagerFactory(
new CachingNetworkManagerFactory);
158 QObject::connect(m_qmlEngine, &QQmlEngine::quit,
this, &QGuiApplication::quit);
161 void ShellApplication::onScreenAdded(QScreen * )
165 if (screens().count() == 2) {
166 m_shellView->setScreen(screens().at(1));
167 m_qmlArgs.setDeviceName(
"desktop");
170 m_shellView->requestActivate();
172 m_secondaryWindow =
new SecondaryWindow(m_qmlEngine);
173 m_secondaryWindow->setScreen(screens().at(0));
176 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
177 m_secondaryWindow->setVisible(
true);
181 void ShellApplication::onScreenAboutToBeRemoved(QScreen *screen)
185 if (screen == m_shellView->screen()) {
186 Q_ASSERT(screens().count() > 1);
187 Q_ASSERT(screens().at(0) != screen);
188 Q_ASSERT(m_secondaryWindow);
189 delete m_secondaryWindow;
190 m_secondaryWindow =
nullptr;
191 m_shellView->setScreen(screens().first());
192 m_qmlArgs.setDeviceName(m_deviceName);
195 m_shellView->requestActivate();