From 735c046ddac45f729e52dda38f7152b62c304bb3 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Tue, 18 Jun 2013 17:39:56 +0200 Subject: [PATCH 1/2] Ensure that the "Sort by Type" setting is respected Before this commit, switching from, e.g., "Sort by Name" to "Sort by Type" sometimes had no effect until the view was refreshed. The problem was that the re-sorting was triggered before the type information was actually added to the model. BUG: 310705 BUG: 312014 FIXED-IN: 4.10.5 REVIEW: 111004 --- dolphin/src/kitemviews/kfileitemmodel.cpp | 6 ++-- dolphin/src/tests/kfileitemmodeltest.cpp | 43 ++++++++++++++++++++++- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/dolphin/src/kitemviews/kfileitemmodel.cpp b/dolphin/src/kitemviews/kfileitemmodel.cpp index c78fdc358c..400d29849e 100644 --- a/dolphin/src/kitemviews/kfileitemmodel.cpp +++ b/dolphin/src/kitemviews/kfileitemmodel.cpp @@ -644,11 +644,11 @@ void KFileItemModel::onSortRoleChanged(const QByteArray& current, const QByteArr Q_UNUSED(previous); m_sortRole = typeForRole(current); -#ifdef KFILEITEMMODEL_DEBUG if (!m_requestRole[m_sortRole]) { - kWarning() << "The sort-role has been changed to a role that has not been received yet"; + QSet newRoles = m_roles; + newRoles << current; + setRoles(newRoles); } -#endif resortAllItems(); } diff --git a/dolphin/src/tests/kfileitemmodeltest.cpp b/dolphin/src/tests/kfileitemmodeltest.cpp index e636bcd917..fd6c2be90a 100644 --- a/dolphin/src/tests/kfileitemmodeltest.cpp +++ b/dolphin/src/tests/kfileitemmodeltest.cpp @@ -67,6 +67,7 @@ private slots: void testSetData(); void testSetDataWithModifiedSortRole_data(); void testSetDataWithModifiedSortRole(); + void testChangeSortRole(); void testModelConsistencyWhenInsertingItems(); void testItemRangeConsistencyWhenInsertingItems(); void testExpandItems(); @@ -274,6 +275,8 @@ void KFileItemModelTest::testSetDataWithModifiedSortRole() // Changing the value of a sort-role must result in // a reordering of the items. QCOMPARE(m_model->sortRole(), QByteArray("text")); + m_model->setSortRole("rating"); + QCOMPARE(m_model->sortRole(), QByteArray("rating")); QStringList files; files << "a.txt" << "b.txt" << "c.txt"; @@ -299,7 +302,6 @@ void KFileItemModelTest::testSetDataWithModifiedSortRole() ratingC.insert("rating", 6); m_model->setData(2, ratingC); - m_model->setSortRole("rating"); QCOMPARE(m_model->data(0).value("rating").toInt(), 2); QCOMPARE(m_model->data(1).value("rating").toInt(), 4); QCOMPARE(m_model->data(2).value("rating").toInt(), 6); @@ -320,6 +322,45 @@ void KFileItemModelTest::testSetDataWithModifiedSortRole() QVERIFY(isModelConsistent()); } +void KFileItemModelTest::testChangeSortRole() +{ + QCOMPARE(m_model->sortRole(), QByteArray("text")); + + QStringList files; + files << "a.txt" << "b.jpg" << "c.txt"; + m_testDir->createFiles(files); + + m_model->loadDirectory(m_testDir->url()); + QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.jpg" << "c.txt"); + + // Simulate that KFileItemModelRolesUpdater determines the mime type. + // Resorting the files by 'type' will only work immediately if their + // mime types are known. + for (int index = 0; index < m_model->count(); ++index) { + m_model->fileItem(index).determineMimeType(); + } + + // Now: sort by type. + QSignalSpy spyItemsMoved(m_model, SIGNAL(itemsMoved(KItemRange,QList))); + m_model->setSortRole("type"); + QCOMPARE(m_model->sortRole(), QByteArray("type")); + QVERIFY(!spyItemsMoved.isEmpty()); + + // The actual order of the files might depend on the translation of the + // result of KFileItem::mimeComment() in the user's language. + QStringList version1; + version1 << "b.jpg" << "a.txt" << "c.txt"; + + QStringList version2; + version2 << "a.txt" << "c.txt" << "b.jpg"; + + const bool ok1 = (itemsInModel() == version1); + const bool ok2 = (itemsInModel() == version2); + + QVERIFY(ok1 || ok2); +} + void KFileItemModelTest::testModelConsistencyWhenInsertingItems() { //QSKIP("Temporary disabled", SkipSingle); From 0af45dd5bf684d096662331904697035a5621a73 Mon Sep 17 00:00:00 2001 From: Dawit Alemayehu Date: Thu, 20 Jun 2013 08:27:12 -0400 Subject: [PATCH 2/2] Save the current session information to disk when it changes and remove the file when Konqueror is shutdown properly. Note this is mainly a fix for the regression caused by my prior commit that prevented Konqueror from doing tons of stat calls. REVIEW: 111048 --- konqueror/src/konqsessionmanager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/konqueror/src/konqsessionmanager.cpp b/konqueror/src/konqsessionmanager.cpp index 9e8851075d..871acff8ee 100644 --- a/konqueror/src/konqsessionmanager.cpp +++ b/konqueror/src/konqsessionmanager.cpp @@ -385,6 +385,8 @@ KonqSessionManager::KonqSessionManager() KonqSessionManager::~KonqSessionManager() { + if (m_sessionConfig) + QFile::remove(m_sessionConfig->name()); delete m_sessionConfig; } @@ -444,6 +446,8 @@ void KonqSessionManager::autoSaveSession() m_autoSaveTimer.stop(); saveCurrentSessionToFile(m_sessionConfig); + m_sessionConfig->sync(); + m_sessionConfig->markAsClean(); // Now that we have saved current session it's safe to remove our owned_by // directory