aboutsummaryrefslogtreecommitdiff
path: root/src/main_qmladaptor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main_qmladaptor.cpp')
-rw-r--r--src/main_qmladaptor.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp
index b34c9d4..d75b15c 100644
--- a/src/main_qmladaptor.cpp
+++ b/src/main_qmladaptor.cpp
@@ -30,6 +30,100 @@ MainQMLAdaptor::MainQMLAdaptor(QObject *parent, QQmlApplicationEngine* engine) :
Q_ASSERT(engine != nullptr);
_engine = engine;
+ _rwaHostModel = new QList<QObject*>;
+}
+
+void MainQMLAdaptor::onRwaHostSelected(QString host_uuid) {
+ Q_ASSERT(host_uuid != "");
+
+ RWAHost *_host = nullptr;
+ for (int i = 0; i < getRWAHostModel().size(); i++) {
+ QObject *obj = getRWAHostModel().value(i);
+ RWAHost *host = qobject_cast<RWAHost *>(obj);
+ Q_ASSERT(host != nullptr);
+
+ if (host->uuid() == host_uuid) {
+ _host = host;
+ }
+ }
+ Q_ASSERT(_host != nullptr);
+
+ qDebug() << "RWAHost was selected!" << _host->uuid() << "aka" << _host->alias();
+}
+
+void MainQMLAdaptor::setRWAHostModel(QList<QObject*> rwa_hosts) {
+
+ _rwaHostModel = &rwa_hosts;
+ emit rwaHostModelChanged(rwa_hosts);
+}
+
+void MainQMLAdaptor::addRWAHost(RWAHost *rwa_host) {
+ _rwaHostModel->append(rwa_host);
+ emit rwaHostModelChanged(*_rwaHostModel);
+}
+
+QList<QObject*> MainQMLAdaptor::getRWAHostModel() {
+ return *_rwaHostModel;
+}
+
+void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) {
+ Q_ASSERT(doc != nullptr);
+
+ // Get the QJsonObject
+ QJsonObject jObject = doc->object();
+ QVariantMap mainMap = jObject.toVariantMap();
+
+ // Status of request
+ QString request_status = mainMap["status"].toString();
+ if (request_status == "success") {
+ // Building host_objects
+ QJsonArray host_objects = jObject.value("hosts").toArray();
+
+ foreach (const QJsonValue &host_object, host_objects) {
+ QString host_uuid = host_object["uuid"].toString();
+ QString host_alias = host_object["alias"].toString();
+ QString host_url = host_object["url"].toString();
+
+ if (host_url == "" || host_uuid == "") {
+ // This two values are required and can't be omitted.
+ QString reason = tr("A host object in the response of D-Bus "
+ "service lacks a necessary value. (host_url or host_uuid)");
+ qCritical().noquote() << tr("An error occured while adding a new host:")
+ << reason;
+ //emit step1Failed(reason);
+
+ return;
+ }
+
+ if (host_alias == "") {
+ qDebug().noquote() << QString("An alias for the host wasn't delivered "
+ "so just use '%0' as alias.").arg(host_url);
+ host_alias = host_url;
+ }
+
+ // Now built RWAHost object.
+ RWAHost *rwa_host = new RWAHost(host_uuid, host_alias, host_url);
+ addRWAHost(rwa_host);
+
+ qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")).arg(rwa_host->alias());
+ }
+ } else {
+ QString reason = tr("An error occured while adding a new host:");
+ qCritical().noquote() << reason;
+
+ QString type = mainMap["type"].toString();
+ if (type != "") {
+ reason = QString(tr("The error is not clear. The session service "
+ "responded with status type '%0'")).arg(type);
+ qCritical().noquote() << reason;
+ } else {
+ reason = QString(tr("The error is not clear. The session service "
+ "responded with no status type!"));
+ qCritical().noquote() << reason;
+ }
+
+ return;
+ }
}
bool MainQMLAdaptor::setConnectButtonEnabled(bool enabled) {