diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main_qmladaptor.cpp | 83 |
1 files changed, 76 insertions, 7 deletions
diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp index a89d085..6d3a60c 100644 --- a/src/main_qmladaptor.cpp +++ b/src/main_qmladaptor.cpp @@ -121,6 +121,7 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { // Building host_objects QJsonArray host_objects = jObject.value("hosts").toArray(); + QList<RWAHost*> *all_rwa_hosts = new QList<RWAHost*>; foreach (const QJsonValue &host_object, host_objects) { QString host_uuid = host_object["uuid"].toString(); QString host_alias = host_object["alias"].toString(); @@ -142,12 +143,46 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { host_alias = host_url; } + // Now built RWAHost object. RWAHost *rwa_host = new RWAHost(host_uuid, host_alias, host_url); - addRWAHost(rwa_host); + all_rwa_hosts->append(rwa_host); + + bool found = false; + for (int i = 0; i < this->_rwaHostModel->size(); i++) { + RWAHost* old_host = qobject_cast<RWAHost*>(_rwaHostModel->value(i)); + Q_ASSERT(old_host != nullptr); + + if (rwa_host->uuid() == old_host->uuid()) { + found = true; + break; + } + } + atLeastOneHostAvailable = true; - qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")).arg(rwa_host->alias()); + if (!found) { + qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")).arg(rwa_host->alias()); + addRWAHost(rwa_host); + } + } + + for (int i = 0; i < this->_rwaHostModel->size(); i++) { + RWAHost* old_host = qobject_cast<RWAHost*>(_rwaHostModel->value(i)); + Q_ASSERT(old_host != nullptr); + + bool found = false; + for (RWAHost *host : *all_rwa_hosts) { + if (host->uuid() == old_host->uuid()) { + found = true; + break; + } + } + + if (!found) { + removeRWAHost(old_host); + qInfo().noquote() << QString(tr("Removed RWAHost '%0'")).arg(old_host->alias()); + } } } else { QString reason = tr("An error occured while adding a new host:"); @@ -176,16 +211,40 @@ void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) { void MainQMLAdaptor::main_content_push(QString scene) { // Find item via 'objectName' + QObject *window = _engine->rootObjects().takeFirst(); + Q_ASSERT(window != nullptr); + QObject *main_content = _engine->rootObjects().takeFirst()->findChild<QObject*>("main_content"); Q_ASSERT(main_content != nullptr); - QMetaObject::invokeMethod(main_content, "push", Q_ARG(QString, scene)); + + QVariant to_cast = main_content->property("currentItem"); + QObject *obj = qvariant_cast<QObject *>(to_cast); + if (obj) { + if (!(scene.contains(obj->objectName()))) { + QVariant arg = QVariant::fromValue(scene); + if(!QMetaObject::invokeMethod(window, "main_content_push", Q_ARG(QVariant, arg))) + qDebug() << "Failed to invoke push"; + } + } } void MainQMLAdaptor::main_content_pop(QString scene) { // Find item via 'objectName' + QObject *window = _engine->rootObjects().takeFirst(); + Q_ASSERT(window != nullptr); + QObject *main_content = _engine->rootObjects().takeFirst()->findChild<QObject*>("main_content"); Q_ASSERT(main_content != nullptr); - QMetaObject::invokeMethod(main_content, "pop", Q_ARG(QString, scene)); + + QVariant to_cast = main_content->property("currentItem"); + QObject *obj = qvariant_cast<QObject *>(to_cast); + if (obj) { + if (!(scene.contains(obj->objectName()))) { + QVariant arg = QVariant::fromValue(scene); + if(!QMetaObject::invokeMethod(window, "main_content_pop", Q_ARG(QVariant, arg))) + qDebug() << "Failed to invoke pop"; + } + } } void MainQMLAdaptor::main_content_replace(QString scene) { @@ -193,9 +252,19 @@ void MainQMLAdaptor::main_content_replace(QString scene) { QObject *window = _engine->rootObjects().takeFirst(); Q_ASSERT(window != nullptr); - QVariant arg = QVariant::fromValue(scene); - if(!QMetaObject::invokeMethod(window, "main_content_replace", Q_ARG(QVariant, arg))) - qDebug() << "Failed to invoke push"; + QObject *main_content = _engine->rootObjects().takeFirst()->findChild<QObject*>("main_content"); + Q_ASSERT(main_content != nullptr); + + QVariant to_cast = main_content->property("currentItem"); + QObject *obj = qvariant_cast<QObject *>(to_cast); + if (obj) { + QString scene_add_server_wizard = "Scene_step_1"; + if (!(scene.contains(obj->objectName()) || scene_add_server_wizard.contains(obj->objectName()))) { + QVariant arg = QVariant::fromValue(scene); + if(!QMetaObject::invokeMethod(window, "main_content_replace", Q_ARG(QVariant, arg))) + qDebug() << "Failed to invoke replace"; + } + } } bool MainQMLAdaptor::setConnectButtonEnabled(bool enabled) { |