17 #include "ShellApplication.h" 27 #include <hybris/properties/properties.h> 31 #include "CachingNetworkManagerFactory.h" 32 #include "UnityCommandLineParser.h" 34 ShellApplication::ShellApplication(
int & argc,
char ** argv,
bool isMirServer)
35 : QGuiApplication(argc, argv)
38 setApplicationName(QStringLiteral(
"unity8"));
40 connect(
this, &QGuiApplication::screenAdded,
this, &ShellApplication::onScreenAdded);
42 setupQmlEngine(isMirServer);
44 UnityCommandLineParser parser(*
this);
46 if (!parser.deviceName().isEmpty()) {
47 m_deviceName = parser.deviceName();
50 property_get(
"ro.product.device", buffer ,
"desktop" );
51 m_deviceName = QString(buffer);
53 m_qmlArgs.setDeviceName(m_deviceName);
55 m_qmlArgs.setMode(parser.mode());
59 if (parser.hasTestability() || getenv(
"QT_LOAD_TESTABILITY")) {
60 QLibrary testLib(QStringLiteral(
"qttestability"));
62 typedef void (*TasInitialize)(void);
63 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
67 qCritical(
"Library qttestability resolve failed!");
70 qCritical(
"Library qttestability load failed!");
74 bindtextdomain(
"unity8", translationDirectory().toUtf8().data());
77 m_shellView =
new ShellView(m_qmlEngine, &m_qmlArgs);
79 if (parser.windowGeometry().isValid()) {
80 m_shellView->setWidth(parser.windowGeometry().width());
81 m_shellView->setHeight(parser.windowGeometry().height());
84 if (parser.hasFrameless()) {
85 m_shellView->setFlags(Qt::FramelessWindowHint);
89 #ifdef UNITY8_ENABLE_TOUCH_EMULATION 92 if (parser.hasMouseToTouch()) {
93 m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
103 if (isMirServer && screens().count() == 2) {
104 m_shellView->setScreen(screens().at(1));
105 m_qmlArgs.setDeviceName(QStringLiteral(
"desktop"));
107 m_secondaryWindow =
new SecondaryWindow(m_qmlEngine);
108 m_secondaryWindow->setScreen(screens().at(0));
110 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
111 m_secondaryWindow->setVisible(
true);
114 if (parser.mode().compare(
"greeter") == 0) {
115 QSize primaryScreenSize = this->primaryScreen()->size();
116 m_shellView->setHeight(primaryScreenSize.height());
117 m_shellView->setWidth(primaryScreenSize.width());
119 m_shellView->requestActivate();
120 if (!QProcess::startDetached(
"/sbin/initctl emit --no-wait unity8-greeter-started")) {
121 qDebug() <<
"Unable to send unity8-greeter-started event to Upstart";
123 }
else if (isMirServer || parser.hasFullscreen()) {
124 m_shellView->showFullScreen();
130 ShellApplication::~ShellApplication()
135 void ShellApplication::destroyResources()
140 m_shellView =
nullptr;
142 delete m_secondaryWindow;
143 m_secondaryWindow =
nullptr;
145 #ifdef UNITY8_ENABLE_TOUCH_EMULATION 146 delete m_mouseTouchAdaptor;
147 m_mouseTouchAdaptor =
nullptr;
151 m_qmlEngine =
nullptr;
154 void ShellApplication::setupQmlEngine(
bool isMirServer)
156 m_qmlEngine =
new QQmlEngine(
this);
158 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
160 prependImportPaths(m_qmlEngine, ::overrideImportPaths());
162 prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
164 appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
166 m_qmlEngine->setNetworkAccessManagerFactory(
new CachingNetworkManagerFactory);
168 QObject::connect(m_qmlEngine, &QQmlEngine::quit,
this, &QGuiApplication::quit);
171 void ShellApplication::onScreenAdded(QScreen * )
175 if (screens().count() == 2) {
176 m_shellView->setScreen(screens().at(1));
177 m_qmlArgs.setDeviceName(QStringLiteral(
"desktop"));
180 m_shellView->requestActivate();
183 m_shellView->setVisible(
true);
185 m_secondaryWindow =
new SecondaryWindow(m_qmlEngine);
186 m_secondaryWindow->setScreen(screens().at(0));
189 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
190 m_secondaryWindow->setVisible(
true);
194 void ShellApplication::onScreenAboutToBeRemoved(QScreen *screen)
198 if (screen == m_shellView->screen()) {
199 const QList<QScreen *> allScreens = screens();
200 Q_ASSERT(allScreens.count() > 1);
201 Q_ASSERT(allScreens.at(0) != screen);
202 Q_ASSERT(m_secondaryWindow);
203 delete m_secondaryWindow;
204 m_secondaryWindow =
nullptr;
205 m_shellView->setScreen(allScreens.first());
206 m_qmlArgs.setDeviceName(m_deviceName);
209 m_shellView->requestActivate();
212 m_shellView->setVisible(
true);