diff options
| author | Victor Blanchard <[email protected]> | 2025-05-28 12:33:52 +0200 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2025-05-28 10:33:52 +0000 |
| commit | edda24eb851c2647f7dde01885008ef60fcadd9a (patch) | |
| tree | b49978ac3135b7de5346a93f43ff013898f3c365 /src/tests/dolphinmainwindowtest.cpp | |
| parent | 0959642be297bf0749467c204e511f5887b17ee1 (diff) | |
dolphinview: Add a dynamic view option
Added a 'dynamic view' option, which allows to switch from a 'compact' or 'details' view to an 'icons' view if most of the files in the directory are images or videos. It reverts to the previous view mode when we switch to a directory which doesn't meet that criteria.
The view mode is only changed once so users don't have to undo that for specific folders when they don't want icon view.
A setting is added in the "Display style" section of the general view setting page.
BUG: 491139
Diffstat (limited to 'src/tests/dolphinmainwindowtest.cpp')
| -rw-r--r-- | src/tests/dolphinmainwindowtest.cpp | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index b3e52ce23..345a56504 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -5,11 +5,11 @@ */ #include "dolphinmainwindow.h" +#include "dolphin_generalsettings.h" #include "dolphinnewfilemenu.h" #include "dolphintabpage.h" #include "dolphintabwidget.h" #include "dolphinviewcontainer.h" -#include "dolphin_generalsettings.h" #include "kitemviews/kfileitemmodel.h" #include "kitemviews/kfileitemmodelrolesupdater.h" #include "kitemviews/kitemlistcontainer.h" @@ -18,6 +18,7 @@ #include "kitemviews/kitemlistwidget.h" #include "testdir.h" #include "views/dolphinitemlistview.h" +#include "views/viewproperties.h" #include <KActionCollection> #include <KConfig> @@ -67,6 +68,7 @@ private Q_SLOTS: void testAutoSaveSession(); void testInlineRename(); void testThumbnailAfterRename(); + void testViewModeAfterDynamicView(); void cleanupTestCase(); private: @@ -1064,6 +1066,86 @@ void DolphinMainWindowTest::testThumbnailAfterRename() QCOMPARE(view->m_model->count(), 1); } +void DolphinMainWindowTest::testViewModeAfterDynamicView() +{ + GeneralSettings *settings = GeneralSettings::self(); + settings->setDynamicView(true); + settings->save(); + + // prepare test data + QScopedPointer<TestDir> testDir{new TestDir()}; + QString testDirUrl(QDir::cleanPath(testDir->url().toString())); + testDir->createDir("a"); + 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->url().path() + "/a/1.jpg"); + + // open test dir and set default view mode to "Details" + m_mainWindow->openDirectories({testDirUrl}, false); + DolphinView *view = m_mainWindow->activeViewContainer()->view(); + QSignalSpy viewDirectoryLoadingCompletedSpy(view, &DolphinView::directoryLoadingCompleted); + QSignalSpy modelDirectoryLoadingCompletedSpy(view->m_model, &KFileItemModel::directoryLoadingCompleted); + m_mainWindow->show(); + QVERIFY(viewDirectoryLoadingCompletedSpy.wait()); + QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); + QVERIFY(m_mainWindow->isVisible()); + m_mainWindow->actionCollection()->action(QStringLiteral("details"))->trigger(); + QCOMPARE(view->m_mode, DolphinView::DetailsView); + + // move to child folder and check that dynamic view changed view mode to icons + m_mainWindow->openFiles({testDirUrl + "/a"}, false); + view->m_model->loadDirectory(QUrl(testDirUrl + "/a")); + view->setUrl(QUrl(testDirUrl + "/a")); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + QCOMPARE(view->m_mode, DolphinView::IconsView); + + // go back to parent folder and check that view mode reverted to details + m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->trigger(); + view->m_model->loadDirectory(testDir->url()); + view->setUrl(testDir->url()); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + QCOMPARE(view->m_mode, DolphinView::DetailsView); + + // test for local views + settings->setGlobalViewProps(false); + settings->save(); + + // go to child folder and check DynamicViewPassed key in view properties as well as view mode + m_mainWindow->openFiles({testDirUrl + "/a"}, false); + view->m_model->loadDirectory(QUrl(testDirUrl + "/a")); + view->setUrl(QUrl(testDirUrl + "/a")); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + QCOMPARE(view->m_mode, DolphinView::IconsView); + QTest::qWait(100); + QVERIFY(ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); + + // change view mode of child folder to "Details" + m_mainWindow->actionCollection()->action(QStringLiteral("details"))->trigger(); + QCOMPARE(view->m_mode, DolphinView::DetailsView); + + // go back to parent folder + m_mainWindow->actionCollection()->action(KStandardAction::name(KStandardAction::Back))->trigger(); + view->m_model->loadDirectory(testDir->url()); + view->setUrl(testDir->url()); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + QCOMPARE(view->m_mode, DolphinView::DetailsView); + QVERIFY(!ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); + + // go to child folder and make sure view mode change to "Details" is permanent + m_mainWindow->openFiles({testDirUrl + "/a"}, false); + view->m_model->loadDirectory(QUrl(testDirUrl + "/a")); + view->setUrl(QUrl(testDirUrl + "/a")); + QVERIFY(modelDirectoryLoadingCompletedSpy.wait()); + QCOMPARE(view->m_mode, DolphinView::DetailsView); + QVERIFY(ViewProperties(view->viewPropertiesUrl()).dynamicViewPassed()); +} + void DolphinMainWindowTest::cleanupTestCase() { m_mainWindow->showNormal(); |
