17 #include "ShellApplication.h" 26 #include <hybris/properties/properties.h> 30 #include "CachingNetworkManagerFactory.h" 31 #include "UnityCommandLineParser.h" 33 ShellApplication::ShellApplication(
int & argc,
char ** argv,
bool isMirServer)
34 : QGuiApplication(argc, argv)
37 setApplicationName(QStringLiteral(
"unity8"));
39 connect(
this, &QGuiApplication::screenAdded,
this, &ShellApplication::onScreenAdded);
41 setupQmlEngine(isMirServer);
43 UnityCommandLineParser parser(*
this);
45 if (!parser.deviceName().isEmpty()) {
46 m_deviceName = parser.deviceName();
49 property_get(
"ro.product.device", buffer ,
"desktop" );
50 m_deviceName = QString(buffer);
52 m_qmlArgs.setDeviceName(m_deviceName);
54 m_qmlArgs.setMode(parser.mode());
58 if (parser.hasTestability() || getenv(
"QT_LOAD_TESTABILITY")) {
59 QLibrary testLib(QStringLiteral(
"qttestability"));
61 typedef void (*TasInitialize)(void);
62 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
66 qCritical(
"Library qttestability resolve failed!");
69 qCritical(
"Library qttestability load failed!");
73 bindtextdomain(
"unity8", translationDirectory().toUtf8().data());
76 m_shellView =
new ShellView(m_qmlEngine, &m_qmlArgs);
78 if (parser.windowGeometry().isValid()) {
79 m_shellView->setWidth(parser.windowGeometry().width());
80 m_shellView->setHeight(parser.windowGeometry().height());
83 if (parser.hasFrameless()) {
84 m_shellView->setFlags(Qt::FramelessWindowHint);
88 #ifdef UNITY8_ENABLE_TOUCH_EMULATION 91 if (parser.hasMouseToTouch()) {
92 m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
102 if (isMirServer && screens().count() == 2) {
103 m_shellView->setScreen(screens().at(1));
104 m_qmlArgs.setDeviceName(QStringLiteral(
"desktop"));
106 m_secondaryWindow =
new SecondaryWindow(m_qmlEngine);
107 m_secondaryWindow->setScreen(screens().at(0));
109 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
110 m_secondaryWindow->setVisible(
true);
113 if (isMirServer || parser.hasFullscreen()) {
114 m_shellView->showFullScreen();
120 ShellApplication::~ShellApplication()
125 void ShellApplication::destroyResources()
130 m_shellView =
nullptr;
132 delete m_secondaryWindow;
133 m_secondaryWindow =
nullptr;
135 #ifdef UNITY8_ENABLE_TOUCH_EMULATION 136 delete m_mouseTouchAdaptor;
137 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(QStringLiteral(
"desktop"));
170 m_shellView->requestActivate();
173 m_shellView->setVisible(
true);
175 m_secondaryWindow =
new SecondaryWindow(m_qmlEngine);
176 m_secondaryWindow->setScreen(screens().at(0));
179 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
180 m_secondaryWindow->setVisible(
true);
184 void ShellApplication::onScreenAboutToBeRemoved(QScreen *screen)
188 if (screen == m_shellView->screen()) {
189 const QList<QScreen *> allScreens = screens();
190 Q_ASSERT(allScreens.count() > 1);
191 Q_ASSERT(allScreens.at(0) != screen);
192 Q_ASSERT(m_secondaryWindow);
193 delete m_secondaryWindow;
194 m_secondaryWindow =
nullptr;
195 m_shellView->setScreen(allScreens.first());
196 m_qmlArgs.setDeviceName(m_deviceName);
199 m_shellView->requestActivate();
202 m_shellView->setVisible(
true);