Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+409
@@ -0,0 +1,409 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* PresentationManagement - Script Overview Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*
|
||||
* Created by Mike Wille, SLSE, 2017-03-15
|
||||
*/
|
||||
|
||||
#include "pre_mobile_dialog.h"
|
||||
#include "ui_pre_mobile_dialog.h"
|
||||
|
||||
#include <Plugins/PresentationManagement/Gui/Common/pre_edit_dialog.h>
|
||||
#include <Plugins/PresentationManagement/Gui/Common/pre_mobile_model.h>
|
||||
#include <Plugins/AudioVideoManagement/Gui/AVMenuEdit/topic_replay.h>
|
||||
#include <LtsUtilsGuiDds/request_helper.h>
|
||||
#include <LtsSession/lts_session_data.h>
|
||||
#include <LtsScriptTimeline/track_entry_painters.h>
|
||||
|
||||
#include <Tools/DBAdministration/settings.h>
|
||||
#include <ngldb/dbconnection.h>
|
||||
|
||||
#include <AudioVideoManagement/ava_control.h>
|
||||
#include <AudioVideoManagement/ava_session.h>
|
||||
|
||||
#include <QHostInfo>
|
||||
#include <QDateTime>
|
||||
#include <QJsonDocument>
|
||||
#include <QProgressBar>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
namespace PresentationManagement
|
||||
{
|
||||
PreMobileDialog::PreMobileDialog(QWidget *parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
||||
, m_model(nullptr)
|
||||
, m_ui(new Ui::PreMobileDialog)
|
||||
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
||||
, m_copyExercise(getLogger("CopyExercise"), DBAdministration::CopyExercise::CopyForAAR, this)
|
||||
, m_widgetProgressBar(new QWidget)
|
||||
, m_progressBar(nullptr)
|
||||
, m_label(nullptr)
|
||||
, m_avScriptsCount(0)
|
||||
, m_avScriptsActualDone(0)
|
||||
, m_logger(getLogger("PreMobileDialog"))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "PreMobileDialog ctor";
|
||||
connect(&m_copyExercise, &DBAdministration::CopyExercise::copyDbFailed, this, &PreMobileDialog::onCopyDbFailed);
|
||||
connect(&m_copyExercise, &DBAdministration::CopyExercise::copyDbFinished, this, &PreMobileDialog::onCopyDbFinished);
|
||||
|
||||
m_ui->setupUi(this);
|
||||
QVBoxLayout *vlayout = new QVBoxLayout();
|
||||
m_widgetProgressBar->setLayout(vlayout);
|
||||
|
||||
m_progressBar = new QProgressBar();
|
||||
m_label = new QLabel();
|
||||
connect(m_label, &QLabel::destroyed, this, [this]()
|
||||
{ERROR_LOG(m_logger) << "Label destroyed";});
|
||||
m_widgetProgressBar->layout()->addWidget(m_label);
|
||||
m_widgetProgressBar->layout()->addWidget(m_progressBar);
|
||||
m_progressBar->setMinimum(0);
|
||||
m_progressBar->setMaximum(100);
|
||||
m_progressBar->show();
|
||||
m_progressBar->setValue(50);
|
||||
|
||||
}
|
||||
|
||||
PreMobileDialog::~PreMobileDialog()
|
||||
{
|
||||
// will be deleted with m_widgetProgressBar
|
||||
//delete m_progressBar;
|
||||
//delete m_label
|
||||
delete m_widgetProgressBar;
|
||||
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void PreMobileDialog::retranslate()
|
||||
{
|
||||
translate(m_ui, tr("Download AAR Scripts"));
|
||||
}
|
||||
|
||||
void PreMobileDialog::enaDisa()
|
||||
{
|
||||
bool enable = !m_model->getDownloadedScriptIds().isEmpty();
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Export, enable);
|
||||
}
|
||||
|
||||
void PreMobileDialog::slotDownload()
|
||||
{
|
||||
if (!m_avmDataIfc->hasAvsSession())
|
||||
{
|
||||
new LtsWidgets::LtsMessageDialogNew(this, tr("AVS session not available - do you still want to start the download?"));
|
||||
return;
|
||||
}
|
||||
|
||||
AudioVideoManagement::AvaSession *avaSession = m_avmDataIfc->avaSession();
|
||||
if (!avaSession->isEstablished())
|
||||
{
|
||||
new LtsWidgets::LtsMessageDialogNew(this, tr("AVS session not available - do you still want to start the download?"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Export, false);
|
||||
int exerciseId = m_session->exerciseId();
|
||||
|
||||
QString hostname = QHostInfo::localHostName().toUpper();
|
||||
|
||||
QString destDb = QStringLiteral("lts_db_") + QString::number(exerciseId);
|
||||
m_copyExercise.init(exerciseId,
|
||||
DBAdministration::Settings::serverDatabaseHost(),
|
||||
DBAdministration::Settings::serverDatabaseName(),
|
||||
hostname,
|
||||
destDb);
|
||||
|
||||
m_progressBar->setValue(0);
|
||||
m_label->setText(tr("Download database data"));
|
||||
setOverlay(m_widgetProgressBar);
|
||||
|
||||
|
||||
connect(&m_copyExercise, &DBAdministration::CopyExercise::nextProgress, this, &PreMobileDialog::onProgressBar);
|
||||
|
||||
if (!m_copyExercise.doCopy(exerciseId))
|
||||
ERROR_LOG(m_logger) << "Failed to copy database from " << DBAdministration::Settings::serverDatabaseHost() << " to " << hostname;
|
||||
|
||||
/*
|
||||
if (!m_progressDialog)
|
||||
m_progressDialog = new QProgressDialog(this);
|
||||
m_progressDialog->setLabelText(tr("Downloading data ..."));
|
||||
m_progressDialog->setMinimum(0);
|
||||
m_progressDialog->setMaximum(0);
|
||||
m_progressDialog->show();
|
||||
*/
|
||||
|
||||
const QVector<int> downloadScriptIds = m_model->getDownloadedScriptIds();
|
||||
m_copyExercise.setDownloadScriptIds(downloadScriptIds);
|
||||
|
||||
}
|
||||
|
||||
void PreMobileDialog::onProgressBar(int nextProgress)
|
||||
{
|
||||
m_progressBar->setValue(nextProgress);
|
||||
|
||||
// 1/4 done
|
||||
if (nextProgress == 25)
|
||||
m_label->setText(tr("Download of database finished"));
|
||||
|
||||
// 2/4 done
|
||||
if (nextProgress == 30)
|
||||
m_label->setText(tr("Dropping old database finished"));
|
||||
|
||||
// 3/4 done
|
||||
if (nextProgress == 35)
|
||||
m_label->setText(tr("Creating new database finished"));
|
||||
|
||||
if (nextProgress == 36)
|
||||
m_label->setText(tr("Importing data into local database"));
|
||||
|
||||
if (nextProgress >= 100)
|
||||
{
|
||||
m_copyExercise.stopPing();
|
||||
new LtsWidgets::LtsMessageDialogNew(this, tr("Download finished"));
|
||||
unsetOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
bool PreMobileDialog::init(const std::shared_ptr<Interface::Dtc> &dtc,
|
||||
const std::shared_ptr<Interface::Ftc> &ftc,
|
||||
const std::shared_ptr<OperatorManagement::Interface::Dtc> &opmDtc,
|
||||
const std::shared_ptr<AudioVideoManagement::DataInterface> &avmDataIfc,
|
||||
LtsSession::LtsSession *session)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "PreMobileDialog::init";
|
||||
m_session = session;
|
||||
m_avmDataIfc = avmDataIfc;
|
||||
m_dtc = dtc;
|
||||
m_ftc = ftc;
|
||||
|
||||
m_model = new PreMobileDialogModel(this);
|
||||
auto predicate = [](const PresentationManagement::Presentation & p)
|
||||
{
|
||||
return (!p.isDeleted());
|
||||
};
|
||||
m_model->initModel(dtc, opmDtc, predicate);
|
||||
|
||||
m_proxyModel = new PresentationManagementDialogProxyModel(this);
|
||||
m_proxyModel->setSourceModel(m_model);
|
||||
connect(m_model, &PreMobileDialogModel::checkboxClicked, this, &PreMobileDialog::enaDisa);
|
||||
m_ui->widget->setModel(m_proxyModel);
|
||||
|
||||
|
||||
#ifndef LTS_DEBUG
|
||||
m_ui->widget->hideColumn(PreMobileDialogModel::Id);
|
||||
#endif
|
||||
|
||||
m_ui->widget->setSortIndicator(PreMobileDialogModel::Name, Qt::AscendingOrder);
|
||||
|
||||
const QMap<qint32, PresentationManagement::Presentation> presentations = dtc->presentations();
|
||||
for (const auto &p : presentations)
|
||||
DEBUG_LOG(m_logger) << "Presentation: id = " << p.id() << ", name = " << p.name().c_str() << ", desc = " << p.description().c_str();
|
||||
|
||||
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged, this, &PreMobileDialog::enaDisa, Qt::UniqueConnection);
|
||||
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Load, this, &PreMobileDialog::slotDownload, Qt::UniqueConnection);
|
||||
|
||||
setOnlineHelpFilename(QStringLiteral("Script_Editor-Mobile_AAR_Scripts"));
|
||||
enaDisa();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PreMobileDialog::onCopyDbFailed()
|
||||
{
|
||||
new LtsWidgets::LtsMessageDialogNew(this, tr("Could not download data - Dump failed"));
|
||||
m_copyExercise.stopPing();
|
||||
enaDisa();
|
||||
unsetOverlay();
|
||||
}
|
||||
|
||||
void PreMobileDialog::onCopyDbFinished()
|
||||
{
|
||||
enaDisa();
|
||||
|
||||
if (!downloadAVScripts())
|
||||
{
|
||||
new LtsWidgets::LtsMessageDialogNew(this, tr("Could not download data - Audio/Video download failed. <br> But scripts without video can be used"));
|
||||
unsetOverlay();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PreMobileDialog::getAVScripts()
|
||||
{
|
||||
const auto scriptIds(m_model->getDownloadedScriptIds());
|
||||
for (int scriptId : scriptIds)
|
||||
{
|
||||
auto req = [this, scriptId]()
|
||||
{
|
||||
return m_ftc->getPresentationContentRequest(GetPresentationContentRequest(scriptId), this);
|
||||
};
|
||||
m_requestHelper->addRequest(req);
|
||||
}
|
||||
m_requestHelper->startRequests(); // blocks
|
||||
}
|
||||
|
||||
void PreMobileDialog::onGetPresentationContentReply(const GetPresentationContentReply &reply)
|
||||
{
|
||||
m_requestHelper->requestReply(reply);
|
||||
if (!reply.errorString().empty())
|
||||
return;
|
||||
handlePresentationContent(reply);
|
||||
}
|
||||
|
||||
void PreMobileDialog::handlePresentationContent(const GetPresentationContentReply &reply)
|
||||
{
|
||||
const auto &contentList = reply.content();
|
||||
|
||||
if (contentList.empty())
|
||||
{
|
||||
WARNING_LOG(m_logger) << "No content for Script Id = " << reply.id();
|
||||
return;
|
||||
}
|
||||
|
||||
std::string audioStr = LtsScriptTimeline::trackEntryTypeName(LtsScriptTimeline::TrackEntryType::Audio).toStdString();
|
||||
std::string videoStr = LtsScriptTimeline::trackEntryTypeName(LtsScriptTimeline::TrackEntryType::Video).toStdString();
|
||||
|
||||
for (const auto &p : contentList)
|
||||
{
|
||||
QJsonObject attributes = QJsonDocument::fromJson(QByteArray::fromStdString(p.attributes())).object();
|
||||
//NOTICE_LOG(m_logger) << "p.id: " << p.id() << "attributes" << p.attributes();
|
||||
|
||||
if (p.presentationTopicType() == audioStr ||
|
||||
p.presentationTopicType() == videoStr )
|
||||
{
|
||||
m_vecScripts.append(attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PreMobileDialog::downloadAVScripts()
|
||||
{
|
||||
INFO_LOG(m_logger) << "IN downloadAVScripts";
|
||||
int nextProgress = 76;
|
||||
m_progressBar->setValue(nextProgress);
|
||||
|
||||
if (!m_avmDataIfc->hasAvsSession())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "avm hasAvsSession failed";
|
||||
m_copyExercise.stopPing();
|
||||
return false;
|
||||
}
|
||||
|
||||
INFO_LOG(m_logger) << "hasAVsSession ok";
|
||||
|
||||
AudioVideoManagement::AvaSession *avaSession = m_avmDataIfc->avaSession();
|
||||
if (!avaSession->isEstablished())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "avaSession not established, abort";
|
||||
m_copyExercise.stopPing();
|
||||
return false;
|
||||
}
|
||||
|
||||
INFO_LOG(m_logger) << "avaSession established";
|
||||
|
||||
m_avaControl = avaSession->control();
|
||||
|
||||
getAVScripts();
|
||||
|
||||
m_avScriptsCount = m_vecScripts.count();
|
||||
QString labelText = tr("Downloaded Audio Video Data: ") + QString::number(m_avScriptsActualDone) + QStringLiteral(" / ") + QString::number(m_avScriptsCount);
|
||||
// 3/4 done
|
||||
m_label->setText(labelText);
|
||||
|
||||
if (m_vecScripts.isEmpty())
|
||||
{
|
||||
onProgressBar(100);
|
||||
return true;
|
||||
}
|
||||
|
||||
const QJsonObject obj = m_vecScripts.takeFirst();
|
||||
const AudioVideoManagement::AvaTopicData topicData(obj);
|
||||
m_lastScriptName = topicData.scriptName();
|
||||
|
||||
m_avaControl->setScript(QStringLiteral("LOCAL_RECORD"), topicData.scriptName(),
|
||||
topicData.isAudio() ? AudioVideoManagement::AvaScriptSource::ServerAudio : AudioVideoManagement::AvaScriptSource::ServerVideo,
|
||||
topicData.streamList(),
|
||||
LtsUtils::createConnection(m_avaControl, &AudioVideoManagement::AvaControl::setScriptResponse,
|
||||
this, &PreMobileDialog::slotScriptSet));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PreMobileDialog::slotScriptSet(const AudioVideoManagement::AvaStreamInfo &streamInfo, AudioVideoManagement::AvaStreamState streamState)
|
||||
{
|
||||
if (streamState == AudioVideoManagement::AvaStreamState::NotPossible)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Script " << m_lastScriptName << " not correctly downloaded";
|
||||
slotScriptDownloaded(streamState);
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "ScriptName: " << m_lastScriptName;
|
||||
DEBUG_LOG(m_logger) << "streamInfo: start" << streamInfo.duration.count();
|
||||
DEBUG_LOG(m_logger) << "streamState: " << static_cast<int>(streamState);
|
||||
|
||||
m_avaControl->startScript(QStringLiteral("LOCAL_RECORD"), m_lastScriptName,
|
||||
LtsUtils::createConnection(m_avaControl, &AudioVideoManagement::AvaControl::startScriptResponse,
|
||||
this, &PreMobileDialog::slotScriptDownloaded));
|
||||
}
|
||||
|
||||
void PreMobileDialog::slotScriptDownloaded(AudioVideoManagement::AvaStreamState streamState)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "streamState: " << static_cast<int>(streamState);
|
||||
|
||||
m_avScriptsActualDone += 1;
|
||||
QString labelText = tr("Downloaded Audio Video Data: ") + QString::number(m_avScriptsActualDone) + QStringLiteral(" / ") + QString::number(m_avScriptsCount);
|
||||
// 3/4 done
|
||||
m_label->setText(labelText);
|
||||
m_progressBar->setValue(m_progressBar->value()+1);
|
||||
|
||||
if (streamState == AudioVideoManagement::AvaStreamState::NotPossible)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Script " << m_lastScriptName << " not correctly downloaded";
|
||||
QString msg = tr("Could not download data - Audio/Video download - Script %1 failed").arg(m_lastScriptName);
|
||||
auto x = new LtsWidgets::LtsMessageDialogNew(this, msg);
|
||||
connect(x, &LtsWidgets::LtsMessageDialogNew::ok,
|
||||
this, &PreMobileDialog::slotScriptDownloadedStep2);
|
||||
return;
|
||||
}
|
||||
|
||||
slotScriptDownloadedStep2();
|
||||
}
|
||||
|
||||
|
||||
void PreMobileDialog::slotScriptDownloadedStep2()
|
||||
{
|
||||
m_avaControl->releaseScript(QStringLiteral("LOCAL_RECORD"), m_lastScriptName);
|
||||
|
||||
|
||||
if (m_vecScripts.isEmpty())
|
||||
{
|
||||
QString labelText = tr("Download Audio Video Data done");
|
||||
// 4/4 done
|
||||
m_label->setText(labelText);
|
||||
onProgressBar(100);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
fprintf(stderr, "slotScriptDownloaded - WAITING....\n");
|
||||
QTimer::singleShot(2500, this, [this]()
|
||||
{
|
||||
fprintf(stderr, "slotScriptDownloaded - GO!!!\n");
|
||||
const QJsonObject obj = m_vecScripts.takeFirst();
|
||||
const AudioVideoManagement::AvaTopicData topicData(obj);
|
||||
m_lastScriptName = topicData.scriptName();
|
||||
|
||||
m_avaControl->setScript(QStringLiteral("LOCAL_RECORD"), topicData.scriptName(),
|
||||
topicData.isAudio() ? AudioVideoManagement::AvaScriptSource::ServerAudio : AudioVideoManagement::AvaScriptSource::ServerVideo,
|
||||
topicData.streamList(),
|
||||
LtsUtils::createConnection(m_avaControl, &AudioVideoManagement::AvaControl::setScriptResponse,
|
||||
this, &PreMobileDialog::slotScriptSet));
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace PresentationManagement
|
||||
Reference in new issue
Block a user