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 KFileItemList
DolphinView::selectedItems() const
296 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
298 // Our view has a selection, we will map them back to the DolphinModel
299 // and then fill the KFileItemList.
300 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
302 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
303 KFileItemList itemList
;
305 const QModelIndexList indexList
= selection
.indexes();
306 foreach (const QModelIndex
&index
, indexList
) {
307 KFileItem item
= m_viewAccessor
.dirModel()->itemForIndex(index
);
308 if (!item
.isNull()) {
309 itemList
.append(item
);
316 KUrl::List
DolphinView::selectedUrls() const
319 const KFileItemList list
= selectedItems();
320 foreach (const KFileItem
&item
, list
) {
321 urls
.append(item
.url());
326 int DolphinView::selectedItemsCount() const
328 return m_viewAccessor
.itemView()->selectionModel()->selectedIndexes().count();
331 QItemSelectionModel
* DolphinView::selectionModel() const
333 return m_viewAccessor
.itemView()->selectionModel();
336 void DolphinView::setContentsPosition(int x
, int y
)
338 QAbstractItemView
* view
= m_viewAccessor
.itemView();
340 view
->horizontalScrollBar()->setValue(x
);
341 view
->verticalScrollBar()->setValue(y
);
343 m_loadingDirectory
= false;
346 void DolphinView::setRestoredContentsPosition(const QPoint
& pos
)
348 // TODO: This function is called by DolphinViewContainer.
349 // If it makes use of DolphinView::restoreState(...) to restore the
350 // view state in KDE 4.5, this function can be removed.
351 m_restoredContentsPosition
= pos
;
354 QPoint
DolphinView::contentsPosition() const
356 // TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
357 // view state in KDE 4.5, this code can be moved to DolphinView::saveState.
358 QAbstractItemView
* view
= m_viewAccessor
.itemView();
360 const int x
= view
->horizontalScrollBar()->value();
361 const int y
= view
->verticalScrollBar()->value();
365 void DolphinView::setZoomLevel(int level
)
367 if (level
< ZoomLevelInfo::minimumLevel()) {
368 level
= ZoomLevelInfo::minimumLevel();
369 } else if (level
> ZoomLevelInfo::maximumLevel()) {
370 level
= ZoomLevelInfo::maximumLevel();
373 if (level
!= zoomLevel()) {
374 m_controller
->setZoomLevel(level
);
375 emit
zoomLevelChanged(level
);
379 int DolphinView::zoomLevel() const
381 return m_controller
->zoomLevel();
384 void DolphinView::setSorting(Sorting sorting
)
386 if (sorting
!= this->sorting()) {
387 updateSorting(sorting
);
391 DolphinView::Sorting
DolphinView::sorting() const
393 return m_viewAccessor
.proxyModel()->sorting();
396 void DolphinView::setSortOrder(Qt::SortOrder order
)
398 if (sortOrder() != order
) {
399 updateSortOrder(order
);
403 Qt::SortOrder
DolphinView::sortOrder() const
405 return m_viewAccessor
.proxyModel()->sortOrder();
408 void DolphinView::setSortFoldersFirst(bool foldersFirst
)
410 if (sortFoldersFirst() != foldersFirst
) {
411 updateSortFoldersFirst(foldersFirst
);
415 bool DolphinView::sortFoldersFirst() const
417 return m_viewAccessor
.proxyModel()->sortFoldersFirst();
420 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
422 const KUrl viewPropsUrl
= rootUrl();
423 ViewProperties
props(viewPropsUrl
);
424 props
.setAdditionalInfo(info
);
425 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
427 emit
additionalInfoChanged();
429 if (m_viewAccessor
.reloadOnAdditionalInfoChange()) {
430 loadDirectory(viewPropsUrl
);
434 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
436 return m_viewAccessor
.itemDelegate()->showInformation();
439 void DolphinView::reload()
441 QByteArray viewState
;
442 QDataStream
saveStream(&viewState
, QIODevice::WriteOnly
);
443 saveState(saveStream
);
444 m_selectedItems
= selectedItems();
447 loadDirectory(url(), true);
449 QDataStream
restoreStream(viewState
);
450 restoreState(restoreStream
);
453 void DolphinView::refresh()
455 m_ignoreViewProperties
= false;
457 const bool oldActivationState
= m_active
;
458 const int oldZoomLevel
= m_controller
->zoomLevel();
462 applyViewProperties();
465 setActive(oldActivationState
);
466 updateZoomLevel(oldZoomLevel
);
469 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
471 Q_UNUSED(rootUrl
); // TODO: remove after columnview-cleanup has been finished
473 if (m_controller
->url() == url
) {
477 m_controller
->setUrl(url
); // emits urlChanged, which we forward
478 m_viewAccessor
.prepareUrlChange(url
);
479 applyViewProperties();
482 // When changing the URL there is no need to keep the version
483 // data of the previous URL.
484 m_viewAccessor
.dirModel()->clearVersionData();
486 emit
startedPathLoading(url
);
489 void DolphinView::setNameFilter(const QString
& nameFilter
)
491 m_controller
->setNameFilter(nameFilter
);
494 void DolphinView::calculateItemCount(int& fileCount
,
496 KIO::filesize_t
& totalFileSize
) const
498 foreach (const KFileItem
& item
, m_viewAccessor
.dirLister()->items()) {
503 totalFileSize
+= item
.size();
508 QString
DolphinView::statusBarText() const
513 KIO::filesize_t totalFileSize
= 0;
515 if (hasSelection()) {
516 // give a summary of the status of the selected files
517 const KFileItemList list
= selectedItems();
518 if (list
.isEmpty()) {
519 // when an item is triggered, it is temporary selected but selectedItems()
520 // will return an empty list
524 KFileItemList::const_iterator it
= list
.begin();
525 const KFileItemList::const_iterator end
= list
.end();
527 const KFileItem
& item
= *it
;
532 totalFileSize
+= item
.size();
537 if (folderCount
+ fileCount
== 1) {
538 // if only one item is selected, show the filename
539 const QString name
= list
.first().name();
540 text
= (folderCount
== 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name
) :
541 i18nc("@info:status", "<filename>%1</filename> selected (%2)",
542 name
, KIO::convertSize(totalFileSize
));
544 // at least 2 items are selected
545 const QString foldersText
= i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount
);
546 const QString filesText
= i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount
);
547 if ((folderCount
> 0) && (fileCount
> 0)) {
548 text
= i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
549 foldersText
, filesText
, KIO::convertSize(totalFileSize
));
550 } else if (fileCount
> 0) {
551 text
= i18nc("@info:status files (size)", "%1 (%2)", filesText
, KIO::convertSize(totalFileSize
));
553 Q_ASSERT(folderCount
> 0);
558 calculateItemCount(fileCount
, folderCount
, totalFileSize
);
559 text
= KIO::itemsSummaryString(fileCount
+ folderCount
,
560 fileCount
, folderCount
,
561 totalFileSize
, true);
567 QList
<QAction
*> DolphinView::versionControlActions(const KFileItemList
& items
) const
569 return m_controller
->versionControlActions(items
);
572 void DolphinView::setUrl(const KUrl
& url
)
574 m_newFileNames
.clear();
575 updateView(url
, KUrl());
578 void DolphinView::selectAll()
580 QAbstractItemView
* view
= m_viewAccessor
.itemView();
581 // TODO: there seems to be a bug in QAbstractItemView::selectAll(); if
582 // the Ctrl-key is pressed (e. g. for Ctrl+A), selectAll() inverts the
583 // selection instead of selecting all items. This is bypassed for KDE 4.0
584 // by invoking clearSelection() first.
585 view
->clearSelection();
589 void DolphinView::invertSelection()
591 QItemSelectionModel
* selectionModel
= m_viewAccessor
.itemView()->selectionModel();
592 const QAbstractItemModel
* itemModel
= selectionModel
->model();
594 const QModelIndex topLeft
= itemModel
->index(0, 0);
595 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
596 itemModel
->columnCount() - 1);
598 const QItemSelection
selection(topLeft
, bottomRight
);
599 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
602 void DolphinView::clearSelection()
604 m_viewAccessor
.itemView()->clearSelection();
607 void DolphinView::changeSelection(const KFileItemList
& selection
)
610 if (selection
.isEmpty()) {
613 const KUrl
& baseUrl
= url();
615 QItemSelection newSelection
;
616 foreach(const KFileItem
& item
, selection
) {
617 url
= item
.url().upUrl();
618 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
619 QModelIndex index
= m_viewAccessor
.proxyModel()->mapFromSource(m_viewAccessor
.dirModel()->indexForItem(item
));
620 newSelection
.select(index
, index
);
623 m_viewAccessor
.itemView()->selectionModel()->select(newSelection
,
624 QItemSelectionModel::ClearAndSelect
625 | QItemSelectionModel::Current
);
628 void DolphinView::renameSelectedItems()
630 KFileItemList items
= selectedItems();
631 const int itemCount
= items
.count();
637 // More than one item has been selected for renaming. Open
638 // a rename dialog and rename all items afterwards.
639 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
640 if (dialog
->exec() == QDialog::Rejected
) {
645 const QString newName
= dialog
->newName();
646 if (newName
.isEmpty()) {
647 emit
errorMessage(dialog
->errorString());
653 // the selection would be invalid after renaming the items, so just clear
657 // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
658 // as one operation instead of n rename operations like it is done now...
659 Q_ASSERT(newName
.contains('#'));
661 // currently the items are sorted by the selection order, resort
662 // them by the file name
663 qSort(items
.begin(), items
.end(), lessThan
);
665 // iterate through all selected items and rename them...
667 foreach (const KFileItem
& item
, items
) {
668 const KUrl
& oldUrl
= item
.url();
670 number
.setNum(index
++);
672 QString name
= newName
;
673 name
.replace('#', number
);
675 if (oldUrl
.fileName() != name
) {
676 KUrl newUrl
= oldUrl
;
677 newUrl
.setFileName(name
);
678 KonqOperations::rename(this, oldUrl
, newUrl
);
681 } else if (DolphinSettings::instance().generalSettings()->renameInline()) {
682 Q_ASSERT(itemCount
== 1);
683 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForItem(items
.first());
684 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
685 m_viewAccessor
.itemView()->edit(proxyIndex
);
687 Q_ASSERT(itemCount
== 1);
689 QPointer
<RenameDialog
> dialog
= new RenameDialog(this, items
);
690 if (dialog
->exec() == QDialog::Rejected
) {
695 const QString newName
= dialog
->newName();
696 if (newName
.isEmpty()) {
697 emit
errorMessage(dialog
->errorString());
703 const KUrl
& oldUrl
= items
.first().url();
704 KUrl newUrl
= oldUrl
;
705 newUrl
.setFileName(newName
);
706 KonqOperations::rename(this, oldUrl
, newUrl
);
709 // assure that the current index remains visible when KDirLister
710 // will notify the view about changed items
711 m_assureVisibleCurrentIndex
= true;
714 void DolphinView::trashSelectedItems()
716 const KUrl::List list
= simplifiedSelectedUrls();
717 KonqOperations::del(this, KonqOperations::TRASH
, list
);
720 void DolphinView::deleteSelectedItems()
722 const KUrl::List list
= simplifiedSelectedUrls();
723 const bool del
= KonqOperations::askDeleteConfirmation(list
,
725 KonqOperations::DEFAULT_CONFIRMATION
,
729 KIO::Job
* job
= KIO::del(list
);
730 connect(job
, SIGNAL(result(KJob
*)),
731 this, SLOT(slotDeleteFileFinished(KJob
*)));
735 void DolphinView::cutSelectedItems()
737 QMimeData
* mimeData
= selectionMimeData();
738 KonqMimeData::addIsCutSelection(mimeData
, true);
739 QApplication::clipboard()->setMimeData(mimeData
);
742 void DolphinView::copySelectedItems()
744 QMimeData
* mimeData
= selectionMimeData();
745 QApplication::clipboard()->setMimeData(mimeData
);
748 void DolphinView::paste()
753 void DolphinView::pasteIntoFolder()
755 const KFileItemList items
= selectedItems();
756 if ((items
.count() == 1) && items
.first().isDir()) {
757 pasteToUrl(items
.first().url());
761 void DolphinView::setShowPreview(bool show
)
763 if (m_showPreview
== show
) {
767 const KUrl viewPropsUrl
= rootUrl();
768 ViewProperties
props(viewPropsUrl
);
769 props
.setShowPreview(show
);
771 m_showPreview
= show
;
772 const int oldZoomLevel
= m_controller
->zoomLevel();
773 emit
showPreviewChanged();
775 // Enabling or disabling the preview might change the icon size of the view.
776 // As the view does not emit a signal when the icon size has been changed,
777 // the used zoom level of the controller must be adjusted manually:
778 updateZoomLevel(oldZoomLevel
);
781 void DolphinView::setShowHiddenFiles(bool show
)
783 if (m_viewAccessor
.dirLister()->showingDotFiles() == show
) {
787 const KUrl viewPropsUrl
= rootUrl();
788 ViewProperties
props(viewPropsUrl
);
789 props
.setShowHiddenFiles(show
);
791 m_viewAccessor
.dirLister()->setShowingDotFiles(show
);
792 emit
showHiddenFilesChanged();
795 void DolphinView::setCategorizedSorting(bool categorized
)
797 if (categorized
== categorizedSorting()) {
801 // setCategorizedSorting(true) may only get invoked
802 // if the view supports categorized sorting
803 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
805 ViewProperties
props(rootUrl());
806 props
.setCategorizedSorting(categorized
);
809 m_storedCategorizedSorting
= categorized
;
810 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
812 emit
categorizedSortingChanged();
815 void DolphinView::toggleSortOrder()
817 const Qt::SortOrder order
= (sortOrder() == Qt::AscendingOrder
) ?
818 Qt::DescendingOrder
:
823 void DolphinView::toggleSortFoldersFirst()
825 setSortFoldersFirst(!sortFoldersFirst());
828 void DolphinView::toggleAdditionalInfo(QAction
* action
)
830 const KFileItemDelegate::Information info
=
831 static_cast<KFileItemDelegate::Information
>(action
->data().toInt());
833 KFileItemDelegate::InformationList list
= additionalInfo();
835 const bool show
= action
->isChecked();
837 const int index
= list
.indexOf(info
);
838 const bool containsInfo
= (index
>= 0);
839 if (show
&& !containsInfo
) {
841 setAdditionalInfo(list
);
842 } else if (!show
&& containsInfo
) {
843 list
.removeAt(index
);
844 setAdditionalInfo(list
);
845 Q_ASSERT(list
.indexOf(info
) < 0);
849 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
851 QWidget::mouseReleaseEvent(event
);
855 bool DolphinView::eventFilter(QObject
* watched
, QEvent
* event
)
857 switch (event
->type()) {
858 case QEvent::FocusIn
:
859 if (watched
== m_viewAccessor
.itemView()) {
860 m_controller
->requestActivation();
864 case QEvent::DragEnter
:
865 if (watched
== m_viewAccessor
.itemView()->viewport()) {
870 case QEvent::KeyPress
:
871 if (watched
== m_viewAccessor
.itemView()) {
872 // clear the selection when Escape has been pressed
873 QKeyEvent
* keyEvent
= static_cast<QKeyEvent
*>(event
);
874 if (keyEvent
->key() == Qt::Key_Escape
) {
881 if (watched
== m_viewAccessor
.itemView()->viewport()) {
882 // Ctrl+wheel events should cause icon zooming, but not if the left mouse button is pressed
883 // (the user is probably trying to scroll during a selection in that case)
884 QWheelEvent
* wheelEvent
= static_cast<QWheelEvent
*>(event
);
885 if (wheelEvent
->modifiers() & Qt::ControlModifier
&& !(wheelEvent
->buttons() & Qt::LeftButton
)) {
886 const int delta
= wheelEvent
->delta();
887 const int level
= zoomLevel();
889 setZoomLevel(level
+ 1);
890 } else if (delta
< 0) {
891 setZoomLevel(level
- 1);
902 return QWidget::eventFilter(watched
, event
);
905 void DolphinView::activate()
910 void DolphinView::triggerItem(const KFileItem
& item
)
912 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
913 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
914 // items are selected by the user, hence don't trigger the
915 // item specified by 'index'
919 // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
920 if (item
.isNull() || m_isContextMenuOpen
) {
924 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
927 void DolphinView::emitDelayedSelectionChangedSignal()
929 // Invoke emitSelectionChangedSignal() with a delay of 300 ms. This assures
930 // that fast selection changes don't result in expensive operations to
931 // collect all file items for the signal (see DolphinView::selectedItems()).
932 m_selectionChangedTimer
->start();
935 void DolphinView::emitSelectionChangedSignal()
937 emit
selectionChanged(DolphinView::selectedItems());
940 void DolphinView::openContextMenu(const QPoint
& pos
,
941 const QList
<QAction
*>& customActions
)
944 const QModelIndex index
= m_viewAccessor
.itemView()->indexAt(pos
);
945 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
946 const QModelIndex dolphinModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(index
);
947 item
= m_viewAccessor
.dirModel()->itemForIndex(dolphinModelIndex
);
950 m_isContextMenuOpen
= true; // TODO: workaround for Qt-issue 207192
951 emit
requestContextMenu(item
, url(), customActions
);
952 m_isContextMenuOpen
= false;
955 void DolphinView::dropUrls(const KFileItem
& destItem
,
956 const KUrl
& destPath
,
959 addNewFileNames(event
->mimeData());
960 DragAndDropHelper::instance().dropUrls(destItem
, destPath
, event
, this);
963 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
965 ViewProperties
props(rootUrl());
966 props
.setSorting(sorting
);
968 m_viewAccessor
.proxyModel()->setSorting(sorting
);
970 emit
sortingChanged(sorting
);
973 void DolphinView::updateSortOrder(Qt::SortOrder order
)
975 ViewProperties
props(rootUrl());
976 props
.setSortOrder(order
);
978 m_viewAccessor
.proxyModel()->setSortOrder(order
);
980 emit
sortOrderChanged(order
);
983 void DolphinView::updateSortFoldersFirst(bool foldersFirst
)
985 ViewProperties
props(rootUrl());
986 props
.setSortFoldersFirst(foldersFirst
);
988 m_viewAccessor
.proxyModel()->setSortFoldersFirst(foldersFirst
);
990 emit
sortFoldersFirstChanged(foldersFirst
);
993 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
995 ViewProperties
props(rootUrl());
996 props
.setAdditionalInfo(info
);
999 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
1001 emit
additionalInfoChanged();
1004 void DolphinView::updateAdditionalInfoActions(KActionCollection
* collection
)
1006 const bool enable
= (m_mode
== DolphinView::DetailsView
) ||
1007 (m_mode
== DolphinView::IconsView
);
1009 QAction
* showSizeInfo
= collection
->action("show_size_info");
1010 QAction
* showDateInfo
= collection
->action("show_date_info");
1011 QAction
* showPermissionsInfo
= collection
->action("show_permissions_info");
1012 QAction
* showOwnerInfo
= collection
->action("show_owner_info");
1013 QAction
* showGroupInfo
= collection
->action("show_group_info");
1014 QAction
* showMimeInfo
= collection
->action("show_mime_info");
1016 showSizeInfo
->setChecked(false);
1017 showDateInfo
->setChecked(false);
1018 showPermissionsInfo
->setChecked(false);
1019 showOwnerInfo
->setChecked(false);
1020 showGroupInfo
->setChecked(false);
1021 showMimeInfo
->setChecked(false);
1023 showSizeInfo
->setEnabled(enable
);
1024 showDateInfo
->setEnabled(enable
);
1025 showPermissionsInfo
->setEnabled(enable
);
1026 showOwnerInfo
->setEnabled(enable
);
1027 showGroupInfo
->setEnabled(enable
);
1028 showMimeInfo
->setEnabled(enable
);
1030 foreach (KFileItemDelegate::Information info
, m_viewAccessor
.itemDelegate()->showInformation()) {
1032 case KFileItemDelegate::Size
:
1033 showSizeInfo
->setChecked(true);
1035 case KFileItemDelegate::ModificationTime
:
1036 showDateInfo
->setChecked(true);
1038 case KFileItemDelegate::Permissions
:
1039 showPermissionsInfo
->setChecked(true);
1041 case KFileItemDelegate::Owner
:
1042 showOwnerInfo
->setChecked(true);
1044 case KFileItemDelegate::OwnerAndGroup
:
1045 showGroupInfo
->setChecked(true);
1047 case KFileItemDelegate::FriendlyMimeType
:
1048 showMimeInfo
->setChecked(true);
1056 QPair
<bool, QString
> DolphinView::pasteInfo() const
1058 return KonqOperations::pasteInfo(url());
1061 void DolphinView::setTabsForFilesEnabled(bool tabsForFiles
)
1063 m_tabsForFiles
= tabsForFiles
;
1066 bool DolphinView::isTabsForFilesEnabled() const
1068 return m_tabsForFiles
;
1071 void DolphinView::activateItem(const KUrl
& url
)
1073 // TODO: If DolphinViewContainer uses DolphinView::restoreState(...) to restore the
1074 // view state in KDE 4.5, this function can be removed.
1075 m_activeItemUrl
= url
;
1078 bool DolphinView::itemsExpandable() const
1080 return m_viewAccessor
.itemsExpandable();
1083 void DolphinView::restoreState(QDataStream
&stream
)
1086 stream
>> m_activeItemUrl
;
1089 stream
>> m_restoredContentsPosition
;
1091 // expanded folders (only relevant for the details view - will be ignored by the view in other view modes)
1092 QSet
<KUrl
> urlsToExpand
;
1093 stream
>> urlsToExpand
;
1094 const DolphinDetailsViewExpander
* expander
= m_viewAccessor
.setExpandedUrls(urlsToExpand
);
1097 m_expanderActive
= true;
1098 connect (expander
, SIGNAL(completed()), this, SLOT(slotLoadingCompleted()));
1101 m_expanderActive
= false;
1105 void DolphinView::saveState(QDataStream
&stream
)
1108 KFileItem currentItem
;
1109 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1112 const QModelIndex proxyIndex
= view
->currentIndex();
1113 const QModelIndex dirModelIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1114 currentItem
= m_viewAccessor
.dirModel()->itemForIndex(dirModelIndex
);
1118 if (!currentItem
.isNull())
1119 currentUrl
= currentItem
.url();
1121 stream
<< currentUrl
;
1124 stream
<< contentsPosition();
1126 // expanded folders (only relevant for the details view - the set will be empty in other view modes)
1127 stream
<< m_viewAccessor
.expandedUrls();
1130 void DolphinView::observeCreatedItem(const KUrl
& url
)
1132 m_createdItemUrl
= url
;
1133 connect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1134 this, SLOT(selectAndScrollToCreatedItem()));
1137 void DolphinView::selectAndScrollToCreatedItem()
1139 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_createdItemUrl
);
1140 if (dirIndex
.isValid()) {
1141 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1142 m_viewAccessor
.itemView()->setCurrentIndex(proxyIndex
);
1145 disconnect(m_viewAccessor
.dirModel(), SIGNAL(rowsInserted(const QModelIndex
&, int, int)),
1146 this, SLOT(selectAndScrollToCreatedItem()));
1147 m_createdItemUrl
= KUrl();
1150 void DolphinView::emitContentsMoved()
1152 // TODO: If DolphinViewContainer uses DolphinView::saveState(...) to save the
1153 // view state in KDE 4.5, the contentsMoved signal might not be needed anymore,
1154 // depending on how the implementation is done.
1155 // In that case, the code in contentsPosition() can be moved to saveState().
1157 // only emit the contents moved signal if no directory loading is ongoing
1158 // (this would reset the contents position always to (0, 0))
1159 if (!m_loadingDirectory
) {
1160 const QPoint
pos(contentsPosition());
1161 emit
contentsMoved(pos
.x(), pos
.y());
1165 void DolphinView::showHoverInformation(const KFileItem
& item
)
1167 emit
requestItemInfo(item
);
1170 void DolphinView::clearHoverInformation()
1172 emit
requestItemInfo(KFileItem());
1175 void DolphinView::slotDeleteFileFinished(KJob
* job
)
1177 if (job
->error() == 0) {
1178 emit
operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
1179 } else if (job
->error() != KIO::ERR_USER_CANCELED
) {
1180 emit
errorMessage(job
->errorString());
1184 void DolphinView::slotRequestUrlChange(const KUrl
& url
)
1186 emit
requestUrlChange(url
);
1187 m_controller
->setUrl(url
);
1190 void DolphinView::slotDirListerCompleted()
1192 if (!m_expanderActive
) {
1193 slotLoadingCompleted();
1196 if (!m_newFileNames
.isEmpty()) {
1197 // select all newly added items created by a paste operation or
1198 // a drag & drop operation
1199 const int rowCount
= m_viewAccessor
.proxyModel()->rowCount();
1200 QItemSelection selection
;
1201 for (int row
= 0; row
< rowCount
; ++row
) {
1202 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->index(row
, 0);
1203 const QModelIndex dirIndex
= m_viewAccessor
.proxyModel()->mapToSource(proxyIndex
);
1204 const KUrl url
= m_viewAccessor
.dirModel()->itemForIndex(dirIndex
).url();
1205 if (m_newFileNames
.contains(url
.fileName())) {
1206 selection
.merge(QItemSelection(proxyIndex
, proxyIndex
), QItemSelectionModel::Select
);
1209 m_viewAccessor
.itemView()->selectionModel()->select(selection
, QItemSelectionModel::Select
);
1211 m_newFileNames
.clear();
1215 void DolphinView::slotLoadingCompleted()
1217 m_expanderActive
= false;
1218 m_loadingDirectory
= false;
1220 if (!m_activeItemUrl
.isEmpty()) {
1221 // assure that the current item remains visible
1222 const QModelIndex dirIndex
= m_viewAccessor
.dirModel()->indexForUrl(m_activeItemUrl
);
1223 if (dirIndex
.isValid()) {
1224 const QModelIndex proxyIndex
= m_viewAccessor
.proxyModel()->mapFromSource(dirIndex
);
1225 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1226 const bool clearSelection
= !hasSelection();
1227 view
->setCurrentIndex(proxyIndex
);
1228 if (clearSelection
) {
1229 view
->clearSelection();
1231 m_activeItemUrl
.clear();
1235 if (!m_selectedItems
.isEmpty()) {
1236 changeSelection(m_selectedItems
);
1237 m_selectedItems
.clear();
1240 // Restore the contents position. This has to be done using a Qt::QueuedConnection
1241 // because the view might not be in its final state yet.
1242 QMetaObject::invokeMethod(this, "restoreContentsPosition", Qt::QueuedConnection
);
1245 void DolphinView::slotRefreshItems()
1247 if (m_assureVisibleCurrentIndex
) {
1248 m_assureVisibleCurrentIndex
= false;
1249 m_viewAccessor
.itemView()->scrollTo(m_viewAccessor
.itemView()->currentIndex());
1253 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
1255 if (!url
.isValid()) {
1256 const QString
location(url
.pathOrUrl());
1257 if (location
.isEmpty()) {
1258 emit
errorMessage(i18nc("@info:status", "The location is empty."));
1260 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
1265 m_loadingDirectory
= true;
1266 m_expanderActive
= false;
1268 m_viewAccessor
.dirLister()->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
1271 void DolphinView::applyViewProperties()
1273 if (m_ignoreViewProperties
) {
1277 const ViewProperties
props(rootUrl());
1279 const Mode mode
= props
.viewMode();
1280 if (m_mode
!= mode
) {
1281 const int oldZoomLevel
= m_controller
->zoomLevel();
1287 updateZoomLevel(oldZoomLevel
);
1289 if (m_viewAccessor
.itemView() == 0) {
1292 Q_ASSERT(m_viewAccessor
.itemView() != 0);
1293 Q_ASSERT(m_viewAccessor
.itemDelegate() != 0);
1295 const bool showHiddenFiles
= props
.showHiddenFiles();
1296 if (showHiddenFiles
!= m_viewAccessor
.dirLister()->showingDotFiles()) {
1297 m_viewAccessor
.dirLister()->setShowingDotFiles(showHiddenFiles
);
1298 emit
showHiddenFilesChanged();
1301 m_storedCategorizedSorting
= props
.categorizedSorting();
1302 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
1303 if (categorized
!= m_viewAccessor
.proxyModel()->isCategorizedModel()) {
1304 m_viewAccessor
.proxyModel()->setCategorizedModel(categorized
);
1305 emit
categorizedSortingChanged();
1308 const DolphinView::Sorting sorting
= props
.sorting();
1309 if (sorting
!= m_viewAccessor
.proxyModel()->sorting()) {
1310 m_viewAccessor
.proxyModel()->setSorting(sorting
);
1311 emit
sortingChanged(sorting
);
1314 const Qt::SortOrder sortOrder
= props
.sortOrder();
1315 if (sortOrder
!= m_viewAccessor
.proxyModel()->sortOrder()) {
1316 m_viewAccessor
.proxyModel()->setSortOrder(sortOrder
);
1317 emit
sortOrderChanged(sortOrder
);
1320 const bool sortFoldersFirst
= props
.sortFoldersFirst();
1321 if (sortFoldersFirst
!= m_viewAccessor
.proxyModel()->sortFoldersFirst()) {
1322 m_viewAccessor
.proxyModel()->setSortFoldersFirst(sortFoldersFirst
);
1323 emit
sortFoldersFirstChanged(sortFoldersFirst
);
1326 KFileItemDelegate::InformationList info
= props
.additionalInfo();
1327 if (info
!= m_viewAccessor
.itemDelegate()->showInformation()) {
1328 m_viewAccessor
.itemDelegate()->setShowInformation(info
);
1329 emit
additionalInfoChanged();
1332 const bool showPreview
= props
.showPreview();
1333 if (showPreview
!= m_showPreview
) {
1334 m_showPreview
= showPreview
;
1335 const int oldZoomLevel
= m_controller
->zoomLevel();
1336 emit
showPreviewChanged();
1338 // Enabling or disabling the preview might change the icon size of the view.
1339 // As the view does not emit a signal when the icon size has been changed,
1340 // the used zoom level of the controller must be adjusted manually:
1341 updateZoomLevel(oldZoomLevel
);
1344 if (DolphinSettings::instance().generalSettings()->globalViewProps()) {
1345 // During the lifetime of a DolphinView instance the global view properties
1346 // should not be changed. This allows e. g. to split a view and use different
1347 // view properties for each view.
1348 m_ignoreViewProperties
= true;
1352 void DolphinView::createView()
1356 Q_ASSERT(m_viewAccessor
.itemView() == 0);
1357 m_viewAccessor
.createView(this, m_controller
, m_mode
);
1359 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1360 Q_ASSERT(view
!= 0);
1361 view
->installEventFilter(this);
1362 view
->viewport()->installEventFilter(this);
1364 m_controller
->setItemView(view
);
1365 connect(m_controller
, SIGNAL(selectionChanged()),
1366 this, SLOT(emitDelayedSelectionChangedSignal()));
1368 // When changing the view mode, the selection is lost due to reinstantiating
1369 // a new item view with a custom selection model. Pass the ownership of the
1370 // selection model to DolphinView, so that it can be shared by all item views.
1371 if (m_selectionModel
!= 0) {
1372 view
->setSelectionModel(m_selectionModel
);
1374 m_selectionModel
= view
->selectionModel();
1376 m_selectionModel
->setParent(this);
1378 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1379 this, SLOT(emitContentsMoved()));
1380 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1381 this, SLOT(emitContentsMoved()));
1383 setFocusProxy(m_viewAccessor
.layoutTarget());
1384 m_topLayout
->insertWidget(1, m_viewAccessor
.layoutTarget());
1387 void DolphinView::deleteView()
1389 QAbstractItemView
* view
= m_viewAccessor
.itemView();
1391 // It's important to set the keyboard focus to the parent
1392 // before deleting the view: Otherwise when having a split
1393 // view the other view will get the focus and will request
1394 // an activation (see DolphinView::eventFilter()).
1398 m_topLayout
->removeWidget(view
);
1401 // disconnect all signal/slots
1403 m_controller
->disconnect(view
);
1405 disconnect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
1406 this, SLOT(emitContentsMoved()));
1407 disconnect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
1408 this, SLOT(emitContentsMoved()));
1410 m_viewAccessor
.deleteView();
1414 void DolphinView::pasteToUrl(const KUrl
& url
)
1416 addNewFileNames(QApplication::clipboard()->mimeData());
1417 KonqOperations::doPaste(this, url
);
1420 void DolphinView::updateZoomLevel(int oldZoomLevel
)
1422 const int newZoomLevel
= ZoomLevelInfo::zoomLevelForIconSize(m_viewAccessor
.itemView()->iconSize());
1423 if (oldZoomLevel
!= newZoomLevel
) {
1424 m_controller
->setZoomLevel(newZoomLevel
);
1425 emit
zoomLevelChanged(newZoomLevel
);
1429 KUrl::List
DolphinView::simplifiedSelectedUrls() const
1431 KUrl::List list
= selectedUrls();
1432 if (itemsExpandable() ) {
1433 list
= KDirModel::simplifiedUrlList(list
);
1438 QMimeData
* DolphinView::selectionMimeData() const
1440 const QAbstractItemView
* view
= m_viewAccessor
.itemView();
1441 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
1442 const QItemSelection selection
= m_viewAccessor
.proxyModel()->mapSelectionToSource(view
->selectionModel()->selection());
1443 return m_viewAccessor
.dirModel()->mimeData(selection
.indexes());
1446 void DolphinView::addNewFileNames(const QMimeData
* mimeData
)
1448 const KUrl::List urls
= KUrl::List::fromMimeData(mimeData
);
1449 foreach (const KUrl
& url
, urls
) {
1450 m_newFileNames
.insert(url
.fileName());
1454 DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel
* proxyModel
) :
1457 m_columnsContainer(0),
1458 m_proxyModel(proxyModel
),
1463 DolphinView::ViewAccessor::~ViewAccessor()
1465 delete m_dragSource
;
1469 void DolphinView::ViewAccessor::createView(QWidget
* parent
,
1470 DolphinController
* controller
,
1473 Q_ASSERT(itemView() == 0);
1477 m_iconsView
= new DolphinIconsView(parent
, controller
, m_proxyModel
);
1481 m_detailsView
= new DolphinDetailsView(parent
, controller
, m_proxyModel
);
1485 m_columnsContainer
= new DolphinColumnViewContainer(parent
, controller
);
1493 void DolphinView::ViewAccessor::deleteView()
1495 QAbstractItemView
* view
= itemView();
1497 if (DragAndDropHelper::instance().isDragSource(view
)) {
1498 // The view is a drag source (the feature "Open folders
1499 // during drag operations" is used). Deleting the view
1500 // during an ongoing drag operation is not allowed, so
1501 // this will postponed.
1502 if (m_dragSource
!= 0) {
1503 // the old stored view is obviously not the drag source anymore
1504 m_dragSource
->deleteLater();
1508 m_dragSource
= view
;
1510 view
->deleteLater();
1517 if (m_columnsContainer
!= 0) {
1518 m_columnsContainer
->deleteLater();
1520 m_columnsContainer
= 0;
1524 void DolphinView::ViewAccessor::prepareUrlChange(const KUrl
& url
)
1526 if (m_columnsContainer
!= 0) {
1527 m_columnsContainer
->showColumn(url
);
1530 if(!m_detailsViewExpander
.isNull()) {
1531 // Stop expanding items in the current folder
1532 m_detailsViewExpander
->stop();
1536 QAbstractItemView
* DolphinView::ViewAccessor::itemView() const
1538 if (m_iconsView
!= 0) {
1542 if (m_detailsView
!= 0) {
1543 return m_detailsView
;
1546 if (m_columnsContainer
!= 0) {
1547 return m_columnsContainer
->activeColumn();
1553 KFileItemDelegate
* DolphinView::ViewAccessor::itemDelegate() const
1555 return static_cast<KFileItemDelegate
*>(itemView()->itemDelegate());
1558 QWidget
* DolphinView::ViewAccessor::layoutTarget() const
1560 if (m_columnsContainer
!= 0) {
1561 return m_columnsContainer
;
1566 KUrl
DolphinView::ViewAccessor::rootUrl() const
1568 return (m_columnsContainer
!= 0) ? m_columnsContainer
->rootUrl() : KUrl();
1571 bool DolphinView::ViewAccessor::supportsCategorizedSorting() const
1573 return m_iconsView
!= 0;
1576 bool DolphinView::ViewAccessor::itemsExpandable() const
1578 return (m_detailsView
!= 0) && m_detailsView
->itemsExpandable();
1582 QSet
<KUrl
> DolphinView::ViewAccessor::expandedUrls() const
1584 if(m_detailsView
!= 0) {
1585 return m_detailsView
->expandedUrls();
1588 return QSet
<KUrl
>();
1592 const DolphinDetailsViewExpander
* DolphinView::ViewAccessor::setExpandedUrls(const QSet
<KUrl
>& urlsToExpand
)
1594 if((m_detailsView
!= 0) && m_detailsView
->itemsExpandable() && !urlsToExpand
.isEmpty()) {
1595 m_detailsViewExpander
= new DolphinDetailsViewExpander(m_detailsView
, urlsToExpand
);
1596 return m_detailsViewExpander
;
1603 bool DolphinView::ViewAccessor::reloadOnAdditionalInfoChange() const
1605 // the details view requires no reloading of the directory, as it maps
1606 // the file item delegate info to its columns internally
1607 return m_detailsView
!= 0;
1610 DolphinModel
* DolphinView::ViewAccessor::dirModel() const
1612 return static_cast<DolphinModel
*>(proxyModel()->sourceModel());
1615 DolphinSortFilterProxyModel
* DolphinView::ViewAccessor::proxyModel() const
1617 if (m_columnsContainer
!= 0) {
1618 return static_cast<DolphinSortFilterProxyModel
*>(m_columnsContainer
->activeColumn()->model());
1620 return m_proxyModel
;
1623 KDirLister
* DolphinView::ViewAccessor::dirLister() const
1625 return dirModel()->dirLister();
1628 void DolphinView::slotRedirection(const KUrl
& oldUrl
, const KUrl
& newUrl
)
1630 emit
redirection(oldUrl
, newUrl
);
1631 m_controller
->redirectToUrl(newUrl
); // #186947
1634 void DolphinView::restoreContentsPosition()
1636 if (!m_restoredContentsPosition
.isNull()) {
1637 setContentsPosition(m_restoredContentsPosition
.x(), m_restoredContentsPosition
.y());
1638 m_restoredContentsPosition
= QPoint();
1642 #include "dolphinview.moc"