aboutsummaryrefslogtreecommitdiff
path: root/src/main_qmladaptor.h
blob: d928acdd5650773faf73d074cacd56da52d5dc98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * This file is part of Remote Support Desktop
 * https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.desktopapp
 * Copyright 2020, 2021 Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de>
 * Copyright 2020, 2021 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#pragma once

#include <QObject>
#include <QQmlApplicationEngine>
#include <QQuickItem>
#include <QMessageBox>
#include <QApplication>
#include <QClipboard>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QTimer>

#include "RWAHost.h"
#include "DBusAPI.h"

class MainQMLAdaptor : public QObject
{
    Q_OBJECT
    // this makes url available as a QML property
    Q_PROPERTY(QList<QObject*> rwaHostModel READ getRWAHostModel NOTIFY rwaHostModelChanged)
    // this makes url available as a QML property
    Q_PROPERTY(QString url READ getURL WRITE setURL NOTIFY urlChanged)
    // this makes pin available as a QML property
    Q_PROPERTY(QString pin READ getPin WRITE setPin NOTIFY pinChanged)
    // this makes session_id available as a QML property
    Q_PROPERTY(QString session_id READ getSessionID WRITE setSessionID NOTIFY sessionIDChanged)
    // this makes showMessageDialog available as a QML property
    Q_PROPERTY(bool showMessageDialog READ getShowMessageDialog NOTIFY showMessageDialogChanged)
    // this makes showMessageDialogTitle available as a QML property
    Q_PROPERTY(QString _messageDialogTitle READ getMessageDialogTitle NOTIFY messageDialogTitleChanged)
    // this makes showMessageDialogText available as a QML property
    Q_PROPERTY(QString _messageDialogText READ getMessageDialogText NOTIFY messageDialogTextChanged)
    // this makes showMessageDialogIcon available as a QML property
    Q_PROPERTY(QMessageBox::Icon _messageDialogIcon READ getMessageDialogIcon NOTIFY messageDialogIconChanged)

public:
    explicit MainQMLAdaptor(QObject *parent, QQmlApplicationEngine *engine = nullptr,
                            DBusAPI *dbus_api = nullptr);

    void setRWAHostModel(QList<QObject*> *rwa_hosts);

    bool setConnectButtonEnabled(bool enabled);
    bool setConnectButtonChecked(bool checked);

    void main_content_push(QString);
    void main_content_pop(QString);
    void main_content_replace(QString);

    bool setStatusIndicator(bool active, QColor color = QColor(255,255,255));
    bool setStatus(QString status);

    bool openMessageDialog(QString title, QString text, QMessageBox::Icon);
    QString getMessageDialogTitle();
    QString getMessageDialogText();
    QMessageBox::Icon getMessageDialogIcon();
    bool getShowMessageDialog();

signals:
    void showMessageDialogChanged(bool show);
    void messageDialogTextChanged(QString text);
    void messageDialogTitleChanged(QString title);
    void messageDialogIconChanged(int iconindex);

    void minimizeWindow();
    void showWindow();

    void onConnectButtonClick(bool checked);

    void pinChanged(QString pin);
    void urlChanged(QString URL);
    void sessionIDChanged(QString session_id);

    void rwaHostModelChanged(QList<QObject*>);

    void onCloseSignal();

    void showToastSignal(QString text, QString durationMs);

protected:
    QString _url;
    QString _pin;
    QString _session_id;
    DBusAPI *_dbus_api;
    QList<QObject*> *_rwaHostModel;

private:
    QQmlApplicationEngine* _engine;

    bool _showMessageDialog;
    QString _messageDialogTitle;
    QString _messageDialogText;
    QMessageBox::Icon _messageDialogIcon;

public slots:
    void handleCopyToClipboardButtonClick(QString copy_data);
    void handleConnectButtonClick(bool checked);

    void get_web_app_hosts_response(QJsonDocument *doc);

    void setPin(QString pin);
    void setURL(QString URL);
    void setSessionID(QString session_id);
    void addRWAHost(RWAHost *rwa_host);
    QString getURL();
    QString getPin();
    QString getSessionID();

    // No pointer because QML doesn't
    // like this type much with pointer
    QList<QObject*> getRWAHostModel();

    void onRwaHostSelected(QString host_uuid);
    void onCloseHandler();

    void showToast(QString text, uint durationMs = 3000);
};