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