diff options
| author | Peter Penz <[email protected]> | 2011-01-09 13:58:35 +0000 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-01-09 13:58:35 +0000 |
| commit | fae8ba471b0adb917f4edd1a99bca47fdaea0169 (patch) | |
| tree | f7aaa90e0d4414867adb82781088b48242a0b969 /src/views | |
| parent | 58ea012256a752fb803a462c0ff025a4de4b5dbf (diff) | |
Encapsulate the creation and handling of the directory lister, the model and proxy model to DolphinView. By this it will be easier later to replace the traditional QAbstractItemViews by any kind of other implementation (e.g. based on QGraphicsView/QML).
svn path=/trunk/KDE/kdebase/apps/; revision=1213189
Diffstat (limited to 'src/views')
| -rw-r--r-- | src/views/dolphinview.cpp | 75 | ||||
| -rw-r--r-- | src/views/dolphinview.h | 42 |
2 files changed, 90 insertions, 27 deletions
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 29f62f735..2dc21b335 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -49,6 +49,7 @@ #include <kurl.h> #include "additionalinfoaccessor.h" +#include "dolphindirlister.h" #include "dolphinmodel.h" #include "dolphincolumnviewcontainer.h" #include "dolphinviewcontroller.h" @@ -67,9 +68,7 @@ #include "zoomlevelinfo.h" #include "dolphindetailsviewexpander.h" -DolphinView::DolphinView(QWidget* parent, - const KUrl& url, - DolphinSortFilterProxyModel* proxyModel) : +DolphinView::DolphinView(const KUrl& url, QWidget* parent) : QWidget(parent), m_active(true), m_showPreview(false), @@ -83,7 +82,7 @@ DolphinView::DolphinView(QWidget* parent, m_topLayout(0), m_dolphinViewController(0), m_viewModeController(0), - m_viewAccessor(proxyModel), + m_viewAccessor(), m_selectionChangedTimer(0), m_activeItemUrl(), m_restoredContentsPosition(), @@ -277,6 +276,11 @@ bool DolphinView::supportsCategorizedSorting() const return m_viewAccessor.supportsCategorizedSorting(); } +KFileItem DolphinView::rootItem() const +{ + return m_viewAccessor.dirLister()->rootItem(); +} + KFileItemList DolphinView::items() const { return m_viewAccessor.dirLister()->items(); @@ -442,6 +446,11 @@ void DolphinView::setNameFilter(const QString& nameFilter) m_viewModeController->setNameFilter(nameFilter); } +QString DolphinView::nameFilter() const +{ + return m_viewModeController->nameFilter(); +} + void DolphinView::calculateItemCount(int& fileCount, int& folderCount, KIO::filesize_t& totalFileSize) const @@ -1326,15 +1335,21 @@ QItemSelection DolphinView::childrenMatchingPattern(const QModelIndex& parent, c void DolphinView::connectViewAccessor() { KDirLister* dirLister = m_viewAccessor.dirLister(); - connect(dirLister, SIGNAL(redirection(KUrl,KUrl)), - this, SLOT(slotRedirection(KUrl,KUrl))); - connect(dirLister, SIGNAL(started(KUrl)), - this, SLOT(slotDirListerStarted(KUrl))); - connect(dirLister, SIGNAL(completed()), - this, SLOT(slotDirListerCompleted())); + connect(dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(slotRedirection(KUrl,KUrl))); + connect(dirLister, SIGNAL(started(KUrl)), this, SLOT(slotDirListerStarted(KUrl))); + connect(dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted())); + connect(dirLister, SIGNAL(canceled()), this, SLOT(slotDirListerCompleted())); connect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)), this, SLOT(slotRefreshItems())); + connect(dirLister, SIGNAL(clear()), this, SIGNAL(itemCountChanged())); + connect(dirLister, SIGNAL(newItems(KFileItemList)), this, SIGNAL(itemCountChanged())); + connect(dirLister, SIGNAL(infoMessage(const QString&)), this, SIGNAL(infoMessage(const QString&))); + connect(dirLister, SIGNAL(errorMessage(const QString&)), this, SIGNAL(infoMessage(const QString&))); + connect(dirLister, SIGNAL(percent(int)), this, SIGNAL(pathLoadingProgress(int))); + connect(dirLister, SIGNAL(urlIsFileError(const KUrl&)), this, SIGNAL(urlIsFileError(const KUrl&))); + connect(dirLister, SIGNAL(itemsDeleted(const KFileItemList&)), this, SIGNAL(itemCountChanged())); + QAbstractItemView* view = m_viewAccessor.itemView(); connect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection))); @@ -1343,15 +1358,21 @@ void DolphinView::connectViewAccessor() void DolphinView::disconnectViewAccessor() { KDirLister* dirLister = m_viewAccessor.dirLister(); - disconnect(dirLister, SIGNAL(redirection(KUrl,KUrl)), - this, SLOT(slotRedirection(KUrl,KUrl))); - disconnect(dirLister, SIGNAL(started(KUrl)), - this, SLOT(slotDirListerStarted(KUrl))); - disconnect(dirLister, SIGNAL(completed()), - this, SLOT(slotDirListerCompleted())); + disconnect(dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(slotRedirection(KUrl,KUrl))); + disconnect(dirLister, SIGNAL(started(KUrl)), this, SLOT(slotDirListerStarted(KUrl))); + disconnect(dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted())); + disconnect(dirLister, SIGNAL(canceled()), this, SLOT(slotDirListerCompleted())); disconnect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)), this, SLOT(slotRefreshItems())); + disconnect(dirLister, SIGNAL(clear()), this, SIGNAL(itemCountChanged())); + disconnect(dirLister, SIGNAL(newItems(KFileItemList)), this, SIGNAL(itemCountChanged())); + disconnect(dirLister, SIGNAL(infoMessage(const QString&)), this, SIGNAL(infoMessage(const QString&))); + disconnect(dirLister, SIGNAL(errorMessage(const QString&)), this, SIGNAL(errorMessage(const QString&))); + disconnect(dirLister, SIGNAL(percent(int)), this, SIGNAL(pathLoadingProgress(int))); + disconnect(dirLister, SIGNAL(urlIsFileError(const KUrl&)), this, SIGNAL(urlIsFileError(const KUrl&))); + disconnect(dirLister, SIGNAL(itemsDeleted(const KFileItemList&)), this, SIGNAL(itemCountChanged())); + QAbstractItemView* view = m_viewAccessor.itemView(); disconnect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(slotSelectionChanged(QItemSelection, QItemSelection))); @@ -1372,18 +1393,36 @@ void DolphinView::updateWritableState() } } -DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel* proxyModel) : +DolphinView::ViewAccessor::ViewAccessor() : m_rootUrl(), m_iconsView(0), m_detailsView(0), m_columnsContainer(0), - m_proxyModel(proxyModel), + m_dolphinModel(0), + m_proxyModel(0), m_dragSource(0) { + DolphinDirLister* dirLister = new DolphinDirLister(); + dirLister->setAutoUpdate(true); + dirLister->setDelayedMimeTypes(true); + + m_dolphinModel = new DolphinModel(); + m_dolphinModel->setDirLister(dirLister); // m_dolphinModel takes ownership of dirLister + m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory); + + m_proxyModel = new DolphinSortFilterProxyModel(); + m_proxyModel->setSourceModel(m_dolphinModel); + m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); } DolphinView::ViewAccessor::~ViewAccessor() { + delete m_proxyModel; + m_proxyModel = 0; + + delete m_dolphinModel; + m_dolphinModel = 0; + delete m_dragSource; m_dragSource = 0; } diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index 91909710f..04b821e71 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -119,15 +119,10 @@ public: }; /** - * @param parent Parent widget of the view. * @param url Specifies the content which should be shown. - * @param proxyModel Used proxy model which specifies the sorting. The - * model is not owned by the view and won't get - * deleted. + * @param parent Parent widget of the view. */ - DolphinView(QWidget* parent, - const KUrl& url, - DolphinSortFilterProxyModel* proxyModel); + DolphinView( const KUrl& url, QWidget* parent); virtual ~DolphinView(); @@ -182,6 +177,13 @@ public: bool supportsCategorizedSorting() const; /** + * Returns the root item which represents the current URL. Note that the returned + * item can be null (KFileItem::isNull() will return true) in case that the directory + * has not been loaded. + */ + KFileItem rootItem() const; + + /** * Returns the items of the view. */ KFileItemList items() const; @@ -189,7 +191,6 @@ public: /** * Returns the selected items. The list is empty if no item has been * selected. - * @see DolphinView::selectedUrls() */ KFileItemList selectedItems() const; @@ -274,6 +275,7 @@ public: * which contain the given filter string will be shown. */ void setNameFilter(const QString& nameFilter); + QString nameFilter() const; /** * Calculates the number of currently shown files into @@ -436,6 +438,11 @@ signals: void itemTriggered(const KFileItem& item); /** + * Is emitted if items have been added or deleted. + */ + void itemCountChanged(); + + /** * Is emitted if a new tab should be opened for the URL \a url. */ void tabRequested(const KUrl& url); @@ -524,6 +531,18 @@ signals: void finishedPathLoading(const KUrl& url); /** + * Is emitted after DolphinView::setUrl() has been invoked and provides + * the information how much percent of the current path have been loaded. + */ + void pathLoadingProgress(int percent); + + /** + * Is emitted if the DolphinView::setUrl() is invoked but the URL is not + * a directory. + */ + void urlIsFileError(const KUrl& file); + + /** * Emitted when KDirLister emits redirection. * Testcase: fish://localhost */ @@ -756,7 +775,7 @@ private: class ViewAccessor { public: - ViewAccessor(DolphinSortFilterProxyModel* proxyModel); + ViewAccessor(); ~ViewAccessor(); void createView(QWidget* parent, @@ -805,9 +824,13 @@ private: DolphinIconsView* m_iconsView; DolphinDetailsView* m_detailsView; DolphinColumnViewContainer* m_columnsContainer; + DolphinModel* m_dolphinModel; DolphinSortFilterProxyModel* m_proxyModel; QAbstractItemView* m_dragSource; QPointer<DolphinDetailsViewExpander> m_detailsViewExpander; + + // For unit tests + friend class DolphinDetailsViewTest; }; bool m_active : 1; @@ -843,6 +866,7 @@ private: // For unit tests friend class TestBase; + friend class DolphinDetailsViewTest; }; /// Allow using DolphinView::Mode in QVariant |
