1 /***************************************************************************
2 * Copyright (C) 2006-2009 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphinview.h"
23 #include <QAbstractItemView>
24 #include <QApplication>
27 #include <QItemSelection>
32 #include <kactioncollection.h>
33 #include <kcolorscheme.h>
34 #include <kdirlister.h>
35 #include <kiconeffect.h>
36 #include <kfileitem.h>
38 #include <kio/deletejob.h>
39 #include <kio/netaccess.h>
40 #include <kio/previewjob.h>
43 #include <kmessagebox.h>
44 #include <kmimetyperesolver.h>
45 #include <konq_fileitemcapabilities.h>
46 #include <konq_operations.h>
47 #include <konqmimedata.h>
48 #include <kstringhandler.h>
49 #include <ktoggleaction.h>
52 #include "dolphinmodel.h"
53 #include "dolphincolumnviewcontainer.h"
54 #include "dolphincontroller.h"
55 #include "dolphindetailsview.h"
56 #include "dolphinfileitemdelegate.h"
57 #include "dolphinnewmenuobserver.h"
58 #include "dolphinsortfilterproxymodel.h"
59 #include "dolphin_detailsmodesettings.h"
60 #include "dolphiniconsview.h"
61 #include "dolphin_generalsettings.h"
62 #include "draganddrophelper.h"
63 #include "renamedialog.h"
64 #include "settings/dolphinsettings.h"
65 #include "viewproperties.h"
66 #include "zoomlevelinfo.h"
67 #include "dolphindetailsviewexpander.h"
70 * Helper function for sorting items with qSort() in
71 * DolphinView::renameSelectedItems().
73 bool lessThan(const KFileItem
& item1
, const KFileItem
& item2
)
75 return KStringHandler::naturalCompare(item1
.name(), item2
.name()) < 0;
78 DolphinView::DolphinView(QWidget
* parent
,
80 DolphinSortFilterProxyModel
* proxyModel
) :
84 m_loadingDirectory(false),
85 m_storedCategorizedSorting(false),
86 m_tabsForFiles(false),
87 m_isContextMenuOpen(false),
88 m_ignoreViewProperties(false),
89 m_assureVisibleCurrentIndex(false),
90 m_mode(DolphinView::IconsView
),
93 m_viewAccessor(proxyModel
),
95 m_selectionChangedTimer(0),
98 m_restoredContentsPosition(),
103 m_topLayout
= new QVBoxLayout(this);
104 m_topLayout
->setSpacing(0);
105 m_topLayout
->setMargin(0);
107 m_controller
= new DolphinController(this);
108 m_controller
->setUrl(url
);
110 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
111 this, SIGNAL(urlChanged(const KUrl
&)));
112 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
113 this, SLOT(slotRequestUrlChange(const KUrl
&)));
115 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&, const QList
<QAction
*>&)),
116 this, SLOT(openContextMenu(const QPoint
&, const QList
<QAction
*>&)));
117 connect(m_controller
, SIGNAL(urlsDropped(const KFileItem
&, const KUrl
&, QDropEvent
*)),
118 this, SLOT(dropUrls(const KFileItem
&, const KUrl
&, QDropEvent
*)));
119 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
120 this, SLOT(updateSorting(DolphinView::Sorting
)));
121 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
122 this, SLOT(updateSortOrder(Qt::SortOrder
)));
123 connect(m_controller
, SIGNAL(sortFoldersFirstChanged(bool)),
124 this, SLOT(updateSortFoldersFirst(bool)));
125 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
126 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
127 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
128 this, SLOT(triggerItem(const KFileItem
&)));
129 connect(m_controller
, SIGNAL(tabRequested(const KUrl
&)),
130 this, SIGNAL(tabRequested(const KUrl
&)));
131 connect(m_controller
, SIGNAL(activated()),
132 this, SLOT(activate()));
133 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
134 this, SLOT(showHoverInformation(const KFileItem
&)));
135 connect(m_controller
, SIGNAL(viewportEntered()),
136 this, SLOT(clearHoverInformation()));
138 KDirLister
* dirLister
= m_viewAccessor
.dirLister();
139 connect(dirLister
, SIGNAL(redirection(KUrl
,KUrl
)),
140 this, SLOT(slotRedirection(KUrl
,KUrl
)));
141 connect(dirLister
, SIGNAL(completed()),
142 this, SLOT(slotDirListerCompleted()));
143 connect(dirLister
, SIGNAL(refreshItems(const QList
<QPair
<KFileItem
,KFileItem
>>&)),
144 this, SLOT(slotRefreshItems()));
146 // When a new item has been created by the "Create New..." menu, the item should
147 // get selected and it must be assured that the item will get visible. As the
148 // creation is done asynchronously, several signals must be checked:
149 connect(&DolphinNewMenuObserver::instance(), SIGNAL(itemCreated(const KUrl
&)),
150 this, SLOT(observeCreatedItem(const KUrl
&)));
152 m_selectionChangedTimer
= new QTimer(this);
153 m_selectionChangedTimer
->setSingleShot(true);
154 m_selectionChangedTimer
->setInterval(300);
155 connect(m_selectionChangedTimer
, SIGNAL(timeout()),
156 this, SLOT(emitSelectionChangedSignal()));
158 applyViewProperties();
159 m_topLayout
->addWidget(m_viewAccessor
.layoutTarget());
162 DolphinView::~DolphinView()
166 const KUrl
& DolphinView::url() const
168 return m_controller
->url();
171 KUrl
DolphinView::rootUrl() const
173 const KUrl viewUrl
= url();
174 const KUrl root
= m_viewAccessor
.rootUrl();
175 if (root
.isEmpty() || !root
.isParentOf(viewUrl
)) {
181 void DolphinView::setActive(bool active
)
183 if (active
== m_active
) {
189 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
191 emitSelectionChangedSignal();
196 QWidget
* viewport
= m_viewAccessor
.itemView()->viewport();
198 palette
.setColor(viewport
->backgroundRole(), color
);
199 viewport
->setPalette(palette
);
204 m_viewAccessor
.itemView()->setFocus();
208 m_controller
->indicateActivationChange(active
);
211 bool DolphinView::isActive() const
216 void DolphinView::setMode(Mode mode
)
218 if (mode
== m_mode
) {
219 return; // the wished mode is already set
222 const int oldZoomLevel
= m_controller
->zoomLevel();
225 // remember the currently selected items, so that they will
226 // be restored after reloading the directory
227 m_selectedItems
= selectedItems();
231 const KUrl viewPropsUrl
= rootUrl();
232 ViewProperties
props(viewPropsUrl
);
233 props
.setViewMode(m_mode
);
236 // the file item delegate has been recreated, apply the current
237 // additional information manually
238 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
239 m_viewAccessor
.itemDelegate()->setShowInformation(infoList
);
240 emit
additionalInfoChanged();
242 // Not all view modes support categorized sorting. Adjust the sorting model
243 // if changing the view mode results in a change of the categorized sorting
245 m_storedCategorizedSorting
= props
.categorizedSorting();
246 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
247 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
248 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
249 emit
categorizedSortingChanged();
254 updateZoomLevel(oldZoomLevel
);
255 loadDirectory(viewPropsUrl
);
258 DolphinView::Mode
DolphinView::mode() const
263 bool DolphinView::showPreview() const
265 return m_showPreview
;
268 bool DolphinView::showHiddenFiles() const
270 return m_viewAccessor
.dirLister()->showingDotFiles();
273 bool DolphinView::categorizedSorting() const
275 // If all view modes would support categorized sorting, returning
276 // m_viewAccessor.proxyModel()->isCategorizedModel() would be the way to go. As
277 // currently only the icons view supports caterized sorting, we remember
278 // the stored view properties state in m_storedCategorizedSorting and
279 // return this state. The application takes care to disable the corresponding
280 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
281 // that this setting is not applied to the current view mode.
282 return m_storedCategorizedSorting
;
285 bool DolphinView::supportsCategorizedSorting() const
287 return m_viewAccessor
.supportsCategorizedSorting();
290 bool DolphinView::hasSelection() const
292 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
293 return (view
!= 0) && view
->selectionModel()->hasSelection();
296 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
298 foreach (const KUrl
& url
, urls
) {
299 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url
);
300 m_selectedItems
.append(item
);
304 KFileItemList
DolphinView::selectedItems() const
306 KFileItemList itemList
;
307 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
312 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
314 const QModelIndexList indexList
= selection
.indexes();
315 foreach (const QModelIndex
&index
, indexList
) {
316 KFileItem item
= m_viewAccessor
.dirModel()->itemForIndex(index
);
317 if (!item
.isNull()) {
318 itemList
.append(item
);
325 KUrl::List
DolphinView::selectedUrls() const
328 const KFileItemList list
= selectedItems();
329 foreach (const KFileItem
&item
, list
) {
330 urls
.append(item
.url());
335 int DolphinView::selectedItemsCount() const
337 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
342 return view
->selectionModel()->selectedIndexes().count();
345 QItemSelectionModel
* DolphinView::selectionModel() const
347 return m_viewAccessor
.itemView()->selectionModel();
350 void DolphinView::setContentsPosition(int x
, int y
)
352 QAbstractItemView
* view
= m_viewAccessor
.itemView();
354 view
->horizontalScrollBar()->setValue(x
);
355 view
->verticalScrollBar()->setValue(y
);
357 m_loadingDirectory
= false;
360 void DolphinView::setRestoredContentsPosition(const QPoint
& pos
)
362 // TODO: This function is called by DolphinViewContainer.
363 // If it makes use of DolphinView::restoreState(...) to restore the
364 // view state in KDE 4.5, this function can be removed.
365 m_restoredContentsPosition
= pos
;
368 QPoint
DolphinView::contentsPosition() const
370 // TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
371 // view state in KDE 4.5, this code can be moved to DolphinView::saveState.
372 QAbstractItemView
* view
= m_viewAccessor
.itemView();
374 const int x
= view
->horizontalScrollBar()->value();
375 const int y
= view
->verticalScrollBar()->value();
379 void DolphinView::setZoomLevel(int level
)
381 if (level
< ZoomLevelInfo::minimumLevel()) {
382 level
= ZoomLevelInfo::minimumLevel();
383 } else if (level
> ZoomLevelInfo::maximumLevel()) {
384 level
= ZoomLevelInfo::maximumLevel();
387 if (level
!= zoomLevel()) {
388 m_controller
->setZoomLevel(level
);
389 emit
zoomLevelChanged(level
);
393 int DolphinView::zoomLevel() const
395 return m_controller
->zoomLevel();
398 void DolphinView::setSorting(Sorting sorting
)
400 if (sorting
!= this->sorting()) {
401 updateSorting(sorting
);
405 DolphinView::Sorting
DolphinView::sorting() const
407 return m_viewAccessor
.proxyModel()->sorting();
410 void DolphinView::setSortOrder(Qt::SortOrder order
)
412 if (sortOrder() != order
) {
413 updateSortOrder(order
);
417 Qt::SortOrder
DolphinView::sortOrder() const
419 return m_viewAccessor
.proxyModel()->sortOrder();
422 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
424 if (sortFoldersFirst() != foldersFirst
) {
425 updateSortFoldersFirst(foldersFirst
);
429 bool DolphinView::sortFoldersFirst() const
431 return m_viewAccessor
.proxyModel()->sortFoldersFirst();
434 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
436 const KUrl viewPropsUrl
= rootUrl();
437 ViewProperties
props(viewPropsUrl
);
438 props
.setAdditionalInfo(info
);
439 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
441 emit
additionalInfoChanged();
443 if (m_viewAccessor
.reloadOnAdditionalInfoChange()) {
444 loadDirectory(viewPropsUrl
);
448 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
450 return m_viewAccessor
.itemDelegate()->showInformation();
453 void DolphinView::reload()
455 QByteArray viewState
;
456 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
457 saveState(saveStream
);
458 m_selectedItems
= selectedItems();
461 loadDirectory(url(), true);
463 QDataStream
restoreStream(viewState
);
464 restoreState(restoreStream
);
467 void DolphinView::refresh()
469 m_ignoreViewProperties
= false;
471 const bool oldActivationState
= m_active
;
472 const int oldZoomLevel
= m_controller
->zoomLevel();
476 applyViewProperties();
479 setActive(oldActivationState
);
480 updateZoomLevel(oldZoomLevel
);
483 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
485 Q_UNUSED(rootUrl
); // TODO: remove after columnview-cleanup has been finished
487 if (m_controller
->url() == url
) {
491 m_controller
->setUrl(url
); // emits urlChanged, which we forward
492 m_viewAccessor
.prepareUrlChange(url
);
493 applyViewProperties();
496 // When changing the URL there is no need to keep the version
497 // data of the previous URL.
498 m_viewAccessor
.dirModel()->clearVersionData();
500 emit
startedPathLoading(url
);
503 void DolphinView::setNameFilter(const QString
& nameFilter
)
505 m_controller
->setNameFilter(nameFilter
);
508 void DolphinView::calculateItemCount(int& fileCount
,
510 KIO::filesize_t
& totalFileSize
) const
512 foreach (const KFileItem
& item
, m_viewAccessor
.dirLister()->items()) {
517 totalFileSize
+= item
.size();
522 QString
DolphinView::statusBarText() const
527 KIO::filesize_t totalFileSize
= 0;
529 if (hasSelection()) {
530 // give a summary of the status of the selected files
531 const KFileItemList list
= selectedItems();
532 if (list
.isEmpty()) {
533 // when an item is triggered, it is temporary selected but selectedItems()
534 // will return an empty list
538 KFileItemList::const_iterator it
= list
.begin();
539 const KFileItemList::const_iterator end
= list
.end();
541 const KFileItem
& item
= *it
;
546 totalFileSize
+= item
.size();
551 if (folderCount
+ fileCount
== 1) {
552 // if only one item is selected, show the filename
553 const QString name
= list
.first().name();
554 text
= (folderCount
== 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name
) :
555 i18nc("@info:status", "<filename>%1</filename> selected (%2)",
556 name
, KIO::convertSize(totalFileSize
));
558 // at least 2 items are selected
559 const QString foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
560 const QString filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
561 if ((folderCount
> 0) && (fileCount
> 0)) {
562 text
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
563 foldersText
, filesText
, KIO::convertSize(totalFileSize
));
564 } else if (fileCount
> 0) {
565 text
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KIO::convertSize(totalFileSize
));
567 Q_ASSERT(folderCount
> 0);
572 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
573 text
= KIO::itemsSummaryString(fileCount
+ folderCount
,
574 fileCount
, folderCount
,
575 totalFileSize
, true);
581 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
583 return m_controller
->versionControlActions(items
);
586 void DolphinView::setUrl(const KUrl
& url
)
588 m_newFileNames
.clear();
589 updateView(url
, KUrl());
592 void DolphinView::selectAll()
594 m_viewAccessor
.itemView()->selectAll();
597 void DolphinView::invertSelection()
599 QItemSelectionModel
* selectionModel
= m_viewAccessor
.itemView()->selectionModel();
600 const QAbstractItemModel
* itemModel
= selectionModel
->model();
602 const QModelIndex topLeft
= itemModel
->index(0, 0);
603 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
604 itemModel
->columnCount() - 1);
606 const QItemSelection
selection(topLeft
, bottomRight
);
607 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
610 void DolphinView::clearSelection()
612 m_viewAccessor
.itemView()->clearSelection();
615 void DolphinView::renameSelectedItems()
617 KFileItemList items
= selectedItems();
618 const int itemCount
= items
.count();
624 // More than one item has been selected for renaming. Open
625 // a rename dialog and rename all items afterwards.
626 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
627 if (dialog
->exec() == QDialog::Rejected
) {
632 const QString newName
= dialog
->newName();
633 if (newName
.isEmpty()) {
634 emit
errorMessage(dialog
->errorString());
640 // the selection would be invalid after renaming the items, so just clear
644 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
645 // as one operation instead of n rename operations like it is done now...
646 Q_ASSERT(newName
.contains('#'));
648 // currently the items are sorted by the selection order, resort
649 // them by the file name
650 qSort(items
.begin(), items
.end(), lessThan
);
652 // iterate through all selected items and rename them...
654 foreach (const KFileItem
& item
, items
) {
655 const KUrl
& oldUrl
= item
.url();
657 number
.setNum(index
++);
659 QString name
= newName
;
660 name
.replace('#', number
);
662 if (oldUrl
.fileName() != name
) {
663 KUrl newUrl
= oldUrl
;
664 newUrl
.setFileName(name
);
665 KonqOperations::rename(this, oldUrl
, newUrl
);
668 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
669 Q_ASSERT(itemCount
== 1);
670 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForItem(items
.first());
671 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
672 m_viewAccessor
.itemView()->edit(proxyIndex
);
674 Q_ASSERT(itemCount
== 1);
676 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
677 if (dialog
->exec() == QDialog::Rejected
) {
682 const QString newName
= dialog
->newName();
683 if (newName
.isEmpty()) {
684 emit
errorMessage(dialog
->errorString());
690 const KUrl
& oldUrl
= items
.first().url();
691 KUrl newUrl
= oldUrl
;
692 newUrl
.setFileName(newName
);
693 KonqOperations::rename(this, oldUrl
, newUrl
);
696 // assure that the current index remains visible when KDirLister
697 // will notify the view about changed items
698 m_assureVisibleCurrentIndex
= true;
701 void DolphinView::trashSelectedItems()
703 const KUrl::List list
= simplifiedSelectedUrls();
704 KonqOperations::del(this, KonqOperations::TRASH
, list
);
707 void DolphinView::deleteSelectedItems()
709 const KUrl::List list
= simplifiedSelectedUrls();
710 const bool del
= KonqOperations::askDeleteConfirmation(list
,
712 KonqOperations::DEFAULT_CONFIRMATION
,
716 KIO::Job
* job
= KIO::del(list
);
717 connect(job
, SIGNAL(result(KJob
*)),
718 this, SLOT(slotDeleteFileFinished(KJob
*)));
722 void DolphinView::cutSelectedItems()
724 QMimeData
* mimeData
= selectionMimeData();
725 KonqMimeData::addIsCutSelection(mimeData
, true);
726 QApplication::clipboard()->setMimeData(mimeData
);
729 void DolphinView::copySelectedItems()
731 QMimeData
* mimeData
= selectionMimeData();
732 QApplication::clipboard()->setMimeData(mimeData
);
735 void DolphinView::paste()
740 void DolphinView::pasteIntoFolder()
742 const KFileItemList items
= selectedItems();
743 if ((items
.count() == 1) && items
.first().isDir()) {
744 pasteToUrl(items
.first().url());
748 void DolphinView::setShowPreview(bool show
)
750 if (m_showPreview
== show
) {
754 const KUrl viewPropsUrl
= rootUrl();
755 ViewProperties
props(viewPropsUrl
);
756 props
.setShowPreview(show
);
758 m_showPreview
= show
;
759 const int oldZoomLevel
= m_controller
->zoomLevel();
760 emit
showPreviewChanged();
762 // Enabling or disabling the preview might change the icon size of the view.
763 // As the view does not emit a signal when the icon size has been changed,
764 // the used zoom level of the controller must be adjusted manually:
765 updateZoomLevel(oldZoomLevel
);
768 void DolphinView::setShowHiddenFiles(bool show
)
770 if (m_viewAccessor
.dirLister()->showingDotFiles() == show
) {
774 const KUrl viewPropsUrl
= rootUrl();
775 ViewProperties
props(viewPropsUrl
);
776 props
.setShowHiddenFiles(show
);
778 m_viewAccessor
.dirLister()->setShowingDotFiles(show
);
779 emit
showHiddenFilesChanged();
782 void DolphinView::setCategorizedSorting(bool categorized
)
784 if (categorized
== categorizedSorting()) {
788 // setCategorizedSorting(true) may only get invoked
789 // if the view supports categorized sorting
790 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
792 ViewProperties
props(rootUrl());
793 props
.setCategorizedSorting(categorized
);
796 m_storedCategorizedSorting
= categorized
;
797 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
799 emit
categorizedSortingChanged();
802 void DolphinView::toggleSortOrder()
804 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
805 Qt::DescendingOrder
:
810 void DolphinView::toggleSortFoldersFirst()
812 setSortFoldersFirst(!sortFoldersFirst());
815 void DolphinView::toggleAdditionalInfo(QAction
* action
)
817 const KFileItemDelegate::Information info
=
818 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
820 KFileItemDelegate::InformationList list
= additionalInfo();
822 const bool show
= action
->isChecked();
824 const int index
= list
.indexOf(info
);
825 const bool containsInfo
= (index
>= 0);
826 if (show
&& !containsInfo
) {
828 setAdditionalInfo(list
);
829 } else if (!show
&& containsInfo
) {
830 list
.removeAt(index
);
831 setAdditionalInfo(list
);
832 Q_ASSERT(list
.indexOf(info
) < 0);
836 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
838 QWidget::mouseReleaseEvent(event
);
842 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
844 switch (event
->type()) {
845 case QEvent::FocusIn
:
846 if (watched
== m_viewAccessor
.itemView()) {
847 m_controller
->requestActivation();
851 case QEvent::DragEnter
:
852 if (watched
== m_viewAccessor
.itemView()->viewport()) {
857 case QEvent::KeyPress
:
858 if (watched
== m_viewAccessor
.itemView()) {
859 // clear the selection when Escape has been pressed
860 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
861 if (keyEvent
->key() == Qt::Key_Escape
) {
868 if (watched
== m_viewAccessor
.itemView()->viewport()) {
869 // Ctrl+wheel events should cause icon zooming, but not if the left mouse button is pressed
870 // (the user is probably trying to scroll during a selection in that case)
871 QWheelEvent
* wheelEvent
= static_cast<QWheelEvent
*>(event
);
872 if (wheelEvent
->modifiers() & Qt::ControlModifier
&& !(wheelEvent
->buttons() & Qt::LeftButton
)) {
873 const int delta
= wheelEvent
->delta();
874 const int level
= zoomLevel();
876 setZoomLevel(level
+ 1);
877 } else if (delta
< 0) {
878 setZoomLevel(level
- 1);
889 return QWidget::eventFilter(watched
, event
);
892 void DolphinView::activate()
897 void DolphinView::triggerItem(const KFileItem
& item
)
899 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
900 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
901 // items are selected by the user, hence don't trigger the
902 // item specified by 'index'
906 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
907 if (item
.isNull() || m_isContextMenuOpen
) {
911 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
914 void DolphinView::slotSelectionChanged(const QItemSelection
& selected
, const QItemSelection
& deselected
)
916 const int count
= selectedItemsCount();
917 const bool selectionStateChanged
= ((count
> 0) && (selected
.count() == count
)) ||
918 ((count
== 0) && !deselected
.isEmpty());
920 // If nothing has been selected before and something got selected (or if something
921 // was selected before and now nothing is selected) the selectionChangedSignal must
922 // be emitted asynchronously as fast as possible to update the edit-actions.
923 m_selectionChangedTimer
->setInterval(selectionStateChanged
? 0 : 300);
924 m_selectionChangedTimer
->start();
927 void DolphinView::emitSelectionChangedSignal()
929 emit
selectionChanged(DolphinView::selectedItems());
932 void DolphinView::openContextMenu(const QPoint
& pos
,
933 const QList
<QAction
*>& customActions
)
936 const QModelIndex index
= m_viewAccessor
.itemView()->indexAt(pos
);
937 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
938 const QModelIndex dolphinModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(index
);
939 item
= m_viewAccessor
.dirModel()->itemForIndex(dolphinModelIndex
);
942 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
943 emit
requestContextMenu(item
, url(), customActions
);
944 m_isContextMenuOpen
= false;
947 void DolphinView::dropUrls(const KFileItem
& destItem
,
948 const KUrl
& destPath
,
951 addNewFileNames(event
->mimeData());
952 DragAndDropHelper::instance().dropUrls(destItem
, destPath
, event
, this);
955 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
957 ViewProperties
props(rootUrl());
958 props
.setSorting(sorting
);
960 m_viewAccessor
.proxyModel()->setSorting(sorting
);
962 emit
sortingChanged(sorting
);
965 void DolphinView::updateSortOrder(Qt::SortOrder order
)
967 ViewProperties
props(rootUrl());
968 props
.setSortOrder(order
);
970 m_viewAccessor
.proxyModel()->setSortOrder(order
);
972 emit
sortOrderChanged(order
);
975 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
977 ViewProperties
props(rootUrl());
978 props
.setSortFoldersFirst(foldersFirst
);
980 m_viewAccessor
.proxyModel()->setSortFoldersFirst(foldersFirst
);
982 emit
sortFoldersFirstChanged(foldersFirst
);
985 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
987 ViewProperties
props(rootUrl());
988 props
.setAdditionalInfo(info
);
991 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
993 emit
additionalInfoChanged();
996 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
998 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
999 (m_mode
== DolphinView::IconsView
);
1001 QAction
* showSizeInfo
= collection
->action("show_size_info");
1002 QAction
* showDateInfo
= collection
->action("show_date_info");
1003 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
1004 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
1005 QAction
* showGroupInfo
= collection
->action("show_group_info");
1006 QAction
* showMimeInfo
= collection
->action("show_mime_info");
1008 showSizeInfo
->setChecked(false);
1009 showDateInfo
->setChecked(false);
1010 showPermissionsInfo
->setChecked(false);
1011 showOwnerInfo
->setChecked(false);
1012 showGroupInfo
->setChecked(false);
1013 showMimeInfo
->setChecked(false);
1015 showSizeInfo
->setEnabled(enable
);
1016 showDateInfo
->setEnabled(enable
);
1017 showPermissionsInfo
->setEnabled(enable
);
1018 showOwnerInfo
->setEnabled(enable
);
1019 showGroupInfo
->setEnabled(enable
);
1020 showMimeInfo
->setEnabled(enable
);
1022 foreach (KFileItemDelegate::Information info
, m_viewAccessor
.itemDelegate()->showInformation()) {
1024 case KFileItemDelegate::Size
:
1025 showSizeInfo
->setChecked(true);
1027 case KFileItemDelegate::ModificationTime
:
1028 showDateInfo
->setChecked(true);
1030 case KFileItemDelegate::Permissions
:
1031 showPermissionsInfo
->setChecked(true);
1033 case KFileItemDelegate::Owner
:
1034 showOwnerInfo
->setChecked(true);
1036 case KFileItemDelegate::OwnerAndGroup
:
1037 showGroupInfo
->setChecked(true);
1039 case KFileItemDelegate::FriendlyMimeType
:
1040 showMimeInfo
->setChecked(true);
1048 QPair
<bool, QString
> DolphinView::pasteInfo() const
1050 return KonqOperations::pasteInfo(url());
1053 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1055 m_tabsForFiles
= tabsForFiles
;
1058 bool DolphinView::isTabsForFilesEnabled() const
1060 return m_tabsForFiles
;
1063 void DolphinView::activateItem(const KUrl
& url
)
1065 // TODO: If DolphinViewContainer uses DolphinView::restoreState(...) to restore the
1066 // view state in KDE 4.5, this function can be removed.
1067 m_activeItemUrl
= url
;
1070 bool DolphinView::itemsExpandable() const
1072 return m_viewAccessor
.itemsExpandable();
1075 void DolphinView::restoreState(QDataStream
&stream
)
1078 stream
>> m_activeItemUrl
;
1081 stream
>> m_restoredContentsPosition
;
1083 // expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1084 QSet
<KUrl
> urlsToExpand
;
1085 stream
>> urlsToExpand
;
1086 const DolphinDetailsViewExpander
* expander
= m_viewAccessor
.setExpandedUrls(urlsToExpand
);
1089 m_expanderActive
= true;
1090 connect (expander
, SIGNAL(completed()), this, SLOT(slotLoadingCompleted()));
1093 m_expanderActive
= false;
1097 void DolphinView::saveState(QDataStream
&stream
)
1100 KFileItem currentItem
;
1101 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1104 const QModelIndex proxyIndex
= view
->currentIndex();
1105 const QModelIndex dirModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1106 currentItem
= m_viewAccessor
.dirModel()->itemForIndex(dirModelIndex
);
1110 if (!currentItem
.isNull())
1111 currentUrl
= currentItem
.url();
1113 stream
<< currentUrl
;
1116 stream
<< contentsPosition();
1118 // expanded folders (only relevant for the details view - the set will be empty in other view modes)
1119 stream
<< m_viewAccessor
.expandedUrls();
1122 void DolphinView::observeCreatedItem(const KUrl
& url
)
1124 m_createdItemUrl
= url
;
1125 connect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1126 this, SLOT(selectAndScrollToCreatedItem()));
1129 void DolphinView::selectAndScrollToCreatedItem()
1131 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_createdItemUrl
);
1132 if (dirIndex
.isValid()) {
1133 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1134 m_viewAccessor
.itemView()->setCurrentIndex(proxyIndex
);
1137 disconnect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1138 this, SLOT(selectAndScrollToCreatedItem()));
1139 m_createdItemUrl
= KUrl();
1142 void DolphinView::emitContentsMoved()
1144 // TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
1145 // view state in KDE 4.5, the contentsMoved signal might not be needed anymore,
1146 // depending on how the implementation is done.
1147 // In that case, the code in contentsPosition() can be moved to saveState().
1149 // only emit the contents moved signal if no directory loading is ongoing
1150 // (this would reset the contents position always to (0, 0))
1151 if (!m_loadingDirectory
) {
1152 const QPoint
pos(contentsPosition());
1153 emit
contentsMoved(pos
.x(), pos
.y());
1157 void DolphinView::showHoverInformation(const KFileItem
& item
)
1159 emit
requestItemInfo(item
);
1162 void DolphinView::clearHoverInformation()
1164 emit
requestItemInfo(KFileItem());
1167 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1169 if (job
->error() == 0) {
1170 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1171 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1172 emit
errorMessage(job
->errorString());
1176 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1178 emit
requestUrlChange(url
);
1179 m_controller
->setUrl(url
);
1182 void DolphinView::slotDirListerCompleted()
1184 if (!m_expanderActive
) {
1185 slotLoadingCompleted();
1188 if (!m_newFileNames
.isEmpty()) {
1189 // select all newly added items created by a paste operation or
1190 // a drag & drop operation
1191 const int rowCount
= m_viewAccessor
.proxyModel()->rowCount();
1192 QItemSelection selection
;
1193 for (int row
= 0; row
< rowCount
; ++row
) {
1194 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->index(row
, 0);
1195 const QModelIndex dirIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1196 const KUrl url
= m_viewAccessor
.dirModel()->itemForIndex(dirIndex
).url();
1197 if (m_newFileNames
.contains(url
.fileName())) {
1198 selection
.merge(QItemSelection(proxyIndex
, proxyIndex
), QItemSelectionModel::Select
);
1201 m_viewAccessor
.itemView()->selectionModel()->select(selection
, QItemSelectionModel::Select
);
1203 m_newFileNames
.clear();
1207 void DolphinView::slotLoadingCompleted()
1209 m_expanderActive
= false;
1210 m_loadingDirectory
= false;
1212 if (!m_activeItemUrl
.isEmpty()) {
1213 // assure that the current item remains visible
1214 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_activeItemUrl
);
1215 if (dirIndex
.isValid()) {
1216 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1217 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1218 const bool clearSelection
= !hasSelection();
1219 view
->setCurrentIndex(proxyIndex
);
1220 if (clearSelection
) {
1221 view
->clearSelection();
1223 m_activeItemUrl
.clear();
1227 if (!m_selectedItems
.isEmpty()) {
1228 const KUrl
& baseUrl
= url();
1230 QItemSelection newSelection
;
1231 foreach(const KFileItem
& item
, m_selectedItems
) {
1232 url
= item
.url().upUrl();
1233 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
1234 QModelIndex index
= m_viewAccessor
.proxyModel()->mapFromSource(m_viewAccessor
.dirModel()->indexForItem(item
));
1235 newSelection
.select(index
, index
);
1238 m_viewAccessor
.itemView()->selectionModel()->select(newSelection
,
1239 QItemSelectionModel::ClearAndSelect
1240 | QItemSelectionModel::Current
);
1241 m_selectedItems
.clear();
1244 // Restore the contents position. This has to be done using a Qt::QueuedConnection
1245 // because the view might not be in its final state yet.
1246 QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection
);
1249 void DolphinView::slotRefreshItems()
1251 if (m_assureVisibleCurrentIndex
) {
1252 m_assureVisibleCurrentIndex
= false;
1253 m_viewAccessor
.itemView()->scrollTo(m_viewAccessor
.itemView()->currentIndex());
1257 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1259 if (!url
.isValid()) {
1260 const QString
location(url
.pathOrUrl());
1261 if (location
.isEmpty()) {
1262 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1264 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1269 m_loadingDirectory
= true;
1270 m_expanderActive
= false;
1272 KDirLister
* dirLister
= m_viewAccessor
.dirLister();
1273 dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1275 KDirLister
* rootDirLister
= m_viewAccessor
.rootDirLister();
1276 if (dirLister
!= rootDirLister
) {
1277 // In the case of the column view the root directory lister can be different. Assure
1278 // that it gets synchronized (clients from DolphinView are not aware that internally
1279 // different directory listers are used).
1280 rootDirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1284 void DolphinView::applyViewProperties()
1286 if (m_ignoreViewProperties
) {
1290 const ViewProperties
props(rootUrl());
1292 const Mode mode
= props
.viewMode();
1293 if (m_mode
!= mode
) {
1294 const int oldZoomLevel
= m_controller
->zoomLevel();
1300 updateZoomLevel(oldZoomLevel
);
1302 if (m_viewAccessor
.itemView() == 0) {
1305 Q_ASSERT(m_viewAccessor
.itemView() != 0);
1306 Q_ASSERT(m_viewAccessor
.itemDelegate() != 0);
1308 const bool showHiddenFiles
= props
.showHiddenFiles();
1309 if (showHiddenFiles
!= m_viewAccessor
.dirLister()->showingDotFiles()) {
1310 m_viewAccessor
.dirLister()->setShowingDotFiles(showHiddenFiles
);
1311 emit
showHiddenFilesChanged();
1314 m_storedCategorizedSorting
= props
.categorizedSorting();
1315 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1316 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
1317 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
1318 emit
categorizedSortingChanged();
1321 const DolphinView::Sorting sorting
= props
.sorting();
1322 if (sorting
!= m_viewAccessor
.proxyModel()->sorting()) {
1323 m_viewAccessor
.proxyModel()->setSorting(sorting
);
1324 emit
sortingChanged(sorting
);
1327 const Qt::SortOrder sortOrder
= props
.sortOrder();
1328 if (sortOrder
!= m_viewAccessor
.proxyModel()->sortOrder()) {
1329 m_viewAccessor
.proxyModel()->setSortOrder(sortOrder
);
1330 emit
sortOrderChanged(sortOrder
);
1333 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1334 if (sortFoldersFirst
!= m_viewAccessor
.proxyModel()->sortFoldersFirst()) {
1335 m_viewAccessor
.proxyModel()->setSortFoldersFirst(sortFoldersFirst
);
1336 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1339 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1340 if (info
!= m_viewAccessor
.itemDelegate()->showInformation()) {
1341 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
1342 emit
additionalInfoChanged();
1345 const bool showPreview
= props
.showPreview();
1346 if (showPreview
!= m_showPreview
) {
1347 m_showPreview
= showPreview
;
1348 const int oldZoomLevel
= m_controller
->zoomLevel();
1349 emit
showPreviewChanged();
1351 // Enabling or disabling the preview might change the icon size of the view.
1352 // As the view does not emit a signal when the icon size has been changed,
1353 // the used zoom level of the controller must be adjusted manually:
1354 updateZoomLevel(oldZoomLevel
);
1357 if (DolphinSettings::instance().generalSettings()->globalViewProps()) {
1358 // During the lifetime of a DolphinView instance the global view properties
1359 // should not be changed. This allows e. g. to split a view and use different
1360 // view properties for each view.
1361 m_ignoreViewProperties
= true;
1365 void DolphinView::createView()
1369 Q_ASSERT(m_viewAccessor
.itemView() == 0);
1370 m_viewAccessor
.createView(this, m_controller
, m_mode
);
1372 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1373 Q_ASSERT(view
!= 0);
1374 view
->installEventFilter(this);
1375 view
->viewport()->installEventFilter(this);
1377 m_controller
->setItemView(view
);
1379 // When changing the view mode, the selection is lost due to reinstantiating
1380 // a new item view with a custom selection model. Pass the ownership of the
1381 // selection model to DolphinView, so that it can be shared by all item views.
1382 if (m_selectionModel
!= 0) {
1383 view
->setSelectionModel(m_selectionModel
);
1385 m_selectionModel
= view
->selectionModel();
1387 m_selectionModel
->setParent(this);
1388 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
1389 this, SLOT(slotSelectionChanged(const QItemSelection
&, const QItemSelection
&)));
1391 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1392 this, SLOT(emitContentsMoved()));
1393 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1394 this, SLOT(emitContentsMoved()));
1396 setFocusProxy(m_viewAccessor
.layoutTarget());
1397 m_topLayout
->insertWidget(1, m_viewAccessor
.layoutTarget());
1400 void DolphinView::deleteView()
1402 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1404 // It's important to set the keyboard focus to the parent
1405 // before deleting the view: Otherwise when having a split
1406 // view the other view will get the focus and will request
1407 // an activation (see DolphinView::eventFilter()).
1411 m_topLayout
->removeWidget(view
);
1414 // disconnect all signal/slots
1416 m_controller
->disconnect(view
);
1418 disconnect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1419 this, SLOT(emitContentsMoved()));
1420 disconnect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1421 this, SLOT(emitContentsMoved()));
1423 m_viewAccessor
.deleteView();
1427 void DolphinView::pasteToUrl(const KUrl
& url
)
1429 addNewFileNames(QApplication::clipboard()->mimeData());
1430 KonqOperations::doPaste(this, url
);
1433 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1435 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor
.itemView()->iconSize());
1436 if (oldZoomLevel
!= newZoomLevel
) {
1437 m_controller
->setZoomLevel(newZoomLevel
);
1438 emit
zoomLevelChanged(newZoomLevel
);
1442 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1444 KUrl::List list
= selectedUrls();
1445 if (itemsExpandable() ) {
1446 list
= KDirModel::simplifiedUrlList(list
);
1451 QMimeData
* DolphinView::selectionMimeData() const
1453 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1454 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
1455 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
1456 return m_viewAccessor
.dirModel()->mimeData(selection
.indexes());
1459 void DolphinView::addNewFileNames(const QMimeData
* mimeData
)
1461 const KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1462 foreach (const KUrl
& url
, urls
) {
1463 m_newFileNames
.insert(url
.fileName());
1467 DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel
* proxyModel
) :
1470 m_columnsContainer(0),
1471 m_proxyModel(proxyModel
),
1476 DolphinView::ViewAccessor::~ViewAccessor()
1478 delete m_dragSource
;
1482 void DolphinView::ViewAccessor::createView(QWidget
* parent
,
1483 DolphinController
* controller
,
1486 Q_ASSERT(itemView() == 0);
1490 m_iconsView
= new DolphinIconsView(parent
, controller
, m_proxyModel
);
1494 m_detailsView
= new DolphinDetailsView(parent
, controller
, m_proxyModel
);
1498 m_columnsContainer
= new DolphinColumnViewContainer(parent
, controller
);
1506 void DolphinView::ViewAccessor::deleteView()
1508 QAbstractItemView
* view
= itemView();
1510 if (DragAndDropHelper::instance().isDragSource(view
)) {
1511 // The view is a drag source (the feature "Open folders
1512 // during drag operations" is used). Deleting the view
1513 // during an ongoing drag operation is not allowed, so
1514 // this will postponed.
1515 if (m_dragSource
!= 0) {
1516 // the old stored view is obviously not the drag source anymore
1517 m_dragSource
->deleteLater();
1521 m_dragSource
= view
;
1523 view
->deleteLater();
1530 if (m_columnsContainer
!= 0) {
1531 m_columnsContainer
->deleteLater();
1533 m_columnsContainer
= 0;
1537 void DolphinView::ViewAccessor::prepareUrlChange(const KUrl
& url
)
1539 if (m_columnsContainer
!= 0) {
1540 m_columnsContainer
->showColumn(url
);
1543 if(!m_detailsViewExpander
.isNull()) {
1544 // stop expanding items in the current folder
1545 m_detailsViewExpander
->stop();
1549 QAbstractItemView
* DolphinView::ViewAccessor::itemView() const
1551 if (m_iconsView
!= 0) {
1555 if (m_detailsView
!= 0) {
1556 return m_detailsView
;
1559 if (m_columnsContainer
!= 0) {
1560 return m_columnsContainer
->activeColumn();
1566 KFileItemDelegate
* DolphinView::ViewAccessor::itemDelegate() const
1568 return static_cast<KFileItemDelegate
*>(itemView()->itemDelegate());
1571 QWidget
* DolphinView::ViewAccessor::layoutTarget() const
1573 if (m_columnsContainer
!= 0) {
1574 return m_columnsContainer
;
1579 KUrl
DolphinView::ViewAccessor::rootUrl() const
1581 return (m_columnsContainer
!= 0) ? m_columnsContainer
->rootUrl() : KUrl();
1584 KDirLister
* DolphinView::ViewAccessor::rootDirLister() const
1586 return static_cast<DolphinModel
*>(m_proxyModel
->sourceModel())->dirLister();
1589 bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
1591 return m_iconsView
!= 0;
1594 bool DolphinView::ViewAccessor::itemsExpandable() const
1596 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1600 QSet
<KUrl
> DolphinView::ViewAccessor::expandedUrls() const
1602 if (m_detailsView
!= 0) {
1603 return m_detailsView
->expandedUrls();
1606 return QSet
<KUrl
>();
1609 const DolphinDetailsViewExpander
* DolphinView::ViewAccessor::setExpandedUrls(const QSet
<KUrl
>& urlsToExpand
)
1611 if ((m_detailsView
!= 0) && m_detailsView
->itemsExpandable() && !urlsToExpand
.isEmpty()) {
1612 m_detailsViewExpander
= new DolphinDetailsViewExpander(m_detailsView
, urlsToExpand
);
1613 return m_detailsViewExpander
;
1620 bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const
1622 // the details view requires no reloading of the directory, as it maps
1623 // the file item delegate info to its columns internally
1624 return m_detailsView
!= 0;
1627 DolphinModel
* DolphinView::ViewAccessor::dirModel() const
1629 return static_cast<DolphinModel
*>(proxyModel()->sourceModel());
1632 DolphinSortFilterProxyModel
* DolphinView::ViewAccessor::proxyModel() const
1634 if (m_columnsContainer
!= 0) {
1635 return static_cast<DolphinSortFilterProxyModel
*>(m_columnsContainer
->activeColumn()->model());
1637 return m_proxyModel
;
1640 KDirLister
* DolphinView::ViewAccessor::dirLister() const
1642 return dirModel()->dirLister();
1645 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1647 emit
redirection(oldUrl
, newUrl
);
1648 m_controller
->redirectToUrl(newUrl
); // #186947
1651 void DolphinView::restoreContentsPosition()
1653 if (!m_restoredContentsPosition
.isNull()) {
1654 setContentsPosition(m_restoredContentsPosition
.x(), m_restoredContentsPosition
.y());
1655 m_restoredContentsPosition
= QPoint();
1659 #include "dolphinview.moc"