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