Unity 8
main.cpp
1 /*
2  * This file is part of system-settings
3  *
4  * Copyright (C) 2014 Canonical Ltd.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 3, as published
8  * by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranties of
12  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13  * PURPOSE. See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include <csignal>
20 #include <libintl.h>
21 #include <qpa/qplatformnativeinterface.h>
22 #include <QDebug>
23 #include <QGuiApplication>
24 #include <QLibrary>
25 #include <QObject>
26 #include <QProcess>
27 #include <QQmlContext>
28 #include <QQmlEngine>
29 #include <QQuickItem>
30 #include <QQuickView>
31 #include <QTimer>
32 
33 #include "PageList.h"
34 
35 void handleQuit()
36 {
37  QProcess::startDetached("initctl start ubuntu-system-settings-wizard-cleanup");
38 }
39 
40 int main(int argc, const char *argv[])
41 {
42  bool isMirServer = false;
43  if (qgetenv("QT_QPA_PLATFORM") == "ubuntumirclient") {
44  setenv("QT_QPA_PLATFORM", "mirserver", 1 /* overwrite */);
45  isMirServer = true;
46  }
47 
48  QGuiApplication::setApplicationName("System Settings Wizard");
49  QGuiApplication *application = new QGuiApplication(argc, (char**)argv);
50 
51  bindtextdomain(I18N_DOMAIN, NULL);
52  textdomain(I18N_DOMAIN);
53 
54  QQuickView* view = new QQuickView();
55  view->setResizeMode(QQuickView::SizeRootObjectToView);
56  view->setTitle("Welcome Wizard");
57 
58  QString rootDir = qgetenv("UBUNTU_SYSTEM_SETTINGS_WIZARD_ROOT"); // for testing
59  if (rootDir.isEmpty())
60  rootDir = WIZARD_ROOT;
61 
62  QString modulesDir = qgetenv("UBUNTU_SYSTEM_SETTINGS_WIZARD_MODULES"); // for testing
63  if (modulesDir.isEmpty())
64  modulesDir = PLUGIN_PRIVATE_MODULE_DIR;
65 
66  if (!isMirServer) {
67  view->engine()->addImportPath(modulesDir + "/Ubuntu/SystemSettings/Wizard/NonMir");
68  }
69  view->engine()->addImportPath(modulesDir);
70  view->engine()->addImportPath(PLUGIN_QML_DIR);
71  view->engine()->addImportPath(SHELL_PLUGINDIR);
72 
73  PageList pageList;
74  view->rootContext()->setContextProperty("pageList", &pageList);
75  view->setSource(QUrl(rootDir + "/ubuntu/settings/wizard/qml/main.qml"));
76  view->setColor("transparent");
77 
78  QObject::connect(view->engine(), &QQmlEngine::quit, handleQuit);
79 
80  if (isMirServer) {
81  view->showFullScreen();
82  } else {
83  view->show();
84  }
85 
86  int result = application->exec();
87 
88  delete view;
89  delete application;
90  return result;
91 }
92 
93 #include "main.moc"