#include "dolphintabwidget.h"
#include "dolphinviewcontainer.h"
#include "kitemviews/kfileitemmodel.h"
+#include "kitemviews/kfileitemmodelrolesupdater.h"
#include "kitemviews/kitemlistcontainer.h"
#include "kitemviews/kitemlistcontroller.h"
#include "kitemviews/kitemlistselectionmanager.h"
void testAccessibilityTree();
void testAutoSaveSession();
void testInlineRename();
+ void testThumbnailAfterRename();
void cleanupTestCase();
private:
QCOMPARE(view->m_model->count(), 4);
}
+void DolphinMainWindowTest::testThumbnailAfterRename()
+{
+ // Create testdir and red square jpg for testing
+ QScopedPointer<TestDir> testDir{new TestDir()};
+ QImage testImage(256, 256, QImage::Format_Mono);
+ testImage.setColorCount(1);
+ testImage.setColor(0, qRgba(255, 0, 0, 255)); // Index #0 = Red
+ for (short x = 0; x < 256; ++x) {
+ for (short y = 0; y < 256; ++y) {
+ testImage.setPixel(x, y, 0);
+ }
+ }
+ testImage.save(testDir.data()->path() + "/a.jpg");
+
+ // Open dir and show it
+ m_mainWindow->openDirectories({testDir->url()}, false);
+ DolphinView *view = m_mainWindow->activeViewContainer()->view();
+ // Prepare signal spies
+ QSignalSpy viewDirectoryLoadingCompletedSpy(view, &DolphinView::directoryLoadingCompleted);
+ QSignalSpy itemsChangedSpy(view->m_model, &KFileItemModel::itemsChanged);
+ QSignalSpy modelDirectoryLoadingCompletedSpy(view->m_model, &KFileItemModel::directoryLoadingCompleted);
+ QSignalSpy previewUpdatedSpy(view->m_view->m_modelRolesUpdater, &KFileItemModelRolesUpdater::previewJobFinished);
+ // Show window and check that our preview has been updated, then wait for it to appear
+ m_mainWindow->show();
+ QVERIFY(viewDirectoryLoadingCompletedSpy.wait());
+ QVERIFY(previewUpdatedSpy.wait());
+ QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data()));
+ QVERIFY(m_mainWindow->isVisible());
+ QTest::qWait(500); // we need to wait for the file widgets to become visible
+
+ // Set image selected and rename it to b.jpg, make sure editing role is working
+ view->markUrlsAsSelected({QUrl(testDir->url().toString() + "/a.jpg")});
+ view->updateViewState();
+ view->renameSelectedItems();
+ QVERIFY(view->m_view->m_editingRole);
+ QTest::keyClick(QApplication::focusWidget(), Qt::Key_B);
+ QTest::keyClick(QApplication::focusWidget(), Qt::Key_Enter);
+ QVERIFY(itemsChangedSpy.wait()); // Make sure that rename worked
+
+ // Check that preview gets updated and filename is correct
+ QVERIFY(previewUpdatedSpy.wait());
+ QVERIFY(!view->m_view->m_editingRole);
+ QCOMPARE(view->m_model->fileItem(0).name(), "b.jpg");
+ QCOMPARE(view->m_model->count(), 1);
+}
+
void DolphinMainWindowTest::cleanupTestCase()
{
m_mainWindow->showNormal();
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);
}
}
}
#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();