2017-10-21 19:20:10 +00:00
|
|
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
|
|
|
#include <cutter.h>
|
|
|
|
#include "SaveProjectDialog.h"
|
|
|
|
#include "ui_SaveProjectDialog.h"
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
CutterCore *core = CutterCore::getInstance();
|
|
|
|
core->setConfig("dir.projects", ui->projectsDirEdit->text().toUtf8().constData());
|
2017-11-26 13:17:16 +00:00
|
|
|
core->setConfig("prj.simple", ui->simpleCheckBox->isChecked());
|
2017-10-21 19:20:10 +00:00
|
|
|
core->setConfig("prj.files", ui->filesCheckBox->isChecked());
|
|
|
|
core->setConfig("prj.git", ui->gitCheckBox->isChecked());
|
|
|
|
core->setConfig("prj.zip", ui->zipCheckBox->isChecked());
|
|
|
|
|
|
|
|
QString projectName = ui->nameEdit->text().trimmed();
|
|
|
|
if(!CutterCore::isProjectNameValid(projectName))
|
|
|
|
{
|
|
|
|
QMessageBox::critical(this, tr("Save project"), tr("Invalid project name."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
core->saveProject(projectName);
|
|
|
|
|
|
|
|
QDialog::done(Saved);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveProjectDialog::reject()
|
|
|
|
{
|
|
|
|
}
|