diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index c0adce9860..8eb47f5ec7 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -165,6 +165,24 @@ bool KFileItemModel::sortFoldersFirst() const return m_sortFoldersFirst; } +void KFileItemModel::setShowHiddenFiles(bool show) +{ + KDirLister* dirLister = m_dirLister.data(); + if (dirLister) { + dirLister->setShowingDotFiles(show); + dirLister->emitChanges(); + if (show) { + slotCompleted(); + } + } +} + +bool KFileItemModel::showHiddenFiles() const +{ + const KDirLister* dirLister = m_dirLister.data(); + return dirLister ? dirLister->showingDotFiles() : false; +} + QMimeData* KFileItemModel::createMimeData(const QSet& indexes) const { QMimeData* data = new QMimeData(); diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index 5d0aa4203f..36ed37ba67 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -41,6 +41,15 @@ class QTimer; * * Also the recursive expansion of sub-directories is supported by * KFileItemModel::setExpanded(). + * + * TODO: In the longterm instead of passing a KDirLister just an URL should + * be passed and a KDirLister used internally. This solves the following issues: + * - The user of the API does not need to decide whether he listens to KDirLister + * or KFileItemModel. + * - It resolves minor conceptual differences between KDirLister and KFileItemModel. + * E.g. there is no way for KFileItemModel to check whether a completed() signal + * will be emitted after newItems() will be send by KDirLister or not (in the case + * of setShowingDotFiles() no completed() signal will get emitted). */ class LIBDOLPHINPRIVATE_EXPORT KFileItemModel : public KItemModelBase { @@ -60,6 +69,9 @@ public: void setSortFoldersFirst(bool foldersFirst); bool sortFoldersFirst() const; + void setShowHiddenFiles(bool show); + bool showHiddenFiles() const; + /** @reimp */ virtual QMimeData* createMimeData(const QSet& indexes) const; @@ -138,6 +150,13 @@ public: QString nameFilter() const; signals: + /** + * Is emitted after the loading of a directory has been completed or new + * items have been inserted to an already loaded directory. Usually + * one or more itemsInserted() signals are emitted before loadingCompleted() + * (the only exception is loading an empty directory, where only a + * loadingCompleted() signal gets emitted). + */ void loadingCompleted(); protected: diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index 598d3054a3..275cd7772f 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -76,8 +76,7 @@ void FoldersPanel::setHiddenFilesShown(bool show) if (m_dirLister) { KFileItemModel* model = fileItemModel(); const QSet expandedUrls = model->expandedUrls(); - m_dirLister->setShowingDotFiles(show); - m_dirLister->openUrl(m_dirLister->url(), KDirLister::Reload); + model->setShowHiddenFiles(show); model->setExpanded(expandedUrls); } } @@ -146,7 +145,6 @@ void FoldersPanel::showEvent(QShowEvent* event) m_dirLister->setMainWindow(window()); m_dirLister->setDelayedMimeTypes(true); m_dirLister->setAutoErrorHandlingEnabled(false, this); - m_dirLister->setShowingDotFiles(FoldersPanelSettings::hiddenFilesShown()); KFileItemListView* view = new KFileItemListView(); view->setWidgetCreator(new KItemListWidgetCreator()); @@ -165,6 +163,7 @@ void FoldersPanel::showEvent(QShowEvent* event) view->setOpacity(0); KFileItemModel* model = new KFileItemModel(m_dirLister, this); + model->setShowHiddenFiles(FoldersPanelSettings::hiddenFilesShown()); // Use a QueuedConnection to give the view the possibility to react first on the // finished loading. connect(model, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()), Qt::QueuedConnection); diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 8730746534..fdca4cf866 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -262,8 +262,7 @@ void DolphinView::setHiddenFilesShown(bool show) ViewProperties props(url()); props.setHiddenFilesShown(show); - m_dirLister->setShowingDotFiles(show); - m_dirLister->emitChanges(); + fileItemModel()->setShowHiddenFiles(show); emit hiddenFilesShownChanged(show); } @@ -1170,9 +1169,8 @@ void DolphinView::applyViewProperties() } const bool hiddenFilesShown = props.hiddenFilesShown(); - if (hiddenFilesShown != m_dirLister->showingDotFiles()) { - m_dirLister->setShowingDotFiles(hiddenFilesShown); - m_dirLister->emitChanges(); + if (hiddenFilesShown != model->showHiddenFiles()) { + model->setShowHiddenFiles(hiddenFilesShown); emit hiddenFilesShownChanged(hiddenFilesShown); }