on 690362d help sign in
unity8/src/Dash/main.cpp
138 lines 4.9 kB history raw
1/*
2 * Copyright (C) 2014 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>
30#include <paths.h>
31#include "../qmldebuggerutils.h"
32#ifdef UNITY8_ENABLE_TOUCH_EMULATION
33 #include "../MouseTouchAdaptor.h"
34#endif
35#include "../CachingNetworkManagerFactory.h"
36#include "../UnixSignalHandler.h"
38int main(int argc, const char *argv[])
40 qSetMessagePattern("[%{time yyyy-mm-dd:hh:mm:ss.zzz}] %{if-category}%{category}: %{endif}%{message}");
41 if (enableQmlDebugger(argc, argv)) {
42 QQmlDebuggingEnabler qQmlEnableDebuggingHelper(true);
43 }
45 QGuiApplication *application = new QGuiApplication(argc, (char**)argv);
47 QCommandLineParser parser;
48 parser.setApplicationDescription(QStringLiteral("Description: Unity 8 Shell Dash"));
49 parser.addHelpOption();
51 QCommandLineOption mousetouchOption(QStringLiteral("mousetouch"),
52 QStringLiteral("Allow the mouse to provide touch input"));
53 parser.addOption(mousetouchOption);
55 QCommandLineOption windowGeometryOption(QStringList() << QStringLiteral("windowgeometry"),
56 QStringLiteral("Specify the window geometry as [<width>x<height>]"), QStringLiteral("windowgeometry"), QStringLiteral("1"));
57 parser.addOption(windowGeometryOption);
59 // FIXME Remove once we drop the need of the hint
60 QCommandLineOption desktopFileHintOption(QStringLiteral("desktop_file_hint"),
61 QStringLiteral("The desktop_file_hint option for QtMir"), QStringLiteral("hint_file"));
62 parser.addOption(desktopFileHintOption);
64 // Treat args with single dashes the same as arguments with two dashes
65 // Ex: -fullscreen == --fullscreen
66 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
67 parser.process(*application);
69 if (getenv("QT_LOAD_TESTABILITY")) {
70 QLibrary testLib(QStringLiteral("qttestability"));
71 if (testLib.load()) {
72 typedef void (*TasInitialize)(void);
73 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
74 if (initFunction) {
75 initFunction();
76 } else {
77 qCritical("Library qttestability resolve failed!");
78 }
79 } else {
80 qCritical("Library qttestability load failed!");
81 }
82 }
84 bindtextdomain("unity8", translationDirectory().toUtf8().data());
85 textdomain("unity8");
87 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
88 // You will need this if you want to interact with touch-only components using a mouse
89 // Needed only when manually testing on a desktop.
90 MouseTouchAdaptor *mouseTouchAdaptor = 0;
91 if (parser.isSet(mousetouchOption)) {
92 mouseTouchAdaptor = MouseTouchAdaptor::instance();
93 }
94 #endif
96 QQmlApplicationEngine *engine = new QQmlApplicationEngine(application);
98 int initialWidth = -1;
99 int initialHeight = -1;
100 if (parser.isSet(windowGeometryOption) &&
101 parser.value(windowGeometryOption).split('x').size() == 2)
102 {
103 QStringList geom = parser.value(windowGeometryOption).split('x');
104 QSize windowSize(geom.at(0).toInt(), geom.at(1).toInt());
105 if (windowSize.isValid()) {
106 initialWidth = windowSize.width();
107 initialHeight = windowSize.height();
108 }
109 }
110 engine->rootContext()->setContextProperty("initialWidth", initialWidth);
111 engine->rootContext()->setContextProperty("initialHeight", initialHeight);
113 QUrl source(::qmlDirectory() + "/Dash/DashApplication.qml");
114 prependImportPaths(engine, ::overrideImportPaths());
115 appendImportPaths(engine, ::fallbackImportPaths());
117 CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
118 engine->setNetworkAccessManagerFactory(managerFactory);
120 engine->load(source);
122 UnixSignalHandler signalHandler([]{
123 QGuiApplication::exit(0);
124 });
125 signalHandler.setupUnixSignalHandlers();
127 int result = application->exec();
129 delete engine;
131 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
132 delete mouseTouchAdaptor;
133 #endif
135 delete application;
137 return result;