~verzegnassi-stefano/+junk/docviewer-tmp-001

« back to all changes in this revision

Viewing changes to src/app/main.cpp

  • Committer: Tarmac
  • Author(s): Stefano Verzegnassi
  • Date: 2015-01-21 18:37:55 UTC
  • mfrom: (48.2.1 ubuntu-docviewer-app)
  • Revision ID: tarmac-20150121183755-carz93q9aruvb2x8
Added Empty State in Welcome screen. Fixes: https://bugs.launchpad.net/bugs/1395065.

Approved by Andrew Hayzen, Nekhelesh Ramananthan, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright: 2013 - 2014 Canonical, Ltd
 
2
 * Copyright: 2013 - 2015 Canonical, Ltd
3
3
 *
4
4
 * This file is part of docviewer
5
5
 *
19
19
 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
20
20
 *          Riccardo Padovani <rpadovani@ubuntu.com>
21
21
 *          David Planella <david.planella@ubuntu.com>
 
22
 *          Stefano Verzegnassi <stefano92.100@gmail.com>
22
23
 */
23
24
 
24
25
#include <QtGui/QGuiApplication>
44
45
 
45
46
    QStringList args = a.arguments();
46
47
    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.";
 
48
        qDebug() << "usage: " + args.at(0) + " [-h|--help] <path>";
50
49
        qDebug() << "    -h|--help     Print this help.";
51
 
        qDebug() << "    -I <path>     Give a path for an additional QML import directory. May be used multiple times.";
 
50
        qDebug() << "    <path>        Path of the document to load.";
52
51
        return 0;
53
52
    }
54
53
 
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());
61
 
            }
62
 
            importPathList.append(addedPath);
 
54
    // Check if the path of the document has been specified.
 
55
    QString docPath;
 
56
    for (int i = 1; i < args.count(); i++) {
 
57
        if (args.at(i) != "-h" && args.at(i) != "--h") {
 
58
            docPath = args.at(i);
63
59
        }
64
60
    }
 
61
    view.engine()->rootContext()->setContextProperty("documentPath", docPath);
65
62
 
66
63
    if (args.contains(QLatin1String("-testability")) || getenv("QT_LOAD_TESTABILITY")) {
67
64
        QLibrary testLib(QLatin1String("qttestability"));
78
75
        }
79
76
    }
80
77
 
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));
92
 
    }
93
 
 
94
78
    view.engine()->setImportPathList(importPathList);
95
79
 
96
80
    QString qmlfile;