2017-10-21 19:20:10 +00:00
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
2018-03-04 17:42:02 +00:00
|
|
|
#include <Cutter.h>
|
2017-10-21 19:20:10 +00:00
|
|
|
#include "SaveProjectDialog.h"
|
|
|
|
#include "ui_SaveProjectDialog.h"
|
2018-03-07 10:49:40 +00:00
|
|
|
#include "utils/TempConfig.h"
|
2017-10-21 19:20:10 +00:00
|
|
|
|
|
|
|
SaveProjectDialog::SaveProjectDialog(bool quit, QWidget *parent) :
|
2017-11-03 17:22:54 +00:00
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::SaveProjectDialog)
|
2017-10-21 19:20:10 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2017-11-03 17:22:54 +00:00
|
|
|
CutterCore *core = CutterCore::getInstance();
|
2017-10-21 19:20:10 +00:00
|
|
|
|
|
|
|
if (quit)
|
|
|
|
{
|
|
|
|
ui->buttonBox->setStandardButtons(QDialogButtonBox::Save
|
|
|
|
| QDialogButtonBox::Discard
|
|
|
|
| QDialogButtonBox::Cancel);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->buttonBox->setStandardButtons(QDialogButtonBox::Save
|
|
|
|
| QDialogButtonBox::Cancel);
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->nameEdit->setText(core->getConfig("prj.name"));
|
2017-11-03 17:22:54 +00:00
|
|
|
ui->projectsDirEdit->setText(core->getConfig("dir.projects"));
|
2017-11-26 13:17:16 +00:00
|
|
|
ui->simpleCheckBox->setChecked(core->getConfigb("prj.simple"));
|
2017-11-03 17:22:54 +00:00
|
|
|
ui->filesCheckBox->setChecked(core->getConfigb("prj.files"));
|
|
|
|
ui->gitCheckBox->setChecked(core->getConfigb("prj.git"));
|
|
|
|
ui->zipCheckBox->setChecked(core->getConfigb("prj.zip"));
|
2017-10-21 19:20:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SaveProjectDialog::~SaveProjectDialog()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveProjectDialog::on_selectProjectsDirButton_clicked()
|
|
|
|
{
|
|
|
|
QFileDialog dialog(this);
|
|
|
|
dialog.setFileMode(QFileDialog::DirectoryOnly);
|
|
|
|
|
|
|
|
QString currentDir = ui->projectsDirEdit->text();
|
|
|
|
if(currentDir.startsWith("~"))
|
|
|
|
{
|
|
|
|
currentDir = QDir::homePath() + currentDir.mid(1);
|
|
|
|
}
|
|
|
|
dialog.setDirectory(currentDir);
|
|
|
|
|
|
|
|
dialog.setWindowTitle(tr("Select project path (dir.projects)"));
|
|
|
|
|
|
|
|
if(!dialog.exec())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString dir = dialog.selectedFiles().first();
|
|
|
|
if (!dir.isEmpty())
|
|
|
|
{
|
|
|
|
ui->projectsDirEdit->setText(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveProjectDialog::on_buttonBox_clicked(QAbstractButton *button)
|
|
|
|
{
|
2017-11-03 17:22:54 +00:00
|
|
|
switch(ui->buttonBox->buttonRole(button))
|
|
|
|
{
|
|
|
|
case QDialogButtonBox::DestructiveRole:
|
2017-10-21 19:20:10 +00:00
|
|
|
QDialog::done(Destructive);
|
2017-11-03 17:22:54 +00:00
|
|
|
break;
|
2017-10-21 19:20:10 +00:00
|
|
|
|
2017-11-03 17:22:54 +00:00
|
|
|
case QDialogButtonBox::RejectRole:
|
2017-10-21 19:20:10 +00:00
|
|
|
QDialog::done(Rejected);
|
2017-11-03 17:22:54 +00:00
|
|
|
break;
|
2017-10-21 19:20:10 +00:00
|
|
|
|
2017-11-03 17:22:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-10-21 19:20:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveProjectDialog::accept()
|
|
|
|
{
|
2018-03-07 10:49:40 +00:00
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig.set("dir.projects", ui->projectsDirEdit->text().toUtf8().constData())
|
|
|
|
.set("prj.simple", ui->simpleCheckBox->isChecked())
|
|
|
|
.set("prj.files", ui->filesCheckBox->isChecked())
|
|
|
|
.set("prj.git", ui->gitCheckBox->isChecked())
|
|
|
|
.set("prj.zip", ui->zipCheckBox->isChecked());
|
2017-10-21 19:20:10 +00:00
|
|
|
|
|
|
|
QString projectName = ui->nameEdit->text().trimmed();
|
|
|
|
if(!CutterCore::isProjectNameValid(projectName))
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Save project"), tr("Invalid project name."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-07 10:49:40 +00:00
|
|
|
Core()->saveProject(projectName);
|
2017-10-21 19:20:10 +00:00
|
|
|
|
|
|
|
QDialog::done(Saved);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveProjectDialog::reject()
|
|
|
|
{
|
2017-12-06 16:58:26 +00:00
|
|
|
done(Rejected);
|
2017-10-21 19:20:10 +00:00
|
|
|
}
|