159 lines
5.4 KiB
C++
Executable File
159 lines
5.4 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* FileManagement - Rename Folder Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Iuliana Ojog, SLSE, 2017-05-22
|
|
*/
|
|
|
|
#include "flm_edit_folder.h"
|
|
#include "ui_flm_edit_folder.h"
|
|
#include <LtsSession/lts_session_data.h>
|
|
|
|
namespace FileManagement
|
|
{
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------
|
|
FolderEditDialog::FolderEditDialog(QWidget *parent)
|
|
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_ui(new Ui::FolderEditDialog)
|
|
, m_workingIndex(QModelIndex())
|
|
, m_logger(getLogger("FolderEditDialog"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
connect(m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, this, &FolderEditDialog::close);
|
|
connect(m_ui->leName, &QLineEdit::textChanged, this, &FolderEditDialog::validate);
|
|
connect(m_ui->leName, &QLineEdit::returnPressed, this, &FolderEditDialog::onReturnPressed);
|
|
|
|
m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Apply)->hide();
|
|
m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Ok)->hide();
|
|
|
|
m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Add)->setDisabled(m_ui->leName->text().isEmpty());
|
|
}
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------
|
|
FolderEditDialog::~FolderEditDialog()
|
|
{
|
|
delete m_ui;
|
|
delete m_requestHelper;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------
|
|
void FolderEditDialog::validate(const QString &folderName)
|
|
{
|
|
m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Add)->setDisabled(folderName.isEmpty());
|
|
}
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------
|
|
void FolderEditDialog::onReturnPressed()
|
|
{
|
|
if (m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Add)->isEnabled())
|
|
m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Add)->setFocus();
|
|
}
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------
|
|
bool FolderEditDialog::init(const QModelIndex &workingIndex, const int &folderId, const int &parentFolderId,
|
|
const std::shared_ptr<FileManagement::Interface::Dtc> &dtc,
|
|
const std::shared_ptr<FileManagement::Interface::Ftc> &ftc,
|
|
bool isAdminMode,
|
|
const FileManagement::Folder &data)
|
|
{
|
|
if (!dtc || !ftc)
|
|
return false;
|
|
|
|
m_workingIndex = workingIndex;
|
|
m_folderId = folderId;
|
|
m_parentFolderId = parentFolderId;
|
|
m_editData = data;
|
|
m_dtc = dtc;
|
|
m_ftc = ftc;
|
|
|
|
setWindowTitle(tr("Create New Folder"));
|
|
if (m_folderId > 0) //EditMode
|
|
{
|
|
m_ui->leName->setText(QString::fromStdString(m_editData.name()));
|
|
m_ui->ltsDialogButtonBox->setText(LtsWidgets::DialogButton::Add, tr("Rename"));
|
|
setWindowTitle(tr("Edit Folder"));
|
|
}
|
|
else if (data.id() > 0) // add folder from copy/paste
|
|
m_ui->leName->setText(QString::fromStdString(m_editData.name()));
|
|
m_ui->ltsDialogButtonBox->connectButton(LtsWidgets::DialogButton::Add, this, &FolderEditDialog::onAddEditFolder);
|
|
|
|
m_ui->cbHidden->setVisible(isAdminMode);
|
|
m_ui->cbHidden->setChecked(m_editData.isHidden());
|
|
|
|
#ifdef TABLET_MODE
|
|
m_ui->leName->setFocusPolicy(Qt::ClickFocus);
|
|
m_ui->leName->clearFocus();
|
|
#else
|
|
m_ui->leName->setFocus();
|
|
#endif
|
|
|
|
return true;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------
|
|
void FolderEditDialog::onAddEditFolder()
|
|
{
|
|
if (apply())
|
|
{
|
|
close();
|
|
DEBUG_LOG(m_logger) << "Added / Edited folder " << m_editData.name();
|
|
}
|
|
}
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------
|
|
bool FolderEditDialog::apply()
|
|
{
|
|
if (m_folderId > 0)
|
|
// already exists (rename folder)
|
|
{
|
|
DEBUG_LOG(m_logger) << "Rename folder id = " << m_folderId;
|
|
m_requestHelper->addRequest([this]()
|
|
{
|
|
FolderModifyRequest req;
|
|
req.id(m_folderId);
|
|
req.name(m_ui->leName->text().toStdString());
|
|
req.path(m_dtc->folder(m_folderId).path());
|
|
req.isEditable(true);
|
|
req.isHidden(m_ui->cbHidden->isChecked());
|
|
req.parentId(m_dtc->folder(m_folderId).parentId());
|
|
req.operatorId(LtsSessionData::LtsSessionData::getInstance()->getOperatorId());
|
|
return m_ftc->folderModifyRequest(req, this);
|
|
});
|
|
|
|
}
|
|
else
|
|
// create new folder
|
|
{
|
|
DEBUG_LOG(m_logger) << "Create new folder";
|
|
|
|
FolderModifyRequest req;
|
|
req.name(m_ui->leName->text().toStdString());
|
|
req.isEditable(true);
|
|
req.isHidden(m_ui->cbHidden->isChecked());
|
|
req.parentId(m_parentFolderId);
|
|
std::vector<int> parentPath;
|
|
if (m_parentFolderId > 0)
|
|
{
|
|
FileManagement::Folder fld = m_dtc->folder(m_parentFolderId);
|
|
parentPath = fld.path();
|
|
}
|
|
req.path(parentPath);
|
|
req.operatorId(LtsSessionData::LtsSessionData::getInstance()->getOperatorId());
|
|
|
|
m_requestHelper->addRequest([req, this]()
|
|
{
|
|
return m_ftc->folderModifyRequest(req, this);
|
|
});
|
|
|
|
}
|
|
// do nothing on failure - rh's message is enough
|
|
return m_requestHelper->startRequests(); // return success or failure
|
|
}
|
|
|
|
} // namespace FileManagement;
|