diff options
| author | Akseli Lahtinen <[email protected]> | 2024-12-19 10:04:16 +0000 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2024-12-19 10:04:16 +0000 |
| commit | eca160ae5a2dbd5590e4bae22cddde488dbacf74 (patch) | |
| tree | fca5a83742c53cdaba71f24f9dfea5a3b7024f25 /src/views | |
| parent | e977737a182c5787d91d18f2d267027ba4f9dc24 (diff) | |
dolphinview: Update thumbnail on filename change
If filename of an item was updated previously, it would modify the model
before the file was actually changed. This led to the model calling
a signal that would try to run a previewjob, but since the filename
is not actually changed yet on disk, it would fail.
This patch moves the model updating after copyjob. Copyjob
will take care of the file renaming if there is already existing file.
We just need to update the model correctly after the job has succeeded.
BUG:497555
Diffstat (limited to 'src/views')
| -rw-r--r-- | src/views/dolphinview.cpp | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 55ab8a27d..6a4ccb70d 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -1889,15 +1889,18 @@ void DolphinView::selectNextItem() void DolphinView::slotRenamingResult(KJob *job) { - if (job->error()) { + // Change model data after renaming has succeeded. On failure we do nothing. + // If there is already an item with the newUrl, the copyjob will open a dialog for it, and + // KFileItemModel will update the data when the dir lister signals that the file name has changed. + if (!job->error()) { KIO::CopyJob *copyJob = qobject_cast<KIO::CopyJob *>(job); Q_ASSERT(copyJob); const QUrl newUrl = copyJob->destUrl(); + const QUrl oldUrl = copyJob->srcUrls().at(0); const int index = m_model->index(newUrl); - if (index >= 0) { + if (m_model->index(oldUrl) == index) { QHash<QByteArray, QVariant> data; - const QUrl oldUrl = copyJob->srcUrls().at(0); - data.insert("text", oldUrl.fileName()); + data.insert("text", newUrl.fileName()); m_model->setData(index, data); } } @@ -2032,24 +2035,12 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray &role, con } #endif - const bool newNameExistsAlready = (m_model->index(newUrl) >= 0); - if (!newNameExistsAlready && m_model->index(oldUrl) == index) { - // Only change the data in the model if no item with the new name - // is in the model yet. If there is an item with the new name - // already, calling KIO::CopyJob will open a dialog - // asking for a new name, and KFileItemModel will update the - // data when the dir lister signals that the file name has changed. - QHash<QByteArray, QVariant> data; - data.insert(role, retVal.newName); - m_model->setData(index, data); - } - KIO::Job *job = KIO::moveAs(oldUrl, newUrl); KJobWidgets::setWindow(job, this); KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job); job->uiDelegate()->setAutoErrorHandlingEnabled(true); - if (!newNameExistsAlready) { + if (m_model->index(newUrl) < 0) { forceUrlsSelection(newUrl, {newUrl}); updateSelectionState(); |
