on 95d4e79 help sign in
unity8/src/Dash/main.cpp
130 lines 4.6 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 "../qmldebuggerutils.h"
31#ifdef UNITY8_ENABLE_TOUCH_EMULATION
32 #include "../MouseTouchAdaptor.h"
33#endif
34#include "../CachingNetworkManagerFactory.h"
36int main(int argc, const char *argv[])
38 if (enableQmlDebugger(argc, argv)) {
39 QQmlDebuggingEnabler qQmlEnableDebuggingHelper(true);
40 }
42 QGuiApplication *application = new QGuiApplication(argc, (char**)argv);
44 QCommandLineParser parser;
45 parser.setApplicationDescription(QStringLiteral("Description: Unity 8 Shell Dash"));
46 parser.addHelpOption();
48 QCommandLineOption mousetouchOption(QStringLiteral("mousetouch"),
49 QStringLiteral("Allow the mouse to provide touch input"));
50 parser.addOption(mousetouchOption);
52 QCommandLineOption windowGeometryOption(QStringList() << QStringLiteral("windowgeometry"),
53 QStringLiteral("Specify the window geometry as [<width>x<height>]"), QStringLiteral("windowgeometry"), QStringLiteral("1"));
54 parser.addOption(windowGeometryOption);
56 // FIXME Remove once we drop the need of the hint
57 QCommandLineOption desktopFileHintOption(QStringLiteral("desktop_file_hint"),
58 QStringLiteral("The desktop_file_hint option for QtMir"), QStringLiteral("hint_file"));
59 parser.addOption(desktopFileHintOption);
61 // Treat args with single dashes the same as arguments with two dashes
62 // Ex: -fullscreen == --fullscreen
63 parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
64 parser.process(*application);
66 if (getenv("QT_LOAD_TESTABILITY")) {
67 QLibrary testLib(QStringLiteral("qttestability"));
68 if (testLib.load()) {
69 typedef void (*TasInitialize)(void);
70 TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
71 if (initFunction) {
72 initFunction();
73 } else {
74 qCritical("Library qttestability resolve failed!");
75 }
76 } else {
77 qCritical("Library qttestability load failed!");
78 }
79 }
81 bindtextdomain("unity8", translationDirectory().toUtf8().data());
82 textdomain("unity8");
84 QQuickView* view = new QQuickView();
85 view->setResizeMode(QQuickView::SizeRootObjectToView);
87 if (parser.isSet(windowGeometryOption) &&
88 parser.value(windowGeometryOption).split('x').size() == 2)
89 {
90 QStringList geom = parser.value(windowGeometryOption).split('x');
91 QSize windowSize(geom.at(0).toInt(), geom.at(1).toInt());
92 if (windowSize.isValid()) {
93 view->setWidth(windowSize.width());
94 view->setHeight(windowSize.height());
95 }
96 }
98 view->setTitle(QStringLiteral("Scopes"));
100 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
101 // You will need this if you want to interact with touch-only components using a mouse
102 // Needed only when manually testing on a desktop.
103 MouseTouchAdaptor *mouseTouchAdaptor = 0;
104 if (parser.isSet(mousetouchOption)) {
105 mouseTouchAdaptor = MouseTouchAdaptor::instance();
106 }
107 #endif
109 QUrl source(::qmlDirectory() + "/Dash/DashApplication.qml");
110 prependImportPaths(view->engine(), ::overrideImportPaths());
111 appendImportPaths(view->engine(), ::fallbackImportPaths());
113 CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
114 view->engine()->setNetworkAccessManagerFactory(managerFactory);
116 view->setSource(source);
117 view->show();
119 int result = application->exec();
121 delete view;
123 #ifdef UNITY8_ENABLE_TOUCH_EMULATION
124 delete mouseTouchAdaptor;
125 #endif
127 delete application;
129 return result;