applicationcontroller.h 2.98 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
    Copyright (C) 2018 Volker Krause <vkrause@kde.org>

    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU General Public License
15
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 17 18 19 20 21 22
*/

#ifndef APPLICATIONCONTROLLER_H
#define APPLICATIONCONTROLLER_H

#include <QObject>

23 24 25 26 27 28 29
#ifdef Q_OS_ANDROID
#include <QAndroidActivityResultReceiver>
#endif

class PkPassManager;
class ReservationManager;

Volker Krause's avatar
Volker Krause committed
30 31
class QGeoPositionInfo;
class QGeoPositionInfoSource;
32
class QNetworkAccessManager;
Volker Krause's avatar
Volker Krause committed
33

34 35 36
class ApplicationController : public QObject
{
    Q_OBJECT
37
    Q_PROPERTY(bool hasClipboardContent READ hasClipboardContent NOTIFY clipboardContentChanged)
38 39 40 41
public:
    explicit ApplicationController(QObject *parent = nullptr);
    ~ApplicationController();

42 43 44
    void setReservationManager(ReservationManager *resMgr);
    void setPkPassManager(PkPassManager *pkPassMgr);

Volker Krause's avatar
Volker Krause committed
45
    // navigation
46
    Q_INVOKABLE void showOnMap(const QVariant &place);
47
    Q_INVOKABLE bool canNavigateTo(const QVariant &place);
Volker Krause's avatar
Volker Krause committed
48
    Q_INVOKABLE void navigateTo(const QVariant &place);
49
    Q_INVOKABLE void navigateTo(const QVariant &from, const QVariant &to);
Volker Krause's avatar
Volker Krause committed
50

Volker Krause's avatar
Volker Krause committed
51 52
    // data import
    Q_INVOKABLE void showImportFileDialog();
53
    Q_INVOKABLE void importFromClipboard();
54
    Q_INVOKABLE void importFromUrl(const QUrl &url);
55 56 57
#ifdef Q_OS_ANDROID
    void importFromIntent(const QAndroidJniObject &intent);
#endif
58
    void importData(const QByteArray &data);
59

60 61
    Q_INVOKABLE void checkCalendar();

62 63
    static ApplicationController* instance();

64 65
    bool hasClipboardContent() const;

66
Q_SIGNALS:
67 68
    void clipboardContentChanged();

Volker Krause's avatar
Volker Krause committed
69
private:
70
    void importLocalFile(const QUrl &url);
71

72 73
    static ApplicationController *s_instance;

74 75
    ReservationManager *m_resMgr = nullptr;
    PkPassManager *m_pkPassMgr = nullptr;
76
    QNetworkAccessManager *m_nam = nullptr;
77

78
#ifndef Q_OS_ANDROID
Volker Krause's avatar
Volker Krause committed
79 80 81 82
    void navigateTo(const QGeoPositionInfo &from, const QVariant &to);

    QGeoPositionInfoSource *m_positionSource = nullptr;
    QMetaObject::Connection m_pendingNavigation;
83 84 85 86 87 88 89 90 91 92
#else
    class ActivityResultReceiver : public QAndroidActivityResultReceiver {
    public:
        explicit inline ActivityResultReceiver(ApplicationController *controller)
            : m_controller(controller) {}
        void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &intent) override;
    private:
        ApplicationController *m_controller;
    };
    ActivityResultReceiver m_activityResultReceiver;
93
#endif
94 95 96
};

#endif // APPLICATIONCONTROLLER_H