on master help sign in
unity8/src/Dash/main.cpp
146 lines 5.2 kB history raw
1/*
2 * Copyright (C) 2014-2016 Canonical, Ltd.
3 *
4 * Authors:
5 * Michael Zanetti <michael.zanetti@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
20#include <QtQuick/QQuickView>
21#include <QtGui/QGuiApplication>
22#include <QtQml/QQmlEngine>
23#include <QtQml/QQmlContext>
24#include <QDebug>
25#include <QCommandLineParser>
26#include <QLibrary>
27#include <libintl.h>
28#include <QQmlApplicationEngine>
29#include <QTranslator>
30#include <QLibraryInfo>
31#include <QLocale>
33#include <paths.h>
34#include "../qmldebuggerutils.h"
35#ifdef UNITY8_ENABLE_TOUCH_EMULATION
36 #include "../MouseTouchAdaptor.h"
37#endif
38#include "../CachingNetworkManagerFactory.h"
39#include "../UnixSignalHandler.h"
41int main(int argc, const char *argv[])
43 qSetMessagePattern("[%{time yyyy-MM-dd:hh:mm:ss.zzz}] %{if-category}%{category}: %{endif}%{message}");
44 if (enableQmlDebugger(argc, argv)) {
45 QQmlDebuggingEnabler qQmlEnableDebuggingHelper(true);
46 }
48 QGuiApplication *application = new QGuiApplication(argc, (char**)argv);
50 QCommandLineParser parser;
51 parser.setApplicationDescription(QStringLiteral("Description: Unity 8 Shell Dash"));
52 parser.addHelpOption();
54 QCommandLineOption mousetouchOption(QStringLiteral("mousetouch"),
55 QStringLiteral("Allow the mouse to provide touch input"));
56 parser.addOption(mousetouchOption);
58 QCommandLineOption windowGeometryOption(QStringList() << QStringLiteral("windowgeometry"),
59 QStringLiteral("Specify the window geometry as [<width>x<height>]"), QStringLiteral("windowgeometry"), QStringLiteral("1"));
60 parser.addOption(windowGeometryOption);
62 // FIXME Remove once we drop the need of the hint
63 QCommandLineOption desktopFileHintOption(QStringLiteral("desktop_file_hint"),
64 QStringLiteral("The desktop_file_hint option for QtMir"), QStringLiteral("hint_file"));
65 parser.addOption(desktopFileHintOption);
67 // Treat args with single dashes the same as arguments with two dashes
68 // Ex: -fullscreen == --fullscreen
69 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
70 parser.process(*application);
72 if (getenv("QT_LOAD_TESTABILITY")) {
73 QLibrary testLib(QStringLiteral("qttestability"));
74 if (testLib.load()) {
75 typedef void (*TasInitialize)(void);
76 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
77 if (initFunction) {
78 initFunction();
79 } else {
80 qCritical("Library qttestability resolve failed!");
81 }
82 } else {
83 qCritical("Library qttestability load failed!");
84 }
85 }
87 QTranslator qtTranslator;
88 if (qtTranslator.load(QLocale(), QStringLiteral("qt_"), qgetenv("SNAP"), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
89 application->installTranslator(&qtTranslator);
90 }
92 bindtextdomain("unity8", translationDirectory().toUtf8().data());
93 textdomain("unity8");
95 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
96 // You will need this if you want to interact with touch-only components using a mouse
97 // Needed only when manually testing on a desktop.
98 MouseTouchAdaptor *mouseTouchAdaptor = 0;
99 if (parser.isSet(mousetouchOption)) {
100 mouseTouchAdaptor = MouseTouchAdaptor::instance();
101 }
102 #endif
104 QQmlApplicationEngine *engine = new QQmlApplicationEngine(application);
106 int initialWidth = -1;
107 int initialHeight = -1;
108 if (parser.isSet(windowGeometryOption) &&
109 parser.value(windowGeometryOption).split('x').size() == 2)
110 {
111 QStringList geom = parser.value(windowGeometryOption).split('x');
112 QSize windowSize(geom.at(0).toInt(), geom.at(1).toInt());
113 if (windowSize.isValid()) {
114 initialWidth = windowSize.width();
115 initialHeight = windowSize.height();
116 }
117 }
118 engine->rootContext()->setContextProperty("initialWidth", initialWidth);
119 engine->rootContext()->setContextProperty("initialHeight", initialHeight);
121 QUrl source(::qmlDirectory() + "/Dash/DashApplication.qml");
122 prependImportPaths(engine, ::overrideImportPaths());
123 appendImportPaths(engine, ::fallbackImportPaths());
125 CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
126 engine->setNetworkAccessManagerFactory(managerFactory);
128 engine->load(source);
130 UnixSignalHandler signalHandler([]{
131 QGuiApplication::exit(0);
132 });
133 signalHandler.setupUnixSignalHandlers();
135 int result = application->exec();
137 delete engine;
139 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
140 delete mouseTouchAdaptor;
141 #endif
143 delete application;
145 return result;