+#include "NewProjectDialog.h"
+
+NewProjectDialog::NewProjectDialog(Parameters *_params, QWidget *parent) : CustomDialog(tr("Create a new project"),tr("Location"), parent) {
+
+ params = _params;
+
+ QHBoxLayout *layNameProj = new QHBoxLayout;
+ QLabel *nameProjLab = new QLabel(tr("Name :"));
+ nameProjEdit = new QLineEdit();
+ nameProjEdit->setMaxLength(100);
+ nameProjEdit->setText("");
+
+ layNameProj->addWidget(nameProjLab);
+ layNameProj->addWidget(nameProjEdit);
+
+ QHBoxLayout *layDirProj = new QHBoxLayout;
+ QLabel *dirProjLab = new QLabel(tr("Path :"));
+ dirProjEdit = new QLineEdit("");
+ dirProjEdit->setMaxLength(500);
+ dirProjButton = new QPushButton(QIcon(":/images/filefind.png"),"");
+ dirProjButton->setFixedWidth(30);
+ pathOk = false;
+
+ layDirProj->addWidget(dirProjLab);
+ layDirProj->addWidget(dirProjEdit);
+ layDirProj->addWidget(dirProjButton);
+
+
+ QVBoxLayout *layAll = new QVBoxLayout;
+ layAll->addLayout(layNameProj);
+ layAll->addLayout(layDirProj);
+
+ setContent(layAll);
+
+ connect(dirProjButton,SIGNAL(clicked()),this,SLOT(chooseProjectPath()));
+ connect(nameProjEdit,SIGNAL(textChanged(QString)),this,SLOT(checkProjectName(QString)));
+ connect(dirProjEdit,SIGNAL(textChanged(QString)),this,SLOT(checkProjectPath(QString)));
+
+}
+
+void NewProjectDialog::checkBeforeAccept() {
+
+ if ((!nameProjEdit->text().isEmpty()) && (pathOk)) {
+ //cout << "all ok" << endl;
+ params->projectPath = dirProjEdit->text();
+ params->projectFile = params->projectPath + "/" + params->projectName + ".xml";
+
+ accept();
+ }
+ else {
+ int ret = QMessageBox::warning(this,"Cannot create the project","Invalid project path");
+
+ }
+}
+
+void NewProjectDialog::chooseProjectPath() {
+
+ QString where;
+ where = QDir::currentPath();
+ QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),where);
+ dirProjEdit->setText(dir);
+}
+
+void NewProjectDialog::checkProjectPath(QString name) {
+ QDir dir(name);
+ if (dir.exists()) {
+ pathOk = true;
+ }
+ else {
+ pathOk = false;
+ }
+}
+
+void NewProjectDialog::checkProjectName(QString name) {
+ params->projectName = Parameters::normalizeName(name);
+ if (name != params->projectName) {
+ nameProjEdit->setText(params->projectName);
+ }
+}