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);
45 setupQmlEngine(isMirServer);
47 UnityCommandLineParser parser(*
this);
49 if (!parser.deviceName().isEmpty()) {
50 m_deviceName = parser.deviceName();
53 property_get(
"ro.product.device", buffer ,
"desktop" );
54 m_deviceName = QString(buffer);
56 m_qmlArgs.setDeviceName(m_deviceName);
58 m_qmlArgs.setMode(parser.mode());
62 if (parser.hasTestability() || getenv(
"QT_LOAD_TESTABILITY")) {
63 QLibrary testLib(QStringLiteral(
"qttestability"));
65 typedef void (*TasInitialize)(void);
66 TasInitialize initFunction = (TasInitialize)testLib.resolve(
"qt_testability_init");
70 qCritical(
"Library qttestability resolve failed!");
73 qCritical(
"Library qttestability load failed!");
77 bindtextdomain(
"unity8", translationDirectory().toUtf8().data());
80 QScopedPointer<QGSettings> gSettings(
new QGSettings(
"com.canonical.Unity8"));
81 gSettings->reset(QStringLiteral(
"alwaysShowOsk"));
83 m_shellView =
new ShellView(m_qmlEngine, &m_qmlArgs);
85 if (parser.windowGeometry().isValid()) {
86 m_shellView->setWidth(parser.windowGeometry().width());
87 m_shellView->setHeight(parser.windowGeometry().height());
90 if (parser.hasFrameless()) {
91 m_shellView->setFlags(Qt::FramelessWindowHint);
95 #ifdef UNITY8_ENABLE_TOUCH_EMULATION 98 if (parser.hasMouseToTouch()) {
99 m_mouseTouchAdaptor = MouseTouchAdaptor::instance();
103 new DebuggingController(
this);
110 if (isMirServer && screens().count() == 2) {
111 m_shellView->setScreen(screens().at(1));
112 m_qmlArgs.setDeviceName(QStringLiteral(
"desktop"));
114 m_secondaryWindow =
new SecondaryWindow(m_qmlEngine);
115 m_secondaryWindow->setScreen(screens().at(0));
117 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
118 m_secondaryWindow->setVisible(
true);
121 if (parser.mode().compare(
"greeter") == 0) {
122 QSize primaryScreenSize = this->primaryScreen()->size();
123 m_shellView->setHeight(primaryScreenSize.height());
124 m_shellView->setWidth(primaryScreenSize.width());
126 m_shellView->requestActivate();
127 if (!QProcess::startDetached(
"initctl emit --no-wait unity8-greeter-started")) {
128 qDebug() <<
"Unable to send unity8-greeter-started event to Upstart";
130 }
else if (isMirServer || parser.hasFullscreen()) {
131 m_shellView->showFullScreen();
137 ShellApplication::~ShellApplication()
142 void ShellApplication::destroyResources()
147 m_shellView =
nullptr;
149 delete m_secondaryWindow;
150 m_secondaryWindow =
nullptr;
152 #ifdef UNITY8_ENABLE_TOUCH_EMULATION 153 delete m_mouseTouchAdaptor;
154 m_mouseTouchAdaptor =
nullptr;
158 m_qmlEngine =
nullptr;
161 void ShellApplication::setupQmlEngine(
bool isMirServer)
163 m_qmlEngine =
new QQmlEngine(
this);
165 m_qmlEngine->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
167 prependImportPaths(m_qmlEngine, ::overrideImportPaths());
169 prependImportPaths(m_qmlEngine, ::nonMirImportPaths());
171 appendImportPaths(m_qmlEngine, ::fallbackImportPaths());
173 m_qmlEngine->setNetworkAccessManagerFactory(
new CachingNetworkManagerFactory);
175 QObject::connect(m_qmlEngine, &QQmlEngine::quit,
this, &QGuiApplication::quit);
178 void ShellApplication::onScreenAdded(QScreen * )
182 if (screens().count() == 2) {
183 m_shellView->setScreen(screens().at(1));
184 m_qmlArgs.setDeviceName(QStringLiteral(
"desktop"));
187 m_shellView->requestActivate();
190 m_shellView->setVisible(
true);
192 m_secondaryWindow =
new SecondaryWindow(m_qmlEngine);
193 m_secondaryWindow->setScreen(screens().at(0));
196 m_secondaryWindow->setWindowState(Qt::WindowFullScreen);
197 m_secondaryWindow->setVisible(
true);
201 void ShellApplication::onScreenAboutToBeRemoved(QScreen *screen)
205 if (screen == m_shellView->screen()) {
206 const QList<QScreen *> allScreens = screens();
207 Q_ASSERT(allScreens.count() > 1);
208 Q_ASSERT(allScreens.at(0) != screen);
209 Q_ASSERT(m_secondaryWindow);
210 delete m_secondaryWindow;
211 m_secondaryWindow =
nullptr;
212 m_shellView->setScreen(allScreens.first());
213 m_qmlArgs.setDeviceName(m_deviceName);
216 m_shellView->requestActivate();
219 m_shellView->setVisible(
true);