cutter/src/dialogs/SaveProjectDialog.cpp

103 lines
2.8 KiB
C++
Raw Normal View History

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