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"));
39 setOrganizationName(QStringLiteral(
"Canonical"));
41 connect(
this, &QGuiApplication::screenAdded,
this, &ShellApplication::onScreenAdded);
43 setupQmlEngine(isMirServer);
45 UnityCommandLineParser parser(*
this);
47 if (!parser.deviceName().isEmpty()) {
48 m_deviceName = parser.deviceName();
51 property_get(
"ro.product.device", buffer ,
"desktop" );
52 m_deviceName = QString(buffer);
54 m_qmlArgs.setDeviceName(m_deviceName);
56 m_qmlArgs.setMode(parser.mode());
60 if (parser.hasTestability() || getenv(
"QT_LOAD_TESTABILITY")) {
61 QLibrary testLib(QStringLiteral(
"qttestability"));
63 typedef void (*TasInitialize)(void);
64 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
68 qCritical(
"Library qttestability resolve failed!");
71 qCritical(
"Library qttestability load failed!");
75 bindtextdomain(
"unity8", translationDirectory().toUtf8().data());
78 m_shellView =
new ShellView(m_qmlEngine, &m_qmlArgs);
80 if (parser.windowGeometry().isValid()) {
81 m_shellView->setWidth(parser.windowGeometry().width());
82 m_shellView->setHeight(parser.windowGeometry().height());
85 if (parser.hasFrameless()) {
86 m_shellView->setFlags(Qt::FramelessWindowHint);
90 #ifdef UNITY8_ENABLE_TOUCH_EMULATION 93 if (parser.hasMouseToTouch()) {
94 m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
104 if (isMirServer && screens().count() == 2) {
105 m_shellView->setScreen(screens().at(1));
106 m_qmlArgs.setDeviceName(QStringLiteral(
"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 (parser.mode().compare(
"greeter") == 0) {
116 QSize primaryScreenSize = this->primaryScreen()->size();
117 m_shellView->setHeight(primaryScreenSize.height());
118 m_shellView->setWidth(primaryScreenSize.width());
120 m_shellView->requestActivate();
121 if (!QProcess::startDetached(
"initctl emit --no-wait unity8-greeter-started")) {
122 qDebug() <<
"Unable to send unity8-greeter-started event to Upstart";
124 }
else if (isMirServer || parser.hasFullscreen()) {
125 m_shellView->showFullScreen();
131 ShellApplication::~ShellApplication()
136 void ShellApplication::destroyResources()
141 m_shellView =
nullptr;
143 delete m_secondaryWindow;
144 m_secondaryWindow =
nullptr;
146 #ifdef UNITY8_ENABLE_TOUCH_EMULATION 147 delete m_mouseTouchAdaptor;
148 m_mouseTouchAdaptor =
nullptr;
152 m_qmlEngine =
nullptr;
155 void ShellApplication::setupQmlEngine(
bool isMirServer)
157 m_qmlEngine =
new QQmlEngine(
this);
159 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
161 prependImportPaths(m_qmlEngine, ::overrideImportPaths());
163 prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
165 appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
167 m_qmlEngine->setNetworkAccessManagerFactory(
new CachingNetworkManagerFactory);
169 QObject::connect(m_qmlEngine, &QQmlEngine::quit,
this, &QGuiApplication::quit);
172 void ShellApplication::onScreenAdded(QScreen * )
176 if (screens().count() == 2) {
177 m_shellView->setScreen(screens().at(1));
178 m_qmlArgs.setDeviceName(QStringLiteral(
"desktop"));
181 m_shellView->requestActivate();
184 m_shellView->setVisible(
true);
186 m_secondaryWindow =
new SecondaryWindow(m_qmlEngine);
187 m_secondaryWindow->setScreen(screens().at(0));
190 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
191 m_secondaryWindow->setVisible(
true);
195 void ShellApplication::onScreenAboutToBeRemoved(QScreen *screen)
199 if (screen == m_shellView->screen()) {
200 const QList<QScreen *> allScreens = screens();
201 Q_ASSERT(allScreens.count() > 1);
202 Q_ASSERT(allScreens.at(0) != screen);
203 Q_ASSERT(m_secondaryWindow);
204 delete m_secondaryWindow;
205 m_secondaryWindow =
nullptr;
206 m_shellView->setScreen(allScreens.first());
207 m_qmlArgs.setDeviceName(m_deviceName);
210 m_shellView->requestActivate();
213 m_shellView->setVisible(
true);