X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/32bd8efc7f08a30622deaa3a80b7b26ceaea9f29..29778152ad:/src/views/renamedialog.cpp diff --git a/src/views/renamedialog.cpp b/src/views/renamedialog.cpp index 95a12474b..96068564d 100644 --- a/src/views/renamedialog.cpp +++ b/src/views/renamedialog.cpp @@ -19,22 +19,21 @@ #include "renamedialog.h" -#include -#include +#include +#include #include #include #include -#include +#include +#include +#include #include #include -#include +#include #include -#include #include -#include #include -#include RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : QDialog(parent), @@ -63,6 +62,7 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : m_okButton->setShortcut(Qt::CTRL + Qt::Key_Return); connect(buttonBox, &QDialogButtonBox::accepted, this, &RenameDialog::slotAccepted); connect(buttonBox, &QDialogButtonBox::rejected, this, &RenameDialog::reject); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QObject::deleteLater); m_okButton->setDefault(true); KGuiItem::assign(m_okButton, KGuiItem(i18nc("@action:button", "&Rename"), QStringLiteral("dialog-ok-apply"))); @@ -137,7 +137,7 @@ RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) : m_spinBox->setDisplayIntegerBase(10); QHBoxLayout* horizontalLayout = new QHBoxLayout(page); - horizontalLayout->setMargin(0); + horizontalLayout->setContentsMargins(0, 0, 0, 0); horizontalLayout->addWidget(infoLabel); horizontalLayout->addWidget(m_spinBox); @@ -156,22 +156,30 @@ void RenameDialog::slotAccepted() widget = this; } + const QList srcList = m_items.urlList(); + const QString newName = m_lineEdit->text(); KIO::FileUndoManager::CommandType cmdType; + KIO::Job *job = nullptr; if (m_renameOneItem) { Q_ASSERT(m_items.count() == 1); cmdType = KIO::FileUndoManager::Rename; + const QUrl oldUrl = m_items.constFirst().url(); + QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename); + newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName)); + m_renamedItems << newUrl; + job = KIO::moveAs(oldUrl, newUrl, KIO::HideProgressInfo); } else { cmdType = KIO::FileUndoManager::BatchRename; + job = KIO::batchRename(srcList, newName, m_spinBox->value(), QLatin1Char('#')); + connect(qobject_cast(job), &KIO::BatchRenameJob::fileRenamed, this, &RenameDialog::slotFileRenamed); } - const QList srcList = m_items.urlList(); - KIO::BatchRenameJob* job = KIO::batchRename(srcList, m_lineEdit->text(), m_spinBox->value(), QLatin1Char('#')); KJobWidgets::setWindow(job, widget); const QUrl parentUrl = srcList.first().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash); KIO::FileUndoManager::self()->recordJob(cmdType, srcList, parentUrl, job); - connect(job, &KIO::BatchRenameJob::fileRenamed, this, &RenameDialog::slotFileRenamed); - connect(job, &KIO::BatchRenameJob::result, this, &RenameDialog::slotResult); + connect(job, &KJob::result, this, &RenameDialog::slotResult); + connect(job, &KJob::result, this, &QObject::deleteLater); job->uiDelegate()->setAutoErrorHandlingEnabled(true); @@ -180,7 +188,7 @@ void RenameDialog::slotAccepted() void RenameDialog::slotTextChanged(const QString& newName) { - bool enable = !newName.isEmpty() && (newName != QLatin1String("..")) && (newName != QLatin1String(".")); + bool enable = !newName.isEmpty() && (newName != QLatin1String("..")) && (newName != QLatin1Char('.')); if (enable && !m_renameOneItem) { const int count = newName.count(QLatin1Char('#')); if (count == 0) {