Commit 2984a407 authored by Ahmad Samir's avatar Ahmad Samir

kdirselectdialog: when creating a new dir that already exists, select it

If the user tries to create a new dir and a dir with that name already
exists, select the existing dir in the tree view.

Don't use KIO::encodeFileName as it replaces '/' with the unicode character
fraction slash, which breaks creating nested dirs.

Drive-by change: port to KIO::setDetails(StatDetails).

Feature: 424082
parent 35fa7f4a
......@@ -136,14 +136,13 @@ void KDirSelectDialog::Private::slotMkdir()
name = KFileUtils::suggestName(m_parent->url(), name);
}
QString directory = KIO::encodeFileName(QInputDialog::getText(m_parent, i18nc("@title:window", "New Folder"),
i18nc("@label:textbox", "Create new folder in:\n%1", where),
QLineEdit::Normal, name, &ok));
const QString directory = QInputDialog::getText(m_parent, i18nc("@title:window", "New Folder"),
i18nc("@label:textbox", "Create new folder in:\n%1", where),
QLineEdit::Normal, name, &ok);
if (!ok) {
return;
}
bool selectDirectory = true;
bool writeOk = false;
bool exists = false;
QUrl folderurl(m_parent->url());
......@@ -159,7 +158,7 @@ void KDirSelectDialog::Private::slotMkdir()
folderurl.setPath(folderurl.path() + QLatin1Char('/') + *it);
KIO::StatJob *job = KIO::stat(folderurl);
KJobWidgets::setWindow(job, m_parent);
job->setDetails(0); //We only want to know if it exists, 0 == that.
job->setDetails(KIO::StatNoDetails); // We only want to know if it exists
job->setSide(KIO::StatJob::DestinationSide);
exists = job->exec();
if (!exists) {
......@@ -172,12 +171,20 @@ void KDirSelectDialog::Private::slotMkdir()
if (exists) { // url was already existent
QString which = folderurl.toDisplayString(QUrl::PreferLocalFile);
KMessageBox::sorry(m_parent, i18n("A file or folder named %1 already exists.", which));
selectDirectory = false;
} else if (!writeOk) {
KMessageBox::sorry(m_parent, i18n("You do not have permission to create that folder."));
} else if (selectDirectory) {
// Select the existing dir (if a file with that name exists, it won't be selected since
// we only show dirs here, this is cheaper than checking if the existing item is a file
// or folder).
m_parent->setCurrentUrl(folderurl);
return;
}
if (!writeOk) {
KMessageBox::sorry(m_parent, i18n("You do not have permission to create that folder."));
return;
}
// Select the newly created dir
m_parent->setCurrentUrl(folderurl);
}
void KDirSelectDialog::Private::slotCurrentChanged()
......
......@@ -29,7 +29,6 @@ class QAbstractItemView;
/**
* A pretty dialog for a KDirSelect control for selecting directories.
* @author Michael Jarrett <michaelj@corel.com>
* @deprecated since 5.0, use QFileDialog::getExistingDirectoryUrl instead.
*/
class KDirSelectDialog : public KDEPlatformFileDialogBase
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment