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
.itemView());
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();
227 const KUrl viewPropsUrl
= rootUrl();
228 ViewProperties
props(viewPropsUrl
);
229 props
.setViewMode(m_mode
);
232 // the file item delegate has been recreated, apply the current
233 // additional information manually
234 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
235 m_viewAccessor
.itemDelegate()->setShowInformation(infoList
);
236 emit
additionalInfoChanged();
238 // Not all view modes support categorized sorting. Adjust the sorting model
239 // if changing the view mode results in a change of the categorized sorting
241 m_storedCategorizedSorting
= props
.categorizedSorting();
242 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
243 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
244 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
245 emit
categorizedSortingChanged();
250 updateZoomLevel(oldZoomLevel
);
252 loadDirectory(viewPropsUrl
);
256 DolphinView::Mode
DolphinView::mode() const
261 bool DolphinView::showPreview() const
263 return m_showPreview
;
266 bool DolphinView::showHiddenFiles() const
268 return m_viewAccessor
.dirLister()->showingDotFiles();
271 bool DolphinView::categorizedSorting() const
273 // If all view modes would support categorized sorting, returning
274 // m_viewAccessor.proxyModel()->isCategorizedModel() would be the way to go. As
275 // currently only the icons view supports caterized sorting, we remember
276 // the stored view properties state in m_storedCategorizedSorting and
277 // return this state. The application takes care to disable the corresponding
278 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
279 // that this setting is not applied to the current view mode.
280 return m_storedCategorizedSorting
;
283 bool DolphinView::supportsCategorizedSorting() const
285 return m_viewAccessor
.supportsCategorizedSorting();
288 void DolphinView::selectAll()
290 QAbstractItemView
* view
= m_viewAccessor
.itemView();
291 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
292 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
293 // selection instead of selecting all items. This is bypassed for KDE 4.0
294 // by invoking clearSelection() first.
295 view
->clearSelection();
299 void DolphinView::invertSelection()
301 QItemSelectionModel
* selectionModel
= m_viewAccessor
.itemView()->selectionModel();
302 const QAbstractItemModel
* itemModel
= selectionModel
->model();
304 const QModelIndex topLeft
= itemModel
->index(0, 0);
305 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
306 itemModel
->columnCount() - 1);
308 const QItemSelection
selection(topLeft
, bottomRight
);
309 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
312 bool DolphinView::hasSelection() const
314 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
315 return view
&& view
->selectionModel()->hasSelection();
318 void DolphinView::clearSelection()
320 QItemSelectionModel
* selModel
= m_viewAccessor
.itemView()->selectionModel();
321 const QModelIndex currentIndex
= selModel
->currentIndex();
322 selModel
->setCurrentIndex(currentIndex
, QItemSelectionModel::Current
|
323 QItemSelectionModel::Clear
);
324 m_selectedItems
.clear();
327 KFileItemList
DolphinView::selectedItems() const
329 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
331 // Our view has a selection, we will map them back to the DolphinModel
332 // and then fill the KFileItemList.
333 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
335 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
336 KFileItemList itemList
;
338 const QModelIndexList indexList
= selection
.indexes();
339 foreach (const QModelIndex
&index
, indexList
) {
340 KFileItem item
= m_viewAccessor
.dirModel()->itemForIndex(index
);
341 if (!item
.isNull()) {
342 itemList
.append(item
);
349 KUrl::List
DolphinView::selectedUrls() const
352 const KFileItemList list
= selectedItems();
353 foreach (const KFileItem
&item
, list
) {
354 urls
.append(item
.url());
359 int DolphinView::selectedItemsCount() const
361 return m_viewAccessor
.itemView()->selectionModel()->selectedIndexes().count();
364 void DolphinView::setContentsPosition(int x
, int y
)
366 QAbstractItemView
* view
= m_viewAccessor
.itemView();
368 view
->horizontalScrollBar()->setValue(x
);
369 view
->verticalScrollBar()->setValue(y
);
371 m_loadingDirectory
= false;
374 void DolphinView::setRestoredContentsPosition(const QPoint
& pos
)
376 // TODO: This function is called by DolphinViewContainer.
377 // If it makes use of DolphinView::restoreState(...) to restore the
378 // view state in KDE 4.5, this function can be removed.
379 m_restoredContentsPosition
= pos
;
382 QPoint
DolphinView::contentsPosition() const
384 // TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
385 // view state in KDE 4.5, this code can be moved to DolphinView::saveState.
386 QAbstractItemView
* view
= m_viewAccessor
.itemView();
388 const int x
= view
->horizontalScrollBar()->value();
389 const int y
= view
->verticalScrollBar()->value();
393 void DolphinView::setZoomLevel(int level
)
395 if (level
< ZoomLevelInfo::minimumLevel()) {
396 level
= ZoomLevelInfo::minimumLevel();
397 } else if (level
> ZoomLevelInfo::maximumLevel()) {
398 level
= ZoomLevelInfo::maximumLevel();
401 if (level
!= zoomLevel()) {
402 m_controller
->setZoomLevel(level
);
403 emit
zoomLevelChanged(level
);
407 int DolphinView::zoomLevel() const
409 return m_controller
->zoomLevel();
412 void DolphinView::setSorting(Sorting sorting
)
414 if (sorting
!= this->sorting()) {
415 updateSorting(sorting
);
419 DolphinView::Sorting
DolphinView::sorting() const
421 return m_viewAccessor
.proxyModel()->sorting();
424 void DolphinView::setSortOrder(Qt::SortOrder order
)
426 if (sortOrder() != order
) {
427 updateSortOrder(order
);
431 Qt::SortOrder
DolphinView::sortOrder() const
433 return m_viewAccessor
.proxyModel()->sortOrder();
436 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
438 if (sortFoldersFirst() != foldersFirst
) {
439 updateSortFoldersFirst(foldersFirst
);
443 bool DolphinView::sortFoldersFirst() const
445 return m_viewAccessor
.proxyModel()->sortFoldersFirst();
448 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
450 const KUrl viewPropsUrl
= rootUrl();
451 ViewProperties
props(viewPropsUrl
);
452 props
.setAdditionalInfo(info
);
453 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
455 emit
additionalInfoChanged();
457 if (m_viewAccessor
.reloadOnAdditionalInfoChange()) {
458 loadDirectory(viewPropsUrl
);
462 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
464 return m_viewAccessor
.itemDelegate()->showInformation();
467 void DolphinView::reload()
470 loadDirectory(url(), true);
473 void DolphinView::refresh()
475 m_ignoreViewProperties
= false;
477 const bool oldActivationState
= m_active
;
478 const int oldZoomLevel
= m_controller
->zoomLevel();
482 applyViewProperties();
485 setActive(oldActivationState
);
486 updateZoomLevel(oldZoomLevel
);
489 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
491 Q_UNUSED(rootUrl
); // TODO: remove after columnview-cleanup has been finished
493 if (m_controller
->url() == url
) {
497 m_controller
->setUrl(url
); // emits urlChanged, which we forward
498 m_viewAccessor
.prepareUrlChange(url
);
499 applyViewProperties();
502 // When changing the URL there is no need to keep the version
503 // data of the previous URL.
504 m_viewAccessor
.dirModel()->clearVersionData();
506 emit
startedPathLoading(url
);
509 void DolphinView::setNameFilter(const QString
& nameFilter
)
511 m_controller
->setNameFilter(nameFilter
);
514 void DolphinView::calculateItemCount(int& fileCount
,
516 KIO::filesize_t
& totalFileSize
) const
518 foreach (const KFileItem
& item
, m_viewAccessor
.dirLister()->items()) {
523 totalFileSize
+= item
.size();
528 QString
DolphinView::statusBarText() const
533 KIO::filesize_t totalFileSize
= 0;
535 if (hasSelection()) {
536 // give a summary of the status of the selected files
537 const KFileItemList list
= selectedItems();
538 if (list
.isEmpty()) {
539 // when an item is triggered, it is temporary selected but selectedItems()
540 // will return an empty list
544 KFileItemList::const_iterator it
= list
.begin();
545 const KFileItemList::const_iterator end
= list
.end();
547 const KFileItem
& item
= *it
;
552 totalFileSize
+= item
.size();
557 if (folderCount
+ fileCount
== 1) {
558 // if only one item is selected, show the filename
559 const QString name
= list
.first().name();
560 text
= (folderCount
== 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name
) :
561 i18nc("@info:status", "<filename>%1</filename> selected (%2)",
562 name
, KIO::convertSize(totalFileSize
));
564 // at least 2 items are selected
565 const QString foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
566 const QString filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
567 if ((folderCount
> 0) && (fileCount
> 0)) {
568 text
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
569 foldersText
, filesText
, KIO::convertSize(totalFileSize
));
570 } else if (fileCount
> 0) {
571 text
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KIO::convertSize(totalFileSize
));
573 Q_ASSERT(folderCount
> 0);
578 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
579 text
= KIO::itemsSummaryString(fileCount
+ folderCount
,
580 fileCount
, folderCount
,
581 totalFileSize
, true);
587 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
589 return m_controller
->versionControlActions(items
);
592 void DolphinView::setUrl(const KUrl
& url
)
594 m_newFileNames
.clear();
595 updateView(url
, KUrl());
598 void DolphinView::changeSelection(const KFileItemList
& selection
)
601 if (selection
.isEmpty()) {
604 const KUrl
& baseUrl
= url();
606 QItemSelection newSelection
;
607 foreach(const KFileItem
& item
, selection
) {
608 url
= item
.url().upUrl();
609 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
610 QModelIndex index
= m_viewAccessor
.proxyModel()->mapFromSource(m_viewAccessor
.dirModel()->indexForItem(item
));
611 newSelection
.select(index
, index
);
614 m_viewAccessor
.itemView()->selectionModel()->select(newSelection
,
615 QItemSelectionModel::ClearAndSelect
616 | QItemSelectionModel::Current
);
619 void DolphinView::renameSelectedItems()
621 KFileItemList items
= selectedItems();
622 const int itemCount
= items
.count();
628 // More than one item has been selected for renaming. Open
629 // a rename dialog and rename all items afterwards.
630 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
631 if (dialog
->exec() == QDialog::Rejected
) {
636 const QString newName
= dialog
->newName();
637 if (newName
.isEmpty()) {
638 emit
errorMessage(dialog
->errorString());
644 // the selection would be invalid after renaming the items, so just clear
648 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
649 // as one operation instead of n rename operations like it is done now...
650 Q_ASSERT(newName
.contains('#'));
652 // currently the items are sorted by the selection order, resort
653 // them by the file name
654 qSort(items
.begin(), items
.end(), lessThan
);
656 // iterate through all selected items and rename them...
658 foreach (const KFileItem
& item
, items
) {
659 const KUrl
& oldUrl
= item
.url();
661 number
.setNum(index
++);
663 QString name
= newName
;
664 name
.replace('#', number
);
666 if (oldUrl
.fileName() != name
) {
667 KUrl newUrl
= oldUrl
;
668 newUrl
.setFileName(name
);
669 KonqOperations::rename(this, oldUrl
, newUrl
);
672 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
673 Q_ASSERT(itemCount
== 1);
674 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForItem(items
.first());
675 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
676 m_viewAccessor
.itemView()->edit(proxyIndex
);
678 Q_ASSERT(itemCount
== 1);
680 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
681 if (dialog
->exec() == QDialog::Rejected
) {
686 const QString newName
= dialog
->newName();
687 if (newName
.isEmpty()) {
688 emit
errorMessage(dialog
->errorString());
694 const KUrl
& oldUrl
= items
.first().url();
695 KUrl newUrl
= oldUrl
;
696 newUrl
.setFileName(newName
);
697 KonqOperations::rename(this, oldUrl
, newUrl
);
700 // assure that the current index remains visible when KDirLister
701 // will notify the view about changed items
702 m_assureVisibleCurrentIndex
= true;
705 void DolphinView::trashSelectedItems()
707 const KUrl::List list
= simplifiedSelectedUrls();
708 KonqOperations::del(this, KonqOperations::TRASH
, list
);
711 void DolphinView::deleteSelectedItems()
713 const KUrl::List list
= simplifiedSelectedUrls();
714 const bool del
= KonqOperations::askDeleteConfirmation(list
,
716 KonqOperations::DEFAULT_CONFIRMATION
,
720 KIO::Job
* job
= KIO::del(list
);
721 connect(job
, SIGNAL(result(KJob
*)),
722 this, SLOT(slotDeleteFileFinished(KJob
*)));
726 void DolphinView::cutSelectedItems()
728 QMimeData
* mimeData
= selectionMimeData();
729 KonqMimeData::addIsCutSelection(mimeData
, true);
730 QApplication::clipboard()->setMimeData(mimeData
);
733 void DolphinView::copySelectedItems()
735 QMimeData
* mimeData
= selectionMimeData();
736 QApplication::clipboard()->setMimeData(mimeData
);
739 void DolphinView::paste()
744 void DolphinView::pasteIntoFolder()
746 const KFileItemList items
= selectedItems();
747 if ((items
.count() == 1) && items
.first().isDir()) {
748 pasteToUrl(items
.first().url());
752 void DolphinView::setShowPreview(bool show
)
754 if (m_showPreview
== show
) {
758 const KUrl viewPropsUrl
= rootUrl();
759 ViewProperties
props(viewPropsUrl
);
760 props
.setShowPreview(show
);
762 m_showPreview
= show
;
763 const int oldZoomLevel
= m_controller
->zoomLevel();
764 emit
showPreviewChanged();
766 // Enabling or disabling the preview might change the icon size of the view.
767 // As the view does not emit a signal when the icon size has been changed,
768 // the used zoom level of the controller must be adjusted manually:
769 updateZoomLevel(oldZoomLevel
);
772 void DolphinView::setShowHiddenFiles(bool show
)
774 if (m_viewAccessor
.dirLister()->showingDotFiles() == show
) {
778 const KUrl viewPropsUrl
= rootUrl();
779 ViewProperties
props(viewPropsUrl
);
780 props
.setShowHiddenFiles(show
);
782 m_viewAccessor
.dirLister()->setShowingDotFiles(show
);
783 emit
showHiddenFilesChanged();
786 void DolphinView::setCategorizedSorting(bool categorized
)
788 if (categorized
== categorizedSorting()) {
792 // setCategorizedSorting(true) may only get invoked
793 // if the view supports categorized sorting
794 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
796 ViewProperties
props(rootUrl());
797 props
.setCategorizedSorting(categorized
);
800 m_storedCategorizedSorting
= categorized
;
801 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
803 emit
categorizedSortingChanged();
806 void DolphinView::toggleSortOrder()
808 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
809 Qt::DescendingOrder
:
814 void DolphinView::toggleSortFoldersFirst()
816 setSortFoldersFirst(!sortFoldersFirst());
819 void DolphinView::toggleAdditionalInfo(QAction
* action
)
821 const KFileItemDelegate::Information info
=
822 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
824 KFileItemDelegate::InformationList list
= additionalInfo();
826 const bool show
= action
->isChecked();
828 const int index
= list
.indexOf(info
);
829 const bool containsInfo
= (index
>= 0);
830 if (show
&& !containsInfo
) {
832 setAdditionalInfo(list
);
833 } else if (!show
&& containsInfo
) {
834 list
.removeAt(index
);
835 setAdditionalInfo(list
);
836 Q_ASSERT(list
.indexOf(info
) < 0);
840 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
842 QWidget::mouseReleaseEvent(event
);
846 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
848 switch (event
->type()) {
849 case QEvent::FocusIn
:
850 if (watched
== m_viewAccessor
.itemView()) {
851 m_controller
->requestActivation();
855 case QEvent::DragEnter
:
856 if (watched
== m_viewAccessor
.itemView()->viewport()) {
861 case QEvent::KeyPress
:
862 if (watched
== m_viewAccessor
.itemView()) {
863 // clear the selection when Escape has been pressed
864 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
865 if (keyEvent
->key() == Qt::Key_Escape
) {
872 if (watched
== m_viewAccessor
.itemView()->viewport()) {
873 // Ctrl+wheel events should cause icon zooming, but not if the left mouse button is pressed
874 // (the user is probably trying to scroll during a selection in that case)
875 QWheelEvent
* wheelEvent
= static_cast<QWheelEvent
*>(event
);
876 if (wheelEvent
->modifiers() & Qt::ControlModifier
&& !(wheelEvent
->buttons() & Qt::LeftButton
)) {
877 const int delta
= wheelEvent
->delta();
878 const int level
= zoomLevel();
880 setZoomLevel(level
+ 1);
881 } else if (delta
< 0) {
882 setZoomLevel(level
- 1);
893 return QWidget::eventFilter(watched
, event
);
896 void DolphinView::activate()
901 void DolphinView::triggerItem(const KFileItem
& item
)
903 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
904 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
905 // items are selected by the user, hence don't trigger the
906 // item specified by 'index'
910 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
911 if (item
.isNull() || m_isContextMenuOpen
) {
915 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
918 void DolphinView::emitDelayedSelectionChangedSignal()
920 // Invoke emitSelectionChangedSignal() with a delay of 300 ms. This assures
921 // that fast selection changes don't result in expensive operations to
922 // collect all file items for the signal (see DolphinView::selectedItems()).
923 m_selectionChangedTimer
->start();
926 void DolphinView::emitSelectionChangedSignal()
928 emit
selectionChanged(DolphinView::selectedItems());
931 void DolphinView::openContextMenu(const QPoint
& pos
,
932 const QList
<QAction
*>& customActions
)
935 const QModelIndex index
= m_viewAccessor
.itemView()->indexAt(pos
);
936 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
937 const QModelIndex dolphinModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(index
);
938 item
= m_viewAccessor
.dirModel()->itemForIndex(dolphinModelIndex
);
941 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
942 emit
requestContextMenu(item
, url(), customActions
);
943 m_isContextMenuOpen
= false;
946 void DolphinView::dropUrls(const KFileItem
& destItem
,
947 const KUrl
& destPath
,
950 addNewFileNames(event
->mimeData());
951 DragAndDropHelper::instance().dropUrls(destItem
, destPath
, event
, this);
954 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
956 ViewProperties
props(rootUrl());
957 props
.setSorting(sorting
);
959 m_viewAccessor
.proxyModel()->setSorting(sorting
);
961 emit
sortingChanged(sorting
);
964 void DolphinView::updateSortOrder(Qt::SortOrder order
)
966 ViewProperties
props(rootUrl());
967 props
.setSortOrder(order
);
969 m_viewAccessor
.proxyModel()->setSortOrder(order
);
971 emit
sortOrderChanged(order
);
974 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
976 ViewProperties
props(rootUrl());
977 props
.setSortFoldersFirst(foldersFirst
);
979 m_viewAccessor
.proxyModel()->setSortFoldersFirst(foldersFirst
);
981 emit
sortFoldersFirstChanged(foldersFirst
);
984 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
986 ViewProperties
props(rootUrl());
987 props
.setAdditionalInfo(info
);
990 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
992 emit
additionalInfoChanged();
995 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
997 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
998 (m_mode
== DolphinView::IconsView
);
1000 QAction
* showSizeInfo
= collection
->action("show_size_info");
1001 QAction
* showDateInfo
= collection
->action("show_date_info");
1002 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
1003 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
1004 QAction
* showGroupInfo
= collection
->action("show_group_info");
1005 QAction
* showMimeInfo
= collection
->action("show_mime_info");
1007 showSizeInfo
->setChecked(false);
1008 showDateInfo
->setChecked(false);
1009 showPermissionsInfo
->setChecked(false);
1010 showOwnerInfo
->setChecked(false);
1011 showGroupInfo
->setChecked(false);
1012 showMimeInfo
->setChecked(false);
1014 showSizeInfo
->setEnabled(enable
);
1015 showDateInfo
->setEnabled(enable
);
1016 showPermissionsInfo
->setEnabled(enable
);
1017 showOwnerInfo
->setEnabled(enable
);
1018 showGroupInfo
->setEnabled(enable
);
1019 showMimeInfo
->setEnabled(enable
);
1021 foreach (KFileItemDelegate::Information info
, m_viewAccessor
.itemDelegate()->showInformation()) {
1023 case KFileItemDelegate::Size
:
1024 showSizeInfo
->setChecked(true);
1026 case KFileItemDelegate::ModificationTime
:
1027 showDateInfo
->setChecked(true);
1029 case KFileItemDelegate::Permissions
:
1030 showPermissionsInfo
->setChecked(true);
1032 case KFileItemDelegate::Owner
:
1033 showOwnerInfo
->setChecked(true);
1035 case KFileItemDelegate::OwnerAndGroup
:
1036 showGroupInfo
->setChecked(true);
1038 case KFileItemDelegate::FriendlyMimeType
:
1039 showMimeInfo
->setChecked(true);
1047 QPair
<bool, QString
> DolphinView::pasteInfo() const
1049 return KonqOperations::pasteInfo(url());
1052 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1054 m_tabsForFiles
= tabsForFiles
;
1057 bool DolphinView::isTabsForFilesEnabled() const
1059 return m_tabsForFiles
;
1062 void DolphinView::activateItem(const KUrl
& url
)
1064 // TODO: If DolphinViewContainer uses DolphinView::restoreState(...) to restore the
1065 // view state in KDE 4.5, this function can be removed.
1066 m_activeItemUrl
= url
;
1069 bool DolphinView::itemsExpandable() const
1071 return m_viewAccessor
.itemsExpandable();
1074 void DolphinView::restoreState(QDataStream
&stream
)
1077 stream
>> m_activeItemUrl
;
1080 stream
>> m_restoredContentsPosition
;
1082 // expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1083 QSet
<KUrl
> urlsToExpand
;
1084 stream
>> urlsToExpand
;
1085 const DolphinDetailsViewExpander
* expander
= m_viewAccessor
.setExpandedUrls(urlsToExpand
);
1088 m_expanderActive
= true;
1089 connect (expander
, SIGNAL(completed()), this, SLOT(slotLoadingCompleted()));
1092 m_expanderActive
= false;
1096 void DolphinView::saveState(QDataStream
&stream
)
1099 KFileItem currentItem
;
1100 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1103 const QModelIndex proxyIndex
= view
->currentIndex();
1104 const QModelIndex dirModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1105 currentItem
= m_viewAccessor
.dirModel()->itemForIndex(dirModelIndex
);
1109 if (!currentItem
.isNull())
1110 currentUrl
= currentItem
.url();
1112 stream
<< currentUrl
;
1115 stream
<< contentsPosition();
1117 // expanded folders (only relevant for the details view - the set will be empty in other view modes)
1118 stream
<< m_viewAccessor
.expandedUrls();
1121 void DolphinView::observeCreatedItem(const KUrl
& url
)
1123 m_createdItemUrl
= url
;
1124 connect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1125 this, SLOT(selectAndScrollToCreatedItem()));
1128 void DolphinView::selectAndScrollToCreatedItem()
1130 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_createdItemUrl
);
1131 if (dirIndex
.isValid()) {
1132 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1133 m_viewAccessor
.itemView()->setCurrentIndex(proxyIndex
);
1136 disconnect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1137 this, SLOT(selectAndScrollToCreatedItem()));
1138 m_createdItemUrl
= KUrl();
1141 void DolphinView::restoreSelection()
1143 disconnect(m_viewAccessor
.dirLister(), SIGNAL(completed()), this, SLOT(restoreSelection()));
1144 changeSelection(m_selectedItems
);
1147 void DolphinView::emitContentsMoved()
1149 // TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
1150 // view state in KDE 4.5, the contentsMoved signal might not be needed anymore,
1151 // depending on how the implementation is done.
1152 // In that case, the code in contentsPosition() can be moved to saveState().
1154 // only emit the contents moved signal if no directory loading is ongoing
1155 // (this would reset the contents position always to (0, 0))
1156 if (!m_loadingDirectory
) {
1157 const QPoint
pos(contentsPosition());
1158 emit
contentsMoved(pos
.x(), pos
.y());
1162 void DolphinView::showHoverInformation(const KFileItem
& item
)
1164 emit
requestItemInfo(item
);
1167 void DolphinView::clearHoverInformation()
1169 emit
requestItemInfo(KFileItem());
1172 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1174 if (job
->error() == 0) {
1175 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1176 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1177 emit
errorMessage(job
->errorString());
1181 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1183 emit
requestUrlChange(url
);
1184 m_controller
->setUrl(url
);
1187 void DolphinView::slotDirListerCompleted()
1189 if (!m_expanderActive
) {
1190 slotLoadingCompleted();
1193 if (!m_newFileNames
.isEmpty()) {
1194 // select all newly added items created by a paste operation or
1195 // a drag & drop operation
1196 const int rowCount
= m_viewAccessor
.proxyModel()->rowCount();
1197 QItemSelection selection
;
1198 for (int row
= 0; row
< rowCount
; ++row
) {
1199 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->index(row
, 0);
1200 const QModelIndex dirIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1201 const KUrl url
= m_viewAccessor
.dirModel()->itemForIndex(dirIndex
).url();
1202 if (m_newFileNames
.contains(url
.fileName())) {
1203 selection
.merge(QItemSelection(proxyIndex
, proxyIndex
), QItemSelectionModel::Select
);
1206 m_viewAccessor
.itemView()->selectionModel()->select(selection
, QItemSelectionModel::Select
);
1208 m_newFileNames
.clear();
1212 void DolphinView::slotLoadingCompleted()
1214 m_expanderActive
= false;
1215 m_loadingDirectory
= false;
1217 if (!m_activeItemUrl
.isEmpty()) {
1218 // assure that the current item remains visible
1219 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_activeItemUrl
);
1220 if (dirIndex
.isValid()) {
1221 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1222 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1223 const bool clearSelection
= !hasSelection();
1224 view
->setCurrentIndex(proxyIndex
);
1225 if (clearSelection
) {
1226 view
->clearSelection();
1228 m_activeItemUrl
.clear();
1232 // Restore the contents position. This has to be done using a Qt::QueuedConnection
1233 // because the view might not be in its final state yet.
1234 QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection
);
1237 void DolphinView::slotRefreshItems()
1239 if (m_assureVisibleCurrentIndex
) {
1240 m_assureVisibleCurrentIndex
= false;
1241 m_viewAccessor
.itemView()->scrollTo(m_viewAccessor
.itemView()->currentIndex());
1245 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1247 if (!url
.isValid()) {
1248 const QString
location(url
.pathOrUrl());
1249 if (location
.isEmpty()) {
1250 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1252 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1257 m_loadingDirectory
= true;
1258 m_expanderActive
= false;
1261 m_selectedItems
= selectedItems();
1262 connect(m_viewAccessor
.dirLister(), SIGNAL(completed()), this, SLOT(restoreSelection()));
1265 m_viewAccessor
.dirLister()->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1268 void DolphinView::applyViewProperties()
1270 if (m_ignoreViewProperties
) {
1274 const ViewProperties
props(rootUrl());
1276 const Mode mode
= props
.viewMode();
1277 if (m_mode
!= mode
) {
1278 const int oldZoomLevel
= m_controller
->zoomLevel();
1284 updateZoomLevel(oldZoomLevel
);
1286 if (m_viewAccessor
.itemView() == 0) {
1289 Q_ASSERT(m_viewAccessor
.itemView() != 0);
1290 Q_ASSERT(m_viewAccessor
.itemDelegate() != 0);
1292 const bool showHiddenFiles
= props
.showHiddenFiles();
1293 if (showHiddenFiles
!= m_viewAccessor
.dirLister()->showingDotFiles()) {
1294 m_viewAccessor
.dirLister()->setShowingDotFiles(showHiddenFiles
);
1295 emit
showHiddenFilesChanged();
1298 m_storedCategorizedSorting
= props
.categorizedSorting();
1299 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1300 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
1301 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
1302 emit
categorizedSortingChanged();
1305 const DolphinView::Sorting sorting
= props
.sorting();
1306 if (sorting
!= m_viewAccessor
.proxyModel()->sorting()) {
1307 m_viewAccessor
.proxyModel()->setSorting(sorting
);
1308 emit
sortingChanged(sorting
);
1311 const Qt::SortOrder sortOrder
= props
.sortOrder();
1312 if (sortOrder
!= m_viewAccessor
.proxyModel()->sortOrder()) {
1313 m_viewAccessor
.proxyModel()->setSortOrder(sortOrder
);
1314 emit
sortOrderChanged(sortOrder
);
1317 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1318 if (sortFoldersFirst
!= m_viewAccessor
.proxyModel()->sortFoldersFirst()) {
1319 m_viewAccessor
.proxyModel()->setSortFoldersFirst(sortFoldersFirst
);
1320 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1323 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1324 if (info
!= m_viewAccessor
.itemDelegate()->showInformation()) {
1325 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
1326 emit
additionalInfoChanged();
1329 const bool showPreview
= props
.showPreview();
1330 if (showPreview
!= m_showPreview
) {
1331 m_showPreview
= showPreview
;
1332 const int oldZoomLevel
= m_controller
->zoomLevel();
1333 emit
showPreviewChanged();
1335 // Enabling or disabling the preview might change the icon size of the view.
1336 // As the view does not emit a signal when the icon size has been changed,
1337 // the used zoom level of the controller must be adjusted manually:
1338 updateZoomLevel(oldZoomLevel
);
1341 if (DolphinSettings::instance().generalSettings()->globalViewProps()) {
1342 // During the lifetime of a DolphinView instance the global view properties
1343 // should not be changed. This allows e. g. to split a view and use different
1344 // view properties for each view.
1345 m_ignoreViewProperties
= true;
1349 void DolphinView::createView()
1353 Q_ASSERT(m_viewAccessor
.itemView() == 0);
1354 m_viewAccessor
.createView(this, m_controller
, m_mode
);
1356 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1357 Q_ASSERT(view
!= 0);
1358 view
->installEventFilter(this);
1359 view
->viewport()->installEventFilter(this);
1361 m_controller
->setItemView(view
);
1362 connect(m_controller
, SIGNAL(selectionChanged()),
1363 this, SLOT(emitDelayedSelectionChangedSignal()));
1365 // When changing the view mode, the selection is lost due to reinstantiating
1366 // a new item view with a custom selection model. Pass the ownership of the
1367 // selection model to DolphinView, so that it can be shared by all item views.
1368 if (m_selectionModel
!= 0) {
1369 view
->setSelectionModel(m_selectionModel
);
1371 m_selectionModel
= view
->selectionModel();
1373 m_selectionModel
->setParent(this);
1375 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1376 this, SLOT(emitContentsMoved()));
1377 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1378 this, SLOT(emitContentsMoved()));
1380 setFocusProxy(m_viewAccessor
.layoutTarget());
1381 m_topLayout
->insertWidget(1, m_viewAccessor
.layoutTarget());
1384 void DolphinView::deleteView()
1386 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1388 // It's important to set the keyboard focus to the parent
1389 // before deleting the view: Otherwise when having a split
1390 // view the other view will get the focus and will request
1391 // an activation (see DolphinView::eventFilter()).
1395 m_topLayout
->removeWidget(view
);
1398 // disconnect all signal/slots
1400 m_controller
->disconnect(view
);
1402 disconnect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1403 this, SLOT(emitContentsMoved()));
1404 disconnect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1405 this, SLOT(emitContentsMoved()));
1407 m_viewAccessor
.deleteView();
1411 void DolphinView::pasteToUrl(const KUrl
& url
)
1413 addNewFileNames(QApplication::clipboard()->mimeData());
1414 KonqOperations::doPaste(this, url
);
1417 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1419 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor
.itemView()->iconSize());
1420 if (oldZoomLevel
!= newZoomLevel
) {
1421 m_controller
->setZoomLevel(newZoomLevel
);
1422 emit
zoomLevelChanged(newZoomLevel
);
1426 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1428 KUrl::List list
= selectedUrls();
1429 if (itemsExpandable() ) {
1430 list
= KDirModel::simplifiedUrlList(list
);
1435 QMimeData
* DolphinView::selectionMimeData() const
1437 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1438 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
1439 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
1440 return m_viewAccessor
.dirModel()->mimeData(selection
.indexes());
1443 void DolphinView::addNewFileNames(const QMimeData
* mimeData
)
1445 const KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1446 foreach (const KUrl
& url
, urls
) {
1447 m_newFileNames
.insert(url
.fileName());
1451 DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel
* proxyModel
) :
1454 m_columnsContainer(0),
1455 m_proxyModel(proxyModel
),
1460 DolphinView::ViewAccessor::~ViewAccessor()
1462 delete m_dragSource
;
1466 void DolphinView::ViewAccessor::createView(QWidget
* parent
,
1467 DolphinController
* controller
,
1470 Q_ASSERT(itemView() == 0);
1474 m_iconsView
= new DolphinIconsView(parent
, controller
, m_proxyModel
);
1478 m_detailsView
= new DolphinDetailsView(parent
, controller
, m_proxyModel
);
1482 m_columnsContainer
= new DolphinColumnViewContainer(parent
, controller
);
1490 void DolphinView::ViewAccessor::deleteView()
1492 QAbstractItemView
* view
= itemView();
1494 if (DragAndDropHelper::instance().isDragSource(view
)) {
1495 // The view is a drag source (the feature "Open folders
1496 // during drag operations" is used). Deleting the view
1497 // during an ongoing drag operation is not allowed, so
1498 // this will postponed.
1499 if (m_dragSource
!= 0) {
1500 // the old stored view is obviously not the drag source anymore
1501 m_dragSource
->deleteLater();
1505 m_dragSource
= view
;
1507 view
->deleteLater();
1514 if (m_columnsContainer
!= 0) {
1515 m_columnsContainer
->deleteLater();
1517 m_columnsContainer
= 0;
1521 void DolphinView::ViewAccessor::prepareUrlChange(const KUrl
& url
)
1523 if (m_columnsContainer
!= 0) {
1524 m_columnsContainer
->showColumn(url
);
1527 if(!m_detailsViewExpander
.isNull()) {
1528 // Stop expanding items in the current folder
1529 m_detailsViewExpander
->stop();
1533 QAbstractItemView
* DolphinView::ViewAccessor::itemView() const
1535 if (m_iconsView
!= 0) {
1539 if (m_detailsView
!= 0) {
1540 return m_detailsView
;
1543 if (m_columnsContainer
!= 0) {
1544 return m_columnsContainer
->activeColumn();
1550 KFileItemDelegate
* DolphinView::ViewAccessor::itemDelegate() const
1552 return static_cast<KFileItemDelegate
*>(itemView()->itemDelegate());
1555 QWidget
* DolphinView::ViewAccessor::layoutTarget() const
1557 if (m_columnsContainer
!= 0) {
1558 return m_columnsContainer
;
1563 KUrl
DolphinView::ViewAccessor::rootUrl() const
1565 return (m_columnsContainer
!= 0) ? m_columnsContainer
->rootUrl() : KUrl();
1568 bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
1570 return m_iconsView
!= 0;
1573 bool DolphinView::ViewAccessor::itemsExpandable() const
1575 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1579 QSet
<KUrl
> DolphinView::ViewAccessor::expandedUrls() const
1581 if(m_detailsView
!= 0) {
1582 return m_detailsView
->expandedUrls();
1585 return QSet
<KUrl
>();
1589 const DolphinDetailsViewExpander
* DolphinView::ViewAccessor::setExpandedUrls(const QSet
<KUrl
>& urlsToExpand
)
1591 if((m_detailsView
!= 0) && m_detailsView
->itemsExpandable() && !urlsToExpand
.isEmpty()) {
1592 m_detailsViewExpander
= new DolphinDetailsViewExpander(m_detailsView
, urlsToExpand
);
1593 return m_detailsViewExpander
;
1600 bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const
1602 // the details view requires no reloading of the directory, as it maps
1603 // the file item delegate info to its columns internally
1604 return m_detailsView
!= 0;
1607 DolphinModel
* DolphinView::ViewAccessor::dirModel() const
1609 return static_cast<DolphinModel
*>(proxyModel()->sourceModel());
1612 DolphinSortFilterProxyModel
* DolphinView::ViewAccessor::proxyModel() const
1614 if (m_columnsContainer
!= 0) {
1615 return static_cast<DolphinSortFilterProxyModel
*>(m_columnsContainer
->activeColumn()->model());
1617 return m_proxyModel
;
1620 KDirLister
* DolphinView::ViewAccessor::dirLister() const
1622 return dirModel()->dirLister();
1625 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1627 emit
redirection(oldUrl
, newUrl
);
1628 m_controller
->redirectToUrl(newUrl
); // #186947
1631 void DolphinView::restoreContentsPosition()
1633 if (!m_restoredContentsPosition
.isNull()) {
1634 setContentsPosition(m_restoredContentsPosition
.x(), m_restoredContentsPosition
.y());
1635 m_restoredContentsPosition
= QPoint();
1639 #include "dolphinview.moc"