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