on f621663 help sign in
unity8/src/Dash/main.cpp
100 lines 3.5 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>
29#include <paths.h>
30#include "../MouseTouchAdaptor.h"
31#include "../CachingNetworkManagerFactory.h"
33int main(int argc, const char *argv[])
35 QGuiApplication *application = new QGuiApplication(argc, (char**)argv);
37 QCommandLineParser parser;
38 parser.setApplicationDescription("Description: Unity 8 Shell Dash");
39 parser.addHelpOption();
41 QCommandLineOption mousetouchOption("mousetouch",
42 "Allow the mouse to provide touch input");
43 parser.addOption(mousetouchOption);
45 // FIXME Remove once we drop the need of the hint
46 QCommandLineOption desktopFileHintOption("desktop_file_hint",
47 "The desktop_file_hint option for QtMir", "hint_file");
48 parser.addOption(desktopFileHintOption);
50 // Treat args with single dashes the same as arguments with two dashes
51 // Ex: -fullscreen == --fullscreen
52 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
53 parser.process(*application);
55 if (getenv("QT_LOAD_TESTABILITY")) {
56 QLibrary testLib(QLatin1String("qttestability"));
57 if (testLib.load()) {
58 typedef void (*TasInitialize)(void);
59 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
60 if (initFunction) {
61 initFunction();
62 } else {
63 qCritical("Library qttestability resolve failed!");
64 }
65 } else {
66 qCritical("Library qttestability load failed!");
67 }
68 }
70 bindtextdomain("unity8", translationDirectory().toUtf8().data());
72 QQuickView* view = new QQuickView();
73 view->setResizeMode(QQuickView::SizeRootObjectToView);
74 view->setTitle("Unity Dash");
76 // You will need this if you want to interact with touch-only components using a mouse
77 // Needed only when manually testing on a desktop.
78 MouseTouchAdaptor *mouseTouchAdaptor = 0;
79 if (parser.isSet(mousetouchOption)) {
80 mouseTouchAdaptor = new MouseTouchAdaptor;
81 application->installNativeEventFilter(mouseTouchAdaptor);
82 }
84 QUrl source(::qmlDirectory()+"Dash/DashApplication.qml");
85 prependImportPaths(view->engine(), ::overrideImportPaths());
86 appendImportPaths(view->engine(), ::fallbackImportPaths());
88 CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
89 view->engine()->setNetworkAccessManagerFactory(managerFactory);
91 view->setSource(source);
92 view->show();
94 int result = application->exec();
96 delete view;
97 delete application;
99 return result;