From kde-commits Thu Dec 31 17:24:18 2015 From: Michel Ludwig Date: Thu, 31 Dec 2015 17:24:18 +0000 To: kde-commits Subject: [kile] src/dialogs: Remove freshly created directory after aborting the new project dialog Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=145158267307676 Git commit 5d1a7ef5b8e32a6259abd20f5fb26b3363c219b7 by Michel Ludwig. Committed on 31/12/2015 at 17:22. Pushed by mludwig into branch 'master'. Remove freshly created directory after aborting the new project dialog Initial patch by Mateusz Krawiec (committed in 2.1 as a38870eee771b71a09ffa= 600ee34bff42a338afc). REVIEW: 126259 M +22 -20 src/dialogs/projectdialogs.cpp http://commits.kde.org/kile/5d1a7ef5b8e32a6259abd20f5fb26b3363c219b7 diff --git a/src/dialogs/projectdialogs.cpp b/src/dialogs/projectdialogs.cpp index 4ec1c28..843f536 100644 --- a/src/dialogs/projectdialogs.cpp +++ b/src/dialogs/projectdialogs.cpp @@ -320,7 +320,7 @@ void KileNewProjectDialog::onAccepted() = if (projectTitle().trimmed().isEmpty()) { if (KMessageBox::warningYesNo(this, i18n("You have not entered a project= name. If you decide to proceed, the project name will be set to \"Untitled= \".\n" - "Do you want to create the project nevertheless?"), i18n("No = Project Name Given")) =3D=3D KMessageBox::Yes) { + "Do you want to create the proj= ect nevertheless?"), i18n("No Project Name Given")) =3D=3D KMessageBox::Yes= ) { m_title->setText(i18n("Untitled")); } else { @@ -328,46 +328,48 @@ void KileNewProjectDialog::onAccepted() } } = - if (folder().trimmed().isEmpty()){ + const QString dirString =3D folder().trimmed(); + const QString fileString =3D file().trimmed(); + + if (dirString.isEmpty()) { KMessageBox::error(this, i18n("Please enter the folder where the project= file should be saved to."), i18n("Empty Location")); return; } = - const QString dirString =3D folder().trimmed(); - if(!QDir::isAbsolutePath(dirString)) { - KMessageBox::error(this, i18n("Please enter an absolute (local) path to = the project folder."), i18n("Invalid Location")); + if (!QDir::isAbsolutePath(dirString)) { + KMessageBox::error(this, i18n("Please enter an absolute path to the proj= ect folder."), i18n("Invalid Location")); + return; + } + + if (createNewFile() && fileString.isEmpty()){ + KMessageBox::error(this, i18n("Please enter a filename for the file that= should be added to this project."), i18n("No File Name Given")); return; } = - QDir dir =3D QDir(dirString); - KILE_DEBUG_MAIN << "project location is " << dir.absolutePath() << endl; + QDir dir(dirString); = - if(!dir.exists()){ + if (!dir.exists()) { dir.mkpath(dir.absolutePath()); } = - if(!dir.exists()){ - KMessageBox::error(this, i18n("Could not create the project folder, chec= k your permissions.")); + if (!dir.exists()) { + KMessageBox::error(this, i18n("Could not create the project folder. Plea= se check if you have write permission.")); return; } = QFileInfo fi(dir.absolutePath()); if (!fi.isDir() || !fi.isWritable()){ - KMessageBox::error(this, i18n("The project folder is not writable, check= your permissions.")); + KMessageBox::error(this, i18n("The project folder is not writable. Pleas= e check the permissions of the project folder.")); return; } + const QString projectFilePath =3D dir.filePath(cleanProjectFile()); - if(QFileInfo(projectFilePath).exists()){ - KMessageBox::error(this, i18n("The project file already exists, pleas= e select another name. Delete the existing project file if your intention w= as to overwrite it."), i18n("Project File Already Exists")); + if (QFileInfo(projectFilePath).exists()) { // this can only happen when t= he project dir existed already + KMessageBox::error(this, i18n("The project file already exists. Please s= elect another name."), i18n("Project File Already Exists")); return; } = if (createNewFile()) { - if (file().trimmed().isEmpty()){ - KMessageBox::error(this, i18n("Please enter a filename for the file tha= t should be added to this project."), i18n("No File Name Given")); - return; - } - //check for validity of name first, then check for existence (fixed by t= braun) QUrl fileURL; fileURL =3D fileURL.adjusted(QUrl::RemoveFilename); @@ -377,8 +379,8 @@ void KileNewProjectDialog::onAccepted() m_file->setText(validURL.fileName()); } = - if(QFileInfo(QDir(fi.path()) , file().trimmed()).exists()){ - if (KMessageBox::warningYesNo(this, i18n("The file \"%1\" already exist= s, overwrite it?", file()), i18n("File Already Exists")) =3D=3D KMessageBox= ::No) { + if(QFileInfo(QDir(fi.path()), fileString).exists()){ + if (KMessageBox::warningYesNo(this, i18n("The file \"%1\" already exist= s, overwrite it?", fileString), i18n("File Already Exists")) =3D=3D KMessag= eBox::No) { return; } }