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 bool DolphinView::hasSelection() const
290 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
291 return view
&& view
->selectionModel()->hasSelection();
294 void DolphinView::markUrlsAsSelected(const QList
<KUrl
>& urls
)
296 foreach (const KUrl
& url
, urls
) {
297 KFileItem
item(KFileItem::Unknown
, KFileItem::Unknown
, url
);
298 m_selectedItems
.append(item
);
302 KFileItemList
DolphinView::selectedItems() const
304 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
306 // Our view has a selection, we will map them back to the DolphinModel
307 // and then fill the KFileItemList.
308 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
310 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
311 KFileItemList itemList
;
313 const QModelIndexList indexList
= selection
.indexes();
314 foreach (const QModelIndex
&index
, indexList
) {
315 KFileItem item
= m_viewAccessor
.dirModel()->itemForIndex(index
);
316 if (!item
.isNull()) {
317 itemList
.append(item
);
324 KUrl::List
DolphinView::selectedUrls() const
327 const KFileItemList list
= selectedItems();
328 foreach (const KFileItem
&item
, list
) {
329 urls
.append(item
.url());
334 int DolphinView::selectedItemsCount() const
336 return m_viewAccessor
.itemView()->selectionModel()->selectedIndexes().count();
339 QItemSelectionModel
* DolphinView::selectionModel() const
341 return m_viewAccessor
.itemView()->selectionModel();
344 void DolphinView::setContentsPosition(int x
, int y
)
346 QAbstractItemView
* view
= m_viewAccessor
.itemView();
348 view
->horizontalScrollBar()->setValue(x
);
349 view
->verticalScrollBar()->setValue(y
);
351 m_loadingDirectory
= false;
354 void DolphinView::setRestoredContentsPosition(const QPoint
& pos
)
356 // TODO: This function is called by DolphinViewContainer.
357 // If it makes use of DolphinView::restoreState(...) to restore the
358 // view state in KDE 4.5, this function can be removed.
359 m_restoredContentsPosition
= pos
;
362 QPoint
DolphinView::contentsPosition() const
364 // TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
365 // view state in KDE 4.5, this code can be moved to DolphinView::saveState.
366 QAbstractItemView
* view
= m_viewAccessor
.itemView();
368 const int x
= view
->horizontalScrollBar()->value();
369 const int y
= view
->verticalScrollBar()->value();
373 void DolphinView::setZoomLevel(int level
)
375 if (level
< ZoomLevelInfo::minimumLevel()) {
376 level
= ZoomLevelInfo::minimumLevel();
377 } else if (level
> ZoomLevelInfo::maximumLevel()) {
378 level
= ZoomLevelInfo::maximumLevel();
381 if (level
!= zoomLevel()) {
382 m_controller
->setZoomLevel(level
);
383 emit
zoomLevelChanged(level
);
387 int DolphinView::zoomLevel() const
389 return m_controller
->zoomLevel();
392 void DolphinView::setSorting(Sorting sorting
)
394 if (sorting
!= this->sorting()) {
395 updateSorting(sorting
);
399 DolphinView::Sorting
DolphinView::sorting() const
401 return m_viewAccessor
.proxyModel()->sorting();
404 void DolphinView::setSortOrder(Qt::SortOrder order
)
406 if (sortOrder() != order
) {
407 updateSortOrder(order
);
411 Qt::SortOrder
DolphinView::sortOrder() const
413 return m_viewAccessor
.proxyModel()->sortOrder();
416 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
418 if (sortFoldersFirst() != foldersFirst
) {
419 updateSortFoldersFirst(foldersFirst
);
423 bool DolphinView::sortFoldersFirst() const
425 return m_viewAccessor
.proxyModel()->sortFoldersFirst();
428 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
430 const KUrl viewPropsUrl
= rootUrl();
431 ViewProperties
props(viewPropsUrl
);
432 props
.setAdditionalInfo(info
);
433 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
435 emit
additionalInfoChanged();
437 if (m_viewAccessor
.reloadOnAdditionalInfoChange()) {
438 loadDirectory(viewPropsUrl
);
442 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
444 return m_viewAccessor
.itemDelegate()->showInformation();
447 void DolphinView::reload()
449 QByteArray viewState
;
450 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
451 saveState(saveStream
);
452 m_selectedItems
= selectedItems();
455 loadDirectory(url(), true);
457 QDataStream
restoreStream(viewState
);
458 restoreState(restoreStream
);
461 void DolphinView::refresh()
463 m_ignoreViewProperties
= false;
465 const bool oldActivationState
= m_active
;
466 const int oldZoomLevel
= m_controller
->zoomLevel();
470 applyViewProperties();
473 setActive(oldActivationState
);
474 updateZoomLevel(oldZoomLevel
);
477 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
479 Q_UNUSED(rootUrl
); // TODO: remove after columnview-cleanup has been finished
481 if (m_controller
->url() == url
) {
485 m_controller
->setUrl(url
); // emits urlChanged, which we forward
486 m_viewAccessor
.prepareUrlChange(url
);
487 applyViewProperties();
490 // When changing the URL there is no need to keep the version
491 // data of the previous URL.
492 m_viewAccessor
.dirModel()->clearVersionData();
494 emit
startedPathLoading(url
);
497 void DolphinView::setNameFilter(const QString
& nameFilter
)
499 m_controller
->setNameFilter(nameFilter
);
502 void DolphinView::calculateItemCount(int& fileCount
,
504 KIO::filesize_t
& totalFileSize
) const
506 foreach (const KFileItem
& item
, m_viewAccessor
.dirLister()->items()) {
511 totalFileSize
+= item
.size();
516 QString
DolphinView::statusBarText() const
521 KIO::filesize_t totalFileSize
= 0;
523 if (hasSelection()) {
524 // give a summary of the status of the selected files
525 const KFileItemList list
= selectedItems();
526 if (list
.isEmpty()) {
527 // when an item is triggered, it is temporary selected but selectedItems()
528 // will return an empty list
532 KFileItemList::const_iterator it
= list
.begin();
533 const KFileItemList::const_iterator end
= list
.end();
535 const KFileItem
& item
= *it
;
540 totalFileSize
+= item
.size();
545 if (folderCount
+ fileCount
== 1) {
546 // if only one item is selected, show the filename
547 const QString name
= list
.first().name();
548 text
= (folderCount
== 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name
) :
549 i18nc("@info:status", "<filename>%1</filename> selected (%2)",
550 name
, KIO::convertSize(totalFileSize
));
552 // at least 2 items are selected
553 const QString foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
554 const QString filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
555 if ((folderCount
> 0) && (fileCount
> 0)) {
556 text
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
557 foldersText
, filesText
, KIO::convertSize(totalFileSize
));
558 } else if (fileCount
> 0) {
559 text
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KIO::convertSize(totalFileSize
));
561 Q_ASSERT(folderCount
> 0);
566 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
567 text
= KIO::itemsSummaryString(fileCount
+ folderCount
,
568 fileCount
, folderCount
,
569 totalFileSize
, true);
575 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
577 return m_controller
->versionControlActions(items
);
580 void DolphinView::setUrl(const KUrl
& url
)
582 m_newFileNames
.clear();
583 updateView(url
, KUrl());
586 void DolphinView::selectAll()
588 m_viewAccessor
.itemView()->selectAll();
591 void DolphinView::invertSelection()
593 QItemSelectionModel
* selectionModel
= m_viewAccessor
.itemView()->selectionModel();
594 const QAbstractItemModel
* itemModel
= selectionModel
->model();
596 const QModelIndex topLeft
= itemModel
->index(0, 0);
597 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
598 itemModel
->columnCount() - 1);
600 const QItemSelection
selection(topLeft
, bottomRight
);
601 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
604 void DolphinView::clearSelection()
606 m_viewAccessor
.itemView()->clearSelection();
609 void DolphinView::renameSelectedItems()
611 KFileItemList items
= selectedItems();
612 const int itemCount
= items
.count();
618 // More than one item has been selected for renaming. Open
619 // a rename dialog and rename all items afterwards.
620 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
621 if (dialog
->exec() == QDialog::Rejected
) {
626 const QString newName
= dialog
->newName();
627 if (newName
.isEmpty()) {
628 emit
errorMessage(dialog
->errorString());
634 // the selection would be invalid after renaming the items, so just clear
638 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
639 // as one operation instead of n rename operations like it is done now...
640 Q_ASSERT(newName
.contains('#'));
642 // currently the items are sorted by the selection order, resort
643 // them by the file name
644 qSort(items
.begin(), items
.end(), lessThan
);
646 // iterate through all selected items and rename them...
648 foreach (const KFileItem
& item
, items
) {
649 const KUrl
& oldUrl
= item
.url();
651 number
.setNum(index
++);
653 QString name
= newName
;
654 name
.replace('#', number
);
656 if (oldUrl
.fileName() != name
) {
657 KUrl newUrl
= oldUrl
;
658 newUrl
.setFileName(name
);
659 KonqOperations::rename(this, oldUrl
, newUrl
);
662 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
663 Q_ASSERT(itemCount
== 1);
664 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForItem(items
.first());
665 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
666 m_viewAccessor
.itemView()->edit(proxyIndex
);
668 Q_ASSERT(itemCount
== 1);
670 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
671 if (dialog
->exec() == QDialog::Rejected
) {
676 const QString newName
= dialog
->newName();
677 if (newName
.isEmpty()) {
678 emit
errorMessage(dialog
->errorString());
684 const KUrl
& oldUrl
= items
.first().url();
685 KUrl newUrl
= oldUrl
;
686 newUrl
.setFileName(newName
);
687 KonqOperations::rename(this, oldUrl
, newUrl
);
690 // assure that the current index remains visible when KDirLister
691 // will notify the view about changed items
692 m_assureVisibleCurrentIndex
= true;
695 void DolphinView::trashSelectedItems()
697 const KUrl::List list
= simplifiedSelectedUrls();
698 KonqOperations::del(this, KonqOperations::TRASH
, list
);
701 void DolphinView::deleteSelectedItems()
703 const KUrl::List list
= simplifiedSelectedUrls();
704 const bool del
= KonqOperations::askDeleteConfirmation(list
,
706 KonqOperations::DEFAULT_CONFIRMATION
,
710 KIO::Job
* job
= KIO::del(list
);
711 connect(job
, SIGNAL(result(KJob
*)),
712 this, SLOT(slotDeleteFileFinished(KJob
*)));
716 void DolphinView::cutSelectedItems()
718 QMimeData
* mimeData
= selectionMimeData();
719 KonqMimeData::addIsCutSelection(mimeData
, true);
720 QApplication::clipboard()->setMimeData(mimeData
);
723 void DolphinView::copySelectedItems()
725 QMimeData
* mimeData
= selectionMimeData();
726 QApplication::clipboard()->setMimeData(mimeData
);
729 void DolphinView::paste()
734 void DolphinView::pasteIntoFolder()
736 const KFileItemList items
= selectedItems();
737 if ((items
.count() == 1) && items
.first().isDir()) {
738 pasteToUrl(items
.first().url());
742 void DolphinView::setShowPreview(bool show
)
744 if (m_showPreview
== show
) {
748 const KUrl viewPropsUrl
= rootUrl();
749 ViewProperties
props(viewPropsUrl
);
750 props
.setShowPreview(show
);
752 m_showPreview
= show
;
753 const int oldZoomLevel
= m_controller
->zoomLevel();
754 emit
showPreviewChanged();
756 // Enabling or disabling the preview might change the icon size of the view.
757 // As the view does not emit a signal when the icon size has been changed,
758 // the used zoom level of the controller must be adjusted manually:
759 updateZoomLevel(oldZoomLevel
);
762 void DolphinView::setShowHiddenFiles(bool show
)
764 if (m_viewAccessor
.dirLister()->showingDotFiles() == show
) {
768 const KUrl viewPropsUrl
= rootUrl();
769 ViewProperties
props(viewPropsUrl
);
770 props
.setShowHiddenFiles(show
);
772 m_viewAccessor
.dirLister()->setShowingDotFiles(show
);
773 emit
showHiddenFilesChanged();
776 void DolphinView::setCategorizedSorting(bool categorized
)
778 if (categorized
== categorizedSorting()) {
782 // setCategorizedSorting(true) may only get invoked
783 // if the view supports categorized sorting
784 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
786 ViewProperties
props(rootUrl());
787 props
.setCategorizedSorting(categorized
);
790 m_storedCategorizedSorting
= categorized
;
791 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
793 emit
categorizedSortingChanged();
796 void DolphinView::toggleSortOrder()
798 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
799 Qt::DescendingOrder
:
804 void DolphinView::toggleSortFoldersFirst()
806 setSortFoldersFirst(!sortFoldersFirst());
809 void DolphinView::toggleAdditionalInfo(QAction
* action
)
811 const KFileItemDelegate::Information info
=
812 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
814 KFileItemDelegate::InformationList list
= additionalInfo();
816 const bool show
= action
->isChecked();
818 const int index
= list
.indexOf(info
);
819 const bool containsInfo
= (index
>= 0);
820 if (show
&& !containsInfo
) {
822 setAdditionalInfo(list
);
823 } else if (!show
&& containsInfo
) {
824 list
.removeAt(index
);
825 setAdditionalInfo(list
);
826 Q_ASSERT(list
.indexOf(info
) < 0);
830 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
832 QWidget::mouseReleaseEvent(event
);
836 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
838 switch (event
->type()) {
839 case QEvent::FocusIn
:
840 if (watched
== m_viewAccessor
.itemView()) {
841 m_controller
->requestActivation();
845 case QEvent::DragEnter
:
846 if (watched
== m_viewAccessor
.itemView()->viewport()) {
851 case QEvent::KeyPress
:
852 if (watched
== m_viewAccessor
.itemView()) {
853 // clear the selection when Escape has been pressed
854 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
855 if (keyEvent
->key() == Qt::Key_Escape
) {
862 if (watched
== m_viewAccessor
.itemView()->viewport()) {
863 // Ctrl+wheel events should cause icon zooming, but not if the left mouse button is pressed
864 // (the user is probably trying to scroll during a selection in that case)
865 QWheelEvent
* wheelEvent
= static_cast<QWheelEvent
*>(event
);
866 if (wheelEvent
->modifiers() & Qt::ControlModifier
&& !(wheelEvent
->buttons() & Qt::LeftButton
)) {
867 const int delta
= wheelEvent
->delta();
868 const int level
= zoomLevel();
870 setZoomLevel(level
+ 1);
871 } else if (delta
< 0) {
872 setZoomLevel(level
- 1);
883 return QWidget::eventFilter(watched
, event
);
886 void DolphinView::activate()
891 void DolphinView::triggerItem(const KFileItem
& item
)
893 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
894 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
895 // items are selected by the user, hence don't trigger the
896 // item specified by 'index'
900 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
901 if (item
.isNull() || m_isContextMenuOpen
) {
905 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
908 void DolphinView::emitDelayedSelectionChangedSignal()
910 // Invoke emitSelectionChangedSignal() with a delay of 300 ms. This assures
911 // that fast selection changes don't result in expensive operations to
912 // collect all file items for the signal (see DolphinView::selectedItems()).
913 m_selectionChangedTimer
->start();
916 void DolphinView::emitSelectionChangedSignal()
918 emit
selectionChanged(DolphinView::selectedItems());
921 void DolphinView::openContextMenu(const QPoint
& pos
,
922 const QList
<QAction
*>& customActions
)
925 const QModelIndex index
= m_viewAccessor
.itemView()->indexAt(pos
);
926 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
927 const QModelIndex dolphinModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(index
);
928 item
= m_viewAccessor
.dirModel()->itemForIndex(dolphinModelIndex
);
931 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
932 emit
requestContextMenu(item
, url(), customActions
);
933 m_isContextMenuOpen
= false;
936 void DolphinView::dropUrls(const KFileItem
& destItem
,
937 const KUrl
& destPath
,
940 addNewFileNames(event
->mimeData());
941 DragAndDropHelper::instance().dropUrls(destItem
, destPath
, event
, this);
944 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
946 ViewProperties
props(rootUrl());
947 props
.setSorting(sorting
);
949 m_viewAccessor
.proxyModel()->setSorting(sorting
);
951 emit
sortingChanged(sorting
);
954 void DolphinView::updateSortOrder(Qt::SortOrder order
)
956 ViewProperties
props(rootUrl());
957 props
.setSortOrder(order
);
959 m_viewAccessor
.proxyModel()->setSortOrder(order
);
961 emit
sortOrderChanged(order
);
964 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
966 ViewProperties
props(rootUrl());
967 props
.setSortFoldersFirst(foldersFirst
);
969 m_viewAccessor
.proxyModel()->setSortFoldersFirst(foldersFirst
);
971 emit
sortFoldersFirstChanged(foldersFirst
);
974 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
976 ViewProperties
props(rootUrl());
977 props
.setAdditionalInfo(info
);
980 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
982 emit
additionalInfoChanged();
985 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
987 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
988 (m_mode
== DolphinView::IconsView
);
990 QAction
* showSizeInfo
= collection
->action("show_size_info");
991 QAction
* showDateInfo
= collection
->action("show_date_info");
992 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
993 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
994 QAction
* showGroupInfo
= collection
->action("show_group_info");
995 QAction
* showMimeInfo
= collection
->action("show_mime_info");
997 showSizeInfo
->setChecked(false);
998 showDateInfo
->setChecked(false);
999 showPermissionsInfo
->setChecked(false);
1000 showOwnerInfo
->setChecked(false);
1001 showGroupInfo
->setChecked(false);
1002 showMimeInfo
->setChecked(false);
1004 showSizeInfo
->setEnabled(enable
);
1005 showDateInfo
->setEnabled(enable
);
1006 showPermissionsInfo
->setEnabled(enable
);
1007 showOwnerInfo
->setEnabled(enable
);
1008 showGroupInfo
->setEnabled(enable
);
1009 showMimeInfo
->setEnabled(enable
);
1011 foreach (KFileItemDelegate::Information info
, m_viewAccessor
.itemDelegate()->showInformation()) {
1013 case KFileItemDelegate::Size
:
1014 showSizeInfo
->setChecked(true);
1016 case KFileItemDelegate::ModificationTime
:
1017 showDateInfo
->setChecked(true);
1019 case KFileItemDelegate::Permissions
:
1020 showPermissionsInfo
->setChecked(true);
1022 case KFileItemDelegate::Owner
:
1023 showOwnerInfo
->setChecked(true);
1025 case KFileItemDelegate::OwnerAndGroup
:
1026 showGroupInfo
->setChecked(true);
1028 case KFileItemDelegate::FriendlyMimeType
:
1029 showMimeInfo
->setChecked(true);
1037 QPair
<bool, QString
> DolphinView::pasteInfo() const
1039 return KonqOperations::pasteInfo(url());
1042 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1044 m_tabsForFiles
= tabsForFiles
;
1047 bool DolphinView::isTabsForFilesEnabled() const
1049 return m_tabsForFiles
;
1052 void DolphinView::activateItem(const KUrl
& url
)
1054 // TODO: If DolphinViewContainer uses DolphinView::restoreState(...) to restore the
1055 // view state in KDE 4.5, this function can be removed.
1056 m_activeItemUrl
= url
;
1059 bool DolphinView::itemsExpandable() const
1061 return m_viewAccessor
.itemsExpandable();
1064 void DolphinView::restoreState(QDataStream
&stream
)
1067 stream
>> m_activeItemUrl
;
1070 stream
>> m_restoredContentsPosition
;
1072 // expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1073 QSet
<KUrl
> urlsToExpand
;
1074 stream
>> urlsToExpand
;
1075 const DolphinDetailsViewExpander
* expander
= m_viewAccessor
.setExpandedUrls(urlsToExpand
);
1078 m_expanderActive
= true;
1079 connect (expander
, SIGNAL(completed()), this, SLOT(slotLoadingCompleted()));
1082 m_expanderActive
= false;
1086 void DolphinView::saveState(QDataStream
&stream
)
1089 KFileItem currentItem
;
1090 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1093 const QModelIndex proxyIndex
= view
->currentIndex();
1094 const QModelIndex dirModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1095 currentItem
= m_viewAccessor
.dirModel()->itemForIndex(dirModelIndex
);
1099 if (!currentItem
.isNull())
1100 currentUrl
= currentItem
.url();
1102 stream
<< currentUrl
;
1105 stream
<< contentsPosition();
1107 // expanded folders (only relevant for the details view - the set will be empty in other view modes)
1108 stream
<< m_viewAccessor
.expandedUrls();
1111 void DolphinView::observeCreatedItem(const KUrl
& url
)
1113 m_createdItemUrl
= url
;
1114 connect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1115 this, SLOT(selectAndScrollToCreatedItem()));
1118 void DolphinView::selectAndScrollToCreatedItem()
1120 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_createdItemUrl
);
1121 if (dirIndex
.isValid()) {
1122 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1123 m_viewAccessor
.itemView()->setCurrentIndex(proxyIndex
);
1126 disconnect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1127 this, SLOT(selectAndScrollToCreatedItem()));
1128 m_createdItemUrl
= KUrl();
1131 void DolphinView::emitContentsMoved()
1133 // TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
1134 // view state in KDE 4.5, the contentsMoved signal might not be needed anymore,
1135 // depending on how the implementation is done.
1136 // In that case, the code in contentsPosition() can be moved to saveState().
1138 // only emit the contents moved signal if no directory loading is ongoing
1139 // (this would reset the contents position always to (0, 0))
1140 if (!m_loadingDirectory
) {
1141 const QPoint
pos(contentsPosition());
1142 emit
contentsMoved(pos
.x(), pos
.y());
1146 void DolphinView::showHoverInformation(const KFileItem
& item
)
1148 emit
requestItemInfo(item
);
1151 void DolphinView::clearHoverInformation()
1153 emit
requestItemInfo(KFileItem());
1156 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1158 if (job
->error() == 0) {
1159 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1160 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1161 emit
errorMessage(job
->errorString());
1165 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1167 emit
requestUrlChange(url
);
1168 m_controller
->setUrl(url
);
1171 void DolphinView::slotDirListerCompleted()
1173 if (!m_expanderActive
) {
1174 slotLoadingCompleted();
1177 if (!m_newFileNames
.isEmpty()) {
1178 // select all newly added items created by a paste operation or
1179 // a drag & drop operation
1180 const int rowCount
= m_viewAccessor
.proxyModel()->rowCount();
1181 QItemSelection selection
;
1182 for (int row
= 0; row
< rowCount
; ++row
) {
1183 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->index(row
, 0);
1184 const QModelIndex dirIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1185 const KUrl url
= m_viewAccessor
.dirModel()->itemForIndex(dirIndex
).url();
1186 if (m_newFileNames
.contains(url
.fileName())) {
1187 selection
.merge(QItemSelection(proxyIndex
, proxyIndex
), QItemSelectionModel::Select
);
1190 m_viewAccessor
.itemView()->selectionModel()->select(selection
, QItemSelectionModel::Select
);
1192 m_newFileNames
.clear();
1196 void DolphinView::slotLoadingCompleted()
1198 m_expanderActive
= false;
1199 m_loadingDirectory
= false;
1201 if (!m_activeItemUrl
.isEmpty()) {
1202 // assure that the current item remains visible
1203 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_activeItemUrl
);
1204 if (dirIndex
.isValid()) {
1205 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1206 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1207 const bool clearSelection
= !hasSelection();
1208 view
->setCurrentIndex(proxyIndex
);
1209 if (clearSelection
) {
1210 view
->clearSelection();
1212 m_activeItemUrl
.clear();
1216 if (!m_selectedItems
.isEmpty()) {
1217 const KUrl
& baseUrl
= url();
1219 QItemSelection newSelection
;
1220 foreach(const KFileItem
& item
, m_selectedItems
) {
1221 url
= item
.url().upUrl();
1222 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
1223 QModelIndex index
= m_viewAccessor
.proxyModel()->mapFromSource(m_viewAccessor
.dirModel()->indexForItem(item
));
1224 newSelection
.select(index
, index
);
1227 m_viewAccessor
.itemView()->selectionModel()->select(newSelection
,
1228 QItemSelectionModel::ClearAndSelect
1229 | QItemSelectionModel::Current
);
1230 m_selectedItems
.clear();
1233 // Restore the contents position. This has to be done using a Qt::QueuedConnection
1234 // because the view might not be in its final state yet.
1235 QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection
);
1238 void DolphinView::slotRefreshItems()
1240 if (m_assureVisibleCurrentIndex
) {
1241 m_assureVisibleCurrentIndex
= false;
1242 m_viewAccessor
.itemView()->scrollTo(m_viewAccessor
.itemView()->currentIndex());
1246 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1248 if (!url
.isValid()) {
1249 const QString
location(url
.pathOrUrl());
1250 if (location
.isEmpty()) {
1251 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1253 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1258 m_loadingDirectory
= true;
1259 m_expanderActive
= false;
1261 m_viewAccessor
.dirLister()->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1264 void DolphinView::applyViewProperties()
1266 if (m_ignoreViewProperties
) {
1270 const ViewProperties
props(rootUrl());
1272 const Mode mode
= props
.viewMode();
1273 if (m_mode
!= mode
) {
1274 const int oldZoomLevel
= m_controller
->zoomLevel();
1280 updateZoomLevel(oldZoomLevel
);
1282 if (m_viewAccessor
.itemView() == 0) {
1285 Q_ASSERT(m_viewAccessor
.itemView() != 0);
1286 Q_ASSERT(m_viewAccessor
.itemDelegate() != 0);
1288 const bool showHiddenFiles
= props
.showHiddenFiles();
1289 if (showHiddenFiles
!= m_viewAccessor
.dirLister()->showingDotFiles()) {
1290 m_viewAccessor
.dirLister()->setShowingDotFiles(showHiddenFiles
);
1291 emit
showHiddenFilesChanged();
1294 m_storedCategorizedSorting
= props
.categorizedSorting();
1295 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1296 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
1297 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
1298 emit
categorizedSortingChanged();
1301 const DolphinView::Sorting sorting
= props
.sorting();
1302 if (sorting
!= m_viewAccessor
.proxyModel()->sorting()) {
1303 m_viewAccessor
.proxyModel()->setSorting(sorting
);
1304 emit
sortingChanged(sorting
);
1307 const Qt::SortOrder sortOrder
= props
.sortOrder();
1308 if (sortOrder
!= m_viewAccessor
.proxyModel()->sortOrder()) {
1309 m_viewAccessor
.proxyModel()->setSortOrder(sortOrder
);
1310 emit
sortOrderChanged(sortOrder
);
1313 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1314 if (sortFoldersFirst
!= m_viewAccessor
.proxyModel()->sortFoldersFirst()) {
1315 m_viewAccessor
.proxyModel()->setSortFoldersFirst(sortFoldersFirst
);
1316 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1319 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1320 if (info
!= m_viewAccessor
.itemDelegate()->showInformation()) {
1321 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
1322 emit
additionalInfoChanged();
1325 const bool showPreview
= props
.showPreview();
1326 if (showPreview
!= m_showPreview
) {
1327 m_showPreview
= showPreview
;
1328 const int oldZoomLevel
= m_controller
->zoomLevel();
1329 emit
showPreviewChanged();
1331 // Enabling or disabling the preview might change the icon size of the view.
1332 // As the view does not emit a signal when the icon size has been changed,
1333 // the used zoom level of the controller must be adjusted manually:
1334 updateZoomLevel(oldZoomLevel
);
1337 if (DolphinSettings::instance().generalSettings()->globalViewProps()) {
1338 // During the lifetime of a DolphinView instance the global view properties
1339 // should not be changed. This allows e. g. to split a view and use different
1340 // view properties for each view.
1341 m_ignoreViewProperties
= true;
1345 void DolphinView::createView()
1349 Q_ASSERT(m_viewAccessor
.itemView() == 0);
1350 m_viewAccessor
.createView(this, m_controller
, m_mode
);
1352 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1353 Q_ASSERT(view
!= 0);
1354 view
->installEventFilter(this);
1355 view
->viewport()->installEventFilter(this);
1357 m_controller
->setItemView(view
);
1358 connect(m_controller
, SIGNAL(selectionChanged()),
1359 this, SLOT(emitDelayedSelectionChangedSignal()));
1361 // When changing the view mode, the selection is lost due to reinstantiating
1362 // a new item view with a custom selection model. Pass the ownership of the
1363 // selection model to DolphinView, so that it can be shared by all item views.
1364 if (m_selectionModel
!= 0) {
1365 view
->setSelectionModel(m_selectionModel
);
1367 m_selectionModel
= view
->selectionModel();
1369 m_selectionModel
->setParent(this);
1371 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1372 this, SLOT(emitContentsMoved()));
1373 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1374 this, SLOT(emitContentsMoved()));
1376 setFocusProxy(m_viewAccessor
.layoutTarget());
1377 m_topLayout
->insertWidget(1, m_viewAccessor
.layoutTarget());
1380 void DolphinView::deleteView()
1382 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1384 // It's important to set the keyboard focus to the parent
1385 // before deleting the view: Otherwise when having a split
1386 // view the other view will get the focus and will request
1387 // an activation (see DolphinView::eventFilter()).
1391 m_topLayout
->removeWidget(view
);
1394 // disconnect all signal/slots
1396 m_controller
->disconnect(view
);
1398 disconnect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1399 this, SLOT(emitContentsMoved()));
1400 disconnect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1401 this, SLOT(emitContentsMoved()));
1403 m_viewAccessor
.deleteView();
1407 void DolphinView::pasteToUrl(const KUrl
& url
)
1409 addNewFileNames(QApplication::clipboard()->mimeData());
1410 KonqOperations::doPaste(this, url
);
1413 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1415 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor
.itemView()->iconSize());
1416 if (oldZoomLevel
!= newZoomLevel
) {
1417 m_controller
->setZoomLevel(newZoomLevel
);
1418 emit
zoomLevelChanged(newZoomLevel
);
1422 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1424 KUrl::List list
= selectedUrls();
1425 if (itemsExpandable() ) {
1426 list
= KDirModel::simplifiedUrlList(list
);
1431 QMimeData
* DolphinView::selectionMimeData() const
1433 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1434 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
1435 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
1436 return m_viewAccessor
.dirModel()->mimeData(selection
.indexes());
1439 void DolphinView::addNewFileNames(const QMimeData
* mimeData
)
1441 const KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1442 foreach (const KUrl
& url
, urls
) {
1443 m_newFileNames
.insert(url
.fileName());
1447 DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel
* proxyModel
) :
1450 m_columnsContainer(0),
1451 m_proxyModel(proxyModel
),
1456 DolphinView::ViewAccessor::~ViewAccessor()
1458 delete m_dragSource
;
1462 void DolphinView::ViewAccessor::createView(QWidget
* parent
,
1463 DolphinController
* controller
,
1466 Q_ASSERT(itemView() == 0);
1470 m_iconsView
= new DolphinIconsView(parent
, controller
, m_proxyModel
);
1474 m_detailsView
= new DolphinDetailsView(parent
, controller
, m_proxyModel
);
1478 m_columnsContainer
= new DolphinColumnViewContainer(parent
, controller
);
1486 void DolphinView::ViewAccessor::deleteView()
1488 QAbstractItemView
* view
= itemView();
1490 if (DragAndDropHelper::instance().isDragSource(view
)) {
1491 // The view is a drag source (the feature "Open folders
1492 // during drag operations" is used). Deleting the view
1493 // during an ongoing drag operation is not allowed, so
1494 // this will postponed.
1495 if (m_dragSource
!= 0) {
1496 // the old stored view is obviously not the drag source anymore
1497 m_dragSource
->deleteLater();
1501 m_dragSource
= view
;
1503 view
->deleteLater();
1510 if (m_columnsContainer
!= 0) {
1511 m_columnsContainer
->deleteLater();
1513 m_columnsContainer
= 0;
1517 void DolphinView::ViewAccessor::prepareUrlChange(const KUrl
& url
)
1519 if (m_columnsContainer
!= 0) {
1520 m_columnsContainer
->showColumn(url
);
1523 if(!m_detailsViewExpander
.isNull()) {
1524 // Stop expanding items in the current folder
1525 m_detailsViewExpander
->stop();
1529 QAbstractItemView
* DolphinView::ViewAccessor::itemView() const
1531 if (m_iconsView
!= 0) {
1535 if (m_detailsView
!= 0) {
1536 return m_detailsView
;
1539 if (m_columnsContainer
!= 0) {
1540 return m_columnsContainer
->activeColumn();
1546 KFileItemDelegate
* DolphinView::ViewAccessor::itemDelegate() const
1548 return static_cast<KFileItemDelegate
*>(itemView()->itemDelegate());
1551 QWidget
* DolphinView::ViewAccessor::layoutTarget() const
1553 if (m_columnsContainer
!= 0) {
1554 return m_columnsContainer
;
1559 KUrl
DolphinView::ViewAccessor::rootUrl() const
1561 return (m_columnsContainer
!= 0) ? m_columnsContainer
->rootUrl() : KUrl();
1564 bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
1566 return m_iconsView
!= 0;
1569 bool DolphinView::ViewAccessor::itemsExpandable() const
1571 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1575 QSet
<KUrl
> DolphinView::ViewAccessor::expandedUrls() const
1577 if(m_detailsView
!= 0) {
1578 return m_detailsView
->expandedUrls();
1581 return QSet
<KUrl
>();
1585 const DolphinDetailsViewExpander
* DolphinView::ViewAccessor::setExpandedUrls(const QSet
<KUrl
>& urlsToExpand
)
1587 if((m_detailsView
!= 0) && m_detailsView
->itemsExpandable() && !urlsToExpand
.isEmpty()) {
1588 m_detailsViewExpander
= new DolphinDetailsViewExpander(m_detailsView
, urlsToExpand
);
1589 return m_detailsViewExpander
;
1596 bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const
1598 // the details view requires no reloading of the directory, as it maps
1599 // the file item delegate info to its columns internally
1600 return m_detailsView
!= 0;
1603 DolphinModel
* DolphinView::ViewAccessor::dirModel() const
1605 return static_cast<DolphinModel
*>(proxyModel()->sourceModel());
1608 DolphinSortFilterProxyModel
* DolphinView::ViewAccessor::proxyModel() const
1610 if (m_columnsContainer
!= 0) {
1611 return static_cast<DolphinSortFilterProxyModel
*>(m_columnsContainer
->activeColumn()->model());
1613 return m_proxyModel
;
1616 KDirLister
* DolphinView::ViewAccessor::dirLister() const
1618 return dirModel()->dirLister();
1621 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1623 emit
redirection(oldUrl
, newUrl
);
1624 m_controller
->redirectToUrl(newUrl
); // #186947
1627 void DolphinView::restoreContentsPosition()
1629 if (!m_restoredContentsPosition
.isNull()) {
1630 setContentsPosition(m_restoredContentsPosition
.x(), m_restoredContentsPosition
.y());
1631 m_restoredContentsPosition
= QPoint();
1635 #include "dolphinview.moc"