aboutsummaryrefslogtreecommitdiff
path: root/src/main_qmladaptor.cpp
blob: 620bb695d15669b19fc17598d02e5b1f573b651c (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
#pragma once

#include "main_qmladaptor.h"

MainQMLAdaptor::MainQMLAdaptor(QObject *parent, QQmlApplicationEngine* engine) : QObject(parent)
{
    _engine = engine;
}

//void MainQMLAdaptor::setSession(Session session) {
//    _session = session;
//}

bool MainQMLAdaptor::setConnectButtonEnabled(bool enabled) {
    // Find item via 'objectName'
    QQuickItem *item = _engine->rootObjects().at(0)->findChild<QQuickItem*>("start_support_button");
    if (item) {
        item->setProperty("enabled", enabled);
        if (item->property("checked").toBool()) {
            item->setProperty("text", tr("Stop remote support session"));
        } else {
            item->setProperty("text", tr("Start remote support session"));
        }
    } else {
        qWarning() << "Unable to find 'start_support_button' Item!";
        return false;
    }

    return true;
}

bool MainQMLAdaptor::setConnectButtonChecked(bool checked) {
    // Find item via 'objectName'
    QQuickItem *item = _engine->rootObjects().at(0)->findChild<QQuickItem*>("start_support_button");
    if (item) {
        item->setProperty("checked", checked);
    } else {
        qWarning() << "Unable to find 'start_support_button' Item!";
        return false;
    }

    return true;
}

bool MainQMLAdaptor::setStatus(QString status) {
    // Find item via 'objectName'
    QQuickItem *item = _engine->rootObjects().at(0)->findChild<QQuickItem*>("dbus_api_status_text");
    if (item) {
        item->setProperty("text", status);
    } else {
        qWarning() << "Unable to find 'dbus_api_status_text' Item!";
        return false;
    }

    return true;
}

bool MainQMLAdaptor::openMessageDialog(QString title, QString text, QMessageBox::Icon icon) {
    _messageDialogText  = text;
    _messageDialogTitle = title;
    _messageDialogIcon  = icon;
    _showMessageDialog = true;
    emit messageDialogIconChanged(_messageDialogIcon);
    emit messageDialogTitleChanged(_messageDialogTitle);
    emit messageDialogTextChanged(_messageDialogText);

    emit showMessageDialogChanged(_showMessageDialog);

    qDebug() << "Opening MessageDialog!";
    return true;
}

QString MainQMLAdaptor::getMessageDialogTitle() {
    return _messageDialogTitle;
}

QString MainQMLAdaptor::getMessageDialogText() {
    return _messageDialogText;
}

QMessageBox::Icon MainQMLAdaptor::getMessageDialogIcon() {
    return _messageDialogIcon;
}

bool MainQMLAdaptor::getShowMessageDialog() {
    return _showMessageDialog;
}

bool MainQMLAdaptor::setStatusIndicator(bool active, QColor color) {
    // Find item via 'objectName'
    QQuickItem *item = _engine->rootObjects().at(0)->findChild<QQuickItem*>("dbus_api_status_indicator");
    if (item) {
        item->setProperty("active", active);
        item->setProperty("color", color);
    } else {
        qWarning() << "Unable to find 'dbus_api_status_indicator' Item!";
        return false;
    }

    return true;
}

void MainQMLAdaptor::handleCopyToClipboardButtonClick(QString copy_data) {
    QClipboard *clipboard = QApplication::clipboard();
    QString originalText = clipboard->text();
    clipboard->setText(copy_data);
    qDebug() << "Copied into clipboard:" << copy_data;
}

void MainQMLAdaptor::handleConnectButtonClick(bool checked) {
    emit onConnectButtonClick(checked);
}

void MainQMLAdaptor::setPin(QString pin) {
    _pin = pin;
    emit pinChanged(pin);
}
void MainQMLAdaptor::setURL(QString URL) {
    _url = URL;
    emit urlChanged(URL);
}
QString MainQMLAdaptor::getURL() {
    return _url;
}
QString MainQMLAdaptor::getPin() {
    return _pin;
}

void MainQMLAdaptor::onCloseHandler() {
    // Do cleanup things here...
    emit onCloseSignal();
}

void MainQMLAdaptor::showToast(QString text, uint durationMs) {
    emit showToastSignal(text, QString::number(durationMs));
}

//void MainQMLAdaptor::onCloseHandler() {
//    qDebug() << "Inside MainQMLAdaptor::onCloseHandler()";

//    // Sending onClose signal to main and there to Session::onCloseHandler()
//    emit MainQMLAdaptor::onCloseSignal();
//}