+void RenameDialog::renameItem(const KFileItem &item, const QString& newName)
+{
+ const QUrl oldUrl = item.url();
+ QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename);
+ newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName));
+
+ QWidget* widget = parentWidget();
+ if (!widget) {
+ widget = this;
+ }
+
+ KIO::Job * job = KIO::moveAs(oldUrl, newUrl, KIO::HideProgressInfo);
+ KJobWidgets::setWindow(job, widget);
+ KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job);
+ job->ui()->setAutoErrorHandlingEnabled(true);
+}
+
+void RenameDialog::slotAccepted()
+{
+ m_newName = m_lineEdit->text();
+
+ if (m_renameOneItem) {
+ Q_ASSERT(m_items.count() == 1);
+ renameItem(m_items.first(), m_newName);
+ } else {
+ renameItems();
+ }
+ 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);
+ }
+ }
+ m_okButton->setEnabled(enable);
+}
+
+void RenameDialog::showEvent(QShowEvent* event)
+{
+ m_lineEdit->setFocus();
+
+ QDialog::showEvent(event);
+}
+
+void RenameDialog::renameItems()