#include "renamedialog.h"
-#include <KLocalizedString>
-#include <KJobWidgets>
+#include <KGuiItem>
+#include <KIO/BatchRenameJob>
#include <KIO/CopyJob>
#include <KIO/FileUndoManager>
#include <KJobUiDelegate>
-#include <KIO/BatchRenameJob>
+#include <KJobWidgets>
+#include <KLocalizedString>
+#include <QDialogButtonBox>
#include <QHBoxLayout>
#include <QLabel>
+#include <QLineEdit>
#include <QMimeDatabase>
-#include <QDialogButtonBox>
#include <QPushButton>
-#include <QLineEdit>
#include <QSpinBox>
-#include <KGuiItem>
RenameDialog::RenameDialog(QWidget *parent, const KFileItemList& items) :
QDialog(parent),
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")));
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);
widget = this;
}
+ const QList<QUrl> 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<KIO::BatchRenameJob*>(job), &KIO::BatchRenameJob::fileRenamed, this, &RenameDialog::slotFileRenamed);
}
- const QList<QUrl> 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);
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) {