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_storedCategorizedSorting(false),
85 m_tabsForFiles(false),
86 m_isContextMenuOpen(false),
87 m_ignoreViewProperties(false),
88 m_assureVisibleCurrentIndex(false),
89 m_mode(DolphinView::IconsView
),
92 m_viewAccessor(proxyModel
),
94 m_selectionChangedTimer(0),
97 m_restoredContentsPosition(),
102 m_topLayout
= new QVBoxLayout(this);
103 m_topLayout
->setSpacing(0);
104 m_topLayout
->setMargin(0);
106 m_controller
= new DolphinController(this);
107 m_controller
->setUrl(url
);
109 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
110 this, SIGNAL(urlChanged(const KUrl
&)));
111 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
112 this, SLOT(slotRequestUrlChange(const KUrl
&)));
114 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&, const QList
<QAction
*>&)),
115 this, SLOT(openContextMenu(const QPoint
&, const QList
<QAction
*>&)));
116 connect(m_controller
, SIGNAL(urlsDropped(const KFileItem
&, const KUrl
&, QDropEvent
*)),
117 this, SLOT(dropUrls(const KFileItem
&, const KUrl
&, QDropEvent
*)));
118 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
119 this, SLOT(updateSorting(DolphinView::Sorting
)));
120 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
121 this, SLOT(updateSortOrder(Qt::SortOrder
)));
122 connect(m_controller
, SIGNAL(sortFoldersFirstChanged(bool)),
123 this, SLOT(updateSortFoldersFirst(bool)));
124 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
125 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
126 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
127 this, SLOT(triggerItem(const KFileItem
&)));
128 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
129 this, SIGNAL(tabRequested(const KUrl
&)));
130 connect(m_controller
, SIGNAL(activated()),
131 this, SLOT(activate()));
132 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
133 this, SLOT(showHoverInformation(const KFileItem
&)));
134 connect(m_controller
, SIGNAL(viewportEntered()),
135 this, SLOT(clearHoverInformation()));
137 KDirLister
* dirLister
= m_viewAccessor
.dirLister();
138 connect(dirLister
, SIGNAL(redirection(KUrl
,KUrl
)),
139 this, SLOT(slotRedirection(KUrl
,KUrl
)));
140 connect(dirLister
, SIGNAL(completed()),
141 this, SLOT(slotDirListerCompleted()));
142 connect(dirLister
, SIGNAL(refreshItems(const QList
<QPair
<KFileItem
,KFileItem
>>&)),
143 this, SLOT(slotRefreshItems()));
145 // When a new item has been created by the "Create New..." menu, the item should
146 // get selected and it must be assured that the item will get visible. As the
147 // creation is done asynchronously, several signals must be checked:
148 connect(&DolphinNewMenuObserver::instance(), SIGNAL(itemCreated(const KUrl
&)),
149 this, SLOT(observeCreatedItem(const KUrl
&)));
151 m_selectionChangedTimer
= new QTimer(this);
152 m_selectionChangedTimer
->setSingleShot(true);
153 m_selectionChangedTimer
->setInterval(300);
154 connect(m_selectionChangedTimer
, SIGNAL(timeout()),
155 this, SLOT(emitSelectionChangedSignal()));
157 applyViewProperties();
158 m_topLayout
->addWidget(m_viewAccessor
.layoutTarget());
161 DolphinView::~DolphinView()
165 const KUrl
& DolphinView::url() const
167 return m_controller
->url();
170 KUrl
DolphinView::rootUrl() const
172 const KUrl viewUrl
= url();
173 const KUrl root
= m_viewAccessor
.rootUrl();
174 if (root
.isEmpty() || !root
.isParentOf(viewUrl
)) {
180 void DolphinView::setActive(bool active
)
182 if (active
== m_active
) {
188 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
190 emitSelectionChangedSignal();
195 QWidget
* viewport
= m_viewAccessor
.itemView()->viewport();
197 palette
.setColor(viewport
->backgroundRole(), color
);
198 viewport
->setPalette(palette
);
203 m_viewAccessor
.itemView()->setFocus();
207 m_controller
->indicateActivationChange(active
);
210 bool DolphinView::isActive() const
215 void DolphinView::setMode(Mode mode
)
217 if (mode
== m_mode
) {
218 return; // the wished mode is already set
221 const int oldZoomLevel
= m_controller
->zoomLevel();
224 // remember the currently selected items, so that they will
225 // be restored after reloading the directory
226 m_selectedItems
= selectedItems();
230 const KUrl viewPropsUrl
= rootUrl();
231 ViewProperties
props(viewPropsUrl
);
232 props
.setViewMode(m_mode
);
235 // the file item delegate has been recreated, apply the current
236 // additional information manually
237 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
238 m_viewAccessor
.itemDelegate()->setShowInformation(infoList
);
239 emit
additionalInfoChanged();
241 // Not all view modes support categorized sorting. Adjust the sorting model
242 // if changing the view mode results in a change of the categorized sorting
244 m_storedCategorizedSorting
= props
.categorizedSorting();
245 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
246 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
247 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
248 emit
categorizedSortingChanged();
253 updateZoomLevel(oldZoomLevel
);
254 loadDirectory(viewPropsUrl
);
257 DolphinView::Mode
DolphinView::mode() const
262 bool DolphinView::showPreview() const
264 return m_showPreview
;
267 bool DolphinView::showHiddenFiles() const
269 return m_viewAccessor
.dirLister()->showingDotFiles();
272 bool DolphinView::categorizedSorting() const
274 // If all view modes would support categorized sorting, returning
275 // m_viewAccessor.proxyModel()->isCategorizedModel() would be the way to go. As
276 // currently only the icons view supports caterized sorting, we remember
277 // the stored view properties state in m_storedCategorizedSorting and
278 // return this state. The application takes care to disable the corresponding
279 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
280 // that this setting is not applied to the current view mode.
281 return m_storedCategorizedSorting
;
284 bool DolphinView::supportsCategorizedSorting() const
286 return m_viewAccessor
.supportsCategorizedSorting();
289 bool DolphinView::hasSelection() const
291 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
292 return (view
!= 0) && view
->selectionModel()->hasSelection();
295 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
297 foreach (const KUrl
& url
, urls
) {
298 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url
);
299 m_selectedItems
.append(item
);
303 KFileItemList
DolphinView::selectedItems() const
305 KFileItemList itemList
;
306 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
311 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
313 const QModelIndexList indexList
= selection
.indexes();
314 foreach (const QModelIndex
&index
, indexList
) {
315 KFileItem item
= m_viewAccessor
.dirModel()->itemForIndex(index
);
316 if (!item
.isNull()) {
317 itemList
.append(item
);
324 KUrl::List
DolphinView::selectedUrls() const
327 const KFileItemList list
= selectedItems();
328 foreach (const KFileItem
&item
, list
) {
329 urls
.append(item
.url());
334 int DolphinView::selectedItemsCount() const
336 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
341 return view
->selectionModel()->selectedIndexes().count();
344 QItemSelectionModel
* DolphinView::selectionModel() const
346 return m_viewAccessor
.itemView()->selectionModel();
349 void DolphinView::setZoomLevel(int level
)
351 if (level
< ZoomLevelInfo::minimumLevel()) {
352 level
= ZoomLevelInfo::minimumLevel();
353 } else if (level
> ZoomLevelInfo::maximumLevel()) {
354 level
= ZoomLevelInfo::maximumLevel();
357 if (level
!= zoomLevel()) {
358 m_controller
->setZoomLevel(level
);
359 emit
zoomLevelChanged(level
);
363 int DolphinView::zoomLevel() const
365 return m_controller
->zoomLevel();
368 void DolphinView::setSorting(Sorting sorting
)
370 if (sorting
!= this->sorting()) {
371 updateSorting(sorting
);
375 DolphinView::Sorting
DolphinView::sorting() const
377 return m_viewAccessor
.proxyModel()->sorting();
380 void DolphinView::setSortOrder(Qt::SortOrder order
)
382 if (sortOrder() != order
) {
383 updateSortOrder(order
);
387 Qt::SortOrder
DolphinView::sortOrder() const
389 return m_viewAccessor
.proxyModel()->sortOrder();
392 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
394 if (sortFoldersFirst() != foldersFirst
) {
395 updateSortFoldersFirst(foldersFirst
);
399 bool DolphinView::sortFoldersFirst() const
401 return m_viewAccessor
.proxyModel()->sortFoldersFirst();
404 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
406 const KUrl viewPropsUrl
= rootUrl();
407 ViewProperties
props(viewPropsUrl
);
408 props
.setAdditionalInfo(info
);
409 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
411 emit
additionalInfoChanged();
413 if (m_viewAccessor
.reloadOnAdditionalInfoChange()) {
414 loadDirectory(viewPropsUrl
);
418 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
420 return m_viewAccessor
.itemDelegate()->showInformation();
423 void DolphinView::reload()
425 QByteArray viewState
;
426 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
427 saveState(saveStream
);
428 m_selectedItems
= selectedItems();
431 loadDirectory(url(), true);
433 QDataStream
restoreStream(viewState
);
434 restoreState(restoreStream
);
437 void DolphinView::refresh()
439 m_ignoreViewProperties
= false;
441 const bool oldActivationState
= m_active
;
442 const int oldZoomLevel
= m_controller
->zoomLevel();
446 applyViewProperties();
449 setActive(oldActivationState
);
450 updateZoomLevel(oldZoomLevel
);
453 void DolphinView::setNameFilter(const QString
& nameFilter
)
455 m_controller
->setNameFilter(nameFilter
);
458 void DolphinView::calculateItemCount(int& fileCount
,
460 KIO::filesize_t
& totalFileSize
) const
462 foreach (const KFileItem
& item
, m_viewAccessor
.dirLister()->items()) {
467 totalFileSize
+= item
.size();
472 QString
DolphinView::statusBarText() const
477 KIO::filesize_t totalFileSize
= 0;
479 if (hasSelection()) {
480 // give a summary of the status of the selected files
481 const KFileItemList list
= selectedItems();
482 if (list
.isEmpty()) {
483 // when an item is triggered, it is temporary selected but selectedItems()
484 // will return an empty list
488 KFileItemList::const_iterator it
= list
.begin();
489 const KFileItemList::const_iterator end
= list
.end();
491 const KFileItem
& item
= *it
;
496 totalFileSize
+= item
.size();
501 if (folderCount
+ fileCount
== 1) {
502 // if only one item is selected, show the filename
503 const QString name
= list
.first().text();
504 text
= (folderCount
== 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name
) :
505 i18nc("@info:status", "<filename>%1</filename> selected (%2)",
506 name
, KIO::convertSize(totalFileSize
));
508 // at least 2 items are selected
509 const QString foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
510 const QString filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
511 if ((folderCount
> 0) && (fileCount
> 0)) {
512 text
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
513 foldersText
, filesText
, KIO::convertSize(totalFileSize
));
514 } else if (fileCount
> 0) {
515 text
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KIO::convertSize(totalFileSize
));
517 Q_ASSERT(folderCount
> 0);
522 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
523 text
= KIO::itemsSummaryString(fileCount
+ folderCount
,
524 fileCount
, folderCount
,
525 totalFileSize
, true);
531 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
533 return m_controller
->versionControlActions(items
);
536 void DolphinView::setUrl(const KUrl
& url
)
538 if (m_controller
->url() != url
) {
539 m_newFileNames
.clear();
541 m_controller
->setUrl(url
); // emits urlChanged, which we forward
542 m_viewAccessor
.prepareUrlChange(url
);
543 applyViewProperties();
546 // When changing the URL there is no need to keep the version
547 // data of the previous URL.
548 m_viewAccessor
.dirModel()->clearVersionData();
550 emit
startedPathLoading(url
);
553 // the selection model might have changed in the case of a column view
554 QItemSelectionModel
* selectionModel
= m_viewAccessor
.itemView()->selectionModel();
555 if (m_selectionModel
!= selectionModel
) {
556 disconnect(m_selectionModel
, SIGNAL(selectionChanged(QItemSelection
, QItemSelection
)),
557 this, SLOT(slotSelectionChanged(QItemSelection
, QItemSelection
)));
558 m_selectionModel
= selectionModel
;
559 connect(m_selectionModel
, SIGNAL(selectionChanged(QItemSelection
, QItemSelection
)),
560 this, SLOT(slotSelectionChanged(QItemSelection
, QItemSelection
)));
564 void DolphinView::selectAll()
566 m_viewAccessor
.itemView()->selectAll();
569 void DolphinView::invertSelection()
571 QItemSelectionModel
* selectionModel
= m_viewAccessor
.itemView()->selectionModel();
572 const QAbstractItemModel
* itemModel
= selectionModel
->model();
574 const QModelIndex topLeft
= itemModel
->index(0, 0);
575 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
576 itemModel
->columnCount() - 1);
578 const QItemSelection
selection(topLeft
, bottomRight
);
579 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
582 void DolphinView::clearSelection()
584 m_viewAccessor
.itemView()->clearSelection();
587 void DolphinView::renameSelectedItems()
589 KFileItemList items
= selectedItems();
590 const int itemCount
= items
.count();
596 // More than one item has been selected for renaming. Open
597 // a rename dialog and rename all items afterwards.
598 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
599 if (dialog
->exec() == QDialog::Rejected
) {
604 const QString newName
= dialog
->newName();
605 if (newName
.isEmpty()) {
606 emit
errorMessage(dialog
->errorString());
612 // the selection would be invalid after renaming the items, so just clear
616 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
617 // as one operation instead of n rename operations like it is done now...
618 Q_ASSERT(newName
.contains('#'));
620 // currently the items are sorted by the selection order, resort
621 // them by the file name
622 qSort(items
.begin(), items
.end(), lessThan
);
624 // iterate through all selected items and rename them...
626 foreach (const KFileItem
& item
, items
) {
627 const KUrl
& oldUrl
= item
.url();
629 number
.setNum(index
++);
631 QString name
= newName
;
632 name
.replace('#', number
);
634 if (oldUrl
.fileName() != name
) {
635 KUrl newUrl
= oldUrl
;
636 newUrl
.setFileName(name
);
637 KonqOperations::rename(this, oldUrl
, newUrl
);
640 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
641 Q_ASSERT(itemCount
== 1);
642 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForItem(items
.first());
643 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
644 m_viewAccessor
.itemView()->edit(proxyIndex
);
646 Q_ASSERT(itemCount
== 1);
648 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
649 if (dialog
->exec() == QDialog::Rejected
) {
654 const QString newName
= dialog
->newName();
655 if (newName
.isEmpty()) {
656 emit
errorMessage(dialog
->errorString());
662 const KUrl
& oldUrl
= items
.first().url();
663 KUrl newUrl
= oldUrl
;
664 newUrl
.setFileName(newName
);
665 KonqOperations::rename(this, oldUrl
, newUrl
);
668 // assure that the current index remains visible when KDirLister
669 // will notify the view about changed items
670 m_assureVisibleCurrentIndex
= true;
673 void DolphinView::trashSelectedItems()
675 const KUrl::List list
= simplifiedSelectedUrls();
676 KonqOperations::del(this, KonqOperations::TRASH
, list
);
679 void DolphinView::deleteSelectedItems()
681 const KUrl::List list
= simplifiedSelectedUrls();
682 const bool del
= KonqOperations::askDeleteConfirmation(list
,
684 KonqOperations::DEFAULT_CONFIRMATION
,
688 KIO::Job
* job
= KIO::del(list
);
689 connect(job
, SIGNAL(result(KJob
*)),
690 this, SLOT(slotDeleteFileFinished(KJob
*)));
694 void DolphinView::cutSelectedItems()
696 QMimeData
* mimeData
= selectionMimeData();
697 KonqMimeData::addIsCutSelection(mimeData
, true);
698 QApplication::clipboard()->setMimeData(mimeData
);
701 void DolphinView::copySelectedItems()
703 QMimeData
* mimeData
= selectionMimeData();
704 QApplication::clipboard()->setMimeData(mimeData
);
707 void DolphinView::paste()
712 void DolphinView::pasteIntoFolder()
714 const KFileItemList items
= selectedItems();
715 if ((items
.count() == 1) && items
.first().isDir()) {
716 pasteToUrl(items
.first().url());
720 void DolphinView::setShowPreview(bool show
)
722 if (m_showPreview
== show
) {
726 const KUrl viewPropsUrl
= rootUrl();
727 ViewProperties
props(viewPropsUrl
);
728 props
.setShowPreview(show
);
730 m_showPreview
= show
;
731 const int oldZoomLevel
= m_controller
->zoomLevel();
732 emit
showPreviewChanged();
734 // Enabling or disabling the preview might change the icon size of the view.
735 // As the view does not emit a signal when the icon size has been changed,
736 // the used zoom level of the controller must be adjusted manually:
737 updateZoomLevel(oldZoomLevel
);
740 void DolphinView::setShowHiddenFiles(bool show
)
742 if (m_viewAccessor
.dirLister()->showingDotFiles() == show
) {
746 const KUrl viewPropsUrl
= rootUrl();
747 ViewProperties
props(viewPropsUrl
);
748 props
.setShowHiddenFiles(show
);
750 m_viewAccessor
.dirLister()->setShowingDotFiles(show
);
751 emit
showHiddenFilesChanged();
754 void DolphinView::setCategorizedSorting(bool categorized
)
756 if (categorized
== categorizedSorting()) {
760 // setCategorizedSorting(true) may only get invoked
761 // if the view supports categorized sorting
762 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
764 ViewProperties
props(rootUrl());
765 props
.setCategorizedSorting(categorized
);
768 m_storedCategorizedSorting
= categorized
;
769 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
771 emit
categorizedSortingChanged();
774 void DolphinView::toggleSortOrder()
776 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
777 Qt::DescendingOrder
:
782 void DolphinView::toggleSortFoldersFirst()
784 setSortFoldersFirst(!sortFoldersFirst());
787 void DolphinView::toggleAdditionalInfo(QAction
* action
)
789 const KFileItemDelegate::Information info
=
790 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
792 KFileItemDelegate::InformationList list
= additionalInfo();
794 const bool show
= action
->isChecked();
796 const int index
= list
.indexOf(info
);
797 const bool containsInfo
= (index
>= 0);
798 if (show
&& !containsInfo
) {
800 setAdditionalInfo(list
);
801 } else if (!show
&& containsInfo
) {
802 list
.removeAt(index
);
803 setAdditionalInfo(list
);
804 Q_ASSERT(list
.indexOf(info
) < 0);
808 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
810 QWidget::mouseReleaseEvent(event
);
814 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
816 switch (event
->type()) {
817 case QEvent::FocusIn
:
818 if (watched
== m_viewAccessor
.itemView()) {
819 m_controller
->requestActivation();
823 case QEvent::DragEnter
:
824 if (watched
== m_viewAccessor
.itemView()->viewport()) {
829 case QEvent::KeyPress
:
830 if (watched
== m_viewAccessor
.itemView()) {
831 // clear the selection when Escape has been pressed
832 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
833 if (keyEvent
->key() == Qt::Key_Escape
) {
840 if (watched
== m_viewAccessor
.itemView()->viewport()) {
841 // Ctrl+wheel events should cause icon zooming, but not if the left mouse button is pressed
842 // (the user is probably trying to scroll during a selection in that case)
843 QWheelEvent
* wheelEvent
= static_cast<QWheelEvent
*>(event
);
844 if (wheelEvent
->modifiers() & Qt::ControlModifier
&& !(wheelEvent
->buttons() & Qt::LeftButton
)) {
845 const int delta
= wheelEvent
->delta();
846 const int level
= zoomLevel();
848 setZoomLevel(level
+ 1);
849 } else if (delta
< 0) {
850 setZoomLevel(level
- 1);
861 return QWidget::eventFilter(watched
, event
);
864 void DolphinView::activate()
869 void DolphinView::triggerItem(const KFileItem
& item
)
871 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
872 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
873 // items are selected by the user, hence don't trigger the
874 // item specified by 'index'
878 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
879 if (item
.isNull() || m_isContextMenuOpen
) {
883 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
886 void DolphinView::slotSelectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
)
888 const int count
= selectedItemsCount();
889 const bool selectionStateChanged
= ((count
> 0) && (selected
.count() == count
)) ||
890 ((count
== 0) && !deselected
.isEmpty());
892 // If nothing has been selected before and something got selected (or if something
893 // was selected before and now nothing is selected) the selectionChangedSignal must
894 // be emitted asynchronously as fast as possible to update the edit-actions.
895 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
896 m_selectionChangedTimer
->start();
899 void DolphinView::emitSelectionChangedSignal()
901 emit
selectionChanged(DolphinView::selectedItems());
904 void DolphinView::openContextMenu(const QPoint
& pos
,
905 const QList
<QAction
*>& customActions
)
908 const QModelIndex index
= m_viewAccessor
.itemView()->indexAt(pos
);
909 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
910 const QModelIndex dolphinModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(index
);
911 item
= m_viewAccessor
.dirModel()->itemForIndex(dolphinModelIndex
);
914 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
915 emit
requestContextMenu(item
, url(), customActions
);
916 m_isContextMenuOpen
= false;
919 void DolphinView::dropUrls(const KFileItem
& destItem
,
920 const KUrl
& destPath
,
923 addNewFileNames(event
->mimeData());
924 DragAndDropHelper::instance().dropUrls(destItem
, destPath
, event
, this);
927 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
929 ViewProperties
props(rootUrl());
930 props
.setSorting(sorting
);
932 m_viewAccessor
.proxyModel()->setSorting(sorting
);
934 emit
sortingChanged(sorting
);
937 void DolphinView::updateSortOrder(Qt::SortOrder order
)
939 ViewProperties
props(rootUrl());
940 props
.setSortOrder(order
);
942 m_viewAccessor
.proxyModel()->setSortOrder(order
);
944 emit
sortOrderChanged(order
);
947 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
949 ViewProperties
props(rootUrl());
950 props
.setSortFoldersFirst(foldersFirst
);
952 m_viewAccessor
.proxyModel()->setSortFoldersFirst(foldersFirst
);
954 emit
sortFoldersFirstChanged(foldersFirst
);
957 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
959 ViewProperties
props(rootUrl());
960 props
.setAdditionalInfo(info
);
963 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
965 emit
additionalInfoChanged();
968 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
970 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
971 (m_mode
== DolphinView::IconsView
);
973 QAction
* showSizeInfo
= collection
->action("show_size_info");
974 QAction
* showDateInfo
= collection
->action("show_date_info");
975 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
976 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
977 QAction
* showGroupInfo
= collection
->action("show_group_info");
978 QAction
* showMimeInfo
= collection
->action("show_mime_info");
980 showSizeInfo
->setChecked(false);
981 showDateInfo
->setChecked(false);
982 showPermissionsInfo
->setChecked(false);
983 showOwnerInfo
->setChecked(false);
984 showGroupInfo
->setChecked(false);
985 showMimeInfo
->setChecked(false);
987 showSizeInfo
->setEnabled(enable
);
988 showDateInfo
->setEnabled(enable
);
989 showPermissionsInfo
->setEnabled(enable
);
990 showOwnerInfo
->setEnabled(enable
);
991 showGroupInfo
->setEnabled(enable
);
992 showMimeInfo
->setEnabled(enable
);
994 foreach (KFileItemDelegate::Information info
, m_viewAccessor
.itemDelegate()->showInformation()) {
996 case KFileItemDelegate::Size
:
997 showSizeInfo
->setChecked(true);
999 case KFileItemDelegate::ModificationTime
:
1000 showDateInfo
->setChecked(true);
1002 case KFileItemDelegate::Permissions
:
1003 showPermissionsInfo
->setChecked(true);
1005 case KFileItemDelegate::Owner
:
1006 showOwnerInfo
->setChecked(true);
1008 case KFileItemDelegate::OwnerAndGroup
:
1009 showGroupInfo
->setChecked(true);
1011 case KFileItemDelegate::FriendlyMimeType
:
1012 showMimeInfo
->setChecked(true);
1020 QPair
<bool, QString
> DolphinView::pasteInfo() const
1022 return KonqOperations::pasteInfo(url());
1025 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1027 m_tabsForFiles
= tabsForFiles
;
1030 bool DolphinView::isTabsForFilesEnabled() const
1032 return m_tabsForFiles
;
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;
1163 if (!m_activeItemUrl
.isEmpty()) {
1164 // assure that the current item remains visible
1165 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_activeItemUrl
);
1166 if (dirIndex
.isValid()) {
1167 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1168 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1169 const bool clearSelection
= !hasSelection();
1170 view
->setCurrentIndex(proxyIndex
);
1171 if (clearSelection
) {
1172 view
->clearSelection();
1174 m_activeItemUrl
.clear();
1178 if (!m_selectedItems
.isEmpty()) {
1179 const KUrl
& baseUrl
= url();
1181 QItemSelection newSelection
;
1182 foreach(const KFileItem
& item
, m_selectedItems
) {
1183 url
= item
.url().upUrl();
1184 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
1185 QModelIndex index
= m_viewAccessor
.proxyModel()->mapFromSource(m_viewAccessor
.dirModel()->indexForItem(item
));
1186 newSelection
.select(index
, index
);
1189 m_viewAccessor
.itemView()->selectionModel()->select(newSelection
,
1190 QItemSelectionModel::ClearAndSelect
1191 | QItemSelectionModel::Current
);
1192 m_selectedItems
.clear();
1195 // Restore the contents position. This has to be done using a Qt::QueuedConnection
1196 // because the view might not be in its final state yet.
1197 QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection
);
1200 void DolphinView::slotRefreshItems()
1202 if (m_assureVisibleCurrentIndex
) {
1203 m_assureVisibleCurrentIndex
= false;
1204 m_viewAccessor
.itemView()->scrollTo(m_viewAccessor
.itemView()->currentIndex());
1208 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1210 if (!url
.isValid()) {
1211 const QString
location(url
.pathOrUrl());
1212 if (location
.isEmpty()) {
1213 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1215 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1220 KDirLister
* dirLister
= m_viewAccessor
.dirLister();
1221 dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1223 KDirLister
* rootDirLister
= m_viewAccessor
.rootDirLister();
1224 if (dirLister
!= rootDirLister
) {
1225 // In the case of the column view the root directory lister can be different. Assure
1226 // that it gets synchronized (clients from DolphinView are not aware that internally
1227 // different directory listers are used).
1228 rootDirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1232 void DolphinView::applyViewProperties()
1234 if (m_ignoreViewProperties
) {
1238 const ViewProperties
props(rootUrl());
1240 const Mode mode
= props
.viewMode();
1241 if (m_mode
!= mode
) {
1242 const int oldZoomLevel
= m_controller
->zoomLevel();
1248 updateZoomLevel(oldZoomLevel
);
1250 if (m_viewAccessor
.itemView() == 0) {
1253 Q_ASSERT(m_viewAccessor
.itemView() != 0);
1254 Q_ASSERT(m_viewAccessor
.itemDelegate() != 0);
1256 const bool showHiddenFiles
= props
.showHiddenFiles();
1257 if (showHiddenFiles
!= m_viewAccessor
.dirLister()->showingDotFiles()) {
1258 m_viewAccessor
.dirLister()->setShowingDotFiles(showHiddenFiles
);
1259 emit
showHiddenFilesChanged();
1262 m_storedCategorizedSorting
= props
.categorizedSorting();
1263 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1264 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
1265 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
1266 emit
categorizedSortingChanged();
1269 const DolphinView::Sorting sorting
= props
.sorting();
1270 if (sorting
!= m_viewAccessor
.proxyModel()->sorting()) {
1271 m_viewAccessor
.proxyModel()->setSorting(sorting
);
1272 emit
sortingChanged(sorting
);
1275 const Qt::SortOrder sortOrder
= props
.sortOrder();
1276 if (sortOrder
!= m_viewAccessor
.proxyModel()->sortOrder()) {
1277 m_viewAccessor
.proxyModel()->setSortOrder(sortOrder
);
1278 emit
sortOrderChanged(sortOrder
);
1281 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1282 if (sortFoldersFirst
!= m_viewAccessor
.proxyModel()->sortFoldersFirst()) {
1283 m_viewAccessor
.proxyModel()->setSortFoldersFirst(sortFoldersFirst
);
1284 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1287 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1288 if (info
!= m_viewAccessor
.itemDelegate()->showInformation()) {
1289 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
1290 emit
additionalInfoChanged();
1293 const bool showPreview
= props
.showPreview();
1294 if (showPreview
!= m_showPreview
) {
1295 m_showPreview
= showPreview
;
1296 const int oldZoomLevel
= m_controller
->zoomLevel();
1297 emit
showPreviewChanged();
1299 // Enabling or disabling the preview might change the icon size of the view.
1300 // As the view does not emit a signal when the icon size has been changed,
1301 // the used zoom level of the controller must be adjusted manually:
1302 updateZoomLevel(oldZoomLevel
);
1305 if (DolphinSettings::instance().generalSettings()->globalViewProps()) {
1306 // During the lifetime of a DolphinView instance the global view properties
1307 // should not be changed. This allows e. g. to split a view and use different
1308 // view properties for each view.
1309 m_ignoreViewProperties
= true;
1313 void DolphinView::createView()
1317 Q_ASSERT(m_viewAccessor
.itemView() == 0);
1318 m_viewAccessor
.createView(this, m_controller
, m_mode
);
1320 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1321 Q_ASSERT(view
!= 0);
1322 view
->installEventFilter(this);
1323 view
->viewport()->installEventFilter(this);
1325 m_controller
->setItemView(view
);
1327 // When changing the view mode, the selection is lost due to reinstantiating
1328 // a new item view with a custom selection model. Pass the ownership of the
1329 // selection model to DolphinView, so that it can be shared by all item views.
1330 if (m_selectionModel
!= 0) {
1331 view
->setSelectionModel(m_selectionModel
);
1333 m_selectionModel
= view
->selectionModel();
1335 m_selectionModel
->setParent(this);
1336 connect(m_selectionModel
, SIGNAL(selectionChanged(QItemSelection
, QItemSelection
)),
1337 this, SLOT(slotSelectionChanged(QItemSelection
, QItemSelection
)));
1339 setFocusProxy(m_viewAccessor
.layoutTarget());
1340 m_topLayout
->insertWidget(1, m_viewAccessor
.layoutTarget());
1343 void DolphinView::deleteView()
1345 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1347 // It's important to set the keyboard focus to the parent
1348 // before deleting the view: Otherwise when having a split
1349 // view the other view will get the focus and will request
1350 // an activation (see DolphinView::eventFilter()).
1354 m_topLayout
->removeWidget(view
);
1357 // disconnect all signal/slots
1359 m_controller
->disconnect(view
);
1362 m_viewAccessor
.deleteView();
1366 void DolphinView::pasteToUrl(const KUrl
& url
)
1368 addNewFileNames(QApplication::clipboard()->mimeData());
1369 KonqOperations::doPaste(this, url
);
1372 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1374 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor
.itemView()->iconSize());
1375 if (oldZoomLevel
!= newZoomLevel
) {
1376 m_controller
->setZoomLevel(newZoomLevel
);
1377 emit
zoomLevelChanged(newZoomLevel
);
1381 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1383 KUrl::List list
= selectedUrls();
1384 if (itemsExpandable() ) {
1385 list
= KDirModel::simplifiedUrlList(list
);
1390 QMimeData
* DolphinView::selectionMimeData() const
1392 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1393 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
1394 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
1395 return m_viewAccessor
.dirModel()->mimeData(selection
.indexes());
1398 void DolphinView::addNewFileNames(const QMimeData
* mimeData
)
1400 const KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1401 foreach (const KUrl
& url
, urls
) {
1402 m_newFileNames
.insert(url
.fileName());
1406 DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel
* proxyModel
) :
1409 m_columnsContainer(0),
1410 m_proxyModel(proxyModel
),
1415 DolphinView::ViewAccessor::~ViewAccessor()
1417 delete m_dragSource
;
1421 void DolphinView::ViewAccessor::createView(QWidget
* parent
,
1422 DolphinController
* controller
,
1425 Q_ASSERT(itemView() == 0);
1429 m_iconsView
= new DolphinIconsView(parent
, controller
, m_proxyModel
);
1433 m_detailsView
= new DolphinDetailsView(parent
, controller
, m_proxyModel
);
1437 m_columnsContainer
= new DolphinColumnViewContainer(parent
, controller
);
1445 void DolphinView::ViewAccessor::deleteView()
1447 QAbstractItemView
* view
= itemView();
1449 if (DragAndDropHelper::instance().isDragSource(view
)) {
1450 // The view is a drag source (the feature "Open folders
1451 // during drag operations" is used). Deleting the view
1452 // during an ongoing drag operation is not allowed, so
1453 // this will postponed.
1454 if (m_dragSource
!= 0) {
1455 // the old stored view is obviously not the drag source anymore
1456 m_dragSource
->deleteLater();
1460 m_dragSource
= view
;
1462 view
->deleteLater();
1469 if (m_columnsContainer
!= 0) {
1470 m_columnsContainer
->deleteLater();
1472 m_columnsContainer
= 0;
1476 void DolphinView::ViewAccessor::prepareUrlChange(const KUrl
& url
)
1478 if (m_columnsContainer
!= 0) {
1479 m_columnsContainer
->showColumn(url
);
1483 QAbstractItemView
* DolphinView::ViewAccessor::itemView() const
1485 if (m_iconsView
!= 0) {
1489 if (m_detailsView
!= 0) {
1490 return m_detailsView
;
1493 if (m_columnsContainer
!= 0) {
1494 return m_columnsContainer
->activeColumn();
1500 KFileItemDelegate
* DolphinView::ViewAccessor::itemDelegate() const
1502 return static_cast<KFileItemDelegate
*>(itemView()->itemDelegate());
1505 QWidget
* DolphinView::ViewAccessor::layoutTarget() const
1507 if (m_columnsContainer
!= 0) {
1508 return m_columnsContainer
;
1513 KUrl
DolphinView::ViewAccessor::rootUrl() const
1515 return (m_columnsContainer
!= 0) ? m_columnsContainer
->rootUrl() : KUrl();
1518 KDirLister
* DolphinView::ViewAccessor::rootDirLister() const
1520 return static_cast<DolphinModel
*>(m_proxyModel
->sourceModel())->dirLister();
1523 bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
1525 return m_iconsView
!= 0;
1528 bool DolphinView::ViewAccessor::itemsExpandable() const
1530 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1534 QSet
<KUrl
> DolphinView::ViewAccessor::expandedUrls() const
1536 if (m_detailsView
!= 0) {
1537 return m_detailsView
->expandedUrls();
1540 return QSet
<KUrl
>();
1543 const DolphinDetailsViewExpander
* DolphinView::ViewAccessor::setExpandedUrls(const QSet
<KUrl
>& urlsToExpand
)
1545 if ((m_detailsView
!= 0) && m_detailsView
->itemsExpandable() && !urlsToExpand
.isEmpty()) {
1546 // Check if another expander is already active and stop it if necessary.
1547 if(!m_detailsViewExpander
.isNull()) {
1548 m_detailsViewExpander
->stop();
1551 m_detailsViewExpander
= new DolphinDetailsViewExpander(m_detailsView
, urlsToExpand
);
1552 return m_detailsViewExpander
;
1559 bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const
1561 // the details view requires no reloading of the directory, as it maps
1562 // the file item delegate info to its columns internally
1563 return m_detailsView
!= 0;
1566 DolphinModel
* DolphinView::ViewAccessor::dirModel() const
1568 return static_cast<DolphinModel
*>(proxyModel()->sourceModel());
1571 DolphinSortFilterProxyModel
* DolphinView::ViewAccessor::proxyModel() const
1573 if (m_columnsContainer
!= 0) {
1574 return static_cast<DolphinSortFilterProxyModel
*>(m_columnsContainer
->activeColumn()->model());
1576 return m_proxyModel
;
1579 KDirLister
* DolphinView::ViewAccessor::dirLister() const
1581 return dirModel()->dirLister();
1584 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1586 emit
redirection(oldUrl
, newUrl
);
1587 m_controller
->redirectToUrl(newUrl
); // #186947
1590 void DolphinView::restoreContentsPosition()
1592 if (!m_restoredContentsPosition
.isNull()) {
1593 const int x
= m_restoredContentsPosition
.x();
1594 const int y
= m_restoredContentsPosition
.y();
1595 m_restoredContentsPosition
= QPoint();
1597 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1598 Q_ASSERT(view
!= 0);
1599 view
->horizontalScrollBar()->setValue(x
);
1600 view
->verticalScrollBar()->setValue(y
);
1604 #include "dolphinview.moc"