Unity 8
 All Classes Functions
main.cpp
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  */
19 
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 
29 #include <paths.h>
30 #include "../MouseTouchAdaptor.h"
31 #include "../CachingNetworkManagerFactory.h"
32 
33 int main(int argc, const char *argv[])
34 {
35  QGuiApplication *application = new QGuiApplication(argc, (char**)argv);
36 
37  QCommandLineParser parser;
38  parser.setApplicationDescription("Description: Unity 8 Shell Dash");
39  parser.addHelpOption();
40 
41  QCommandLineOption mousetouchOption("mousetouch",
42  "Allow the mouse to provide touch input");
43  parser.addOption(mousetouchOption);
44 
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);
49 
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);
54 
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  }
69 
70  bindtextdomain("unity8", translationDirectory().toUtf8().data());
71  textdomain("unity8");
72 
73  QQuickView* view = new QQuickView();
74  view->setResizeMode(QQuickView::SizeRootObjectToView);
75  view->setTitle("Unity Dash");
76 
77  // You will need this if you want to interact with touch-only components using a mouse
78  // Needed only when manually testing on a desktop.
79  MouseTouchAdaptor *mouseTouchAdaptor = 0;
80  if (parser.isSet(mousetouchOption)) {
81  mouseTouchAdaptor = new MouseTouchAdaptor;
82  application->installNativeEventFilter(mouseTouchAdaptor);
83  }
84 
85  QUrl source(::qmlDirectory()+"Dash/DashApplication.qml");
86  prependImportPaths(view->engine(), ::overrideImportPaths());
87  appendImportPaths(view->engine(), ::fallbackImportPaths());
88 
89  CachingNetworkManagerFactory *managerFactory = new CachingNetworkManagerFactory();
90  view->engine()->setNetworkAccessManagerFactory(managerFactory);
91 
92  view->setSource(source);
93  view->show();
94 
95  int result = application->exec();
96 
97  delete view;
98  delete application;
99 
100  return result;
101 }