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>
33 #include <KColorScheme>
35 #include <KIconEffect>
37 #include <KFileItemListProperties>
39 #include <KIO/DeleteJob>
40 #include <KIO/NetAccess>
41 #include <KIO/PreviewJob>
44 #include <KMessageBox>
45 #include <konq_fileitemcapabilities.h>
46 #include <konq_operations.h>
47 #include <konqmimedata.h>
48 #include <KToggleAction>
51 #include "additionalinfoaccessor.h"
52 #include "dolphindirlister.h"
53 #include "dolphinmodel.h"
54 #include "dolphincolumnviewcontainer.h"
55 #include "dolphinviewcontroller.h"
56 #include "dolphindetailsview.h"
57 #include "dolphinfileitemdelegate.h"
58 #include "dolphinnewfilemenuobserver.h"
59 #include "dolphinsortfilterproxymodel.h"
60 #include "dolphin_detailsmodesettings.h"
61 #include "dolphiniconsview.h"
62 #include "dolphin_generalsettings.h"
63 #include "draganddrophelper.h"
64 #include "renamedialog.h"
65 #include "settings/dolphinsettings.h"
66 #include "viewmodecontroller.h"
67 #include "viewproperties.h"
68 #include "zoomlevelinfo.h"
69 #include "dolphindetailsviewexpander.h"
71 DolphinView::DolphinView(const KUrl
& url
, QWidget
* parent
) :
75 m_storedCategorizedSorting(false),
76 m_tabsForFiles(false),
77 m_isContextMenuOpen(false),
78 m_assureVisibleCurrentIndex(false),
79 m_expanderActive(false),
80 m_isFolderWritable(true),
81 m_mode(DolphinView::IconsView
),
83 m_dolphinViewController(0),
84 m_viewModeController(0),
86 m_selectionChangedTimer(0),
88 m_restoredContentsPosition(),
93 m_topLayout
= new QVBoxLayout(this);
94 m_topLayout
->setSpacing(0);
95 m_topLayout
->setMargin(0);
97 m_dolphinViewController
= new DolphinViewController(this);
99 m_viewModeController
= new ViewModeController(this);
100 m_viewModeController
->setUrl(url
);
102 connect(m_viewModeController
, SIGNAL(urlChanged(const KUrl
&)),
103 this, SIGNAL(urlChanged(const KUrl
&)));
105 connect(m_dolphinViewController
, SIGNAL(requestContextMenu(const QPoint
&, const QList
<QAction
*>&)),
106 this, SLOT(openContextMenu(const QPoint
&, const QList
<QAction
*>&)));
107 connect(m_dolphinViewController
, SIGNAL(urlsDropped(const KFileItem
&, const KUrl
&, QDropEvent
*)),
108 this, SLOT(dropUrls(const KFileItem
&, const KUrl
&, QDropEvent
*)));
109 connect(m_dolphinViewController
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
110 this, SLOT(updateSorting(DolphinView::Sorting
)));
111 connect(m_dolphinViewController
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
112 this, SLOT(updateSortOrder(Qt::SortOrder
)));
113 connect(m_dolphinViewController
, SIGNAL(sortFoldersFirstChanged(bool)),
114 this, SLOT(updateSortFoldersFirst(bool)));
115 connect(m_dolphinViewController
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
116 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
117 connect(m_dolphinViewController
, SIGNAL(itemTriggered(const KFileItem
&)),
118 this, SLOT(triggerItem(const KFileItem
&)));
119 connect(m_dolphinViewController
, SIGNAL(tabRequested(const KUrl
&)),
120 this, SIGNAL(tabRequested(const KUrl
&)));
121 connect(m_dolphinViewController
, SIGNAL(activated()),
122 this, SLOT(activate()));
123 connect(m_dolphinViewController
, SIGNAL(itemEntered(const KFileItem
&)),
124 this, SLOT(showHoverInformation(const KFileItem
&)));
125 connect(m_dolphinViewController
, SIGNAL(viewportEntered()),
126 this, SLOT(clearHoverInformation()));
127 connect(m_dolphinViewController
, SIGNAL(urlChangeRequested(KUrl
)),
128 this, SLOT(slotUrlChangeRequested(KUrl
)));
130 // When a new item has been created by the "Create New..." menu, the item should
131 // get selected and it must be assured that the item will get visible. As the
132 // creation is done asynchronously, several signals must be checked:
133 connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(itemCreated(const KUrl
&)),
134 this, SLOT(observeCreatedItem(const KUrl
&)));
136 m_selectionChangedTimer
= new QTimer(this);
137 m_selectionChangedTimer
->setSingleShot(true);
138 m_selectionChangedTimer
->setInterval(300);
139 connect(m_selectionChangedTimer
, SIGNAL(timeout()),
140 this, SLOT(emitSelectionChangedSignal()));
142 applyViewProperties();
143 m_topLayout
->addWidget(m_viewAccessor
.layoutTarget());
146 DolphinView::~DolphinView()
150 KUrl
DolphinView::url() const
152 return m_viewModeController
->url();
155 KUrl
DolphinView::rootUrl() const
157 const KUrl viewUrl
= url();
158 const KUrl root
= m_viewAccessor
.rootUrl();
159 if (root
.isEmpty() || !root
.isParentOf(viewUrl
)) {
165 void DolphinView::setActive(bool active
)
167 if (active
== m_active
) {
173 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
178 QWidget
* viewport
= m_viewAccessor
.itemView()->viewport();
180 palette
.setColor(viewport
->backgroundRole(), color
);
181 viewport
->setPalette(palette
);
186 m_viewAccessor
.itemView()->setFocus();
188 emitSelectionChangedSignal();
189 emit
writeStateChanged(m_isFolderWritable
);
192 m_viewModeController
->indicateActivationChange(active
);
195 bool DolphinView::isActive() const
200 void DolphinView::setMode(Mode mode
)
202 if (mode
== m_mode
) {
203 return; // the wished mode is already set
206 const int oldZoomLevel
= m_viewModeController
->zoomLevel();
209 // remember the currently selected items, so that they will
210 // be restored after reloading the directory
211 m_selectedItems
= selectedItems();
213 const bool hasFocus
= m_viewAccessor
.itemView()->hasFocus();
216 const KUrl viewPropsUrl
= rootUrl();
217 ViewProperties
props(viewPropsUrl
);
218 props
.setViewMode(m_mode
);
222 m_viewAccessor
.itemView()->setFocus();
225 // the file item delegate has been recreated, apply the current
226 // additional information manually
227 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
228 m_viewAccessor
.itemDelegate()->setShowInformation(infoList
);
229 emit
additionalInfoChanged();
231 // Not all view modes support categorized sorting. Adjust the sorting model
232 // if changing the view mode results in a change of the categorized sorting
234 m_storedCategorizedSorting
= props
.categorizedSorting();
235 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
236 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
237 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
238 emit
categorizedSortingChanged();
243 updateZoomLevel(oldZoomLevel
);
244 loadDirectory(viewPropsUrl
);
247 DolphinView::Mode
DolphinView::mode() const
252 bool DolphinView::showPreview() const
254 return m_showPreview
;
257 bool DolphinView::showHiddenFiles() const
259 return m_viewAccessor
.dirLister()->showingDotFiles();
262 bool DolphinView::categorizedSorting() const
264 // If all view modes would support categorized sorting, returning
265 // m_viewAccessor.proxyModel()->isCategorizedModel() would be the way to go. As
266 // currently only the icons view supports caterized sorting, we remember
267 // the stored view properties state in m_storedCategorizedSorting and
268 // return this state. The application takes care to disable the corresponding
269 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
270 // that this setting is not applied to the current view mode.
271 return m_storedCategorizedSorting
;
274 bool DolphinView::supportsCategorizedSorting() const
276 return m_viewAccessor
.supportsCategorizedSorting();
279 KFileItem
DolphinView::rootItem() const
281 return m_viewAccessor
.dirLister()->rootItem();
284 KFileItemList
DolphinView::items() const
286 return m_viewAccessor
.dirLister()->items();
289 KFileItemList
DolphinView::selectedItems() const
291 KFileItemList itemList
;
292 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
297 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
299 const QModelIndexList indexList
= selection
.indexes();
300 foreach (const QModelIndex
&index
, indexList
) {
301 KFileItem item
= m_viewAccessor
.dirModel()->itemForIndex(index
);
302 if (!item
.isNull()) {
303 itemList
.append(item
);
310 int DolphinView::selectedItemsCount() const
312 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
317 return view
->selectionModel()->selectedIndexes().count();
320 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
322 foreach (const KUrl
& url
, urls
) {
323 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url
);
324 m_selectedItems
.append(item
);
328 void DolphinView::setItemSelectionEnabled(const QRegExp
& pattern
, bool enabled
)
330 const QItemSelection matchingIndexes
= childrenMatchingPattern(QModelIndex(), pattern
);
331 const QItemSelectionModel::SelectionFlags command
= enabled
332 ? QItemSelectionModel::Select
333 : QItemSelectionModel::Deselect
;
334 m_viewAccessor
.itemView()->selectionModel()->select(matchingIndexes
, command
);
337 void DolphinView::setZoomLevel(int level
)
339 if (level
< ZoomLevelInfo::minimumLevel()) {
340 level
= ZoomLevelInfo::minimumLevel();
341 } else if (level
> ZoomLevelInfo::maximumLevel()) {
342 level
= ZoomLevelInfo::maximumLevel();
345 if (level
!= zoomLevel()) {
346 m_viewModeController
->setZoomLevel(level
);
347 emit
zoomLevelChanged(level
);
351 int DolphinView::zoomLevel() const
353 return m_viewModeController
->zoomLevel();
356 void DolphinView::setSorting(Sorting sorting
)
358 if (sorting
!= this->sorting()) {
359 updateSorting(sorting
);
363 DolphinView::Sorting
DolphinView::sorting() const
365 return m_viewAccessor
.proxyModel()->sorting();
368 void DolphinView::setSortOrder(Qt::SortOrder order
)
370 if (sortOrder() != order
) {
371 updateSortOrder(order
);
375 Qt::SortOrder
DolphinView::sortOrder() const
377 return m_viewAccessor
.proxyModel()->sortOrder();
380 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
382 if (sortFoldersFirst() != foldersFirst
) {
383 updateSortFoldersFirst(foldersFirst
);
387 bool DolphinView::sortFoldersFirst() const
389 return m_viewAccessor
.proxyModel()->sortFoldersFirst();
392 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
394 const KUrl viewPropsUrl
= rootUrl();
395 ViewProperties
props(viewPropsUrl
);
396 props
.setAdditionalInfo(info
);
397 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
399 emit
additionalInfoChanged();
401 if (m_viewAccessor
.reloadOnAdditionalInfoChange()) {
402 loadDirectory(viewPropsUrl
);
406 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
408 return m_viewAccessor
.itemDelegate()->showInformation();
411 void DolphinView::reload()
413 QByteArray viewState
;
414 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
415 saveState(saveStream
);
416 m_selectedItems
= selectedItems();
419 loadDirectory(url(), true);
421 QDataStream
restoreStream(viewState
);
422 restoreState(restoreStream
);
425 void DolphinView::stopLoading()
427 m_viewAccessor
.dirLister()->stop();
430 void DolphinView::refresh()
432 const bool oldActivationState
= m_active
;
433 const int oldZoomLevel
= m_viewModeController
->zoomLevel();
437 applyViewProperties();
440 setActive(oldActivationState
);
441 updateZoomLevel(oldZoomLevel
);
444 void DolphinView::setNameFilter(const QString
& nameFilter
)
446 m_viewModeController
->setNameFilter(nameFilter
);
449 QString
DolphinView::nameFilter() const
451 return m_viewModeController
->nameFilter();
454 void DolphinView::calculateItemCount(int& fileCount
,
456 KIO::filesize_t
& totalFileSize
) const
458 foreach (const KFileItem
& item
, m_viewAccessor
.dirLister()->items()) {
463 totalFileSize
+= item
.size();
468 QString
DolphinView::statusBarText() const
473 KIO::filesize_t totalFileSize
= 0;
475 if (hasSelection()) {
476 // give a summary of the status of the selected files
477 const KFileItemList list
= selectedItems();
478 if (list
.isEmpty()) {
479 // when an item is triggered, it is temporary selected but selectedItems()
480 // will return an empty list
484 KFileItemList::const_iterator it
= list
.begin();
485 const KFileItemList::const_iterator end
= list
.end();
487 const KFileItem
& item
= *it
;
492 totalFileSize
+= item
.size();
497 if (folderCount
+ fileCount
== 1) {
498 // if only one item is selected, show the filename
499 const QString name
= list
.first().text();
500 text
= (folderCount
== 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name
) :
501 i18nc("@info:status", "<filename>%1</filename> selected (%2)",
502 name
, KIO::convertSize(totalFileSize
));
504 // at least 2 items are selected
505 const QString foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
506 const QString filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
507 if ((folderCount
> 0) && (fileCount
> 0)) {
508 text
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
509 foldersText
, filesText
, KIO::convertSize(totalFileSize
));
510 } else if (fileCount
> 0) {
511 text
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KIO::convertSize(totalFileSize
));
513 Q_ASSERT(folderCount
> 0);
518 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
519 text
= KIO::itemsSummaryString(fileCount
+ folderCount
,
520 fileCount
, folderCount
,
521 totalFileSize
, true);
527 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
529 return m_dolphinViewController
->versionControlActions(items
);
532 void DolphinView::setUrl(const KUrl
& url
)
534 if (m_viewModeController
->url() == url
) {
538 const bool hadSelection
= hasSelection();
540 // The selection model and directory lister might change in the case of the column view:
541 disconnectViewAccessor();
543 m_newFileNames
.clear();
545 m_viewModeController
->setUrl(url
); // emits urlChanged, which we forward
546 m_viewAccessor
.prepareUrlChange(url
);
547 applyViewProperties();
549 // When changing the URL there is no need to keep the version
550 // data of the previous URL.
551 m_viewAccessor
.dirModel()->clearVersionData();
553 // Reconnect to the (probably) new selection model and directory lister
554 connectViewAccessor();
557 if (hadSelection
|| hasSelection()) {
558 emitSelectionChangedSignal();
562 void DolphinView::selectAll()
564 m_viewAccessor
.itemView()->selectAll();
567 void DolphinView::invertSelection()
569 // Implementation note: Using selectionModel->select(selection, QItemSelectionModel::Toggle) does not
570 // work, as QItemSelectionModel::hasSelection() provides invalid values in this case. This might be a Qt-issue -
571 // when changing the implementation with an updated Qt-version don't forget to run the Dolphin-unit-tests that
572 // verify this usecase.
573 const KFileItemList selItems
= selectedItems();
576 QItemSelection invertedSelection
;
577 foreach (const KFileItem
& item
, items()) {
578 if (!selItems
.contains(item
)) {
579 const QModelIndex index
= m_viewAccessor
.proxyModel()->mapFromSource(m_viewAccessor
.dirModel()->indexForItem(item
));
580 invertedSelection
.select(index
, index
);
584 QItemSelectionModel
* selectionModel
= m_viewAccessor
.itemView()->selectionModel();
585 selectionModel
->select(invertedSelection
, QItemSelectionModel::ClearAndSelect
| QItemSelectionModel::Current
);
588 void DolphinView::clearSelection()
590 m_viewAccessor
.itemView()->clearSelection();
593 void DolphinView::renameSelectedItems()
595 KFileItemList items
= selectedItems();
596 const int itemCount
= items
.count();
601 if ((itemCount
== 1) && DolphinSettings::instance().generalSettings()->renameInline()) {
602 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForItem(items
.first());
603 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
604 m_viewAccessor
.itemView()->edit(proxyIndex
);
606 RenameDialog
* dialog
= new RenameDialog(this, items
);
607 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
610 dialog
->activateWindow();
614 void DolphinView::trashSelectedItems()
616 const KUrl::List list
= simplifiedSelectedUrls();
617 KonqOperations::del(this, KonqOperations::TRASH
, list
);
620 void DolphinView::deleteSelectedItems()
622 const KUrl::List list
= simplifiedSelectedUrls();
623 const bool del
= KonqOperations::askDeleteConfirmation(list
,
625 KonqOperations::DEFAULT_CONFIRMATION
,
629 KIO::Job
* job
= KIO::del(list
);
630 connect(job
, SIGNAL(result(KJob
*)),
631 this, SLOT(slotDeleteFileFinished(KJob
*)));
635 void DolphinView::cutSelectedItems()
637 QMimeData
* mimeData
= selectionMimeData();
638 KonqMimeData::addIsCutSelection(mimeData
, true);
639 QApplication::clipboard()->setMimeData(mimeData
);
642 void DolphinView::copySelectedItems()
644 QMimeData
* mimeData
= selectionMimeData();
645 QApplication::clipboard()->setMimeData(mimeData
);
648 void DolphinView::paste()
653 void DolphinView::pasteIntoFolder()
655 const KFileItemList items
= selectedItems();
656 if ((items
.count() == 1) && items
.first().isDir()) {
657 pasteToUrl(items
.first().url());
661 void DolphinView::setShowPreview(bool show
)
663 if (m_showPreview
== show
) {
667 const KUrl viewPropsUrl
= rootUrl();
668 ViewProperties
props(viewPropsUrl
);
669 props
.setShowPreview(show
);
671 m_showPreview
= show
;
672 const int oldZoomLevel
= m_viewModeController
->zoomLevel();
673 emit
showPreviewChanged();
675 // Enabling or disabling the preview might change the icon size of the view.
676 // As the view does not emit a signal when the icon size has been changed,
677 // the used zoom level of the controller must be adjusted manually:
678 updateZoomLevel(oldZoomLevel
);
681 void DolphinView::setShowHiddenFiles(bool show
)
683 if (m_viewAccessor
.dirLister()->showingDotFiles() == show
) {
687 const KUrl viewPropsUrl
= rootUrl();
688 ViewProperties
props(viewPropsUrl
);
689 props
.setShowHiddenFiles(show
);
691 m_viewAccessor
.dirLister()->setShowingDotFiles(show
);
692 emit
showHiddenFilesChanged();
695 void DolphinView::setCategorizedSorting(bool categorized
)
697 if (categorized
== categorizedSorting()) {
701 // setCategorizedSorting(true) may only get invoked
702 // if the view supports categorized sorting
703 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
705 ViewProperties
props(rootUrl());
706 props
.setCategorizedSorting(categorized
);
709 m_storedCategorizedSorting
= categorized
;
710 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
712 emit
categorizedSortingChanged();
715 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
717 QWidget::mouseReleaseEvent(event
);
721 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
723 switch (event
->type()) {
724 case QEvent::FocusIn
:
725 if (watched
== m_viewAccessor
.itemView()) {
726 m_dolphinViewController
->requestActivation();
730 case QEvent::DragEnter
:
731 if (watched
== m_viewAccessor
.itemView()->viewport()) {
736 case QEvent::KeyPress
:
737 if (watched
== m_viewAccessor
.itemView()) {
738 // clear the selection when Escape has been pressed
739 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
740 if (keyEvent
->key() == Qt::Key_Escape
) {
747 if (watched
== m_viewAccessor
.itemView()->viewport()) {
748 // Ctrl+wheel events should cause icon zooming, but not if the left mouse button is pressed
749 // (the user is probably trying to scroll during a selection in that case)
750 QWheelEvent
* wheelEvent
= static_cast<QWheelEvent
*>(event
);
751 if (wheelEvent
->modifiers() & Qt::ControlModifier
&& !(wheelEvent
->buttons() & Qt::LeftButton
)) {
752 const int delta
= wheelEvent
->delta();
753 const int level
= zoomLevel();
755 setZoomLevel(level
+ 1);
756 } else if (delta
< 0) {
757 setZoomLevel(level
- 1);
768 return QWidget::eventFilter(watched
, event
);
771 void DolphinView::activate()
776 void DolphinView::triggerItem(const KFileItem
& item
)
778 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
779 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
780 // items are selected by the user, hence don't trigger the
781 // item specified by 'index'
785 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
786 if (item
.isNull() || m_isContextMenuOpen
) {
790 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
793 void DolphinView::slotSelectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
)
795 const int count
= selectedItemsCount();
796 const bool selectionStateChanged
= ((count
> 0) && (selected
.count() == count
)) ||
797 ((count
== 0) && !deselected
.isEmpty());
799 // If nothing has been selected before and something got selected (or if something
800 // was selected before and now nothing is selected) the selectionChangedSignal must
801 // be emitted asynchronously as fast as possible to update the edit-actions.
802 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
803 m_selectionChangedTimer
->start();
806 void DolphinView::emitSelectionChangedSignal()
808 m_selectionChangedTimer
->stop();
809 emit
selectionChanged(selectedItems());
812 void DolphinView::openContextMenu(const QPoint
& pos
,
813 const QList
<QAction
*>& customActions
)
816 const QModelIndex index
= m_viewAccessor
.itemView()->indexAt(pos
);
817 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
818 const QModelIndex dolphinModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(index
);
819 item
= m_viewAccessor
.dirModel()->itemForIndex(dolphinModelIndex
);
822 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
823 emit
requestContextMenu(item
, url(), customActions
);
824 m_isContextMenuOpen
= false;
827 void DolphinView::dropUrls(const KFileItem
& destItem
,
828 const KUrl
& destPath
,
831 addNewFileNames(event
->mimeData());
832 DragAndDropHelper::instance().dropUrls(destItem
, destPath
, event
, this);
835 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
837 ViewProperties
props(rootUrl());
838 props
.setSorting(sorting
);
840 m_viewAccessor
.proxyModel()->setSorting(sorting
);
842 emit
sortingChanged(sorting
);
845 void DolphinView::updateSortOrder(Qt::SortOrder order
)
847 ViewProperties
props(rootUrl());
848 props
.setSortOrder(order
);
850 m_viewAccessor
.proxyModel()->setSortOrder(order
);
852 emit
sortOrderChanged(order
);
855 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
857 ViewProperties
props(rootUrl());
858 props
.setSortFoldersFirst(foldersFirst
);
860 m_viewAccessor
.proxyModel()->setSortFoldersFirst(foldersFirst
);
862 emit
sortFoldersFirstChanged(foldersFirst
);
865 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
867 ViewProperties
props(rootUrl());
868 props
.setAdditionalInfo(info
);
871 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
873 emit
additionalInfoChanged();
876 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
878 const AdditionalInfoAccessor
& infoAccessor
= AdditionalInfoAccessor::instance();
880 const KFileItemDelegate::InformationList checkedInfo
= m_viewAccessor
.itemDelegate()->showInformation();
881 const KFileItemDelegate::InformationList infoKeys
= infoAccessor
.keys();
883 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
884 (m_mode
== DolphinView::IconsView
);
886 foreach (const KFileItemDelegate::Information
& info
, infoKeys
) {
887 const QString name
= infoAccessor
.actionCollectionName(info
, AdditionalInfoAccessor::AdditionalInfoType
);
888 QAction
* action
= collection
->action(name
);
889 Q_ASSERT(action
!= 0);
890 action
->setEnabled(enable
);
891 action
->setChecked(checkedInfo
.contains(info
));
895 QPair
<bool, QString
> DolphinView::pasteInfo() const
897 return KonqOperations::pasteInfo(url());
900 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
902 m_tabsForFiles
= tabsForFiles
;
905 bool DolphinView::isTabsForFilesEnabled() const
907 return m_tabsForFiles
;
910 bool DolphinView::itemsExpandable() const
912 return m_viewAccessor
.itemsExpandable();
915 void DolphinView::restoreState(QDataStream
& stream
)
917 // Restore the URL of the current item that had the keyboard focus
918 stream
>> m_activeItemUrl
;
920 // Restore the root URL
923 m_viewAccessor
.setRootUrl(rootUrl
);
925 // Restore the view position
926 stream
>> m_restoredContentsPosition
;
928 // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
929 QSet
<KUrl
> urlsToExpand
;
930 stream
>> urlsToExpand
;
931 const DolphinDetailsViewExpander
* expander
= m_viewAccessor
.setExpandedUrls(urlsToExpand
);
933 m_expanderActive
= true;
934 connect (expander
, SIGNAL(completed()), this, SLOT(slotLoadingCompleted()));
937 m_expanderActive
= false;
941 void DolphinView::saveState(QDataStream
& stream
)
943 // Save the URL of the current item that has the keyboard focus
944 KFileItem currentItem
;
945 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
948 const QModelIndex proxyIndex
= view
->currentIndex();
949 const QModelIndex dirModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
950 currentItem
= m_viewAccessor
.dirModel()->itemForIndex(dirModelIndex
);
954 if (!currentItem
.isNull()) {
955 currentItemUrl
= currentItem
.url();
958 stream
<< currentItemUrl
;
961 stream
<< m_viewAccessor
.rootUrl();
963 // Save view position
964 const int x
= view
->horizontalScrollBar()->value();
965 const int y
= view
->verticalScrollBar()->value();
966 stream
<< QPoint(x
, y
);
968 // Save expanded folders (only relevant for the details view - the set will be empty in other view modes)
969 stream
<< m_viewAccessor
.expandedUrls();
972 bool DolphinView::hasSelection() const
974 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
975 return (view
!= 0) && view
->selectionModel()->hasSelection();
978 void DolphinView::observeCreatedItem(const KUrl
& url
)
980 m_createdItemUrl
= url
;
981 connect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
982 this, SLOT(selectAndScrollToCreatedItem()));
985 void DolphinView::selectAndScrollToCreatedItem()
987 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_createdItemUrl
);
988 if (dirIndex
.isValid()) {
989 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
990 m_viewAccessor
.itemView()->setCurrentIndex(proxyIndex
);
993 disconnect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
994 this, SLOT(selectAndScrollToCreatedItem()));
995 m_createdItemUrl
= KUrl();
998 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1000 if (oldUrl
.equals(url(), KUrl::CompareWithoutTrailingSlash
)) {
1001 emit
redirection(oldUrl
, newUrl
);
1002 m_viewModeController
->redirectToUrl(newUrl
); // #186947
1006 void DolphinView::restoreContentsPosition()
1008 if (!m_restoredContentsPosition
.isNull()) {
1009 const int x
= m_restoredContentsPosition
.x();
1010 const int y
= m_restoredContentsPosition
.y();
1011 m_restoredContentsPosition
= QPoint();
1013 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1014 Q_ASSERT(view
!= 0);
1015 view
->horizontalScrollBar()->setValue(x
);
1016 view
->verticalScrollBar()->setValue(y
);
1020 void DolphinView::slotUrlChangeRequested(const KUrl
& url
)
1022 m_viewModeController
->setUrl(url
);
1023 updateWritableState();
1026 void DolphinView::showHoverInformation(const KFileItem
& item
)
1028 emit
requestItemInfo(item
);
1031 void DolphinView::clearHoverInformation()
1033 emit
requestItemInfo(KFileItem());
1036 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1038 if (job
->error() == 0) {
1039 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1040 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1041 emit
errorMessage(job
->errorString());
1045 void DolphinView::slotDirListerStarted(const KUrl
& url
)
1047 // Disable the writestate temporary until it can be determined in a fast way
1048 // in DolphinView::slotDirListerCompleted()
1049 if (m_isFolderWritable
) {
1050 m_isFolderWritable
= false;
1051 emit
writeStateChanged(m_isFolderWritable
);
1054 emit
startedPathLoading(url
);
1057 void DolphinView::slotDirListerCompleted()
1059 if (!m_expanderActive
) {
1060 slotLoadingCompleted();
1063 if (!m_newFileNames
.isEmpty()) {
1064 // select all newly added items created by a paste operation or
1065 // a drag & drop operation, and clear the previous selection
1066 m_viewAccessor
.itemView()->clearSelection();
1067 const int rowCount
= m_viewAccessor
.proxyModel()->rowCount();
1068 QItemSelection selection
;
1069 for (int row
= 0; row
< rowCount
; ++row
) {
1070 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->index(row
, 0);
1071 const QModelIndex dirIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1072 const KUrl url
= m_viewAccessor
.dirModel()->itemForIndex(dirIndex
).url();
1073 if (m_newFileNames
.contains(url
.fileName())) {
1074 selection
.merge(QItemSelection(proxyIndex
, proxyIndex
), QItemSelectionModel::Select
);
1077 m_viewAccessor
.itemView()->selectionModel()->select(selection
, QItemSelectionModel::Select
);
1079 m_newFileNames
.clear();
1082 updateWritableState();
1085 void DolphinView::slotLoadingCompleted()
1087 m_expanderActive
= false;
1089 if (!m_activeItemUrl
.isEmpty()) {
1090 // assure that the current item remains visible
1091 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_activeItemUrl
);
1092 if (dirIndex
.isValid()) {
1093 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1094 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1095 const bool clearSelection
= !hasSelection();
1096 view
->setCurrentIndex(proxyIndex
);
1097 if (clearSelection
) {
1098 view
->clearSelection();
1100 m_activeItemUrl
.clear();
1104 if (!m_selectedItems
.isEmpty()) {
1105 const KUrl
& baseUrl
= url();
1107 QItemSelection newSelection
;
1108 foreach(const KFileItem
& item
, m_selectedItems
) {
1109 url
= item
.url().upUrl();
1110 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
1111 const QModelIndex index
= m_viewAccessor
.proxyModel()->mapFromSource(m_viewAccessor
.dirModel()->indexForItem(item
));
1112 newSelection
.select(index
, index
);
1115 m_viewAccessor
.itemView()->selectionModel()->select(newSelection
,
1116 QItemSelectionModel::ClearAndSelect
1117 | QItemSelectionModel::Current
);
1118 m_selectedItems
.clear();
1121 // Restore the contents position. This has to be done using a Qt::QueuedConnection
1122 // because the view might not be in its final state yet.
1123 QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection
);
1125 emit
finishedPathLoading(url());
1128 void DolphinView::slotRefreshItems()
1130 if (m_assureVisibleCurrentIndex
) {
1131 m_assureVisibleCurrentIndex
= false;
1132 m_viewAccessor
.itemView()->scrollTo(m_viewAccessor
.itemView()->currentIndex());
1136 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1138 if (!url
.isValid()) {
1139 const QString
location(url
.pathOrUrl());
1140 if (location
.isEmpty()) {
1141 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1143 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1148 KDirLister
* dirLister
= m_viewAccessor
.dirLister();
1149 dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1152 void DolphinView::applyViewProperties()
1154 const ViewProperties
props(rootUrl());
1156 const Mode mode
= props
.viewMode();
1157 if (m_mode
!= mode
) {
1158 const int oldZoomLevel
= m_viewModeController
->zoomLevel();
1164 updateZoomLevel(oldZoomLevel
);
1166 if (m_viewAccessor
.itemView() == 0) {
1170 Q_ASSERT(m_viewAccessor
.itemView() != 0);
1171 Q_ASSERT(m_viewAccessor
.itemDelegate() != 0);
1173 const bool showHiddenFiles
= props
.showHiddenFiles();
1174 if (showHiddenFiles
!= m_viewAccessor
.dirLister()->showingDotFiles()) {
1175 m_viewAccessor
.dirLister()->setShowingDotFiles(showHiddenFiles
);
1176 emit
showHiddenFilesChanged();
1179 m_storedCategorizedSorting
= props
.categorizedSorting();
1180 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1181 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
1182 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
1183 emit
categorizedSortingChanged();
1186 const DolphinView::Sorting sorting
= props
.sorting();
1187 if (sorting
!= m_viewAccessor
.proxyModel()->sorting()) {
1188 m_viewAccessor
.proxyModel()->setSorting(sorting
);
1189 emit
sortingChanged(sorting
);
1192 const Qt::SortOrder sortOrder
= props
.sortOrder();
1193 if (sortOrder
!= m_viewAccessor
.proxyModel()->sortOrder()) {
1194 m_viewAccessor
.proxyModel()->setSortOrder(sortOrder
);
1195 emit
sortOrderChanged(sortOrder
);
1198 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1199 if (sortFoldersFirst
!= m_viewAccessor
.proxyModel()->sortFoldersFirst()) {
1200 m_viewAccessor
.proxyModel()->setSortFoldersFirst(sortFoldersFirst
);
1201 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1204 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1205 if (info
!= m_viewAccessor
.itemDelegate()->showInformation()) {
1206 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
1207 emit
additionalInfoChanged();
1210 const bool showPreview
= props
.showPreview();
1211 if (showPreview
!= m_showPreview
) {
1212 m_showPreview
= showPreview
;
1213 const int oldZoomLevel
= m_viewModeController
->zoomLevel();
1214 emit
showPreviewChanged();
1216 // Enabling or disabling the preview might change the icon size of the view.
1217 // As the view does not emit a signal when the icon size has been changed,
1218 // the used zoom level of the controller must be adjusted manually:
1219 updateZoomLevel(oldZoomLevel
);
1223 void DolphinView::createView()
1227 Q_ASSERT(m_viewAccessor
.itemView() == 0);
1228 Q_ASSERT(m_dolphinViewController
->itemView() == 0);
1229 m_viewAccessor
.createView(this, m_dolphinViewController
, m_viewModeController
, m_mode
);
1231 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1232 Q_ASSERT(view
!= 0);
1233 view
->installEventFilter(this);
1234 view
->viewport()->installEventFilter(this);
1236 m_dolphinViewController
->setItemView(view
);
1238 const int zoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(view
->iconSize());
1239 m_viewModeController
->setZoomLevel(zoomLevel
);
1241 connectViewAccessor();
1243 setFocusProxy(m_viewAccessor
.layoutTarget());
1244 m_topLayout
->insertWidget(1, m_viewAccessor
.layoutTarget());
1247 void DolphinView::deleteView()
1249 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1250 Q_ASSERT((m_dolphinViewController
->itemView() == 0) || (m_dolphinViewController
->itemView() == view
));
1251 m_dolphinViewController
->setItemView(0);
1254 disconnectViewAccessor();
1257 // It's important to set the keyboard focus to the parent
1258 // before deleting the view: Otherwise when having a split
1259 // view the other view will get the focus and will request
1260 // an activation (see DolphinView::eventFilter()).
1265 m_viewModeController
->disconnect(view
);
1267 m_viewAccessor
.deleteView();
1271 void DolphinView::pasteToUrl(const KUrl
& url
)
1273 addNewFileNames(QApplication::clipboard()->mimeData());
1274 KonqOperations::doPaste(this, url
);
1277 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1279 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor
.itemView()->iconSize());
1280 if (oldZoomLevel
!= newZoomLevel
) {
1281 m_viewModeController
->setZoomLevel(newZoomLevel
);
1282 emit
zoomLevelChanged(newZoomLevel
);
1286 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1290 const KFileItemList items
= selectedItems();
1291 foreach (const KFileItem
&item
, items
) {
1292 urls
.append(item
.url());
1296 if (itemsExpandable()) {
1297 urls
= KDirModel::simplifiedUrlList(urls
);
1303 QMimeData
* DolphinView::selectionMimeData() const
1305 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1306 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
1307 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
1308 return m_viewAccessor
.dirModel()->mimeData(selection
.indexes());
1311 void DolphinView::addNewFileNames(const QMimeData
* mimeData
)
1313 const KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1314 foreach (const KUrl
& url
, urls
) {
1315 m_newFileNames
.insert(url
.fileName());
1319 QItemSelection
DolphinView::childrenMatchingPattern(const QModelIndex
& parent
, const QRegExp
& pattern
) const
1321 QItemSelection matchingIndexes
;
1322 const DolphinSortFilterProxyModel
* proxyModel
= m_viewAccessor
.proxyModel();
1323 const DolphinModel
* dolphinModel
= m_viewAccessor
.dirModel();
1325 const int rowCount
= proxyModel
->rowCount(parent
);
1327 for (int row
= 0; row
< rowCount
; ++row
) {
1328 QModelIndex index
= proxyModel
->index(row
, 0, parent
);
1329 QModelIndex sourceIndex
= proxyModel
->mapToSource(index
);
1331 if (sourceIndex
.isValid() && pattern
.exactMatch(dolphinModel
->data(sourceIndex
).toString())) {
1332 matchingIndexes
+= QItemSelectionRange(index
);
1335 if (proxyModel
->hasChildren(index
)) {
1336 matchingIndexes
+= childrenMatchingPattern(index
, pattern
);
1340 return matchingIndexes
;
1343 void DolphinView::connectViewAccessor()
1345 KDirLister
* dirLister
= m_viewAccessor
.dirLister();
1346 connect(dirLister
, SIGNAL(redirection(KUrl
,KUrl
)), this, SLOT(slotRedirection(KUrl
,KUrl
)));
1347 connect(dirLister
, SIGNAL(started(KUrl
)), this, SLOT(slotDirListerStarted(KUrl
)));
1348 connect(dirLister
, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
1349 connect(dirLister
, SIGNAL(refreshItems(const QList
<QPair
<KFileItem
,KFileItem
>>&)),
1350 this, SLOT(slotRefreshItems()));
1352 connect(dirLister
, SIGNAL(clear()), this, SIGNAL(itemCountChanged()));
1353 connect(dirLister
, SIGNAL(newItems(KFileItemList
)), this, SIGNAL(itemCountChanged()));
1354 connect(dirLister
, SIGNAL(infoMessage(const QString
&)), this, SIGNAL(infoMessage(const QString
&)));
1355 connect(dirLister
, SIGNAL(errorMessage(const QString
&)), this, SIGNAL(infoMessage(const QString
&)));
1356 connect(dirLister
, SIGNAL(percent(int)), this, SIGNAL(pathLoadingProgress(int)));
1357 connect(dirLister
, SIGNAL(urlIsFileError(const KUrl
&)), this, SIGNAL(urlIsFileError(const KUrl
&)));
1358 connect(dirLister
, SIGNAL(itemsDeleted(const KFileItemList
&)), this, SIGNAL(itemCountChanged()));
1360 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1361 connect(view
->selectionModel(), SIGNAL(selectionChanged(QItemSelection
, QItemSelection
)),
1362 this, SLOT(slotSelectionChanged(QItemSelection
, QItemSelection
)));
1365 void DolphinView::disconnectViewAccessor()
1367 KDirLister
* dirLister
= m_viewAccessor
.dirLister();
1368 disconnect(dirLister
, SIGNAL(redirection(KUrl
,KUrl
)), this, SLOT(slotRedirection(KUrl
,KUrl
)));
1369 disconnect(dirLister
, SIGNAL(started(KUrl
)), this, SLOT(slotDirListerStarted(KUrl
)));
1370 disconnect(dirLister
, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
1371 disconnect(dirLister
, SIGNAL(refreshItems(const QList
<QPair
<KFileItem
,KFileItem
>>&)),
1372 this, SLOT(slotRefreshItems()));
1374 disconnect(dirLister
, SIGNAL(clear()), this, SIGNAL(itemCountChanged()));
1375 disconnect(dirLister
, SIGNAL(newItems(KFileItemList
)), this, SIGNAL(itemCountChanged()));
1376 disconnect(dirLister
, SIGNAL(infoMessage(const QString
&)), this, SIGNAL(infoMessage(const QString
&)));
1377 disconnect(dirLister
, SIGNAL(errorMessage(const QString
&)), this, SIGNAL(errorMessage(const QString
&)));
1378 disconnect(dirLister
, SIGNAL(percent(int)), this, SIGNAL(pathLoadingProgress(int)));
1379 disconnect(dirLister
, SIGNAL(urlIsFileError(const KUrl
&)), this, SIGNAL(urlIsFileError(const KUrl
&)));
1380 disconnect(dirLister
, SIGNAL(itemsDeleted(const KFileItemList
&)), this, SIGNAL(itemCountChanged()));
1382 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1383 disconnect(view
->selectionModel(), SIGNAL(selectionChanged(QItemSelection
, QItemSelection
)),
1384 this, SLOT(slotSelectionChanged(QItemSelection
, QItemSelection
)));
1387 void DolphinView::updateWritableState()
1389 const bool wasFolderWritable
= m_isFolderWritable
;
1390 m_isFolderWritable
= true;
1392 const KFileItem item
= m_viewAccessor
.dirLister()->rootItem();
1393 if (!item
.isNull()) {
1394 KFileItemListProperties
capabilities(KFileItemList() << item
);
1395 m_isFolderWritable
= capabilities
.supportsWriting();
1397 if (m_isFolderWritable
!= wasFolderWritable
) {
1398 emit
writeStateChanged(m_isFolderWritable
);
1402 DolphinView::ViewAccessor::ViewAccessor() :
1406 m_columnsContainer(0),
1411 DolphinDirLister
* dirLister
= new DolphinDirLister();
1412 dirLister
->setAutoUpdate(true);
1413 dirLister
->setDelayedMimeTypes(true);
1415 m_dolphinModel
= new DolphinModel();
1416 m_dolphinModel
->setDirLister(dirLister
); // m_dolphinModel takes ownership of dirLister
1417 m_dolphinModel
->setDropsAllowed(DolphinModel::DropOnDirectory
);
1419 m_proxyModel
= new DolphinSortFilterProxyModel();
1420 m_proxyModel
->setSourceModel(m_dolphinModel
);
1421 m_proxyModel
->setFilterCaseSensitivity(Qt::CaseInsensitive
);
1424 DolphinView::ViewAccessor::~ViewAccessor()
1426 delete m_proxyModel
;
1429 delete m_dolphinModel
;
1432 delete m_dragSource
;
1436 void DolphinView::ViewAccessor::createView(QWidget
* parent
,
1437 DolphinViewController
* dolphinViewController
,
1438 const ViewModeController
* viewModeController
,
1441 Q_ASSERT(itemView() == 0);
1445 m_iconsView
= new DolphinIconsView(parent
,
1446 dolphinViewController
,
1452 m_detailsView
= new DolphinDetailsView(parent
,
1453 dolphinViewController
,
1459 m_columnsContainer
= new DolphinColumnViewContainer(parent
,
1460 dolphinViewController
,
1461 viewModeController
);
1462 if (!m_rootUrl
.isEmpty() && m_rootUrl
.isParentOf(viewModeController
->url())) {
1463 // The column-view must show several columns starting with m_rootUrl as
1464 // first column and viewModeController->url() as last column.
1465 m_columnsContainer
->showColumn(m_rootUrl
);
1466 m_columnsContainer
->showColumn(viewModeController
->url());
1475 void DolphinView::ViewAccessor::deleteView()
1477 if (m_columnsContainer
!= 0) {
1478 m_columnsContainer
->close();
1479 m_columnsContainer
->disconnect();
1480 m_columnsContainer
->deleteLater();
1481 m_columnsContainer
= 0;
1483 QAbstractItemView
* view
= itemView();
1488 if (DragAndDropHelper::instance().isDragSource(view
)) {
1489 // The view is a drag source (the feature "Open folders
1490 // during drag operations" is used). Deleting the view
1491 // during an ongoing drag operation is not allowed, so
1492 // this will postponed.
1493 if (m_dragSource
!= 0) {
1494 // the old stored view is obviously not the drag source anymore
1495 m_dragSource
->deleteLater();
1499 m_dragSource
= view
;
1501 view
->deleteLater();
1511 void DolphinView::ViewAccessor::prepareUrlChange(const KUrl
& url
)
1513 if (m_columnsContainer
!= 0) {
1514 m_columnsContainer
->showColumn(url
);
1518 QAbstractItemView
* DolphinView::ViewAccessor::itemView() const
1520 if (m_iconsView
!= 0) {
1524 if (m_detailsView
!= 0) {
1525 return m_detailsView
;
1528 if (m_columnsContainer
!= 0) {
1529 return m_columnsContainer
->activeColumn();
1535 KFileItemDelegate
* DolphinView::ViewAccessor::itemDelegate() const
1537 return static_cast<KFileItemDelegate
*>(itemView()->itemDelegate());
1540 QWidget
* DolphinView::ViewAccessor::layoutTarget() const
1542 if (m_columnsContainer
!= 0) {
1543 return m_columnsContainer
;
1548 void DolphinView::ViewAccessor::setRootUrl(const KUrl
& rootUrl
)
1550 m_rootUrl
= rootUrl
;
1553 KUrl
DolphinView::ViewAccessor::rootUrl() const
1555 return (m_columnsContainer
!= 0) ? m_columnsContainer
->rootUrl() : m_rootUrl
;
1558 bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
1560 return m_iconsView
!= 0;
1563 bool DolphinView::ViewAccessor::itemsExpandable() const
1565 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1568 QSet
<KUrl
> DolphinView::ViewAccessor::expandedUrls() const
1570 if (m_detailsView
!= 0) {
1571 return m_detailsView
->expandedUrls();
1574 return QSet
<KUrl
>();
1577 const DolphinDetailsViewExpander
* DolphinView::ViewAccessor::setExpandedUrls(const QSet
<KUrl
>& urlsToExpand
)
1579 if ((m_detailsView
!= 0) && m_detailsView
->itemsExpandable() && !urlsToExpand
.isEmpty()) {
1580 // Check if another expander is already active and stop it if necessary.
1581 if(!m_detailsViewExpander
.isNull()) {
1582 m_detailsViewExpander
->stop();
1585 m_detailsViewExpander
= new DolphinDetailsViewExpander(m_detailsView
, urlsToExpand
);
1586 return m_detailsViewExpander
;
1593 bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const
1595 // the details view requires no reloading of the directory, as it maps
1596 // the file item delegate info to its columns internally
1597 return m_detailsView
!= 0;
1600 DolphinModel
* DolphinView::ViewAccessor::dirModel() const
1602 return static_cast<DolphinModel
*>(proxyModel()->sourceModel());
1605 DolphinSortFilterProxyModel
* DolphinView::ViewAccessor::proxyModel() const
1607 if (m_columnsContainer
!= 0) {
1608 return static_cast<DolphinSortFilterProxyModel
*>(m_columnsContainer
->activeColumn()->model());
1610 return m_proxyModel
;
1613 KDirLister
* DolphinView::ViewAccessor::dirLister() const
1615 return dirModel()->dirLister();
1618 #include "dolphinview.moc"