]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix PlacesItemModel loading with hidden devices
authorRenato Araujo Oliveira Filho <renato.araujo@kdab.com>
Wed, 20 Dec 2017 18:26:35 +0000 (15:26 -0300)
committerRenato Araujo Oliveira Filho <renato.araujo@kdab.com>
Mon, 8 Jan 2018 11:52:38 +0000 (08:52 -0300)
Summary:
Make sure that hidden devices loaded after module initialization does
not appear in the view.
Check for item visibility before add it on the model.

Test Plan: Unit test created

Reviewers: franckarrecot

Reviewed By: franckarrecot

Subscribers: cfeck, ervin, #dolphin

Differential Revision: https://phabricator.kde.org/D9441

src/panels/places/placesitemmodel.cpp
src/tests/placesitemmodeltest.cpp

index 577596c7422beb7807ce13404dbdf4db98c71c8a..b23877629a938b9bd9f3d1071a26bbc05723acec 100644 (file)
@@ -392,6 +392,10 @@ void PlacesItemModel::dropMimeDataBefore(int index, const QMimeData* mimeData)
 
 void PlacesItemModel::addItemFromSourceModel(const QModelIndex &index)
 {
+    if (!m_hiddenItemsShown && m_sourceModel->isHidden(index)) {
+        return;
+    }
+
     const KBookmark bookmark = m_sourceModel->bookmarkForIndex(index);
     Q_ASSERT(!bookmark.isNull());
     PlacesItem *item = new PlacesItem(bookmark);
index 7c4cf308ba6a637cffed3a24388d692cb3e2eb0d..ef24292ed42ea2137306397c512cc37058bf9256 100644 (file)
@@ -82,6 +82,7 @@ private slots:
     void testIcons_data();
     void testIcons();
     void testDragAndDrop();
+    void testHideDevices();
 
 private:
     PlacesItemModel* m_model;
@@ -758,6 +759,29 @@ void PlacesItemModelTest::testDragAndDrop()
     CHECK_PLACES_URLS(urls);
 }
 
+void PlacesItemModelTest::testHideDevices()
+{
+    QSignalSpy itemsRemoved(m_model, &PlacesItemModel::itemsRemoved);
+    QStringList urls = initialUrls();
+
+    m_model->setGroupHidden(KFilePlacesModel::RemovableDevicesType, true);
+    QTRY_VERIFY(m_model->isGroupHidden(KFilePlacesModel::RemovableDevicesType));
+    QTRY_COMPARE(itemsRemoved.count(), 3);
+
+    // remove removable-devices
+    urls.removeOne(QStringLiteral("/media/floppy0"));
+    urls.removeOne(QStringLiteral("/media/XO-Y4"));
+    urls.removeOne(QStringLiteral("/media/cdrom"));
+
+    // check if the correct urls was removed
+    CHECK_PLACES_URLS(urls);
+
+    delete m_model;
+    m_model = new PlacesItemModel();
+    QTRY_COMPARE(m_model->count(), urls.count());
+    CHECK_PLACES_URLS(urls);
+}
+
 QTEST_MAIN(PlacesItemModelTest)
 
 #include "placesitemmodeltest.moc"