on ec00b9e help sign in
unity8/src/Dash/main.cpp
115 lines 4.1 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 "../ApplicationArguments.h"
32#include "../CachingNetworkManagerFactory.h"
34int main(int argc, const char *argv[])
36 QGuiApplication *application = new QGuiApplication(argc, (char**)argv);
38 QCommandLineParser parser;
39 parser.setApplicationDescription("Description: Unity 8 Shell Dash");
40 parser.addHelpOption();
42 QCommandLineOption mousetouchOption("mousetouch",
43 "Allow the mouse to provide touch input");
44 parser.addOption(mousetouchOption);
46 QCommandLineOption windowGeometryOption(QStringList() << "windowgeometry",
47 "Specify the window geometry as [<width>x<height>]", "windowgeometry", "1");
48 parser.addOption(windowGeometryOption);
50 // FIXME Remove once we drop the need of the hint
51 QCommandLineOption desktopFileHintOption("desktop_file_hint",
52 "The desktop_file_hint option for QtMir", "hint_file");
53 parser.addOption(desktopFileHintOption);
55 // Treat args with single dashes the same as arguments with two dashes
56 // Ex: -fullscreen == --fullscreen
57 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
58 parser.process(*application);
60 ApplicationArguments qmlArgs;
61 if (parser.isSet(windowGeometryOption) &&
62 parser.value(windowGeometryOption).split('x').size() == 2)
63 {
64 QStringList geom = parser.value(windowGeometryOption).split('x');
65 qmlArgs.setSize(geom.at(0).toInt(), geom.at(1).toInt());
66 }
68 if (getenv("QT_LOAD_TESTABILITY")) {
69 QLibrary testLib(QLatin1String("qttestability"));
70 if (testLib.load()) {
71 typedef void (*TasInitialize)(void);
72 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
73 if (initFunction) {
74 initFunction();
75 } else {
76 qCritical("Library qttestability resolve failed!");
77 }
78 } else {
79 qCritical("Library qttestability load failed!");
80 }
81 }
83 bindtextdomain("unity8", translationDirectory().toUtf8().data());
84 textdomain("unity8");
86 QQuickView* view = new QQuickView();
87 view->setResizeMode(QQuickView::SizeRootObjectToView);
88 view->setTitle("Scopes");
89 view->rootContext()->setContextProperty("applicationArguments", &qmlArgs);
91 // You will need this if you want to interact with touch-only components using a mouse
92 // Needed only when manually testing on a desktop.
93 MouseTouchAdaptor *mouseTouchAdaptor = 0;
94 if (parser.isSet(mousetouchOption)) {
95 mouseTouchAdaptor = new MouseTouchAdaptor;
96 application->installNativeEventFilter(mouseTouchAdaptor);
97 }
99 QUrl source(::qmlDirectory()+"Dash/DashApplication.qml");
100 prependImportPaths(view->engine(), ::overrideImportPaths());
101 appendImportPaths(view->engine(), ::fallbackImportPaths());
103 CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
104 view->engine()->setNetworkAccessManagerFactory(managerFactory);
106 view->setSource(source);
107 view->show();
109 int result = application->exec();
111 delete view;
112 delete application;
114 return result;