- if (button == Ok) {
- m_newName = m_lineEdit->text();
- if (m_newName.isEmpty()) {
- m_errorString = i18nc("@info:status",
- "The new name is empty. A name with at least one character must be entered.");
- } else if (!m_renameOneItem && (m_newName.count('#') == 0)) {
- m_newName.truncate(0);
- m_errorString = i18nc("@info:status", "The name must contain at least one # character.");
+ QWidget* widget = parentWidget();
+ if (!widget) {
+ widget = this;
+ }
+
+ KIO::FileUndoManager::CommandType cmdType;
+ if (m_renameOneItem) {
+ Q_ASSERT(m_items.count() == 1);
+ cmdType = KIO::FileUndoManager::Rename;
+ } else {
+ cmdType = KIO::FileUndoManager::BatchRename;
+ }
+
+ 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);
+
+ job->uiDelegate()->setAutoErrorHandlingEnabled(true);
+
+ accept();
+}
+
+void RenameDialog::slotTextChanged(const QString& newName)
+{
+ bool enable = !newName.isEmpty() && (newName != QLatin1String("..")) && (newName != QLatin1String("."));
+ if (enable && !m_renameOneItem) {
+ const int count = newName.count(QLatin1Char('#'));
+ if (count == 0) {
+ // Renaming multiple files without '#' will only work if all extensions are different.
+ enable = m_allExtensionsDifferent;
+ } else {
+ // Assure that the new name contains exactly one # (or a connected sequence of #'s)
+ const int first = newName.indexOf(QLatin1Char('#'));
+ const int last = newName.lastIndexOf(QLatin1Char('#'));
+ enable = (last - first + 1 == count);