+DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel* proxyModel) :
+ m_iconsView(0),
+ m_detailsView(0),
+ m_columnsContainer(0),
+ m_proxyModel(proxyModel),
+ m_dragSource(0)
+{
+}
+
+DolphinView::ViewAccessor::~ViewAccessor()
+{
+ delete m_dragSource;
+ m_dragSource = 0;
+}
+
+void DolphinView::ViewAccessor::createView(QWidget* parent,
+ DolphinViewController* dolphinViewController,
+ const ViewModeController* viewModeController,
+ Mode mode)
+{
+ Q_ASSERT(itemView() == 0);
+
+ switch (mode) {
+ case IconsView:
+ m_iconsView = new DolphinIconsView(parent,
+ dolphinViewController,
+ viewModeController,
+ m_proxyModel);
+ break;
+
+ case DetailsView:
+ m_detailsView = new DolphinDetailsView(parent,
+ dolphinViewController,
+ viewModeController,
+ m_proxyModel);
+ break;
+
+ case ColumnView:
+ m_columnsContainer = new DolphinColumnViewContainer(parent,
+ dolphinViewController,
+ viewModeController);
+ break;
+
+ default:
+ Q_ASSERT(false);
+ }
+}
+
+void DolphinView::ViewAccessor::deleteView()
+{
+ QAbstractItemView* view = itemView();
+ if (view != 0) {
+ if (DragAndDropHelper::instance().isDragSource(view)) {
+ // The view is a drag source (the feature "Open folders
+ // during drag operations" is used). Deleting the view
+ // during an ongoing drag operation is not allowed, so
+ // this will postponed.
+ if (m_dragSource != 0) {
+ // the old stored view is obviously not the drag source anymore
+ m_dragSource->deleteLater();
+ m_dragSource = 0;
+ }
+ view->hide();
+ m_dragSource = view;
+ } else {
+ view->deleteLater();
+ }
+ }
+
+ m_iconsView = 0;
+ m_detailsView = 0;
+
+ if (m_columnsContainer != 0) {
+ m_columnsContainer->deleteLater();
+ }
+ m_columnsContainer = 0;
+}
+
+
+void DolphinView::ViewAccessor::prepareUrlChange(const KUrl& url)
+{
+ if (m_columnsContainer != 0) {
+ m_columnsContainer->showColumn(url);
+ }
+}
+
+QAbstractItemView* DolphinView::ViewAccessor::itemView() const
+{
+ if (m_iconsView != 0) {
+ return m_iconsView;
+ }
+
+ if (m_detailsView != 0) {
+ return m_detailsView;
+ }
+
+ if (m_columnsContainer != 0) {
+ return m_columnsContainer->activeColumn();
+ }
+
+ return 0;
+}
+
+KFileItemDelegate* DolphinView::ViewAccessor::itemDelegate() const
+{
+ return static_cast<KFileItemDelegate*>(itemView()->itemDelegate());
+}
+
+QWidget* DolphinView::ViewAccessor::layoutTarget() const
+{
+ if (m_columnsContainer != 0) {
+ return m_columnsContainer;
+ }
+ return itemView();
+}
+
+KUrl DolphinView::ViewAccessor::rootUrl() const
+{
+ return (m_columnsContainer != 0) ? m_columnsContainer->rootUrl() : KUrl();
+}
+
+bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
+{
+ return m_iconsView != 0;
+}
+
+bool DolphinView::ViewAccessor::itemsExpandable() const
+{
+ return (m_detailsView != 0) && m_detailsView->itemsExpandable();
+}
+
+
+QSet<KUrl> DolphinView::ViewAccessor::expandedUrls() const
+{
+ if (m_detailsView != 0) {
+ return m_detailsView->expandedUrls();
+ }
+
+ return QSet<KUrl>();
+}
+
+const DolphinDetailsViewExpander* DolphinView::ViewAccessor::setExpandedUrls(const QSet<KUrl>& urlsToExpand)
+{
+ if ((m_detailsView != 0) && m_detailsView->itemsExpandable() && !urlsToExpand.isEmpty()) {
+ // Check if another expander is already active and stop it if necessary.
+ if(!m_detailsViewExpander.isNull()) {
+ m_detailsViewExpander->stop();
+ }
+
+ m_detailsViewExpander = new DolphinDetailsViewExpander(m_detailsView, urlsToExpand);
+ return m_detailsViewExpander;
+ }
+ else {
+ return 0;
+ }
+}
+
+bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const
+{
+ // the details view requires no reloading of the directory, as it maps
+ // the file item delegate info to its columns internally
+ return m_detailsView != 0;
+}
+
+DolphinModel* DolphinView::ViewAccessor::dirModel() const
+{
+ return static_cast<DolphinModel*>(proxyModel()->sourceModel());
+}
+
+DolphinSortFilterProxyModel* DolphinView::ViewAccessor::proxyModel() const
+{
+ if (m_columnsContainer != 0) {
+ return static_cast<DolphinSortFilterProxyModel*>(m_columnsContainer->activeColumn()->model());
+ }
+ return m_proxyModel;
+}
+
+KDirLister* DolphinView::ViewAccessor::dirLister() const
+{
+ return dirModel()->dirLister();
+}
+
+void DolphinView::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
+{
+ if (oldUrl.equals(url(), KUrl::CompareWithoutTrailingSlash)) {
+ emit redirection(oldUrl, newUrl);
+ m_controller->redirectToUrl(newUrl); // #186947
+ }
+}
+
+void DolphinView::restoreContentsPosition()
+{
+ if (!m_restoredContentsPosition.isNull()) {
+ const int x = m_restoredContentsPosition.x();
+ const int y = m_restoredContentsPosition.y();
+ m_restoredContentsPosition = QPoint();
+
+ QAbstractItemView* view = m_viewAccessor.itemView();
+ Q_ASSERT(view != 0);
+ view->horizontalScrollBar()->setValue(x);
+ view->verticalScrollBar()->setValue(y);
+ }
+}
+