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>
37 #include <kfileitemlistproperties.h>
39 #include <kio/deletejob.h>
40 #include <kio/netaccess.h>
41 #include <kio/previewjob.h>
44 #include <kmessagebox.h>
45 #include <konq_fileitemcapabilities.h>
46 #include <konq_operations.h>
47 #include <konqmimedata.h>
48 #include <ktoggleaction.h>
51 #include "additionalinfoaccessor.h"
52 #include "dolphinmodel.h"
53 #include "dolphincolumnviewcontainer.h"
54 #include "dolphinviewcontroller.h"
55 #include "dolphindetailsview.h"
56 #include "dolphinfileitemdelegate.h"
57 #include "dolphinnewfilemenuobserver.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 "viewmodecontroller.h"
66 #include "viewproperties.h"
67 #include "zoomlevelinfo.h"
68 #include "dolphindetailsviewexpander.h"
70 DolphinView::DolphinView(QWidget
* parent
,
72 DolphinSortFilterProxyModel
* proxyModel
) :
76 m_storedCategorizedSorting(false),
77 m_tabsForFiles(false),
78 m_isContextMenuOpen(false),
79 m_assureVisibleCurrentIndex(false),
80 m_expanderActive(false),
81 m_isFolderWritable(true),
82 m_mode(DolphinView::IconsView
),
84 m_dolphinViewController(0),
85 m_viewModeController(0),
86 m_viewAccessor(proxyModel
),
87 m_selectionChangedTimer(0),
89 m_restoredContentsPosition(),
94 m_topLayout
= new QVBoxLayout(this);
95 m_topLayout
->setSpacing(0);
96 m_topLayout
->setMargin(0);
98 m_dolphinViewController
= new DolphinViewController(this);
100 m_viewModeController
= new ViewModeController(this);
101 m_viewModeController
->setUrl(url
);
103 connect(m_viewModeController
, SIGNAL(urlChanged(const KUrl
&)),
104 this, SIGNAL(urlChanged(const KUrl
&)));
106 connect(m_dolphinViewController
, SIGNAL(requestContextMenu(const QPoint
&, const QList
<QAction
*>&)),
107 this, SLOT(openContextMenu(const QPoint
&, const QList
<QAction
*>&)));
108 connect(m_dolphinViewController
, SIGNAL(urlsDropped(const KFileItem
&, const KUrl
&, QDropEvent
*)),
109 this, SLOT(dropUrls(const KFileItem
&, const KUrl
&, QDropEvent
*)));
110 connect(m_dolphinViewController
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
111 this, SLOT(updateSorting(DolphinView::Sorting
)));
112 connect(m_dolphinViewController
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
113 this, SLOT(updateSortOrder(Qt::SortOrder
)));
114 connect(m_dolphinViewController
, SIGNAL(sortFoldersFirstChanged(bool)),
115 this, SLOT(updateSortFoldersFirst(bool)));
116 connect(m_dolphinViewController
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
117 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
118 connect(m_dolphinViewController
, SIGNAL(itemTriggered(const KFileItem
&)),
119 this, SLOT(triggerItem(const KFileItem
&)));
120 connect(m_dolphinViewController
, SIGNAL(tabRequested(const KUrl
&)),
121 this, SIGNAL(tabRequested(const KUrl
&)));
122 connect(m_dolphinViewController
, SIGNAL(activated()),
123 this, SLOT(activate()));
124 connect(m_dolphinViewController
, SIGNAL(itemEntered(const KFileItem
&)),
125 this, SLOT(showHoverInformation(const KFileItem
&)));
126 connect(m_dolphinViewController
, SIGNAL(viewportEntered()),
127 this, SLOT(clearHoverInformation()));
128 connect(m_dolphinViewController
, SIGNAL(urlChangeRequested(KUrl
)),
129 this, SLOT(slotUrlChangeRequested(KUrl
)));
131 // When a new item has been created by the "Create New..." menu, the item should
132 // get selected and it must be assured that the item will get visible. As the
133 // creation is done asynchronously, several signals must be checked:
134 connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(itemCreated(const KUrl
&)),
135 this, SLOT(observeCreatedItem(const KUrl
&)));
137 m_selectionChangedTimer
= new QTimer(this);
138 m_selectionChangedTimer
->setSingleShot(true);
139 m_selectionChangedTimer
->setInterval(300);
140 connect(m_selectionChangedTimer
, SIGNAL(timeout()),
141 this, SLOT(emitSelectionChangedSignal()));
143 applyViewProperties();
144 m_topLayout
->addWidget(m_viewAccessor
.layoutTarget());
147 DolphinView::~DolphinView()
151 KUrl
DolphinView::url() const
153 return m_viewModeController
->url();
156 KUrl
DolphinView::rootUrl() const
158 const KUrl viewUrl
= url();
159 const KUrl root
= m_viewAccessor
.rootUrl();
160 if (root
.isEmpty() || !root
.isParentOf(viewUrl
)) {
166 void DolphinView::setActive(bool active
)
168 if (active
== m_active
) {
174 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
179 QWidget
* viewport
= m_viewAccessor
.itemView()->viewport();
181 palette
.setColor(viewport
->backgroundRole(), color
);
182 viewport
->setPalette(palette
);
187 m_viewAccessor
.itemView()->setFocus();
189 emitSelectionChangedSignal();
190 emit
writeStateChanged(m_isFolderWritable
);
193 m_viewModeController
->indicateActivationChange(active
);
196 bool DolphinView::isActive() const
201 void DolphinView::setMode(Mode mode
)
203 if (mode
== m_mode
) {
204 return; // the wished mode is already set
207 const int oldZoomLevel
= m_viewModeController
->zoomLevel();
210 // remember the currently selected items, so that they will
211 // be restored after reloading the directory
212 m_selectedItems
= selectedItems();
216 const KUrl viewPropsUrl
= rootUrl();
217 ViewProperties
props(viewPropsUrl
);
218 props
.setViewMode(m_mode
);
221 // the file item delegate has been recreated, apply the current
222 // additional information manually
223 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
224 m_viewAccessor
.itemDelegate()->setShowInformation(infoList
);
225 emit
additionalInfoChanged();
227 // Not all view modes support categorized sorting. Adjust the sorting model
228 // if changing the view mode results in a change of the categorized sorting
230 m_storedCategorizedSorting
= props
.categorizedSorting();
231 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
232 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
233 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
234 emit
categorizedSortingChanged();
239 updateZoomLevel(oldZoomLevel
);
240 loadDirectory(viewPropsUrl
);
243 DolphinView::Mode
DolphinView::mode() const
248 bool DolphinView::showPreview() const
250 return m_showPreview
;
253 bool DolphinView::showHiddenFiles() const
255 return m_viewAccessor
.dirLister()->showingDotFiles();
258 bool DolphinView::categorizedSorting() const
260 // If all view modes would support categorized sorting, returning
261 // m_viewAccessor.proxyModel()->isCategorizedModel() would be the way to go. As
262 // currently only the icons view supports caterized sorting, we remember
263 // the stored view properties state in m_storedCategorizedSorting and
264 // return this state. The application takes care to disable the corresponding
265 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
266 // that this setting is not applied to the current view mode.
267 return m_storedCategorizedSorting
;
270 bool DolphinView::supportsCategorizedSorting() const
272 return m_viewAccessor
.supportsCategorizedSorting();
275 KFileItemList
DolphinView::items() const
277 return m_viewAccessor
.dirLister()->items();
280 KFileItemList
DolphinView::selectedItems() const
282 KFileItemList itemList
;
283 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
288 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
290 const QModelIndexList indexList
= selection
.indexes();
291 foreach (const QModelIndex
&index
, indexList
) {
292 KFileItem item
= m_viewAccessor
.dirModel()->itemForIndex(index
);
293 if (!item
.isNull()) {
294 itemList
.append(item
);
301 int DolphinView::selectedItemsCount() const
303 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
308 return view
->selectionModel()->selectedIndexes().count();
311 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
313 foreach (const KUrl
& url
, urls
) {
314 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url
);
315 m_selectedItems
.append(item
);
319 void DolphinView::setItemSelectionEnabled(const QRegExp
& pattern
, bool enabled
)
321 const QItemSelection matchingIndexes
= childrenMatchingPattern(QModelIndex(), pattern
);
322 const QItemSelectionModel::SelectionFlags command
= enabled
323 ? QItemSelectionModel::Select
324 : QItemSelectionModel::Deselect
;
325 m_viewAccessor
.itemView()->selectionModel()->select(matchingIndexes
, command
);
328 void DolphinView::setZoomLevel(int level
)
330 if (level
< ZoomLevelInfo::minimumLevel()) {
331 level
= ZoomLevelInfo::minimumLevel();
332 } else if (level
> ZoomLevelInfo::maximumLevel()) {
333 level
= ZoomLevelInfo::maximumLevel();
336 if (level
!= zoomLevel()) {
337 m_viewModeController
->setZoomLevel(level
);
338 emit
zoomLevelChanged(level
);
342 int DolphinView::zoomLevel() const
344 return m_viewModeController
->zoomLevel();
347 void DolphinView::setSorting(Sorting sorting
)
349 if (sorting
!= this->sorting()) {
350 updateSorting(sorting
);
354 DolphinView::Sorting
DolphinView::sorting() const
356 return m_viewAccessor
.proxyModel()->sorting();
359 void DolphinView::setSortOrder(Qt::SortOrder order
)
361 if (sortOrder() != order
) {
362 updateSortOrder(order
);
366 Qt::SortOrder
DolphinView::sortOrder() const
368 return m_viewAccessor
.proxyModel()->sortOrder();
371 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
373 if (sortFoldersFirst() != foldersFirst
) {
374 updateSortFoldersFirst(foldersFirst
);
378 bool DolphinView::sortFoldersFirst() const
380 return m_viewAccessor
.proxyModel()->sortFoldersFirst();
383 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
385 const KUrl viewPropsUrl
= rootUrl();
386 ViewProperties
props(viewPropsUrl
);
387 props
.setAdditionalInfo(info
);
388 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
390 emit
additionalInfoChanged();
392 if (m_viewAccessor
.reloadOnAdditionalInfoChange()) {
393 loadDirectory(viewPropsUrl
);
397 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
399 return m_viewAccessor
.itemDelegate()->showInformation();
402 void DolphinView::reload()
404 QByteArray viewState
;
405 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
406 saveState(saveStream
);
407 m_selectedItems
= selectedItems();
410 loadDirectory(url(), true);
412 QDataStream
restoreStream(viewState
);
413 restoreState(restoreStream
);
416 void DolphinView::stopLoading()
418 m_viewAccessor
.dirLister()->stop();
421 void DolphinView::refresh()
423 const bool oldActivationState
= m_active
;
424 const int oldZoomLevel
= m_viewModeController
->zoomLevel();
428 applyViewProperties();
431 setActive(oldActivationState
);
432 updateZoomLevel(oldZoomLevel
);
435 void DolphinView::setNameFilter(const QString
& nameFilter
)
437 m_viewModeController
->setNameFilter(nameFilter
);
440 void DolphinView::calculateItemCount(int& fileCount
,
442 KIO::filesize_t
& totalFileSize
) const
444 foreach (const KFileItem
& item
, m_viewAccessor
.dirLister()->items()) {
449 totalFileSize
+= item
.size();
454 QString
DolphinView::statusBarText() const
459 KIO::filesize_t totalFileSize
= 0;
461 if (hasSelection()) {
462 // give a summary of the status of the selected files
463 const KFileItemList list
= selectedItems();
464 if (list
.isEmpty()) {
465 // when an item is triggered, it is temporary selected but selectedItems()
466 // will return an empty list
470 KFileItemList::const_iterator it
= list
.begin();
471 const KFileItemList::const_iterator end
= list
.end();
473 const KFileItem
& item
= *it
;
478 totalFileSize
+= item
.size();
483 if (folderCount
+ fileCount
== 1) {
484 // if only one item is selected, show the filename
485 const QString name
= list
.first().text();
486 text
= (folderCount
== 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name
) :
487 i18nc("@info:status", "<filename>%1</filename> selected (%2)",
488 name
, KIO::convertSize(totalFileSize
));
490 // at least 2 items are selected
491 const QString foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
492 const QString filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
493 if ((folderCount
> 0) && (fileCount
> 0)) {
494 text
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
495 foldersText
, filesText
, KIO::convertSize(totalFileSize
));
496 } else if (fileCount
> 0) {
497 text
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KIO::convertSize(totalFileSize
));
499 Q_ASSERT(folderCount
> 0);
504 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
505 text
= KIO::itemsSummaryString(fileCount
+ folderCount
,
506 fileCount
, folderCount
,
507 totalFileSize
, true);
513 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
515 return m_dolphinViewController
->versionControlActions(items
);
518 void DolphinView::setUrl(const KUrl
& url
)
520 if (m_viewModeController
->url() == url
) {
524 const bool hadSelection
= hasSelection();
526 // The selection model and directory lister might change in the case of the column view:
527 disconnectViewAccessor();
529 m_newFileNames
.clear();
531 m_viewModeController
->setUrl(url
); // emits urlChanged, which we forward
532 m_viewAccessor
.prepareUrlChange(url
);
533 applyViewProperties();
535 // When changing the URL there is no need to keep the version
536 // data of the previous URL.
537 m_viewAccessor
.dirModel()->clearVersionData();
539 // Reconnect to the (probably) new selection model and directory lister
540 connectViewAccessor();
543 if (hadSelection
|| hasSelection()) {
544 emitSelectionChangedSignal();
548 void DolphinView::selectAll()
550 m_viewAccessor
.itemView()->selectAll();
553 void DolphinView::invertSelection()
555 QItemSelectionModel
* selectionModel
= m_viewAccessor
.itemView()->selectionModel();
556 const QAbstractItemModel
* itemModel
= selectionModel
->model();
558 const QModelIndex topLeft
= itemModel
->index(0, 0);
559 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
560 itemModel
->columnCount() - 1);
562 const QItemSelection
selection(topLeft
, bottomRight
);
563 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
566 void DolphinView::clearSelection()
568 m_viewAccessor
.itemView()->clearSelection();
571 void DolphinView::renameSelectedItems()
573 KFileItemList items
= selectedItems();
574 const int itemCount
= items
.count();
579 if ((itemCount
== 1) && DolphinSettings::instance().generalSettings()->renameInline()) {
580 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForItem(items
.first());
581 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
582 m_viewAccessor
.itemView()->edit(proxyIndex
);
584 RenameDialog
* dialog
= new RenameDialog(this, items
);
585 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
588 dialog
->activateWindow();
592 void DolphinView::trashSelectedItems()
594 const KUrl::List list
= simplifiedSelectedUrls();
595 KonqOperations::del(this, KonqOperations::TRASH
, list
);
598 void DolphinView::deleteSelectedItems()
600 const KUrl::List list
= simplifiedSelectedUrls();
601 const bool del
= KonqOperations::askDeleteConfirmation(list
,
603 KonqOperations::DEFAULT_CONFIRMATION
,
607 KIO::Job
* job
= KIO::del(list
);
608 connect(job
, SIGNAL(result(KJob
*)),
609 this, SLOT(slotDeleteFileFinished(KJob
*)));
613 void DolphinView::cutSelectedItems()
615 QMimeData
* mimeData
= selectionMimeData();
616 KonqMimeData::addIsCutSelection(mimeData
, true);
617 QApplication::clipboard()->setMimeData(mimeData
);
620 void DolphinView::copySelectedItems()
622 QMimeData
* mimeData
= selectionMimeData();
623 QApplication::clipboard()->setMimeData(mimeData
);
626 void DolphinView::paste()
631 void DolphinView::pasteIntoFolder()
633 const KFileItemList items
= selectedItems();
634 if ((items
.count() == 1) && items
.first().isDir()) {
635 pasteToUrl(items
.first().url());
639 void DolphinView::setShowPreview(bool show
)
641 if (m_showPreview
== show
) {
645 const KUrl viewPropsUrl
= rootUrl();
646 ViewProperties
props(viewPropsUrl
);
647 props
.setShowPreview(show
);
649 m_showPreview
= show
;
650 const int oldZoomLevel
= m_viewModeController
->zoomLevel();
651 emit
showPreviewChanged();
653 // Enabling or disabling the preview might change the icon size of the view.
654 // As the view does not emit a signal when the icon size has been changed,
655 // the used zoom level of the controller must be adjusted manually:
656 updateZoomLevel(oldZoomLevel
);
659 void DolphinView::setShowHiddenFiles(bool show
)
661 if (m_viewAccessor
.dirLister()->showingDotFiles() == show
) {
665 const KUrl viewPropsUrl
= rootUrl();
666 ViewProperties
props(viewPropsUrl
);
667 props
.setShowHiddenFiles(show
);
669 m_viewAccessor
.dirLister()->setShowingDotFiles(show
);
670 emit
showHiddenFilesChanged();
673 void DolphinView::setCategorizedSorting(bool categorized
)
675 if (categorized
== categorizedSorting()) {
679 // setCategorizedSorting(true) may only get invoked
680 // if the view supports categorized sorting
681 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
683 ViewProperties
props(rootUrl());
684 props
.setCategorizedSorting(categorized
);
687 m_storedCategorizedSorting
= categorized
;
688 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
690 emit
categorizedSortingChanged();
693 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
695 QWidget::mouseReleaseEvent(event
);
699 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
701 switch (event
->type()) {
702 case QEvent::FocusIn
:
703 if (watched
== m_viewAccessor
.itemView()) {
704 m_dolphinViewController
->requestActivation();
708 case QEvent::DragEnter
:
709 if (watched
== m_viewAccessor
.itemView()->viewport()) {
714 case QEvent::KeyPress
:
715 if (watched
== m_viewAccessor
.itemView()) {
716 // clear the selection when Escape has been pressed
717 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
718 if (keyEvent
->key() == Qt::Key_Escape
) {
725 if (watched
== m_viewAccessor
.itemView()->viewport()) {
726 // Ctrl+wheel events should cause icon zooming, but not if the left mouse button is pressed
727 // (the user is probably trying to scroll during a selection in that case)
728 QWheelEvent
* wheelEvent
= static_cast<QWheelEvent
*>(event
);
729 if (wheelEvent
->modifiers() & Qt::ControlModifier
&& !(wheelEvent
->buttons() & Qt::LeftButton
)) {
730 const int delta
= wheelEvent
->delta();
731 const int level
= zoomLevel();
733 setZoomLevel(level
+ 1);
734 } else if (delta
< 0) {
735 setZoomLevel(level
- 1);
746 return QWidget::eventFilter(watched
, event
);
749 void DolphinView::activate()
754 void DolphinView::triggerItem(const KFileItem
& item
)
756 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
757 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
758 // items are selected by the user, hence don't trigger the
759 // item specified by 'index'
763 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
764 if (item
.isNull() || m_isContextMenuOpen
) {
768 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
771 void DolphinView::slotSelectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
)
773 const int count
= selectedItemsCount();
774 const bool selectionStateChanged
= ((count
> 0) && (selected
.count() == count
)) ||
775 ((count
== 0) && !deselected
.isEmpty());
777 // If nothing has been selected before and something got selected (or if something
778 // was selected before and now nothing is selected) the selectionChangedSignal must
779 // be emitted asynchronously as fast as possible to update the edit-actions.
780 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
781 m_selectionChangedTimer
->start();
784 void DolphinView::emitSelectionChangedSignal()
786 m_selectionChangedTimer
->stop();
787 emit
selectionChanged(selectedItems());
790 void DolphinView::openContextMenu(const QPoint
& pos
,
791 const QList
<QAction
*>& customActions
)
794 const QModelIndex index
= m_viewAccessor
.itemView()->indexAt(pos
);
795 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
796 const QModelIndex dolphinModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(index
);
797 item
= m_viewAccessor
.dirModel()->itemForIndex(dolphinModelIndex
);
800 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
801 emit
requestContextMenu(item
, url(), customActions
);
802 m_isContextMenuOpen
= false;
805 void DolphinView::dropUrls(const KFileItem
& destItem
,
806 const KUrl
& destPath
,
809 addNewFileNames(event
->mimeData());
810 DragAndDropHelper::instance().dropUrls(destItem
, destPath
, event
, this);
813 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
815 ViewProperties
props(rootUrl());
816 props
.setSorting(sorting
);
818 m_viewAccessor
.proxyModel()->setSorting(sorting
);
820 emit
sortingChanged(sorting
);
823 void DolphinView::updateSortOrder(Qt::SortOrder order
)
825 ViewProperties
props(rootUrl());
826 props
.setSortOrder(order
);
828 m_viewAccessor
.proxyModel()->setSortOrder(order
);
830 emit
sortOrderChanged(order
);
833 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
835 ViewProperties
props(rootUrl());
836 props
.setSortFoldersFirst(foldersFirst
);
838 m_viewAccessor
.proxyModel()->setSortFoldersFirst(foldersFirst
);
840 emit
sortFoldersFirstChanged(foldersFirst
);
843 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
845 ViewProperties
props(rootUrl());
846 props
.setAdditionalInfo(info
);
849 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
851 emit
additionalInfoChanged();
854 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
856 const AdditionalInfoAccessor
& infoAccessor
= AdditionalInfoAccessor::instance();
858 const KFileItemDelegate::InformationList checkedInfo
= m_viewAccessor
.itemDelegate()->showInformation();
859 const KFileItemDelegate::InformationList infoKeys
= infoAccessor
.keys();
861 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
862 (m_mode
== DolphinView::IconsView
);
864 foreach (const KFileItemDelegate::Information
& info
, infoKeys
) {
865 const QString name
= infoAccessor
.actionCollectionName(info
, AdditionalInfoAccessor::AdditionalInfoType
);
866 QAction
* action
= collection
->action(name
);
867 Q_ASSERT(action
!= 0);
868 action
->setEnabled(enable
);
869 action
->setChecked(checkedInfo
.contains(info
));
873 QPair
<bool, QString
> DolphinView::pasteInfo() const
875 return KonqOperations::pasteInfo(url());
878 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
880 m_tabsForFiles
= tabsForFiles
;
883 bool DolphinView::isTabsForFilesEnabled() const
885 return m_tabsForFiles
;
888 bool DolphinView::itemsExpandable() const
890 return m_viewAccessor
.itemsExpandable();
893 void DolphinView::restoreState(QDataStream
& stream
)
895 // Restore the URL of the current item that had the keyboard focus
896 stream
>> m_activeItemUrl
;
898 // Restore the root URL
901 m_viewAccessor
.setRootUrl(rootUrl
);
903 // Restore the view position
904 stream
>> m_restoredContentsPosition
;
906 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
907 QSet
<KUrl
> urlsToExpand
;
908 stream
>> urlsToExpand
;
909 const DolphinDetailsViewExpander
* expander
= m_viewAccessor
.setExpandedUrls(urlsToExpand
);
911 m_expanderActive
= true;
912 connect (expander
, SIGNAL(completed()), this, SLOT(slotLoadingCompleted()));
915 m_expanderActive
= false;
919 void DolphinView::saveState(QDataStream
& stream
)
921 // Save the URL of the current item that has the keyboard focus
922 KFileItem currentItem
;
923 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
926 const QModelIndex proxyIndex
= view
->currentIndex();
927 const QModelIndex dirModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
928 currentItem
= m_viewAccessor
.dirModel()->itemForIndex(dirModelIndex
);
932 if (!currentItem
.isNull()) {
933 currentItemUrl
= currentItem
.url();
936 stream
<< currentItemUrl
;
939 stream
<< m_viewAccessor
.rootUrl();
941 // Save view position
942 const int x
= view
->horizontalScrollBar()->value();
943 const int y
= view
->verticalScrollBar()->value();
944 stream
<< QPoint(x
, y
);
946 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
947 stream
<< m_viewAccessor
.expandedUrls();
950 bool DolphinView::hasSelection() const
952 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
953 return (view
!= 0) && view
->selectionModel()->hasSelection();
956 void DolphinView::observeCreatedItem(const KUrl
& url
)
958 m_createdItemUrl
= url
;
959 connect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
960 this, SLOT(selectAndScrollToCreatedItem()));
963 void DolphinView::selectAndScrollToCreatedItem()
965 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_createdItemUrl
);
966 if (dirIndex
.isValid()) {
967 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
968 m_viewAccessor
.itemView()->setCurrentIndex(proxyIndex
);
971 disconnect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
972 this, SLOT(selectAndScrollToCreatedItem()));
973 m_createdItemUrl
= KUrl();
976 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
978 if (oldUrl
.equals(url(), KUrl::CompareWithoutTrailingSlash
)) {
979 emit
redirection(oldUrl
, newUrl
);
980 m_viewModeController
->redirectToUrl(newUrl
); // #186947
984 void DolphinView::restoreContentsPosition()
986 if (!m_restoredContentsPosition
.isNull()) {
987 const int x
= m_restoredContentsPosition
.x();
988 const int y
= m_restoredContentsPosition
.y();
989 m_restoredContentsPosition
= QPoint();
991 QAbstractItemView
* view
= m_viewAccessor
.itemView();
993 view
->horizontalScrollBar()->setValue(x
);
994 view
->verticalScrollBar()->setValue(y
);
998 void DolphinView::slotUrlChangeRequested(const KUrl
& url
)
1000 m_viewModeController
->setUrl(url
);
1001 updateWritableState();
1004 void DolphinView::showHoverInformation(const KFileItem
& item
)
1006 emit
requestItemInfo(item
);
1009 void DolphinView::clearHoverInformation()
1011 emit
requestItemInfo(KFileItem());
1014 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1016 if (job
->error() == 0) {
1017 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1018 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1019 emit
errorMessage(job
->errorString());
1023 void DolphinView::slotDirListerStarted(const KUrl
& url
)
1025 // Disable the writestate temporary until it can be determined in a fast way
1026 // in DolphinView::slotDirListerCompleted()
1027 if (m_isFolderWritable
) {
1028 m_isFolderWritable
= false;
1029 emit
writeStateChanged(m_isFolderWritable
);
1032 emit
startedPathLoading(url
);
1035 void DolphinView::slotDirListerCompleted()
1037 if (!m_expanderActive
) {
1038 slotLoadingCompleted();
1041 if (!m_newFileNames
.isEmpty()) {
1042 // select all newly added items created by a paste operation or
1043 // a drag & drop operation, and clear the previous selection
1044 m_viewAccessor
.itemView()->clearSelection();
1045 const int rowCount
= m_viewAccessor
.proxyModel()->rowCount();
1046 QItemSelection selection
;
1047 for (int row
= 0; row
< rowCount
; ++row
) {
1048 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->index(row
, 0);
1049 const QModelIndex dirIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1050 const KUrl url
= m_viewAccessor
.dirModel()->itemForIndex(dirIndex
).url();
1051 if (m_newFileNames
.contains(url
.fileName())) {
1052 selection
.merge(QItemSelection(proxyIndex
, proxyIndex
), QItemSelectionModel::Select
);
1055 m_viewAccessor
.itemView()->selectionModel()->select(selection
, QItemSelectionModel::Select
);
1057 m_newFileNames
.clear();
1060 updateWritableState();
1063 void DolphinView::slotLoadingCompleted()
1065 m_expanderActive
= false;
1067 if (!m_activeItemUrl
.isEmpty()) {
1068 // assure that the current item remains visible
1069 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_activeItemUrl
);
1070 if (dirIndex
.isValid()) {
1071 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1072 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1073 const bool clearSelection
= !hasSelection();
1074 view
->setCurrentIndex(proxyIndex
);
1075 if (clearSelection
) {
1076 view
->clearSelection();
1078 m_activeItemUrl
.clear();
1082 if (!m_selectedItems
.isEmpty()) {
1083 const KUrl
& baseUrl
= url();
1085 QItemSelection newSelection
;
1086 foreach(const KFileItem
& item
, m_selectedItems
) {
1087 url
= item
.url().upUrl();
1088 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
1089 QModelIndex index
= m_viewAccessor
.proxyModel()->mapFromSource(m_viewAccessor
.dirModel()->indexForItem(item
));
1090 newSelection
.select(index
, index
);
1093 m_viewAccessor
.itemView()->selectionModel()->select(newSelection
,
1094 QItemSelectionModel::ClearAndSelect
1095 | QItemSelectionModel::Current
);
1096 m_selectedItems
.clear();
1099 // Restore the contents position. This has to be done using a Qt::QueuedConnection
1100 // because the view might not be in its final state yet.
1101 QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection
);
1103 emit
finishedPathLoading(url());
1106 void DolphinView::slotRefreshItems()
1108 if (m_assureVisibleCurrentIndex
) {
1109 m_assureVisibleCurrentIndex
= false;
1110 m_viewAccessor
.itemView()->scrollTo(m_viewAccessor
.itemView()->currentIndex());
1114 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1116 if (!url
.isValid()) {
1117 const QString
location(url
.pathOrUrl());
1118 if (location
.isEmpty()) {
1119 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1121 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1126 KDirLister
* dirLister
= m_viewAccessor
.dirLister();
1127 dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1130 void DolphinView::applyViewProperties()
1132 const ViewProperties
props(rootUrl());
1134 const Mode mode
= props
.viewMode();
1135 if (m_mode
!= mode
) {
1136 const int oldZoomLevel
= m_viewModeController
->zoomLevel();
1142 updateZoomLevel(oldZoomLevel
);
1144 if (m_viewAccessor
.itemView() == 0) {
1148 Q_ASSERT(m_viewAccessor
.itemView() != 0);
1149 Q_ASSERT(m_viewAccessor
.itemDelegate() != 0);
1151 const bool showHiddenFiles
= props
.showHiddenFiles();
1152 if (showHiddenFiles
!= m_viewAccessor
.dirLister()->showingDotFiles()) {
1153 m_viewAccessor
.dirLister()->setShowingDotFiles(showHiddenFiles
);
1154 emit
showHiddenFilesChanged();
1157 m_storedCategorizedSorting
= props
.categorizedSorting();
1158 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1159 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
1160 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
1161 emit
categorizedSortingChanged();
1164 const DolphinView::Sorting sorting
= props
.sorting();
1165 if (sorting
!= m_viewAccessor
.proxyModel()->sorting()) {
1166 m_viewAccessor
.proxyModel()->setSorting(sorting
);
1167 emit
sortingChanged(sorting
);
1170 const Qt::SortOrder sortOrder
= props
.sortOrder();
1171 if (sortOrder
!= m_viewAccessor
.proxyModel()->sortOrder()) {
1172 m_viewAccessor
.proxyModel()->setSortOrder(sortOrder
);
1173 emit
sortOrderChanged(sortOrder
);
1176 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1177 if (sortFoldersFirst
!= m_viewAccessor
.proxyModel()->sortFoldersFirst()) {
1178 m_viewAccessor
.proxyModel()->setSortFoldersFirst(sortFoldersFirst
);
1179 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1182 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1183 if (info
!= m_viewAccessor
.itemDelegate()->showInformation()) {
1184 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
1185 emit
additionalInfoChanged();
1188 const bool showPreview
= props
.showPreview();
1189 if (showPreview
!= m_showPreview
) {
1190 m_showPreview
= showPreview
;
1191 const int oldZoomLevel
= m_viewModeController
->zoomLevel();
1192 emit
showPreviewChanged();
1194 // Enabling or disabling the preview might change the icon size of the view.
1195 // As the view does not emit a signal when the icon size has been changed,
1196 // the used zoom level of the controller must be adjusted manually:
1197 updateZoomLevel(oldZoomLevel
);
1201 void DolphinView::createView()
1205 Q_ASSERT(m_viewAccessor
.itemView() == 0);
1206 Q_ASSERT(m_dolphinViewController
->itemView() == 0);
1207 m_viewAccessor
.createView(this, m_dolphinViewController
, m_viewModeController
, m_mode
);
1209 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1210 Q_ASSERT(view
!= 0);
1211 view
->installEventFilter(this);
1212 view
->viewport()->installEventFilter(this);
1214 m_dolphinViewController
->setItemView(view
);
1216 const int zoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(view
->iconSize());
1217 m_viewModeController
->setZoomLevel(zoomLevel
);
1219 connectViewAccessor();
1221 setFocusProxy(m_viewAccessor
.layoutTarget());
1222 m_topLayout
->insertWidget(1, m_viewAccessor
.layoutTarget());
1225 void DolphinView::deleteView()
1227 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1228 Q_ASSERT((m_dolphinViewController
->itemView() == 0) || (m_dolphinViewController
->itemView() == view
));
1229 m_dolphinViewController
->setItemView(0);
1232 disconnectViewAccessor();
1234 // It's important to set the keyboard focus to the parent
1235 // before deleting the view: Otherwise when having a split
1236 // view the other view will get the focus and will request
1237 // an activation (see DolphinView::eventFilter()).
1241 m_viewModeController
->disconnect(view
);
1243 m_viewAccessor
.deleteView();
1247 void DolphinView::pasteToUrl(const KUrl
& url
)
1249 addNewFileNames(QApplication::clipboard()->mimeData());
1250 KonqOperations::doPaste(this, url
);
1253 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1255 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor
.itemView()->iconSize());
1256 if (oldZoomLevel
!= newZoomLevel
) {
1257 m_viewModeController
->setZoomLevel(newZoomLevel
);
1258 emit
zoomLevelChanged(newZoomLevel
);
1262 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1266 const KFileItemList items
= selectedItems();
1267 foreach (const KFileItem
&item
, items
) {
1268 urls
.append(item
.url());
1272 if (itemsExpandable()) {
1273 urls
= KDirModel::simplifiedUrlList(urls
);
1279 QMimeData
* DolphinView::selectionMimeData() const
1281 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1282 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
1283 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
1284 return m_viewAccessor
.dirModel()->mimeData(selection
.indexes());
1287 void DolphinView::addNewFileNames(const QMimeData
* mimeData
)
1289 const KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1290 foreach (const KUrl
& url
, urls
) {
1291 m_newFileNames
.insert(url
.fileName());
1295 QItemSelection
DolphinView::childrenMatchingPattern(const QModelIndex
& parent
, const QRegExp
& pattern
) const
1297 QItemSelection matchingIndexes
;
1298 const DolphinSortFilterProxyModel
* proxyModel
= m_viewAccessor
.proxyModel();
1299 const DolphinModel
* dolphinModel
= m_viewAccessor
.dirModel();
1301 const int rowCount
= proxyModel
->rowCount(parent
);
1303 for (int row
= 0; row
< rowCount
; ++row
) {
1304 QModelIndex index
= proxyModel
->index(row
, 0, parent
);
1305 QModelIndex sourceIndex
= proxyModel
->mapToSource(index
);
1307 if (sourceIndex
.isValid() && pattern
.exactMatch(dolphinModel
->data(sourceIndex
).toString())) {
1308 matchingIndexes
+= QItemSelectionRange(index
);
1311 if (proxyModel
->hasChildren(index
)) {
1312 matchingIndexes
+= childrenMatchingPattern(index
, pattern
);
1316 return matchingIndexes
;
1319 void DolphinView::connectViewAccessor()
1321 KDirLister
* dirLister
= m_viewAccessor
.dirLister();
1322 connect(dirLister
, SIGNAL(redirection(KUrl
,KUrl
)),
1323 this, SLOT(slotRedirection(KUrl
,KUrl
)));
1324 connect(dirLister
, SIGNAL(started(KUrl
)),
1325 this, SLOT(slotDirListerStarted(KUrl
)));
1326 connect(dirLister
, SIGNAL(completed()),
1327 this, SLOT(slotDirListerCompleted()));
1328 connect(dirLister
, SIGNAL(refreshItems(const QList
<QPair
<KFileItem
,KFileItem
>>&)),
1329 this, SLOT(slotRefreshItems()));
1331 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1332 connect(view
->selectionModel(), SIGNAL(selectionChanged(QItemSelection
, QItemSelection
)),
1333 this, SLOT(slotSelectionChanged(QItemSelection
, QItemSelection
)));
1336 void DolphinView::disconnectViewAccessor()
1338 KDirLister
* dirLister
= m_viewAccessor
.dirLister();
1339 disconnect(dirLister
, SIGNAL(redirection(KUrl
,KUrl
)),
1340 this, SLOT(slotRedirection(KUrl
,KUrl
)));
1341 disconnect(dirLister
, SIGNAL(started(KUrl
)),
1342 this, SLOT(slotDirListerStarted(KUrl
)));
1343 disconnect(dirLister
, SIGNAL(completed()),
1344 this, SLOT(slotDirListerCompleted()));
1345 disconnect(dirLister
, SIGNAL(refreshItems(const QList
<QPair
<KFileItem
,KFileItem
>>&)),
1346 this, SLOT(slotRefreshItems()));
1348 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1349 disconnect(view
->selectionModel(), SIGNAL(selectionChanged(QItemSelection
, QItemSelection
)),
1350 this, SLOT(slotSelectionChanged(QItemSelection
, QItemSelection
)));
1353 void DolphinView::updateWritableState()
1355 const bool wasFolderWritable
= m_isFolderWritable
;
1356 m_isFolderWritable
= true;
1358 const KFileItem item
= m_viewAccessor
.dirLister()->rootItem();
1359 if (!item
.isNull()) {
1360 KFileItemListProperties
capabilities(KFileItemList() << item
);
1361 m_isFolderWritable
= capabilities
.supportsWriting();
1363 if (m_isFolderWritable
!= wasFolderWritable
) {
1364 emit
writeStateChanged(m_isFolderWritable
);
1368 DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel
* proxyModel
) :
1372 m_columnsContainer(0),
1373 m_proxyModel(proxyModel
),
1378 DolphinView::ViewAccessor::~ViewAccessor()
1380 delete m_dragSource
;
1384 void DolphinView::ViewAccessor::createView(QWidget
* parent
,
1385 DolphinViewController
* dolphinViewController
,
1386 const ViewModeController
* viewModeController
,
1389 Q_ASSERT(itemView() == 0);
1393 m_iconsView
= new DolphinIconsView(parent
,
1394 dolphinViewController
,
1400 m_detailsView
= new DolphinDetailsView(parent
,
1401 dolphinViewController
,
1407 m_columnsContainer
= new DolphinColumnViewContainer(parent
,
1408 dolphinViewController
,
1409 viewModeController
);
1410 if (!m_rootUrl
.isEmpty() && m_rootUrl
.isParentOf(viewModeController
->url())) {
1411 // The column-view must show several columns starting with m_rootUrl as
1412 // first column and viewModeController->url() as last column.
1413 m_columnsContainer
->showColumn(m_rootUrl
);
1414 m_columnsContainer
->showColumn(viewModeController
->url());
1423 void DolphinView::ViewAccessor::deleteView()
1425 if (m_columnsContainer
!= 0) {
1426 m_columnsContainer
->close();
1427 m_columnsContainer
->disconnect();
1428 m_columnsContainer
->deleteLater();
1429 m_columnsContainer
= 0;
1431 QAbstractItemView
* view
= itemView();
1436 if (DragAndDropHelper::instance().isDragSource(view
)) {
1437 // The view is a drag source (the feature "Open folders
1438 // during drag operations" is used). Deleting the view
1439 // during an ongoing drag operation is not allowed, so
1440 // this will postponed.
1441 if (m_dragSource
!= 0) {
1442 // the old stored view is obviously not the drag source anymore
1443 m_dragSource
->deleteLater();
1447 m_dragSource
= view
;
1449 view
->deleteLater();
1459 void DolphinView::ViewAccessor::prepareUrlChange(const KUrl
& url
)
1461 if (m_columnsContainer
!= 0) {
1462 m_columnsContainer
->showColumn(url
);
1466 QAbstractItemView
* DolphinView::ViewAccessor::itemView() const
1468 if (m_iconsView
!= 0) {
1472 if (m_detailsView
!= 0) {
1473 return m_detailsView
;
1476 if (m_columnsContainer
!= 0) {
1477 return m_columnsContainer
->activeColumn();
1483 KFileItemDelegate
* DolphinView::ViewAccessor::itemDelegate() const
1485 return static_cast<KFileItemDelegate
*>(itemView()->itemDelegate());
1488 QWidget
* DolphinView::ViewAccessor::layoutTarget() const
1490 if (m_columnsContainer
!= 0) {
1491 return m_columnsContainer
;
1496 void DolphinView::ViewAccessor::setRootUrl(const KUrl
& rootUrl
)
1498 m_rootUrl
= rootUrl
;
1501 KUrl
DolphinView::ViewAccessor::rootUrl() const
1503 return (m_columnsContainer
!= 0) ? m_columnsContainer
->rootUrl() : m_rootUrl
;
1506 bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
1508 return m_iconsView
!= 0;
1511 bool DolphinView::ViewAccessor::itemsExpandable() const
1513 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1516 QSet
<KUrl
> DolphinView::ViewAccessor::expandedUrls() const
1518 if (m_detailsView
!= 0) {
1519 return m_detailsView
->expandedUrls();
1522 return QSet
<KUrl
>();
1525 const DolphinDetailsViewExpander
* DolphinView::ViewAccessor::setExpandedUrls(const QSet
<KUrl
>& urlsToExpand
)
1527 if ((m_detailsView
!= 0) && m_detailsView
->itemsExpandable() && !urlsToExpand
.isEmpty()) {
1528 // Check if another expander is already active and stop it if necessary.
1529 if(!m_detailsViewExpander
.isNull()) {
1530 m_detailsViewExpander
->stop();
1533 m_detailsViewExpander
= new DolphinDetailsViewExpander(m_detailsView
, urlsToExpand
);
1534 return m_detailsViewExpander
;
1541 bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const
1543 // the details view requires no reloading of the directory, as it maps
1544 // the file item delegate info to its columns internally
1545 return m_detailsView
!= 0;
1548 DolphinModel
* DolphinView::ViewAccessor::dirModel() const
1550 return static_cast<DolphinModel
*>(proxyModel()->sourceModel());
1553 DolphinSortFilterProxyModel
* DolphinView::ViewAccessor::proxyModel() const
1555 if (m_columnsContainer
!= 0) {
1556 return static_cast<DolphinSortFilterProxyModel
*>(m_columnsContainer
->activeColumn()->model());
1558 return m_proxyModel
;
1561 KDirLister
* DolphinView::ViewAccessor::dirLister() const
1563 return dirModel()->dirLister();
1566 #include "dolphinview.moc"