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