284 lines
9.2 KiB
C++
Executable File
284 lines
9.2 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* ScriptChooser Payload UI
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*
|
|
* Created by Mike Wille, SLSE, 2017-03-21
|
|
*/
|
|
|
|
#include "script_chooser.h"
|
|
#include "ui_script_chooser.h"
|
|
|
|
#include <ConnectDialog/connect_dialog_nt.h>
|
|
#include <LtsDataView/search_model.h>
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <LtsWidgets/lts_global_wait_dialog.h>
|
|
#include <LtsWidgets/lts_message_dialog.h>
|
|
#include <Plugins/PresentationManagement/Gui/Common/pre_model.h>
|
|
#include <QMessageBox>
|
|
#include <QCloseEvent>
|
|
#include <QTimer>
|
|
|
|
|
|
namespace PresentationManagement
|
|
{
|
|
|
|
ScriptChooser::ScriptChooser(const std::shared_ptr<Interface::Dtc> &dtc,
|
|
const std::shared_ptr<PresentationManagement::Interface::Ftc> &ftc,
|
|
const std::shared_ptr<OperatorManagement::Interface::Dtc> &opmDtc,
|
|
bool isPlayerMode,
|
|
bool isImportDialog,
|
|
QWidget *parent)
|
|
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
|
|
, m_model(new PresentationManagementDialogModel(this))
|
|
, m_proxy(new PresentationManagementDialogProxyModel(this))
|
|
, m_selected(false)
|
|
, m_isImportDialog(isImportDialog)
|
|
, m_ui(new Ui::ScriptChooser)
|
|
, m_logger(getLogger(QStringLiteral("ScriptChooser")))
|
|
, m_ftc(ftc)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
{
|
|
if (!m_isImportDialog)
|
|
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(false);
|
|
|
|
m_ui->setupUi(this);
|
|
setWindowFlags( Qt::Dialog | Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::WindowTitleHint ); // hints..
|
|
|
|
// only show Valid (= not deleted) scripts
|
|
auto predicate = [](const PresentationManagement::Presentation & p)
|
|
{
|
|
return (!p.isDeleted() && p.fileStatus() == FileStatus::Valid);
|
|
};
|
|
m_model->initModel(dtc, opmDtc, predicate);
|
|
m_proxy->setSourceModel(m_model);
|
|
|
|
m_ui->ltsDataView->seamless();
|
|
// m_ui->ltsDataView->selectCustomView();
|
|
m_ui->ltsDataView->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
|
|
m_ui->ltsDataView->setModel(m_proxy);//, [this]() { return new CustomViewExercise(this); }); TODO: custom widgets!
|
|
int operatorId = LtsSessionData::LtsSessionData::getInstance()->getOperatorId();
|
|
bool bSetOperator = m_ui->ltsDataView->setInitialSearchContent(
|
|
PresentationManagementDialogModel::Columns::Operator, QVariant(LtsSessionData::LtsSessionData::getInstance()->getOperatorId())
|
|
);
|
|
if (!bSetOperator)
|
|
WARNING_LOG(m_logger) << "could not set initial operator id to " << operatorId;
|
|
|
|
connect(m_ui->ltsDataView, &LtsDataView::LtsDataView::signalSelectionChanged,
|
|
this, &ScriptChooser::onEnaDisa, Qt::QueuedConnection);
|
|
connect(m_ui->ltsDataView, &LtsDataView::LtsDataView::signalDoubleClicked,
|
|
this, &ScriptChooser::onScriptSelected, Qt::QueuedConnection);
|
|
connect(m_ui->ltsDataView, &LtsDataView::LtsDataView::signalEnterPressed,
|
|
this, &ScriptChooser::onScriptSelected, Qt::QueuedConnection);
|
|
connect(m_ui->pbSelect, &QPushButton::clicked,
|
|
this, &ScriptChooser::onScriptSelected, Qt::QueuedConnection);
|
|
connect(m_ui->pbDeleteScript, &QPushButton::clicked,
|
|
this, &ScriptChooser::onDeleteScript, Qt::QueuedConnection);
|
|
|
|
setSelectorMode(isPlayerMode); // has to be called BEFORE manually setVisible on the buttons!
|
|
|
|
if (!isImportDialog)
|
|
{
|
|
connect(m_ui->pbQuit, &QPushButton::clicked,
|
|
this, &ScriptChooser::signalQuit, Qt::QueuedConnection);
|
|
}
|
|
else
|
|
{
|
|
m_ui->pbNewScript->setVisible(false);
|
|
m_ui->pbEditQuit->setVisible(false);
|
|
}
|
|
|
|
connect(m_ui->pbQuit, &QPushButton::clicked, this, [this]()
|
|
{
|
|
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
|
|
m_close = true;
|
|
close();
|
|
});
|
|
|
|
connect(m_ui->pbNewScript, &QPushButton::clicked,
|
|
this, &ScriptChooser::signalNewScript, Qt::QueuedConnection);
|
|
|
|
connect(m_ui->pbEditQuit, &QPushButton::clicked,
|
|
this, &ScriptChooser::signalEditQuit);
|
|
|
|
#ifndef LTS_DEBUG
|
|
m_ui->ltsDataView->hideColumn(PresentationManagementDialogModel::Id);
|
|
#endif
|
|
m_ui->ltsDataView->setSortIndicator(PresentationManagementDialogModel::Name, Qt::AscendingOrder);
|
|
|
|
if (!m_isImportDialog)
|
|
{
|
|
qint32 scriptId = LtsSessionData::LtsSessionData::getInstance()->getScriptId();
|
|
|
|
if (scriptId == 0)
|
|
return;
|
|
|
|
LtsSessionData::LtsSessionData::getInstance()->setScriptId(0);
|
|
|
|
if (scriptId < 0)
|
|
{
|
|
FATAL_LOG(m_logger) << "ScriptIdPreset " << scriptId << " is invalid!";
|
|
Q_ASSERT(false);
|
|
return;
|
|
}
|
|
|
|
bool isExistingScriptId = false;
|
|
qint32 rowCounter;
|
|
|
|
for (rowCounter = 0; rowCounter < m_model->rowCount(); ++rowCounter)
|
|
{
|
|
if (m_model->getRowData(rowCounter).id() == scriptId)
|
|
{
|
|
isExistingScriptId = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (scriptId < 0 || !isExistingScriptId)
|
|
{
|
|
FATAL_LOG(m_logger) << "ScriptIdPreset " << scriptId << " is invalid!";
|
|
Q_ASSERT(false);
|
|
return;
|
|
}
|
|
|
|
QTimer::singleShot(100, this, [this, rowCounter]()
|
|
{
|
|
const Presentation p = m_model->getRowData(rowCounter);
|
|
|
|
if (p.id() <= 0)
|
|
return;
|
|
|
|
setEnabled(false);
|
|
|
|
if (!m_isImportDialog)
|
|
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
|
|
|
|
emit signalSelectScript(p.id());
|
|
m_close = true;
|
|
close();
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
ScriptChooser::~ScriptChooser()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
|
|
void ScriptChooser::reject()
|
|
{
|
|
if (!m_selected && !m_isImportDialog /* do not quit session if this dialog is misused as import dialog for a running app */)
|
|
emit signalQuit();
|
|
|
|
QDialog::reject();
|
|
}
|
|
|
|
void ScriptChooser::onDeleteScript()
|
|
{
|
|
int ret = QMessageBox::warning(this, tr("DELETE SCRIPT"),
|
|
tr("Do you really want to delete the selected script?"),
|
|
QMessageBox::Yes | QMessageBox::Cancel);
|
|
if(ret == QMessageBox::Yes)
|
|
{
|
|
const QModelIndex idx = m_ui->ltsDataView->currentIndex();
|
|
const Presentation pre = m_model->getRowData(idx.row());
|
|
const FileStatus fs = FileStatus::Deleted;
|
|
PresentationChangeStatusRequest req;
|
|
|
|
req.id(pre.id());
|
|
req.fileStatus(fs);
|
|
req.operatorId(LtsSessionData::LtsSessionData::getInstance()->getOperatorId());
|
|
req.lastModified(QDateTime::currentMSecsSinceEpoch());
|
|
DEBUG_LOG(m_logger) << "Changing status for presentation id = " << pre.id();
|
|
|
|
m_requestHelper->startSingleRequest([this, req]()
|
|
{
|
|
return m_ftc->presentationChangeStatusRequest(PresentationChangeStatusRequest(req), this);
|
|
});
|
|
|
|
auto srcIdx = m_ui->ltsDataView->proxyModel()->mapFromSource(idx);
|
|
m_ui->ltsDataView->proxyModel()->removeRow(srcIdx.row());
|
|
|
|
if (m_requestHelper->failed())
|
|
ERROR_LOG(m_logger) << "Failed to change status for presentation-script_chooser";
|
|
}
|
|
|
|
}
|
|
void ScriptChooser::onScriptSelected()
|
|
{
|
|
if (m_isImportDialog)
|
|
{
|
|
connect(new LtsWidgets::LtsMessageDialogNew(this, tr("You are about to import the selected script to the currently open script.<br />"
|
|
"The import script will be inserted at the indicated position and moves all topics after the indicated position to after the to-be imported script's content.<br/>"
|
|
"Info: The indicated position is indicated by the light blue vertical line. Its position can be changed by clicking on a topic or by clicking at the desired position in the header (where the time texts are drawn on).<br />"
|
|
"This operation can't be reversed.<br />"
|
|
"<br />"
|
|
"Are you sure you want to import the selected script?<br />"
|
|
"Click yes to import the script.<br />"
|
|
"Click no to cancel this operation and don't import."), tr("Import script"), LtsWidgets::Behaviour::Modal, LtsWidgets::Button::Yes | LtsWidgets::Button::No),
|
|
&LtsWidgets::LtsMessageDialogNew::yes,
|
|
this, &ScriptChooser::onImportScript, Qt::QueuedConnection);
|
|
|
|
return;
|
|
}
|
|
|
|
onImportScript();
|
|
}
|
|
|
|
|
|
void ScriptChooser::onImportScript()
|
|
{
|
|
if (m_selected)
|
|
return;
|
|
|
|
m_selected = true;
|
|
|
|
const QModelIndex idx = m_ui->ltsDataView->currentIndex();
|
|
const Presentation p = m_model->getRowData(idx.row());
|
|
|
|
if (p.id() <= 0)
|
|
return;
|
|
|
|
setEnabled(false);
|
|
|
|
if (!m_isImportDialog)
|
|
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
|
|
|
|
emit signalSelectScript(p.id());
|
|
m_close = true;
|
|
close();
|
|
}
|
|
|
|
|
|
void ScriptChooser::onEnaDisa()
|
|
{
|
|
m_ui->pbSelect->setEnabled(m_ui->ltsDataView->selectedRows().size() == 1);
|
|
m_ui->pbDeleteScript->setEnabled(m_ui->ltsDataView->selectedRows().size() == 1);
|
|
}
|
|
|
|
|
|
void ScriptChooser::closeEvent(QCloseEvent *event)
|
|
{
|
|
if (!m_close)
|
|
{
|
|
event->ignore();
|
|
return;
|
|
}
|
|
|
|
if (!m_isImportDialog)
|
|
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
|
|
}
|
|
|
|
|
|
void ScriptChooser::setSelectorMode(bool isPlayer)
|
|
{
|
|
m_ui->pbNewScript->setVisible(!isPlayer);
|
|
m_ui->pbEditQuit->setVisible(isPlayer);
|
|
}
|
|
|
|
} // namespace PresentationManagement
|