17 #include "ShellApplication.h" 29 #include <hybris/properties/properties.h> 33 #include "CachingNetworkManagerFactory.h" 34 #include "UnityCommandLineParser.h" 35 #include "DebuggingController.h" 37 ShellApplication::ShellApplication(
int & argc,
char ** argv,
bool isMirServer)
38 : QGuiApplication(argc, argv)
40 setApplicationName(QStringLiteral(
"unity8"));
41 setOrganizationName(QStringLiteral(
"Canonical"));
43 connect(
this, &QGuiApplication::screenAdded,
this, &ShellApplication::onScreenAdded);
44 connect(
this, &QGuiApplication::screenRemoved,
this, &ShellApplication::onScreenRemoved);
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 property_get(
"ubuntu.unity8.interactive_blur", buffer,
"true");
64 m_qmlArgs.setInteractiveBlur(QString(buffer) == QStringLiteral(
"true"));
69 if (parser.hasTestability() || getenv(
"QT_LOAD_TESTABILITY")) {
70 QLibrary testLib(QStringLiteral(
"qttestability"));
72 typedef void (*TasInitialize)(void);
73 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
77 qCritical(
"Library qttestability resolve failed!");
80 qCritical(
"Library qttestability load failed!");
84 bindtextdomain(
"unity8", translationDirectory().toUtf8().data());
87 QScopedPointer<QGSettings> gSettings(
new QGSettings(
"com.canonical.Unity8"));
88 gSettings->reset(QStringLiteral(
"alwaysShowOsk"));
90 m_shellView =
new ShellView(m_qmlEngine, &m_qmlArgs);
92 if (parser.windowGeometry().isValid()) {
93 m_shellView->setWidth(parser.windowGeometry().width());
94 m_shellView->setHeight(parser.windowGeometry().height());
97 if (parser.hasFrameless()) {
98 m_shellView->setFlags(Qt::FramelessWindowHint);
102 #ifdef UNITY8_ENABLE_TOUCH_EMULATION 105 if (parser.hasMouseToTouch()) {
106 m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
110 new DebuggingController(
this);
117 if (isMirServer && screens().count() == 2) {
118 m_shellView->setScreen(screens().at(1));
119 m_qmlArgs.setDeviceName(QStringLiteral(
"desktop"));
121 m_secondaryWindow =
new SecondaryWindow(m_qmlEngine);
122 m_secondaryWindow->setScreen(screens().at(0));
124 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
125 m_secondaryWindow->setVisible(
true);
128 if (parser.mode().compare(
"greeter") == 0) {
129 QSize primaryScreenSize = this->primaryScreen()->size();
130 m_shellView->setHeight(primaryScreenSize.height());
131 m_shellView->setWidth(primaryScreenSize.width());
133 m_shellView->requestActivate();
134 if (!QProcess::startDetached(
"initctl emit --no-wait unity8-greeter-started")) {
135 qDebug() <<
"Unable to send unity8-greeter-started event to Upstart";
137 }
else if (isMirServer || parser.hasFullscreen()) {
138 m_shellView->showFullScreen();
144 ShellApplication::~ShellApplication()
149 void ShellApplication::destroyResources()
154 m_shellView =
nullptr;
156 delete m_secondaryWindow;
157 m_secondaryWindow =
nullptr;
159 #ifdef UNITY8_ENABLE_TOUCH_EMULATION 160 delete m_mouseTouchAdaptor;
161 m_mouseTouchAdaptor =
nullptr;
165 m_qmlEngine =
nullptr;
168 void ShellApplication::setupQmlEngine(
bool isMirServer)
170 m_qmlEngine =
new QQmlEngine(
this);
172 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
174 prependImportPaths(m_qmlEngine, ::overrideImportPaths());
176 prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
178 appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
180 m_qmlEngine->setNetworkAccessManagerFactory(
new CachingNetworkManagerFactory);
182 QObject::connect(m_qmlEngine, &QQmlEngine::quit,
this, &QGuiApplication::quit);
185 void ShellApplication::onScreenAdded(QScreen * )
189 if (screens().count() == 2) {
190 m_shellView->setScreen(screens().at(1));
191 m_qmlArgs.setDeviceName(QStringLiteral(
"desktop"));
194 m_shellView->setVisible(
true);
196 m_secondaryWindow =
new SecondaryWindow(m_qmlEngine);
197 m_secondaryWindow->setScreen(screens().at(0));
200 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
201 m_secondaryWindow->setVisible(
true);
207 m_shellView->requestActivate();
211 void ShellApplication::onScreenRemoved(QScreen *screen)
215 if (screen == m_shellView->screen()) {
216 const QList<QScreen *> allScreens = screens();
217 Q_ASSERT(allScreens.count() > 1);
218 Q_ASSERT(allScreens.at(0) != screen);
219 Q_ASSERT(m_secondaryWindow);
220 delete m_secondaryWindow;
221 m_secondaryWindow =
nullptr;
222 m_shellView->setScreen(allScreens.first());
223 m_qmlArgs.setDeviceName(m_deviceName);
226 m_shellView->requestActivate();
229 m_shellView->setVisible(
true);