1 /***************************************************************************
2 * Copyright (C) 2006-2009 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphinview.h"
23 #include <QAbstractItemView>
24 #include <QApplication>
27 #include <QItemSelection>
32 #include <kactioncollection.h>
33 #include <kcolorscheme.h>
34 #include <kdirlister.h>
35 #include <kiconeffect.h>
36 #include <kfileitem.h>
38 #include <kio/deletejob.h>
39 #include <kio/netaccess.h>
40 #include <kio/previewjob.h>
43 #include <kmessagebox.h>
44 #include <kmimetyperesolver.h>
45 #include <konq_fileitemcapabilities.h>
46 #include <konq_operations.h>
47 #include <konqmimedata.h>
48 #include <kstringhandler.h>
49 #include <ktoggleaction.h>
52 #include "dolphinmodel.h"
53 #include "dolphincolumnviewcontainer.h"
54 #include "dolphincontroller.h"
55 #include "dolphindetailsview.h"
56 #include "dolphinfileitemdelegate.h"
57 #include "dolphinnewmenuobserver.h"
58 #include "dolphinsortfilterproxymodel.h"
59 #include "dolphin_detailsmodesettings.h"
60 #include "dolphiniconsview.h"
61 #include "dolphin_generalsettings.h"
62 #include "draganddrophelper.h"
63 #include "renamedialog.h"
64 #include "settings/dolphinsettings.h"
65 #include "viewproperties.h"
66 #include "zoomlevelinfo.h"
67 #include "dolphindetailsviewexpander.h"
70 * Helper function for sorting items with qSort() in
71 * DolphinView::renameSelectedItems().
73 bool lessThan(const KFileItem
& item1
, const KFileItem
& item2
)
75 return KStringHandler::naturalCompare(item1
.name(), item2
.name()) < 0;
78 DolphinView::DolphinView(QWidget
* parent
,
80 DolphinSortFilterProxyModel
* proxyModel
) :
84 m_loadingDirectory(false),
85 m_storedCategorizedSorting(false),
86 m_tabsForFiles(false),
87 m_isContextMenuOpen(false),
88 m_ignoreViewProperties(false),
89 m_assureVisibleCurrentIndex(false),
90 m_mode(DolphinView::IconsView
),
93 m_viewAccessor(proxyModel
),
95 m_selectionChangedTimer(0),
98 m_restoredContentsPosition(),
103 m_topLayout
= new QVBoxLayout(this);
104 m_topLayout
->setSpacing(0);
105 m_topLayout
->setMargin(0);
107 m_controller
= new DolphinController(this);
108 m_controller
->setUrl(url
);
110 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
111 this, SIGNAL(urlChanged(const KUrl
&)));
112 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
113 this, SLOT(slotRequestUrlChange(const KUrl
&)));
115 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&, const QList
<QAction
*>&)),
116 this, SLOT(openContextMenu(const QPoint
&, const QList
<QAction
*>&)));
117 connect(m_controller
, SIGNAL(urlsDropped(const KFileItem
&, const KUrl
&, QDropEvent
*)),
118 this, SLOT(dropUrls(const KFileItem
&, const KUrl
&, QDropEvent
*)));
119 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
120 this, SLOT(updateSorting(DolphinView::Sorting
)));
121 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
122 this, SLOT(updateSortOrder(Qt::SortOrder
)));
123 connect(m_controller
, SIGNAL(sortFoldersFirstChanged(bool)),
124 this, SLOT(updateSortFoldersFirst(bool)));
125 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
126 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
127 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
128 this, SLOT(triggerItem(const KFileItem
&)));
129 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
130 this, SIGNAL(tabRequested(const KUrl
&)));
131 connect(m_controller
, SIGNAL(activated()),
132 this, SLOT(activate()));
133 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
134 this, SLOT(showHoverInformation(const KFileItem
&)));
135 connect(m_controller
, SIGNAL(viewportEntered()),
136 this, SLOT(clearHoverInformation()));
138 KDirLister
* dirLister
= m_viewAccessor
.dirLister();
139 connect(dirLister
, SIGNAL(redirection(KUrl
,KUrl
)),
140 this, SLOT(slotRedirection(KUrl
,KUrl
)));
141 connect(dirLister
, SIGNAL(completed()),
142 this, SLOT(slotDirListerCompleted()));
143 connect(dirLister
, SIGNAL(refreshItems(const QList
<QPair
<KFileItem
,KFileItem
>>&)),
144 this, SLOT(slotRefreshItems()));
146 // When a new item has been created by the "Create New..." menu, the item should
147 // get selected and it must be assured that the item will get visible. As the
148 // creation is done asynchronously, several signals must be checked:
149 connect(&DolphinNewMenuObserver::instance(), SIGNAL(itemCreated(const KUrl
&)),
150 this, SLOT(observeCreatedItem(const KUrl
&)));
152 m_selectionChangedTimer
= new QTimer(this);
153 m_selectionChangedTimer
->setSingleShot(true);
154 m_selectionChangedTimer
->setInterval(300);
155 connect(m_selectionChangedTimer
, SIGNAL(timeout()),
156 this, SLOT(emitSelectionChangedSignal()));
158 applyViewProperties();
159 m_topLayout
->addWidget(m_viewAccessor
.layoutTarget());
162 DolphinView::~DolphinView()
166 const KUrl
& DolphinView::url() const
168 return m_controller
->url();
171 KUrl
DolphinView::rootUrl() const
173 const KUrl viewUrl
= url();
174 const KUrl root
= m_viewAccessor
.rootUrl();
175 if (root
.isEmpty() || !root
.isParentOf(viewUrl
)) {
181 void DolphinView::setActive(bool active
)
183 if (active
== m_active
) {
189 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
191 emitSelectionChangedSignal();
196 QWidget
* viewport
= m_viewAccessor
.itemView()->viewport();
198 palette
.setColor(viewport
->backgroundRole(), color
);
199 viewport
->setPalette(palette
);
204 m_viewAccessor
.itemView()->setFocus();
208 m_controller
->indicateActivationChange(active
);
211 bool DolphinView::isActive() const
216 void DolphinView::setMode(Mode mode
)
218 if (mode
== m_mode
) {
219 return; // the wished mode is already set
222 const int oldZoomLevel
= m_controller
->zoomLevel();
225 // remember the currently selected items, so that they will
226 // be restored after reloading the directory
227 m_selectedItems
= selectedItems();
231 const KUrl viewPropsUrl
= rootUrl();
232 ViewProperties
props(viewPropsUrl
);
233 props
.setViewMode(m_mode
);
236 // the file item delegate has been recreated, apply the current
237 // additional information manually
238 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
239 m_viewAccessor
.itemDelegate()->setShowInformation(infoList
);
240 emit
additionalInfoChanged();
242 // Not all view modes support categorized sorting. Adjust the sorting model
243 // if changing the view mode results in a change of the categorized sorting
245 m_storedCategorizedSorting
= props
.categorizedSorting();
246 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
247 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
248 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
249 emit
categorizedSortingChanged();
254 updateZoomLevel(oldZoomLevel
);
255 loadDirectory(viewPropsUrl
);
258 DolphinView::Mode
DolphinView::mode() const
263 bool DolphinView::showPreview() const
265 return m_showPreview
;
268 bool DolphinView::showHiddenFiles() const
270 return m_viewAccessor
.dirLister()->showingDotFiles();
273 bool DolphinView::categorizedSorting() const
275 // If all view modes would support categorized sorting, returning
276 // m_viewAccessor.proxyModel()->isCategorizedModel() would be the way to go. As
277 // currently only the icons view supports caterized sorting, we remember
278 // the stored view properties state in m_storedCategorizedSorting and
279 // return this state. The application takes care to disable the corresponding
280 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
281 // that this setting is not applied to the current view mode.
282 return m_storedCategorizedSorting
;
285 bool DolphinView::supportsCategorizedSorting() const
287 return m_viewAccessor
.supportsCategorizedSorting();
290 bool DolphinView::hasSelection() const
292 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
293 return (view
!= 0) && view
->selectionModel()->hasSelection();
296 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
298 foreach (const KUrl
& url
, urls
) {
299 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url
);
300 m_selectedItems
.append(item
);
304 KFileItemList
DolphinView::selectedItems() const
306 KFileItemList itemList
;
307 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
312 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
314 const QModelIndexList indexList
= selection
.indexes();
315 foreach (const QModelIndex
&index
, indexList
) {
316 KFileItem item
= m_viewAccessor
.dirModel()->itemForIndex(index
);
317 if (!item
.isNull()) {
318 itemList
.append(item
);
325 KUrl::List
DolphinView::selectedUrls() const
328 const KFileItemList list
= selectedItems();
329 foreach (const KFileItem
&item
, list
) {
330 urls
.append(item
.url());
335 int DolphinView::selectedItemsCount() const
337 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
342 return view
->selectionModel()->selectedIndexes().count();
345 QItemSelectionModel
* DolphinView::selectionModel() const
347 return m_viewAccessor
.itemView()->selectionModel();
350 void DolphinView::setZoomLevel(int level
)
352 if (level
< ZoomLevelInfo::minimumLevel()) {
353 level
= ZoomLevelInfo::minimumLevel();
354 } else if (level
> ZoomLevelInfo::maximumLevel()) {
355 level
= ZoomLevelInfo::maximumLevel();
358 if (level
!= zoomLevel()) {
359 m_controller
->setZoomLevel(level
);
360 emit
zoomLevelChanged(level
);
364 int DolphinView::zoomLevel() const
366 return m_controller
->zoomLevel();
369 void DolphinView::setSorting(Sorting sorting
)
371 if (sorting
!= this->sorting()) {
372 updateSorting(sorting
);
376 DolphinView::Sorting
DolphinView::sorting() const
378 return m_viewAccessor
.proxyModel()->sorting();
381 void DolphinView::setSortOrder(Qt::SortOrder order
)
383 if (sortOrder() != order
) {
384 updateSortOrder(order
);
388 Qt::SortOrder
DolphinView::sortOrder() const
390 return m_viewAccessor
.proxyModel()->sortOrder();
393 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
395 if (sortFoldersFirst() != foldersFirst
) {
396 updateSortFoldersFirst(foldersFirst
);
400 bool DolphinView::sortFoldersFirst() const
402 return m_viewAccessor
.proxyModel()->sortFoldersFirst();
405 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
407 const KUrl viewPropsUrl
= rootUrl();
408 ViewProperties
props(viewPropsUrl
);
409 props
.setAdditionalInfo(info
);
410 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
412 emit
additionalInfoChanged();
414 if (m_viewAccessor
.reloadOnAdditionalInfoChange()) {
415 loadDirectory(viewPropsUrl
);
419 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
421 return m_viewAccessor
.itemDelegate()->showInformation();
424 void DolphinView::reload()
426 QByteArray viewState
;
427 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
428 saveState(saveStream
);
429 m_selectedItems
= selectedItems();
432 loadDirectory(url(), true);
434 QDataStream
restoreStream(viewState
);
435 restoreState(restoreStream
);
438 void DolphinView::refresh()
440 m_ignoreViewProperties
= false;
442 const bool oldActivationState
= m_active
;
443 const int oldZoomLevel
= m_controller
->zoomLevel();
447 applyViewProperties();
450 setActive(oldActivationState
);
451 updateZoomLevel(oldZoomLevel
);
454 void DolphinView::setNameFilter(const QString
& nameFilter
)
456 m_controller
->setNameFilter(nameFilter
);
459 void DolphinView::calculateItemCount(int& fileCount
,
461 KIO::filesize_t
& totalFileSize
) const
463 foreach (const KFileItem
& item
, m_viewAccessor
.dirLister()->items()) {
468 totalFileSize
+= item
.size();
473 QString
DolphinView::statusBarText() const
478 KIO::filesize_t totalFileSize
= 0;
480 if (hasSelection()) {
481 // give a summary of the status of the selected files
482 const KFileItemList list
= selectedItems();
483 if (list
.isEmpty()) {
484 // when an item is triggered, it is temporary selected but selectedItems()
485 // will return an empty list
489 KFileItemList::const_iterator it
= list
.begin();
490 const KFileItemList::const_iterator end
= list
.end();
492 const KFileItem
& item
= *it
;
497 totalFileSize
+= item
.size();
502 if (folderCount
+ fileCount
== 1) {
503 // if only one item is selected, show the filename
504 const QString name
= list
.first().text();
505 text
= (folderCount
== 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name
) :
506 i18nc("@info:status", "<filename>%1</filename> selected (%2)",
507 name
, KIO::convertSize(totalFileSize
));
509 // at least 2 items are selected
510 const QString foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
511 const QString filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
512 if ((folderCount
> 0) && (fileCount
> 0)) {
513 text
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
514 foldersText
, filesText
, KIO::convertSize(totalFileSize
));
515 } else if (fileCount
> 0) {
516 text
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KIO::convertSize(totalFileSize
));
518 Q_ASSERT(folderCount
> 0);
523 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
524 text
= KIO::itemsSummaryString(fileCount
+ folderCount
,
525 fileCount
, folderCount
,
526 totalFileSize
, true);
532 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
534 return m_controller
->versionControlActions(items
);
537 void DolphinView::setUrl(const KUrl
& url
)
539 if (m_controller
->url() == url
) {
543 m_newFileNames
.clear();
545 m_controller
->setUrl(url
); // emits urlChanged, which we forward
546 m_viewAccessor
.prepareUrlChange(url
);
547 applyViewProperties();
550 // When changing the URL there is no need to keep the version
551 // data of the previous URL.
552 m_viewAccessor
.dirModel()->clearVersionData();
554 emit
startedPathLoading(url
);
557 void DolphinView::selectAll()
559 m_viewAccessor
.itemView()->selectAll();
562 void DolphinView::invertSelection()
564 QItemSelectionModel
* selectionModel
= m_viewAccessor
.itemView()->selectionModel();
565 const QAbstractItemModel
* itemModel
= selectionModel
->model();
567 const QModelIndex topLeft
= itemModel
->index(0, 0);
568 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
569 itemModel
->columnCount() - 1);
571 const QItemSelection
selection(topLeft
, bottomRight
);
572 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
575 void DolphinView::clearSelection()
577 m_viewAccessor
.itemView()->clearSelection();
580 void DolphinView::renameSelectedItems()
582 KFileItemList items
= selectedItems();
583 const int itemCount
= items
.count();
589 // More than one item has been selected for renaming. Open
590 // a rename dialog and rename all items afterwards.
591 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
592 if (dialog
->exec() == QDialog::Rejected
) {
597 const QString newName
= dialog
->newName();
598 if (newName
.isEmpty()) {
599 emit
errorMessage(dialog
->errorString());
605 // the selection would be invalid after renaming the items, so just clear
609 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
610 // as one operation instead of n rename operations like it is done now...
611 Q_ASSERT(newName
.contains('#'));
613 // currently the items are sorted by the selection order, resort
614 // them by the file name
615 qSort(items
.begin(), items
.end(), lessThan
);
617 // iterate through all selected items and rename them...
619 foreach (const KFileItem
& item
, items
) {
620 const KUrl
& oldUrl
= item
.url();
622 number
.setNum(index
++);
624 QString name
= newName
;
625 name
.replace('#', number
);
627 if (oldUrl
.fileName() != name
) {
628 KUrl newUrl
= oldUrl
;
629 newUrl
.setFileName(name
);
630 KonqOperations::rename(this, oldUrl
, newUrl
);
633 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
634 Q_ASSERT(itemCount
== 1);
635 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForItem(items
.first());
636 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
637 m_viewAccessor
.itemView()->edit(proxyIndex
);
639 Q_ASSERT(itemCount
== 1);
641 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
642 if (dialog
->exec() == QDialog::Rejected
) {
647 const QString newName
= dialog
->newName();
648 if (newName
.isEmpty()) {
649 emit
errorMessage(dialog
->errorString());
655 const KUrl
& oldUrl
= items
.first().url();
656 KUrl newUrl
= oldUrl
;
657 newUrl
.setFileName(newName
);
658 KonqOperations::rename(this, oldUrl
, newUrl
);
661 // assure that the current index remains visible when KDirLister
662 // will notify the view about changed items
663 m_assureVisibleCurrentIndex
= true;
666 void DolphinView::trashSelectedItems()
668 const KUrl::List list
= simplifiedSelectedUrls();
669 KonqOperations::del(this, KonqOperations::TRASH
, list
);
672 void DolphinView::deleteSelectedItems()
674 const KUrl::List list
= simplifiedSelectedUrls();
675 const bool del
= KonqOperations::askDeleteConfirmation(list
,
677 KonqOperations::DEFAULT_CONFIRMATION
,
681 KIO::Job
* job
= KIO::del(list
);
682 connect(job
, SIGNAL(result(KJob
*)),
683 this, SLOT(slotDeleteFileFinished(KJob
*)));
687 void DolphinView::cutSelectedItems()
689 QMimeData
* mimeData
= selectionMimeData();
690 KonqMimeData::addIsCutSelection(mimeData
, true);
691 QApplication::clipboard()->setMimeData(mimeData
);
694 void DolphinView::copySelectedItems()
696 QMimeData
* mimeData
= selectionMimeData();
697 QApplication::clipboard()->setMimeData(mimeData
);
700 void DolphinView::paste()
705 void DolphinView::pasteIntoFolder()
707 const KFileItemList items
= selectedItems();
708 if ((items
.count() == 1) && items
.first().isDir()) {
709 pasteToUrl(items
.first().url());
713 void DolphinView::setShowPreview(bool show
)
715 if (m_showPreview
== show
) {
719 const KUrl viewPropsUrl
= rootUrl();
720 ViewProperties
props(viewPropsUrl
);
721 props
.setShowPreview(show
);
723 m_showPreview
= show
;
724 const int oldZoomLevel
= m_controller
->zoomLevel();
725 emit
showPreviewChanged();
727 // Enabling or disabling the preview might change the icon size of the view.
728 // As the view does not emit a signal when the icon size has been changed,
729 // the used zoom level of the controller must be adjusted manually:
730 updateZoomLevel(oldZoomLevel
);
733 void DolphinView::setShowHiddenFiles(bool show
)
735 if (m_viewAccessor
.dirLister()->showingDotFiles() == show
) {
739 const KUrl viewPropsUrl
= rootUrl();
740 ViewProperties
props(viewPropsUrl
);
741 props
.setShowHiddenFiles(show
);
743 m_viewAccessor
.dirLister()->setShowingDotFiles(show
);
744 emit
showHiddenFilesChanged();
747 void DolphinView::setCategorizedSorting(bool categorized
)
749 if (categorized
== categorizedSorting()) {
753 // setCategorizedSorting(true) may only get invoked
754 // if the view supports categorized sorting
755 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
757 ViewProperties
props(rootUrl());
758 props
.setCategorizedSorting(categorized
);
761 m_storedCategorizedSorting
= categorized
;
762 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
764 emit
categorizedSortingChanged();
767 void DolphinView::toggleSortOrder()
769 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
770 Qt::DescendingOrder
:
775 void DolphinView::toggleSortFoldersFirst()
777 setSortFoldersFirst(!sortFoldersFirst());
780 void DolphinView::toggleAdditionalInfo(QAction
* action
)
782 const KFileItemDelegate::Information info
=
783 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
785 KFileItemDelegate::InformationList list
= additionalInfo();
787 const bool show
= action
->isChecked();
789 const int index
= list
.indexOf(info
);
790 const bool containsInfo
= (index
>= 0);
791 if (show
&& !containsInfo
) {
793 setAdditionalInfo(list
);
794 } else if (!show
&& containsInfo
) {
795 list
.removeAt(index
);
796 setAdditionalInfo(list
);
797 Q_ASSERT(list
.indexOf(info
) < 0);
801 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
803 QWidget::mouseReleaseEvent(event
);
807 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
809 switch (event
->type()) {
810 case QEvent::FocusIn
:
811 if (watched
== m_viewAccessor
.itemView()) {
812 m_controller
->requestActivation();
816 case QEvent::DragEnter
:
817 if (watched
== m_viewAccessor
.itemView()->viewport()) {
822 case QEvent::KeyPress
:
823 if (watched
== m_viewAccessor
.itemView()) {
824 // clear the selection when Escape has been pressed
825 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
826 if (keyEvent
->key() == Qt::Key_Escape
) {
833 if (watched
== m_viewAccessor
.itemView()->viewport()) {
834 // Ctrl+wheel events should cause icon zooming, but not if the left mouse button is pressed
835 // (the user is probably trying to scroll during a selection in that case)
836 QWheelEvent
* wheelEvent
= static_cast<QWheelEvent
*>(event
);
837 if (wheelEvent
->modifiers() & Qt::ControlModifier
&& !(wheelEvent
->buttons() & Qt::LeftButton
)) {
838 const int delta
= wheelEvent
->delta();
839 const int level
= zoomLevel();
841 setZoomLevel(level
+ 1);
842 } else if (delta
< 0) {
843 setZoomLevel(level
- 1);
854 return QWidget::eventFilter(watched
, event
);
857 void DolphinView::activate()
862 void DolphinView::triggerItem(const KFileItem
& item
)
864 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
865 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
866 // items are selected by the user, hence don't trigger the
867 // item specified by 'index'
871 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
872 if (item
.isNull() || m_isContextMenuOpen
) {
876 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
879 void DolphinView::slotSelectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
)
881 const int count
= selectedItemsCount();
882 const bool selectionStateChanged
= ((count
> 0) && (selected
.count() == count
)) ||
883 ((count
== 0) && !deselected
.isEmpty());
885 // If nothing has been selected before and something got selected (or if something
886 // was selected before and now nothing is selected) the selectionChangedSignal must
887 // be emitted asynchronously as fast as possible to update the edit-actions.
888 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
889 m_selectionChangedTimer
->start();
892 void DolphinView::emitSelectionChangedSignal()
894 emit
selectionChanged(DolphinView::selectedItems());
897 void DolphinView::openContextMenu(const QPoint
& pos
,
898 const QList
<QAction
*>& customActions
)
901 const QModelIndex index
= m_viewAccessor
.itemView()->indexAt(pos
);
902 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
903 const QModelIndex dolphinModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(index
);
904 item
= m_viewAccessor
.dirModel()->itemForIndex(dolphinModelIndex
);
907 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
908 emit
requestContextMenu(item
, url(), customActions
);
909 m_isContextMenuOpen
= false;
912 void DolphinView::dropUrls(const KFileItem
& destItem
,
913 const KUrl
& destPath
,
916 addNewFileNames(event
->mimeData());
917 DragAndDropHelper::instance().dropUrls(destItem
, destPath
, event
, this);
920 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
922 ViewProperties
props(rootUrl());
923 props
.setSorting(sorting
);
925 m_viewAccessor
.proxyModel()->setSorting(sorting
);
927 emit
sortingChanged(sorting
);
930 void DolphinView::updateSortOrder(Qt::SortOrder order
)
932 ViewProperties
props(rootUrl());
933 props
.setSortOrder(order
);
935 m_viewAccessor
.proxyModel()->setSortOrder(order
);
937 emit
sortOrderChanged(order
);
940 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
942 ViewProperties
props(rootUrl());
943 props
.setSortFoldersFirst(foldersFirst
);
945 m_viewAccessor
.proxyModel()->setSortFoldersFirst(foldersFirst
);
947 emit
sortFoldersFirstChanged(foldersFirst
);
950 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
952 ViewProperties
props(rootUrl());
953 props
.setAdditionalInfo(info
);
956 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
958 emit
additionalInfoChanged();
961 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
963 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
964 (m_mode
== DolphinView::IconsView
);
966 QAction
* showSizeInfo
= collection
->action("show_size_info");
967 QAction
* showDateInfo
= collection
->action("show_date_info");
968 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
969 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
970 QAction
* showGroupInfo
= collection
->action("show_group_info");
971 QAction
* showMimeInfo
= collection
->action("show_mime_info");
973 showSizeInfo
->setChecked(false);
974 showDateInfo
->setChecked(false);
975 showPermissionsInfo
->setChecked(false);
976 showOwnerInfo
->setChecked(false);
977 showGroupInfo
->setChecked(false);
978 showMimeInfo
->setChecked(false);
980 showSizeInfo
->setEnabled(enable
);
981 showDateInfo
->setEnabled(enable
);
982 showPermissionsInfo
->setEnabled(enable
);
983 showOwnerInfo
->setEnabled(enable
);
984 showGroupInfo
->setEnabled(enable
);
985 showMimeInfo
->setEnabled(enable
);
987 foreach (KFileItemDelegate::Information info
, m_viewAccessor
.itemDelegate()->showInformation()) {
989 case KFileItemDelegate::Size
:
990 showSizeInfo
->setChecked(true);
992 case KFileItemDelegate::ModificationTime
:
993 showDateInfo
->setChecked(true);
995 case KFileItemDelegate::Permissions
:
996 showPermissionsInfo
->setChecked(true);
998 case KFileItemDelegate::Owner
:
999 showOwnerInfo
->setChecked(true);
1001 case KFileItemDelegate::OwnerAndGroup
:
1002 showGroupInfo
->setChecked(true);
1004 case KFileItemDelegate::FriendlyMimeType
:
1005 showMimeInfo
->setChecked(true);
1013 QPair
<bool, QString
> DolphinView::pasteInfo() const
1015 return KonqOperations::pasteInfo(url());
1018 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1020 m_tabsForFiles
= tabsForFiles
;
1023 bool DolphinView::isTabsForFilesEnabled() const
1025 return m_tabsForFiles
;
1028 void DolphinView::activateItem(const KUrl
& url
)
1030 // TODO: If DolphinViewContainer uses DolphinView::restoreState(...) to restore the
1031 // view state in KDE 4.5, this function can be removed.
1032 m_activeItemUrl
= url
;
1035 bool DolphinView::itemsExpandable() const
1037 return m_viewAccessor
.itemsExpandable();
1040 void DolphinView::restoreState(QDataStream
& stream
)
1043 stream
>> m_activeItemUrl
;
1046 stream
>> m_restoredContentsPosition
;
1048 // expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1049 QSet
<KUrl
> urlsToExpand
;
1050 stream
>> urlsToExpand
;
1051 const DolphinDetailsViewExpander
* expander
= m_viewAccessor
.setExpandedUrls(urlsToExpand
);
1052 if (expander
!= 0) {
1053 m_expanderActive
= true;
1054 connect (expander
, SIGNAL(completed()), this, SLOT(slotLoadingCompleted()));
1057 m_expanderActive
= false;
1061 void DolphinView::saveState(QDataStream
& stream
)
1064 KFileItem currentItem
;
1065 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1068 const QModelIndex proxyIndex
= view
->currentIndex();
1069 const QModelIndex dirModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1070 currentItem
= m_viewAccessor
.dirModel()->itemForIndex(dirModelIndex
);
1074 if (!currentItem
.isNull()) {
1075 currentUrl
= currentItem
.url();
1078 stream
<< currentUrl
;
1081 const int x
= view
->horizontalScrollBar()->value();
1082 const int y
= view
->verticalScrollBar()->value();
1083 stream
<< QPoint(x
, y
);
1085 // expanded folders (only relevant for the details view - the set will be empty in other view modes)
1086 stream
<< m_viewAccessor
.expandedUrls();
1089 void DolphinView::observeCreatedItem(const KUrl
& url
)
1091 m_createdItemUrl
= url
;
1092 connect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1093 this, SLOT(selectAndScrollToCreatedItem()));
1096 void DolphinView::selectAndScrollToCreatedItem()
1098 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_createdItemUrl
);
1099 if (dirIndex
.isValid()) {
1100 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1101 m_viewAccessor
.itemView()->setCurrentIndex(proxyIndex
);
1104 disconnect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1105 this, SLOT(selectAndScrollToCreatedItem()));
1106 m_createdItemUrl
= KUrl();
1109 void DolphinView::showHoverInformation(const KFileItem
& item
)
1111 emit
requestItemInfo(item
);
1114 void DolphinView::clearHoverInformation()
1116 emit
requestItemInfo(KFileItem());
1119 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1121 if (job
->error() == 0) {
1122 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1123 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1124 emit
errorMessage(job
->errorString());
1128 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1130 emit
requestUrlChange(url
);
1131 m_controller
->setUrl(url
);
1134 void DolphinView::slotDirListerCompleted()
1136 if (!m_expanderActive
) {
1137 slotLoadingCompleted();
1140 if (!m_newFileNames
.isEmpty()) {
1141 // select all newly added items created by a paste operation or
1142 // a drag & drop operation
1143 const int rowCount
= m_viewAccessor
.proxyModel()->rowCount();
1144 QItemSelection selection
;
1145 for (int row
= 0; row
< rowCount
; ++row
) {
1146 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->index(row
, 0);
1147 const QModelIndex dirIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1148 const KUrl url
= m_viewAccessor
.dirModel()->itemForIndex(dirIndex
).url();
1149 if (m_newFileNames
.contains(url
.fileName())) {
1150 selection
.merge(QItemSelection(proxyIndex
, proxyIndex
), QItemSelectionModel::Select
);
1153 m_viewAccessor
.itemView()->selectionModel()->select(selection
, QItemSelectionModel::Select
);
1155 m_newFileNames
.clear();
1159 void DolphinView::slotLoadingCompleted()
1161 m_expanderActive
= false;
1162 m_loadingDirectory
= false;
1164 if (!m_activeItemUrl
.isEmpty()) {
1165 // assure that the current item remains visible
1166 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_activeItemUrl
);
1167 if (dirIndex
.isValid()) {
1168 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1169 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1170 const bool clearSelection
= !hasSelection();
1171 view
->setCurrentIndex(proxyIndex
);
1172 if (clearSelection
) {
1173 view
->clearSelection();
1175 m_activeItemUrl
.clear();
1179 if (!m_selectedItems
.isEmpty()) {
1180 const KUrl
& baseUrl
= url();
1182 QItemSelection newSelection
;
1183 foreach(const KFileItem
& item
, m_selectedItems
) {
1184 url
= item
.url().upUrl();
1185 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
1186 QModelIndex index
= m_viewAccessor
.proxyModel()->mapFromSource(m_viewAccessor
.dirModel()->indexForItem(item
));
1187 newSelection
.select(index
, index
);
1190 m_viewAccessor
.itemView()->selectionModel()->select(newSelection
,
1191 QItemSelectionModel::ClearAndSelect
1192 | QItemSelectionModel::Current
);
1193 m_selectedItems
.clear();
1196 // Restore the contents position. This has to be done using a Qt::QueuedConnection
1197 // because the view might not be in its final state yet.
1198 QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection
);
1201 void DolphinView::slotRefreshItems()
1203 if (m_assureVisibleCurrentIndex
) {
1204 m_assureVisibleCurrentIndex
= false;
1205 m_viewAccessor
.itemView()->scrollTo(m_viewAccessor
.itemView()->currentIndex());
1209 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1211 if (!url
.isValid()) {
1212 const QString
location(url
.pathOrUrl());
1213 if (location
.isEmpty()) {
1214 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1216 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1221 m_loadingDirectory
= true;
1222 m_expanderActive
= false;
1224 KDirLister
* dirLister
= m_viewAccessor
.dirLister();
1225 dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1227 KDirLister
* rootDirLister
= m_viewAccessor
.rootDirLister();
1228 if (dirLister
!= rootDirLister
) {
1229 // In the case of the column view the root directory lister can be different. Assure
1230 // that it gets synchronized (clients from DolphinView are not aware that internally
1231 // different directory listers are used).
1232 rootDirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1236 void DolphinView::applyViewProperties()
1238 if (m_ignoreViewProperties
) {
1242 const ViewProperties
props(rootUrl());
1244 const Mode mode
= props
.viewMode();
1245 if (m_mode
!= mode
) {
1246 const int oldZoomLevel
= m_controller
->zoomLevel();
1252 updateZoomLevel(oldZoomLevel
);
1254 if (m_viewAccessor
.itemView() == 0) {
1257 Q_ASSERT(m_viewAccessor
.itemView() != 0);
1258 Q_ASSERT(m_viewAccessor
.itemDelegate() != 0);
1260 const bool showHiddenFiles
= props
.showHiddenFiles();
1261 if (showHiddenFiles
!= m_viewAccessor
.dirLister()->showingDotFiles()) {
1262 m_viewAccessor
.dirLister()->setShowingDotFiles(showHiddenFiles
);
1263 emit
showHiddenFilesChanged();
1266 m_storedCategorizedSorting
= props
.categorizedSorting();
1267 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1268 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
1269 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
1270 emit
categorizedSortingChanged();
1273 const DolphinView::Sorting sorting
= props
.sorting();
1274 if (sorting
!= m_viewAccessor
.proxyModel()->sorting()) {
1275 m_viewAccessor
.proxyModel()->setSorting(sorting
);
1276 emit
sortingChanged(sorting
);
1279 const Qt::SortOrder sortOrder
= props
.sortOrder();
1280 if (sortOrder
!= m_viewAccessor
.proxyModel()->sortOrder()) {
1281 m_viewAccessor
.proxyModel()->setSortOrder(sortOrder
);
1282 emit
sortOrderChanged(sortOrder
);
1285 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1286 if (sortFoldersFirst
!= m_viewAccessor
.proxyModel()->sortFoldersFirst()) {
1287 m_viewAccessor
.proxyModel()->setSortFoldersFirst(sortFoldersFirst
);
1288 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1291 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1292 if (info
!= m_viewAccessor
.itemDelegate()->showInformation()) {
1293 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
1294 emit
additionalInfoChanged();
1297 const bool showPreview
= props
.showPreview();
1298 if (showPreview
!= m_showPreview
) {
1299 m_showPreview
= showPreview
;
1300 const int oldZoomLevel
= m_controller
->zoomLevel();
1301 emit
showPreviewChanged();
1303 // Enabling or disabling the preview might change the icon size of the view.
1304 // As the view does not emit a signal when the icon size has been changed,
1305 // the used zoom level of the controller must be adjusted manually:
1306 updateZoomLevel(oldZoomLevel
);
1309 if (DolphinSettings::instance().generalSettings()->globalViewProps()) {
1310 // During the lifetime of a DolphinView instance the global view properties
1311 // should not be changed. This allows e. g. to split a view and use different
1312 // view properties for each view.
1313 m_ignoreViewProperties
= true;
1317 void DolphinView::createView()
1321 Q_ASSERT(m_viewAccessor
.itemView() == 0);
1322 m_viewAccessor
.createView(this, m_controller
, m_mode
);
1324 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1325 Q_ASSERT(view
!= 0);
1326 view
->installEventFilter(this);
1327 view
->viewport()->installEventFilter(this);
1329 m_controller
->setItemView(view
);
1331 // When changing the view mode, the selection is lost due to reinstantiating
1332 // a new item view with a custom selection model. Pass the ownership of the
1333 // selection model to DolphinView, so that it can be shared by all item views.
1334 if (m_selectionModel
!= 0) {
1335 view
->setSelectionModel(m_selectionModel
);
1337 m_selectionModel
= view
->selectionModel();
1339 m_selectionModel
->setParent(this);
1340 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1341 this, SLOT(slotSelectionChanged(const QItemSelection
&, const QItemSelection
&)));
1343 setFocusProxy(m_viewAccessor
.layoutTarget());
1344 m_topLayout
->insertWidget(1, m_viewAccessor
.layoutTarget());
1347 void DolphinView::deleteView()
1349 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1351 // It's important to set the keyboard focus to the parent
1352 // before deleting the view: Otherwise when having a split
1353 // view the other view will get the focus and will request
1354 // an activation (see DolphinView::eventFilter()).
1358 m_topLayout
->removeWidget(view
);
1361 // disconnect all signal/slots
1363 m_controller
->disconnect(view
);
1366 m_viewAccessor
.deleteView();
1370 void DolphinView::pasteToUrl(const KUrl
& url
)
1372 addNewFileNames(QApplication::clipboard()->mimeData());
1373 KonqOperations::doPaste(this, url
);
1376 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1378 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor
.itemView()->iconSize());
1379 if (oldZoomLevel
!= newZoomLevel
) {
1380 m_controller
->setZoomLevel(newZoomLevel
);
1381 emit
zoomLevelChanged(newZoomLevel
);
1385 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1387 KUrl::List list
= selectedUrls();
1388 if (itemsExpandable() ) {
1389 list
= KDirModel::simplifiedUrlList(list
);
1394 QMimeData
* DolphinView::selectionMimeData() const
1396 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1397 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
1398 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
1399 return m_viewAccessor
.dirModel()->mimeData(selection
.indexes());
1402 void DolphinView::addNewFileNames(const QMimeData
* mimeData
)
1404 const KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1405 foreach (const KUrl
& url
, urls
) {
1406 m_newFileNames
.insert(url
.fileName());
1410 DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel
* proxyModel
) :
1413 m_columnsContainer(0),
1414 m_proxyModel(proxyModel
),
1419 DolphinView::ViewAccessor::~ViewAccessor()
1421 delete m_dragSource
;
1425 void DolphinView::ViewAccessor::createView(QWidget
* parent
,
1426 DolphinController
* controller
,
1429 Q_ASSERT(itemView() == 0);
1433 m_iconsView
= new DolphinIconsView(parent
, controller
, m_proxyModel
);
1437 m_detailsView
= new DolphinDetailsView(parent
, controller
, m_proxyModel
);
1441 m_columnsContainer
= new DolphinColumnViewContainer(parent
, controller
);
1449 void DolphinView::ViewAccessor::deleteView()
1451 QAbstractItemView
* view
= itemView();
1453 if (DragAndDropHelper::instance().isDragSource(view
)) {
1454 // The view is a drag source (the feature "Open folders
1455 // during drag operations" is used). Deleting the view
1456 // during an ongoing drag operation is not allowed, so
1457 // this will postponed.
1458 if (m_dragSource
!= 0) {
1459 // the old stored view is obviously not the drag source anymore
1460 m_dragSource
->deleteLater();
1464 m_dragSource
= view
;
1466 view
->deleteLater();
1473 if (m_columnsContainer
!= 0) {
1474 m_columnsContainer
->deleteLater();
1476 m_columnsContainer
= 0;
1480 void DolphinView::ViewAccessor::prepareUrlChange(const KUrl
& url
)
1482 if (m_columnsContainer
!= 0) {
1483 m_columnsContainer
->showColumn(url
);
1486 if(!m_detailsViewExpander
.isNull()) {
1487 // stop expanding items in the current folder
1488 m_detailsViewExpander
->stop();
1492 QAbstractItemView
* DolphinView::ViewAccessor::itemView() const
1494 if (m_iconsView
!= 0) {
1498 if (m_detailsView
!= 0) {
1499 return m_detailsView
;
1502 if (m_columnsContainer
!= 0) {
1503 return m_columnsContainer
->activeColumn();
1509 KFileItemDelegate
* DolphinView::ViewAccessor::itemDelegate() const
1511 return static_cast<KFileItemDelegate
*>(itemView()->itemDelegate());
1514 QWidget
* DolphinView::ViewAccessor::layoutTarget() const
1516 if (m_columnsContainer
!= 0) {
1517 return m_columnsContainer
;
1522 KUrl
DolphinView::ViewAccessor::rootUrl() const
1524 return (m_columnsContainer
!= 0) ? m_columnsContainer
->rootUrl() : KUrl();
1527 KDirLister
* DolphinView::ViewAccessor::rootDirLister() const
1529 return static_cast<DolphinModel
*>(m_proxyModel
->sourceModel())->dirLister();
1532 bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
1534 return m_iconsView
!= 0;
1537 bool DolphinView::ViewAccessor::itemsExpandable() const
1539 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1543 QSet
<KUrl
> DolphinView::ViewAccessor::expandedUrls() const
1545 if (m_detailsView
!= 0) {
1546 return m_detailsView
->expandedUrls();
1549 return QSet
<KUrl
>();
1552 const DolphinDetailsViewExpander
* DolphinView::ViewAccessor::setExpandedUrls(const QSet
<KUrl
>& urlsToExpand
)
1554 if ((m_detailsView
!= 0) && m_detailsView
->itemsExpandable() && !urlsToExpand
.isEmpty()) {
1555 m_detailsViewExpander
= new DolphinDetailsViewExpander(m_detailsView
, urlsToExpand
);
1556 return m_detailsViewExpander
;
1563 bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const
1565 // the details view requires no reloading of the directory, as it maps
1566 // the file item delegate info to its columns internally
1567 return m_detailsView
!= 0;
1570 DolphinModel
* DolphinView::ViewAccessor::dirModel() const
1572 return static_cast<DolphinModel
*>(proxyModel()->sourceModel());
1575 DolphinSortFilterProxyModel
* DolphinView::ViewAccessor::proxyModel() const
1577 if (m_columnsContainer
!= 0) {
1578 return static_cast<DolphinSortFilterProxyModel
*>(m_columnsContainer
->activeColumn()->model());
1580 return m_proxyModel
;
1583 KDirLister
* DolphinView::ViewAccessor::dirLister() const
1585 return dirModel()->dirLister();
1588 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1590 emit
redirection(oldUrl
, newUrl
);
1591 m_controller
->redirectToUrl(newUrl
); // #186947
1594 void DolphinView::restoreContentsPosition()
1596 if (!m_restoredContentsPosition
.isNull()) {
1597 const int x
= m_restoredContentsPosition
.x();
1598 const int y
= m_restoredContentsPosition
.y();
1599 m_restoredContentsPosition
= QPoint();
1601 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1602 Q_ASSERT(view
!= 0);
1603 view
->horizontalScrollBar()->setValue(x
);
1604 view
->verticalScrollBar()->setValue(y
);
1606 m_loadingDirectory
= false;
1610 #include "dolphinview.moc"