2
* Copyright: 2013 - 2014 Canonical, Ltd
4
* This file is part of docviewer
6
* docviewer is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* reminders 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.
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/>.
19
* Authors: Michael Zanetti <michael.zanetti@canonical.com>
20
* Riccardo Padovani <rpadovani@ubuntu.com>
21
* David Planella <david.planella@ubuntu.com>
24
#include <QtGui/QGuiApplication>
25
#include <QtQuick/QQuickView>
26
#include <QtQml/QtQml>
32
int main(int argc, char *argv[])
34
QGuiApplication a(argc, argv);
36
view.setResizeMode(QQuickView::SizeRootObjectToView);
38
// Set up import paths
39
QStringList importPathList = view.engine()->importPathList();
40
// Prepend the location of the plugin in the build dir,
41
// so that Qt Creator finds it there, thus overriding the one installed
42
// in the sistem if there is one
43
importPathList.prepend(QCoreApplication::applicationDirPath() + "/../plugin/");
45
QStringList args = a.arguments();
46
if (args.contains("-h") || args.contains("--help")) {
47
qDebug() << "usage: " + args.at(0) + " [-p|--phone] [-t|--tablet] [-h|--help] [-I <path>]";
48
qDebug() << " -p|--phone If running on Desktop, start in a phone sized window.";
49
qDebug() << " -t|--tablet If running on Desktop, start in a tablet sized window.";
50
qDebug() << " -h|--help Print this help.";
51
qDebug() << " -I <path> Give a path for an additional QML import directory. May be used multiple times.";
55
for (int i = 0; i < args.count(); i++) {
56
if (args.at(i) == "-I" && args.count() > i + 1) {
57
QString addedPath = args.at(i+1);
58
if (addedPath.startsWith('.')) {
59
addedPath = addedPath.right(addedPath.length() - 1);
60
addedPath.prepend(QDir::currentPath());
62
importPathList.append(addedPath);
66
if (args.contains(QLatin1String("-testability")) || getenv("QT_LOAD_TESTABILITY")) {
67
QLibrary testLib(QLatin1String("qttestability"));
69
typedef void (*TasInitialize)(void);
70
TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
74
qCritical("Library qttestability resolve failed!");
77
qCritical("Library qttestability load failed!");
81
view.engine()->rootContext()->setContextProperty("tablet", QVariant(false));
82
view.engine()->rootContext()->setContextProperty("phone", QVariant(false));
83
if (args.contains("-t") || args.contains("--tablet")) {
84
qDebug() << "running in tablet mode";
85
view.engine()->rootContext()->setContextProperty("tablet", QVariant(true));
86
} else if (args.contains("-p") || args.contains("--phone")){
87
qDebug() << "running in phone mode";
88
view.engine()->rootContext()->setContextProperty("phone", QVariant(true));
89
} else if (qgetenv("QT_QPA_PLATFORM") != "ubuntumirclient") {
90
// Default to tablet size on X11
91
view.engine()->rootContext()->setContextProperty("tablet", QVariant(true));
94
view.engine()->setImportPathList(importPathList);
97
const QString filePath = QLatin1String("qml/ubuntu-docviewer-app.qml");
98
QStringList paths = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
99
paths.prepend(QDir::currentPath());
100
paths.prepend(QCoreApplication::applicationDirPath());
101
Q_FOREACH (const QString &path, paths) {
102
QString myPath = path + QLatin1Char('/') + filePath;
103
if (QFile::exists(myPath)) {
109
if (qmlfile.isEmpty()) {
110
qFatal("File: %s does not exist at any of the standard paths!", qPrintable(filePath));
113
// Make sure our cache dir exists. It'll be used all over in this app.
114
// We need to set the applicationName for that.
115
// It'll be overwritten again when qml loads but we need it already now.
116
// So if you want to change it, make sure to find all the places where it is set, not just here :D
117
QCoreApplication::setApplicationName("com.ubuntu.docviewer");
119
QDir cacheDir(QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first());
120
if (!cacheDir.exists()) {
121
qDebug() << "creating cacheDir:" << cacheDir.absolutePath();
122
cacheDir.mkpath(cacheDir.absolutePath());
125
qDebug() << "using main qml file from:" << qmlfile;
126
view.setSource(QUrl::fromLocalFile(qmlfile));