diff --git a/src/blackgui/components/autopublishcomponent.cpp b/src/blackgui/components/autopublishcomponent.cpp new file mode 100644 index 000000000..3dba683b7 --- /dev/null +++ b/src/blackgui/components/autopublishcomponent.cpp @@ -0,0 +1,88 @@ +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +#include "autopublishcomponent.h" +#include "ui_autopublishcomponent.h" +#include "blackgui/guiapplication.h" +#include "blackcore/webdataservices.h" +#include "blackmisc/simulation/aircraftmodellist.h" + +#include + +using namespace BlackMisc; +using namespace BlackMisc::Simulation; + +namespace BlackGui +{ + namespace Components + { + CAutoPublishComponent::CAutoPublishComponent(QWidget *parent) : + COverlayMessagesFrame(parent), + ui(new Ui::CAutoPublishComponent) + { + ui->setupUi(this); + connect(ui->pb_Analyze, &QPushButton::released, this, &CAutoPublishComponent::analyzeAgainstDBData, Qt::QueuedConnection); + connect(ui->pb_SendToDB, &QPushButton::released, this, &CAutoPublishComponent::sendToDb, Qt::QueuedConnection); + connect(ui->pb_DeleteFiles, &QPushButton::released, this, &CAutoPublishComponent::deleteAllFiles, Qt::QueuedConnection); + } + + CAutoPublishComponent::~CAutoPublishComponent() + { } + + int CAutoPublishComponent::readFiles() + { + const int r = m_data.readFromJsonFiles(); + this->displayData(); + return r; + } + + void CAutoPublishComponent::analyzeAgainstDBData() + { + if (!sGui || sGui->isShuttingDown()) { return; } + const CAircraftModelList dbModels = sGui->getWebDataServices()->getModels(); + const CStatusMessageList msgs = m_data.analyzeAgainstDBData(dbModels); + this->showOverlayMessages(msgs); + } + + void CAutoPublishComponent::sendToDb() + { + if (!sGui || sGui->isShuttingDown()) { return; } + if (m_data.isEmpty()) + { + this->showOverlayHTMLMessage("No data!", 5000); + return; + } + + const CAircraftModelList dbModels = sGui->getWebDataServices()->getModels(); + CStatusMessageList msgs = m_data.analyzeAgainstDBData(dbModels); + if (!msgs.hasErrorMessages()) + { + const CStatusMessageList publishMsgs = sGui->getWebDataServices()->asyncAutoPublish(m_data); + msgs.push_back(publishMsgs); + } + this->showOverlayMessages(msgs); + } + + void CAutoPublishComponent::displayData() + { + ui->pte_Json->setPlainText(m_data.toDatabaseJson()); + ui->le_Summary->setText(m_data.getSummary()); + } + + void CAutoPublishComponent::deleteAllFiles() + { + const int c = CAutoPublishData::deleteAutoPublishFiles(); + if (c > 0) + { + this->showOverlayHTMLMessage(QStringLiteral("Deleted %1 file(s)").arg(c)); + } + this->readFiles() ; + } + + } // ns +} // ns diff --git a/src/blackgui/components/autopublishcomponent.h b/src/blackgui/components/autopublishcomponent.h new file mode 100644 index 000000000..7f34b6dcb --- /dev/null +++ b/src/blackgui/components/autopublishcomponent.h @@ -0,0 +1,58 @@ +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_COMPONENTS_AUTOPUBLISHCOMPONENT_H +#define BLACKGUI_COMPONENTS_AUTOPUBLISHCOMPONENT_H + +#include "blackgui/overlaymessagesframe.h" +#include "blackmisc/simulation/autopublishdata.h" + +#include +#include + +namespace Ui { class CAutoPublishComponent; } +namespace BlackGui +{ + namespace Components + { + //! Data automatically collected and be be sent to backend + class CAutoPublishComponent : public COverlayMessagesFrame + { + Q_OBJECT + + public: + //! Ctor + explicit CAutoPublishComponent(QWidget *parent = nullptr); + + //! Destructor + virtual ~CAutoPublishComponent(); + + //! Read the files + int readFiles(); + + private: + QScopedPointer ui; + BlackMisc::Simulation::CAutoPublishData m_data; + + //! Analyze against DB data + void analyzeAgainstDBData(); + + //! Send to DB + void sendToDb(); + + //! Display data in JSON text field + void displayData(); + + //! Delete all files + void deleteAllFiles(); + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackgui/components/autopublishcomponent.ui b/src/blackgui/components/autopublishcomponent.ui new file mode 100644 index 000000000..c6a6442b2 --- /dev/null +++ b/src/blackgui/components/autopublishcomponent.ui @@ -0,0 +1,110 @@ + + + CAutoPublishComponent + + + + 0 + 0 + 323 + 389 + + + + Auto publish information + + + + + + Summary + + + + + + swift automatically collects data about your used models. These collected data can help to improve the matching and interpolation experience. There are no hidden data, you can see the data as it is sent below. + + + true + + + + + + + true + + + + + + + + + + DB data (JSON) + + + + + + true + + + + + + + + + + + + + send to DB + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + clean + + + + + + + analyze + + + + + + + + + + le_Summary + pte_Json + pb_SendToDB + pb_DeleteFiles + pb_Analyze + + + + diff --git a/src/blackgui/components/autopublishdialog.cpp b/src/blackgui/components/autopublishdialog.cpp new file mode 100644 index 000000000..e8185e277 --- /dev/null +++ b/src/blackgui/components/autopublishdialog.cpp @@ -0,0 +1,40 @@ +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +#include "autopublishdialog.h" +#include "ui_autopublishdialog.h" + +namespace BlackGui +{ + namespace Components + { + CAutoPublishDialog::CAutoPublishDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CAutoPublishDialog) + { + ui->setupUi(this); + this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); + } + + CAutoPublishDialog::~CAutoPublishDialog() + { } + + int CAutoPublishDialog::readFiles() + { + return ui->comp_AutoPublish->readFiles(); + } + + int CAutoPublishDialog::readAndShow() + { + const int r = ui->comp_AutoPublish->readFiles(); + this->show(); + return r; + } + + } // ns +} // ns diff --git a/src/blackgui/components/autopublishdialog.h b/src/blackgui/components/autopublishdialog.h new file mode 100644 index 000000000..de3a87678 --- /dev/null +++ b/src/blackgui/components/autopublishdialog.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2019 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated, + * or distributed except according to the terms contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_COMPONENTS_AUTOPUBLISHDIALOG_H +#define BLACKGUI_COMPONENTS_AUTOPUBLISHDIALOG_H + +#include "blackgui/blackguiexport.h" + +#include +#include + +namespace Ui { class CAutoPublishDialog; } +namespace BlackGui +{ + namespace Components + { + //! CAutoPublishComponent as dialog + class BLACKGUI_EXPORT CAutoPublishDialog : public QDialog + { + Q_OBJECT + + public: + //! Ctor + explicit CAutoPublishDialog(QWidget *parent = nullptr); + + //! Destructor + virtual ~CAutoPublishDialog(); + + //! \copydoc CAutoPublishComponent::readFiles + int readFiles(); + + //! Read files and show dialog + int readAndShow(); + + private: + QScopedPointer ui; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/autopublishdialog.ui b/src/blackgui/components/autopublishdialog.ui new file mode 100644 index 000000000..791d6c0fe --- /dev/null +++ b/src/blackgui/components/autopublishdialog.ui @@ -0,0 +1,75 @@ + + + CAutoPublishDialog + + + + 0 + 0 + 640 + 480 + + + + Auto publish data + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + BlackGui::Components::CAutoPublishComponent + QFrame +
blackgui/components/autopublishcomponent.h
+ 1 +
+
+ + + + bb_AutoPublishDialog + accepted() + CAutoPublishDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + bb_AutoPublishDialog + rejected() + CAutoPublishDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +