]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/renamedialog.cpp
Rename variables to improve readability of Dolphin::attachToExistingInstance
[dolphin.git] / src / views / renamedialog.cpp
index 24b7986be9bf216a45288fe3a4d890bb3a904c64..96068564d16dab31659d3c96507a24ef695aed53 100644 (file)
 
 #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),
@@ -62,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")));
@@ -136,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);
 
@@ -155,22 +156,30 @@ void RenameDialog::slotAccepted()
         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);
 
@@ -179,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) {